Mohammed Morsi
2008-Aug-22 21:35 UTC
[Ovirt-devel] [PATCH] vm creation / start / stop tests via selenium
--- autobuild.sh | 5 +- wui/src/test/fixtures/cpus.yml | 68 ++++++++++++++++---- wui/src/test/fixtures/hosts.yml | 10 +++ wui/src/test/fixtures/nics.yml | 13 +++- wui/src/test/fixtures/quotas.yml | 8 +- wui/src/test/fixtures/storage_pools.yml | 9 +++ wui/src/test/functional/interface_test.rb | 98 +++++++++++++++++++++++++++- wui/src/test/unit/cpu_test.rb | 2 + 8 files changed, 189 insertions(+), 24 deletions(-) diff --git a/autobuild.sh b/autobuild.sh index 6c95cb1..95395d0 100755 --- a/autobuild.sh +++ b/autobuild.sh @@ -80,7 +80,10 @@ fi echo "Running the wui tests" $ssh_cmd \ "sed -i \"s/#RAILS_ENV=production/RAILS_ENV=test/g\" /etc/sysconfig/ovirt-rails && \ - service ovirt-mongrel-rails restart && service httpd restart && \ + sed -i \"s/development/test/\" /usr/share/ovirt-wui/dutils/active_record_env.rb && \ + service ovirt-taskomatic restart && \ + service ovirt-mongrel-rails restart && \ + service httpd restart && \ curl -i http://management.priv.ovirt.org/ovirt/ | \ grep 'HTTP/1.1 200 OK' && \ cd /usr/share/ovirt-wui && rake test" > "$RESULTS" 2>&1 \ diff --git a/wui/src/test/fixtures/cpus.yml b/wui/src/test/fixtures/cpus.yml index 5586303..995b433 100644 --- a/wui/src/test/fixtures/cpus.yml +++ b/wui/src/test/fixtures/cpus.yml @@ -1,21 +1,65 @@ # Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html one: + id: 1 + host_id: 10 cpu_number: 1 core_number: 1 - cpu_id_level: 1 - vendor: 1 - family: 1 - model: 1 - family: MyString - flags: MyString + number_of_cores: 2 + vendor: 'intel' two: + id: 2 + host_id: 10 cpu_number: 1 + core_number: 2 + number_of_cores: 2 + vendor: 'intel' + +three: + id: 3 + host_id: 10 + cpu_number: 2 + core_number: 1 + number_of_cores: 4 + vendor: 'intel' + +four: + id: 4 + host_id: 10 + cpu_number: 2 + core_number: 2 + number_of_cores: 4 + vendor: 'intel' + +five: + id: 5 + host_id: 10 + cpu_number: 2 + core_number: 3 + number_of_cores: 4 + vendor: 'intel' + +six: + id: 6 + host_id: 10 + cpu_number: 2 + core_number: 4 + number_of_cores: 4 + vendor: 'intel' + +seven: + id: 7 + host_id: 10 + cpu_number: 3 + core_number: 1 + number_of_cores: 1 + vendor: 'intel' + +seven: + id: 8 + host_id: 10 + cpu_number: 4 core_number: 1 - cpu_id_level: 1 - vendor: 1 - family: 1 - model: 1 - family: MyString - flags: MyString + number_of_cores: 1 + vendor: 'intel' diff --git a/wui/src/test/fixtures/hosts.yml b/wui/src/test/fixtures/hosts.yml index f10a756..a4e1fc6 100644 --- a/wui/src/test/fixtures/hosts.yml +++ b/wui/src/test/fixtures/hosts.yml @@ -79,3 +79,13 @@ nine: is_disabled: 0 hypervisor_type: 'kvm' hardware_pool_id: 3 +ten: + id: 10 + uuid: '75f8d5f3-faf0-4308-9f20-e4b03d013a27' + hostname: 'node3.priv.ovirt.org' + arch: 'x86_64' + memory: 4194304 + is_disabled: 0 + hypervisor_type: 'kvm' + hardware_pool_id: 1 + state: "available" diff --git a/wui/src/test/fixtures/nics.yml b/wui/src/test/fixtures/nics.yml index 008cfb7..db57e55 100644 --- a/wui/src/test/fixtures/nics.yml +++ b/wui/src/test/fixtures/nics.yml @@ -5,18 +5,25 @@ one: ip_addr: '1.2.3.4' usage_type: '1' bandwidth: 100 - host_id: 1 + host_id: 10 two: id: 2 mac: 'AA:BB:CC:DD:EE:FF' ip_addr: '2.3.4.5' usage_type: '2' bandwidth: 1000 - host_id: 1 + host_id: 10 three: id: 3 mac: '00:FF:11:EE:22:DD' ip_addr: '3.4.5.6' usage_type: '1' bandwidth: 10 - host_id: 2 + host_id: 10 +four: + id: 4 + mac: '00:FF:11:EE:22:DD' + ip_addr: '3.4.5.6' + usage_type: '1' + bandwidth: 10 + host_id: 10 diff --git a/wui/src/test/fixtures/quotas.yml b/wui/src/test/fixtures/quotas.yml index 2d56ea0..757c934 100644 --- a/wui/src/test/fixtures/quotas.yml +++ b/wui/src/test/fixtures/quotas.yml @@ -1,11 +1,11 @@ # Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html one: id: 1 - total_vcpus: 8 + total_vcpus: 30 total_vmemory: 2097152 - total_vnics: 3 - total_storage: 500 - total_vms: 2 + total_vnics: 20 + total_storage: 104857600 + total_vms: 20 pool_id: 1 two: id: 2 diff --git a/wui/src/test/fixtures/storage_pools.yml b/wui/src/test/fixtures/storage_pools.yml index 34159ce..0610333 100644 --- a/wui/src/test/fixtures/storage_pools.yml +++ b/wui/src/test/fixtures/storage_pools.yml @@ -9,36 +9,44 @@ two: id: 2 hardware_pool_id: 4 type: 'NfsStoragePool' + ip_addr: '127.0.0.1' export_path: '/tmp/foopath' three: id: 3 hardware_pool_id: 4 type: 'NfsStoragePool' + ip_addr: '192.168.50.1' export_path: '/tmp/barpath' four: id: 4 hardware_pool_id: 9 type: 'IscsiStoragePool' port: 121 + ip_addr: '192.168.50.1' target: 'rubarb' + hardware_pool_id: 1 five: id: 5 hardware_pool_id: 9 type: 'NfsStoragePool' + ip_addr: '192.168.50.2' export_path: '/tmp/thepath' six: id: 6 hardware_pool_id: 9 type: 'NfsStoragePool' + ip_addr: '192.168.50.3' export_path: '/tmp/anotherpath' seven: id: 7 hardware_pool_id: 9 type: 'NfsStoragePool' + ip_addr: '192.168.50.4' export_path: '/tmp/apath' eight: id: 8 hardware_pool_id: 6 + ip_addr: '192.168.50.2' type: 'IscsiStoragePool' port: 531 target: 'bartarget' @@ -52,5 +60,6 @@ ten: id: 10 hardware_pool_id: 6 type: 'IscsiStoragePool' + ip_addr: '192.168.50.3' port: 539 target: 'stayontarget' diff --git a/wui/src/test/functional/interface_test.rb b/wui/src/test/functional/interface_test.rb index 6563b44..eadeb74 100644 --- a/wui/src/test/functional/interface_test.rb +++ b/wui/src/test/functional/interface_test.rb @@ -27,17 +27,107 @@ if File.exists? File.dirname(__FILE__) + '/../selenium.rb' "*firefox /usr/lib64/firefox-3.0.1/firefox", "http://192.168.50.2/ovirt/", 15000) @browser.start + @browser.set_speed(1500) # ms delay between operations end def test_ovirt @browser.open("http://192.168.50.2/ovirt/") assert_equal("Dashboard", @browser.get_title()) - @browser.close end - def teardown - @browser.stop - end + def test_view_pool + @browser.open("http://192.168.50.2/ovirt/") + @browser.wait_for_condition( + "selenium.isElementPresent(\"//div[@id='side']/ul/li/span/a\")", + 10000) + @browser.click( + "//div[@id='side']/ul/li/span/a") # click 'master pool' link + @browser.wait_for_condition( + "selenium.isElementPresent(\"//div[@class='summary_title']\")", + 10000) + + # verify the title of the pool + assert_equal("master pool", + @browser.get_text("//div[@class='summary_title']")) + end + + def test_create_start_stop_vm + @browser.open("http://192.168.50.2/ovirt/") + @browser.wait_for_condition( + "selenium.isElementPresent(\"//div[@id='side']/ul/li/ul/li[1]/span/a\")", + 10000) + # click on 'foobar' vm resource pool link: + @browser.click "//div[@id='side']/ul/li/ul/li[1]/span/a" + @browser.wait_for_condition( + "selenium.isElementPresent(\"//li[@id='nav_vmpool']/a\")", + 10000) + # click on virtual machines tab + @browser.click "//li[@id='nav_vmpool']/a" + @browser.wait_for_condition( + "selenium.isElementPresent(\"//div[@id='toolbar_nav']/ul/li[1]/a\")", + 10000) + # click on 'add virtual machine' + @browser.click "//div[@id='toolbar_nav']/ul/li[1]/a" + + # retrieve current # of vms + num_vms = @browser.get_xpath_count "//table[@id='vms_grid']/tbody/tr" + + # fill in required fields + @browser.wait_for_condition( + "selenium.isElementPresent(\"//input[@id='vm_description']\")", + 10000) + @browser.type("//input[@id='vm_description']", "zzz-selenium-test-vm") + @browser.type("//input[@id='vm_num_vcpus_allocated']", "1") + @browser.type("//input[@id='vm_memory_allocated_in_mb']", "256") + # select 1st storage pool + #@browser.click("//table[@id='storage_volumes_grid']/tbody/tr/td/div/input") + @browser.wait_for_condition( + "selenium.isElementPresent(\"//form[@id='vm_form']/div[2]/div[2]/div[2]/a\")", + 10000) + # click the button + @browser.click "//form[@id='vm_form']/div[2]/div[2]/div[2]/a" + + @browser.wait_for_condition( + "selenium.isElementPresent(\"//table[@id='vms_grid']/tbody/tr[" + (num_vms.to_i + 1).to_s + "]\")", + 20000) + # verify title of newly created vm + assert_equal("zzz-selenium-test-vm", + @browser.get_text("//table[@id='vms_grid']/tbody/tr[" + (num_vms.to_i + 1).to_s + "]/td[2]/div")) + + # start it, click checkbox, 'start vm', confirmation button; reload tab, check result + @browser.click "//table[@id='vms_grid']/tbody/tr[" + (num_vms.to_i + 1).to_s + "]/td[1]/div/input" + @browser.click "//div[@id='toolbar_nav']/ul/li[2]/ul/li[1]" + @browser.wait_for_condition( + "selenium.isElementPresent(\"//div[@id='vm_action_results']/div[3]/div/div[2]/a\")", + 10000) + @browser.click "//div[@id='vm_action_results']/div[3]/div/div[2]/a" + @browser.click "//div[@id='side']/ul/li/ul/li[1]/span/a" + @browser.wait_for_condition( + "selenium.isElementPresent(\"//table[@id='vms_grid']/tbody/tr[" + (num_vms.to_i + 1).to_s + "]/td[7]/div\")", + 20000) + assert_equal("running", + @browser.get_text("//table[@id='vms_grid']/tbody/tr[" + (num_vms.to_i + 1).to_s + "]/td[7]/div")) + + # stop / destroy vm + @browser.click "//table[@id='vms_grid']/tbody/tr[" + (num_vms.to_i + 1).to_s + "]/td[1]/div/input" + @browser.click "//div[@id='toolbar_nav']/ul/li[2]/ul/li[2]" + @browser.wait_for_condition( + "selenium.isElementPresent(\"//div[@id='vm_action_results']/div[3]/div/div[2]/a\")", + 10000) + @browser.click "//div[@id='vm_action_results']/div[3]/div/div[2]/a" + @browser.click "//div[@id='side']/ul/li/ul/li[1]/span/a" + @browser.wait_for_condition( + "selenium.isElementPresent(\"//table[@id='vms_grid']/tbody/tr[" + (num_vms.to_i + 1).to_s + "]/td[7]/div\")", + 20000) + assert_equal("stopped", + @browser.get_text("//table[@id='vms_grid']/tbody/tr[" + (num_vms.to_i + 1).to_s + "]/td[7]/div")) + + end + + def teardown + @browser.close + @browser.stop + end end end diff --git a/wui/src/test/unit/cpu_test.rb b/wui/src/test/unit/cpu_test.rb index 5b64ca7..9558525 100644 --- a/wui/src/test/unit/cpu_test.rb +++ b/wui/src/test/unit/cpu_test.rb @@ -1,6 +1,8 @@ require File.dirname(__FILE__) + '/../test_helper' class CpuTest < ActiveSupport::TestCase + fixtures :cpus + # Replace this with your real tests. def test_truth assert true -- 1.5.4.1
Mohammed Morsi
2008-Aug-22 21:35 UTC
[Ovirt-devel] [PATCH] small bug fix, the include_vm variable is null when passed in from vm_controller.create
--- wui/src/app/models/storage_volume.rb | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/wui/src/app/models/storage_volume.rb b/wui/src/app/models/storage_volume.rb index ccc5839..4044a13 100644 --- a/wui/src/app/models/storage_volume.rb +++ b/wui/src/app/models/storage_volume.rb @@ -53,7 +53,7 @@ class StorageVolume < ActiveRecord::Base def self.find_for_vm(include_vm, vm_pool) if vm_pool condition = "(vms.id is null and storage_pools.hardware_pool_id=#{vm_pool.get_hardware_pool.id})" - condition += " or vms.id=#{include_vm.id}" if (include_vm.id) + condition += " or vms.id=#{include_vm.id}" if (include_vm && include_vm.id) self.find(:all, :include => [:vms, :storage_pool], :conditions => condition) else return [] -- 1.5.4.1
David Lutterkort
2008-Aug-26 22:16 UTC
[Ovirt-devel] Re: [PATCH] vm creation / start / stop tests via selenium
On Tue, 2008-08-26 at 17:25 -0400, Mohammed Morsi wrote:> --- > autobuild.sh | 5 +- > wui/src/test/fixtures/cpus.yml | 68 ++++++++++++++++---- > wui/src/test/fixtures/hosts.yml | 10 +++ > wui/src/test/fixtures/nics.yml | 13 +++- > wui/src/test/fixtures/quotas.yml | 8 +- > wui/src/test/fixtures/storage_pools.yml | 9 +++ > wui/src/test/functional/interface_test.rb | 98 +++++++++++++++++++++++++++- > wui/src/test/unit/cpu_test.rb | 2 + > 8 files changed, 189 insertions(+), 24 deletions(-)ACK. Some small nits:> diff --git a/autobuild.sh b/autobuild.sh > index 6c95cb1..95395d0 100755 > --- a/autobuild.sh > +++ b/autobuild.sh > @@ -80,7 +80,10 @@ fi > echo "Running the wui tests" > $ssh_cmd \ > "sed -i \"s/#RAILS_ENV=production/RAILS_ENV=test/g\" /etc/sysconfig/ovirt-rails && \ > - service ovirt-mongrel-rails restart && service httpd restart && \ > + sed -i \"s/development/test/\" /usr/share/ovirt-wui/dutils/active_record_env.rb && \Why is it necessary to patch active_record_env.rb ? Shouldn't it be enough to set the RAILS_ENV environment variable ?> diff --git a/wui/src/test/functional/interface_test.rb b/wui/src/test/functional/interface_test.rb > index 6563b44..eadeb74 100644 > --- a/wui/src/test/functional/interface_test.rb > +++ b/wui/src/test/functional/interface_test.rb> + # click the button > + @browser.click "//form[@id='vm_form']/div[2]/div[2]/div[2]/a"Ultimately, we should fix up the templates/views so that the tests can reference the elements they are really interested in by their id, instead of depending on the exact structure of the HTML ... that will become rather painful to maintain. If it works now, that's fine, but as soon as it breaks, the fix should be to annotate the generated HTML, rather than adapt the tests all the time. David