Simplify APIMockTestCase
There is no need to use stub_*client() because we can simply use mock.patch(.object). This commit removed stub_*client(). Part of blueprint mock-framework-in-unit-tests Change-Id: I1563720e3fc636f7b042d030baf59e0b1a0e9bf0 Signed-off-by: Akihiro Motoki <amotoki@gmail.com>
This commit is contained in:
parent
7c09346e08
commit
7b7ace0aeb
@ -615,38 +615,13 @@ class APITestCase(TestCase):
|
||||
return self.swiftclient
|
||||
|
||||
|
||||
class APIMockTestCase(APITestCase):
|
||||
class APIMockTestCase(TestCase):
|
||||
|
||||
use_mox = False
|
||||
|
||||
def stub_novaclient(self):
|
||||
if not hasattr(self, "novaclient"):
|
||||
self.novaclient = mock.Mock()
|
||||
return self.novaclient
|
||||
|
||||
def stub_cinderclient(self):
|
||||
if not hasattr(self, "cinderclient"):
|
||||
self.cinderclient = mock.Mock()
|
||||
return self.cinderclient
|
||||
|
||||
def stub_glanceclient(self):
|
||||
if not hasattr(self, "glanceclient"):
|
||||
self.glanceclient = mock.Mock()
|
||||
return self.glanceclient
|
||||
|
||||
def stub_keystoneclient(self):
|
||||
if not hasattr(self, "keystoneclient"):
|
||||
self.keystoneclient = mock.Mock()
|
||||
return self.keystoneclient
|
||||
|
||||
def stub_neutronclient(self):
|
||||
if not hasattr(self, "neutronclient"):
|
||||
self.neutronclient = mock.Mock()
|
||||
return self.neutronclient
|
||||
|
||||
def stub_swiftclient(self):
|
||||
# This method should not be called.
|
||||
raise NotImplementedError
|
||||
def setUp(self):
|
||||
super(APIMockTestCase, self).setUp()
|
||||
utils.patch_middleware_get_user()
|
||||
|
||||
|
||||
# Need this to test both Glance API V1 and V2 versions
|
||||
|
@ -16,6 +16,7 @@ from django.conf import settings
|
||||
from django.test.utils import override_settings
|
||||
|
||||
import cinderclient as cinder_client
|
||||
import mock
|
||||
|
||||
from openstack_dashboard import api
|
||||
from openstack_dashboard.test import helpers as test
|
||||
@ -23,13 +24,14 @@ from openstack_dashboard.test import helpers as test
|
||||
|
||||
class CinderApiTests(test.APIMockTestCase):
|
||||
|
||||
def test_volume_list(self):
|
||||
@mock.patch.object(api.cinder, 'cinderclient')
|
||||
def test_volume_list(self, mock_cinderclient):
|
||||
search_opts = {'all_tenants': 1}
|
||||
detailed = True
|
||||
|
||||
volumes = self.cinder_volumes.list()
|
||||
volume_transfers = self.cinder_volume_transfers.list()
|
||||
cinderclient = self.stub_cinderclient()
|
||||
cinderclient = mock_cinderclient.return_value
|
||||
|
||||
volumes_mock = cinderclient.volumes.list
|
||||
volumes_mock.return_value = volumes
|
||||
@ -45,12 +47,13 @@ class CinderApiTests(test.APIMockTestCase):
|
||||
search_opts=search_opts)
|
||||
self.assertEqual(len(volumes), len(api_volumes))
|
||||
|
||||
def test_volume_list_paged(self):
|
||||
@mock.patch.object(api.cinder, 'cinderclient')
|
||||
def test_volume_list_paged(self, mock_cinderclient):
|
||||
search_opts = {'all_tenants': 1}
|
||||
detailed = True
|
||||
volumes = self.cinder_volumes.list()
|
||||
volume_transfers = self.cinder_volume_transfers.list()
|
||||
cinderclient = self.stub_cinderclient()
|
||||
cinderclient = mock_cinderclient.return_value
|
||||
|
||||
volumes_mock = cinderclient.volumes.list
|
||||
volumes_mock.return_value = volumes
|
||||
@ -70,7 +73,8 @@ class CinderApiTests(test.APIMockTestCase):
|
||||
|
||||
@override_settings(API_RESULT_PAGE_SIZE=2)
|
||||
@override_settings(OPENSTACK_API_VERSIONS={'volume': 2})
|
||||
def test_volume_list_paginate_first_page(self):
|
||||
@mock.patch.object(api.cinder, 'cinderclient')
|
||||
def test_volume_list_paginate_first_page(self, mock_cinderclient):
|
||||
api.cinder.VERSIONS._active = None
|
||||
page_size = settings.API_RESULT_PAGE_SIZE
|
||||
volumes = self.cinder_volumes.list()
|
||||
@ -80,7 +84,7 @@ class CinderApiTests(test.APIMockTestCase):
|
||||
mock_volumes = volumes[:page_size + 1]
|
||||
expected_volumes = mock_volumes[:-1]
|
||||
|
||||
cinderclient = self.stub_cinderclient()
|
||||
cinderclient = mock_cinderclient.return_value
|
||||
|
||||
volumes_mock = cinderclient.volumes.list
|
||||
volumes_mock.return_value = mock_volumes
|
||||
@ -103,7 +107,8 @@ class CinderApiTests(test.APIMockTestCase):
|
||||
|
||||
@override_settings(API_RESULT_PAGE_SIZE=2)
|
||||
@override_settings(OPENSTACK_API_VERSIONS={'volume': 2})
|
||||
def test_volume_list_paginate_second_page(self):
|
||||
@mock.patch.object(api.cinder, 'cinderclient')
|
||||
def test_volume_list_paginate_second_page(self, mock_cinderclient):
|
||||
api.cinder.VERSIONS._active = None
|
||||
page_size = settings.API_RESULT_PAGE_SIZE
|
||||
volumes = self.cinder_volumes.list()
|
||||
@ -114,7 +119,7 @@ class CinderApiTests(test.APIMockTestCase):
|
||||
expected_volumes = mock_volumes[:-1]
|
||||
marker = expected_volumes[0].id
|
||||
|
||||
cinderclient = self.stub_cinderclient()
|
||||
cinderclient = mock_cinderclient.return_value
|
||||
|
||||
volumes_mock = cinderclient.volumes.list
|
||||
volumes_mock.return_value = mock_volumes
|
||||
@ -138,7 +143,8 @@ class CinderApiTests(test.APIMockTestCase):
|
||||
|
||||
@override_settings(API_RESULT_PAGE_SIZE=2)
|
||||
@override_settings(OPENSTACK_API_VERSIONS={'volume': 2})
|
||||
def test_volume_list_paginate_last_page(self):
|
||||
@mock.patch.object(api.cinder, 'cinderclient')
|
||||
def test_volume_list_paginate_last_page(self, mock_cinderclient):
|
||||
api.cinder.VERSIONS._active = None
|
||||
page_size = settings.API_RESULT_PAGE_SIZE
|
||||
volumes = self.cinder_volumes.list()
|
||||
@ -149,7 +155,7 @@ class CinderApiTests(test.APIMockTestCase):
|
||||
expected_volumes = mock_volumes
|
||||
marker = expected_volumes[0].id
|
||||
|
||||
cinderclient = self.stub_cinderclient()
|
||||
cinderclient = mock_cinderclient.return_value
|
||||
|
||||
volumes_mock = cinderclient.volumes.list
|
||||
volumes_mock.return_value = mock_volumes
|
||||
@ -173,7 +179,8 @@ class CinderApiTests(test.APIMockTestCase):
|
||||
|
||||
@override_settings(API_RESULT_PAGE_SIZE=2)
|
||||
@override_settings(OPENSTACK_API_VERSIONS={'volume': 2})
|
||||
def test_volume_list_paginate_back_from_some_page(self):
|
||||
@mock.patch.object(api.cinder, 'cinderclient')
|
||||
def test_volume_list_paginate_back_from_some_page(self, mock_cinderclient):
|
||||
api.cinder.VERSIONS._active = None
|
||||
page_size = settings.API_RESULT_PAGE_SIZE
|
||||
volumes = self.cinder_volumes.list()
|
||||
@ -184,7 +191,7 @@ class CinderApiTests(test.APIMockTestCase):
|
||||
expected_volumes = mock_volumes[:-1]
|
||||
marker = expected_volumes[0].id
|
||||
|
||||
cinderclient = self.stub_cinderclient()
|
||||
cinderclient = mock_cinderclient.return_value
|
||||
|
||||
volumes_mock = cinderclient.volumes.list
|
||||
volumes_mock.return_value = mock_volumes
|
||||
@ -208,7 +215,8 @@ class CinderApiTests(test.APIMockTestCase):
|
||||
|
||||
@override_settings(API_RESULT_PAGE_SIZE=2)
|
||||
@override_settings(OPENSTACK_API_VERSIONS={'volume': 2})
|
||||
def test_volume_list_paginate_back_to_first_page(self):
|
||||
@mock.patch.object(api.cinder, 'cinderclient')
|
||||
def test_volume_list_paginate_back_to_first_page(self, mock_cinderclient):
|
||||
api.cinder.VERSIONS._active = None
|
||||
page_size = settings.API_RESULT_PAGE_SIZE
|
||||
volumes = self.cinder_volumes.list()
|
||||
@ -219,7 +227,7 @@ class CinderApiTests(test.APIMockTestCase):
|
||||
expected_volumes = mock_volumes
|
||||
marker = expected_volumes[0].id
|
||||
|
||||
cinderclient = self.stub_cinderclient()
|
||||
cinderclient = mock_cinderclient.return_value
|
||||
|
||||
volumes_mock = cinderclient.volumes.list
|
||||
volumes_mock.return_value = mock_volumes
|
||||
@ -241,10 +249,11 @@ class CinderApiTests(test.APIMockTestCase):
|
||||
self.assertTrue(more_data)
|
||||
self.assertFalse(prev_data)
|
||||
|
||||
def test_volume_snapshot_list(self):
|
||||
@mock.patch.object(api.cinder, 'cinderclient')
|
||||
def test_volume_snapshot_list(self, mock_cinderclient):
|
||||
search_opts = {'all_tenants': 1}
|
||||
volume_snapshots = self.cinder_volume_snapshots.list()
|
||||
cinderclient = self.stub_cinderclient()
|
||||
cinderclient = mock_cinderclient.return_value
|
||||
|
||||
snapshots_mock = cinderclient.volume_snapshots.list
|
||||
snapshots_mock.return_value = volume_snapshots
|
||||
@ -252,7 +261,9 @@ class CinderApiTests(test.APIMockTestCase):
|
||||
api.cinder.volume_snapshot_list(self.request, search_opts=search_opts)
|
||||
snapshots_mock.assert_called_once_with(search_opts=search_opts)
|
||||
|
||||
def test_volume_snapshot_list_no_volume_configured(self):
|
||||
@mock.patch.object(api.cinder, 'cinderclient')
|
||||
def test_volume_snapshot_list_no_volume_configured(self,
|
||||
mock_cinderclient):
|
||||
# remove volume from service catalog
|
||||
catalog = self.service_catalog
|
||||
for service in catalog:
|
||||
@ -261,7 +272,7 @@ class CinderApiTests(test.APIMockTestCase):
|
||||
search_opts = {'all_tenants': 1}
|
||||
volume_snapshots = self.cinder_volume_snapshots.list()
|
||||
|
||||
cinderclient = self.stub_cinderclient()
|
||||
cinderclient = mock_cinderclient.return_value
|
||||
|
||||
snapshots_mock = cinderclient.volume_snapshots.list
|
||||
snapshots_mock.return_value = volume_snapshots
|
||||
@ -270,7 +281,8 @@ class CinderApiTests(test.APIMockTestCase):
|
||||
|
||||
snapshots_mock.assert_called_once_with(search_opts=search_opts)
|
||||
|
||||
def test_volume_type_list_with_qos_associations(self):
|
||||
@mock.patch.object(api.cinder, 'cinderclient')
|
||||
def test_volume_type_list_with_qos_associations(self, mock_cinderclient):
|
||||
volume_types = self.cinder_volume_types.list()
|
||||
# Due to test data limitations, we can only run this test using
|
||||
# one qos spec, which is associated with one volume type.
|
||||
@ -281,7 +293,7 @@ class CinderApiTests(test.APIMockTestCase):
|
||||
qos_specs_only_one = [qos_specs_full[0]]
|
||||
associations = self.cinder_qos_spec_associations.list()
|
||||
|
||||
cinderclient = self.stub_cinderclient()
|
||||
cinderclient = mock_cinderclient.return_value
|
||||
|
||||
volume_types_mock = cinderclient.volume_types.list
|
||||
volume_types_mock.return_value = volume_types
|
||||
@ -300,13 +312,14 @@ class CinderApiTests(test.APIMockTestCase):
|
||||
qos_associations_mock.assert_called_once_with(qos_specs_only_one[0].id)
|
||||
self.assertEqual(associate_spec, qos_specs_only_one[0].name)
|
||||
|
||||
def test_volume_type_get_with_qos_association(self):
|
||||
@mock.patch.object(api.cinder, 'cinderclient')
|
||||
def test_volume_type_get_with_qos_association(self, mock_cinderclient):
|
||||
volume_type = self.cinder_volume_types.first()
|
||||
qos_specs_full = self.cinder_qos_specs.list()
|
||||
qos_specs_only_one = [qos_specs_full[0]]
|
||||
associations = self.cinder_qos_spec_associations.list()
|
||||
|
||||
cinderclient = self.stub_cinderclient()
|
||||
cinderclient = mock_cinderclient.return_value
|
||||
|
||||
volume_types_mock = cinderclient.volume_types.get
|
||||
volume_types_mock.return_value = volume_type
|
||||
@ -327,7 +340,8 @@ class CinderApiTests(test.APIMockTestCase):
|
||||
qos_associations_mock.assert_called_once_with(qos_specs_only_one[0].id)
|
||||
self.assertEqual(associate_spec, qos_specs_only_one[0].name)
|
||||
|
||||
def test_absolute_limits_with_negative_values(self):
|
||||
@mock.patch.object(api.cinder, 'cinderclient')
|
||||
def test_absolute_limits_with_negative_values(self, mock_cinderclient):
|
||||
values = {"maxTotalVolumes": -1, "totalVolumesUsed": -1}
|
||||
expected_results = {"maxTotalVolumes": float("inf"),
|
||||
"totalVolumesUsed": 0}
|
||||
@ -343,7 +357,7 @@ class CinderApiTests(test.APIMockTestCase):
|
||||
|
||||
fake_limits = [FakeLimit(k, v) for k, v in values.items()]
|
||||
|
||||
cinderclient = self.stub_cinderclient()
|
||||
cinderclient = mock_cinderclient.return_value
|
||||
mock_limit = cinderclient.limits.get
|
||||
mock_limit.return_value = AbsoluteLimit(fake_limits)
|
||||
|
||||
@ -354,9 +368,10 @@ class CinderApiTests(test.APIMockTestCase):
|
||||
|
||||
mock_limit.assert_called_once()
|
||||
|
||||
def test_pool_list(self):
|
||||
@mock.patch.object(api.cinder, 'cinderclient')
|
||||
def test_pool_list(self, mock_cinderclient):
|
||||
pools = self.cinder_pools.list()
|
||||
cinderclient = self.stub_cinderclient()
|
||||
cinderclient = mock_cinderclient.return_value
|
||||
|
||||
cinderclient.pools.list.return_value = pools
|
||||
|
||||
@ -364,9 +379,10 @@ class CinderApiTests(test.APIMockTestCase):
|
||||
|
||||
cinderclient.pools.list.assert_called_once_with(detailed=True)
|
||||
|
||||
def test_volume_type_default(self):
|
||||
@mock.patch.object(api.cinder, 'cinderclient')
|
||||
def test_volume_type_default(self, mock_cinderclient):
|
||||
volume_type = self.cinder_volume_types.first()
|
||||
cinderclient = self.stub_cinderclient()
|
||||
cinderclient = mock_cinderclient.return_value
|
||||
|
||||
cinderclient.volume_types.default.return_value = volume_type
|
||||
|
||||
@ -374,9 +390,10 @@ class CinderApiTests(test.APIMockTestCase):
|
||||
self.assertEqual(default_volume_type, volume_type)
|
||||
cinderclient.volume_types.default.assert_called_once()
|
||||
|
||||
def test_cgroup_list(self):
|
||||
@mock.patch.object(api.cinder, 'cinderclient')
|
||||
def test_cgroup_list(self, mock_cinderclient):
|
||||
cgroups = self.cinder_consistencygroups.list()
|
||||
cinderclient = self.stub_cinderclient()
|
||||
cinderclient = mock_cinderclient.return_value
|
||||
|
||||
mock_cgs = cinderclient.consistencygroups.list
|
||||
mock_cgs.return_value = cgroups
|
||||
@ -386,9 +403,10 @@ class CinderApiTests(test.APIMockTestCase):
|
||||
self.assertEqual(len(cgroups), len(api_cgroups))
|
||||
mock_cgs.assert_called_once_with(search_opts=None)
|
||||
|
||||
def test_cgroup_get(self):
|
||||
@mock.patch.object(api.cinder, 'cinderclient')
|
||||
def test_cgroup_get(self, mock_cinderclient):
|
||||
cgroup = self.cinder_consistencygroups.first()
|
||||
cinderclient = self.stub_cinderclient()
|
||||
cinderclient = mock_cinderclient.return_value
|
||||
|
||||
mock_cg = cinderclient.consistencygroups.get
|
||||
mock_cg.return_value = cgroup
|
||||
@ -400,10 +418,11 @@ class CinderApiTests(test.APIMockTestCase):
|
||||
self.assertEqual(api_cgroup.description, cgroup.description)
|
||||
self.assertEqual(api_cgroup.volume_types, cgroup.volume_types)
|
||||
|
||||
def test_cgroup_list_with_vol_type_names(self):
|
||||
@mock.patch.object(api.cinder, 'cinderclient')
|
||||
def test_cgroup_list_with_vol_type_names(self, mock_cinderclient):
|
||||
cgroups = self.cinder_consistencygroups.list()
|
||||
volume_types_list = self.cinder_volume_types.list()
|
||||
cinderclient = self.stub_cinderclient()
|
||||
cinderclient = mock_cinderclient.return_value
|
||||
|
||||
mock_cgs = cinderclient.consistencygroups.list
|
||||
mock_cgs.return_value = cgroups
|
||||
@ -421,9 +440,10 @@ class CinderApiTests(test.APIMockTestCase):
|
||||
self.assertEqual(volume_types_list[i].name,
|
||||
api_cgroups[0].volume_type_names[i])
|
||||
|
||||
def test_cgsnapshot_list(self):
|
||||
@mock.patch.object(api.cinder, 'cinderclient')
|
||||
def test_cgsnapshot_list(self, mock_cinderclient):
|
||||
cgsnapshots = self.cinder_cg_snapshots.list()
|
||||
cinderclient = self.stub_cinderclient()
|
||||
cinderclient = mock_cinderclient.return_value
|
||||
|
||||
mock_cg_snapshots = cinderclient.cgsnapshots.list
|
||||
mock_cg_snapshots.return_value = cgsnapshots
|
||||
@ -433,9 +453,10 @@ class CinderApiTests(test.APIMockTestCase):
|
||||
mock_cg_snapshots.assert_called_once_with(search_opts=None)
|
||||
self.assertEqual(len(cgsnapshots), len(api_cgsnapshots))
|
||||
|
||||
def test_cgsnapshot_get(self):
|
||||
@mock.patch.object(api.cinder, 'cinderclient')
|
||||
def test_cgsnapshot_get(self, mock_cinderclient):
|
||||
cgsnapshot = self.cinder_cg_snapshots.first()
|
||||
cinderclient = self.stub_cinderclient()
|
||||
cinderclient = mock_cinderclient.return_value
|
||||
|
||||
mock_cg_snapshot = cinderclient.cgsnapshots.get
|
||||
mock_cg_snapshot.return_value = cgsnapshot
|
||||
|
@ -31,14 +31,15 @@ class GlanceApiTests(test.APIMockTestCase):
|
||||
api.glance.VERSIONS.clear_active_cache()
|
||||
|
||||
@override_settings(API_RESULT_PAGE_SIZE=2)
|
||||
def test_image_list_detailed_no_pagination(self):
|
||||
@mock.patch.object(api.glance, 'glanceclient')
|
||||
def test_image_list_detailed_no_pagination(self, mock_glanceclient):
|
||||
# Verify that all images are returned even with a small page size
|
||||
api_images = self.images_api.list()
|
||||
expected_images = self.images.list() # Wrapped Images
|
||||
filters = {}
|
||||
limit = getattr(settings, 'API_RESULT_LIMIT', 1000)
|
||||
|
||||
glanceclient = self.stub_glanceclient()
|
||||
glanceclient = mock_glanceclient.return_value
|
||||
mock_images_list = glanceclient.images.list
|
||||
mock_images_list.return_value = iter(api_images)
|
||||
|
||||
@ -55,7 +56,8 @@ class GlanceApiTests(test.APIMockTestCase):
|
||||
self.assertFalse(has_prev)
|
||||
|
||||
@override_settings(API_RESULT_PAGE_SIZE=2)
|
||||
def test_image_list_detailed_sort_options(self):
|
||||
@mock.patch.object(api.glance, 'glanceclient')
|
||||
def test_image_list_detailed_sort_options(self, mock_glanceclient):
|
||||
# Verify that sort_dir and sort_key work
|
||||
api_images = self.images_api.list()
|
||||
expected_images = self.images.list() # Wrapped Images
|
||||
@ -64,7 +66,7 @@ class GlanceApiTests(test.APIMockTestCase):
|
||||
sort_dir = 'asc'
|
||||
sort_key = 'min_disk'
|
||||
|
||||
glanceclient = self.stub_glanceclient()
|
||||
glanceclient = mock_glanceclient.return_value
|
||||
mock_images_list = glanceclient.images.list
|
||||
mock_images_list.return_value = iter(api_images)
|
||||
|
||||
@ -83,7 +85,9 @@ class GlanceApiTests(test.APIMockTestCase):
|
||||
self.assertFalse(has_prev)
|
||||
|
||||
@override_settings(API_RESULT_PAGE_SIZE=2)
|
||||
def test_image_list_detailed_pagination_more_page_size(self):
|
||||
@mock.patch.object(api.glance, 'glanceclient')
|
||||
def test_image_list_detailed_pagination_more_page_size(self,
|
||||
mock_glanceclient):
|
||||
# The total snapshot count is over page size, should return
|
||||
# page_size images.
|
||||
filters = {}
|
||||
@ -94,7 +98,7 @@ class GlanceApiTests(test.APIMockTestCase):
|
||||
expected_images = self.images.list() # Wrapped Images
|
||||
images_iter = iter(api_images)
|
||||
|
||||
glanceclient = self.stub_glanceclient()
|
||||
glanceclient = mock_glanceclient.return_value
|
||||
mock_images_list = glanceclient.images.list
|
||||
mock_images_list.return_value = images_iter
|
||||
|
||||
@ -121,7 +125,9 @@ class GlanceApiTests(test.APIMockTestCase):
|
||||
len(api_images) - len(expected_images) - 1)
|
||||
|
||||
@override_settings(API_RESULT_PAGE_SIZE=20)
|
||||
def test_image_list_detailed_pagination_less_page_size(self):
|
||||
@mock.patch.object(api.glance, 'glanceclient')
|
||||
def test_image_list_detailed_pagination_less_page_size(self,
|
||||
mock_glanceclient):
|
||||
# The total image count is less than page size, should return images
|
||||
# more, prev should return False.
|
||||
filters = {}
|
||||
@ -131,7 +137,7 @@ class GlanceApiTests(test.APIMockTestCase):
|
||||
api_images = self.images_api.list()
|
||||
expected_images = self.images.list() # Wrapped Images
|
||||
|
||||
glanceclient = self.stub_glanceclient()
|
||||
glanceclient = mock_glanceclient.return_value
|
||||
mock_images_list = glanceclient.images.list
|
||||
mock_images_list.return_value = iter(api_images)
|
||||
|
||||
@ -153,7 +159,9 @@ class GlanceApiTests(test.APIMockTestCase):
|
||||
self.assertFalse(has_prev)
|
||||
|
||||
@override_settings(API_RESULT_PAGE_SIZE=9)
|
||||
def test_image_list_detailed_pagination_equal_page_size(self):
|
||||
@mock.patch.object(api.glance, 'glanceclient')
|
||||
def test_image_list_detailed_pagination_equal_page_size(self,
|
||||
mock_glanceclient):
|
||||
# The total image count equals page size, should return
|
||||
# page_size images. more, prev should return False
|
||||
filters = {}
|
||||
@ -163,7 +171,7 @@ class GlanceApiTests(test.APIMockTestCase):
|
||||
api_images = self.images_api.list()
|
||||
expected_images = self.images.list() # Wrapped Images
|
||||
|
||||
glanceclient = self.stub_glanceclient()
|
||||
glanceclient = mock_glanceclient.return_value
|
||||
mock_images_list = glanceclient.images.list
|
||||
mock_images_list.return_value = iter(api_images)
|
||||
|
||||
@ -185,7 +193,8 @@ class GlanceApiTests(test.APIMockTestCase):
|
||||
self.assertEqual(len(expected_images), len(images))
|
||||
|
||||
@override_settings(API_RESULT_PAGE_SIZE=2)
|
||||
def test_image_list_detailed_pagination_marker(self):
|
||||
@mock.patch.object(api.glance, 'glanceclient')
|
||||
def test_image_list_detailed_pagination_marker(self, mock_glanceclient):
|
||||
# Tests getting a second page with a marker.
|
||||
filters = {}
|
||||
page_size = settings.API_RESULT_PAGE_SIZE
|
||||
@ -196,7 +205,7 @@ class GlanceApiTests(test.APIMockTestCase):
|
||||
expected_images = self.images.list()[page_size:] # Wrapped Images
|
||||
images_iter = iter(api_images)
|
||||
|
||||
glanceclient = self.stub_glanceclient()
|
||||
glanceclient = mock_glanceclient.return_value
|
||||
mock_images_list = glanceclient.images.list
|
||||
mock_images_list.return_value = images_iter
|
||||
|
||||
@ -222,7 +231,9 @@ class GlanceApiTests(test.APIMockTestCase):
|
||||
len(api_images) - len(expected_images) - 1)
|
||||
|
||||
@override_settings(API_RESULT_PAGE_SIZE=2)
|
||||
def test_image_list_detailed_pagination_marker_prev(self):
|
||||
@mock.patch.object(api.glance, 'glanceclient')
|
||||
def test_image_list_detailed_pagination_marker_prev(self,
|
||||
mock_glanceclient):
|
||||
# Tests getting previous page with a marker.
|
||||
filters = {}
|
||||
page_size = settings.API_RESULT_PAGE_SIZE
|
||||
@ -233,7 +244,7 @@ class GlanceApiTests(test.APIMockTestCase):
|
||||
expected_images = self.images.list()[page_size:] # Wrapped Images
|
||||
images_iter = iter(api_images)
|
||||
|
||||
glanceclient = self.stub_glanceclient()
|
||||
glanceclient = mock_glanceclient.return_value
|
||||
mock_images_list = glanceclient.images.list
|
||||
mock_images_list.return_value = images_iter
|
||||
|
||||
@ -259,8 +270,9 @@ class GlanceApiTests(test.APIMockTestCase):
|
||||
self.assertEqual(len(list(images_iter)),
|
||||
len(api_images) - len(expected_images) - 1)
|
||||
|
||||
def test_get_image_empty_name(self):
|
||||
glanceclient = self.stub_glanceclient()
|
||||
@mock.patch.object(api.glance, 'glanceclient')
|
||||
def test_get_image_empty_name(self, mock_glanceclient):
|
||||
glanceclient = mock_glanceclient.return_value
|
||||
mock_images_get = glanceclient.images.get
|
||||
mock_images_get.return_value = self.empty_name_image
|
||||
|
||||
@ -269,11 +281,12 @@ class GlanceApiTests(test.APIMockTestCase):
|
||||
mock_images_get.assert_called_once_with('empty')
|
||||
self.assertIsNone(image.name)
|
||||
|
||||
def test_metadefs_namespace_list(self):
|
||||
@mock.patch.object(api.glance, 'glanceclient')
|
||||
def test_metadefs_namespace_list(self, mock_glanceclient):
|
||||
metadata_defs = self.metadata_defs.list()
|
||||
limit = getattr(settings, 'API_RESULT_LIMIT', 1000)
|
||||
|
||||
glanceclient = self.stub_glanceclient()
|
||||
glanceclient = mock_glanceclient.return_value
|
||||
mock_metadefs_list = glanceclient.metadefs_namespace.list
|
||||
mock_metadefs_list.return_value = metadata_defs
|
||||
|
||||
@ -290,13 +303,15 @@ class GlanceApiTests(test.APIMockTestCase):
|
||||
self.assertFalse(more)
|
||||
self.assertFalse(prev)
|
||||
|
||||
def test_metadefs_namespace_list_with_properties_target(self):
|
||||
@mock.patch.object(api.glance, 'glanceclient')
|
||||
def test_metadefs_namespace_list_with_properties_target(self,
|
||||
mock_glanceclient):
|
||||
metadata_defs = self.metadata_defs.list()
|
||||
limit = getattr(settings, 'API_RESULT_LIMIT', 1000)
|
||||
filters = {'resource_types': ['OS::Cinder::Volume'],
|
||||
'properties_target': 'user'}
|
||||
|
||||
glanceclient = self.stub_glanceclient()
|
||||
glanceclient = mock_glanceclient.return_value
|
||||
mock_metadefs_list = glanceclient.metadefs_namespace.list
|
||||
mock_metadefs_list.return_value = metadata_defs
|
||||
|
||||
@ -323,7 +338,9 @@ class GlanceApiTests(test.APIMockTestCase):
|
||||
res_types = api.glance.metadefs_resource_types_list(self.request)
|
||||
self.assertItemsEqual(res_types, [])
|
||||
|
||||
def _test_image_create_external_upload(self, api_version=2):
|
||||
@mock.patch.object(api.glance, 'glanceclient')
|
||||
def _test_image_create_external_upload(self, mock_glanceclient,
|
||||
api_version=2):
|
||||
expected_image = self.images.first()
|
||||
service = base.get_service_from_catalog(self.service_catalog, 'image')
|
||||
base_url = base.get_url_for_service(service, 'RegionOne', 'publicURL')
|
||||
@ -333,7 +350,7 @@ class GlanceApiTests(test.APIMockTestCase):
|
||||
url_template = '%s/v2/images/%s/file'
|
||||
upload_url = url_template % (base_url, expected_image.id)
|
||||
|
||||
glanceclient = self.stub_glanceclient()
|
||||
glanceclient = mock_glanceclient.return_value
|
||||
mock_image_create = glanceclient.images.create
|
||||
mock_image_create.return_value = expected_image
|
||||
|
||||
|
@ -31,7 +31,8 @@ class RoleAPITests(test.APIMockTestCase):
|
||||
self.role = self.roles.member
|
||||
self.roles = self.roles.list()
|
||||
|
||||
def test_remove_tenant_user(self):
|
||||
@mock.patch.object(api.keystone, 'keystoneclient')
|
||||
def test_remove_tenant_user(self, mock_keystoneclient):
|
||||
"""Tests api.keystone.remove_tenant_user
|
||||
|
||||
Verifies that remove_tenant_user is called with the right arguments
|
||||
@ -40,7 +41,7 @@ class RoleAPITests(test.APIMockTestCase):
|
||||
There are no assertions in this test because the checking is handled
|
||||
by mox in the VerifyAll() call in tearDown().
|
||||
"""
|
||||
keystoneclient = self.stub_keystoneclient()
|
||||
keystoneclient = mock_keystoneclient.return_value
|
||||
tenant = self.tenants.first()
|
||||
|
||||
keystoneclient.roles.roles_for_user.return_value = self.roles
|
||||
@ -59,8 +60,9 @@ class RoleAPITests(test.APIMockTestCase):
|
||||
for role in self.roles]
|
||||
)
|
||||
|
||||
def test_get_default_role(self):
|
||||
keystoneclient = self.stub_keystoneclient()
|
||||
@mock.patch.object(api.keystone, 'keystoneclient')
|
||||
def test_get_default_role(self, mock_keystoneclient):
|
||||
keystoneclient = mock_keystoneclient.return_value
|
||||
keystoneclient.roles.list.return_value = self.roles
|
||||
|
||||
role = api.keystone.get_default_role(self.request)
|
||||
|
@ -26,7 +26,8 @@ from openstack_dashboard.test import helpers as test
|
||||
class NetworkApiNeutronTests(test.APIMockTestCase):
|
||||
def setUp(self):
|
||||
super(NetworkApiNeutronTests, self).setUp()
|
||||
self.qclient = self.stub_neutronclient()
|
||||
neutronclient = mock.patch.object(api.neutron, 'neutronclient').start()
|
||||
self.qclient = neutronclient.return_value
|
||||
|
||||
def _get_expected_addresses(self, server, no_fip_expected=True):
|
||||
server_ports = self.ports.filter(device_id=server.id)
|
||||
|
@ -27,11 +27,12 @@ from openstack_dashboard.test import helpers as test
|
||||
|
||||
|
||||
class NeutronApiTests(test.APIMockTestCase):
|
||||
def test_network_list(self):
|
||||
@mock.patch.object(api.neutron, 'neutronclient')
|
||||
def test_network_list(self, mock_neutronclient):
|
||||
networks = {'networks': self.api_networks.list()}
|
||||
subnets = {'subnets': self.api_subnets.list()}
|
||||
|
||||
neutronclient = self.stub_neutronclient()
|
||||
neutronclient = mock_neutronclient.return_value
|
||||
neutronclient.list_networks.return_value = networks
|
||||
neutronclient.list_subnets.return_value = subnets
|
||||
|
||||
@ -163,7 +164,8 @@ class NeutronApiTests(test.APIMockTestCase):
|
||||
'foo': 'bar'},
|
||||
should_called=['non_shared', 'external'])
|
||||
|
||||
def test_network_get(self):
|
||||
@mock.patch.object(api.neutron, 'neutronclient')
|
||||
def test_network_get(self, mock_neutronclient):
|
||||
network = {'network': self.api_networks.first()}
|
||||
subnet = {'subnet': self.api_subnets.first()}
|
||||
subnetv6 = {'subnet': self.api_subnets.list()[1]}
|
||||
@ -171,7 +173,7 @@ class NeutronApiTests(test.APIMockTestCase):
|
||||
subnet_id = self.api_networks.first()['subnets'][0]
|
||||
subnetv6_id = self.api_networks.first()['subnets'][1]
|
||||
|
||||
neutronclient = self.stub_neutronclient()
|
||||
neutronclient = mock_neutronclient.return_value
|
||||
neutronclient.show_network.return_value = network
|
||||
neutronclient.show_subnet.side_effect = [subnet, subnetv6]
|
||||
|
||||
@ -186,12 +188,13 @@ class NeutronApiTests(test.APIMockTestCase):
|
||||
mock.call(subnetv6_id),
|
||||
])
|
||||
|
||||
def test_network_get_with_subnet_get_notfound(self):
|
||||
@mock.patch.object(api.neutron, 'neutronclient')
|
||||
def test_network_get_with_subnet_get_notfound(self, mock_neutronclient):
|
||||
network = {'network': self.api_networks.first()}
|
||||
network_id = self.api_networks.first()['id']
|
||||
subnet_id = self.api_networks.first()['subnets'][0]
|
||||
|
||||
neutronclient = self.stub_neutronclient()
|
||||
neutronclient = mock_neutronclient.return_value
|
||||
neutronclient.show_network.return_value = network
|
||||
neutronclient.show_subnet.side_effect = neutron_exc.NotFound
|
||||
|
||||
@ -203,11 +206,12 @@ class NeutronApiTests(test.APIMockTestCase):
|
||||
neutronclient.show_network.assert_called_once_with(network_id)
|
||||
neutronclient.show_subnet.assert_called_once_with(subnet_id)
|
||||
|
||||
def test_network_create(self):
|
||||
@mock.patch.object(api.neutron, 'neutronclient')
|
||||
def test_network_create(self, mock_neutronclient):
|
||||
network = {'network': self.api_networks.first()}
|
||||
form_data = {'network': {'name': 'net1',
|
||||
'tenant_id': self.request.user.project_id}}
|
||||
neutronclient = self.stub_neutronclient()
|
||||
neutronclient = mock_neutronclient.return_value
|
||||
neutronclient.create_network.return_value = network
|
||||
|
||||
ret_val = api.neutron.network_create(self.request, name='net1')
|
||||
@ -215,11 +219,12 @@ class NeutronApiTests(test.APIMockTestCase):
|
||||
self.assertIsInstance(ret_val, api.neutron.Network)
|
||||
neutronclient.create_network.assert_called_once_with(body=form_data)
|
||||
|
||||
def test_network_update(self):
|
||||
@mock.patch.object(api.neutron, 'neutronclient')
|
||||
def test_network_update(self, mock_neutronclient):
|
||||
network = {'network': self.api_networks.first()}
|
||||
network_id = self.api_networks.first()['id']
|
||||
|
||||
neutronclient = self.stub_neutronclient()
|
||||
neutronclient = mock_neutronclient.return_value
|
||||
form_data = {'network': {'name': 'net1'}}
|
||||
neutronclient.update_network.return_value = network
|
||||
|
||||
@ -230,20 +235,22 @@ class NeutronApiTests(test.APIMockTestCase):
|
||||
neutronclient.update_network.assert_called_once_with(network_id,
|
||||
body=form_data)
|
||||
|
||||
def test_network_delete(self):
|
||||
@mock.patch.object(api.neutron, 'neutronclient')
|
||||
def test_network_delete(self, mock_neutronclient):
|
||||
network_id = self.api_networks.first()['id']
|
||||
|
||||
neutronclient = self.stub_neutronclient()
|
||||
neutronclient = mock_neutronclient.return_value
|
||||
neutronclient.delete_network.return_value = None
|
||||
|
||||
api.neutron.network_delete(self.request, network_id)
|
||||
|
||||
neutronclient.delete_network.assert_called_once_with(network_id)
|
||||
|
||||
def test_get_network_ip_availability(self):
|
||||
@mock.patch.object(api.neutron, 'neutronclient')
|
||||
def test_get_network_ip_availability(self, mock_neutronclient):
|
||||
network = {'network': self.api_networks.first()}
|
||||
mock_ip_availability = self.ip_availability.get()
|
||||
neutronclient = self.stub_neutronclient()
|
||||
neutronclient = mock_neutronclient.return_value
|
||||
neutronclient.show_network_ip_availability.return_value = \
|
||||
mock_ip_availability
|
||||
|
||||
@ -254,10 +261,11 @@ class NeutronApiTests(test.APIMockTestCase):
|
||||
neutronclient.show_network_ip_availability.assert_called_once_with(
|
||||
network)
|
||||
|
||||
def test_subnet_network_ip_availability(self):
|
||||
@mock.patch.object(api.neutron, 'neutronclient')
|
||||
def test_subnet_network_ip_availability(self, mock_neutronclient):
|
||||
network = {'network': self.api_networks.first()}
|
||||
mock_ip_availability = self.ip_availability.get()
|
||||
neutronclient = self.stub_neutronclient()
|
||||
neutronclient = mock_neutronclient.return_value
|
||||
neutronclient.show_network_ip_availability.return_value = \
|
||||
mock_ip_availability
|
||||
|
||||
@ -271,10 +279,11 @@ class NeutronApiTests(test.APIMockTestCase):
|
||||
neutronclient.show_network_ip_availability.assert_called_once_with(
|
||||
network)
|
||||
|
||||
def test_subnet_list(self):
|
||||
@mock.patch.object(api.neutron, 'neutronclient')
|
||||
def test_subnet_list(self, mock_neutronclient):
|
||||
subnets = {'subnets': self.api_subnets.list()}
|
||||
|
||||
neutronclient = self.stub_neutronclient()
|
||||
neutronclient = mock_neutronclient.return_value
|
||||
neutronclient.list_subnets.return_value = subnets
|
||||
|
||||
ret_val = api.neutron.subnet_list(self.request)
|
||||
@ -283,11 +292,12 @@ class NeutronApiTests(test.APIMockTestCase):
|
||||
self.assertIsInstance(n, api.neutron.Subnet)
|
||||
neutronclient.list_subnets.assert_called_once_with()
|
||||
|
||||
def test_subnet_get(self):
|
||||
@mock.patch.object(api.neutron, 'neutronclient')
|
||||
def test_subnet_get(self, mock_neutronclient):
|
||||
subnet = {'subnet': self.api_subnets.first()}
|
||||
subnet_id = self.api_subnets.first()['id']
|
||||
|
||||
neutronclient = self.stub_neutronclient()
|
||||
neutronclient = mock_neutronclient.return_value
|
||||
neutronclient.show_subnet.return_value = subnet
|
||||
|
||||
ret_val = api.neutron.subnet_get(self.request, subnet_id)
|
||||
@ -295,7 +305,8 @@ class NeutronApiTests(test.APIMockTestCase):
|
||||
self.assertIsInstance(ret_val, api.neutron.Subnet)
|
||||
neutronclient.show_subnet.assert_called_once_with(subnet_id)
|
||||
|
||||
def test_subnet_create(self):
|
||||
@mock.patch.object(api.neutron, 'neutronclient')
|
||||
def test_subnet_create(self, mock_neutronclient):
|
||||
subnet_data = self.api_subnets.first()
|
||||
params = {'network_id': subnet_data['network_id'],
|
||||
'tenant_id': subnet_data['tenant_id'],
|
||||
@ -304,7 +315,7 @@ class NeutronApiTests(test.APIMockTestCase):
|
||||
'ip_version': subnet_data['ip_version'],
|
||||
'gateway_ip': subnet_data['gateway_ip']}
|
||||
|
||||
neutronclient = self.stub_neutronclient()
|
||||
neutronclient = mock_neutronclient.return_value
|
||||
neutronclient.create_subnet.return_value = {'subnet': subnet_data}
|
||||
|
||||
ret_val = api.neutron.subnet_create(self.request, **params)
|
||||
@ -313,13 +324,14 @@ class NeutronApiTests(test.APIMockTestCase):
|
||||
neutronclient.create_subnet.assert_called_once_with(
|
||||
body={'subnet': params})
|
||||
|
||||
def test_subnet_update(self):
|
||||
@mock.patch.object(api.neutron, 'neutronclient')
|
||||
def test_subnet_update(self, mock_neutronclient):
|
||||
subnet_data = self.api_subnets.first()
|
||||
subnet_id = subnet_data['id']
|
||||
params = {'name': subnet_data['name'],
|
||||
'gateway_ip': subnet_data['gateway_ip']}
|
||||
|
||||
neutronclient = self.stub_neutronclient()
|
||||
neutronclient = mock_neutronclient.return_value
|
||||
neutronclient.update_subnet.return_value = {'subnet': subnet_data}
|
||||
|
||||
ret_val = api.neutron.subnet_update(self.request, subnet_id, **params)
|
||||
@ -328,20 +340,22 @@ class NeutronApiTests(test.APIMockTestCase):
|
||||
neutronclient.update_subnet.assert_called_once_with(
|
||||
subnet_id, body={'subnet': params})
|
||||
|
||||
def test_subnet_delete(self):
|
||||
@mock.patch.object(api.neutron, 'neutronclient')
|
||||
def test_subnet_delete(self, mock_neutronclient):
|
||||
subnet_id = self.api_subnets.first()['id']
|
||||
|
||||
neutronclient = self.stub_neutronclient()
|
||||
neutronclient = mock_neutronclient.return_value
|
||||
neutronclient.delete_subnet.return_value = None
|
||||
|
||||
api.neutron.subnet_delete(self.request, subnet_id)
|
||||
|
||||
neutronclient.delete_subnet.assert_called_once_with(subnet_id)
|
||||
|
||||
def test_subnetpool_list(self):
|
||||
@mock.patch.object(api.neutron, 'neutronclient')
|
||||
def test_subnetpool_list(self, mock_neutronclient):
|
||||
subnetpools = {'subnetpools': self.api_subnetpools.list()}
|
||||
|
||||
neutronclient = self.stub_neutronclient()
|
||||
neutronclient = mock_neutronclient.return_value
|
||||
neutronclient.list_subnetpools.return_value = subnetpools
|
||||
|
||||
ret_val = api.neutron.subnetpool_list(self.request)
|
||||
@ -350,11 +364,12 @@ class NeutronApiTests(test.APIMockTestCase):
|
||||
self.assertIsInstance(n, api.neutron.SubnetPool)
|
||||
neutronclient.list_subnetpools.assert_called_once_with()
|
||||
|
||||
def test_subnetpool_get(self):
|
||||
@mock.patch.object(api.neutron, 'neutronclient')
|
||||
def test_subnetpool_get(self, mock_neutronclient):
|
||||
subnetpool = {'subnetpool': self.api_subnetpools.first()}
|
||||
subnetpool_id = self.api_subnetpools.first()['id']
|
||||
|
||||
neutronclient = self.stub_neutronclient()
|
||||
neutronclient = mock_neutronclient.return_value
|
||||
neutronclient.show_subnetpool.return_value = subnetpool
|
||||
|
||||
ret_val = api.neutron.subnetpool_get(self.request, subnetpool_id)
|
||||
@ -362,13 +377,14 @@ class NeutronApiTests(test.APIMockTestCase):
|
||||
self.assertIsInstance(ret_val, api.neutron.SubnetPool)
|
||||
neutronclient.show_subnetpool.assert_called_once_with(subnetpool_id)
|
||||
|
||||
def test_subnetpool_create(self):
|
||||
@mock.patch.object(api.neutron, 'neutronclient')
|
||||
def test_subnetpool_create(self, mock_neutronclient):
|
||||
subnetpool_data = self.api_subnetpools.first()
|
||||
params = {'name': subnetpool_data['name'],
|
||||
'prefixes': subnetpool_data['prefixes'],
|
||||
'tenant_id': subnetpool_data['tenant_id']}
|
||||
|
||||
neutronclient = self.stub_neutronclient()
|
||||
neutronclient = mock_neutronclient.return_value
|
||||
neutronclient.create_subnetpool.return_value = {'subnetpool':
|
||||
subnetpool_data}
|
||||
|
||||
@ -378,13 +394,14 @@ class NeutronApiTests(test.APIMockTestCase):
|
||||
neutronclient.create_subnetpool.assert_called_once_with(
|
||||
body={'subnetpool': params})
|
||||
|
||||
def test_subnetpool_update(self):
|
||||
@mock.patch.object(api.neutron, 'neutronclient')
|
||||
def test_subnetpool_update(self, mock_neutronclient):
|
||||
subnetpool_data = self.api_subnetpools.first()
|
||||
subnetpool_id = subnetpool_data['id']
|
||||
params = {'name': subnetpool_data['name'],
|
||||
'prefixes': subnetpool_data['prefixes']}
|
||||
|
||||
neutronclient = self.stub_neutronclient()
|
||||
neutronclient = mock_neutronclient.return_value
|
||||
neutronclient.update_subnetpool.return_value = {'subnetpool':
|
||||
subnetpool_data}
|
||||
|
||||
@ -395,20 +412,22 @@ class NeutronApiTests(test.APIMockTestCase):
|
||||
neutronclient.update_subnetpool.assert_called_once_with(
|
||||
subnetpool_id, body={'subnetpool': params})
|
||||
|
||||
def test_subnetpool_delete(self):
|
||||
@mock.patch.object(api.neutron, 'neutronclient')
|
||||
def test_subnetpool_delete(self, mock_neutronclient):
|
||||
subnetpool_id = self.api_subnetpools.first()['id']
|
||||
|
||||
neutronclient = self.stub_neutronclient()
|
||||
neutronclient = mock_neutronclient.return_value
|
||||
neutronclient.delete_subnetpool.return_value = None
|
||||
|
||||
api.neutron.subnetpool_delete(self.request, subnetpool_id)
|
||||
|
||||
neutronclient.delete_subnetpool.assert_called_once_with(subnetpool_id)
|
||||
|
||||
def test_port_list(self):
|
||||
@mock.patch.object(api.neutron, 'neutronclient')
|
||||
def test_port_list(self, mock_neutronclient):
|
||||
ports = {'ports': self.api_ports.list()}
|
||||
|
||||
neutronclient = self.stub_neutronclient()
|
||||
neutronclient = mock_neutronclient.return_value
|
||||
neutronclient.list_ports.return_value = ports
|
||||
|
||||
ret_val = api.neutron.port_list(self.request)
|
||||
@ -418,15 +437,17 @@ class NeutronApiTests(test.APIMockTestCase):
|
||||
neutronclient.list_ports.assert_called_once_with()
|
||||
|
||||
@mock.patch.object(api.neutron, 'is_extension_supported')
|
||||
def test_port_list_with_trunk_types(self, mock_is_extension_supported):
|
||||
@mock.patch.object(api.neutron, 'neutronclient')
|
||||
def test_port_list_with_trunk_types(
|
||||
self, mock_neutronclient, mock_is_extension_supported):
|
||||
ports = self.api_tp_ports.list()
|
||||
trunks = self.api_tp_trunks.list()
|
||||
|
||||
# list_extensions is decorated with memoized_with_request,
|
||||
# stub_neutronclient is not called. We need to mock it separately.
|
||||
# list_extensions is decorated with memoized_with_request, so
|
||||
# neutronclient() is not called. We need to mock it separately.
|
||||
mock_is_extension_supported.return_value = True # trunk
|
||||
|
||||
neutronclient = self.stub_neutronclient()
|
||||
neutronclient = mock_neutronclient.return_value
|
||||
neutronclient.list_ports.return_value = {'ports': ports}
|
||||
neutronclient.list_trunks.return_value = {'trunks': trunks}
|
||||
|
||||
@ -460,15 +481,16 @@ class NeutronApiTests(test.APIMockTestCase):
|
||||
neutronclient.list_trunks.assert_called_once_with()
|
||||
|
||||
@mock.patch.object(api.neutron, 'is_extension_supported')
|
||||
@mock.patch.object(api.neutron, 'neutronclient')
|
||||
def test_port_list_with_trunk_types_without_trunk_extension(
|
||||
self, mock_is_extension_supported):
|
||||
self, mock_neutronclient, mock_is_extension_supported):
|
||||
ports = self.api_tp_ports.list()
|
||||
|
||||
# list_extensions is decorated with memoized_with_request,
|
||||
# the simpliest way is to mock it directly.
|
||||
mock_is_extension_supported.return_value = False # trunk
|
||||
|
||||
neutronclient = self.stub_neutronclient()
|
||||
neutronclient = mock_neutronclient.return_value
|
||||
neutronclient.list_ports.return_value = {'ports': ports}
|
||||
|
||||
ret_val = api.neutron.port_list_with_trunk_types(self.request)
|
||||
@ -484,11 +506,12 @@ class NeutronApiTests(test.APIMockTestCase):
|
||||
test.IsHttpRequest(), 'trunk')
|
||||
neutronclient.list_ports.assert_called_once_with()
|
||||
|
||||
def test_port_get(self):
|
||||
@mock.patch.object(api.neutron, 'neutronclient')
|
||||
def test_port_get(self, mock_neutronclient):
|
||||
port = {'port': self.api_ports.first()}
|
||||
port_id = self.api_ports.first()['id']
|
||||
|
||||
neutronclient = self.stub_neutronclient()
|
||||
neutronclient = mock_neutronclient.return_value
|
||||
neutronclient.show_port.return_value = port
|
||||
|
||||
ret_val = api.neutron.port_get(self.request, port_id)
|
||||
@ -496,14 +519,15 @@ class NeutronApiTests(test.APIMockTestCase):
|
||||
self.assertIsInstance(ret_val, api.neutron.Port)
|
||||
neutronclient.show_port.assert_called_once_with(port_id)
|
||||
|
||||
def test_port_create(self):
|
||||
@mock.patch.object(api.neutron, 'neutronclient')
|
||||
def test_port_create(self, mock_neutronclient):
|
||||
port = {'port': self.api_ports.first()}
|
||||
params = {'network_id': port['port']['network_id'],
|
||||
'tenant_id': port['port']['tenant_id'],
|
||||
'name': port['port']['name'],
|
||||
'device_id': port['port']['device_id']}
|
||||
|
||||
neutronclient = self.stub_neutronclient()
|
||||
neutronclient = mock_neutronclient.return_value
|
||||
neutronclient.create_port.return_value = port
|
||||
|
||||
ret_val = api.neutron.port_create(self.request, **params)
|
||||
@ -513,13 +537,14 @@ class NeutronApiTests(test.APIMockTestCase):
|
||||
neutronclient.create_port.assert_called_once_with(
|
||||
body={'port': params})
|
||||
|
||||
def test_port_update(self):
|
||||
@mock.patch.object(api.neutron, 'neutronclient')
|
||||
def test_port_update(self, mock_neutronclient):
|
||||
port_data = self.api_ports.first()
|
||||
port_id = port_data['id']
|
||||
params = {'name': port_data['name'],
|
||||
'device_id': port_data['device_id']}
|
||||
|
||||
neutronclient = self.stub_neutronclient()
|
||||
neutronclient = mock_neutronclient.return_value
|
||||
neutronclient.update_port.return_value = {'port': port_data}
|
||||
|
||||
ret_val = api.neutron.port_update(self.request, port_id, **params)
|
||||
@ -529,19 +554,21 @@ class NeutronApiTests(test.APIMockTestCase):
|
||||
neutronclient.update_port.assert_called_once_with(
|
||||
port_id, body={'port': params})
|
||||
|
||||
def test_port_delete(self):
|
||||
@mock.patch.object(api.neutron, 'neutronclient')
|
||||
def test_port_delete(self, mock_neutronclient):
|
||||
port_id = self.api_ports.first()['id']
|
||||
|
||||
neutronclient = self.stub_neutronclient()
|
||||
neutronclient = mock_neutronclient.return_value
|
||||
neutronclient.delete_port.return_value = None
|
||||
|
||||
api.neutron.port_delete(self.request, port_id)
|
||||
|
||||
neutronclient.delete_port.assert_called_once_with(port_id)
|
||||
|
||||
def test_trunk_list(self):
|
||||
@mock.patch.object(api.neutron, 'neutronclient')
|
||||
def test_trunk_list(self, mock_neutronclient):
|
||||
trunks = {'trunks': self.api_trunks.list()}
|
||||
neutron_client = self.stub_neutronclient()
|
||||
neutron_client = mock_neutronclient.return_value
|
||||
neutron_client.list_trunks.return_value = trunks
|
||||
|
||||
ret_val = api.neutron.trunk_list(self.request)
|
||||
@ -550,11 +577,12 @@ class NeutronApiTests(test.APIMockTestCase):
|
||||
self.assertIsInstance(t, api.neutron.Trunk)
|
||||
neutron_client.list_trunks.assert_called_once_with()
|
||||
|
||||
def test_trunk_show(self):
|
||||
@mock.patch.object(api.neutron, 'neutronclient')
|
||||
def test_trunk_show(self, mock_neutronclient):
|
||||
trunk = {'trunk': self.api_trunks.first()}
|
||||
trunk_id = self.api_trunks.first()['id']
|
||||
|
||||
neutron_client = self.stub_neutronclient()
|
||||
neutron_client = mock_neutronclient.return_value
|
||||
neutron_client.show_trunk.return_value = trunk
|
||||
|
||||
ret_val = api.neutron.trunk_show(self.request, trunk_id)
|
||||
@ -579,13 +607,14 @@ class NeutronApiTests(test.APIMockTestCase):
|
||||
self.assertEqual(obj.name_or_id, trunk_dict['name_or_id'])
|
||||
self.assertEqual(2, trunk_dict['subport_count'])
|
||||
|
||||
def test_trunk_create(self):
|
||||
@mock.patch.object(api.neutron, 'neutronclient')
|
||||
def test_trunk_create(self, mock_neutronclient):
|
||||
trunk = {'trunk': self.api_trunks.first()}
|
||||
params = {'name': trunk['trunk']['name'],
|
||||
'port_id': trunk['trunk']['port_id'],
|
||||
'project_id': trunk['trunk']['project_id']}
|
||||
|
||||
neutronclient = self.stub_neutronclient()
|
||||
neutronclient = mock_neutronclient.return_value
|
||||
neutronclient.create_trunk.return_value = trunk
|
||||
|
||||
ret_val = api.neutron.trunk_create(self.request, **params)
|
||||
@ -595,17 +624,19 @@ class NeutronApiTests(test.APIMockTestCase):
|
||||
neutronclient.create_trunk.assert_called_once_with(
|
||||
body={'trunk': params})
|
||||
|
||||
def test_trunk_delete(self):
|
||||
@mock.patch.object(api.neutron, 'neutronclient')
|
||||
def test_trunk_delete(self, mock_neutronclient):
|
||||
trunk_id = self.api_trunks.first()['id']
|
||||
|
||||
neutronclient = self.stub_neutronclient()
|
||||
neutronclient = mock_neutronclient.return_value
|
||||
neutronclient.delete_trunk.return_value = None
|
||||
|
||||
api.neutron.trunk_delete(self.request, trunk_id)
|
||||
|
||||
neutronclient.delete_trunk.assert_called_once_with(trunk_id)
|
||||
|
||||
def test_trunk_update_details(self):
|
||||
@mock.patch.object(api.neutron, 'neutronclient')
|
||||
def test_trunk_update_details(self, mock_neutronclient):
|
||||
trunk_data = self.api_trunks.first()
|
||||
trunk_id = trunk_data['id']
|
||||
old_trunk = {'name': trunk_data['name'],
|
||||
@ -619,7 +650,7 @@ class NeutronApiTests(test.APIMockTestCase):
|
||||
'port_id': trunk_data['port_id'],
|
||||
'admin_state_up': trunk_data['admin_state_up']}
|
||||
|
||||
neutronclient = self.stub_neutronclient()
|
||||
neutronclient = mock_neutronclient.return_value
|
||||
neutronclient.update_trunk.return_value = {'trunk': new_trunk}
|
||||
|
||||
ret_val = api.neutron.trunk_update(self.request, trunk_id,
|
||||
@ -631,7 +662,8 @@ class NeutronApiTests(test.APIMockTestCase):
|
||||
neutronclient.update_trunk.assert_called_once_with(
|
||||
trunk_id, body={'trunk': {'name': 'foo'}})
|
||||
|
||||
def test_trunk_update_add_subports(self):
|
||||
@mock.patch.object(api.neutron, 'neutronclient')
|
||||
def test_trunk_update_add_subports(self, mock_neutronclient):
|
||||
trunk_data = self.api_trunks.first()
|
||||
trunk_id = trunk_data['id']
|
||||
old_trunk = {'name': trunk_data['name'],
|
||||
@ -650,7 +682,7 @@ class NeutronApiTests(test.APIMockTestCase):
|
||||
'segmentation_type': 'vlan'}],
|
||||
'admin_state_up': trunk_data['admin_state_up']}
|
||||
|
||||
neutronclient = self.stub_neutronclient()
|
||||
neutronclient = mock_neutronclient.return_value
|
||||
neutronclient.trunk_add_subports.return_value = {'trunk': new_trunk}
|
||||
|
||||
ret_val = api.neutron.trunk_update(self.request, trunk_id,
|
||||
@ -665,7 +697,8 @@ class NeutronApiTests(test.APIMockTestCase):
|
||||
'segmentation_type': 'vlan'}]}
|
||||
)
|
||||
|
||||
def test_trunk_update_remove_subports(self):
|
||||
@mock.patch.object(api.neutron, 'neutronclient')
|
||||
def test_trunk_update_remove_subports(self, mock_neutronclient):
|
||||
trunk_data = self.api_trunks.first()
|
||||
trunk_id = trunk_data['id']
|
||||
old_trunk = {'name': trunk_data['name'],
|
||||
@ -684,7 +717,7 @@ class NeutronApiTests(test.APIMockTestCase):
|
||||
'sub_ports': [],
|
||||
'admin_state_up': trunk_data['admin_state_up']}
|
||||
|
||||
neutronclient = self.stub_neutronclient()
|
||||
neutronclient = mock_neutronclient.return_value
|
||||
neutronclient.trunk_remove_subports.return_value = {'trunk': new_trunk}
|
||||
|
||||
ret_val = api.neutron.trunk_update(self.request, trunk_id,
|
||||
@ -699,10 +732,11 @@ class NeutronApiTests(test.APIMockTestCase):
|
||||
old_trunk['sub_ports'][0]['port_id']}]}
|
||||
)
|
||||
|
||||
def test_router_list(self):
|
||||
@mock.patch.object(api.neutron, 'neutronclient')
|
||||
def test_router_list(self, mock_neutronclient):
|
||||
routers = {'routers': self.api_routers.list()}
|
||||
|
||||
neutronclient = self.stub_neutronclient()
|
||||
neutronclient = mock_neutronclient.return_value
|
||||
neutronclient.list_routers.return_value = routers
|
||||
|
||||
ret_val = api.neutron.router_list(self.request)
|
||||
@ -711,11 +745,12 @@ class NeutronApiTests(test.APIMockTestCase):
|
||||
self.assertIsInstance(n, api.neutron.Router)
|
||||
neutronclient.list_routers.assert_called_once_with()
|
||||
|
||||
def test_router_get(self):
|
||||
@mock.patch.object(api.neutron, 'neutronclient')
|
||||
def test_router_get(self, mock_neutronclient):
|
||||
router = {'router': self.api_routers.first()}
|
||||
router_id = self.api_routers.first()['id']
|
||||
|
||||
neutronclient = self.stub_neutronclient()
|
||||
neutronclient = mock_neutronclient.return_value
|
||||
neutronclient.show_router.return_value = router
|
||||
|
||||
ret_val = api.neutron.router_get(self.request, router_id)
|
||||
@ -723,10 +758,11 @@ class NeutronApiTests(test.APIMockTestCase):
|
||||
self.assertIsInstance(ret_val, api.neutron.Router)
|
||||
neutronclient.show_router.assert_called_once_with(router_id)
|
||||
|
||||
def test_router_create(self):
|
||||
@mock.patch.object(api.neutron, 'neutronclient')
|
||||
def test_router_create(self, mock_neutronclient):
|
||||
router = {'router': self.api_routers.first()}
|
||||
|
||||
neutronclient = self.stub_neutronclient()
|
||||
neutronclient = mock_neutronclient.return_value
|
||||
form_data = {'router': {'name': 'router1',
|
||||
'tenant_id': self.request.user.project_id}}
|
||||
neutronclient.create_router.return_value = router
|
||||
@ -736,21 +772,23 @@ class NeutronApiTests(test.APIMockTestCase):
|
||||
self.assertIsInstance(ret_val, api.neutron.Router)
|
||||
neutronclient.create_router.assert_called_once_with(body=form_data)
|
||||
|
||||
def test_router_delete(self):
|
||||
@mock.patch.object(api.neutron, 'neutronclient')
|
||||
def test_router_delete(self, mock_neutronclient):
|
||||
router_id = self.api_routers.first()['id']
|
||||
|
||||
neutronclient = self.stub_neutronclient()
|
||||
neutronclient = mock_neutronclient.return_value
|
||||
neutronclient.delete_router.return_value = None
|
||||
|
||||
api.neutron.router_delete(self.request, router_id)
|
||||
|
||||
neutronclient.delete_router.assert_called_once_with(router_id)
|
||||
|
||||
def test_router_add_interface(self):
|
||||
@mock.patch.object(api.neutron, 'neutronclient')
|
||||
def test_router_add_interface(self, mock_neutronclient):
|
||||
subnet_id = self.api_subnets.first()['id']
|
||||
router_id = self.api_routers.first()['id']
|
||||
|
||||
neutronclient = self.stub_neutronclient()
|
||||
neutronclient = mock_neutronclient.return_value
|
||||
form_data = {'subnet_id': subnet_id}
|
||||
neutronclient.add_interface_router.return_value = None
|
||||
|
||||
@ -760,11 +798,12 @@ class NeutronApiTests(test.APIMockTestCase):
|
||||
neutronclient.add_interface_router.assert_called_once_with(router_id,
|
||||
form_data)
|
||||
|
||||
def test_router_remove_interface(self):
|
||||
@mock.patch.object(api.neutron, 'neutronclient')
|
||||
def test_router_remove_interface(self, mock_neutronclient):
|
||||
router_id = self.api_routers.first()['id']
|
||||
fake_port = self.api_ports.first()['id']
|
||||
|
||||
neutronclient = self.stub_neutronclient()
|
||||
neutronclient = mock_neutronclient.return_value
|
||||
neutronclient.remove_interface_router.return_value = None
|
||||
|
||||
api.neutron.router_remove_interface(
|
||||
@ -773,7 +812,7 @@ class NeutronApiTests(test.APIMockTestCase):
|
||||
neutronclient.remove_interface_router.assert_called_once_with(
|
||||
router_id, {'port_id': fake_port})
|
||||
|
||||
# stub_neutronclient does not work because api.neutron.list_extensions
|
||||
# Mocking neutronclient() does not work because api.neutron.list_extensions
|
||||
# is decorated with memoized_with_request, so we need to mock
|
||||
# neutronclient.v2_0.client directly.
|
||||
@mock.patch('neutronclient.v2_0.client.Client.list_extensions')
|
||||
@ -787,11 +826,12 @@ class NeutronApiTests(test.APIMockTestCase):
|
||||
|
||||
mock_list_extensions.assert_called_once_with()
|
||||
|
||||
def test_router_static_route_list(self):
|
||||
@mock.patch.object(api.neutron, 'neutronclient')
|
||||
def test_router_static_route_list(self, mock_neutronclient):
|
||||
router = {'router': self.api_routers_with_routes.first()}
|
||||
router_id = self.api_routers_with_routes.first()['id']
|
||||
|
||||
neutronclient = self.stub_neutronclient()
|
||||
neutronclient = mock_neutronclient.return_value
|
||||
neutronclient.show_router.return_value = router
|
||||
|
||||
ret_val = api.neutron.router_static_route_list(self.request, router_id)
|
||||
@ -799,14 +839,15 @@ class NeutronApiTests(test.APIMockTestCase):
|
||||
self.assertIsInstance(ret_val[0], api.neutron.RouterStaticRoute)
|
||||
neutronclient.show_router.assert_called_once_with(router_id)
|
||||
|
||||
def test_router_static_route_remove(self):
|
||||
@mock.patch.object(api.neutron, 'neutronclient')
|
||||
def test_router_static_route_remove(self, mock_neutronclient):
|
||||
router = {'router': self.api_routers_with_routes.first()}
|
||||
router_id = self.api_routers_with_routes.first()['id']
|
||||
post_router = copy.deepcopy(router)
|
||||
route = api.neutron.RouterStaticRoute(post_router['router']
|
||||
['routes'].pop())
|
||||
|
||||
neutronclient = self.stub_neutronclient()
|
||||
neutronclient = mock_neutronclient.return_value
|
||||
neutronclient.show_router.return_value = router
|
||||
neutronclient.update_router.return_value = post_router
|
||||
|
||||
@ -818,7 +859,8 @@ class NeutronApiTests(test.APIMockTestCase):
|
||||
neutronclient.update_router.assert_called_once_with(
|
||||
router_id, body=body)
|
||||
|
||||
def test_router_static_route_add(self):
|
||||
@mock.patch.object(api.neutron, 'neutronclient')
|
||||
def test_router_static_route_add(self, mock_neutronclient):
|
||||
router = {'router': self.api_routers_with_routes.first()}
|
||||
router_id = self.api_routers_with_routes.first()['id']
|
||||
post_router = copy.deepcopy(router)
|
||||
@ -826,7 +868,7 @@ class NeutronApiTests(test.APIMockTestCase):
|
||||
post_router['router']['routes'].insert(0, route)
|
||||
body = {'router': {'routes': post_router['router']['routes']}}
|
||||
|
||||
neutronclient = self.stub_neutronclient()
|
||||
neutronclient = mock_neutronclient.return_value
|
||||
neutronclient.show_router.return_value = router
|
||||
neutronclient.update_router.return_value = post_router
|
||||
|
||||
@ -946,7 +988,8 @@ class NeutronApiTests(test.APIMockTestCase):
|
||||
def test_get_router_ha_permission_without_l3_ha_extension(self):
|
||||
self._test_get_router_ha_permission_with_policy_check(False)
|
||||
|
||||
def test_list_resources_with_long_filters(self):
|
||||
@mock.patch.object(api.neutron, 'neutronclient')
|
||||
def test_list_resources_with_long_filters(self, mock_neutronclient):
|
||||
# In this tests, port_list is called with id=[10 port ID]
|
||||
# filter. It generates about 40*10 char length URI.
|
||||
# Each port ID is converted to "id=<UUID>&" in URI and
|
||||
@ -962,7 +1005,7 @@ class NeutronApiTests(test.APIMockTestCase):
|
||||
for i in range(10)]
|
||||
port_ids = tuple([port['id'] for port in ports])
|
||||
|
||||
neutronclient = self.stub_neutronclient()
|
||||
neutronclient = mock_neutronclient.return_value
|
||||
uri_len_exc = neutron_exc.RequestURITooLong(excess=220)
|
||||
list_ports_retval = [uri_len_exc]
|
||||
for i in range(0, 10, 4):
|
||||
@ -981,11 +1024,12 @@ class NeutronApiTests(test.APIMockTestCase):
|
||||
expected_calls.append(mock.call(id=tuple(port_ids[i:i + 4])))
|
||||
neutronclient.list_ports.assert_has_calls(expected_calls)
|
||||
|
||||
def test_qos_policies_list(self):
|
||||
@mock.patch.object(api.neutron, 'neutronclient')
|
||||
def test_qos_policies_list(self, mock_neutronclient):
|
||||
exp_policies = self.qos_policies.list()
|
||||
api_qos_policies = {'policies': self.api_qos_policies.list()}
|
||||
|
||||
neutronclient = self.stub_neutronclient()
|
||||
neutronclient = mock_neutronclient.return_value
|
||||
neutronclient.list_qos_policies.return_value = api_qos_policies
|
||||
|
||||
ret_val = api.neutron.policy_list(self.request)
|
||||
@ -995,11 +1039,12 @@ class NeutronApiTests(test.APIMockTestCase):
|
||||
self.assertEqual(exp_policies[0].name, ret_val[0].name)
|
||||
neutronclient.list_qos_policies.assert_called_once_with()
|
||||
|
||||
def test_qos_policy_create(self):
|
||||
@mock.patch.object(api.neutron, 'neutronclient')
|
||||
def test_qos_policy_create(self, mock_neutronclient):
|
||||
qos_policy = self.api_qos_policies.first()
|
||||
post_data = {'policy': {'name': qos_policy['name']}}
|
||||
|
||||
neutronclient = self.stub_neutronclient()
|
||||
neutronclient = mock_neutronclient.return_value
|
||||
neutronclient.create_qos_policy.return_value = {'policy': qos_policy}
|
||||
|
||||
ret_val = api.neutron.policy_create(self.request,
|
||||
@ -1014,7 +1059,8 @@ class NeutronApiSecurityGroupTests(test.APIMockTestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(NeutronApiSecurityGroupTests, self).setUp()
|
||||
self.qclient = self.stub_neutronclient()
|
||||
neutronclient = mock.patch.object(api.neutron, 'neutronclient').start()
|
||||
self.qclient = neutronclient.return_value
|
||||
self.sg_dict = dict([(sg['id'], sg['name']) for sg
|
||||
in self.api_security_groups.list()])
|
||||
|
||||
@ -1224,7 +1270,8 @@ class NeutronApiFloatingIpTests(test.APIMockTestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(NeutronApiFloatingIpTests, self).setUp()
|
||||
self.qclient = self.stub_neutronclient()
|
||||
neutronclient = mock.patch.object(api.neutron, 'neutronclient').start()
|
||||
self.qclient = neutronclient.return_value
|
||||
|
||||
@override_settings(OPENSTACK_NEUTRON_NETWORK={'enable_router': True})
|
||||
def test_floating_ip_supported(self):
|
||||
@ -1395,7 +1442,8 @@ class NeutronApiFloatingIpTests(test.APIMockTestCase):
|
||||
'enable_fip_topology_check': True,
|
||||
}
|
||||
)
|
||||
def test_floating_ip_target_list(self):
|
||||
@mock.patch.object(api.nova, 'novaclient')
|
||||
def test_floating_ip_target_list(self, mock_novaclient):
|
||||
ports = self.api_ports.list()
|
||||
# Port on the first subnet is connected to a router
|
||||
# attached to external network in neutron_data.
|
||||
@ -1419,7 +1467,7 @@ class NeutronApiFloatingIpTests(test.APIMockTestCase):
|
||||
filters = {'tenant_id': self.request.user.tenant_id}
|
||||
self.qclient.list_ports.return_value = {'ports': ports}
|
||||
servers = self.servers.list()
|
||||
novaclient = self.stub_novaclient()
|
||||
novaclient = mock_novaclient.return_value
|
||||
ver = mock.Mock(min_version='2.1', version='2.45')
|
||||
novaclient.versions.get_current.return_value = ver
|
||||
novaclient.servers.list.return_value = servers
|
||||
@ -1455,8 +1503,9 @@ class NeutronApiFloatingIpTests(test.APIMockTestCase):
|
||||
self.qclient.list_routers.assert_called_once_with()
|
||||
self.qclient.list_subnets.assert_called_once_with()
|
||||
|
||||
@mock.patch.object(api.nova, 'novaclient')
|
||||
def _test_target_floating_ip_port_by_instance(self, server, ports,
|
||||
candidates):
|
||||
candidates, mock_novaclient):
|
||||
# list_ports and list_networks are called multiple times,
|
||||
# we prepare a list for return values.
|
||||
list_ports_retvals = []
|
||||
@ -1484,7 +1533,7 @@ class NeutronApiFloatingIpTests(test.APIMockTestCase):
|
||||
self.qclient.list_subnets.side_effect = [{'subnets': shared_subs}]
|
||||
|
||||
# _get_server_name()
|
||||
novaclient = self.stub_novaclient()
|
||||
novaclient = mock_novaclient.return_value
|
||||
ver = mock.Mock(min_version='2.1', version='2.45')
|
||||
novaclient.versions.get_current.return_value = ver
|
||||
novaclient.servers.get.return_value = server
|
||||
|
@ -71,13 +71,14 @@ class ComputeApiTests(test.APIMockTestCase):
|
||||
ver.version = version
|
||||
mock_novaclient.versions.get_current.return_value = ver
|
||||
# To handle upgrade_api
|
||||
self.novaclient.api_version = api_versions.APIVersion(version)
|
||||
mock_novaclient.api_version = api_versions.APIVersion(version)
|
||||
|
||||
def test_server_reboot(self):
|
||||
@mock.patch.object(api.nova, 'novaclient')
|
||||
def test_server_reboot(self, mock_novaclient):
|
||||
server = self.servers.first()
|
||||
HARDNESS = servers.REBOOT_HARD
|
||||
|
||||
novaclient = self.stub_novaclient()
|
||||
novaclient = mock_novaclient.return_value
|
||||
novaclient.servers.reboot.return_value = None
|
||||
|
||||
ret_val = api.nova.server_reboot(self.request, server.id)
|
||||
@ -86,11 +87,12 @@ class ComputeApiTests(test.APIMockTestCase):
|
||||
novaclient.servers.reboot.assert_called_once_with(
|
||||
server.id, HARDNESS)
|
||||
|
||||
def test_server_soft_reboot(self):
|
||||
@mock.patch.object(api.nova, 'novaclient')
|
||||
def test_server_soft_reboot(self, mock_novaclient):
|
||||
server = self.servers.first()
|
||||
HARDNESS = servers.REBOOT_SOFT
|
||||
|
||||
novaclient = self.stub_novaclient()
|
||||
novaclient = mock_novaclient.return_value
|
||||
novaclient.servers.reboot.return_value = None
|
||||
|
||||
ret_val = api.nova.server_reboot(self.request, server.id, HARDNESS)
|
||||
@ -99,12 +101,13 @@ class ComputeApiTests(test.APIMockTestCase):
|
||||
novaclient.servers.reboot.assert_called_once_with(
|
||||
server.id, HARDNESS)
|
||||
|
||||
def test_server_vnc_console(self):
|
||||
@mock.patch.object(api.nova, 'novaclient')
|
||||
def test_server_vnc_console(self, mock_novaclient):
|
||||
server = self.servers.first()
|
||||
console = self.servers.vnc_console_data
|
||||
console_type = console["console"]["type"]
|
||||
|
||||
novaclient = self.stub_novaclient()
|
||||
novaclient = mock_novaclient.return_value
|
||||
novaclient.servers.get_vnc_console.return_value = console
|
||||
|
||||
ret_val = api.nova.server_vnc_console(self.request,
|
||||
@ -115,12 +118,13 @@ class ComputeApiTests(test.APIMockTestCase):
|
||||
novaclient.servers.get_vnc_console.assert_called_once_with(
|
||||
server.id, console_type)
|
||||
|
||||
def test_server_spice_console(self):
|
||||
@mock.patch.object(api.nova, 'novaclient')
|
||||
def test_server_spice_console(self, mock_novaclient):
|
||||
server = self.servers.first()
|
||||
console = self.servers.spice_console_data
|
||||
console_type = console["console"]["type"]
|
||||
|
||||
novaclient = self.stub_novaclient()
|
||||
novaclient = mock_novaclient.return_value
|
||||
novaclient.servers.get_spice_console.return_value = console
|
||||
|
||||
ret_val = api.nova.server_spice_console(self.request,
|
||||
@ -130,12 +134,13 @@ class ComputeApiTests(test.APIMockTestCase):
|
||||
novaclient.servers.get_spice_console.assert_called_once_with(
|
||||
server.id, console_type)
|
||||
|
||||
def test_server_rdp_console(self):
|
||||
@mock.patch.object(api.nova, 'novaclient')
|
||||
def test_server_rdp_console(self, mock_novaclient):
|
||||
server = self.servers.first()
|
||||
console = self.servers.rdp_console_data
|
||||
console_type = console["console"]["type"]
|
||||
|
||||
novaclient = self.stub_novaclient()
|
||||
novaclient = mock_novaclient.return_value
|
||||
novaclient.servers.get_rdp_console.return_value = console
|
||||
|
||||
ret_val = api.nova.server_rdp_console(self.request,
|
||||
@ -145,12 +150,13 @@ class ComputeApiTests(test.APIMockTestCase):
|
||||
novaclient.servers.get_rdp_console.assert_called_once_with(
|
||||
server.id, console_type)
|
||||
|
||||
def test_server_mks_console(self):
|
||||
@mock.patch.object(api.nova, 'novaclient')
|
||||
def test_server_mks_console(self, mock_novaclient):
|
||||
server = self.servers.first()
|
||||
console = self.servers.mks_console_data
|
||||
console_type = console["remote_console"]["type"]
|
||||
|
||||
novaclient = self.stub_novaclient()
|
||||
novaclient = mock_novaclient.return_value
|
||||
self._mock_current_version(novaclient, '2.53')
|
||||
novaclient.servers.get_mks_console.return_value = console
|
||||
|
||||
@ -162,10 +168,11 @@ class ComputeApiTests(test.APIMockTestCase):
|
||||
novaclient.servers.get_mks_console.assert_called_once_with(
|
||||
server.id, console_type)
|
||||
|
||||
def test_server_list(self):
|
||||
@mock.patch.object(api.nova, 'novaclient')
|
||||
def test_server_list(self, mock_novaclient):
|
||||
servers = self.servers.list()
|
||||
|
||||
novaclient = self.stub_novaclient()
|
||||
novaclient = mock_novaclient.return_value
|
||||
self._mock_current_version(novaclient, '2.40')
|
||||
novaclient.servers.list.return_value = servers
|
||||
|
||||
@ -178,10 +185,11 @@ class ComputeApiTests(test.APIMockTestCase):
|
||||
novaclient.servers.list.assert_called_once_with(
|
||||
True, {'all_tenants': True})
|
||||
|
||||
def test_server_list_pagination(self):
|
||||
@mock.patch.object(api.nova, 'novaclient')
|
||||
def test_server_list_pagination(self, mock_novaclient):
|
||||
page_size = getattr(settings, 'API_RESULT_PAGE_SIZE', 20)
|
||||
servers = self.servers.list()
|
||||
novaclient = self.stub_novaclient()
|
||||
novaclient = mock_novaclient.return_value
|
||||
self._mock_current_version(novaclient, '2.45')
|
||||
novaclient.servers.list.return_value = servers
|
||||
|
||||
@ -200,10 +208,11 @@ class ComputeApiTests(test.APIMockTestCase):
|
||||
'limit': page_size + 1})
|
||||
|
||||
@override_settings(API_RESULT_PAGE_SIZE=1)
|
||||
def test_server_list_pagination_more(self):
|
||||
@mock.patch.object(api.nova, 'novaclient')
|
||||
def test_server_list_pagination_more(self, mock_novaclient):
|
||||
page_size = getattr(settings, 'API_RESULT_PAGE_SIZE', 1)
|
||||
servers = self.servers.list()
|
||||
novaclient = self.stub_novaclient()
|
||||
novaclient = mock_novaclient.return_value
|
||||
self._mock_current_version(novaclient, '2.45')
|
||||
novaclient.servers.list.return_value = servers[:page_size + 1]
|
||||
|
||||
@ -223,8 +232,9 @@ class ComputeApiTests(test.APIMockTestCase):
|
||||
'marker': None,
|
||||
'limit': page_size + 1})
|
||||
|
||||
def test_usage_get(self):
|
||||
novaclient = self.stub_novaclient()
|
||||
@mock.patch.object(api.nova, 'novaclient')
|
||||
def test_usage_get(self, mock_novaclient):
|
||||
novaclient = mock_novaclient.return_value
|
||||
self._mock_current_version(novaclient, '2.1')
|
||||
novaclient.usages.get.return_value = self.usages.first()
|
||||
|
||||
@ -236,8 +246,9 @@ class ComputeApiTests(test.APIMockTestCase):
|
||||
novaclient.usage.get.assert_called_once_with(
|
||||
self.tenant.id, 'start', 'end')
|
||||
|
||||
def test_usage_get_paginated(self):
|
||||
novaclient = self.stub_novaclient()
|
||||
@mock.patch.object(api.nova, 'novaclient')
|
||||
def test_usage_get_paginated(self, mock_novaclient):
|
||||
novaclient = mock_novaclient.return_value
|
||||
self._mock_current_version(novaclient, '2.40')
|
||||
novaclient.usage.get.side_effect = [
|
||||
self.usages.first(),
|
||||
@ -255,10 +266,11 @@ class ComputeApiTests(test.APIMockTestCase):
|
||||
marker=u'063cf7f3-ded1-4297-bc4c-31eae876cc93'),
|
||||
])
|
||||
|
||||
def test_usage_list(self):
|
||||
@mock.patch.object(api.nova, 'novaclient')
|
||||
def test_usage_list(self, mock_novaclient):
|
||||
usages = self.usages.list()
|
||||
|
||||
novaclient = self.stub_novaclient()
|
||||
novaclient = mock_novaclient.return_value
|
||||
self._mock_current_version(novaclient, '2.1')
|
||||
novaclient.usage.list.return_value = usages
|
||||
|
||||
@ -269,10 +281,11 @@ class ComputeApiTests(test.APIMockTestCase):
|
||||
novaclient.versions.get_current.assert_called_once_with()
|
||||
novaclient.usage.list.assert_called_once_with('start', 'end', True)
|
||||
|
||||
def test_usage_list_paginated(self):
|
||||
@mock.patch.object(api.nova, 'novaclient')
|
||||
def test_usage_list_paginated(self, mock_novaclient):
|
||||
usages = self.usages.list()
|
||||
|
||||
novaclient = self.stub_novaclient()
|
||||
novaclient = mock_novaclient.return_value
|
||||
self._mock_current_version(novaclient, '2.40')
|
||||
novaclient.usage.list.side_effect = [
|
||||
usages,
|
||||
@ -290,10 +303,11 @@ class ComputeApiTests(test.APIMockTestCase):
|
||||
marker=u'063cf7f3-ded1-4297-bc4c-31eae876cc93'),
|
||||
])
|
||||
|
||||
def test_server_get(self):
|
||||
@mock.patch.object(api.nova, 'novaclient')
|
||||
def test_server_get(self, mock_novaclient):
|
||||
server = self.servers.first()
|
||||
|
||||
novaclient = self.stub_novaclient()
|
||||
novaclient = mock_novaclient.return_value
|
||||
self._mock_current_version(novaclient, '2.45')
|
||||
novaclient.servers.get.return_value = server
|
||||
|
||||
@ -302,11 +316,12 @@ class ComputeApiTests(test.APIMockTestCase):
|
||||
novaclient.versions.get_current.assert_called_once_with()
|
||||
novaclient.servers.get.assert_called_once_with(server.id)
|
||||
|
||||
def test_server_metadata_update(self):
|
||||
@mock.patch.object(api.nova, 'novaclient')
|
||||
def test_server_metadata_update(self, mock_novaclient):
|
||||
server = self.servers.first()
|
||||
metadata = {'foo': 'bar'}
|
||||
|
||||
novaclient = self.stub_novaclient()
|
||||
novaclient = mock_novaclient.return_value
|
||||
novaclient.servers.set_meta.return_value = None
|
||||
|
||||
ret_val = api.nova.server_metadata_update(self.request,
|
||||
@ -316,11 +331,12 @@ class ComputeApiTests(test.APIMockTestCase):
|
||||
novaclient.servers.set_meta.assert_called_once_with(server.id,
|
||||
metadata)
|
||||
|
||||
def test_server_metadata_delete(self):
|
||||
@mock.patch.object(api.nova, 'novaclient')
|
||||
def test_server_metadata_delete(self, mock_novaclient):
|
||||
server = self.servers.first()
|
||||
keys = ['a', 'b']
|
||||
|
||||
novaclient = self.stub_novaclient()
|
||||
novaclient = mock_novaclient.return_value
|
||||
novaclient.servers.delete_meta.return_value = None
|
||||
|
||||
ret_val = api.nova.server_metadata_delete(self.request,
|
||||
@ -329,7 +345,8 @@ class ComputeApiTests(test.APIMockTestCase):
|
||||
self.assertIsNone(ret_val)
|
||||
novaclient.servers.delete_meta.assert_called_once_with(server.id, keys)
|
||||
|
||||
def _test_absolute_limits(self, values, expected_results):
|
||||
@mock.patch.object(api.nova, 'novaclient')
|
||||
def _test_absolute_limits(self, values, expected_results, mock_novaclient):
|
||||
limits = mock.Mock()
|
||||
limits.absolute = []
|
||||
for key, val in values.items():
|
||||
@ -338,7 +355,7 @@ class ComputeApiTests(test.APIMockTestCase):
|
||||
limit.value = val
|
||||
limits.absolute.append(limit)
|
||||
|
||||
novaclient = self.stub_novaclient()
|
||||
novaclient = mock_novaclient.return_value
|
||||
novaclient.limits.get.return_value = limits
|
||||
|
||||
ret_val = api.nova.tenant_absolute_limits(self.request, reserved=True)
|
||||
@ -373,9 +390,10 @@ class ComputeApiTests(test.APIMockTestCase):
|
||||
}
|
||||
self._test_absolute_limits(values, expected_results)
|
||||
|
||||
def test_cold_migrate_host_succeed(self):
|
||||
@mock.patch.object(api.nova, 'novaclient')
|
||||
def test_cold_migrate_host_succeed(self, mock_novaclient):
|
||||
hypervisor = self.hypervisors.first()
|
||||
novaclient = self.stub_novaclient()
|
||||
novaclient = mock_novaclient.return_value
|
||||
novaclient.hypervisors.search.return_value = [hypervisor]
|
||||
novaclient.servers.migrate.return_value = None
|
||||
|
||||
@ -386,9 +404,10 @@ class ComputeApiTests(test.APIMockTestCase):
|
||||
novaclient.hypervisors.search.assert_called_once_with('host', True)
|
||||
novaclient.servers.migrate.assert_called_once_with('test_uuid')
|
||||
|
||||
def test_cold_migrate_host_fails(self):
|
||||
@mock.patch.object(api.nova, 'novaclient')
|
||||
def test_cold_migrate_host_fails(self, mock_novaclient):
|
||||
hypervisor = self.hypervisors.first()
|
||||
novaclient = self.stub_novaclient()
|
||||
novaclient = mock_novaclient.return_value
|
||||
novaclient.hypervisors.search.return_value = [hypervisor]
|
||||
novaclient.servers.migrate.side_effect = \
|
||||
nova_exceptions.ClientException(404)
|
||||
@ -399,10 +418,11 @@ class ComputeApiTests(test.APIMockTestCase):
|
||||
novaclient.hypervisors.search.assert_called_once_with('host', True)
|
||||
novaclient.servers.migrate.assert_called_once_with('test_uuid')
|
||||
|
||||
def test_live_migrate_host_with_active_vm(self):
|
||||
@mock.patch.object(api.nova, 'novaclient')
|
||||
def test_live_migrate_host_with_active_vm(self, mock_novaclient):
|
||||
hypervisor = self.hypervisors.first()
|
||||
server = self.servers.first()
|
||||
novaclient = self.stub_novaclient()
|
||||
novaclient = mock_novaclient.return_value
|
||||
server_uuid = hypervisor.servers[0]["uuid"]
|
||||
|
||||
self._mock_current_version(novaclient, '2.45')
|
||||
@ -420,10 +440,11 @@ class ComputeApiTests(test.APIMockTestCase):
|
||||
novaclient.servers.live_migrate.assert_called_once_with(
|
||||
server_uuid, None, True, True)
|
||||
|
||||
def test_live_migrate_host_with_paused_vm(self):
|
||||
@mock.patch.object(api.nova, 'novaclient')
|
||||
def test_live_migrate_host_with_paused_vm(self, mock_novaclient):
|
||||
hypervisor = self.hypervisors.first()
|
||||
server = self.servers.list()[3]
|
||||
novaclient = self.stub_novaclient()
|
||||
novaclient = mock_novaclient.return_value
|
||||
server_uuid = hypervisor.servers[0]["uuid"]
|
||||
|
||||
self._mock_current_version(novaclient, '2.45')
|
||||
@ -440,10 +461,11 @@ class ComputeApiTests(test.APIMockTestCase):
|
||||
novaclient.servers.live_migrate.assert_called_once_with(
|
||||
server_uuid, None, True, True)
|
||||
|
||||
def test_live_migrate_host_without_running_vm(self):
|
||||
@mock.patch.object(api.nova, 'novaclient')
|
||||
def test_live_migrate_host_without_running_vm(self, mock_novaclient):
|
||||
hypervisor = self.hypervisors.first()
|
||||
server = self.servers.list()[1]
|
||||
novaclient = self.stub_novaclient()
|
||||
novaclient = mock_novaclient.return_value
|
||||
server_uuid = hypervisor.servers[0]["uuid"]
|
||||
|
||||
self._mock_current_version(novaclient, '2.45')
|
||||
@ -461,9 +483,10 @@ class ComputeApiTests(test.APIMockTestCase):
|
||||
|
||||
"""Flavor Tests"""
|
||||
|
||||
def test_flavor_list_no_extras(self):
|
||||
@mock.patch.object(api.nova, 'novaclient')
|
||||
def test_flavor_list_no_extras(self, mock_novaclient):
|
||||
flavors = self.flavors.list()
|
||||
novaclient = self.stub_novaclient()
|
||||
novaclient = mock_novaclient.return_value
|
||||
novaclient.flavors.list.return_value = flavors
|
||||
|
||||
api_flavors = api.nova.flavor_list(self.request)
|
||||
@ -471,9 +494,10 @@ class ComputeApiTests(test.APIMockTestCase):
|
||||
self.assertEqual(len(flavors), len(api_flavors))
|
||||
novaclient.flavors.list.assert_called_once_with(is_public=True)
|
||||
|
||||
def test_flavor_get_no_extras(self):
|
||||
@mock.patch.object(api.nova, 'novaclient')
|
||||
def test_flavor_get_no_extras(self, mock_novaclient):
|
||||
flavor = self.flavors.list()[1]
|
||||
novaclient = self.stub_novaclient()
|
||||
novaclient = mock_novaclient.return_value
|
||||
novaclient.flavors.get.return_value = flavor
|
||||
|
||||
api_flavor = api.nova.flavor_get(self.request, flavor.id)
|
||||
@ -481,11 +505,13 @@ class ComputeApiTests(test.APIMockTestCase):
|
||||
self.assertEqual(api_flavor.id, flavor.id)
|
||||
novaclient.flavors.get.assert_called_once_with(flavor.id)
|
||||
|
||||
def _test_flavor_list_paged(self, reversed_order=False, paginate=True):
|
||||
@mock.patch.object(api.nova, 'novaclient')
|
||||
def _test_flavor_list_paged(self, mock_novaclient,
|
||||
reversed_order=False, paginate=True):
|
||||
page_size = getattr(settings, 'API_RESULT_PAGE_SIZE', 20)
|
||||
flavors = self.flavors.list()
|
||||
order = 'asc' if reversed_order else 'desc'
|
||||
novaclient = self.stub_novaclient()
|
||||
novaclient = mock_novaclient.return_value
|
||||
novaclient.flavors.list.return_value = flavors
|
||||
|
||||
api_flavors, has_more, has_prev = api.nova.flavor_list_paged(
|
||||
@ -505,11 +531,12 @@ class ComputeApiTests(test.APIMockTestCase):
|
||||
is_public=True)
|
||||
|
||||
@override_settings(API_RESULT_PAGE_SIZE=1)
|
||||
def test_flavor_list_pagination_more_and_prev(self):
|
||||
@mock.patch.object(api.nova, 'novaclient')
|
||||
def test_flavor_list_pagination_more_and_prev(self, mock_novaclient):
|
||||
page_size = getattr(settings, 'API_RESULT_PAGE_SIZE', 1)
|
||||
flavors = self.flavors.list()
|
||||
marker = flavors[0].id
|
||||
novaclient = self.stub_novaclient()
|
||||
novaclient = mock_novaclient.return_value
|
||||
novaclient.flavors.list.return_value = flavors[1:page_size + 2]
|
||||
|
||||
api_flavors, has_more, has_prev = api.nova\
|
||||
@ -538,10 +565,11 @@ class ComputeApiTests(test.APIMockTestCase):
|
||||
def test_flavor_list_paged_paginate_false(self):
|
||||
self._test_flavor_list_paged(paginate=False)
|
||||
|
||||
def test_flavor_create(self):
|
||||
@mock.patch.object(api.nova, 'novaclient')
|
||||
def test_flavor_create(self, mock_novaclient):
|
||||
flavor = self.flavors.first()
|
||||
|
||||
novaclient = self.stub_novaclient()
|
||||
novaclient = mock_novaclient.return_value
|
||||
novaclient.flavors.create.return_value = flavor
|
||||
|
||||
api_flavor = api.nova.flavor_create(self.request,
|
||||
@ -565,9 +593,10 @@ class ComputeApiTests(test.APIMockTestCase):
|
||||
flavorid='auto', ephemeral=0, swap=0, is_public=True,
|
||||
rxtx_factor=1)
|
||||
|
||||
def test_flavor_delete(self):
|
||||
@mock.patch.object(api.nova, 'novaclient')
|
||||
def test_flavor_delete(self, mock_novaclient):
|
||||
flavor = self.flavors.first()
|
||||
novaclient = self.stub_novaclient()
|
||||
novaclient = mock_novaclient.return_value
|
||||
novaclient.flavors.delete.return_value = None
|
||||
|
||||
api_val = api.nova.flavor_delete(self.request, flavor.id)
|
||||
@ -575,12 +604,13 @@ class ComputeApiTests(test.APIMockTestCase):
|
||||
self.assertIsNone(api_val)
|
||||
novaclient.flavors.delete.assert_called_once_with(flavor.id)
|
||||
|
||||
def test_flavor_access_list(self):
|
||||
@mock.patch.object(api.nova, 'novaclient')
|
||||
def test_flavor_access_list(self, mock_novaclient):
|
||||
flavor_access = self.flavor_access.list()
|
||||
flavor = [f for f in self.flavors.list() if f.id ==
|
||||
flavor_access[0].flavor_id][0]
|
||||
|
||||
novaclient = self.stub_novaclient()
|
||||
novaclient = mock_novaclient.return_value
|
||||
novaclient.flavor_access.list.return_value = flavor_access
|
||||
|
||||
api_flavor_access = api.nova.flavor_access_list(self.request, flavor)
|
||||
@ -591,13 +621,14 @@ class ComputeApiTests(test.APIMockTestCase):
|
||||
self.assertEqual(access.flavor_id, flavor.id)
|
||||
novaclient.flavor_access.list.assert_called_once_with(flavor=flavor)
|
||||
|
||||
def test_add_tenant_to_flavor(self):
|
||||
@mock.patch.object(api.nova, 'novaclient')
|
||||
def test_add_tenant_to_flavor(self, mock_novaclient):
|
||||
flavor_access = [self.flavor_access.first()]
|
||||
flavor = [f for f in self.flavors.list() if f.id ==
|
||||
flavor_access[0].flavor_id][0]
|
||||
tenant = [t for t in self.tenants.list() if t.id ==
|
||||
flavor_access[0].tenant_id][0]
|
||||
novaclient = self.stub_novaclient()
|
||||
novaclient = mock_novaclient.return_value
|
||||
novaclient.flavor_access.add_tenant_access.return_value = flavor_access
|
||||
|
||||
api_flavor_access = api.nova.add_tenant_to_flavor(self.request,
|
||||
@ -613,14 +644,15 @@ class ComputeApiTests(test.APIMockTestCase):
|
||||
novaclient.flavor_access.add_tenant_access.assert_called_once_with(
|
||||
flavor=flavor, tenant=tenant)
|
||||
|
||||
def test_remove_tenant_from_flavor(self):
|
||||
@mock.patch.object(api.nova, 'novaclient')
|
||||
def test_remove_tenant_from_flavor(self, mock_novaclient):
|
||||
flavor_access = [self.flavor_access.first()]
|
||||
flavor = [f for f in self.flavors.list() if f.id ==
|
||||
flavor_access[0].flavor_id][0]
|
||||
tenant = [t for t in self.tenants.list() if t.id ==
|
||||
flavor_access[0].tenant_id][0]
|
||||
|
||||
novaclient = self.stub_novaclient()
|
||||
novaclient = mock_novaclient.return_value
|
||||
novaclient.flavor_access.remove_tenant_access.return_value = []
|
||||
|
||||
api_val = api.nova.remove_tenant_from_flavor(self.request,
|
||||
@ -632,10 +664,11 @@ class ComputeApiTests(test.APIMockTestCase):
|
||||
novaclient.flavor_access.remove_tenant_access.assert_called_once_with(
|
||||
flavor=flavor, tenant=tenant)
|
||||
|
||||
def test_server_group_list(self):
|
||||
@mock.patch.object(api.nova, 'novaclient')
|
||||
def test_server_group_list(self, mock_novaclient):
|
||||
server_groups = self.server_groups.list()
|
||||
|
||||
novaclient = self.stub_novaclient()
|
||||
novaclient = mock_novaclient.return_value
|
||||
novaclient.server_groups.list.return_value = server_groups
|
||||
|
||||
ret_val = api.nova.server_group_list(self.request)
|
||||
@ -644,10 +677,11 @@ class ComputeApiTests(test.APIMockTestCase):
|
||||
self.assertEqual(len(ret_val), len(server_groups))
|
||||
novaclient.server_groups.list.assert_called_once_with()
|
||||
|
||||
def test_server_group_create(self):
|
||||
@mock.patch.object(api.nova, 'novaclient')
|
||||
def test_server_group_create(self, mock_novaclient):
|
||||
servergroup = self.server_groups.first()
|
||||
kwargs = {'name': servergroup.name, 'policies': servergroup.policies}
|
||||
novaclient = self.stub_novaclient()
|
||||
novaclient = mock_novaclient.return_value
|
||||
self._mock_current_version(novaclient, '2.45')
|
||||
novaclient.server_groups.create.return_value = servergroup
|
||||
|
||||
@ -658,9 +692,10 @@ class ComputeApiTests(test.APIMockTestCase):
|
||||
novaclient.versions.get_current.assert_called_once_with()
|
||||
novaclient.server_groups.create.assert_called_once_with(**kwargs)
|
||||
|
||||
def test_server_group_delete(self):
|
||||
@mock.patch.object(api.nova, 'novaclient')
|
||||
def test_server_group_delete(self, mock_novaclient):
|
||||
servergroup_id = self.server_groups.first().id
|
||||
novaclient = self.stub_novaclient()
|
||||
novaclient = mock_novaclient.return_value
|
||||
novaclient.server_groups.delete.return_value = None
|
||||
|
||||
api_val = api.nova.server_group_delete(self.request, servergroup_id)
|
||||
@ -668,9 +703,10 @@ class ComputeApiTests(test.APIMockTestCase):
|
||||
self.assertIsNone(api_val)
|
||||
novaclient.server_groups.delete.assert_called_once_with(servergroup_id)
|
||||
|
||||
def test_server_group_get(self):
|
||||
@mock.patch.object(api.nova, 'novaclient')
|
||||
def test_server_group_get(self, mock_novaclient):
|
||||
servergroup = self.server_groups.first()
|
||||
novaclient = self.stub_novaclient()
|
||||
novaclient = mock_novaclient.return_value
|
||||
self._mock_current_version(novaclient, '2.45')
|
||||
novaclient.server_groups.get.return_value = servergroup
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user