Skip to content

Commit 45e1e87

Browse files
Balazs Gibizermarkgoddard
authored andcommitted
Remove global state from the FakeDriver
The virt driver FakeDriver used in both the functional and in the unit test used a global state to configure the host and node names the driver reports. This was hard to use when more then one compute service is started. Also global state is dangerous. It turned out that only a set of unit tests are using multiple nodes per compute the rest of the tests can simply use host=<hostname>, nodes=[<hostname>] setup. So this removes the global state. Change-Id: I2cf2fcbaebc706f897ce5dfbff47d32117064f9c (cherry picked from commit b5666fb)
1 parent 32e73f5 commit 45e1e87

31 files changed

+30
-176
lines changed

doc/api_samples/os-hypervisors/v2.53/hypervisors-list-resp.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"hypervisors": [
33
{
4-
"hypervisor_hostname": "fake-mini",
4+
"hypervisor_hostname": "host2",
55
"id": "1bb62a04-c576-402c-8147-9e89757a09e3",
66
"state": "up",
77
"status": "enabled"

nova/test.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,12 @@ def flags(self, **kw):
419419

420420
def start_service(self, name, host=None, **kwargs):
421421
cell = None
422+
# if the host is None then the CONF.host remains defaulted to
423+
# 'fake-mini' (originally done in ConfFixture)
424+
if host is not None:
425+
# Make sure that CONF.host is relevant to the right hostname
426+
self.useFixture(nova_fixtures.ConfPatcher(host=host))
427+
422428
if name == 'compute' and self.USES_DB:
423429
# NOTE(danms): We need to create the HostMapping first, because
424430
# otherwise we'll fail to update the scheduler while running
@@ -431,9 +437,6 @@ def start_service(self, name, host=None, **kwargs):
431437
cell_mapping=cell)
432438
hm.create()
433439
self.host_mappings[hm.host] = hm
434-
if host is not None:
435-
# Make sure that CONF.host is relevant to the right hostname
436-
self.useFixture(nova_fixtures.ConfPatcher(host=host))
437440
svc = self.useFixture(
438441
nova_fixtures.ServiceFixture(name, host, cell=cell, **kwargs))
439442

nova/tests/functional/api_sample_tests/api_samples/os-hypervisors/v2.53/hypervisors-list-resp.json.tpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"hypervisors": [
33
{
4-
"hypervisor_hostname": "fake-mini",
4+
"hypervisor_hostname": "host2",
55
"id": "%(hypervisor_id)s",
66
"state": "up",
77
"status": "enabled"

nova/tests/functional/api_sample_tests/test_hypervisors.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
from nova.cells import utils as cells_utils
1919
from nova import objects
2020
from nova.tests.functional.api_sample_tests import api_sample_base
21-
from nova.virt import fake
2221

2322

2423
class HypervisorsSampleJsonTests(api_sample_base.ApiSampleTestBaseV21):
@@ -157,8 +156,6 @@ def setUp(self):
157156
# Start a new compute service to fake a record with hypervisor id=2
158157
# for pagination test.
159158
host = 'host1'
160-
fake.set_nodes([host])
161-
self.addCleanup(fake.restore_nodes)
162159
self.start_service('compute', host=host)
163160

164161
def test_hypervisors_list(self):
@@ -205,8 +202,6 @@ def test_hypervisors_list(self):
205202
def test_hypervisors_detail(self):
206203
# Start another compute service to get a 2nd compute for paging tests.
207204
host = 'host2'
208-
fake.set_nodes([host])
209-
self.addCleanup(fake.restore_nodes)
210205
service_2 = self.start_service('compute', host=host).service_ref
211206
compute_node_2 = service_2.compute_node
212207
marker = self.compute_node_1.uuid

nova/tests/functional/compute/test_live_migration.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
from nova.tests.functional import integrated_helpers
2121
from nova.tests.unit import fake_notifier
2222
from nova.tests import uuidsentinel as uuids
23-
from nova.virt import fake
2423

2524

2625
class FakeCinderError(object):
@@ -53,8 +52,6 @@ def setUp(self):
5352
# Start a second compte node (the first one was started for us by
5453
# _IntegratedTestBase. set_nodes() is needed to avoid duplicate
5554
# nodenames. See comments in test_bug_1702454.py.
56-
fake.set_nodes(['host2'])
57-
self.addCleanup(fake.restore_nodes)
5855
self.compute2 = self.start_service('compute', host='host2')
5956

6057
# To get the old Cinder flow we need to hack the service version, otherwise

nova/tests/functional/integrated_helpers.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
import nova.tests.unit.image.fake
3636
from nova.tests.unit import policy_fixture
3737
from nova.tests import uuidsentinel as uuids
38-
from nova.virt import fake
3938

4039

4140
CONF = nova.conf.CONF
@@ -396,8 +395,6 @@ def _start_compute(self, host, cell_name=None):
396395
compute service (defaults to cell1)
397396
:return: the nova compute service object
398397
"""
399-
fake.set_nodes([host])
400-
self.addCleanup(fake.restore_nodes)
401398
compute = self.start_service('compute', host=host, cell=cell_name)
402399
self.computes[host] = compute
403400
return compute

nova/tests/functional/notification_sample_tests/test_instance.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
from nova.tests.functional.notification_sample_tests \
2323
import notification_sample_base
2424
from nova.tests.unit import fake_notifier
25-
from nova.virt import fake
2625

2726
COMPUTE_VERSION_OLD_ATTACH_FLOW = \
2827
compute_api.CINDER_V3_ATTACH_MIN_COMPUTE_VERSION - 1
@@ -48,8 +47,6 @@ def test_multiple_compute_actions(self):
4847
self._wait_for_notification('instance.create.end')
4948
self._attach_volume_to_server(server, self.cinder.SWAP_OLD_VOL)
5049
# server will boot on the 'compute' host
51-
fake.set_nodes(['host2'])
52-
self.addCleanup(fake.restore_nodes)
5350
self.compute2 = self.start_service('compute', host='host2')
5451

5552
actions = [

nova/tests/functional/regressions/test_bug_1669054.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
from nova import context
1414
from nova import objects
1515
from nova.tests.functional import integrated_helpers
16-
from nova.virt import fake
1716

1817

1918
class ResizeEvacuateTestCase(integrated_helpers._IntegratedTestBase,
@@ -47,8 +46,6 @@ def test_resize_then_evacuate(self):
4746
self._wait_for_state_change(self.api, server, 'ACTIVE')
4847

4948
# Start up another compute service so we can resize.
50-
fake.set_nodes(['host2'])
51-
self.addCleanup(fake.restore_nodes)
5249
host2 = self.start_service('compute', host='host2')
5350

5451
# Now resize the server to move it to host2.

nova/tests/functional/regressions/test_bug_1671648.py

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
from nova.tests.unit import fake_network
2323
import nova.tests.unit.image.fake
2424
from nova.tests.unit import policy_fixture
25-
from nova.virt import fake
2625

2726

2827
class TestRetryBetweenComputeNodeBuilds(test.TestCase):
@@ -67,17 +66,7 @@ def setUp(self):
6766

6867
# We start two compute services because we're going to fake one
6968
# of them to fail the build so we can trigger the retry code.
70-
# set_nodes() is needed to have each compute service return a
71-
# different nodename, so we get two hosts in the list of candidates
72-
# for scheduling. Otherwise both hosts will have the same default
73-
# nodename "fake-mini". The host passed to start_service controls the
74-
# "host" attribute and set_nodes() sets the "nodename" attribute.
75-
# We set_nodes() to make host and nodename the same for each compute.
76-
fake.set_nodes(['host1'])
77-
self.addCleanup(fake.restore_nodes)
7869
self.start_service('compute', host='host1')
79-
fake.set_nodes(['host2'])
80-
self.addCleanup(fake.restore_nodes)
8170
self.start_service('compute', host='host2')
8271

8372
self.useFixture(cast_as_call.CastAsCall(self))

nova/tests/functional/regressions/test_bug_1702454.py

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
from nova.tests.unit import cast_as_call
1818
from nova.tests.unit.image import fake as image_fake
1919
from nova.tests.unit import policy_fixture
20-
from nova.virt import fake
2120

2221

2322
class HostNameWeigher(weights.BaseHostWeigher):
@@ -99,20 +98,8 @@ def setUp(self):
9998
self.start_service('scheduler')
10099

101100
# Let's now start three compute nodes as we said above.
102-
# set_nodes() is needed to have each compute service return a
103-
# different nodename, so we get two hosts in the list of candidates
104-
# for scheduling. Otherwise both hosts will have the same default
105-
# nodename "fake-mini". The host passed to start_service controls the
106-
# "host" attribute and set_nodes() sets the "nodename" attribute.
107-
# We set_nodes() to make host and nodename the same for each compute.
108-
fake.set_nodes(['host1'])
109-
self.addCleanup(fake.restore_nodes)
110101
self.start_service('compute', host='host1')
111-
fake.set_nodes(['host2'])
112-
self.addCleanup(fake.restore_nodes)
113102
self.start_service('compute', host='host2')
114-
fake.set_nodes(['host3'])
115-
self.addCleanup(fake.restore_nodes)
116103
self.start_service('compute', host='host3')
117104
self.useFixture(cast_as_call.CastAsCall(self))
118105

nova/tests/functional/regressions/test_bug_1718455.py

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
from nova.tests.unit import fake_network
1919
import nova.tests.unit.image.fake
2020
from nova.tests.unit import policy_fixture
21-
from nova.virt import fake
2221

2322

2423
class TestLiveMigrateOneOfConcurrentlyCreatedInstances(
@@ -60,17 +59,7 @@ def setUp(self):
6059
self.start_service('conductor')
6160
self.start_service('scheduler')
6261

63-
# set_nodes() is needed to have each compute service return a
64-
# different nodename, so we get two hosts in the list of candidates
65-
# for scheduling. Otherwise both hosts will have the same default
66-
# nodename "fake-mini". The host passed to start_service controls the
67-
# "host" attribute and set_nodes() sets the "nodename" attribute.
68-
# We set_nodes() to make host and nodename the same for each compute.
69-
fake.set_nodes(['host1'])
70-
self.addCleanup(fake.restore_nodes)
7162
self.start_service('compute', host='host1')
72-
fake.set_nodes(['host2'])
73-
self.addCleanup(fake.restore_nodes)
7463
self.start_service('compute', host='host2')
7564

7665
fake_network.set_stub_network_methods(self)

nova/tests/functional/regressions/test_bug_1718512.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
from nova.tests.functional import integrated_helpers
2020
from nova.tests.unit.image import fake as image_fake
2121
from nova.tests.unit import policy_fixture
22-
from nova.virt import fake
2322

2423

2524
class HostNameWeigher(weights.BaseHostWeigher):
@@ -86,8 +85,6 @@ def setUp(self):
8685

8786
# Let's now start three compute nodes as we said above.
8887
for host in ['host1', 'host2', 'host3']:
89-
fake.set_nodes([host])
90-
self.addCleanup(fake.restore_nodes)
9188
self.start_service('compute', host=host)
9289

9390
def _stub_resize_failure(self, failed_host):

nova/tests/functional/regressions/test_bug_1719730.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
from nova.tests.unit import fake_network
1818
import nova.tests.unit.image.fake
1919
from nova.tests.unit import policy_fixture
20-
from nova.virt import fake
2120

2221

2322
class TestRescheduleWithServerGroup(test.TestCase,
@@ -64,11 +63,7 @@ def setUp(self):
6463

6564
# We start two compute services because we're going to fake one raising
6665
# RescheduledException to trigger a retry to the other compute host.
67-
fake.set_nodes(['host1'])
68-
self.addCleanup(fake.restore_nodes)
6966
self.start_service('compute', host='host1')
70-
fake.set_nodes(['host2'])
71-
self.addCleanup(fake.restore_nodes)
7267
self.start_service('compute', host='host2')
7368

7469
self.image_id = self.api.get_images()[0]['id']

nova/tests/functional/regressions/test_bug_1735407.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
from nova.tests.unit import fake_notifier
1818
import nova.tests.unit.image.fake
1919
from nova.tests.unit import policy_fixture
20-
from nova.virt import fake
2120

2221

2322
class TestParallelEvacuationWithServerGroup(
@@ -57,11 +56,7 @@ def setUp(self):
5756

5857
# We start two compute services because we need two instances with
5958
# anti-affinity server group policy to be booted
60-
fake.set_nodes(['host1'])
61-
self.addCleanup(fake.restore_nodes)
6259
self.compute1 = self.start_service('compute', host='host1')
63-
fake.set_nodes(['host2'])
64-
self.addCleanup(fake.restore_nodes)
6560
self.compute2 = self.start_service('compute', host='host2')
6661

6762
self.image_id = self.api.get_images()[0]['id']
@@ -122,8 +117,6 @@ def test_parallel_evacuate_with_server_group(self):
122117
self.api.force_down_service('host2', 'nova-compute', True)
123118

124119
# start a third compute to have place for one of the instances
125-
fake.set_nodes(['host3'])
126-
self.addCleanup(fake.restore_nodes)
127120
self.compute3 = self.start_service('compute', host='host3')
128121

129122
# evacuate both instances

nova/tests/functional/regressions/test_bug_1741307.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
from nova.tests.functional import integrated_helpers
1616
import nova.tests.unit.image.fake
1717
from nova.tests.unit import policy_fixture
18-
from nova.virt import fake
1918

2019

2120
class TestResizeWithCachingScheduler(test.TestCase,
@@ -65,8 +64,6 @@ def setUp(self):
6564

6665
# Create two compute nodes/services.
6766
for host in ('host1', 'host2'):
68-
fake.set_nodes([host])
69-
self.addCleanup(fake.restore_nodes)
7067
self.start_service('compute', host=host)
7168

7269
flavors = self.api.get_flavors()

nova/tests/functional/regressions/test_bug_1746483.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
from nova.tests.unit.image import fake as image_fakes
1818
from nova.tests.unit import policy_fixture
1919
from nova import utils
20-
from nova.virt import fake
2120

2221
CONF = config.CONF
2322

@@ -67,8 +66,6 @@ def setUp(self):
6766
# Create two compute nodes/services so we can restrict the image
6867
# we'll use to one of the hosts.
6968
for host in ('host1', 'host2'):
70-
fake.set_nodes([host])
71-
self.addCleanup(fake.restore_nodes)
7269
self.start_service('compute', host=host)
7370

7471
def test_boot_from_volume_with_isolated_image(self):

nova/tests/functional/regressions/test_bug_1764556.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
from nova.tests.unit.image import fake as fake_image
1919
from nova.tests.unit import policy_fixture
2020
from nova import utils
21-
from nova.virt import fake as fake_virt
2221

2322

2423
class InstanceListWithDeletedServicesTestCase(
@@ -50,7 +49,6 @@ def setUp(self):
5049

5150
# the image fake backend needed for image discovery
5251
fake_image.stub_out_image_service(self)
53-
self.addCleanup(fake_image.FakeImageService_reset)
5452
# Get the image before we set the microversion to latest to avoid
5553
# the proxy issues with GET /images in 2.36.
5654
self.image_id = self.api.get_images()[0]['id']
@@ -83,8 +81,6 @@ def test_instance_list_deleted_service_with_no_uuid(self):
8381
5. migrate the instance back to the host1 service
8482
6. list instances which will try to online migrate the old service uuid
8583
"""
86-
fake_virt.set_nodes(['host1'])
87-
self.addCleanup(fake_virt.restore_nodes)
8884
host1 = self.start_service('compute', host='host1')
8985

9086
# Create an instance which will be on host1 since it's the only host.
@@ -96,8 +92,6 @@ def test_instance_list_deleted_service_with_no_uuid(self):
9692

9793
# Now we start a 2nd compute which is "upgraded" (has a uuid) and
9894
# we'll migrate the instance to that host.
99-
fake_virt.set_nodes(['host2'])
100-
self.addCleanup(fake_virt.restore_nodes)
10195
host2 = self.start_service('compute', host='host2')
10296
self.assertIsNotNone(host2.service_ref.uuid)
10397

nova/tests/functional/regressions/test_bug_1764883.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
from nova.tests.unit import fake_notifier
1919
import nova.tests.unit.image.fake
2020
from nova.tests.unit import policy_fixture
21-
from nova.virt import fake
2221

2322

2423
class TestEvacuationWithSourceReturningDuringRebuild(
@@ -62,12 +61,8 @@ def setUp(self):
6261
# Start two computes
6362
self.computes = {}
6463

65-
fake.set_nodes(['host1'])
66-
self.addCleanup(fake.restore_nodes)
6764
self.computes['host1'] = self.start_service('compute', host='host1')
6865

69-
fake.set_nodes(['host2'])
70-
self.addCleanup(fake.restore_nodes)
7166
self.computes['host2'] = self.start_service('compute', host='host2')
7267

7368
self.image_id = self.api.get_images()[0]['id']

nova/tests/functional/regressions/test_bug_1781710.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
from nova.tests.functional import integrated_helpers
1818
from nova.tests.unit.image import fake as image_fake
1919
from nova.tests.unit import policy_fixture
20-
from nova.virt import fake
2120

2221

2322
class HostNameWeigher(weights.BaseHostWeigher):
@@ -76,11 +75,7 @@ def setUp(self):
7675
group='workarounds')
7776
self.start_service('scheduler')
7877

79-
fake.set_nodes(['host1'])
80-
self.addCleanup(fake.restore_nodes)
8178
self.start_service('compute', host='host1')
82-
fake.set_nodes(['host2'])
83-
self.addCleanup(fake.restore_nodes)
8479
self.start_service('compute', host='host2')
8580

8681
def test_anti_affinity_multi_create(self):

0 commit comments

Comments
 (0)