Skip to content

Commit b5666fb

Browse files
Balazs GibizerBalazs Gibizer
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
1 parent fae51fc commit b5666fb

30 files changed

+27
-161
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
@@ -16,7 +16,6 @@
1616
import mock
1717

1818
from nova.tests.functional.api_sample_tests import api_sample_base
19-
from nova.virt import fake
2019

2120

2221
class HypervisorsSampleJsonTests(api_sample_base.ApiSampleTestBaseV21):
@@ -113,8 +112,6 @@ def setUp(self):
113112
# Start a new compute service to fake a record with hypervisor id=2
114113
# for pagination test.
115114
host = 'host1'
116-
fake.set_nodes([host])
117-
self.addCleanup(fake.restore_nodes)
118115
self.start_service('compute', host=host)
119116

120117
def test_hypervisors_list(self):
@@ -161,8 +158,6 @@ def test_hypervisors_list(self):
161158
def test_hypervisors_detail(self):
162159
# Start another compute service to get a 2nd compute for paging tests.
163160
host = 'host2'
164-
fake.set_nodes([host])
165-
self.addCleanup(fake.restore_nodes)
166161
service_2 = self.start_service('compute', host=host).service_ref
167162
compute_node_2 = service_2.compute_node
168163
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 import fixtures as nova_fixtures
2121
from nova.tests.functional import integrated_helpers
2222
from nova.tests.unit import fake_notifier
23-
from nova.virt import fake
2423

2524

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

6158
# 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
@@ -42,7 +42,6 @@
4242
import nova.tests.unit.image.fake
4343
from nova.tests.unit import policy_fixture
4444
from nova import utils
45-
from nova.virt import fake
4645

4746

4847
CONF = nova.conf.CONF
@@ -450,8 +449,6 @@ def _start_compute(self, host, cell_name=None):
450449
compute service (defaults to cell1)
451450
:return: the nova compute service object
452451
"""
453-
fake.set_nodes([host])
454-
self.addCleanup(fake.restore_nodes)
455452
compute = self.start_service('compute', host=host, cell=cell_name)
456453
self.computes[host] = compute
457454
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
@@ -51,8 +50,6 @@ def test_multiple_compute_actions(self):
5150
self._wait_for_notification('instance.create.end')
5251
self._attach_volume_to_server(server, self.cinder.SWAP_OLD_VOL)
5352
# server will boot on the 'compute' host
54-
fake.set_nodes(['host2'])
55-
self.addCleanup(fake.restore_nodes)
5653
self.compute2 = self.start_service('compute', host='host2')
5754

5855
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 & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
from nova.tests.unit import fake_network
2424
import nova.tests.unit.image.fake
2525
from nova.tests.unit import policy_fixture
26-
from nova.virt import fake
2726

2827

2928
class TestRetryBetweenComputeNodeBuilds(test.TestCase):
@@ -66,16 +65,7 @@ def setUp(self):
6665

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

8171
self.scheduler_service = self.start_service('scheduler')

nova/tests/functional/regressions/test_bug_1702454.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 cast_as_call
1919
from nova.tests.unit.image import fake as image_fake
2020
from nova.tests.unit import policy_fixture
21-
from nova.virt import fake
2221

2322

2423
class HostNameWeigher(weights.BaseHostWeigher):
@@ -96,18 +95,8 @@ def setUp(self):
9695
self.start_service('scheduler')
9796

9897
# Let's now start three compute nodes as we said above.
99-
# set_nodes() is needed to have each compute service return a
100-
# different nodename, so we get two hosts in the list of candidates
101-
# for scheduling. Otherwise both hosts will have the same default
102-
# nodename "fake-mini". The host passed to start_service controls the
103-
# "host" attribute and set_nodes() sets the "nodename" attribute.
104-
# We set_nodes() to make host and nodename the same for each compute.
105-
fake.set_nodes(['host1'])
106-
self.addCleanup(fake.restore_nodes)
10798
self.start_service('compute', host='host1')
108-
fake.set_nodes(['host2'])
10999
self.start_service('compute', host='host2')
110-
fake.set_nodes(['host3'])
111100
self.start_service('compute', host='host3')
112101
self.useFixture(cast_as_call.CastAsCall(self))
113102

nova/tests/functional/regressions/test_bug_1718455.py

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

2423

2524
class TestLiveMigrateOneOfConcurrentlyCreatedInstances(
@@ -61,16 +60,7 @@ def setUp(self):
6160
self.start_service('conductor')
6261
self.start_service('scheduler')
6362

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

7666
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
@@ -20,7 +20,6 @@
2020
from nova.tests.functional import integrated_helpers
2121
from nova.tests.unit.image import fake as image_fake
2222
from nova.tests.unit import policy_fixture
23-
from nova.virt import fake
2423

2524

2625
class HostNameWeigher(weights.BaseHostWeigher):
@@ -82,9 +81,7 @@ def setUp(self):
8281
self.start_service('scheduler')
8382

8483
# Let's now start three compute nodes as we said above.
85-
self.addCleanup(fake.restore_nodes)
8684
for host in ['host1', 'host2', 'host3']:
87-
fake.set_nodes([host])
8885
self.start_service('compute', host=host)
8986

9087
def _stub_resize_failure(self, failed_host):

nova/tests/functional/regressions/test_bug_1719730.py

Lines changed: 0 additions & 4 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 TestRescheduleWithServerGroup(test.TestCase,
@@ -65,10 +64,7 @@ def setUp(self):
6564

6665
# We start two compute services because we're going to fake one raising
6766
# RescheduledException to trigger a retry to the other compute host.
68-
fake.set_nodes(['host1'])
69-
self.addCleanup(fake.restore_nodes)
7067
self.start_service('compute', host='host1')
71-
fake.set_nodes(['host2'])
7268
self.start_service('compute', host='host2')
7369

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

nova/tests/functional/regressions/test_bug_1735407.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 TestParallelEvacuationWithServerGroup(
@@ -61,10 +60,7 @@ def setUp(self):
6160

6261
# We start two compute services because we need two instances with
6362
# anti-affinity server group policy to be booted
64-
fake.set_nodes(['host1'])
65-
self.addCleanup(fake.restore_nodes)
6663
self.compute1 = self.start_service('compute', host='host1')
67-
fake.set_nodes(['host2'])
6864
self.compute2 = self.start_service('compute', host='host2')
6965

7066
self.image_id = self.api.get_images()[0]['id']
@@ -124,7 +120,6 @@ def test_parallel_evacuate_with_server_group(self):
124120
self.api.force_down_service('host2', 'nova-compute', True)
125121

126122
# start a third compute to have place for one of the instances
127-
fake.set_nodes(['host3'])
128123
self.compute3 = self.start_service('compute', host='host3')
129124

130125
# 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
@@ -16,7 +16,6 @@
1616
from nova.tests.functional import integrated_helpers
1717
import nova.tests.unit.image.fake
1818
from nova.tests.unit import policy_fixture
19-
from nova.virt import fake
2019

2120

2221
class TestResizeWithNoAllocationScheduler(
@@ -63,9 +62,7 @@ def setUp(self):
6362
self.start_service('conductor')
6463

6564
# Create two compute nodes/services.
66-
self.addCleanup(fake.restore_nodes)
6765
for host in ('host1', 'host2'):
68-
fake.set_nodes([host])
6966
self.start_service('compute', host=host)
7067

7168
scheduler_service = self.start_service('scheduler')

nova/tests/functional/regressions/test_bug_1746483.py

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

2322
CONF = config.CONF
2423

@@ -67,9 +66,7 @@ def setUp(self):
6766

6867
# Create two compute nodes/services so we can restrict the image
6968
# we'll use to one of the hosts.
70-
self.addCleanup(fake.restore_nodes)
7169
for host in ('host1', 'host2'):
72-
fake.set_nodes([host])
7370
self.start_service('compute', host=host)
7471

7572
def test_boot_from_volume_with_isolated_image(self):

nova/tests/functional/regressions/test_bug_1764883.py

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

2423

2524
class TestEvacuationWithSourceReturningDuringRebuild(
@@ -63,11 +62,8 @@ def setUp(self):
6362
# Start two computes
6463
self.computes = {}
6564

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

70-
fake.set_nodes(['host2'])
7167
self.computes['host2'] = self.start_service('compute', host='host2')
7268

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

nova/tests/functional/regressions/test_bug_1781710.py

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

2322

2423
class HostNameWeigher(weights.BaseHostWeigher):
@@ -77,10 +76,7 @@ def setUp(self):
7776
group='workarounds')
7877
self.start_service('scheduler')
7978

80-
fake.set_nodes(['host1'])
81-
self.addCleanup(fake.restore_nodes)
8279
self.start_service('compute', host='host1')
83-
fake.set_nodes(['host2'])
8480
self.start_service('compute', host='host2')
8581

8682
def test_anti_affinity_multi_create(self):

nova/tests/functional/regressions/test_bug_1784353.py

Lines changed: 0 additions & 4 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 TestRescheduleWithVolumesAttached(
@@ -55,11 +54,8 @@ def setUp(self):
5554
self.start_service('scheduler')
5655

5756
# Start two computes to allow the instance to be rescheduled
58-
fake.set_nodes(['host1'])
59-
self.addCleanup(fake.restore_nodes)
6057
self.host1 = self.start_service('compute', host='host1')
6158

62-
fake.set_nodes(['host2'])
6359
self.host2 = self.start_service('compute', host='host2')
6460

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

nova/tests/functional/regressions/test_bug_1797580.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
from nova.tests.functional import integrated_helpers
1717
from nova.tests.unit.image import fake as image_fake
1818
from nova.tests.unit import policy_fixture
19-
from nova.virt import fake
2019

2120

2221
class ColdMigrateTargetHostThenLiveMigrateTest(
@@ -60,9 +59,7 @@ def setUp(self):
6059
self.start_service('conductor')
6160
self.start_service('scheduler')
6261

63-
self.addCleanup(fake.restore_nodes)
6462
for host in ('host1', 'host2'):
65-
fake.set_nodes([host])
6663
self.start_service('compute', host=host)
6764

6865
def test_cold_migrate_target_host_then_live_migrate(self):

0 commit comments

Comments
 (0)