def test_cinder_volume_shrink_fails(self): stack_name = 'test_cvolume_shrink_fail_stack' # create script self._mock_create_volume(vt_base.FakeVolume('creating'), stack_name, size=2) # update script fv = vt_base.FakeVolume('available', size=2) self.cinder_fc.volumes.get(fv.id).AndReturn(fv) self.m.ReplayAll() self.t['resources']['volume']['properties']['size'] = 2 stack = utils.parse_stack(self.t, stack_name=stack_name) rsrc = self.create_volume(self.t, stack, 'volume') props = copy.deepcopy(rsrc.properties.data) props['size'] = 1 after = rsrc_defn.ResourceDefinition(rsrc.name, rsrc.type(), props) update_task = scheduler.TaskRunner(rsrc.update, after) ex = self.assertRaises(exception.ResourceFailure, update_task) self.assertEqual('NotSupported: Shrinking volume is not supported.', six.text_type(ex)) self.assertEqual((rsrc.UPDATE, rsrc.FAILED), rsrc.state) self.m.VerifyAll()
def test_cinder_volume_extend_detached(self): stack_name = 'test_cvolume_extend_det_stack' # create script self._mock_create_volume(vt_base.FakeVolume('creating'), stack_name) # update script fv = vt_base.FakeVolume('available', size=1, attachments=[]) self.cinder_fc.volumes.get(fv.id).AndReturn(fv) self.cinder_fc.volumes.get(fv.id).AndReturn(fv) self.cinder_fc.volumes.extend(fv.id, 2) self.cinder_fc.volumes.get(fv.id).AndReturn( vt_base.FakeVolume('extending')) self.cinder_fc.volumes.get(fv.id).AndReturn( vt_base.FakeVolume('extending')) self.cinder_fc.volumes.get(fv.id).AndReturn( vt_base.FakeVolume('available')) self.m.ReplayAll() stack = utils.parse_stack(self.t, stack_name=stack_name) rsrc = self.create_volume(self.t, stack, 'volume') props = copy.deepcopy(rsrc.properties.data) props['size'] = 2 after = rsrc_defn.ResourceDefinition(rsrc.name, rsrc.type(), props) update_task = scheduler.TaskRunner(rsrc.update, after) self.assertIsNone(update_task()) self.assertEqual((rsrc.UPDATE, rsrc.COMPLETE), rsrc.state) self.m.VerifyAll()
def test_volume_detach_non_exist(self): fv = vt_base.FakeVolume('creating') fva = vt_base.FakeVolume('in-use') stack_name = 'test_volume_detach_nonexist_stack' self._mock_create_volume(fv, stack_name) self._mock_create_server_volume_script(fva) self.stub_VolumeConstraint_validate() # delete script self.fc.volumes.delete_server_volume(u'WikiDatabase', 'vol-123').AndReturn(None) self.cinder_fc.volumes.get(fva.id).AndRaise( cinder_exp.NotFound('Not found')) self.fc.volumes.get_server_volume(u'WikiDatabase', 'vol-123').AndRaise( fakes_nova.fake_exception()) self.m.ReplayAll() stack = utils.parse_stack(self.t, stack_name=stack_name) self.create_volume(self.t, stack, 'DataVolume') rsrc = self.create_attachment(self.t, stack, 'MountPoint') scheduler.TaskRunner(rsrc.delete)() self.m.VerifyAll()
def test_cinder_create_from_image(self): fv = vt_base.FakeVolume('downloading') stack_name = 'test_cvolume_create_from_img_stack' image_id = '46988116-6703-4623-9dbc-2bc6d284021b' cinder.CinderClientPlugin._create().AndReturn(self.cinder_fc) self.m.StubOutWithMock(glance.GlanceClientPlugin, 'get_image_id') glance.GlanceClientPlugin.get_image_id( image_id).MultipleTimes().AndReturn(image_id) self.cinder_fc.volumes.create(size=1, availability_zone='nova', description='ImageVolumeDescription', name='ImageVolume', imageRef=image_id).AndReturn(fv) self.cinder_fc.volumes.get(fv.id).AndReturn(fv) fv_ready = vt_base.FakeVolume('available', id=fv.id) self.cinder_fc.volumes.get(fv.id).AndReturn(fv_ready) self.m.ReplayAll() self.t['resources']['volume']['properties'] = { 'size': '1', 'name': 'ImageVolume', 'description': 'ImageVolumeDescription', 'availability_zone': 'nova', 'image': image_id, } stack = utils.parse_stack(self.t, stack_name=stack_name) self.create_volume(self.t, stack, 'volume') self.m.VerifyAll()
def test_cinder_volume_update_read_only(self): # update read only access mode fv = vt_base.FakeVolume('update_read_only_access_mode') stack_name = 'test_update_read_only' cinder.CinderClientPlugin._create().AndReturn(self.cinder_fc) self.cinder_fc.volumes.create(size=1, availability_zone='nova', description='test_description', name='test_name', metadata={ u'key': u'value' }).AndReturn(fv) update_readonly_mock = self.patchobject(self.cinder_fc.volumes, 'update_readonly_flag') update_readonly_mock(fv.id, True).return_value(None) fv_ready = vt_base.FakeVolume('available', id=fv.id) self.cinder_fc.volumes.get(fv.id).AndReturn(fv_ready) self.m.ReplayAll() stack = utils.parse_stack(self.t, stack_name=stack_name) rsrc = self.create_volume(self.t, stack, 'volume') props = copy.deepcopy(rsrc.properties.data) props['read_only'] = True after = rsrc_defn.ResourceDefinition(rsrc.name, rsrc.type(), props) scheduler.TaskRunner(rsrc.update, after)() self.assertEqual((rsrc.UPDATE, rsrc.COMPLETE), rsrc.state)
def test_cinder_create_with_read_only(self): fv = vt_base.FakeVolume('with_read_only_access_mode') stack_name = 'test_create_with_read_only' cinder.CinderClientPlugin._create().AndReturn(self.cinder_fc) self.cinder_fc.volumes.create(size=1, availability_zone='nova', description='ImageVolumeDescription', name='ImageVolume').AndReturn(fv) update_readonly_mock = self.patchobject(self.cinder_fc.volumes, 'update_readonly_flag') update_readonly_mock(fv.id, False).return_value(None) fv_ready = vt_base.FakeVolume('available', id=fv.id) self.cinder_fc.volumes.get(fv.id).AndReturn(fv_ready) self.m.ReplayAll() self.t['resources']['volume']['properties'] = { 'size': '1', 'name': 'ImageVolume', 'description': 'ImageVolumeDescription', 'availability_zone': 'nova', 'read_only': False, } stack = utils.parse_stack(self.t, stack_name=stack_name) self.create_volume(self.t, stack, 'volume') self.m.VerifyAll()
def test_cinder_create(self): fv = vt_base.FakeVolume('creating') stack_name = 'test_cvolume_stack' self.stub_SnapshotConstraint_validate() self.stub_VolumeConstraint_validate() self.stub_VolumeTypeConstraint_validate() cinder.CinderClientPlugin._create().AndReturn(self.cinder_fc) self.cinder_fc.volumes.create(size=1, availability_zone='nova', description='test_description', name='test_name', metadata={ 'key': 'value' }, volume_type='lvm').AndReturn(fv) self.cinder_fc.volumes.get(fv.id).AndReturn(fv) fv_ready = vt_base.FakeVolume('available', id=fv.id) self.cinder_fc.volumes.get(fv.id).AndReturn(fv_ready) self.m.ReplayAll() self.t['resources']['volume']['properties'].update({ 'volume_type': 'lvm', }) stack = utils.parse_stack(self.t, stack_name=stack_name) self.create_volume(self.t, stack, 'volume') self.m.VerifyAll()
def test_cinder_volume_extend_fails_to_complete(self): stack_name = 'test_cvolume_extend_fail_compl_stack' # create script self._mock_create_volume(vt_base.FakeVolume('creating'), stack_name) # update script fv = vt_base.FakeVolume('available', size=1, attachments=[]) self.cinder_fc.volumes.get(fv.id).AndReturn(fv) self.cinder_fc.volumes.get(fv.id).AndReturn(fv) self.cinder_fc.volumes.extend(fv.id, 2) self.cinder_fc.volumes.get(fv.id).AndReturn( vt_base.FakeVolume('extending')) self.cinder_fc.volumes.get(fv.id).AndReturn( vt_base.FakeVolume('extending')) self.cinder_fc.volumes.get(fv.id).AndReturn( vt_base.FakeVolume('error_extending')) self.m.ReplayAll() stack = utils.parse_stack(self.t, stack_name=stack_name) rsrc = self.create_volume(self.t, stack, 'volume') props = copy.deepcopy(rsrc.properties.data) props['size'] = 2 after = rsrc_defn.ResourceDefinition(rsrc.name, rsrc.type(), props) update_task = scheduler.TaskRunner(rsrc.update, after) ex = self.assertRaises(exception.ResourceFailure, update_task) self.assertIn("Volume resize failed - Unknown status error_extending", six.text_type(ex)) self.assertEqual((rsrc.UPDATE, rsrc.FAILED), rsrc.state) self.m.VerifyAll()
def test_volume_detachment_err(self): stack_name = 'test_volume_detach_err_stack' self._mock_create_volume(vt_base.FakeVolume('creating'), stack_name) fva = self._mock_create_server_volume_script( vt_base.FakeVolume('attaching')) self.stub_VolumeConstraint_validate() # delete script fva = vt_base.FakeVolume('in-use') self.fc.volumes.get_server_volume(u'WikiDatabase', 'vol-123').AndReturn(fva) self.cinder_fc.volumes.get(fva.id).AndReturn(fva) self.fc.volumes.delete_server_volume( 'WikiDatabase', 'vol-123').AndRaise(fakes_nova.fake_exception(400)) self.cinder_fc.volumes.get(fva.id).AndReturn( vt_base.FakeVolume('available', id=fva.id)) self.fc.volumes.get_server_volume(u'WikiDatabase', 'vol-123').AndReturn(fva) self.fc.volumes.get_server_volume( u'WikiDatabase', 'vol-123').AndRaise(fakes_nova.fake_exception()) self.m.ReplayAll() stack = utils.parse_stack(self.t, stack_name=stack_name) self.create_volume(self.t, stack, 'DataVolume') rsrc = self.create_attachment(self.t, stack, 'MountPoint') scheduler.TaskRunner(rsrc.delete)() self.m.VerifyAll()
def test_cinder_attachment(self): fv = vt_base.FakeVolume('creating', 'available') fva = vt_base.FakeVolume('attaching', 'in-use') stack_name = 'test_volume_attach_stack' self._mock_create_volume(fv, stack_name) self._mock_create_server_volume_script(fva) self.stub_VolumeConstraint_validate() # delete script fva = vt_base.FakeVolume('in-use', 'available') self.fc.volumes.get_server_volume(u'WikiDatabase', 'vol-123').AndReturn(fva) self.cinder_fc.volumes.get(fva.id).AndReturn(fva) self.fc.volumes.delete_server_volume( 'WikiDatabase', 'vol-123').MultipleTimes().AndReturn(None) self.fc.volumes.get_server_volume(u'WikiDatabase', 'vol-123').AndReturn(fva) self.fc.volumes.get_server_volume(u'WikiDatabase', 'vol-123').AndRaise( fakes_v1_1.fake_exception()) self.m.ReplayAll() stack = utils.parse_stack(self.t, stack_name=stack_name) self.create_volume(self.t, stack, 'volume') self.assertEqual('available', fv.status) rsrc = self.create_attachment(self.t, stack, 'attachment') scheduler.TaskRunner(rsrc.delete)() self.m.VerifyAll()
def test_volume_attachment_updates_not_supported(self): nova.NovaClientPlugin.get_server = mock.Mock( return_value=mock.MagicMock()) fv = vt_base.FakeVolume('creating', 'available') fva = vt_base.FakeVolume('attaching', 'in-use') stack_name = 'test_volume_attach_stack' self._mock_create_volume(fv, stack_name) self._mock_create_server_volume_script(fva) self.stub_VolumeConstraint_validate() self.m.ReplayAll() stack = utils.parse_stack(self.t, stack_name=stack_name) self.create_volume(self.t, stack, 'DataVolume') self.assertEqual('available', fv.status) rsrc = self.create_attachment(self.t, stack, 'MountPoint') props = copy.deepcopy(rsrc.properties.data) props['InstanceId'] = 'some_other_instance_id' props['VolumeId'] = 'some_other_volume_id' props['Device'] = '/dev/vdz' after = rsrc_defn.ResourceDefinition(rsrc.name, rsrc.type(), props) update_task = scheduler.TaskRunner(rsrc.update, after) ex = self.assertRaises(exception.ResourceFailure, update_task) self.assertIn('NotSupported: Update to properties Device, InstanceId, ' 'VolumeId of MountPoint (AWS::EC2::VolumeAttachment)', six.text_type(ex)) self.assertEqual((rsrc.UPDATE, rsrc.FAILED), rsrc.state) self.m.VerifyAll()
def test_volume(self): stack_name = 'test_volume_create_stack' # create script fv = self._mock_create_volume(vt_base.FakeVolume('creating'), stack_name) # failed delete due to in-use script self.cinder_fc.volumes.get(fv.id).AndReturn( vt_base.FakeVolume('in-use')) # delete script self._mock_delete_volume(fv) self.m.ReplayAll() stack = utils.parse_stack(self.t, stack_name=stack_name) rsrc = self.create_volume(self.t, stack, 'DataVolume') ex = self.assertRaises(exception.ResourceFailure, scheduler.TaskRunner(rsrc.destroy)) self.assertIn("Volume in use", six.text_type(ex)) scheduler.TaskRunner(rsrc.destroy)() self.m.VerifyAll()
def test_volume_detach_with_error(self): fv = vt_base.FakeVolume('creating', 'available') fva = vt_base.FakeVolume('attaching', 'in-use') stack_name = 'test_volume_attach_stack' self._mock_create_volume(fv, stack_name) self._mock_create_server_volume_script(fva) self.stub_VolumeConstraint_validate() # delete script fva = vt_base.FakeVolume('in-use', 'error') self.fc.volumes.get_server_volume(u'WikiDatabase', 'vol-123').AndReturn(fva) self.cinder_fc.volumes.get(fva.id).AndReturn(fva) self.fc.volumes.delete_server_volume('WikiDatabase', 'vol-123').AndReturn(None) self.m.ReplayAll() stack = utils.parse_stack(self.t, stack_name=stack_name) self.create_volume(self.t, stack, 'DataVolume') self.assertEqual('available', fv.status) rsrc = self.create_attachment(self.t, stack, 'MountPoint') detach_task = scheduler.TaskRunner(rsrc.delete) ex = self.assertRaises(exception.ResourceFailure, detach_task) self.assertIn('Volume detachment failed - Unknown status error', six.text_type(ex)) self.m.VerifyAll()
def test_cinder_default(self): fv = vt_base.FakeVolume('creating') stack_name = 'test_cvolume_default_stack' cinder.CinderClientPlugin._create().AndReturn( self.cinder_fc) vol_name = utils.PhysName(stack_name, 'volume') self.cinder_fc.volumes.create( size=1, availability_zone='nova', description=None, name=vol_name).AndReturn(fv) self.cinder_fc.volumes.get(fv.id).AndReturn(fv) fv_ready = vt_base.FakeVolume('available', id=fv.id) self.cinder_fc.volumes.get(fv.id).AndReturn(fv_ready) self.m.ReplayAll() self.t['resources']['volume']['properties'] = { 'size': '1', 'availability_zone': 'nova', } stack = utils.parse_stack(self.t, stack_name=stack_name) self.create_volume(self.t, stack, 'volume') self.m.VerifyAll()
def test_cinder_volume_extend_fails_to_start(self): fv = vt_base.FakeVolume('creating', 'available', size=1, attachments=[]) stack_name = 'test_volume_stack' # create script self._mock_create_volume(fv, stack_name) # update script self.cinder_fc.volumes.get(fv.id).AndReturn(fv) fv2 = vt_base.FakeVolume('extending', 'extending') self.cinder_fc.volumes.get(fv.id).AndReturn(fv2) self.cinder_fc.volumes.extend(fv.id, 2).AndRaise(cinder_exp.OverLimit(413)) self.m.ReplayAll() stack = utils.parse_stack(self.t, stack_name=stack_name) rsrc = self.create_volume(self.t, stack, 'volume') self.assertEqual('available', fv.status) props = copy.deepcopy(rsrc.properties.data) props['size'] = 2 after = rsrc_defn.ResourceDefinition(rsrc.name, rsrc.type(), props) update_task = scheduler.TaskRunner(rsrc.update, after) ex = self.assertRaises(exception.ResourceFailure, update_task) self.assertIn('Over limit', six.text_type(ex)) self.assertEqual((rsrc.UPDATE, rsrc.FAILED), rsrc.state) self.m.VerifyAll()
def test_volume_default_az(self): fv = vt_base.FakeVolume('creating') stack_name = 'test_volume_defaultaz_stack' # create script nova.NovaClientPlugin._create().AndReturn(self.fc) self.m.StubOutWithMock(instance.Instance, 'handle_create') self.m.StubOutWithMock(instance.Instance, 'check_create_complete') self.m.StubOutWithMock(instance.Instance, '_resolve_attribute') self.m.StubOutWithMock(aws_vol.VolumeAttachment, 'handle_create') self.m.StubOutWithMock(aws_vol.VolumeAttachment, 'check_create_complete') instance.Instance.handle_create().AndReturn(None) instance.Instance.check_create_complete(None).AndReturn(True) instance.Instance._resolve_attribute( 'AvailabilityZone').MultipleTimes().AndReturn(None) cinder.CinderClientPlugin._create().AndReturn( self.cinder_fc) self.stub_ImageConstraint_validate() self.stub_ServerConstraint_validate() self.stub_VolumeConstraint_validate() vol_name = utils.PhysName(stack_name, 'DataVolume') self.cinder_fc.volumes.create( size=1, availability_zone=None, description=vol_name, name=vol_name, metadata={u'Usage': u'Wiki Data Volume'}).AndReturn(fv) self.cinder_fc.volumes.get(fv.id).AndReturn(fv) fv_ready = vt_base.FakeVolume('available', id=fv.id) self.cinder_fc.volumes.get(fv.id).AndReturn(fv_ready) aws_vol.VolumeAttachment.handle_create().AndReturn(None) aws_vol.VolumeAttachment.check_create_complete( None).AndReturn(True) # delete script self.m.StubOutWithMock(instance.Instance, 'handle_delete') self.m.StubOutWithMock(aws_vol.VolumeAttachment, 'handle_delete') self.m.StubOutWithMock(aws_vol.VolumeAttachment, 'check_delete_complete') instance.Instance.handle_delete().AndReturn(None) self.cinder_fc.volumes.get('vol-123').AndRaise( cinder_exp.NotFound('Not found')) cookie = object() aws_vol.VolumeAttachment.handle_delete().AndReturn(cookie) aws_vol.VolumeAttachment.check_delete_complete(cookie).AndReturn(True) self.m.ReplayAll() stack = utils.parse_stack(self.t, stack_name=stack_name) rsrc = stack['DataVolume'] self.assertIsNone(rsrc.validate()) scheduler.TaskRunner(stack.create)() self.assertEqual((rsrc.CREATE, rsrc.COMPLETE), rsrc.state) scheduler.TaskRunner(stack.delete)() self.m.VerifyAll()
def test_cinder_volume_attachment_update_volume(self): fv = vt_base.FakeVolume('creating', 'available') fva = vt_base.FakeVolume('attaching', 'in-use') fv2 = vt_base.FakeVolume('creating', 'available') fv2.id = 'vol-456' fv2a = vt_base.FakeVolume('attaching', 'in-use') fv2a.id = 'vol-456' stack_name = 'test_volume_attach_stack' self.stub_VolumeConstraint_validate() self._mock_create_volume(fv, stack_name) vol2_name = utils.PhysName(stack_name, 'volume2') self.cinder_fc.volumes.create(size=2, availability_zone='nova', description=None, name=vol2_name).AndReturn(fv2) self._mock_create_server_volume_script(fva) # delete script fva = vt_base.FakeVolume('in-use', 'available') self.fc.volumes.get_server_volume(u'WikiDatabase', 'vol-123').AndReturn(fva) self.cinder_fc.volumes.get(fva.id).AndReturn(fva) self.fc.volumes.delete_server_volume( 'WikiDatabase', 'vol-123').MultipleTimes().AndReturn(None) self.fc.volumes.get_server_volume(u'WikiDatabase', 'vol-123').AndReturn(fva) self.fc.volumes.get_server_volume(u'WikiDatabase', 'vol-123').AndRaise( fakes_v1_1.fake_exception()) # attach script self._mock_create_server_volume_script(fv2a, volume='vol-456', update=True) self.m.ReplayAll() stack = utils.parse_stack(self.t, stack_name=stack_name) self.create_volume(self.t, stack, 'volume') self.assertEqual('available', fv.status) self.create_volume(self.t, stack, 'volume2') self.assertEqual('available', fv2.status) rsrc = self.create_attachment(self.t, stack, 'attachment') self.assertEqual((rsrc.CREATE, rsrc.COMPLETE), rsrc.state) props = copy.deepcopy(rsrc.properties.data) props['volume_id'] = 'vol-456' after = rsrc_defn.ResourceDefinition(rsrc.name, rsrc.type(), props) scheduler.TaskRunner(rsrc.update, after)() self.assertEqual((rsrc.UPDATE, rsrc.COMPLETE), rsrc.state) self.assertEqual(fv2a.id, rsrc.resource_id) self.m.VerifyAll()
def test_volume_restore(self): stack_name = 'test_cvolume_restore_stack' # create script cinder.CinderClientPlugin._create().MultipleTimes().AndReturn( self.cinder_fc) self.cinder_fc.volumes.create(size=1, availability_zone=None, description='test_description', name='test_name').AndReturn( vt_base.FakeVolume('creating')) fv = vt_base.FakeVolume('available') self.cinder_fc.volumes.get(fv.id).AndReturn(fv) # snapshot script fb = vt_base.FakeBackup('creating') self.m.StubOutWithMock(self.cinder_fc.backups, 'create') self.cinder_fc.backups.create(fv.id).AndReturn(fb) self.m.StubOutWithMock(self.cinder_fc.backups, 'get') self.cinder_fc.backups.get(fb.id).AndReturn( vt_base.FakeBackup('available')) # restore script fvbr = vt_base.FakeBackupRestore('vol-123') self.m.StubOutWithMock(self.cinder_fc.restores, 'restore') self.cinder_fc.restores.restore('backup-123').AndReturn(fvbr) self.cinder_fc.volumes.get('vol-123').AndReturn(fv) self.cinder_fc.volumes.update('vol-123', description='test_description', name='test_name') self.cinder_fc.volumes.get('vol-123').AndReturn(fv) self.m.ReplayAll() t = template_format.parse(single_cinder_volume_template) stack = utils.parse_stack(t, stack_name=stack_name) scheduler.TaskRunner(stack.create)() self.assertEqual((stack.CREATE, stack.COMPLETE), stack.state) scheduler.TaskRunner(stack.snapshot)() self.assertEqual((stack.SNAPSHOT, stack.COMPLETE), stack.state) data = stack.prepare_abandon() fake_snapshot = collections.namedtuple('Snapshot', ('data', 'stack_id'))(data, stack.id) stack.restore(fake_snapshot) self.assertEqual((stack.RESTORE, stack.COMPLETE), stack.state) self.m.VerifyAll()
def test_cinder_volume_extend_attached(self): stack_name = 'test_cvolume_extend_att_stack' # create script self.stub_VolumeConstraint_validate() self._mock_create_volume(vt_base.FakeVolume('creating'), stack_name) self._mock_create_server_volume_script(vt_base.FakeVolume('attaching')) # update script attachments = [{ 'id': 'vol-123', 'device': '/dev/vdc', 'server_id': u'WikiDatabase' }] fv2 = vt_base.FakeVolume('in-use', attachments=attachments, size=1) self.cinder_fc.volumes.get(fv2.id).AndReturn(fv2) # detach script fvd = vt_base.FakeVolume('in-use') self.fc.volumes.get_server_volume(u'WikiDatabase', 'vol-123').AndReturn(fvd) self.cinder_fc.volumes.get(fvd.id).AndReturn(fvd) self.fc.volumes.delete_server_volume('WikiDatabase', 'vol-123') self.cinder_fc.volumes.get(fvd.id).AndReturn( vt_base.FakeVolume('available')) self.fc.volumes.get_server_volume(u'WikiDatabase', 'vol-123').AndReturn(fvd) self.fc.volumes.get_server_volume(u'WikiDatabase', 'vol-123').AndRaise( fakes_nova.fake_exception()) # resize script self.cinder_fc.volumes.extend(fvd.id, 2) self.cinder_fc.volumes.get(fvd.id).AndReturn( vt_base.FakeVolume('extending')) self.cinder_fc.volumes.get(fvd.id).AndReturn( vt_base.FakeVolume('extending')) self.cinder_fc.volumes.get(fvd.id).AndReturn( vt_base.FakeVolume('available')) # attach script self._mock_create_server_volume_script(vt_base.FakeVolume('attaching'), update=True) self.m.ReplayAll() stack = utils.parse_stack(self.t, stack_name=stack_name) rsrc = self.create_volume(self.t, stack, 'volume') self.create_attachment(self.t, stack, 'attachment') props = copy.deepcopy(rsrc.properties.data) props['size'] = 2 after = rsrc_defn.ResourceDefinition(rsrc.name, rsrc.type(), props) update_task = scheduler.TaskRunner(rsrc.update, after) self.assertIsNone(update_task()) self.assertEqual((rsrc.UPDATE, rsrc.COMPLETE), rsrc.state) self.m.VerifyAll()
def test_volume_check(self): stack = utils.parse_stack(self.t, stack_name='volume_check') res = stack['DataVolume'] res.cinder = mock.Mock() fake_volume = vt_base.FakeVolume('available', 'available') res.cinder().volumes.get.return_value = fake_volume scheduler.TaskRunner(res.check)() self.assertEqual((res.CHECK, res.COMPLETE), res.state) fake_volume = vt_base.FakeVolume('in-use', 'in-use') res.cinder().volumes.get.return_value = fake_volume scheduler.TaskRunner(res.check)() self.assertEqual((res.CHECK, res.COMPLETE), res.state)
def _mock_create_volume(self, fv, stack_name, final_status='available'): cinder.CinderClientPlugin._create().MultipleTimes().AndReturn( self.cinder_fc) vol_name = utils.PhysName(stack_name, 'DataVolume') self.cinder_fc.volumes.create( size=1, availability_zone='nova', description=vol_name, name=vol_name, metadata={u'Usage': u'Wiki Data Volume'}).AndReturn( vt_base.FakeVolume(fv)) self.cinder_fc.volumes.get(fv.id).AndReturn(fv) fv_ready = vt_base.FakeVolume(final_status, id=fv.id) self.cinder_fc.volumes.get(fv.id).AndReturn(fv_ready) return fv_ready
def test_volume(self): fv = vt_base.FakeVolume('creating', 'available') stack_name = 'test_volume_stack' # create script self._mock_create_volume(fv, stack_name) # delete script self.cinder_fc.volumes.get('vol-123').AndReturn(fv) self.cinder_fc.volumes.get('vol-123').AndReturn(fv) self.m.ReplayAll() stack = utils.parse_stack(self.t, stack_name=stack_name) rsrc = self.create_volume(self.t, stack, 'DataVolume') self.assertEqual('available', fv.status) fv.status = 'in-use' ex = self.assertRaises(exception.ResourceFailure, scheduler.TaskRunner(rsrc.destroy)) self.assertIn("Volume in use", six.text_type(ex)) self._mock_delete_volume(fv) fv.status = 'available' scheduler.TaskRunner(rsrc.destroy)() self.m.VerifyAll()
def test_snapshot_no_volume(self): stack_name = 'test_volume_stack' cfg.CONF.set_override('action_retry_limit', 0) fv = vt_base.FakeVolume('creating', 'error') self._mock_create_volume(fv, stack_name) self.cinder_fc.volumes.get('vol-123').AndReturn(fv) self.m.ReplayAll() self.t['Resources']['DataVolume']['DeletionPolicy'] = 'Snapshot' self.t['Resources']['DataVolume']['Properties'][ 'AvailabilityZone'] = 'nova' stack = utils.parse_stack(self.t, stack_name=stack_name) resource_defns = stack.t.resource_definitions(stack) rsrc = aws_vol.Volume('DataVolume', resource_defns['DataVolume'], stack) create = scheduler.TaskRunner(rsrc.create) ex = self.assertRaises(exception.ResourceFailure, create) self.assertIn('Went to status error due to "Unknown"', six.text_type(ex)) self._mock_delete_volume(fv) scheduler.TaskRunner(rsrc.destroy)() self.m.VerifyAll()
def test_volume_update_not_supported(self): stack_name = 'test_volume_stack' fv = vt_base.FakeVolume('creating', 'available') self._mock_create_volume(fv, stack_name) self.m.ReplayAll() t = template_format.parse(volume_template) stack = utils.parse_stack(t, stack_name=stack_name) rsrc = self.create_volume(t, stack, 'DataVolume') props = copy.deepcopy(rsrc.properties.data) props['Size'] = 2 props['Tags'] = None props['AvailabilityZone'] = 'other' after = rsrc_defn.ResourceDefinition(rsrc.name, rsrc.type(), props) updater = scheduler.TaskRunner(rsrc.update, after) ex = self.assertRaises(exception.ResourceFailure, updater) self.assertIn("NotSupported: Update to properties " "AvailabilityZone, Size, Tags of DataVolume " "(AWS::EC2::Volume) is not supported", six.text_type(ex)) self.assertEqual((rsrc.UPDATE, rsrc.FAILED), rsrc.state)
def test_volume_deleting_delete(self): fv = vt_base.FakeVolume('creating', 'available') stack_name = 'test_volume_deleting_stack' self._mock_create_volume(fv, stack_name) self.cinder_fc.volumes.get('vol-123').AndReturn(fv) self.m.ReplayAll() stack = utils.parse_stack(self.t, stack_name=stack_name) rsrc = self.create_volume(self.t, stack, 'DataVolume') self.assertEqual('available', fv.status) # make sure that delete was not called self.m.StubOutWithMock(fv, 'delete') self.m.StubOutWithMock(fv, 'get') fv.get().AndReturn(None) fv.get().AndRaise(cinder_exp.NotFound('Not found')) self.m.ReplayAll() fv.status = 'deleting' scheduler.TaskRunner(rsrc.destroy)() self.m.VerifyAll()
def test_cinder_snapshot_error(self): fv = vt_base.FakeVolume('creating', 'available') fb = vt_base.FakeBackup('creating', 'error') stack_name = 'test_volume_stack' cinder.CinderClientPlugin._create().MultipleTimes().AndReturn( self.cinder_fc) self.cinder_fc.volumes.create( size=1, availability_zone=None, name='test_name', description='test_description').AndReturn(fv) self.m.StubOutWithMock(self.cinder_fc.backups, 'create') self.cinder_fc.backups.create('vol-123').AndReturn(fb) self.m.ReplayAll() t = template_format.parse(single_cinder_volume_template) stack = utils.parse_stack(t, stack_name=stack_name) rsrc = stack['volume'] scheduler.TaskRunner(rsrc.create)() self.assertRaises(exception.ResourceFailure, scheduler.TaskRunner(rsrc.snapshot)) self.assertEqual((rsrc.SNAPSHOT, rsrc.FAILED), rsrc.state) self.assertEqual("Error: error", rsrc.status_reason) self.assertEqual({}, db_api.resource_data_get_all(rsrc)) self.m.VerifyAll()
def test_cinder_volume_update_name_and_metadata(self): # update the name, description and metadata fv = vt_base.FakeVolume('creating', 'available', size=1, name='my_vol', description='test') stack_name = 'test_volume_stack' update_name = 'update_name' meta = {'Key': 'New Value'} update_description = 'update_description' kwargs = {'name': update_name, 'description': update_description} self._mock_create_volume(fv, stack_name) self.cinder_fc.volumes.get(fv.id).AndReturn(fv) self.cinder_fc.volumes.update(fv, **kwargs).AndReturn(None) self.cinder_fc.volumes.update_all_metadata(fv, meta).AndReturn(None) self.m.ReplayAll() stack = utils.parse_stack(self.t, stack_name=stack_name) rsrc = self.create_volume(self.t, stack, 'volume') props = copy.deepcopy(rsrc.properties.data) props['name'] = update_name props['description'] = update_description props['metadata'] = meta after = rsrc_defn.ResourceDefinition(rsrc.name, rsrc.type(), props) scheduler.TaskRunner(rsrc.update, after)() self.assertEqual((rsrc.UPDATE, rsrc.COMPLETE), rsrc.state)
def test_create_from_snapshot(self): stack_name = 'test_volume_create_from_snapshot_stack' fv = vt_base.FakeVolume('restoring-backup') fvbr = vt_base.FakeBackupRestore('vol-123') # create script cinder.CinderClientPlugin._create().AndReturn( self.cinder_fc) self.m.StubOutWithMock(self.cinder_fc.restores, 'restore') self.cinder_fc.restores.restore('backup-123').AndReturn(fvbr) self.cinder_fc.volumes.get('vol-123').AndReturn(fv) vol_name = utils.PhysName(stack_name, 'DataVolume') self.cinder_fc.volumes.update('vol-123', description=vol_name, name=vol_name) fv.status = 'available' self.cinder_fc.volumes.get('vol-123').AndReturn(fv) self.m.ReplayAll() self.t['Resources']['DataVolume']['Properties'][ 'SnapshotId'] = 'backup-123' stack = utils.parse_stack(self.t, stack_name=stack_name) self.create_volume(self.t, stack, 'DataVolume') self.m.VerifyAll()
def test_create_from_snapshot_error(self): stack_name = 'test_volume_create_from_snap_err_stack' cfg.CONF.set_override('action_retry_limit', 0) fv = vt_base.FakeVolume('restoring-backup') fvbr = vt_base.FakeBackupRestore('vol-123') # create script cinder.CinderClientPlugin._create().AndReturn( self.cinder_fc) self.m.StubOutWithMock(self.cinder_fc.restores, 'restore') self.cinder_fc.restores.restore('backup-123').AndReturn(fvbr) self.cinder_fc.volumes.get('vol-123').AndReturn(fv) vol_name = utils.PhysName(stack_name, 'DataVolume') self.cinder_fc.volumes.update(fv.id, description=vol_name, name=vol_name) fv.status = 'error' self.cinder_fc.volumes.get('vol-123').AndReturn(fv) self.m.ReplayAll() self.t['Resources']['DataVolume']['Properties'][ 'SnapshotId'] = 'backup-123' stack = utils.parse_stack(self.t, stack_name=stack_name) ex = self.assertRaises(exception.ResourceFailure, self.create_volume, self.t, stack, 'DataVolume') self.assertIn('Went to status error due to "Unknown"', six.text_type(ex)) self.m.VerifyAll()
def test_cinder_snapshot(self): fv = vt_base.FakeVolume('creating', 'available') fb = vt_base.FakeBackup('creating', 'available') stack_name = 'test_cvolume_snpsht_stack' cinder.CinderClientPlugin._create().MultipleTimes().AndReturn( self.cinder_fc) self.cinder_fc.volumes.create(size=1, availability_zone=None, description='test_description', name='test_name').AndReturn(fv) self.m.StubOutWithMock(self.cinder_fc.backups, 'create') self.cinder_fc.backups.create('vol-123').AndReturn(fb) self.m.ReplayAll() t = template_format.parse(single_cinder_volume_template) stack = utils.parse_stack(t, stack_name=stack_name) rsrc = stack['volume'] scheduler.TaskRunner(rsrc.create)() scheduler.TaskRunner(rsrc.snapshot)() self.assertEqual((rsrc.SNAPSHOT, rsrc.COMPLETE), rsrc.state) self.assertEqual({'backup_id': 'backup-123'}, db_api.resource_data_get_all(rsrc)) self.m.VerifyAll()