Skip to content

Commit 19ef365

Browse files
committed
tests: Remove '_FakeImageService'
Migrate unit tests over to the new GlanceFixture, allowing us to fully delete '_FakeImageService' and various helpers. Change-Id: I3e3d9bbd32aa2fe0777681f21ba827610d5b3040 Signed-off-by: Stephen Finucane <[email protected]>
1 parent cc45581 commit 19ef365

21 files changed

+110
-592
lines changed

nova/tests/unit/api/openstack/compute/test_access_ips.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
from nova.api.openstack.compute import servers as servers_v21
1818
from nova import exception
1919
from nova import test
20+
from nova.tests import fixtures
2021
from nova.tests.unit.api.openstack import fakes
21-
from nova.tests.unit.image import fake
2222

2323
v4_key = "accessIPv4"
2424
v6_key = "accessIPv6"
@@ -38,7 +38,7 @@ def fake_rebuild(*args, **kwargs):
3838

3939
fakes.stub_out_nw_api(self)
4040
self._set_up_controller()
41-
fake.stub_out_image_service(self)
41+
self.useFixture(fixtures.GlanceFixture(self))
4242
self.stub_out('nova.compute.api.API.get',
4343
# This project_id matches fakes.HTTPRequest.blank.
4444
fakes.fake_compute_get(project_id=fakes.FAKE_PROJECT_ID))

nova/tests/unit/api/openstack/compute/test_availability_zone.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@
2828
from nova import exception
2929
from nova import objects
3030
from nova import test
31+
from nova.tests import fixtures
3132
from nova.tests.unit.api.openstack import fakes
32-
from nova.tests.unit.image import fake
3333
from nova.tests.unit import matchers
3434
from nova.tests.unit.objects import test_service
3535

@@ -208,7 +208,7 @@ def create_db_entry_for_new_instance(*args, **kwargs):
208208
instance.uuid = FAKE_UUID
209209
return instance
210210

211-
fake.stub_out_image_service(self)
211+
self.useFixture(fixtures.GlanceFixture(self))
212212
self.stub_out('nova.compute.api.API.create_db_entry_for_new_instance',
213213
create_db_entry_for_new_instance)
214214

nova/tests/unit/api/openstack/compute/test_disk_config.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@
2424
from nova import exception
2525
from nova import objects
2626
from nova import test
27+
from nova.tests import fixtures
2728
from nova.tests.unit.api.openstack import fakes
2829
from nova.tests.unit import fake_instance
29-
import nova.tests.unit.image.fake
3030

3131

3232
MANUAL_INSTANCE_UUID = fakes.FAKE_UUID
@@ -100,8 +100,7 @@ def _get_expected_msg_for_invalid_disk_config(self):
100100
' not one of [\'AUTO\', \'MANUAL\']", "code": 400}}}}')
101101

102102
def _setup_fake_image_service(self):
103-
self.image_service = nova.tests.unit.image.fake.stub_out_image_service(
104-
self)
103+
self.image_service = self.useFixture(fixtures.GlanceFixture(self))
105104
timestamp = datetime.datetime(2011, 1, 1, 1, 2, 3)
106105
image = {'id': '88580842-f50a-11e2-8d3a-f23c91aec05e',
107106
'name': 'fakeimage7',
@@ -117,10 +116,6 @@ def _setup_fake_image_service(self):
117116
'properties': {'auto_disk_config': 'Disabled'}}
118117
self.image_service.create(None, image)
119118

120-
def tearDown(self):
121-
super(DiskConfigTestCaseV21, self).tearDown()
122-
nova.tests.unit.image.fake.FakeImageService_reset()
123-
124119
def assertDiskConfig(self, dict_, value):
125120
self.assertIn(API_DISK_CONFIG, dict_)
126121
self.assertEqual(dict_[API_DISK_CONFIG], value)

nova/tests/unit/api/openstack/compute/test_server_actions.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@
2929
from nova.image import glance
3030
from nova import objects
3131
from nova import test
32+
from nova.tests import fixtures as nova_fixtures
3233
from nova.tests.unit.api.openstack import fakes
3334
from nova.tests.unit import fake_block_device
3435
from nova.tests.unit import fake_instance
35-
from nova.tests.unit.image import fake
3636

3737

3838
CONF = nova.conf.CONF
@@ -69,7 +69,7 @@ def setUp(self):
6969
self.stub_out('nova.objects.Instance.save', lambda *a, **kw: None)
7070

7171
fakes.stub_out_compute_api_snapshot(self)
72-
fake.stub_out_image_service(self)
72+
self.useFixture(nova_fixtures.GlanceFixture(self))
7373
self.flags(enable_instance_password=True, group='api')
7474
# TODO(stephenfin): Use uuidsentinel instead of this
7575
self._image_href = '155d900f-4e14-4e4c-a73d-069cbf4541e6'
@@ -591,7 +591,7 @@ def return_image_meta(*args, **kwargs):
591591

592592
return image_meta
593593

594-
self.stub_out('nova.tests.unit.image.fake._FakeImageService.show',
594+
self.stub_out('nova.tests.fixtures.GlanceFixture.show',
595595
return_image_meta)
596596
body = {
597597
"rebuild": {
@@ -643,7 +643,7 @@ def return_image_meta(*args, **kwargs):
643643

644644
return image_meta
645645

646-
self.stub_out('nova.tests.unit.image.fake._FakeImageService.show',
646+
self.stub_out('nova.tests.fixtures.GlanceFixture.show',
647647
return_image_meta)
648648
self.stub_out('nova.compute.api.API.get', wrap_get)
649649
self.stub_out('nova.objects.Instance.save', fake_save)

nova/tests/unit/api/openstack/compute/test_servers.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@
7070
from nova.tests.unit import fake_block_device
7171
from nova.tests.unit import fake_flavor
7272
from nova.tests.unit import fake_instance
73-
from nova.tests.unit.image import fake
7473
from nova.tests.unit import matchers
7574
from nova import utils as nova_utils
7675

@@ -228,7 +227,7 @@ def setUp(self):
228227
super(ControllerTest, self).setUp()
229228
fakes.stub_out_nw_api(self)
230229
fakes.stub_out_key_pair_funcs(self)
231-
fake.stub_out_image_service(self)
230+
self.useFixture(nova_fixtures.GlanceFixture(self))
232231
fakes.stub_out_secgroup_api(
233232
self, security_groups=[{'name': 'default'}])
234233
return_server = fakes.fake_compute_get(id=2, availability_zone='nova',
@@ -3066,7 +3065,7 @@ def test_rebuild_instance_with_metadata_value_not_string(self):
30663065
self.controller._action_rebuild, self.req,
30673066
FAKE_UUID, body=self.body)
30683067

3069-
@mock.patch.object(fake._FakeImageService, 'show',
3068+
@mock.patch.object(nova_fixtures.GlanceFixture, 'show',
30703069
return_value=dict(
30713070
id='76fa36fc-c930-4bf3-8c8a-ea2a2420deb6',
30723071
name='public image', is_public=True,
@@ -3082,7 +3081,7 @@ def test_rebuild_instance_fails_when_min_ram_too_small(self, mock_show):
30823081
self.req.environ['nova.context'], self.image_uuid,
30833082
include_locations=False, show_deleted=True)
30843083

3085-
@mock.patch.object(fake._FakeImageService, 'show',
3084+
@mock.patch.object(nova_fixtures.GlanceFixture, 'show',
30863085
return_value=dict(
30873086
id='76fa36fc-c930-4bf3-8c8a-ea2a2420deb6',
30883087
name='public image', is_public=True,
@@ -3098,7 +3097,7 @@ def test_rebuild_instance_fails_when_min_disk_too_small(self, mock_show):
30983097
self.req.environ['nova.context'], self.image_uuid,
30993098
include_locations=False, show_deleted=True)
31003099

3101-
@mock.patch.object(fake._FakeImageService, 'show',
3100+
@mock.patch.object(nova_fixtures.GlanceFixture, 'show',
31023101
return_value=dict(
31033102
id='76fa36fc-c930-4bf3-8c8a-ea2a2420deb6',
31043103
name='public image', is_public=True,
@@ -3120,7 +3119,7 @@ def test_rebuild_instance_name_all_blank(self):
31203119
self.controller._action_rebuild,
31213120
self.req, FAKE_UUID, body=self.body)
31223121

3123-
@mock.patch.object(fake._FakeImageService, 'show',
3122+
@mock.patch.object(nova_fixtures.GlanceFixture, 'show',
31243123
return_value=dict(
31253124
id='76fa36fc-c930-4bf3-8c8a-ea2a2420deb6',
31263125
name='public image', is_public=True,
@@ -3140,7 +3139,7 @@ def fake_get_image(self, context, image_href, **kwargs):
31403139
name='public image', is_public=True, status='active')
31413140

31423141
with test.nested(
3143-
mock.patch.object(fake._FakeImageService, 'show',
3142+
mock.patch.object(nova_fixtures.GlanceFixture, 'show',
31443143
side_effect=fake_get_image),
31453144
mock.patch.object(self.controller.compute_api, 'rebuild',
31463145
side_effect=exception.OnsetFileLimitExceeded)
@@ -4251,7 +4250,7 @@ def server_update_and_get_original(
42514250
return (inst, inst)
42524251

42534252
fakes.stub_out_key_pair_funcs(self)
4254-
fake.stub_out_image_service(self)
4253+
self.useFixture(nova_fixtures.GlanceFixture(self))
42554254
self.stub_out('nova.db.api.instance_create', instance_create)
42564255
self.stub_out('nova.db.api.instance_system_metadata_update',
42574256
lambda *a, **kw: None)
@@ -4384,7 +4383,7 @@ def test_create_server_image_too_large(self):
43844383
"Flavor's disk is too small for requested image."):
43854384
self.controller.create(self.req, body=self.body)
43864385

4387-
@mock.patch.object(fake._FakeImageService, 'show',
4386+
@mock.patch.object(nova_fixtures.GlanceFixture, 'show',
43884387
return_value=dict(
43894388
id='76fa36fc-c930-4bf3-8c8a-ea2a2420deb6',
43904389
status='active',

nova/tests/unit/api/openstack/compute/test_urlmap.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,14 @@
1616
from oslo_serialization import jsonutils
1717

1818
from nova import test
19+
from nova.tests import fixtures
1920
from nova.tests.unit.api.openstack import fakes
20-
import nova.tests.unit.image.fake
2121

2222

2323
class UrlmapTest(test.NoDBTestCase):
2424
def setUp(self):
2525
super(UrlmapTest, self).setUp()
26-
nova.tests.unit.image.fake.stub_out_image_service(self)
27-
28-
def tearDown(self):
29-
super(UrlmapTest, self).tearDown()
30-
nova.tests.unit.image.fake.FakeImageService_reset()
26+
self.useFixture(fixtures.GlanceFixture(self))
3127

3228
def test_path_version_v2(self):
3329
# Test URL path specifying v2 returns v2 content.

nova/tests/unit/compute/test_api.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@
6161
from nova.tests.unit import fake_instance
6262
from nova.tests.unit import fake_request_spec
6363
from nova.tests.unit import fake_volume
64-
from nova.tests.unit.image import fake as fake_image
6564
from nova.tests.unit import matchers
6665
from nova.tests.unit.objects import test_flavor
6766
from nova.tests.unit.objects import test_migration
@@ -3263,7 +3262,7 @@ def fake_get_absolute_limits(context):
32633262
self.useFixture(fixtures.MockPatchObject(
32643263
self.compute_api.compute_rpcapi, 'unquiesce_instance',
32653264
side_effect=fake_unquiesce_instance))
3266-
fake_image.stub_out_image_service(self)
3265+
self.useFixture(nova_fixtures.GlanceFixture(self))
32673266

32683267
with test.nested(
32693268
mock.patch.object(compute_api.API, '_record_action_start'),
@@ -3636,8 +3635,8 @@ def _setup_fake_image_with_disabled_disk_config(self):
36363635
'properties': {"auto_disk_config": "Disabled"},
36373636
}
36383637

3639-
fake_image.stub_out_image_service(self)
3640-
self.stub_out('nova.tests.unit.image.fake._FakeImageService.show',
3638+
self.useFixture(nova_fixtures.GlanceFixture(self))
3639+
self.stub_out('nova.tests.fixtures.GlanceFixture.show',
36413640
lambda obj, context, image_id, **kwargs: self.fake_image)
36423641
return self.fake_image['id']
36433642

@@ -3649,8 +3648,8 @@ def _setup_fake_image_with_invalid_arch(self):
36493648
'properties': {"hw_architecture": "arm64"},
36503649
}
36513650

3652-
fake_image.stub_out_image_service(self)
3653-
self.stub_out('nova.tests.unit.image.fake._FakeImageService.show',
3651+
self.useFixture(nova_fixtures.GlanceFixture(self))
3652+
self.stub_out('nova.tests.fixtures.GlanceFixture.show',
36543653
lambda obj, context, image_id, **kwargs: self.fake_image)
36553654
return self.fake_image['id']
36563655

0 commit comments

Comments
 (0)