Esempio n. 1
0
    def test_create_from_snapshot_available(self):
        date = datetime.datetime(1, 1, 1, 1, 1, 1)
        timeutils.set_time_override(override_time=date)
        snapshot = fake_snapshot('fakesnapshotid',
                                 share_id='fakeshare_id',
                                 status='available')
        share = fake_share('fakeid',
                           user_id=self.context.user_id,
                           project_id=self.context.project_id,
                           snapshot_id=snapshot['id'],
                           status='creating')
        options = share.copy()
        for name in ('id', 'export_location', 'host', 'launched_at',
                     'terminated_at'):
            options.pop(name, None)
        request_spec = {'share_properties': options,
                        'share_proto': share['share_proto'],
                        'share_id': share['id'],
                        'snapshot_id': share['snapshot_id'],
                        }

        self.mox.StubOutWithMock(db_driver, 'share_create')
        db_driver.share_create(self.context, options).AndReturn(share)
        self.scheduler_rpcapi.create_share(self.context, mox.IgnoreArg(),
                                           share['id'], share['snapshot_id'],
                                           request_spec=request_spec,
                                           filter_properties={})
        self.mox.ReplayAll()
        self.api.create(self.context, 'nfs', '1', 'fakename', 'fakedesc',
                        snapshot=snapshot, availability_zone='fakeaz')
Esempio n. 2
0
    def test_create_snapshot(self):
        date = datetime.datetime(1, 1, 1, 1, 1, 1)
        timeutils.set_time_override(override_time=date)
        share = fake_share('fakeid',
                           status='available')
        snapshot = fake_snapshot('fakesnapshotid',
                                 share_id=share['id'],
                                 status='creating')
        fake_name = 'fakename'
        fake_desc = 'fakedesc'
        options = {'share_id': share['id'],
                   'user_id': self.context.user_id,
                   'project_id': self.context.project_id,
                   'status': "creating",
                   'progress': '0%',
                   'share_size': share['size'],
                   'size': 1,
                   'display_name': fake_name,
                   'display_description': fake_desc,
                   'share_proto': share['share_proto'],
                   'export_location': share['export_location']}

        self.mox.StubOutWithMock(share_api, 'check_policy')
        share_api.check_policy(self.context, 'create_snapshot', share)
        self.mox.StubOutWithMock(quota.QUOTAS, 'reserve')
        quota.QUOTAS.reserve(self.context, snapshots=1, gigabytes=1).\
            AndReturn('reservation')
        self.mox.StubOutWithMock(db_driver, 'share_snapshot_create')
        db_driver.share_snapshot_create(self.context,
                                        options).AndReturn(snapshot)
        self.mox.StubOutWithMock(quota.QUOTAS, 'commit')
        quota.QUOTAS.commit(self.context, 'reservation')
        self.share_rpcapi.create_snapshot(self.context, share, snapshot)
        self.mox.ReplayAll()
        self.api.create_snapshot(self.context, share, fake_name, fake_desc)
Esempio n. 3
0
 def setUp(self):
     super(AuditPeriodTest, self).setUp()
     #a fairly random time to test with
     self.test_time = datetime.datetime(second=23,
                                        minute=12,
                                        hour=8,
                                        day=5,
                                        month=3,
                                        year=2012)
     timeutils.set_time_override(override_time=self.test_time)
Esempio n. 4
0
    def test_delete_error(self):
        date = datetime.datetime(2, 2, 2, 2, 2, 2)
        timeutils.set_time_override(override_time=date)
        share = fake_share('fakeid', status='error')
        options = {'status': 'deleting',
                   'terminated_at': date}
        deleting_share = share.copy()
        deleting_share.update(options)

        self.mox.StubOutWithMock(db_driver, 'share_update')
        db_driver.share_update(self.context, share['id'], options).\
            AndReturn(deleting_share)
        self.share_rpcapi.delete_share(self.context, deleting_share)
        self.mox.ReplayAll()
        self.api.delete(self.context, share)
        self.mox.UnsetStubs()
        self.mox.VerifyAll()
Esempio n. 5
0
 def test_delete_snapshot(self):
     date = datetime.datetime(1, 1, 1, 1, 1, 1)
     timeutils.set_time_override(override_time=date)
     share = fake_share('fakeid')
     snapshot = fake_snapshot('fakesnapshotid', share_id=share['id'],
                              status='available')
     self.mox.StubOutWithMock(share_api, 'check_policy')
     share_api.check_policy(self.context, 'delete_snapshot', snapshot)
     self.mox.StubOutWithMock(db_driver, 'share_snapshot_update')
     db_driver.share_snapshot_update(self.context, snapshot['id'],
                                     {'status': 'deleting'})
     self.mox.StubOutWithMock(db_driver, 'share_get')
     db_driver.share_get(self.context,
                         snapshot['share_id']).AndReturn(share)
     self.share_rpcapi.delete_snapshot(self.context, snapshot,
                                       share['host'])
     self.mox.ReplayAll()
     self.api.delete_snapshot(self.context, snapshot)