From dca7117fdf3faf655d0ebaf945ab9ba3d8e14682 Mon Sep 17 00:00:00 2001 From: "Gary W. Smith" Date: Tue, 3 Mar 2015 11:19:17 -0800 Subject: [PATCH] Permit using latest python-cinderclient Fix a number of unit tests so that they will work with the latest cinderclient, which will be released by the end of Kilo. The problem was that several horizon unit tests made calls into python-cinderclient that should have been stubbed out (but were not). These calls silently did nothing in the released python-cinderclient due to a "feature" where certain GET functions would return an empty list when the auth url was an empty string, instead of returning an auth failure. Recent changes in the python-cinderclient authorization functions closed this hole, which then revealed problems in the horizon unit tests: 1) several tests were lacking stubs to cinder calls, and 2) the auth url in test of cinderclient v2 was empty due to a missing dictionary entry in test_data/keystone_data.py Change-Id: I33967a924f4e47009fdc1613248afd1bd377f34f Closes-Bug: 1423425 Co-Authored-By: Richard Hagarty --- .../dashboards/admin/aggregates/tests.py | 9 +++++++- .../dashboards/admin/info/tests.py | 1 + .../dashboards/admin/volumes/tests.py | 5 +++- .../volumes/volume_types/qos_specs/tests.py | 3 +++ .../nodegroup_templates/tests.py | 18 +++++++++++++-- .../project/volumes/volumes/tests.py | 23 +++++++++++++++++++ .../test/test_data/keystone_data.py | 12 ++++++++++ 7 files changed, 67 insertions(+), 4 deletions(-) diff --git a/openstack_dashboard/dashboards/admin/aggregates/tests.py b/openstack_dashboard/dashboards/admin/aggregates/tests.py index 9ec56a7944..f24fec49d6 100644 --- a/openstack_dashboard/dashboards/admin/aggregates/tests.py +++ b/openstack_dashboard/dashboards/admin/aggregates/tests.py @@ -180,13 +180,20 @@ class AggregatesViewTests(test.BaseAdminViewTests): @mock.patch('openstack_dashboard.api.nova.extension_supported', mock.Mock(return_value=False)) + @test.create_stubs({api.nova: ('aggregate_details_list', + 'availability_zone_list',), + api.cinder: ('tenant_absolute_limits',)}) def test_panel_not_available(self): + api.cinder.tenant_absolute_limits(IsA(http.HttpRequest)). \ + MultipleTimes().AndReturn(self.cinder_limits['absolute']) + self.mox.ReplayAll() + self.patchers['aggregates'].stop() res = self.client.get(reverse('horizon:admin:overview:index')) self.assertNotIn('Host Aggregates', res.content) @test.create_stubs({api.nova: ('aggregate_details_list', - 'availability_zone_list',), }) + 'availability_zone_list',)}) def test_index(self): api.nova.aggregate_details_list(IsA(http.HttpRequest)) \ .AndReturn(self.aggregates.list()) diff --git a/openstack_dashboard/dashboards/admin/info/tests.py b/openstack_dashboard/dashboards/admin/info/tests.py index 1a7682722b..45000cf6ec 100644 --- a/openstack_dashboard/dashboards/admin/info/tests.py +++ b/openstack_dashboard/dashboards/admin/info/tests.py @@ -64,6 +64,7 @@ class SystemInfoViewTests(test.BaseAdminViewTests): services_tab._tables['services'].data, ['', '', + '', '', '', '', diff --git a/openstack_dashboard/dashboards/admin/volumes/tests.py b/openstack_dashboard/dashboards/admin/volumes/tests.py index 4dab97e25c..eb56f6f581 100644 --- a/openstack_dashboard/dashboards/admin/volumes/tests.py +++ b/openstack_dashboard/dashboards/admin/volumes/tests.py @@ -25,11 +25,14 @@ from openstack_dashboard.test import helpers as test class VolumeTests(test.BaseAdminViewTests): @test.create_stubs({api.nova: ('server_list',), - cinder: ('volume_list',), + cinder: ('volume_list', + 'volume_snapshot_list'), keystone: ('tenant_list',)}) def test_index(self): cinder.volume_list(IsA(http.HttpRequest), search_opts={ 'all_tenants': True}).AndReturn(self.cinder_volumes.list()) + cinder.volume_snapshot_list(IsA(http.HttpRequest), search_opts={ + 'all_tenants': True}).AndReturn([]) api.nova.server_list(IsA(http.HttpRequest), search_opts={ 'all_tenants': True}) \ .AndReturn([self.servers.list(), False]) diff --git a/openstack_dashboard/dashboards/admin/volumes/volume_types/qos_specs/tests.py b/openstack_dashboard/dashboards/admin/volumes/volume_types/qos_specs/tests.py index e7dab587ee..ccf6afbae8 100644 --- a/openstack_dashboard/dashboards/admin/volumes/volume_types/qos_specs/tests.py +++ b/openstack_dashboard/dashboards/admin/volumes/volume_types/qos_specs/tests.py @@ -65,6 +65,7 @@ class QosSpecsTests(test.BaseAdminViewTests): self.assertMessageCount(success=1) @test.create_stubs({api.cinder: ('volume_type_list_with_qos_associations', + 'volume_encryption_type_list', 'qos_spec_list', 'qos_spec_delete',)}) def test_delete_qos_spec(self): @@ -74,6 +75,8 @@ class QosSpecsTests(test.BaseAdminViewTests): api.cinder.volume_type_list_with_qos_associations( IsA(http.HttpRequest)).\ AndReturn(self.volume_types.list()) + api.cinder.volume_encryption_type_list(IsA(http.HttpRequest))\ + .AndReturn(self.cinder_volume_encryption_types.list()[0:1]) api.cinder.qos_spec_list(IsA(http.HttpRequest)).\ AndReturn(self.cinder_qos_specs.list()) api.cinder.qos_spec_delete(IsA(http.HttpRequest), diff --git a/openstack_dashboard/dashboards/project/data_processing/nodegroup_templates/tests.py b/openstack_dashboard/dashboards/project/data_processing/nodegroup_templates/tests.py index 44d450c11e..a15f274c5f 100644 --- a/openstack_dashboard/dashboards/project/data_processing/nodegroup_templates/tests.py +++ b/openstack_dashboard/dashboards/project/data_processing/nodegroup_templates/tests.py @@ -82,10 +82,17 @@ class DataProcessingNodeGroupTests(test.TestCase): @test.create_stubs({api.sahara: ('nodegroup_template_get', 'plugin_get_version_details'), api.network: ('floating_ip_pools_list', - 'security_group_list')}) + 'security_group_list'), + api.cinder: ('extension_supported', + 'availability_zone_list')}) def test_copy(self): ngt = self.nodegroup_templates.first() configs = self.plugins_configs.first() + api.cinder.extension_supported(IsA(http.HttpRequest), + 'AvailabilityZones') \ + .AndReturn(True) + api.cinder.availability_zone_list(IsA(http.HttpRequest))\ + .AndReturn(self.availability_zones.list()) api.sahara.nodegroup_template_get(IsA(http.HttpRequest), ngt.id) \ .AndReturn(ngt) @@ -114,7 +121,9 @@ class DataProcessingNodeGroupTests(test.TestCase): 'plugin_get_version_details'), api.network: ('floating_ip_pools_list', 'security_group_list'), - api.nova: ('flavor_list',)}) + api.nova: ('flavor_list',), + api.cinder: ('extension_supported', + 'availability_zone_list')}) def test_create(self): flavor = self.flavors.first() ngt = self.nodegroup_templates.first() @@ -123,6 +132,11 @@ class DataProcessingNodeGroupTests(test.TestCase): self.mox.StubOutWithMock( workflow_helpers, 'parse_configs_from_context') + api.cinder.extension_supported(IsA(http.HttpRequest), + 'AvailabilityZones') \ + .AndReturn(True) + api.cinder.availability_zone_list(IsA(http.HttpRequest))\ + .AndReturn(self.availability_zones.list()) api.nova.flavor_list(IsA(http.HttpRequest)).AndReturn([flavor]) api.sahara.plugin_get_version_details(IsA(http.HttpRequest), ngt.plugin_name, diff --git a/openstack_dashboard/dashboards/project/volumes/volumes/tests.py b/openstack_dashboard/dashboards/project/volumes/volumes/tests.py index 0cc674782e..e1ab2956fa 100644 --- a/openstack_dashboard/dashboards/project/volumes/volumes/tests.py +++ b/openstack_dashboard/dashboards/project/volumes/volumes/tests.py @@ -805,6 +805,7 @@ class VolumeViewTests(test.TestCase): @test.create_stubs({cinder: ('tenant_absolute_limits', 'volume_list', + 'volume_snapshot_list', 'volume_backup_supported', 'volume_delete',), api.nova: ('server_list',)}) @@ -818,11 +819,17 @@ class VolumeViewTests(test.TestCase): MultipleTimes().AndReturn(True) cinder.volume_list(IsA(http.HttpRequest), search_opts=None).\ AndReturn(volumes) + cinder.volume_snapshot_list(IsA(http.HttpRequest), + search_opts=None).\ + AndReturn([]) cinder.volume_delete(IsA(http.HttpRequest), volume.id) api.nova.server_list(IsA(http.HttpRequest), search_opts=None).\ AndReturn([self.servers.list(), False]) cinder.volume_list(IsA(http.HttpRequest), search_opts=None).\ AndReturn(volumes) + cinder.volume_snapshot_list(IsA(http.HttpRequest), + search_opts=None).\ + AndReturn([]) api.nova.server_list(IsA(http.HttpRequest), search_opts=None).\ AndReturn([self.servers.list(), False]) cinder.tenant_absolute_limits(IsA(http.HttpRequest)).MultipleTimes().\ @@ -996,6 +1003,7 @@ class VolumeViewTests(test.TestCase): @test.create_stubs({cinder: ('tenant_absolute_limits', 'volume_list', + 'volume_snapshot_list', 'volume_backup_supported',), api.nova: ('server_list',)}) def test_create_button_disabled_when_quota_exceeded(self): @@ -1007,6 +1015,9 @@ class VolumeViewTests(test.TestCase): MultipleTimes().AndReturn(True) cinder.volume_list(IsA(http.HttpRequest), search_opts=None)\ .AndReturn(volumes) + cinder.volume_snapshot_list(IsA(http.HttpRequest), + search_opts=None).\ + AndReturn([]) api.nova.server_list(IsA(http.HttpRequest), search_opts=None)\ .AndReturn([self.servers.list(), False]) cinder.tenant_absolute_limits(IsA(http.HttpRequest))\ @@ -1431,6 +1442,7 @@ class VolumeViewTests(test.TestCase): self._test_encryption(True) @test.create_stubs({cinder: ('volume_list', + 'volume_snapshot_list', 'volume_backup_supported', 'tenant_absolute_limits'), api.nova: ('server_list',)}) @@ -1444,6 +1456,9 @@ class VolumeViewTests(test.TestCase): .MultipleTimes('backup_supported').AndReturn(False) cinder.volume_list(IsA(http.HttpRequest), search_opts=None)\ .AndReturn(self.volumes.list()) + cinder.volume_snapshot_list(IsA(http.HttpRequest), + search_opts=None).\ + AndReturn(self.cinder_volume_snapshots.list()) api.nova.server_list(IsA(http.HttpRequest), search_opts=None)\ .AndReturn([self.servers.list(), False]) cinder.tenant_absolute_limits(IsA(http.HttpRequest))\ @@ -1492,6 +1507,7 @@ class VolumeViewTests(test.TestCase): @test.create_stubs({cinder: ('volume_backup_supported', 'volume_list', + 'volume_snapshot_list', 'tenant_absolute_limits'), api.nova: ('server_list',)}) def test_create_transfer_availability(self): @@ -1501,6 +1517,9 @@ class VolumeViewTests(test.TestCase): .MultipleTimes().AndReturn(False) cinder.volume_list(IsA(http.HttpRequest), search_opts=None)\ .AndReturn(self.volumes.list()) + cinder.volume_snapshot_list(IsA(http.HttpRequest), + search_opts=None).\ + AndReturn([]) api.nova.server_list(IsA(http.HttpRequest), search_opts=None)\ .AndReturn([self.servers.list(), False]) cinder.tenant_absolute_limits(IsA(http.HttpRequest))\ @@ -1540,6 +1559,7 @@ class VolumeViewTests(test.TestCase): @test.create_stubs({cinder: ('volume_backup_supported', 'volume_list', + 'volume_snapshot_list', 'transfer_delete', 'tenant_absolute_limits'), api.nova: ('server_list',)}) @@ -1560,6 +1580,9 @@ class VolumeViewTests(test.TestCase): .MultipleTimes().AndReturn(False) cinder.volume_list(IsA(http.HttpRequest), search_opts=None)\ .AndReturn(volumes) + cinder.volume_snapshot_list(IsA(http.HttpRequest), + search_opts=None).\ + AndReturn([]) cinder.transfer_delete(IsA(http.HttpRequest), transfer.id) api.nova.server_list(IsA(http.HttpRequest), search_opts=None).\ AndReturn([self.servers.list(), False]) diff --git a/openstack_dashboard/test/test_data/keystone_data.py b/openstack_dashboard/test/test_data/keystone_data.py index 3d8cde0889..17b435d31d 100644 --- a/openstack_dashboard/test/test_data/keystone_data.py +++ b/openstack_dashboard/test/test_data/keystone_data.py @@ -60,6 +60,18 @@ SERVICE_CATALOG = [ "adminURL": "http://admin.nova.example.com:8776/v1", "internalURL": "http://int.nova.example.com:8776/v1", "publicURL": "http://public.nova.example.com:8776/v1"}]}, + {"type": "volumev2", + "name": "cinderv2", + "endpoints_links": [], + "endpoints": [ + {"region": "RegionOne", + "adminURL": "http://admin.nova.example.com:8776/v2", + "internalURL": "http://int.nova.example.com:8776/v2", + "publicURL": "http://public.nova.example.com:8776/v2"}, + {"region": "RegionTwo", + "adminURL": "http://admin.nova.example.com:8776/v2", + "internalURL": "http://int.nova.example.com:8776/v2", + "publicURL": "http://public.nova.example.com:8776/v2"}]}, {"type": "image", "name": "glance", "endpoints_links": [],