Clean up test_check_attach_availability_zone_differs
This test is really four tests, two of which don't make any difference and one is a happy path test which is redundant with the test_check_attach test that comes right after it. The two tests which don't make any difference are the ones where the instance.host is set to None. This made a difference before az.get_instance_availability_zone was mocked out but it's not used anymore in this test. There are some other cleanups in this change: - move the mock to be a decorator - use an instance object - use a valid uuid for the volume id - use self.flags so we don't have to reset the config override Change-Id: I44f32f10d99f7cc6edce1d5ae4bc359c6d14fdf3
This commit is contained in:
parent
414df1e56e
commit
3ab5b00fe2
|
@ -143,38 +143,20 @@ class CinderApiTestCase(test.NoDBTestCase):
|
|||
self.assertRaises(exception.InvalidVolume,
|
||||
self.api.check_attach, self.ctx, volume)
|
||||
|
||||
def test_check_attach_availability_zone_differs(self):
|
||||
volume = {'id': 'fake', 'status': 'available'}
|
||||
volume['attach_status'] = "detached"
|
||||
instance = {'id': 'fake',
|
||||
'availability_zone': 'zone1', 'host': 'fakehost'}
|
||||
@mock.patch.object(cinder.az, 'get_instance_availability_zone',
|
||||
return_value='zone1')
|
||||
def test_check_attach_availability_zone_differs(self,
|
||||
mock_get_instance_az):
|
||||
self.flags(cross_az_attach=False, group='cinder')
|
||||
volume = {'id': uuids.volume_id,
|
||||
'status': 'available',
|
||||
'attach_status': 'detached',
|
||||
'availability_zone': 'zone2'}
|
||||
instance = fake_instance_obj(self.ctx)
|
||||
|
||||
with mock.patch.object(cinder.az, 'get_instance_availability_zone',
|
||||
side_effect=lambda context,
|
||||
instance: 'zone1') as mock_get_instance_az:
|
||||
|
||||
CONF.set_override('cross_az_attach', False, group='cinder')
|
||||
volume['availability_zone'] = 'zone1'
|
||||
self.assertIsNone(self.api.check_attach(self.ctx,
|
||||
volume, instance))
|
||||
mock_get_instance_az.assert_called_once_with(self.ctx, instance)
|
||||
mock_get_instance_az.reset_mock()
|
||||
volume['availability_zone'] = 'zone2'
|
||||
self.assertRaises(exception.InvalidVolume,
|
||||
self.api.check_attach, self.ctx, volume, instance)
|
||||
mock_get_instance_az.assert_called_once_with(self.ctx, instance)
|
||||
mock_get_instance_az.reset_mock()
|
||||
del instance['host']
|
||||
volume['availability_zone'] = 'zone1'
|
||||
self.assertIsNone(self.api.check_attach(
|
||||
self.ctx, volume, instance))
|
||||
mock_get_instance_az.assert_called_once_with(self.ctx, instance)
|
||||
mock_get_instance_az.reset_mock()
|
||||
volume['availability_zone'] = 'zone2'
|
||||
self.assertRaises(exception.InvalidVolume,
|
||||
self.api.check_attach, self.ctx, volume, instance)
|
||||
mock_get_instance_az.assert_called_once_with(self.ctx, instance)
|
||||
CONF.reset()
|
||||
self.assertRaises(exception.InvalidVolume,
|
||||
self.api.check_attach, self.ctx, volume, instance)
|
||||
mock_get_instance_az.assert_called_once_with(self.ctx, instance)
|
||||
|
||||
def test_check_attach(self):
|
||||
volume = {'status': 'available'}
|
||||
|
|
Loading…
Reference in New Issue