[Ovirt-devel] [PATCH server] permit many-to-many vms / networks relationship (test changes)
Mohammed Morsi
mmorsi at redhat.com
Thu Jul 9 21:56:28 UTC 2009
implements changes to the tests to test newly
added / modified features
---
src/test/fixtures/nics.yml | 16 +++---
src/test/fixtures/vms.yml | 8 ---
src/test/unit/network_test.rb | 69 ++++++++++++++++++++++++++++--
src/test/unit/nic_test.rb | 95 ++++++++++++++++++++++++++++++++++++++++-
src/test/unit/vm_test.rb | 14 +++---
5 files changed, 173 insertions(+), 29 deletions(-)
diff --git a/src/test/fixtures/nics.yml b/src/test/fixtures/nics.yml
index 97397cd..aff7e9b 100644
--- a/src/test/fixtures/nics.yml
+++ b/src/test/fixtures/nics.yml
@@ -3,21 +3,21 @@ mailserver_nic_one:
usage_type: 1
bandwidth: 100
host: mailservers_managed_node
- physical_network: mail_network_one
+ network: mail_network_one
mailserver_nic_two:
mac: 22:11:33:66:44:55
usage_type: 1
bandwidth: 100
host: mailservers_managed_node
- physical_network: mail_network_two
+ network: mail_network_two
fileserver_nic_one:
mac: 00:99:00:99:13:07
usage_type: 1
bandwidth: 100
host: fileserver_managed_node
- physical_network: fileserver_network
+ network: fileserver_network
ldapserver_nic_one:
mac: 00:03:02:00:09:06
@@ -25,32 +25,32 @@ ldapserver_nic_one:
bandwidth: 100
bridge:
host: ldapserver_managed_node
- physical_network: static_physical_network_one
+ network: static_physical_network_one
buildserver_nic_one:
mac: 07:17:19:65:03:38
usage_type: 1
bandwidth: 100
host: buildserver_managed_node
- physical_network: dhcp_physical_network_one
+ network: dhcp_physical_network_one
buildserver_nic_two:
mac: 07:17:19:65:03:39
usage_type: 1
bandwidth: 100
host: buildserver_managed_node
- physical_network: static_physical_network_one
+ network: static_physical_network_one
mediaserver_nic_one:
mac: 07:17:19:65:03:32
usage_type: 1
bandwidth: 100
host: mediaserver_managed_node
- physical_network: mediaserver_network_one
+ network: mediaserver_network_one
mediaserver_nic_two:
mac: 07:17:19:65:03:31
usage_type: 1
bandwidth: 100
host: mediaserver_managed_node
- physical_network: mediaserver_network_two
+ network: mediaserver_network_two
diff --git a/src/test/fixtures/vms.yml b/src/test/fixtures/vms.yml
index b2711b2..4b07e32 100644
--- a/src/test/fixtures/vms.yml
+++ b/src/test/fixtures/vms.yml
@@ -5,7 +5,6 @@ production_httpd_vm:
num_vcpus_used: 2
memory_allocated: 262144
memory_used: 131072
- vnic_mac_addr: 23:51:90:A1:13:37
state: stopped
needs_restart: 0
boot_device: hd
@@ -20,7 +19,6 @@ production_mysqld_vm:
num_vcpus_used: 1
memory_allocated: 2048
memory_used: 512
- vnic_mac_addr: 15:99:FE:ED:11:EE
state: running
needs_restart: 0
boot_device: network
@@ -33,7 +31,6 @@ production_ftpd_vm:
num_vcpus_used: 1
memory_allocated: 1024
memory_used: 512
- vnic_mac_addr: FF:AA:BB:00:11:55
state: stopped
needs_restart: 1
boot_device: cdrom
@@ -46,7 +43,6 @@ production_postgresql_vm:
num_vcpus_used: 2
memory_allocated: 2048
memory_used: 1536
- vnic_mac_addr: 48:24:12:93:42:11
state: running
needs_restart: 0
boot_device: hd
@@ -59,7 +55,6 @@ foobar_prod1_vm:
num_vcpus_used: 2
memory_allocated: 4096
memory_used: 4096
- vnic_mac_addr: FF:FF:FF:EE:EE:EE
state: running
needs_restart: 0
boot_device: cdrom
@@ -85,7 +80,6 @@ foobar_prod2_vm:
num_vcpus_used: 2
memory_allocated: 4096
memory_used: 4096
- vnic_mac_addr: EE:EE:EE:FF:FF:FF
state: running
needs_restart: 0
boot_device: cdrom
@@ -98,7 +92,6 @@ corp_com_errata_vm:
num_vcpus_used: 2
memory_allocated: 2048
memory_used: 2048
- vnic_mac_addr: 77:77:77:77:77:77
state: running
needs_restart: 0
boot_device: network
@@ -111,7 +104,6 @@ corp_com_bugzilla_vm:
num_vcpus_used: 2
memory_allocated: 2048
memory_used: 2048
- vnic_mac_addr: 77:77:77:77:77:77
state: running
needs_restart: 0
boot_device: network
diff --git a/src/test/unit/network_test.rb b/src/test/unit/network_test.rb
index 64c5df4..9b75e8b 100644
--- a/src/test/unit/network_test.rb
+++ b/src/test/unit/network_test.rb
@@ -1,8 +1,69 @@
-require 'test_helper'
+# Copyright (C) 2008 Red Hat, Inc.
+# Written by Mohammed Morsi <mmorsi 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 NetworkTest < ActiveSupport::TestCase
- # Replace this with your real tests.
- def test_truth
- assert true
+ fixtures :networks
+ fixtures :vms
+ fixtures :hosts
+ fixtures :nics
+ fixtures :boot_types
+
+ def setup
+ end
+
+ def test_vlan_invalid_without_number
+ vl = Vlan.new({:name => 'testvlan', :boot_type_id => 2})
+ flunk "Vlan without number should not be valid" if vl.valid?
+ vl.number = 1
+ flunk "Vlan with number should be valid" unless vl.valid?
+ end
+
+ def test_vlan_nics_only_associated_with_vm
+ vl = Vlan.create({:name => 'testvlan',
+ :boot_type => boot_types(:boot_type_dhcp),
+ :number => 1}) # need to create for id
+ nic = Nic.new({:mac => '11:22:33:44:55:66',
+ :bandwidth => 100,
+ :network => vl,
+ :host => hosts(:prod_corp_com)})
+ vl.nics.push nic
+ flunk "Nic assigned to vlan must only be associated with vm" if vl.valid?
+ nic.host = nil
+ nic.vm = vms(:production_httpd_vm)
+ flunk "Vlan consisting of only vm nics should be valid" unless vl.valid?
+ end
+
+ def test_physical_network_is_destroyable
+ pn = PhysicalNetwork.new
+ flunk "PhysicalNetwork with no nics should be destroyable" unless pn.is_destroyable?
+ pn.nics.push Nic.new
+ flunk "PhysicalNetwork with nics should not be destroyable" if pn.is_destroyable?
+ end
+
+ def test_vlan_is_destroyable
+ vl = Vlan.new
+ flunk "Vlan with no nics and bondings should be destroyable" unless vl.is_destroyable?
+ vl.nics.push Nic.new
+ flunk "Vlan with nics should not be destroyable" if vl.is_destroyable?
+ vl.nics.clear
+ vl.bondings.push Bonding.new
+ flunk "Vlan with bondings should not be destroyable" if vl.is_destroyable?
end
end
diff --git a/src/test/unit/nic_test.rb b/src/test/unit/nic_test.rb
index 07f54c6..b6bdb07 100644
--- a/src/test/unit/nic_test.rb
+++ b/src/test/unit/nic_test.rb
@@ -24,6 +24,7 @@ class NicTest < Test::Unit::TestCase
fixtures :nics
fixtures :hosts
fixtures :networks
+ fixtures :vms
def setup
@nic = Nic.new(
@@ -31,7 +32,7 @@ class NicTest < Test::Unit::TestCase
:usage_type => 1,
:bandwidth => 100 )
@nic.host = hosts(:prod_corp_com)
- @nic.physical_network = networks(:static_physical_network_one)
+ @nic.network = networks(:static_physical_network_one)
@ip_address = IpV4Address.new(
:address => '1.2.3.4',
@@ -74,10 +75,100 @@ class NicTest < Test::Unit::TestCase
end
def test_static_network_nic_must_have_ip
- @nic.physical_network = networks(:static_physical_network_one)
+ @nic.network = networks(:static_physical_network_one)
@nic.ip_addresses.delete_if { true }
flunk 'Nics assigned to static networks must have at least one ip' if @nic.valid?
end
+ def test_vm_nic_must_have_network
+ @nic.host = nil
+ @nic.vm = vms(:production_httpd_vm)
+ flunk 'vm nic that is assigned to network is valid' unless @nic.valid?
+
+ @nic.network = nil
+ flunk 'vm nic without a network is not valid' if @nic.valid?
+ end
+
+ def test_host_nic_cant_be_assigned_to_vlan
+ @nic.network = networks(:dhcp_vlan_one)
+ flunk 'host nic cant be assgined to vlan' if @nic.valid?
+ end
+
+ def test_nic_networking
+ flunk 'nic.networking? should return true if assigned to network' unless @nic.networking?
+ @nic.network = nil
+ flunk 'nic.networking? should return false if not assigned to network' if @nic.networking?
+ end
+
+ def test_nic_boot_protocol
+ nic = Nic.new
+ nic.ip_addresses << @ip_address
+ nic.network = networks(:static_physical_network_one)
+ flunk 'incorrect nic boot protocol' unless nic.boot_protocol == 'static'
+ end
+
+ def test_nic_ip_addresses
+ nic = Nic.new
+ nic.ip_addresses << @ip_address
+ nic.network = networks(:static_physical_network_one)
+ flunk 'incorrect nic ip address' unless nic.ip_address == @ip_address.address
+ end
+
+ def test_nic_netmask
+ nic = Nic.new
+ network = Network.new
+ network.ip_addresses << @ip_address
+ nic.network = network
+
+ flunk 'incorrect nic netmask' unless nic.netmask == @ip_address.netmask
+ end
+
+
+ def test_nic_broadcast
+ nic = Nic.new
+ network = Network.new
+ network.ip_addresses << @ip_address
+ nic.network = network
+
+ flunk 'incorrect nic broadcast' unless nic.broadcast == @ip_address.broadcast
+ end
+
+ def test_nic_gateway
+ nic = Nic.new
+ network = Network.new
+ network.ip_addresses << @ip_address
+ nic.network = network
+
+ flunk 'incorrect nic gateway' unless nic.gateway == @ip_address.gateway
+ end
+
+ def test_nic_parent
+ flunk 'incorrect host nic parent' unless @nic.parent == hosts(:prod_corp_com)
+
+ @nic.host = nil
+ flunk 'incorrect nic parent' unless @nic.parent == nil
+
+ @nic.vm = vms(:production_httpd_vm)
+ flunk 'incorrect vm nic parent' unless @nic.parent == vms(:production_httpd_vm)
+ end
+
+ def test_nic_gen_mac
+ mac = Nic::gen_mac
+ flunk 'invalid generated mac' unless mac =~ /^([0-9a-fA-F]{2}([:-]|$)){6}$/
+ end
+
+ def test_nic_vm_xor_nic_host
+ flunk 'host nic without vm is valid' unless @nic.valid?
+
+ @nic.vm = vms(:production_httpd_vm)
+ flunk 'nic cannot specify both host and vm' if @nic.valid?
+
+ @nic.host = nil
+ flunk 'vm nic without host is valid' unless @nic.valid?
+
+ @nic.vm = nil
+ flunk 'nic must specify either host or vm' if @nic.valid?
+ end
+
end
diff --git a/src/test/unit/vm_test.rb b/src/test/unit/vm_test.rb
index a5d6b3d..80071c7 100644
--- a/src/test/unit/vm_test.rb
+++ b/src/test/unit/vm_test.rb
@@ -38,8 +38,8 @@ class VmTest < ActiveSupport::TestCase
:num_vcpus_allocated => 1,
:boot_device => 'hd',
:memory_allocated_in_mb => 1,
- :memory_allocated => 1024,
- :vnic_mac_addr => '11:22:33:44:55:66')
+ :memory_allocated => 1024)
+
@vm.vm_resource_pool = pools(:corp_com_production_vmpool)
end
@@ -76,11 +76,6 @@ class VmTest < ActiveSupport::TestCase
flunk 'Vm must specify memory_allocated_in_mb' if @vm.valid?
end
- def test_valid_fails_without_vnic_mac_addr
- @vm.vnic_mac_addr = ''
- flunk 'Vm must specify vnic_mac_addr' if @vm.valid?
- end
-
def test_valid_fails_without_vm_resources_pool_id
@vm.vm_resource_pool_id = ''
flunk 'Vm must specify vm_resources_pool_id' if @vm.valid?
@@ -195,4 +190,9 @@ class VmTest < ActiveSupport::TestCase
def test_paginated_results
assert_equal 5, Vm.paged_with_perms('ovirtadmin', Privilege::VIEW, 1, 'vms.id').size
end
+
+ def test_vm_gen_uuid
+ uuid = Vm::gen_uuid
+ flunk 'invalid generated uuid' unless uuid =~ /[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}/
+ end
end
--
1.6.0.6
More information about the ovirt-devel
mailing list