Exemple #1
0
    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()
Exemple #2
0
    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()
Exemple #3
0
    def _test_volume_restore(self,
                             stack_name,
                             final_status='available',
                             stack_final_status=('RESTORE', 'COMPLETE')):
        # 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)
        self.stub_VolumeBackupConstraint_validate()

        # 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',
                                        'vol-123').AndReturn(fvbr)
        fv_restoring = vt_base.FakeVolume('restoring-backup', id=fv.id)
        self.cinder_fc.volumes.get('vol-123').AndReturn(fv_restoring)
        fv_final = vt_base.FakeVolume(final_status, id=fv.id)
        self.cinder_fc.volumes.get('vol-123').AndReturn(fv_final)

        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, None)()

        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_final_status, stack.state)

        self.m.VerifyAll()
Exemple #4
0
    def test_cinder_volume_extend_created_from_backup_with_same_size(self):
        stack_name = 'test_cvolume_extend_snapsht_stack'

        # create script
        self.stub_VolumeBackupConstraint_validate()
        fvbr = vt_base.FakeBackupRestore('vol-123')
        cinder.CinderClientPlugin._create().MultipleTimes().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(
            vt_base.FakeVolume('restoring-backup'))
        vol_name = utils.PhysName(stack_name, 'volume')
        self.cinder_fc.volumes.update('vol-123',
                                      description=None,
                                      name=vol_name).AndReturn(None)
        self.cinder_fc.volumes.get('vol-123').AndReturn(
            vt_base.FakeVolume('available'))

        # 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'] = {
            'availability_zone': 'nova',
            'backup_id': 'backup-123'
        }
        stack = utils.parse_stack(self.t, stack_name=stack_name)

        rsrc = self.create_volume(self.t, stack, 'volume')
        self.assertEqual((rsrc.CREATE, rsrc.COMPLETE), rsrc.state)
        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)
        self.assertIsNone(update_task())

        self.assertEqual((rsrc.UPDATE, rsrc.COMPLETE), rsrc.state)
        self.m.VerifyAll()