Skip to content

Commit d56d1a8

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "Verify a move operation for cross_az_attach=False"
2 parents f6620d4 + bc3cf01 commit d56d1a8

File tree

1 file changed

+46
-1
lines changed

1 file changed

+46
-1
lines changed

nova/tests/functional/test_cross_az_attach.py

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,23 +28,30 @@ class CrossAZAttachTestCase(test.TestCase,
2828
def setUp(self):
2929
super(CrossAZAttachTestCase, self).setUp()
3030
# Use the standard fixtures.
31+
self.useFixture(nova_fixtures.CastAsCallFixture(self))
3132
self.useFixture(nova_fixtures.RealPolicyFixture())
3233
self.useFixture(nova_fixtures.CinderFixture(self, az=self.az))
3334
self.useFixture(nova_fixtures.GlanceFixture(self))
3435
self.useFixture(nova_fixtures.NeutronFixture(self))
3536
self.useFixture(func_fixtures.PlacementFixture())
37+
self.useFixture(nova_fixtures.HostNameWeigherFixture())
38+
self.notifier = self.useFixture(
39+
nova_fixtures.NotificationFixture(self))
3640
# Start nova controller services.
3741
self.api = self.useFixture(nova_fixtures.OSAPIFixture(
3842
api_version='v2.1')).admin_api
3943
self.start_service('conductor')
4044
self.start_service('scheduler')
41-
# Start one compute service and add it to the AZ. This allows us to
45+
# Start two compute services and add them to the AZ. This allows us to
4246
# get past the AvailabilityZoneFilter and build a server.
4347
self.start_service('compute', host='host1')
48+
self.start_service('compute', host='host2')
4449
agg_id = self.api.post_aggregate({'aggregate': {
4550
'name': self.az, 'availability_zone': self.az}})['id']
4651
self.api.api_post('/os-aggregates/%s/action' % agg_id,
4752
{'add_host': {'host': 'host1'}})
53+
self.api.api_post('/os-aggregates/%s/action' % agg_id,
54+
{'add_host': {'host': 'host2'}})
4855

4956
def test_cross_az_attach_false_boot_from_volume_no_az_specified(self):
5057
"""Tests the scenario where [cinder]/cross_az_attach=False and the
@@ -138,3 +145,41 @@ def test_cross_az_attach_false_no_volumes(self):
138145
self.flags(cross_az_attach=False, group='cinder')
139146
server = self._create_server(az=self.az)
140147
self.assertEqual(self.az, server['OS-EXT-AZ:availability_zone'])
148+
149+
def test_cross_az_attach_false_migrate_continues_to_pin_an_az(self):
150+
self.flags(cross_az_attach=False, group='cinder')
151+
server = self._build_server()
152+
server['block_device_mapping_v2'] = [{
153+
'source_type': 'volume',
154+
'destination_type': 'volume',
155+
'boot_index': 0,
156+
'uuid': nova_fixtures.CinderFixture.IMAGE_BACKED_VOL
157+
}]
158+
server = self.api.post_server({'server': server})
159+
server = self._wait_for_state_change(server, 'ACTIVE')
160+
# The instance is now pinned to a specific AZ.
161+
self.assertEqual(self.az, server['OS-EXT-AZ:availability_zone'])
162+
# Start a third compute service and add it to a different 'london' AZ.
163+
self.start_service('compute', host='host3')
164+
agg_id = self.api.post_aggregate({'aggregate': {
165+
'name': 'london', 'availability_zone': 'london'}})['id']
166+
self.api.api_post('/os-aggregates/%s/action' % agg_id,
167+
{'add_host': {'host': 'host3'}})
168+
169+
# we want 2.56 because of the host param in migrate action.
170+
self.api.microversion = '2.56'
171+
172+
# We can migrate the instance to another host in the same AZ
173+
server = self._migrate_server(server, host='host2')
174+
# let's move it back to host1
175+
server = self._revert_resize(server)
176+
177+
# Now let's try to migrate to host3 which is a different AZ.
178+
# It fails miserably.
179+
ex = self.assertRaises(api_client.OpenStackApiException,
180+
self.api.post_server_action,
181+
server['id'], {'migrate': {'host': 'host3'}})
182+
self.assertEqual(500, ex.response.status_code)
183+
# And yeah, that's due to the fact that the only tested host in not in
184+
# the pinned AZ.
185+
self.assertIn('NoValidHost', str(ex))

0 commit comments

Comments
 (0)