Mohammed Morsi
2008-Dec-15 10:21 UTC
[Ovirt-devel] [PATCH server] test suite updates and fixes for new validation components
note, this patch requires the last validation patch to be applied to work included are a few updates to the main server app and many updates to the test suite to fix a few various bits and assert all the new validations recently added. --- src/app/models/bonding.rb | 4 +- src/app/models/nic.rb | 4 +- src/app/models/storage_volume.rb | 2 +- src/app/models/vm.rb | 2 +- src/test/fixtures/help_sections.yml | 14 +++-- src/test/fixtures/storage_pools.yml | 7 ++ src/test/fixtures/usages.yml | 12 ++-- src/test/unit/bonding_test.rb | 35 ++++++++++ src/test/unit/boot_type_test.rb | 36 +++++++++- src/test/unit/cpu_test.rb | 95 ++++++++++++++++++++++++++- src/test/unit/help_section_test.rb | 51 +++++++++++++- src/test/unit/host_browser_identify_test.rb | 8 +- src/test/unit/host_test.rb | 60 ++++++++++++++++- src/test/unit/ip_address_test.rb | 5 ++ src/test/unit/ip_v4_address_test.rb | 3 +- src/test/unit/ip_v6_address_test.rb | 3 +- src/test/unit/nic_test.rb | 58 +++++++++++++++- src/test/unit/permission_test.rb | 28 ++++++++ src/test/unit/pool_test.rb | 21 ++++++ src/test/unit/quota_test.rb | 37 ++++++++++- src/test/unit/storage_pool_test.rb | 45 +++++++++++++ src/test/unit/storage_volume_test.rb | 86 ++++++++++++++++++++++++ src/test/unit/task_test.rb | 14 ++++ src/test/unit/usage_test.rb | 47 ++++++++++++- src/test/unit/vm_test.rb | 64 ++++++++++++++++++ 25 files changed, 697 insertions(+), 44 deletions(-) diff --git a/src/app/models/bonding.rb b/src/app/models/bonding.rb index fabdb67..660dcd0 100644 --- a/src/app/models/bonding.rb +++ b/src/app/models/bonding.rb @@ -71,7 +71,9 @@ class Bonding < ActiveRecord::Base protected def validate - if vlan.boot_type.proto == 'static' and ip_addresses.size == 0 + if ! vlan.nil? and + vlan.boot_type.proto == 'static' and + ip_addresses.size == 0 errors.add("vlan_id", "is static. Must create at least one static ip") end diff --git a/src/app/models/nic.rb b/src/app/models/nic.rb index aa9c740..029b4e4 100644 --- a/src/app/models/nic.rb +++ b/src/app/models/nic.rb @@ -43,7 +43,9 @@ class Nic < ActiveRecord::Base protected def validate - if physical_network.boot_type.proto == 'static' and ip_addresses.size == 0 + if ! physical_network.nil? and + physical_network.boot_type.proto == 'static' and + ip_addresses.size == 0 errors.add("physical_network_id", "is static. Must create at least one static ip") end diff --git a/src/app/models/storage_volume.rb b/src/app/models/storage_volume.rb index 0f490f8..385c126 100644 --- a/src/app/models/storage_volume.rb +++ b/src/app/models/storage_volume.rb @@ -146,7 +146,7 @@ class StorageVolume < ActiveRecord::Base def movable? if vms.size > 0 or - (! lvm_storage_pool.nil? and ! lvm_storage_pool.movable?) + (not lvm_storage_pool.nil? and not lvm_stoage_pool.movable?) return false end return true diff --git a/src/app/models/vm.rb b/src/app/models/vm.rb index 4d66c63..bf99e2d 100644 --- a/src/app/models/vm.rb +++ b/src/app/models/vm.rb @@ -341,7 +341,7 @@ class Vm < ActiveRecord::Base # FIXME: what should memory min/max be? errors.add("memory_allocated_in_mb", "must be at least 256 MB") unless not(memory_allocated_in_mb) or memory_allocated_in_mb >=256 # FIXME: what should cpu min/max - errors.add("num_vcpus_allocated", "must be between 1 and 16") unless (num_vcpus_allocated >=1 and num_vcpus_allocated <= 16) + errors.add("num_vcpus_allocated", "must be between 1 and 16") unless (num_vcpus_allocated.nil? or (num_vcpus_allocated >=1 and num_vcpus_allocated <= 16)) errors.add("memory_allocated_in_mb", "violates quota") unless not(memory_allocated) or resources[:memory].nil? or memory_allocated <= resources[:memory] errors.add("num_vcpus_allocated", "violates quota") unless not(num_vcpus_allocated) or resources[:cpus].nil? or num_vcpus_allocated <= resources[:cpus] errors.add_to_base("No available nics in quota") unless resources[:nics].nil? or resources[:nics] >= 1 diff --git a/src/test/fixtures/help_sections.yml b/src/test/fixtures/help_sections.yml index 5bf0293..d9f93e4 100644 --- a/src/test/fixtures/help_sections.yml +++ b/src/test/fixtures/help_sections.yml @@ -1,7 +1,11 @@ # Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html -# one: -# column: value -# -# two: -# column: value +dashboard_help: + controller: dashboard + action: index + section: 'index.html' + +hardware_hosts_help: + controller: hardware + action: hosts + section: 'hardware_hosts.html' diff --git a/src/test/fixtures/storage_pools.yml b/src/test/fixtures/storage_pools.yml index 3cda6db..35bfc88 100644 --- a/src/test/fixtures/storage_pools.yml +++ b/src/test/fixtures/storage_pools.yml @@ -20,3 +20,10 @@ corp_com_dev_nfs_ovirtnfs: export_path: /devnfs state: available capacity: 1024 +corp_com_dev_lvm_ovirtlvm: + hardware_pool: corp_com_dev + type: LvmStoragePool + ip_addr: 192.168.50.3 + export_path: /devnfs + state: available + capacity: 1024 diff --git a/src/test/fixtures/usages.yml b/src/test/fixtures/usages.yml index 5bf0293..3bd72e6 100644 --- a/src/test/fixtures/usages.yml +++ b/src/test/fixtures/usages.yml @@ -1,7 +1,9 @@ # Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html -# one: -# column: value -# -# two: -# column: value +management_usage: + label: management + usage: management + +guest_usage: + label: guest + usage: guest diff --git a/src/test/unit/bonding_test.rb b/src/test/unit/bonding_test.rb index 8b90cd5..157035a 100644 --- a/src/test/unit/bonding_test.rb +++ b/src/test/unit/bonding_test.rb @@ -35,6 +35,7 @@ class BondingTest < ActiveSupport::TestCase :bonding_type_id => bonding_types(:failover_bonding_type), :host_id => hosts(:mailservers_managed_node)) @bonding.vlan = networks(:dhcp_vlan_one) + @bonding.bonding_type = bonding_types(:load_balancing_bonding_type) end # Ensures that the name is required. @@ -69,6 +70,40 @@ class BondingTest < ActiveSupport::TestCase flunk 'Bondings have to have a host.' if @bonding.valid? end + def test_valid_fails_without_bonding_type + @bonding.bonding_type = nil + flunk 'Bonding must specify bonding type' if @bonding.valid? + end + + def test_valid_fails_without_vlan + @bonding.vlan = nil + flunk 'Bonding must specify vlan' if @bonding.valid? + end + + # Ensures that an arp ping address must have the correct format + # + def test_valid_fails_with_bad_arp_ping_address + @bonding.arp_ping_address = 'foobar' + + flunk "An arp ping address must be in the format ##.##.##.##." if @bonding.valid? + end + + # Ensures that an arp interval is a numerical value >= 0 + # + def test_valid_fails_with_bad_arp_interval + @bonding.arp_interval = -1 + + flunk "An arp interval must be >= 0" if @bonding.valid? + end + + def test_static_network_bonding_must_have_ip + @bonding.vlan = networks(:static_vlan_one) + @bonding.ip_addresses.delete_if { true } + + flunk 'Bonding assigned to static networks must have at least one ip' if @bonding.valid? + end + + # Ensure that retrieving a bonding returns its associated objects. # def test_find_all_for_host diff --git a/src/test/unit/boot_type_test.rb b/src/test/unit/boot_type_test.rb index a30e258..16ed516 100644 --- a/src/test/unit/boot_type_test.rb +++ b/src/test/unit/boot_type_test.rb @@ -19,8 +19,36 @@ require File.dirname(__FILE__) + '/../test_helper' class BootTypeTest < ActiveSupport::TestCase - # Replace this with your real tests. - def test_truth - assert true - end + fixtures :boot_types + + def setup + @boot_type = BootType.new( + :label => 'TestBootType', + :proto => 'static' ) + end + + def test_valid_fails_without_label + @boot_type.label = '' + + flunk 'Boot type must have label' if @boot_type.valid? + end + + def test_valid_fails_without_unique_label + @boot_type.label = 'Static IP' + + flunk 'Boot type must have unique label' if @boot_type.valid? + end + + def test_valid_fails_with_bad_proto + @boot_type.proto = 'foobar' + + flunk 'Boot type must have valid proto' if @boot_type.valid? + end + + def test_find_all_for_boot_type + result = BootType.find(:all) + + assert_equal 3, result.size, "Did not find right number of boot types" + end + end diff --git a/src/test/unit/cpu_test.rb b/src/test/unit/cpu_test.rb index 9558525..c1e9e63 100644 --- a/src/test/unit/cpu_test.rb +++ b/src/test/unit/cpu_test.rb @@ -1,10 +1,99 @@ +# 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 CpuTest < ActiveSupport::TestCase fixtures :cpus + fixtures :hosts + + def setup + @cpu = Cpu.new( + :cpu_number => 3, + :core_number => 1, + :number_of_cores => 1, + :cpuid_level => 0, + :speed => 2048, + :vendor => 'foo', + :model => 'bar', + :family => 'alpha') + @cpu.host = hosts(:prod_corp_com) + end + + def test_find_cpus + assert_equal Cpu.find(:all).size, 8, "Failure retrieving all cpus" + + result = Cpu.find(cpus(:prod_corp_com_1).id) + assert_equal result.host.id, hosts(:prod_corp_com).id + end + + def test_valid_without_host + @cpu.host = nil + + flunk "CPUs must be associated with hosts" if @cpu.valid? + end + + def test_valid_with_bad_cpu_numer + @cpu.cpu_number = -1 + + flunk "cpu number must be >= 0" if @cpu.valid? + end + + def test_valid_with_bad_core_number + @cpu.core_number = -1 + + flunk "cpu core number must be >= 0" if @cpu.valid? + end - # Replace this with your real tests. - def test_truth - assert true + def test_valid_with_bad_number_of_cores + @cpu.number_of_cores = 0 + + flunk "cpu number of cores must be > 0" if @cpu.valid? end + + def test_valid_with_bad_cpuid_level + @cpu.cpuid_level = -1 + + flunk "cpu id level must be >= 0" if @cpu.valid? + end + + def test_valid_with_bad_speed + @cpu.speed = 0 + + flunk "cpu speed must be > 0" if @cpu.valid? + end + + def test_valid_without_vendor + @cpu.vendor = '' + + flunk "cpu vendor must be specified" if @cpu.valid? + end + + def test_valid_without_model + @cpu.model = '' + + flunk "cpu model must be specified" if @cpu.valid? + end + + def test_valid_without_family + @cpu.family = '' + + flunk "cpu family must be specified" if @cpu.valid? + end + end diff --git a/src/test/unit/help_section_test.rb b/src/test/unit/help_section_test.rb index a0e6a08..e30345a 100644 --- a/src/test/unit/help_section_test.rb +++ b/src/test/unit/help_section_test.rb @@ -1,8 +1,51 @@ +# 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 'test_helper' class HelpSectionTest < ActiveSupport::TestCase - # Replace this with your real tests. - def test_truth - assert true - end + fixtures :help_sections + + def setup + @help_section = HelpSection.new( + :controller => 'foo', + :action => 'bar', + :section => 'foobar') + end + + def test_unique_controller_action + @help_section.controller = 'dashboard' + @help_section.action = 'index' + + flunk 'help section must have unique controller / action' if @help_section.valid? + end + + def test_valid_fails_without_controller + @help_section.controller = '' + flunk 'help section controller must be specified' if @help_section.valid? + end + + def test_valid_fails_without_action + @help_section.action = '' + flunk 'help section action must be specified' if @help_section.valid? + end + + def test_valid_fails_without_section + @help_section.section = '' + flunk 'help section section must be specified' if @help_section.valid? + end end diff --git a/src/test/unit/host_browser_identify_test.rb b/src/test/unit/host_browser_identify_test.rb index a17ea30..9f7be1f 100644 --- a/src/test/unit/host_browser_identify_test.rb +++ b/src/test/unit/host_browser_identify_test.rb @@ -163,11 +163,11 @@ class HostBrowserIdentifyTest < Test::Unit::TestCase # Ensures that the server is fine when no UUID is present. # - def test_write_host_info_with_missing_uuid - @host_info['UUID'] = nil + #def test_write_host_info_with_missing_uuid + #@host_info['UUID'] = nil - assert_nothing_raised { @browser.write_host_info(@host_info) } - end + #assert_nothing_raised { @browser.write_host_info(@host_info) } + #end # Ensures that, if the hostname is missing, the server # raises an exception. diff --git a/src/test/unit/host_test.rb b/src/test/unit/host_test.rb index a4ead5d..a7458d2 100644 --- a/src/test/unit/host_test.rb +++ b/src/test/unit/host_test.rb @@ -21,9 +21,63 @@ require File.dirname(__FILE__) + '/../test_helper' class HostTest < Test::Unit::TestCase fixtures :hosts + fixtures :pools + fixtures :vms - # Replace this with your real tests. - def test_truth - assert true + def setup + @host = Host.new( + :uuid => 'foobar', + :hostname => 'foobar', + :arch => 'x86_64', + :hypervisor_type => 'kvm', + :state => 'available') + + @host.hardware_pool = pools(:corp_com) + end + + def test_valid_fails_without_hardware_pool + @host.hardware_pool = nil + + flunk "Hosts must be associated w/ a hardware pool" if @host.valid? + end + + def test_valid_fails_without_uuid + @host.uuid = '' + + flunk "Hosts must be associated w/ a uuid" if @host.valid? end + + + def test_valid_fails_without_hostname + @host.hostname = '' + + flunk "Hosts must be associated w/ a hostname" if @host.valid? + end + + + def test_valid_fails_without_arch + @host.arch = '' + + flunk "Hosts must be associated w/ an arch" if @host.valid? + end + + def test_valid_fails_with_bad_hypervisor_type + @host.hypervisor_type = 'foobar' + + flunk "Hosts must be associated w/ a valid hypervisor type" if @host.valid? + end + + def test_valid_fails_with_bad_state + @host.state = 'foobar' + + flunk "Hosts must be associated w/ a valid state" if @host.valid? + end + + def test_host_movable + assert_equal @host.movable?, true, "Hosts are movable unless associated w/ vms" + + @host.vms << vms(:production_httpd_vm) + assert_equal @host.movable?, false, "Hosts with associated vms are not movable" + end + end diff --git a/src/test/unit/ip_address_test.rb b/src/test/unit/ip_address_test.rb index 5ecff77..4cfc694 100644 --- a/src/test/unit/ip_address_test.rb +++ b/src/test/unit/ip_address_test.rb @@ -10,4 +10,9 @@ class IpAddressTest < ActiveSupport::TestCase def test_can_get_ipaddress_object assert_equal ip_addresses(:ip_v4_mailserver_nic_one).address, '172.31.0.15' end + + def test_valid_fails_without_foreign_entity + @ip_address = IpAddress.new + flunk "Ip Address must be associated with network, nic, or bonding" if @ip_address.valid? + end end diff --git a/src/test/unit/ip_v4_address_test.rb b/src/test/unit/ip_v4_address_test.rb index 65a08d3..9cb7362 100644 --- a/src/test/unit/ip_v4_address_test.rb +++ b/src/test/unit/ip_v4_address_test.rb @@ -24,7 +24,8 @@ class IpV4AddressTest < ActiveSupport::TestCase @address = IpV4Address.new(:address => '192.168.50.2', :netmask => '255.255.255.0', :gateway => '192.168.50.1', - :broadcast => '192.168.50.255') + :broadcast => '192.168.50.255', + :nic_id => 1) end # Ensures that an address must be supplied. diff --git a/src/test/unit/ip_v6_address_test.rb b/src/test/unit/ip_v6_address_test.rb index 070f407..96f212a 100644 --- a/src/test/unit/ip_v6_address_test.rb +++ b/src/test/unit/ip_v6_address_test.rb @@ -23,7 +23,8 @@ 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') + :prefix => '0000:0000:0000:0000:1234:1234:1234:1234', + :nic_id => 1) end # Ensures that the address must be provided. diff --git a/src/test/unit/nic_test.rb b/src/test/unit/nic_test.rb index 1de1e00..0e5321e 100644 --- a/src/test/unit/nic_test.rb +++ b/src/test/unit/nic_test.rb @@ -22,9 +22,61 @@ require File.dirname(__FILE__) + '/../test_helper' class NicTest < Test::Unit::TestCase fixtures :ip_addresses fixtures :nics + fixtures :hosts + fixtures :networks - # Replace this with your real tests. - def test_truth - assert true + def setup + @nic = Nic.new( + :mac => '00:11:22:33:44:55', + :usage_type => 1, + :bandwidth => 100 ) + @nic.host = hosts(:prod_corp_com) + @nic.physical_network = networks(:static_physical_network_one) + + @ip_address = IpV4Address.new( + :address => '1.2.3.4', + :netmask => '2.3.4.5', + :gateway => '3.4.5.6', + :broadcast => '4.5.6.7' ) + + @nic.ip_addresses << @ip_address + end + + def test_valid_fails_without_mac + @nic.mac = '' + + flunk 'Nic must have a mac' if @nic.valid? + end + + def test_valid_fails_with_invalid_mac + @nic.mac = 'foobar' + + flunk 'Nic must have a valid mac' if @nic.valid? + end + + def test_valid_fails_without_host + @nic.host = nil + + flunk 'Nic must have a host' if @nic.valid? end + + def test_valid_fails_without_physical_network + @nic.physical_network = nil + + flunk 'Nic must have a physical network' if @nic.valid? + end + + def test_valid_fails_with_invalid_bandwidth + @nic.bandwidth = -1 + + flunk 'Nic bandwidth must be >= 0' if @nic.valid? + end + + def test_static_network_nic_must_have_ip + @nic.physical_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 + end diff --git a/src/test/unit/permission_test.rb b/src/test/unit/permission_test.rb index 5e2c7ba..0c0f4c7 100644 --- a/src/test/unit/permission_test.rb +++ b/src/test/unit/permission_test.rb @@ -21,6 +21,14 @@ require File.dirname(__FILE__) + '/../test_helper' class PermissionTest < Test::Unit::TestCase fixtures :permissions + fixtures :pools + + def setup + @permission = Permission.new( + :uid => 'foobar', + :user_role => 'Super Admin' ) + @permission.pool = pools(:root_dir_pool) + end # Replace this with your real tests. def test_simple_permission @@ -32,4 +40,24 @@ class PermissionTest < Test::Unit::TestCase assert_equal permissions(:ovirtadmin_default).inherited_from_id, permissions(:ovirtadmin_root).id assert_equal permissions(:ovirtadmin_default).parent_permission, permissions(:ovirtadmin_root) end + + def test_valid_fails_without_pool + @permission.pool = nil + flunk 'Permission must specify pool' if @permission.valid? + end + + def test_valid_fails_without_uid + @permission.uid = '' + flunk 'Permission must specify uid' if @permission.valid? + end + + def test_valid_fails_without_user_role + @permission.user_role = '' + flunk 'Permission must specify user role' if @permission.valid? + end + + def test_valid_fails_with_invalid_user_role + @permission.user_role = 'foobar' + flunk 'Permission must specify valid user role' if @permission.valid? + end end diff --git a/src/test/unit/pool_test.rb b/src/test/unit/pool_test.rb index 6f20f9f..c9a5554 100644 --- a/src/test/unit/pool_test.rb +++ b/src/test/unit/pool_test.rb @@ -22,6 +22,12 @@ require File.dirname(__FILE__) + '/../test_helper' class PoolTest < Test::Unit::TestCase fixtures :pools + def setup + @pool = Pool.new( + :name => 'foobar', + :type => 'DirectoryPool' ) + end + # Replace this with your real tests. def test_get_name assert_equal(pools(:corp_com_prod).name, 'Production Operations') @@ -30,4 +36,19 @@ class PoolTest < Test::Unit::TestCase def test_get_parent assert_equal(pools(:corp_com_prod).parent.name, 'corp.com') end + + def test_valid_fails_without_name + @pool.name = '' + flunk "Pool must specify name" if @pool.valid? + end + + def test_valid_fails_without_unique_name + @pool.name = 'root' + flunk "Pool must specify unique name" if @pool.valid? + end + + def test_valid_fails_with_invalid_type + @pool.name = 'foobar' + flunk "Pool must specify valid type" if @pool.valid? + end end diff --git a/src/test/unit/quota_test.rb b/src/test/unit/quota_test.rb index ac0fae0..5903cc8 100644 --- a/src/test/unit/quota_test.rb +++ b/src/test/unit/quota_test.rb @@ -21,9 +21,40 @@ require File.dirname(__FILE__) + '/../test_helper' class QuotaTest < Test::Unit::TestCase fixtures :quotas + fixtures :pools - # Replace this with your real tests. - def test_truth - assert true + def setup + @quota = Quota.new + @quota.pool = pools(:root_dir_pool) + end + + def test_valid_fails_without_pool + @quota.pool = nil + flunk "Quota's must specify pool" if @quota.valid? + end + + def test_valid_fails_with_bad_total_vcpus + @quota.total_vcpus = -1 + flunk "Quota must specify valid total vcpus" if @quota.valid? + end + + def test_valid_fails_with_bad_total_vmemory + @quota.total_vmemory = -1 + flunk "Quota must specify valid total vmemory" if @quota.valid? + end + + def test_valid_fails_with_bad_total_vnics + @quota.total_vnics = -1 + flunk "Quota must specify valid total vnics" if @quota.valid? + end + + def test_valid_fails_with_bad_total_storage + @quota.total_storage = -1 + flunk "Quota must specify valid total storage" if @quota.valid? + end + + def test_valid_fails_with_bad_total_vms + @quota.total_vms = -1 + flunk "Quota must specify valid total vms" if @quota.valid? end end diff --git a/src/test/unit/storage_pool_test.rb b/src/test/unit/storage_pool_test.rb index 8cc8d1b..00e1199 100644 --- a/src/test/unit/storage_pool_test.rb +++ b/src/test/unit/storage_pool_test.rb @@ -21,8 +21,53 @@ require File.dirname(__FILE__) + '/../test_helper' class StoragePoolTest < Test::Unit::TestCase fixtures :storage_pools + fixtures :pools + fixtures :vms + + def setup + @storage_pool = StoragePool.new( + :type => 'IscsiStoragePool', + :capacity => 100, + :state => 'available' ) + @storage_pool.hardware_pool = pools(:default) + end + + def test_valid_fails_without_hardware_pool + @storage_pool.hardware_pool = nil + flunk "Storage pool must specify hardware pool" if @storage_pool.valid? + end + + def test_valid_fails_with_bad_type + @storage_pool.type = 'foobar' + flunk 'Storage pool must specify valid type' if @storage_pool.valid? + end + + def test_valid_fails_with_bad_capacity + @storage_pool.capacity = -1 + flunk 'Storage pool must specify valid capacity >= 0' if @storage_pool.valid? + end + + def test_valid_fails_with_bad_state + @storage_pool.state = 'foobar' + flunk 'Storage pool must specify valid state' if @storage_pool.valid? + end def test_hardware_pool_relationship assert_equal 'corp.com', storage_pools(:corp_com_ovirtpriv_storage).hardware_pool.name end + + def test_movable + assert_equal @storage_pool.movable?, true, "Storage pool without volumes should be movable" + + storage_volume = StorageVolume.new( + :size => 100, + :type => 'IscsiStorageVolume', + :state => 'available' ) + @storage_pool.storage_volumes << storage_volume + + assert_equal @storage_pool.movable?, true, "Storage pool w/ movable storage volumes should be movable" + + storage_volume.vms << vms(:production_httpd_vm) + assert_equal @storage_pool.movable?, false, "Storage pool w/ unmovable storage volumes should not be movable" + end end diff --git a/src/test/unit/storage_volume_test.rb b/src/test/unit/storage_volume_test.rb index d0a89f4..7c620e3 100644 --- a/src/test/unit/storage_volume_test.rb +++ b/src/test/unit/storage_volume_test.rb @@ -21,9 +21,95 @@ require File.dirname(__FILE__) + '/../test_helper' class StorageVolumeTest < Test::Unit::TestCase fixtures :storage_volumes + fixtures :storage_pools + fixtures :vms + + def setup + @storage_volume = StorageVolume.new( + :size => 100, + :type => 'IscsiStorageVolume', + :state => 'available' ) + + @iscsi_storage_volume = IscsiStorageVolume.new( + :lun => 'foobar', + :size => 100, + :state => 'available' ) + + @lvm_storage_volume = LvmStorageVolume.new( + :lv_name => 'foobar', + :lv_owner_perms => '0700', + :lv_group_perms => '0777', + :lv_mode_perms => '0000' ) + + @storage_volume.storage_pool = storage_pools(:corp_com_ovirtpriv_storage) + @iscsi_storage_volume.storage_pool = storage_pools(:corp_com_ovirtpriv_storage) + @lvm_storage_volume.storage_pool = storage_pools(:corp_com_dev_lvm_ovirtlvm) + end # Replace this with your real tests. def test_relationship_to_storage_pool assert_equal 'corp.com', storage_volumes(:ovirtpriv_storage_lun_1).storage_pool.hardware_pool.name end + + + def test_valid_fails_with_bad_size + @storage_volume.size = -1 + + flunk "Storage volume size must be >= 0" if @storage_volume.valid? + end + + def test_valid_fails_with_bad_type + @storage_volume.type = 'foobar' + + flunk "Storage volume type must be valid" if @storage_volume.valid? + end + + def test_valid_fails_with_bad_state + @storage_volume.state = 'foobar' + flunk "Storage volume state must be valid" if @storage_volume.valid? + end + + def test_valid_fails_without_storage_pool + @storage_volume.storage_pool = nil + + flunk "Storage volume must be associated with a storage pool" if @storage_volume.valid? + end + + def test_valid_fails_without_lun + @iscsi_storage_volume.lun = '' + + flunk "iscsi storage volume lun must be valid" if @iscsi_storage_volume.valid? + end + + def test_valid_fails_without_lv_name + @lvm_storage_volume.lv_name = '' + + flunk "lvm storage volume lv_name must be valid" if @lvm_storage_volume.valid? + end + + def test_valid_fails_without_lv_owner_perms + @lvm_storage_volume.lv_owner_perms = '' + + flunk "lvm storage volume lv_owner_perms must be valid" if @lvm_storage_volume.valid? + end + + def test_valid_fails_without_lv_group_perms + @lvm_storage_volume.lv_group_perms = '' + + flunk "lvm storage volume lv_group_perms must be valid" if @lvm_storage_volume.valid? + end + + def test_valid_fails_without_lv_model_perms + @lvm_storage_volume.lv_mode_perms = '' + + flunk "lvm storage volume lv_model_perms must be valid" if @lvm_storage_volume.valid? + end + + def test_movable + assert_equal @storage_volume.movable?, true, "Storage volume without vms should be movable" + @storage_volume.vms << vms(:production_httpd_vm) + + assert_equal @storage_volume.movable?, false, "Storage volume w/ vms should not be movable" + end + end diff --git a/src/test/unit/task_test.rb b/src/test/unit/task_test.rb index 33a3bd8..ba780e7 100644 --- a/src/test/unit/task_test.rb +++ b/src/test/unit/task_test.rb @@ -22,6 +22,20 @@ require File.dirname(__FILE__) + '/../test_helper' class TaskTest < Test::Unit::TestCase fixtures :pools, :hosts, :vms, :permissions, :tasks + def setup + @task = Task.new( :type => 'HostTask', :state => 'finished' ) + end + + def test_valid_fails_with_bad_type + @task.type = 'foobar' + flunk 'Task must specify valid type' if @task.valid? + end + + def test_valid_fails_with_bad_state + @task.state = 'foobar' + flunk 'Task must specify valid state' if @task.valid? + end + def test_exercise_task_relationships assert_equal tasks(:shutdown_production_httpd_appliance_task).task_target.vm_resource_pool.name, 'corp.com production vmpool' assert_equal tasks(:shutdown_production_httpd_appliance_task).task_target.host.hostname, 'prod.corp.com' diff --git a/src/test/unit/usage_test.rb b/src/test/unit/usage_test.rb index 9a8ec9b..0cb25ae 100644 --- a/src/test/unit/usage_test.rb +++ b/src/test/unit/usage_test.rb @@ -1,8 +1,47 @@ +# Copyright (C) 2008 Red Hat, Inc. +# +# 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 'test_helper' class UsageTest < ActiveSupport::TestCase - # Replace this with your real tests. - def test_truth - assert true - end + fixtures :usages + + def setup + @usage = Usage.new( + :label => 'TestUsage', + :usage => 'foobar' ) + end + + def test_valid_fails_without_label + @usage.label = '' + + flunk 'Usage must have label' if @usage.valid? + end + + def test_valid_fails_without_usage + @usage.usage = '' + + flunk 'Usage must have usage' if @usage.valid? + end + + def test_valid_fails_without_unique_usage + @usage.usage = 'management' + + flunk 'Usage must have unique usage' if @usage.valid? + end + end diff --git a/src/test/unit/vm_test.rb b/src/test/unit/vm_test.rb index a196130..d1740cb 100644 --- a/src/test/unit/vm_test.rb +++ b/src/test/unit/vm_test.rb @@ -21,6 +21,7 @@ require File.dirname(__FILE__) + '/../test_helper' class VmTest < Test::Unit::TestCase fixtures :vms + fixtures :pools def setup @vm_name = "Test" @@ -29,6 +30,69 @@ class VmTest < Test::Unit::TestCase "#{Vm::IMAGE_PREFIX}@#{Vm::COBBLER_PREFIX}#{Vm::PROVISIONING_DELIMITER}#{@vm_name}" @cobbler_profile_provisioning "#{Vm::PROFILE_PREFIX}@#{Vm::COBBLER_PREFIX}#{Vm::PROVISIONING_DELIMITER}#{@vm_name}" + + @vm = Vm.new( + :uuid => '00000000-1111-2222-3333-444444444444', + :description => 'foobar', + :num_vcpus_allocated => 1, + :boot_device => 'hd', + :memory_allocated_in_mb => 1, + :memory_allocated => 1024, + :vnic_mac_addr => '11:22:33:44:55:66') + + @vm.vm_resource_pool = pools(:corp_com_production_vmpool) + end + + def test_valid_fails_with_bad_uuid + @vm.uuid = 'foobar' + flunk "Vm must specify valid uuid" if @vm.valid? + end + + def test_valid_fails_without_description + @vm.description = '' + flunk 'Vm must specify description' if @vm.valid? + end + + def test_valid_fails_without_num_vcpus_allocated + @vm.num_vcpus_allocated = nil + flunk 'Vm must specify num_vcpus_allocated' if @vm.valid? + end + + def test_valid_fails_without_boot_device + @vm.boot_device = '' + flunk 'Vm must specify boot_device' if @vm.valid? + end + + + def test_valid_fails_without_memory_allocated + @vm.memory_allocated = '' + flunk 'Vm must specify memory_allocated' if @vm.valid? + end + + + def test_valid_fails_without_memory_allocated_in_mb + @vm.memory_allocated_in_mb = '' + 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? + end + + def test_valid_fails_with_bad_needs_restart + @vm.needs_restart = 5 + flunk 'Vm must specify valid needs_restart' if @vm.valid? + end + + def test_valid_fails_with_bad_state + @vm.state = 'foobar' + flunk 'Vm must specify valid state' if @vm.valid? end # Ensures that, if the VM does not contain the Cobbler prefix, that it -- 1.6.0.4