[Ovirt-devel] [PATCH server] Replaced the config scripts with configuration encoding.

Darryl L. Pierce dpierce at redhat.com
Mon Oct 20 18:25:21 UTC 2008


Rather than sending the node a series of scripts that load
kernel modules, or are tightly coupled to tools like augeas,
this patch introduces an encoding scheme for data.

A line that begins with "bonding" describes a bonded interface.
>From it the configuration processor generates a simple bonding
file that includes an alias for the bonding kernel module

A line that begins with "ifcfg" describes an network
interface. It will contain the mac address and interface name,
followed by all needed configuration values to bring the
interface up.

THIS PATCH FIXES THE ABOVE CHECKIN MESSAGE.
---
 src/db/migrate/024_add_boot_type_to_bonding.rb     |    2 +-
 .../migrate/025_allow_nic_boot_type_to_be_null.rb  |   28 +++++
 src/lib/managed_node_configuration.rb              |   81 +++++++------
 src/test/fixtures/bondings.yml                     |   10 ++-
 src/test/fixtures/bondings_nics.yml                |    8 ++
 src/test/fixtures/hosts.yml                        |   10 ++
 src/test/fixtures/nics.yml                         |   14 ++
 .../functional/managed_node_configuration_test.rb  |  127 ++++++--------------
 8 files changed, 152 insertions(+), 128 deletions(-)
 create mode 100644 src/db/migrate/025_allow_nic_boot_type_to_be_null.rb

diff --git a/src/db/migrate/024_add_boot_type_to_bonding.rb b/src/db/migrate/024_add_boot_type_to_bonding.rb
index e2cf1c6..17e085f 100644
--- a/src/db/migrate/024_add_boot_type_to_bonding.rb
+++ b/src/db/migrate/024_add_boot_type_to_bonding.rb
@@ -19,7 +19,7 @@
 
 class AddBootTypeToBonding < ActiveRecord::Migration
   def self.up
-    add_column :bondings, :boot_type_id, :integer, :null => false
+    add_column :bondings, :boot_type_id, :integer, :null => true
 
     execute 'alter table bondings add constraint fk_bondings_boot_type
              foreign key (boot_type_id) references boot_types(id)'
diff --git a/src/db/migrate/025_allow_nic_boot_type_to_be_null.rb b/src/db/migrate/025_allow_nic_boot_type_to_be_null.rb
new file mode 100644
index 0000000..b09ada1
--- /dev/null
+++ b/src/db/migrate/025_allow_nic_boot_type_to_be_null.rb
@@ -0,0 +1,28 @@
+#
+# Copyright (C) 2008 Red Hat, Inc.
+# Written by Darryl L. Pierce <dpierce at redhat.com>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; version 2 of the License.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+# MA  02110-1301, USA.  A copy of the GNU General Public License is
+# also available at http://www.gnu.org/copyleft/gpl.html.
+
+class AllowNicBootTypeToBeNull < ActiveRecord::Migration
+  def self.up
+    change_column :nics, :boot_type_id, :integer, :null => true
+  end
+
+  def self.down
+    change_column :nics, :boot_type_id, :integer, :null => false
+  end
+end
diff --git a/src/lib/managed_node_configuration.rb b/src/lib/managed_node_configuration.rb
index 93f8448..101be9f 100644
--- a/src/lib/managed_node_configuration.rb
+++ b/src/lib/managed_node_configuration.rb
@@ -23,36 +23,57 @@
 
 require 'stringio'
 
+# +ManagedNodeConfiguration+ generates a configuration file for an oVirt node
+# based on information about the hardware submitted by the node and the
+# configuration details held in the database.
+#
+# The configuration is returned as a series of encoded lines.
+#
+# For a kernel module, the formation of the line is as follows:
+#
+# bonding=[bonding alias]
+#
+# An example would be for loading the +bonding+ kernel module to setup a bonded
+# interface for load balancing. In this example, the bonded interface would be
+# named +failover0+ on the node:
+#
+# bonding=failover0
+#
+# For a network interface (including a bonded interface) an example would be:
+#
+# ifcfg=00:11:22:33:44|eth0|BOOTPROTO=dhcp|bridge=ovirtbr0|ONBOOT=yes
+#
+# In this line, the network interface +eth0+ has a hardware MAC address of
+# +00:11:22:33:44+. It will use DHCP for retrieving it's IP address details,
+# and will use the +ovirtbr0+ interface as a bridge.
+#
 class ManagedNodeConfiguration
   NIC_ENTRY_PREFIX='/files/etc/sysconfig/network-scripts'
 
   def self.generate(host, macs)
     result = StringIO.new
 
-    result.puts "#!/bin/bash"
     result.puts "# THIS FILE IS GENERATED!"
 
     # first process any bondings that're defined
     unless host.bondings.empty?
-      result.puts "cat <<\EOF > /var/tmp/pre-config-script"
-      result.puts "#!/bin/bash"
-      result.puts "# THIS FILE IS GENERATED!"
-
       host.bondings.each do |bonding|
-        result.puts "/sbin/modprobe bonding mode=#{bonding.bonding_type.mode}"
+        result.puts "bonding=#{bonding.interface_name}"
       end
-
-      result.puts "EOF"
     end
 
     # now process the network interfaces  and bondings
-    result.puts "cat <<\EOF > /var/tmp/node-augtool"
 
     host.bondings.each do |bonding|
-      result.puts "rm #{NIC_ENTRY_PREFIX}/ifcfg-#{bonding.interface_name}"
-      result.puts "set #{NIC_ENTRY_PREFIX}/ifcfg-#{bonding.interface_name}/DEVICE #{bonding.interface_name}"
-      result.puts "set #{NIC_ENTRY_PREFIX}/ifcfg-#{bonding.interface_name}/IPADDR #{bonding.ip_addr}" if bonding.ip_addr
-      result.puts "set #{NIC_ENTRY_PREFIX}/ifcfg-#{bonding.interface_name}/ONBOOT yes"
+      entry = "ifcfg=none|#{bonding.interface_name}|BONDING_OPTS=\"mode=#{bonding.bonding_type.mode} miimon=100\""
+
+      if bonding.ip_addr == nil || bonding.ip_addr.empty?
+        entry += "|BOOTPROTO=dhcp"
+      else
+        entry += "|BOOTPROTO=static|IPADDR=#{bonding.ip_addr}|NETMASK=#{bonding.netmask}|BROADCAST=#{bonding.broadcast}"
+      end
+
+      result.puts "#{entry}|ONBOOT=yes"
 
       bonding.nics.each do |nic|
         process_nic result, nic, macs, bonding
@@ -75,9 +96,6 @@ class ManagedNodeConfiguration
       end
     end
 
-    result.puts "save"
-    result.puts "EOF"
-
     result.string
   end
 
@@ -87,31 +105,20 @@ class ManagedNodeConfiguration
     iface_name = macs[nic.mac]
 
     if iface_name
-      result.puts "rm #{NIC_ENTRY_PREFIX}/ifcfg-#{iface_name}"
-      result.puts "set #{NIC_ENTRY_PREFIX}/ifcfg-#{iface_name}/DEVICE #{iface_name}"
+      entry = "ifcfg=#{nic.mac}|#{iface_name}"
 
       if bonding
-        result.puts "set #{NIC_ENTRY_PREFIX}/ifcfg-#{iface_name}/MASTER #{bonding.interface_name}"
-        result.puts "set #{NIC_ENTRY_PREFIX}/ifcfg-#{iface_name}/SLAVE yes"
+        entry += "|MASTER=#{bonding.interface_name}|SLAVE=yes"
       else
-        result.puts "set #{NIC_ENTRY_PREFIX}/ifcfg-#{iface_name}/BOOTPROTO #{nic.boot_type.proto}"
-
-        if nic.boot_type.proto == 'static'
-          result.puts "set #{NIC_ENTRY_PREFIX}/ifcfg-#{iface_name}/IPADDR #{nic.ip_addr}"
-          result.puts "set #{NIC_ENTRY_PREFIX}/ifcfg-#{iface_name}/NETMASK #{nic.netmask}"
-          result.puts "set #{NIC_ENTRY_PREFIX}/ifcfg-#{iface_name}/BROADCAST #{nic.broadcast}"
-        end
-
-	if bridged
-	  result.puts "set #{NIC_ENTRY_PREFIX}/ifcfg-#{iface_name}/BRIDGE ovirtbr0"
-	elsif is_bridge
-	  result.puts "set #{NIC_ENTRY_PREFIX}/ifcfg-#{iface_name}/TYPE bridge"
-	  result.puts "set #{NIC_ENTRY_PREFIX}/ifcfg-#{iface_name}/PEERNTP yes"
-	  result.puts "set #{NIC_ENTRY_PREFIX}/ifcfg-#{iface_name}/DELAY 0"
-	end
+        entry += "|BOOTPROTO=#{nic.boot_type.proto}"
+        entry += "|IPADDR=#{nic.ip_addr}|NETMASK=#{nic.netmask}|BROADCAST=#{nic.broadcast}" if nic.boot_type.proto == 'static'
+        entry += "|BRIDGE=#{nic.bridge}" if nic.bridge && !is_bridge
+        entry += "|BRIDGE=ovirtbr0" if !nic.bridge && !is_bridge
+        entry += "|TYPE=bridge" if is_bridge
       end
-
-      result.puts "set #{NIC_ENTRY_PREFIX}/ifcfg-#{iface_name}/ONBOOT yes"
+      entry += "|ONBOOT=yes"
     end
+
+    result.puts entry if defined? entry
   end
 end
diff --git a/src/test/fixtures/bondings.yml b/src/test/fixtures/bondings.yml
index 29473c7..227b92b 100644
--- a/src/test/fixtures/bondings.yml
+++ b/src/test/fixtures/bondings.yml
@@ -1,11 +1,17 @@
 mailservers_managed_node_bonding:
     name: Production Network
-    interface_name: bond0
+    interface_name: mailbonding0
     bonding_type_id: <%= Fixtures.identify(:link_aggregation_bonding_type) %>
     host_id: <%= Fixtures.identify(:mailservers_managed_node) %>
-    boot_type_id: <%= Fixtures.identify(:boot_type_static) %>
+    boot_type_id: <%= Fixtures.identify(:boot_type_static_ip) %>
     ip_addr: 172.31.0.15
     netmask: 255.255.255.
     broadcast: 172.31.0.255
     arp_ping_address: 172.31.0.100
     arp_interval: 0
+
+mediaserver_managed_node_bonding:
+    name: Fileserver Network
+    interface_name: mediabonding0
+    bonding_type_id: <%= Fixtures.identify(:link_aggregation_bonding_type) %>
+    host_id: <%= Fixtures.identify(:mediaserver_managed_node) %>
diff --git a/src/test/fixtures/bondings_nics.yml b/src/test/fixtures/bondings_nics.yml
index 11a3d1a..607ff8b 100644
--- a/src/test/fixtures/bondings_nics.yml
+++ b/src/test/fixtures/bondings_nics.yml
@@ -5,3 +5,11 @@ mailservers_managed_node_bonding_nic_1:
 mailservers_managed_node_bonding_nic_2:
     bonding_id: <%= Fixtures.identify(:mailservers_managed_node_bonding) %>
     nic_id: <%= Fixtures.identify(:mailserver_nic_two) %>
+
+mediaservers_managed_node_bonding_nic_1:
+    bonding_id: <%= Fixtures.identify(:mediaserver_managed_node_bonding) %>
+    nic_id: <%= Fixtures.identify(:mediaserver_nic_one) %>
+
+mediaservers_managed_node_bonding_nic_2:
+    bonding_id: <%= Fixtures.identify(:mediaserver_managed_node_bonding) %>
+    nic_id: <%= Fixtures.identify(:mediaserver_nic_two) %>
diff --git a/src/test/fixtures/hosts.yml b/src/test/fixtures/hosts.yml
index 5b8af15..28282c2 100644
--- a/src/test/fixtures/hosts.yml
+++ b/src/test/fixtures/hosts.yml
@@ -125,3 +125,13 @@ buildserver_managed_node:
     is_disabled: 0
     hypervisor_type: 'kvm'
     hardware_pool_id: <%= Fixtures.identify(:prodops_pool) %>
+
+mediaserver_managed_node:
+    uuid: '6293acd9-2784-11dc-9387-001558c41534'
+    hostname: 'build.mynetwork.com'
+    arch: 'x86_64'
+    memory: 65536
+    is_disabled: 0
+    hypervisor_type: 'kvm'
+    hardware_pool_id: <%= Fixtures.identify(:prodops_pool) %>
+
diff --git a/src/test/fixtures/nics.yml b/src/test/fixtures/nics.yml
index ccf71d2..5b2cecc 100644
--- a/src/test/fixtures/nics.yml
+++ b/src/test/fixtures/nics.yml
@@ -78,3 +78,17 @@ buildserver_nic_two:
     broadcast: '172.31.0.255'
     host_id: <%= Fixtures.identify(:buildserver_managed_node) %>
     boot_type_id: <%= Fixtures.identify(:boot_type_static_ip) %>
+
+mediaserver_nic_one:
+    mac: '07:17:19:65:03:32'
+    usage_type: '1'
+    bandwidth: 100
+    host_id: <%= Fixtures.identify(:mediaserver_managed_node) %>
+    boot_type_id: <%= Fixtures.identify(:boot_type_dhcp) %>
+
+mediaserver_nic_two:
+    mac: '07:17:19:65:03:31'
+    usage_type: '1'
+    bandwidth: 100
+    host_id: <%= Fixtures.identify(:mediaserver_managed_node) %>
+    boot_type_id: <%= Fixtures.identify(:boot_type_dhcp) %>
diff --git a/src/test/functional/managed_node_configuration_test.rb b/src/test/functional/managed_node_configuration_test.rb
index d0d8aa3..14c9736 100644
--- a/src/test/functional/managed_node_configuration_test.rb
+++ b/src/test/functional/managed_node_configuration_test.rb
@@ -36,6 +36,7 @@ class ManagedNodeConfigurationTest < Test::Unit::TestCase
     @host_with_ip_address = hosts(:ldapserver_managed_node)
     @host_with_multiple_nics = hosts(:buildserver_managed_node)
     @host_with_bondings = hosts(:mailservers_managed_node)
+    @host_with_dhcp_bondings = hosts(:mediaserver_managed_node)
   end
 
   # Ensures that network interfaces uses DHCP when no IP address is specified.
@@ -44,23 +45,9 @@ class ManagedNodeConfigurationTest < Test::Unit::TestCase
     nic = @host_with_dhcp_card.nics.first
 
     expected = <<-HERE
-#!/bin/bash
 # THIS FILE IS GENERATED!
-cat <<\EOF > /var/tmp/node-augtool
-rm /files/etc/sysconfig/network-scripts/ifcfg-eth0
-set /files/etc/sysconfig/network-scripts/ifcfg-eth0/DEVICE eth0
-set /files/etc/sysconfig/network-scripts/ifcfg-eth0/BOOTPROTO #{nic.boot_type.proto}
-set /files/etc/sysconfig/network-scripts/ifcfg-eth0/BRIDGE ovirtbr0
-set /files/etc/sysconfig/network-scripts/ifcfg-eth0/ONBOOT yes
-rm /files/etc/sysconfig/network-scripts/ifcfg-ovirtbr0
-set /files/etc/sysconfig/network-scripts/ifcfg-ovirtbr0/DEVICE ovirtbr0
-set /files/etc/sysconfig/network-scripts/ifcfg-ovirtbr0/BOOTPROTO #{nic.boot_type.proto}
-set /files/etc/sysconfig/network-scripts/ifcfg-ovirtbr0/TYPE bridge
-set /files/etc/sysconfig/network-scripts/ifcfg-ovirtbr0/PEERNTP yes
-set /files/etc/sysconfig/network-scripts/ifcfg-ovirtbr0/DELAY 0
-set /files/etc/sysconfig/network-scripts/ifcfg-ovirtbr0/ONBOOT yes
-save
-EOF
+ifcfg=#{nic.mac}|eth0|BOOTPROTO=dhcp|BRIDGE=ovirtbr0|ONBOOT=yes
+ifcfg=#{nic.mac}|ovirtbr0|BOOTPROTO=dhcp|TYPE=bridge|ONBOOT=yes
     HERE
 
     result = ManagedNodeConfiguration.generate(
@@ -77,29 +64,9 @@ EOF
     nic = @host_with_ip_address.nics.first
 
     expected = <<-HERE
-#!/bin/bash
 # THIS FILE IS GENERATED!
-cat <<\EOF > /var/tmp/node-augtool
-rm /files/etc/sysconfig/network-scripts/ifcfg-eth0
-set /files/etc/sysconfig/network-scripts/ifcfg-eth0/DEVICE eth0
-set /files/etc/sysconfig/network-scripts/ifcfg-eth0/BOOTPROTO #{nic.boot_type.proto}
-set /files/etc/sysconfig/network-scripts/ifcfg-eth0/IPADDR #{nic.ip_addr}
-set /files/etc/sysconfig/network-scripts/ifcfg-eth0/NETMASK #{nic.netmask}
-set /files/etc/sysconfig/network-scripts/ifcfg-eth0/BROADCAST #{nic.broadcast}
-set /files/etc/sysconfig/network-scripts/ifcfg-eth0/BRIDGE ovirtbr0
-set /files/etc/sysconfig/network-scripts/ifcfg-eth0/ONBOOT yes
-rm /files/etc/sysconfig/network-scripts/ifcfg-ovirtbr0
-set /files/etc/sysconfig/network-scripts/ifcfg-ovirtbr0/DEVICE ovirtbr0
-set /files/etc/sysconfig/network-scripts/ifcfg-ovirtbr0/BOOTPROTO #{nic.boot_type.proto}
-set /files/etc/sysconfig/network-scripts/ifcfg-ovirtbr0/IPADDR #{nic.ip_addr}
-set /files/etc/sysconfig/network-scripts/ifcfg-ovirtbr0/NETMASK #{nic.netmask}
-set /files/etc/sysconfig/network-scripts/ifcfg-ovirtbr0/BROADCAST #{nic.broadcast}
-set /files/etc/sysconfig/network-scripts/ifcfg-ovirtbr0/TYPE bridge
-set /files/etc/sysconfig/network-scripts/ifcfg-ovirtbr0/PEERNTP yes
-set /files/etc/sysconfig/network-scripts/ifcfg-ovirtbr0/DELAY 0
-set /files/etc/sysconfig/network-scripts/ifcfg-ovirtbr0/ONBOOT yes
-save
-EOF
+ifcfg=#{nic.mac}|eth0|BOOTPROTO=#{nic.boot_type.proto}|IPADDR=#{nic.ip_addr}|NETMASK=#{nic.netmask}|BROADCAST=#{nic.broadcast}|BRIDGE=#{nic.bridge}|ONBOOT=yes
+ifcfg=#{nic.mac}|ovirtbr0|BOOTPROTO=#{nic.boot_type.proto}|IPADDR=#{nic.ip_addr}|NETMASK=|BROADCAST=#{nic.netmask}|TYPE=bridge|ONBOOT=yes
     HERE
 
     result = ManagedNodeConfiguration.generate(
@@ -117,34 +84,10 @@ EOF
     nic2 = @host_with_multiple_nics.nics[1]
 
     expected = <<-HERE
-#!/bin/bash
 # THIS FILE IS GENERATED!
-cat <<\EOF > /var/tmp/node-augtool
-rm /files/etc/sysconfig/network-scripts/ifcfg-eth0
-set /files/etc/sysconfig/network-scripts/ifcfg-eth0/DEVICE eth0
-set /files/etc/sysconfig/network-scripts/ifcfg-eth0/BOOTPROTO #{nic1.boot_type.proto}
-set /files/etc/sysconfig/network-scripts/ifcfg-eth0/IPADDR #{nic1.ip_addr}
-set /files/etc/sysconfig/network-scripts/ifcfg-eth0/NETMASK #{nic1.netmask}
-set /files/etc/sysconfig/network-scripts/ifcfg-eth0/BROADCAST #{nic1.broadcast}
-set /files/etc/sysconfig/network-scripts/ifcfg-eth0/BRIDGE ovirtbr0
-set /files/etc/sysconfig/network-scripts/ifcfg-eth0/ONBOOT yes
-rm /files/etc/sysconfig/network-scripts/ifcfg-ovirtbr0
-set /files/etc/sysconfig/network-scripts/ifcfg-ovirtbr0/DEVICE ovirtbr0
-set /files/etc/sysconfig/network-scripts/ifcfg-ovirtbr0/BOOTPROTO #{nic1.boot_type.proto}
-set /files/etc/sysconfig/network-scripts/ifcfg-ovirtbr0/IPADDR #{nic1.ip_addr}
-set /files/etc/sysconfig/network-scripts/ifcfg-ovirtbr0/NETMASK #{nic1.netmask}
-set /files/etc/sysconfig/network-scripts/ifcfg-ovirtbr0/BROADCAST #{nic1.broadcast}
-set /files/etc/sysconfig/network-scripts/ifcfg-ovirtbr0/TYPE bridge
-set /files/etc/sysconfig/network-scripts/ifcfg-ovirtbr0/PEERNTP yes
-set /files/etc/sysconfig/network-scripts/ifcfg-ovirtbr0/DELAY 0
-set /files/etc/sysconfig/network-scripts/ifcfg-ovirtbr0/ONBOOT yes
-rm /files/etc/sysconfig/network-scripts/ifcfg-eth1
-set /files/etc/sysconfig/network-scripts/ifcfg-eth1/DEVICE eth1
-set /files/etc/sysconfig/network-scripts/ifcfg-eth1/BOOTPROTO #{nic2.boot_type.proto}
-set /files/etc/sysconfig/network-scripts/ifcfg-eth1/BRIDGE ovirtbr0
-set /files/etc/sysconfig/network-scripts/ifcfg-eth1/ONBOOT yes
-save
-EOF
+ifcfg=#{nic1.mac}|eth0|BOOTPROTO=#{nic1.boot_type.proto}|IPADDR=#{nic1.ip_addr}|NETMASK=#{nic1.netmask}|BROADCAST=#{nic1.broadcast}|BRIDGE=ovirtbr0|ONBOOT=yes
+ifcfg=#{nic1.mac}|ovirtbr0|BOOTPROTO=#{nic1.boot_type.proto}|IPADDR=#{nic1.ip_addr}|NETMASK=#{nic1.netmask}|BROADCAST=#{nic1.broadcast}|TYPE=bridge|ONBOOT=yes
+ifcfg=#{nic2.mac}|eth1|BOOTPROTO=#{nic2.boot_type.proto}|BRIDGE=ovirtbr0|ONBOOT=yes
     HERE
 
     result = ManagedNodeConfiguration.generate(
@@ -167,30 +110,11 @@ EOF
     nic2 = bonding.nics[1]
 
     expected = <<-HERE
-#!/bin/bash
 # THIS FILE IS GENERATED!
-cat <<\EOF > /var/tmp/pre-config-script
-#!/bin/bash
-# THIS FILE IS GENERATED!
-/sbin/modprobe bonding mode=#{bonding.bonding_type.mode}
-EOF
-cat <<\EOF > /var/tmp/node-augtool
-rm /files/etc/sysconfig/network-scripts/ifcfg-#{bonding.interface_name}
-set /files/etc/sysconfig/network-scripts/ifcfg-#{bonding.interface_name}/DEVICE #{bonding.interface_name}
-set /files/etc/sysconfig/network-scripts/ifcfg-#{bonding.interface_name}/IPADDR 172.31.0.15
-set /files/etc/sysconfig/network-scripts/ifcfg-#{bonding.interface_name}/ONBOOT yes
-rm /files/etc/sysconfig/network-scripts/ifcfg-eth0
-set /files/etc/sysconfig/network-scripts/ifcfg-eth0/DEVICE eth0
-set /files/etc/sysconfig/network-scripts/ifcfg-eth0/MASTER #{bonding.interface_name}
-set /files/etc/sysconfig/network-scripts/ifcfg-eth0/SLAVE yes
-set /files/etc/sysconfig/network-scripts/ifcfg-eth0/ONBOOT yes
-rm /files/etc/sysconfig/network-scripts/ifcfg-eth1
-set /files/etc/sysconfig/network-scripts/ifcfg-eth1/DEVICE eth1
-set /files/etc/sysconfig/network-scripts/ifcfg-eth1/MASTER #{bonding.interface_name}
-set /files/etc/sysconfig/network-scripts/ifcfg-eth1/SLAVE yes
-set /files/etc/sysconfig/network-scripts/ifcfg-eth1/ONBOOT yes
-save
-EOF
+bonding=#{bonding.interface_name}
+ifcfg=none|#{bonding.interface_name}|BONDING_OPTS="mode=#{bonding.bonding_type.mode} miimon=100"|BOOTPROTO=static|IPADDR=#{bonding.ip_addr}|NETMASK=#{bonding.netmask}|BROADCAST=#{bonding.broadcast}|ONBOOT=yes
+ifcfg=#{nic1.mac}|eth0|MASTER=#{bonding.interface_name}|SLAVE=yes|ONBOOT=yes
+ifcfg=#{nic2.mac}|eth1|MASTER=#{bonding.interface_name}|SLAVE=yes|ONBOOT=yes
 HERE
 
     result = ManagedNodeConfiguration.generate(
@@ -203,4 +127,31 @@ HERE
     assert_equal expected, result
   end
 
+  # Ensures that the generated bonding supports DHCP boot protocol.
+  #
+  def test_generate_with_dhcp_bonding
+    bonding = @host_with_dhcp_bondings.bondings.first
+
+    bonding.ip_addr=nil
+    nic1 = bonding.nics[0]
+    nic2 = bonding.nics[1]
+
+    expected = <<-HERE
+# THIS FILE IS GENERATED!
+bonding=#{bonding.interface_name}
+ifcfg=none|#{bonding.interface_name}|BONDING_OPTS="mode=#{bonding.bonding_type.mode} miimon=100"|BOOTPROTO=dhcp|ONBOOT=yes
+ifcfg=#{nic1.mac}|eth0|MASTER=#{bonding.interface_name}|SLAVE=yes|ONBOOT=yes
+ifcfg=#{nic2.mac}|eth1|MASTER=#{bonding.interface_name}|SLAVE=yes|ONBOOT=yes
+HERE
+
+    result = ManagedNodeConfiguration.generate(
+      @host_with_dhcp_bondings,
+      {
+        "#{nic1.mac}" => 'eth0',
+        "#{nic2.mac}" => 'eth1'
+      })
+
+    assert_equal expected, result
+  end
+
 end
-- 
1.5.5.1




More information about the ovirt-devel mailing list