Darryl L. Pierce
2008-Oct-06 17:39 UTC
[Ovirt-devel] [PATCH server] Replaced the config scripts with configuration encoding.
*** NOTE *** This patch is a request for comments. I'm looking for some feedback on the encoding strategy I'm using below. The goal is to get away from using embedded scripts and to instead just describe the desired state to the node. *** NOTE *** 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 "kmod" describes a kernel module that needs to be loaded. It will containing the module's name, an optional alias for the module, and then the module options if such are required. 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. Signed-off-by: Darryl L. Pierce <dpierce at redhat.com> --- src/app/models/bonding.rb | 1 + src/lib/managed_node_configuration.rb | 72 +++++++++------ src/test/fixtures/bondings.yml | 8 ++- 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 | 94 ++++++++------------ 7 files changed, 118 insertions(+), 89 deletions(-) diff --git a/src/app/models/bonding.rb b/src/app/models/bonding.rb index 941e2cd..7bef2f8 100644 --- a/src/app/models/bonding.rb +++ b/src/app/models/bonding.rb @@ -38,6 +38,7 @@ class Bonding < ActiveRecord::Base belongs_to :host belongs_to :bonding_type + belongs_to :boot_type has_and_belongs_to_many :nics, :join_table => 'bondings_nics', diff --git a/src/lib/managed_node_configuration.rb b/src/lib/managed_node_configuration.rb index 4ade235..7a1ceac 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: +# +# kmod=[module name]|[module alias]|[module options] +# +# 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: +# +# kmod=bonding|failover0|mode=2 miimon=100 downdelay=200 +# +# 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 "kmod=bonding|#{bonding.interface_name}|mode=#{bonding.bonding_type.mode} miimon=100 downdelay=200" 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}" + + 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 @@ -66,9 +87,6 @@ class ManagedNodeConfiguration end end - result.puts "save" - result.puts "EOF" - result.string end @@ -78,24 +96,18 @@ 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 + 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 end - - result.puts "set #{NIC_ENTRY_PREFIX}/ifcfg-#{iface_name}/BRIDGE #{nic.bridge}" if nic.bridge - 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 c2a47b5..7023e08 100644 --- a/src/test/fixtures/bondings.yml +++ b/src/test/fixtures/bondings.yml @@ -1,6 +1,6 @@ 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) %> ip_addr: 172.31.0.15 @@ -8,3 +8,9 @@ mailservers_managed_node_bonding: 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 b5a7ec5..0cad09b 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,15 +45,8 @@ 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/ONBOOT yes -save -EOF +ifcfg=#{nic.mac}|eth0|BOOTPROTO=dhcp|ONBOOT=yes HERE result = ManagedNodeConfiguration.generate( @@ -69,19 +63,8 @@ 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 -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 HERE result = ManagedNodeConfiguration.generate( @@ -99,22 +82,9 @@ 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/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/ONBOOT yes -save -EOF +ifcfg=#{nic1.mac}|eth0|BOOTPROTO=#{nic1.boot_type.proto}|IPADDR=#{nic1.ip_addr}|NETMASK=#{nic1.netmask}|BROADCAST=#{nic1.broadcast}|ONBOOT=yes +ifcfg=#{nic2.mac}|eth1|BOOTPROTO=#{nic2.boot_type.proto}|ONBOOT=yes HERE result = ManagedNodeConfiguration.generate( @@ -137,30 +107,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 +kmod=bonding|#{bonding.interface_name}|mode=#{bonding.bonding_type.mode} miimon=100 downdelay=200 +ifcfg=none|#{bonding.interface_name}|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( @@ -173,4 +124,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! +kmod=bonding|#{bonding.interface_name}|mode=#{bonding.bonding_type.mode} miimon=100 downdelay=200 +ifcfg=none|#{bonding.interface_name}|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
Chris Lalancette
2008-Oct-08 11:51 UTC
[Ovirt-devel] [PATCH server] Replaced the config scripts with configuration encoding.
Darryl L. Pierce wrote:> *** NOTE *** > This patch is a request for comments. I'm looking for some feedback on the encoding > strategy I'm using below. The goal is to get away from using embedded scripts and to > instead just describe the desired state to the node. > *** NOTE *** > > 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 "kmod" describes a kernel module that > needs to be loaded. It will containing the module's name, an > optional alias for the module, and then the module options > if such are required. > > 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 is definitely a step in the right direction. I'm still a tiny bit concerned about using the generic "kmod", as opposed to just "bonding"; the former gives us more flexibility, but still leaves a security hole for loading any random kernel module. The latter means that we have to implement something different for every new thing we want to support, but that's not necessarily a bad thing. So instead of: kmod=[module name]|[module alias]|[module options] I think I would rather see: bonding=alias|options For the ifcfg, that looks fine to me, as long as the number of delimited fields is unlimited, and all of the additional field would be put in the ifcfg- script. That is, this is perfectly valid: ifcfg=00:11:22:33:44|eth0|BOOTPROTO=dhcp|bridge=ovirtbr0|ONBOOT=yes but so is: ifcfg=00:11:22:33:44|eth0|BOOTPROTO=dhcp|bridge=ovirtbr0|ONBOOT=yes|DELAY=0 Chris Lalancette
Darryl L. Pierce
2008-Oct-08 19:04 UTC
[Ovirt-devel] [PATCH server] Replaced the config scripts with configuration encoding.
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 "kmod" describes a kernel module that needs to be loaded. It will containing the module's name, an optional alias for the module, and then the module options if such are required. 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. Signed-off-by: Darryl L. Pierce <dpierce at redhat.com> --- src/app/models/bonding.rb | 1 + src/lib/managed_node_configuration.rb | 72 +++++++++------ src/test/fixtures/bondings.yml | 8 ++- 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 | 94 ++++++++------------ 7 files changed, 118 insertions(+), 89 deletions(-) diff --git a/src/app/models/bonding.rb b/src/app/models/bonding.rb index 941e2cd..7bef2f8 100644 --- a/src/app/models/bonding.rb +++ b/src/app/models/bonding.rb @@ -38,6 +38,7 @@ class Bonding < ActiveRecord::Base belongs_to :host belongs_to :bonding_type + belongs_to :boot_type has_and_belongs_to_many :nics, :join_table => 'bondings_nics', diff --git a/src/lib/managed_node_configuration.rb b/src/lib/managed_node_configuration.rb index 4ade235..8c8892b 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: +# +# kmod=[module name]|[module alias]|[module options] +# +# 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: +# +# kmod=bonding|failover0|mode=2 miimon=100 downdelay=200 +# +# 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}|mode=#{bonding.bonding_type.mode} miimon=100 downdelay=200" 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}" + + 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 @@ -66,9 +87,6 @@ class ManagedNodeConfiguration end end - result.puts "save" - result.puts "EOF" - result.string end @@ -78,24 +96,18 @@ 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 + 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 end - - result.puts "set #{NIC_ENTRY_PREFIX}/ifcfg-#{iface_name}/BRIDGE #{nic.bridge}" if nic.bridge - 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 c2a47b5..7023e08 100644 --- a/src/test/fixtures/bondings.yml +++ b/src/test/fixtures/bondings.yml @@ -1,6 +1,6 @@ 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) %> ip_addr: 172.31.0.15 @@ -8,3 +8,9 @@ mailservers_managed_node_bonding: 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 b5a7ec5..fd2139e 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,15 +45,8 @@ 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/ONBOOT yes -save -EOF +ifcfg=#{nic.mac}|eth0|BOOTPROTO=dhcp|ONBOOT=yes HERE result = ManagedNodeConfiguration.generate( @@ -69,19 +63,8 @@ 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 -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 HERE result = ManagedNodeConfiguration.generate( @@ -99,22 +82,9 @@ 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/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/ONBOOT yes -save -EOF +ifcfg=#{nic1.mac}|eth0|BOOTPROTO=#{nic1.boot_type.proto}|IPADDR=#{nic1.ip_addr}|NETMASK=#{nic1.netmask}|BROADCAST=#{nic1.broadcast}|ONBOOT=yes +ifcfg=#{nic2.mac}|eth1|BOOTPROTO=#{nic2.boot_type.proto}|ONBOOT=yes HERE result = ManagedNodeConfiguration.generate( @@ -137,30 +107,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}|mode=#{bonding.bonding_type.mode} miimon=100 downdelay=200 +ifcfg=none|#{bonding.interface_name}|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( @@ -173,4 +124,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}|mode=#{bonding.bonding_type.mode} miimon=100 downdelay=200 +ifcfg=none|#{bonding.interface_name}|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
Daniel P. Berrange
2008-Oct-08 20:05 UTC
[Ovirt-devel] [PATCH server] Replaced the config scripts with configuration encoding.
On Mon, Oct 06, 2008 at 01:39:33PM -0400, Darryl L. Pierce wrote:> *** NOTE *** > This patch is a request for comments. I'm looking for some feedback on the encoding > strategy I'm using below. The goal is to get away from using embedded scripts and to > instead just describe the desired state to the node. > *** NOTE ***> +# +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: > +# > +# kmod=[module name]|[module alias]|[module options] > +# > +# 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: > +# > +# kmod=bonding|failover0|mode=2 miimon=100 downdelay=200There shouldn't be any need for configuration keyed off the module. As per the other mail i send, the only thing in modprobe.conf should be an 'alias bond0 bonding'. Everything else is NIC device config.> +# 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.> +kmod=bonding|#{bonding.interface_name}|mode=#{bonding.bonding_type.mode} miimon=100 downdelay=200 > +ifcfg=none|#{bonding.interface_name}|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=yesSo, in this exampe, move those kmod= bonding options into the ifcfg= line that follows. Daniel -- |: Red Hat, Engineering, London -o- http://people.redhat.com/berrange/ :| |: http://libvirt.org -o- http://virt-manager.org -o- http://ovirt.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|
Darryl L. Pierce
2008-Oct-08 21:14 UTC
[Ovirt-devel] [PATCH server] Replaced the config scripts with configuration encoding.
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 "kmod" describes a kernel module that needs to be loaded. It will containing the module's name, an optional alias for the module, and then the module options if such are required. 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. Signed-off-by: Darryl L. Pierce <dpierce at redhat.com> --- src/app/models/bonding.rb | 1 + src/lib/managed_node_configuration.rb | 72 +++++++++------ src/test/fixtures/bondings.yml | 8 ++- 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 | 94 ++++++++------------ 7 files changed, 118 insertions(+), 89 deletions(-) diff --git a/src/app/models/bonding.rb b/src/app/models/bonding.rb index 941e2cd..7bef2f8 100644 --- a/src/app/models/bonding.rb +++ b/src/app/models/bonding.rb @@ -38,6 +38,7 @@ class Bonding < ActiveRecord::Base belongs_to :host belongs_to :bonding_type + belongs_to :boot_type has_and_belongs_to_many :nics, :join_table => 'bondings_nics', diff --git a/src/lib/managed_node_configuration.rb b/src/lib/managed_node_configuration.rb index 4ade235..fc33560 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: +# +# kmod=[module name]|[module alias]|[module options] +# +# 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: +# +# kmod=bonding|failover0|mode=2 miimon=100 downdelay=200 +# +# 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 @@ -66,9 +87,6 @@ class ManagedNodeConfiguration end end - result.puts "save" - result.puts "EOF" - result.string end @@ -78,24 +96,18 @@ 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 + 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 end - - result.puts "set #{NIC_ENTRY_PREFIX}/ifcfg-#{iface_name}/BRIDGE #{nic.bridge}" if nic.bridge - 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 c2a47b5..7023e08 100644 --- a/src/test/fixtures/bondings.yml +++ b/src/test/fixtures/bondings.yml @@ -1,6 +1,6 @@ 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) %> ip_addr: 172.31.0.15 @@ -8,3 +8,9 @@ mailservers_managed_node_bonding: 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 b5a7ec5..e5b9c18 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,15 +45,8 @@ 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/ONBOOT yes -save -EOF +ifcfg=#{nic.mac}|eth0|BOOTPROTO=dhcp|ONBOOT=yes HERE result = ManagedNodeConfiguration.generate( @@ -69,19 +63,8 @@ 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 -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 HERE result = ManagedNodeConfiguration.generate( @@ -99,22 +82,9 @@ 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/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/ONBOOT yes -save -EOF +ifcfg=#{nic1.mac}|eth0|BOOTPROTO=#{nic1.boot_type.proto}|IPADDR=#{nic1.ip_addr}|NETMASK=#{nic1.netmask}|BROADCAST=#{nic1.broadcast}|ONBOOT=yes +ifcfg=#{nic2.mac}|eth1|BOOTPROTO=#{nic2.boot_type.proto}|ONBOOT=yes HERE result = ManagedNodeConfiguration.generate( @@ -137,30 +107,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( @@ -173,4 +124,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
Darryl L. Pierce
2008-Oct-14 15:38 UTC
[Ovirt-devel] [PATCH server] Replaced the config scripts with configuration encoding.
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 "kmod" describes a kernel module that needs to be loaded. It will containing the module's name, an optional alias for the module, and then the module options if such are required. 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. Signed-off-by: Darryl L. Pierce <dpierce at redhat.com> --- src/app/models/bonding.rb | 1 + src/lib/managed_node_configuration.rb | 72 +++++++++------ src/test/fixtures/bondings.yml | 8 ++- 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 | 94 ++++++++------------ 7 files changed, 118 insertions(+), 89 deletions(-) diff --git a/src/app/models/bonding.rb b/src/app/models/bonding.rb index 4b6e8a5..859df31 100644 --- a/src/app/models/bonding.rb +++ b/src/app/models/bonding.rb @@ -44,6 +44,7 @@ class Bonding < ActiveRecord::Base belongs_to :host belongs_to :bonding_type + belongs_to :boot_type has_and_belongs_to_many :nics, :join_table => 'bondings_nics', diff --git a/src/lib/managed_node_configuration.rb b/src/lib/managed_node_configuration.rb index 4ade235..fc33560 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: +# +# kmod=[module name]|[module alias]|[module options] +# +# 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: +# +# kmod=bonding|failover0|mode=2 miimon=100 downdelay=200 +# +# 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 @@ -66,9 +87,6 @@ class ManagedNodeConfiguration end end - result.puts "save" - result.puts "EOF" - result.string end @@ -78,24 +96,18 @@ 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 + 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 end - - result.puts "set #{NIC_ENTRY_PREFIX}/ifcfg-#{iface_name}/BRIDGE #{nic.bridge}" if nic.bridge - 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 c2a47b5..7023e08 100644 --- a/src/test/fixtures/bondings.yml +++ b/src/test/fixtures/bondings.yml @@ -1,6 +1,6 @@ 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) %> ip_addr: 172.31.0.15 @@ -8,3 +8,9 @@ mailservers_managed_node_bonding: 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 b5a7ec5..e5b9c18 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,15 +45,8 @@ 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/ONBOOT yes -save -EOF +ifcfg=#{nic.mac}|eth0|BOOTPROTO=dhcp|ONBOOT=yes HERE result = ManagedNodeConfiguration.generate( @@ -69,19 +63,8 @@ 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 -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 HERE result = ManagedNodeConfiguration.generate( @@ -99,22 +82,9 @@ 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/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/ONBOOT yes -save -EOF +ifcfg=#{nic1.mac}|eth0|BOOTPROTO=#{nic1.boot_type.proto}|IPADDR=#{nic1.ip_addr}|NETMASK=#{nic1.netmask}|BROADCAST=#{nic1.broadcast}|ONBOOT=yes +ifcfg=#{nic2.mac}|eth1|BOOTPROTO=#{nic2.boot_type.proto}|ONBOOT=yes HERE result = ManagedNodeConfiguration.generate( @@ -137,30 +107,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( @@ -173,4 +124,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
Darryl L. Pierce
2008-Oct-20 18:05 UTC
[Ovirt-devel] [PATCH server] Replaced the config scripts with configuration encoding.
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 "kmod" describes a kernel module that needs to be loaded. It will containing the module's name, an optional alias for the module, and then the module options if such are required. 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. Signed-off-by: Darryl L. Pierce <dpierce at redhat.com> --- 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
Darryl L. Pierce
2008-Oct-20 18:25 UTC
[Ovirt-devel] [PATCH server] Replaced the config scripts with configuration encoding.
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 bondingfile 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