Jason Guiditta
2009-May-13 13:42 UTC
[Ovirt-devel] [PATCH server] Random cleanup/cloud UI prep.
This patch fixes a bunch of errors in the tests, and adds a few model methods that will be used in the upcoming Cloud UI V1 patch. Signed-off-by: Jason Guiditta <jguiditt at redhat.com> --- src/app/controllers/application.rb | 2 +- src/app/controllers/resources_controller.rb | 8 +------- src/app/models/vm.rb | 13 +++++++++++++ src/app/models/vm_task.rb | 11 +++++++++++ src/config/database.yml | 2 +- src/test/fixtures/storage_volumes.yml | 2 +- src/test/fixtures/vms.yml | 14 +++++++------- src/test/unit/host_browser_identify_test.rb | 4 ++-- src/test/unit/storage_volume_test.rb | 6 ++++-- src/test/unit/vm_test.rb | 4 ++++ 10 files changed, 45 insertions(+), 21 deletions(-) diff --git a/src/app/controllers/application.rb b/src/app/controllers/application.rb index cff5b77..14fe618 100644 --- a/src/app/controllers/application.rb +++ b/src/app/controllers/application.rb @@ -60,7 +60,7 @@ class ApplicationController < ActionController::Base end def is_logged_in - redirect_to(:controller => "login", :action => "login") unless get_login_user + redirect_to(:controller => "/login", :action => "login") unless get_login_user end def get_help_section diff --git a/src/app/controllers/resources_controller.rb b/src/app/controllers/resources_controller.rb index 97d5ee9..bf2a234 100644 --- a/src/app/controllers/resources_controller.rb +++ b/src/app/controllers/resources_controller.rb @@ -51,13 +51,7 @@ class ResourcesController < PoolController # resource's vms list page def show_vms - @actions = [VmTask.label_and_action(VmTask::ACTION_START_VM), - VmTask.label_and_action(VmTask::ACTION_SHUTDOWN_VM), - (VmTask.label_and_action(VmTask::ACTION_POWEROFF_VM) << "break"), - VmTask.label_and_action(VmTask::ACTION_SUSPEND_VM), - VmTask.label_and_action(VmTask::ACTION_RESUME_VM), - VmTask.label_and_action(VmTask::ACTION_SAVE_VM), - VmTask.label_and_action(VmTask::ACTION_RESTORE_VM)] + @actions = VmTask.get_vm_actions show end diff --git a/src/app/models/vm.rb b/src/app/models/vm.rb index 6880c22..f2e53ed 100644 --- a/src/app/models/vm.rb +++ b/src/app/models/vm.rb @@ -380,6 +380,19 @@ class Vm < ActiveRecord::Base return i end + # Make method for calling paginated vms easier for clients. + # TODO: Might want to have an optional param for per_page var + def self.paged_with_perms(user, priv, page, order) + Vm.paginate(:include => [{:vm_resource_pool => + {:permissions => {:role => :privileges}}}], + :conditions => ["privileges.name=:priv + and permissions.uid=:user", + { :user => user, :priv => priv }], + :per_page => 5, + :page => page, + :order => order) + end + protected def validate resources = vm_resource_pool.max_resources_for_vm(self) diff --git a/src/app/models/vm_task.rb b/src/app/models/vm_task.rb index 984e807..762438f 100644 --- a/src/app/models/vm_task.rb +++ b/src/app/models/vm_task.rb @@ -160,6 +160,17 @@ class VmTask < Task def self.label_and_action(action) return [action_label(action), action, action_icon(action)] end + + def self.get_vm_actions + return [label_and_action(VmTask::ACTION_START_VM), + label_and_action(VmTask::ACTION_SHUTDOWN_VM), + (label_and_action(VmTask::ACTION_POWEROFF_VM) << "break"), + label_and_action(VmTask::ACTION_SUSPEND_VM), + label_and_action(VmTask::ACTION_RESUME_VM), + label_and_action(VmTask::ACTION_SAVE_VM), + label_and_action(VmTask::ACTION_RESTORE_VM)] + end + def host nil end diff --git a/src/config/database.yml b/src/config/database.yml index 497eb26..5de15c9 100644 --- a/src/config/database.yml +++ b/src/config/database.yml @@ -21,7 +21,7 @@ # rake db:drop:all # rake db:create:all # rake db:migrate -# rake db:tests:prepare +# rake db:test:prepare # # And when there are changes to the database, simple run: # diff --git a/src/test/fixtures/storage_volumes.yml b/src/test/fixtures/storage_volumes.yml index 8e5b60a..40dc469 100644 --- a/src/test/fixtures/storage_volumes.yml +++ b/src/test/fixtures/storage_volumes.yml @@ -19,7 +19,7 @@ ovirtpriv_storage_lun_3: storage_pool: corp_com_ovirtpriv_storage type: IscsiStorageVolume state: available - lvm_pool_id: corp_com_dev_lvm_ovirtlvm + lvm_storage_pool: corp_com_dev_lvm_ovirtlvm ovirtpriv_lvm_volume_1: size: 1048576 path: /dev/disk/by-id/scsi-S_beaf321013 diff --git a/src/test/fixtures/vms.yml b/src/test/fixtures/vms.yml index 40997b0..e64db5c 100644 --- a/src/test/fixtures/vms.yml +++ b/src/test/fixtures/vms.yml @@ -64,8 +64,8 @@ foobar_prod1_vm: needs_restart: 0 boot_device: cdrom host: fedoraworkstation_foobar_com - vm_resource_pool_id: 2 -ten: + vm_resource_pool: corp_com_production_vmpool +foobar_prod2_vm: uuid: 24b9a994-d415-481d-ace8-1d810b601eb6 description: foobar prod2 num_vcpus_allocated: 2 @@ -77,8 +77,8 @@ ten: needs_restart: 0 boot_device: cdrom host_id: 6 - vm_resource_pool_id: 2 -eleven: + vm_resource_pool: corp_com_production_vmpool +corp_com_errata_vm: uuid: 9b2c3c73-1abe-460e-b671-b8b7b6719e4c description: corp.com errata appliance num_vcpus_allocated: 2 @@ -90,8 +90,8 @@ eleven: needs_restart: 0 boot_device: network host_id: 8 - vm_resource_pool_id: 6 -twelve: + vm_resource_pool: corp_com_production_vmpool +corp_com_bugzilla_vm: uuid: 552134c7-b0ad-4607-bbf5-d6b9a33c2476 description: corp.com bugzilla appliance num_vcpus_allocated: 2 @@ -103,4 +103,4 @@ twelve: needs_restart: 0 boot_device: network host_id: 8 - vm_resource_pool_id: 6 + vm_resource_pool: corp_com_production_vmpool \ No newline at end of file diff --git a/src/test/unit/host_browser_identify_test.rb b/src/test/unit/host_browser_identify_test.rb index a17ea30..229eb7d 100644 --- a/src/test/unit/host_browser_identify_test.rb +++ b/src/test/unit/host_browser_identify_test.rb @@ -245,7 +245,7 @@ class HostBrowserIdentifyTest < Test::Unit::TestCase info = @browser.get_remote_info - assert_equal 3,info.keys.size, "Should contain four keys" + assert_equal 4,info.keys.size, "Should contain four keys" assert info.include?("CPUINFO") end @@ -278,7 +278,7 @@ class HostBrowserIdentifyTest < Test::Unit::TestCase info = @browser.get_remote_info - assert_equal 3,info.keys.size, "Should contain four keys" + assert_equal 4,info.keys.size, "Should contain four keys" assert info.include?('CPUINFO') assert_equal 2, info['CPUINFO'].size, "Should contain details for two CPUs" assert_not_nil info['CPUINFO'][0]['key1'] diff --git a/src/test/unit/storage_volume_test.rb b/src/test/unit/storage_volume_test.rb index 16be0fb..f0e144e 100644 --- a/src/test/unit/storage_volume_test.rb +++ b/src/test/unit/storage_volume_test.rb @@ -122,11 +122,13 @@ class StorageVolumeTest < Test::Unit::TestCase storage_volumes(:ovirtpriv_lvm_volume_1).ui_parent, 'Incorrect ui parent returned' #test isci volume values - assert_equal storage_volumes(:corp_com_ovirtpriv_storage).type.to_s + '_' +storage_volumes(:corp_com_ovirtpriv_storage).id.to_s, + assert_equal storage_volumes(:ovirtpriv_storage_lun_3).storage_pool.type.to_s + '_' + + storage_volumes(:ovirtpriv_storage_lun_3).storage_pool_id.to_s, storage_volumes(:ovirtpriv_storage_lun_3).ui_parent, 'Incorrect ui parent returned' #test nfs volume values - assert_equal storage_volumes(:corp_com_nfs_ovirtnfs).type.to_s + '_' +storage_volumes(:corp_com_nfs_ovirtnfs).id.to_s, + assert_equal storage_volumes(:ovirt_nfs_disk_3).storage_pool.type.to_s + '_' + + storage_volumes(:ovirt_nfs_disk_3).storage_pool_id.to_s, storage_volumes(:ovirt_nfs_disk_3).ui_parent, 'Incorrect ui parent returned' end diff --git a/src/test/unit/vm_test.rb b/src/test/unit/vm_test.rb index b868dfa..5e03715 100644 --- a/src/test/unit/vm_test.rb +++ b/src/test/unit/vm_test.rb @@ -172,4 +172,8 @@ class VmTest < Test::Unit::TestCase def test_get_pending_state assert_equal 'stopped', vms(:production_httpd_vm).get_pending_state end + + def test_paginated_results + assert_equal 5, Vm.paged_with_perms('ovirtadmin', Privilege::VIEW, 1, 'vms.id').size + end end -- 1.6.0.6
Scott Seago
2009-May-13 14:33 UTC
[Ovirt-devel] [PATCH server] Random cleanup/cloud UI prep.
Jason Guiditta wrote:> This patch fixes a bunch of errors in the tests, and adds > a few model methods that will be used in the upcoming Cloud UI V1 > patch. > > Signed-off-by: Jason Guiditta <jguiditt at redhat.com> > --- > diff --git a/src/app/models/vm.rb b/src/app/models/vm.rb > index 6880c22..f2e53ed 100644 > --- a/src/app/models/vm.rb > +++ b/src/app/models/vm.rb > @@ -380,6 +380,19 @@ class Vm < ActiveRecord::Base > return i > end > > + # Make method for calling paginated vms easier for clients. > + # TODO: Might want to have an optional param for per_page var > + def self.paged_with_perms(user, priv, page, order) > + Vm.paginate(:include => [{:vm_resource_pool => > + {:permissions => {:role => :privileges}}}], > + :conditions => ["privileges.name=:priv > + and permissions.uid=:user", > + { :user => user, :priv => priv }], > + :per_page => 5, > + :page => page, > + :order => order) > + end > + >OK just one comment here, I wonder if we should somehow incorporate this logic into the index controller/service layer action, since logically this action corresponds to VmController.index. Although since you're not using VmController maybe you could consider implementing svc_index in VmService (which would call this) and then pulling out the almost-identical logic in VmController.index I'll try to test this a bit later -- and actually the comment above isn't so much about this patch but rather about how we use this method in the controllers later anyway. Scott
Scott Seago
2009-May-13 15:20 UTC
[Ovirt-devel] [PATCH server] Random cleanup/cloud UI prep.
Jason Guiditta wrote:> This patch fixes a bunch of errors in the tests, and adds > a few model methods that will be used in the upcoming Cloud UI V1 > patch. > > Signed-off-by: Jason Guiditta <jguiditt at redhat.com> > >ACK Scott