[Ovirt-devel] [PATCH server] network related fixes to tests and backend components
Mohammed Morsi
mmorsi at redhat.com
Mon Nov 3 18:21:25 UTC 2008
---
src/host-browser/host-browser.rb | 19 ++--
src/lib/managed_node_configuration.rb | 14 ++-
src/test/fixtures/bondings.yml | 4 -
src/test/fixtures/ip_addresses.yml | 61 +++++++++++
src/test/fixtures/networks.yml | 33 ++++++
src/test/fixtures/nics.yml | 108 +++++++++-----------
src/test/fixtures/usages.yml | 7 ++
.../functional/managed_node_configuration_test.rb | 14 ++--
src/test/functional/network_controller_test.rb | 8 ++
src/test/functional/nic_controller_test.rb | 2 +-
src/test/unit/bonding_test.rb | 11 +--
src/test/unit/ip_address_test.rb | 8 ++
src/test/unit/ip_v4_address_test.rb | 106 +++++++++++++++++++
src/test/unit/ip_v6_address_test.rb | 85 +++++++++++++++
src/test/unit/network_test.rb | 8 ++
src/test/unit/nic_test.rb | 1 +
src/test/unit/usage_test.rb | 8 ++
17 files changed, 402 insertions(+), 95 deletions(-)
create mode 100644 src/test/fixtures/ip_addresses.yml
create mode 100644 src/test/fixtures/networks.yml
create mode 100644 src/test/fixtures/usages.yml
create mode 100644 src/test/functional/network_controller_test.rb
create mode 100644 src/test/unit/ip_address_test.rb
create mode 100644 src/test/unit/ip_v4_address_test.rb
create mode 100644 src/test/unit/ip_v6_address_test.rb
create mode 100644 src/test/unit/network_test.rb
create mode 100644 src/test/unit/usage_test.rb
diff --git a/src/host-browser/host-browser.rb b/src/host-browser/host-browser.rb
index 79d34e8..52d2999 100755
--- a/src/host-browser/host-browser.rb
+++ b/src/host-browser/host-browser.rb
@@ -264,6 +264,13 @@ class HostBrowser
host.cpus << detail
end
+ # Create a new network for the host
+ boot_type = BootType.find_by_proto('dhcp')
+ network_name = (host.uuid ? host.uuid : "") + ' Physical Network'
+ network = PhysicalNetwork.create(
+ :name => network_name,
+ :boot_type_id => boot_type.id)
+
# Update the NIC details for this host:
# -if the NIC exists, then update the IP address
# -if the NIC does not exist, create it
@@ -284,9 +291,6 @@ class HostBrowser
updated_nic = Nic.find_by_id(nic.id)
updated_nic.bandwidth = detail['BANDWIDTH']
- updated_nic.ip_addr = detail['IP_ADDRESS']
- updated_nic.netmask = detail['NETMASK']
- updated_nic.broadcast = detail['BROADCAST']
updated_nic.save!
found=true
@@ -302,18 +306,13 @@ class HostBrowser
end
# iterate over any nics left and create new records for them.
- boot_type = BootType.find_by_proto('dhcp')
-
nic_info.collect do |nic|
puts "Creating a new nic..."
detail = Nic.new(
'mac' => nic['MAC'].upcase,
'bandwidth' => nic['BANDWIDTH'],
- 'usage_type' => 1,
- 'ip_addr' => nic['IP_ADDRESS'],
- 'netmask' => nic['NETMASK'],
- 'broadcast' => nic['BROADCAST'],
- 'boot_type_id' => boot_type.id)
+ 'usage_type' => 1)
+ detail.physical_network = network
host.nics << detail
end
diff --git a/src/lib/managed_node_configuration.rb b/src/lib/managed_node_configuration.rb
index 101be9f..7cd2839 100644
--- a/src/lib/managed_node_configuration.rb
+++ b/src/lib/managed_node_configuration.rb
@@ -67,10 +67,11 @@ class ManagedNodeConfiguration
host.bondings.each do |bonding|
entry = "ifcfg=none|#{bonding.interface_name}|BONDING_OPTS=\"mode=#{bonding.bonding_type.mode} miimon=100\""
- if bonding.ip_addr == nil || bonding.ip_addr.empty?
+ if bonding.ip_addresses.empty?
entry += "|BOOTPROTO=dhcp"
else
- entry += "|BOOTPROTO=static|IPADDR=#{bonding.ip_addr}|NETMASK=#{bonding.netmask}|BROADCAST=#{bonding.broadcast}"
+ ip = bonding.ip_addresses[0]
+ entry += "|BOOTPROTO=static|IPADDR=#{ip.address}|NETMASK=#{ip.netmask}|BROADCAST=#{ip.broadcast}"
end
result.puts "#{entry}|ONBOOT=yes"
@@ -84,7 +85,7 @@ class ManagedNodeConfiguration
host.nics.each do |nic|
# only process this nic if it doesn't have a bonding
# TODO remove the hack to force a bridge into the picture
- if nic.bonding.empty?
+ if nic.bondings.empty?
process_nic result, nic, macs, nil, false, true
# TODO remove this when bridges are properly supported
@@ -110,8 +111,11 @@ class ManagedNodeConfiguration
if bonding
entry += "|MASTER=#{bonding.interface_name}|SLAVE=yes"
else
- entry += "|BOOTPROTO=#{nic.boot_type.proto}"
- entry += "|IPADDR=#{nic.ip_addr}|NETMASK=#{nic.netmask}|BROADCAST=#{nic.broadcast}" if nic.boot_type.proto == 'static'
+ entry += "|BOOTPROTO=#{nic.physical_network.boot_type.proto}"
+ if nic.physical_network.boot_type.proto == 'static'
+ ip = nic.ip_addresses[0]
+ entry += "|IPADDR=#{ip.address}|NETMASK=#{ip.netmask}|BROADCAST=#{ip.broadcast}"
+ end
entry += "|BRIDGE=#{nic.bridge}" if nic.bridge && !is_bridge
entry += "|BRIDGE=ovirtbr0" if !nic.bridge && !is_bridge
entry += "|TYPE=bridge" if is_bridge
diff --git a/src/test/fixtures/bondings.yml b/src/test/fixtures/bondings.yml
index 227b92b..3c793f6 100644
--- a/src/test/fixtures/bondings.yml
+++ b/src/test/fixtures/bondings.yml
@@ -3,10 +3,6 @@ mailservers_managed_node_bonding:
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_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
diff --git a/src/test/fixtures/ip_addresses.yml b/src/test/fixtures/ip_addresses.yml
new file mode 100644
index 0000000..aed3811
--- /dev/null
+++ b/src/test/fixtures/ip_addresses.yml
@@ -0,0 +1,61 @@
+ip_v4_one:
+ nic_id: <%= Fixtures.identify(:nic_one) %>
+ type: IpV4Address
+ address: 1.2.3.4
+ netmask: 255.255.255.0
+ gateway: 1.2.3.1
+ broadcast: 1.2.3.255
+
+ip_v4_two:
+ nic_id: <%= Fixtures.identify(:nic_two) %>
+ type: IpV4Address
+ address: 2.3.4.5
+ netmask: 255.255.255.0
+ gateway: 1.2.3.1
+ broadcast: 2.3.4.255
+
+ip_v4_three:
+ nic_id: <%= Fixtures.identify(:nic_three) %>
+ type: IpV4Address
+ address: 3.4.5.6
+ netmask: 255.255.255.0
+ gateway: 3.4.5.1
+ broadcast: 3.4.5.255
+
+ip_v4_four:
+ nic_id: <%= Fixtures.identify(:nic_four) %>
+ type: IpV4Address
+ address: 3.4.5.6
+ netmask: 255.255.255.0
+ gateway: 3.4.5.1
+ broadcast: 3.4.5.255
+
+ip_v4_mailserver_nic_one:
+ nic_id: <%= Fixtures.identify(:mailserver_nic_one) %>
+ type: IpV4Address
+ address: 172.31.0.15
+ netmask: 255.255.255.0
+ gateway: 172.31.0.1
+ broadcast: 172.31.0.255
+
+ip_v4_ldapserver_nic_one:
+ nic_id: <%= Fixtures.identify(:ldapserver_nic_one) %>
+ type: IpV4Address
+ address: 172.31.0.25
+ gateway: 172.31.0.1
+
+ip_v4_buildserver_nic_one:
+ nic_id: <%= Fixtures.identify(:buildserver_nic_two) %>
+ type: IpV4Address
+ address: 172.31.0.31
+ netmask: 255.255.255.0
+ gateway: 172.31.0.1
+ broadcast: 172.31.0.255
+
+ip_v4_mailservers_managed_node_bonding:
+ bonding_id: <%= Fixtures.identify(:mailservers_managed_node_bonding) %>
+ type: IpV4Address
+ address: 192.168.50.100
+ netmask: 255.255.255.0
+ gateway: 192.168.50.1
+ broadcast: 192.168.50.255
diff --git a/src/test/fixtures/networks.yml b/src/test/fixtures/networks.yml
new file mode 100644
index 0000000..cb50c0c
--- /dev/null
+++ b/src/test/fixtures/networks.yml
@@ -0,0 +1,33 @@
+static_vlan_one:
+ type: 'Vlan'
+ name: 'Static Vlan 1'
+ boot_type_id: <%= Fixtures.identify(:boot_type_static_ip) %>
+ number: 1
+
+dhcp_vlan_one:
+ type: 'Vlan'
+ name: 'DHCP Vlan 1'
+ boot_type_id: <%= Fixtures.identify(:boot_type_dhcp) %>
+ number: 2
+
+bootp_vlan_one:
+ type: 'Vlan'
+ name: 'BOOTP Vlan 1'
+ boot_type_id: <%= Fixtures.identify(:boot_type_bootp) %>
+ number: 3
+
+static_physical_network_one:
+ type: 'PhysicalNetwork'
+ name: 'Static Physical Network 1'
+ boot_type_id: <%= Fixtures.identify(:boot_type_static_ip) %>
+
+dhcp_physical_network_one:
+ type: 'PhysicalNetwork'
+ name: 'DHCP Physical Network 1'
+ boot_type_id: <%= Fixtures.identify(:boot_type_dhcp) %>
+
+bootp_physical_network_one:
+ type: 'PhysicalNetwork'
+ name: 'BOOTP Physical Network 1'
+ boot_type_id: <%= Fixtures.identify(:boot_type_bootp) %>
+
diff --git a/src/test/fixtures/nics.yml b/src/test/fixtures/nics.yml
index 5b2cecc..7f65ef6 100644
--- a/src/test/fixtures/nics.yml
+++ b/src/test/fixtures/nics.yml
@@ -1,94 +1,84 @@
-one:
+nic_one:
id: 1
mac: '00:11:22:33:44:55'
- ip_addr: '1.2.3.4'
- usage_type: '1'
bandwidth: 100
host_id: 10
- boot_type_id: <%= Fixtures.identify(:boot_type_static_ip) %>
-two:
+ physical_network_id: <%= Fixtures.identify(:dhcp_physical_network_one) %>
+nic_two:
id: 2
mac: 'AA:BB:CC:DD:EE:FF'
- ip_addr: '2.3.4.5'
usage_type: '2'
bandwidth: 1000
host_id: 10
- boot_type_id: <%= Fixtures.identify(:boot_type_static_ip) %>
-three:
+ physical_network_id: <%= Fixtures.identify(:dhcp_physical_network_one) %>
+nic_three:
id: 3
mac: '00:FF:11:EE:22:DD'
- ip_addr: '3.4.5.6'
usage_type: '1'
bandwidth: 10
host_id: 10
- boot_type_id: <%= Fixtures.identify(:boot_type_static_ip) %>
-four:
+ physical_network_id: <%= Fixtures.identify(:dhcp_physical_network_one) %>
+nic_four:
id: 4
mac: '00:FF:11:EE:22:DD'
- ip_addr: '3.4.5.6'
usage_type: '1'
bandwidth: 10
host_id: 10
- boot_type_id: <%= Fixtures.identify(:boot_type_static_ip) %>
+ physical_network_id: <%= Fixtures.identify(:dhcp_physical_network_one) %>
mailserver_nic_one:
- mac: '00:11:22:33:44:55'
- usage_type: '1'
- bandwidth: 100
- ip_addr: '172.31.0.15'
- host_id: <%= Fixtures.identify(:mailservers_managed_node) %>
- boot_type_id: <%= Fixtures.identify(:boot_type_static_ip) %>
+ mac: '00:11:22:33:44:55'
+ usage_type: '1'
+ bandwidth: 100
+ host_id: <%= Fixtures.identify(:mailservers_managed_node) %>
+ physical_network_id: <%= Fixtures.identify(:dhcp_physical_network_one) %>
mailserver_nic_two:
- mac: '22:11:33:66:44:55'
- usage_type: '1'
- bandwidth: 100
- host_id: <%= Fixtures.identify(:mailservers_managed_node) %>
- boot_type_id: <%= Fixtures.identify(:boot_type_dhcp) %>
+ mac: '22:11:33:66:44:55'
+ usage_type: '1'
+ bandwidth: 100
+ host_id: <%= Fixtures.identify(:mailservers_managed_node) %>
+ physical_network_id: <%= Fixtures.identify(:dhcp_physical_network_one) %>
fileserver_nic_one:
- mac: '00:99:00:99:13:07'
- usage_type: '1'
- bandwidth: 100
- host_id: <%= Fixtures.identify(:fileserver_managed_node) %>
- boot_type_id: <%= Fixtures.identify(:boot_type_dhcp) %>
+ mac: '00:99:00:99:13:07'
+ usage_type: '1'
+ bandwidth: 100
+ host_id: <%= Fixtures.identify(:fileserver_managed_node) %>
+ physical_network_id: <%= Fixtures.identify(:dhcp_physical_network_one) %>
ldapserver_nic_one:
- mac: '00:03:02:00:09:06'
- usage_type: '1'
- bandwidth: 100
- bridge: 'ovirtbr0'
- ip_addr: '172.31.0.25'
- host_id: <%= Fixtures.identify(:ldapserver_managed_node) %>
- boot_type_id: <%= Fixtures.identify(:boot_type_static_ip) %>
+ mac: '00:03:02:00:09:06'
+ usage_type: '1'
+ bandwidth: 100
+ bridge: 'ovirtbr0'
+ host_id: <%= Fixtures.identify(:ldapserver_managed_node) %>
+ physical_network_id: <%= Fixtures.identify(:static_physical_network_one) %>
buildserver_nic_one:
- mac: '07:17:19:65:03:38'
- usage_type: '1'
- bandwidth: 100
- host_id: <%= Fixtures.identify(:buildserver_managed_node) %>
- boot_type_id: <%= Fixtures.identify(:boot_type_dhcp) %>
+ mac: '07:17:19:65:03:38'
+ usage_type: '1'
+ bandwidth: 100
+ host_id: <%= Fixtures.identify(:buildserver_managed_node) %>
+ physical_network_id: <%= Fixtures.identify(:dhcp_physical_network_one) %>
buildserver_nic_two:
- mac: '07:17:19:65:03:39'
- usage_type: '1'
- bandwidth: 100
- ip_addr: '172.31.0.31'
- netmask: '255.255.255.0'
- broadcast: '172.31.0.255'
- host_id: <%= Fixtures.identify(:buildserver_managed_node) %>
- boot_type_id: <%= Fixtures.identify(:boot_type_static_ip) %>
+ mac: '07:17:19:65:03:39'
+ usage_type: '1'
+ bandwidth: 100
+ host_id: <%= Fixtures.identify(:buildserver_managed_node) %>
+ physical_network_id: <%= Fixtures.identify(:static_physical_network_one) %>
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) %>
+ mac: '07:17:19:65:03:32'
+ usage_type: '1'
+ bandwidth: 100
+ host_id: <%= Fixtures.identify(:mediaserver_managed_node) %>
+ physical_network_id: <%= Fixtures.identify(:dhcp_physical_network_one) %>
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) %>
+ mac: '07:17:19:65:03:31'
+ usage_type: '1'
+ bandwidth: 100
+ host_id: <%= Fixtures.identify(:mediaserver_managed_node) %>
+ physical_network_id: <%= Fixtures.identify(:dhcp_physical_network_one) %>
diff --git a/src/test/fixtures/usages.yml b/src/test/fixtures/usages.yml
new file mode 100644
index 0000000..5bf0293
--- /dev/null
+++ b/src/test/fixtures/usages.yml
@@ -0,0 +1,7 @@
+# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
+
+# one:
+# column: value
+#
+# two:
+# column: value
diff --git a/src/test/functional/managed_node_configuration_test.rb b/src/test/functional/managed_node_configuration_test.rb
index 14c9736..b614502 100644
--- a/src/test/functional/managed_node_configuration_test.rb
+++ b/src/test/functional/managed_node_configuration_test.rb
@@ -30,6 +30,7 @@ class ManagedNodeConfigurationTest < Test::Unit::TestCase
fixtures :boot_types
fixtures :hosts
fixtures :nics
+ fixtures :networks
def setup
@host_with_dhcp_card = hosts(:fileserver_managed_node)
@@ -65,8 +66,8 @@ ifcfg=#{nic.mac}|ovirtbr0|BOOTPROTO=dhcp|TYPE=bridge|ONBOOT=yes
expected = <<-HERE
# THIS FILE IS GENERATED!
-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
+ifcfg=#{nic.mac}|eth0|BOOTPROTO=#{nic.physical_network.boot_type.proto}|IPADDR=#{nic.ip_addresses.first.address}|NETMASK=#{nic.ip_addresses.first.netmask}|BROADCAST=#{nic.ip_addresses.first.broadcast}|BRIDGE=#{nic.bridge}|ONBOOT=yes
+ifcfg=#{nic.mac}|ovirtbr0|BOOTPROTO=#{nic.physical_network.boot_type.proto}|IPADDR=#{nic.ip_addresses.first.address}|NETMASK=|BROADCAST=#{nic.ip_addresses.first.netmask}|TYPE=bridge|ONBOOT=yes
HERE
result = ManagedNodeConfiguration.generate(
@@ -85,9 +86,9 @@ ifcfg=#{nic.mac}|ovirtbr0|BOOTPROTO=#{nic.boot_type.proto}|IPADDR=#{nic.ip_addr}
expected = <<-HERE
# THIS FILE IS GENERATED!
-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
+ifcfg=#{nic1.mac}|eth0|BOOTPROTO=#{nic1.physical_network.boot_type.proto}|IPADDR=#{nic1.ip_addresses.first.address}|NETMASK=#{nic1.ip_addresses.first.netmask}|BROADCAST=#{nic1.ip_addresses.first.broadcast}|BRIDGE=ovirtbr0|ONBOOT=yes
+ifcfg=#{nic1.mac}|ovirtbr0|BOOTPROTO=#{nic1.physical_network.boot_type.proto}|IPADDR=#{nic1.ip_addresses.first.address}|NETMASK=#{nic1.ip_addresses.first.netmask}|BROADCAST=#{nic1.ip_addresses.first.broadcast}|TYPE=bridge|ONBOOT=yes
+ifcfg=#{nic2.mac}|eth1|BOOTPROTO=#{nic2.physical_network.boot_type.proto}|BRIDGE=ovirtbr0|ONBOOT=yes
HERE
result = ManagedNodeConfiguration.generate(
@@ -112,7 +113,7 @@ ifcfg=#{nic2.mac}|eth1|BOOTPROTO=#{nic2.boot_type.proto}|BRIDGE=ovirtbr0|ONBOOT=
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=static|IPADDR=#{bonding.ip_addr}|NETMASK=#{bonding.netmask}|BROADCAST=#{bonding.broadcast}|ONBOOT=yes
+ifcfg=none|#{bonding.interface_name}|BONDING_OPTS="mode=#{bonding.bonding_type.mode} miimon=100"|BOOTPROTO=static|IPADDR=#{bonding.ip_addresses.first.address}|NETMASK=#{bonding.ip_addresses.first.netmask}|BROADCAST=#{bonding.ip_addresses.first.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
@@ -132,7 +133,6 @@ HERE
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]
diff --git a/src/test/functional/network_controller_test.rb b/src/test/functional/network_controller_test.rb
new file mode 100644
index 0000000..8ca4094
--- /dev/null
+++ b/src/test/functional/network_controller_test.rb
@@ -0,0 +1,8 @@
+require 'test_helper'
+
+class NetworkControllerTest < ActionController::TestCase
+ # Replace this with your real tests.
+ def test_truth
+ assert true
+ end
+end
diff --git a/src/test/functional/nic_controller_test.rb b/src/test/functional/nic_controller_test.rb
index 4ae1f8d..3405c80 100644
--- a/src/test/functional/nic_controller_test.rb
+++ b/src/test/functional/nic_controller_test.rb
@@ -31,7 +31,7 @@ class NicControllerTest < Test::Unit::TestCase
@request = ActionController::TestRequest.new
@response = ActionController::TestResponse.new
- @first_id = nics(:one).id
+ @first_id = nics(:nic_one).id
end
def test_show
diff --git a/src/test/unit/bonding_test.rb b/src/test/unit/bonding_test.rb
index fbcb138..3df46da 100644
--- a/src/test/unit/bonding_test.rb
+++ b/src/test/unit/bonding_test.rb
@@ -26,13 +26,14 @@ class BondingTest < ActiveSupport::TestCase
fixtures :boot_types
fixtures :hosts
fixtures :nics
+ fixtures :networks
def setup
@bonding = Bonding.new(
:name => 'Bonding1',
:interface_name => 'bond0',
+ :vlan_id => networks(:dhcp_vlan_one),
:bonding_type_id => bonding_types(:failover_bonding_type),
- :boot_type_id => boot_types(:boot_type_dhcp),
:host_id => hosts(:mailservers_managed_node))
end
@@ -52,14 +53,6 @@ class BondingTest < ActiveSupport::TestCase
flunk 'Bondings have to have an interface name.' if @bonding.valid?
end
- # Ensures that the bonding requires a boot type.
- #
- def test_valid_fails_without_boot_type
- @bonding.boot_type_id = nil
-
- flunk 'Bondings have to have a boot type.' if @bonding.valid?
- end
-
# Ensures that the bonding type is required.
#
def test_valid_fails_without_type
diff --git a/src/test/unit/ip_address_test.rb b/src/test/unit/ip_address_test.rb
new file mode 100644
index 0000000..152578e
--- /dev/null
+++ b/src/test/unit/ip_address_test.rb
@@ -0,0 +1,8 @@
+require 'test_helper'
+
+class IpAddressTest < ActiveSupport::TestCase
+ # Replace this with your real tests.
+ def test_truth
+ assert true
+ end
+end
diff --git a/src/test/unit/ip_v4_address_test.rb b/src/test/unit/ip_v4_address_test.rb
new file mode 100644
index 0000000..65a08d3
--- /dev/null
+++ b/src/test/unit/ip_v4_address_test.rb
@@ -0,0 +1,106 @@
+#
+# 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.
+
+require File.dirname(__FILE__) + '/../test_helper'
+
+class IpV4AddressTest < ActiveSupport::TestCase
+ def setup
+ @address = IpV4Address.new(:address => '192.168.50.2',
+ :netmask => '255.255.255.0',
+ :gateway => '192.168.50.1',
+ :broadcast => '192.168.50.255')
+ end
+
+ # Ensures that an address must be supplied.
+ #
+ def test_valid_fails_without_address
+ @address.address = nil
+
+ flunk "An address must be present." if @address.valid?
+ end
+
+ # Ensures that an address has to be in the correct format.
+ #
+ def test_valid_fails_with_bad_address
+ @address.address = '192.168'
+
+ flunk "An address must be in the format ##.##.##.##." if @address.valid?
+ end
+
+ # Ensures that a netmask must be supplied.
+ #
+ def test_valid_fails_without_netmask
+ @address.network_id = 1
+ @address.netmask = nil
+
+ flunk "An address must have a netmask." if @address.valid?
+ end
+
+ # Ensures that a netmask must have the correct format.
+ #
+ def test_valid_fails_with_bad_netmask
+ @address.network_id = 1
+ @address.netmask = 'farkle'
+
+ flunk "A netmask must be in the format ##.##.##.##." if @address.valid?
+ end
+
+ # Ensures that a gateway must be supplied.
+ #
+ def test_valid_fails_without_gateway
+ @address.network_id = 1
+ @address.gateway = nil
+
+ flunk "A gateway address must be supplied." if @address.valid?
+ end
+
+ # Ensures that a gateway must be in the correct format.
+ #
+ def test_valid_fails_with_bad_gateway
+ @address.network_id = 1
+ @address.gateway = '-3.a2.0.8'
+
+
+ flunk "The gateway address must be in the format ##.##.##.##." if @address.valid?
+ end
+
+ # Ensures that a broadcast must be supplied.
+ #
+ def test_valid_fails_without_broadcast
+ @address.network_id = 1
+ @address.broadcast = nil
+
+ flunk "A broadcast addres must be supplied." if @address.valid?
+ end
+
+ # Ensures that a broadcast must be in the correct format.
+ #
+ def test_valid_fails_with_bad_broadcast
+ @address.network_id = 1
+ @address.broadcast = '-3.2.0.8'
+
+ flunk "The broadcast address must be in the format ##.##.##.##." if @address.valid?
+ end
+
+ # Ensures that a well-formed address is valid.
+ #
+ def test_valid
+ flunk "There is an error with validation." unless @address.valid?
+ end
+end
diff --git a/src/test/unit/ip_v6_address_test.rb b/src/test/unit/ip_v6_address_test.rb
new file mode 100644
index 0000000..070f407
--- /dev/null
+++ b/src/test/unit/ip_v6_address_test.rb
@@ -0,0 +1,85 @@
+#
+# 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.
+
+require File.dirname(__FILE__) + '/../test_helper'
+
+class IpV6AddressTest < ActiveSupport::TestCase
+ def setup
+ @address = IpV6Address.new(:address => 'fe80:0:0:0:200:f8ff:fe21:67cf',
+ :gateway => ':::::::717',
+ :prefix => '0000:0000:0000:0000:1234:1234:1234:1234')
+ end
+
+ # Ensures that the address must be provided.
+ #
+ def test_valid_fails_without_address
+ @address.address = nil
+ flunk "An address must be provided." if @address.valid?
+ end
+
+ # Ensures that the address must be in the correct format.
+ #
+ def test_valid_fails_with_bad_address
+ @address.address = "farkle"
+
+ flunk "The address must be in the correct format." if @address.valid?
+ end
+
+ # Ensures that the gateway must be provided.
+ #
+ def test_valid_fails_without_gateway
+ @address.network_id = 1
+ @address.gateway = nil
+
+ flunk "The gateway address must be provided." if @address.valid?
+ end
+
+ # Ensures that the gateway address is in the correct format.
+ #
+ def test_valid_fails_with_bad_gateway
+ @address.network_id = 1
+ @address.gateway = '0-:::::::717'
+
+ flunk "The gateway address must be in the correct format." if @address.valid?
+ end
+
+ # Ensures that the prefix must be provided.
+ #
+ def test_valid_fails_without_prefix
+ @address.network_id = 1
+ @address.prefix = nil
+
+ flunk "The prefix must be provided." if @address.valid?
+ end
+
+ # Ensures that the prefix is in the correct format.
+ #
+ def test_valid_fails_with_invalid_prefix
+ @address.network_id = 1
+ @address.prefix = 'whoops'
+
+ flunk "The prefix must be in the correct format." if @address.valid?
+ end
+
+ # Ensures that a well-formed address is considered valid.
+ #
+ def test_valid
+ flunk "There is an problem with address validation." unless @address.valid?
+ end
+end
diff --git a/src/test/unit/network_test.rb b/src/test/unit/network_test.rb
new file mode 100644
index 0000000..64c5df4
--- /dev/null
+++ b/src/test/unit/network_test.rb
@@ -0,0 +1,8 @@
+require 'test_helper'
+
+class NetworkTest < ActiveSupport::TestCase
+ # Replace this with your real tests.
+ def test_truth
+ assert true
+ end
+end
diff --git a/src/test/unit/nic_test.rb b/src/test/unit/nic_test.rb
index a0776a2..1de1e00 100644
--- a/src/test/unit/nic_test.rb
+++ b/src/test/unit/nic_test.rb
@@ -20,6 +20,7 @@
require File.dirname(__FILE__) + '/../test_helper'
class NicTest < Test::Unit::TestCase
+ fixtures :ip_addresses
fixtures :nics
# Replace this with your real tests.
diff --git a/src/test/unit/usage_test.rb b/src/test/unit/usage_test.rb
new file mode 100644
index 0000000..9a8ec9b
--- /dev/null
+++ b/src/test/unit/usage_test.rb
@@ -0,0 +1,8 @@
+require 'test_helper'
+
+class UsageTest < ActiveSupport::TestCase
+ # Replace this with your real tests.
+ def test_truth
+ assert true
+ end
+end
--
1.5.6.5
More information about the ovirt-devel
mailing list