def test_create_from_snapshot_available(self): date = datetime.datetime(1, 1, 1, 1, 1, 1) self.mock_utcnow.return_value = 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'], 'volume_type': None, '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')
def test_create(self): date = datetime.datetime(1, 1, 1, 1, 1, 1) self.mock_utcnow.return_value = date share = fake_share('fakeid', user_id=self.context.user_id, project_id=self.context.project_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'], 'volume_type': None, } with mock.patch.object(db_driver, 'share_create', mock.Mock(return_value=share)): self.api.create(self.context, 'nfs', '1', 'fakename', 'fakedesc', availability_zone='fakeaz') db_driver.share_create.assert_called_once_with( self.context, options)
def test_create_from_snapshot_available(self): date = datetime.datetime(1, 1, 1, 1, 1, 1) self.mock_utcnow.return_value = 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")
def test_delete_error(self): date = datetime.datetime(2, 2, 2, 2, 2, 2) self.mock_utcnow.return_value = date share = fake_share("fakeid", status="error") options = {"status": "deleting", "terminated_at": date} deleting_share = share.copy() deleting_share.update(options) with mock.patch.object(db_driver, "share_update", mock.Mock(return_value=deleting_share)): self.api.delete(self.context, share) db_driver.share_update.assert_called_once_with(self.context, share["id"], options) self.share_rpcapi.delete_share.assert_called_once_with(self.context, deleting_share)
def test_create_from_snapshot_with_volume_type_same(self): # Prepare data for test CONF.set_default("use_scheduler_creating_share_from_snapshot", False) date = datetime.datetime(1, 1, 1, 1, 1, 1) self.mock_utcnow.return_value = date share_id = 'fake_share_id' snapshot = fake_snapshot('fakesnapshotid', share_id=share_id, status='available') volume_type = {'id': 'fake_volume_type'} share = fake_share(share_id, user_id=self.context.user_id, project_id=self.context.project_id, snapshot_id=snapshot['id'], status='creating', volume_type_id=volume_type['id']) 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, 'volume_type': volume_type, 'snapshot_id': share['snapshot_id'], } self.stubs.Set(db_driver, 'share_create', mock.Mock(return_value=share)) self.stubs.Set(db_driver, 'share_update', mock.Mock(return_value=share)) self.stubs.Set(db_driver, 'share_get', mock.Mock(return_value=share)) # Call tested method self.api.create(self.context, 'nfs', '1', 'fakename', 'fakedesc', snapshot=snapshot, availability_zone='fakeaz', volume_type=volume_type) # Verify results self.share_rpcapi.create_share.assert_called_once_with( self.context, share, snapshot['share']['host'], request_spec=request_spec, filter_properties={}, snapshot_id=snapshot['id']) db_driver.share_create.assert_called_once_with( self.context, options) share_api.policy.check_policy.assert_called_once_with( self.context, 'share', 'create') quota.QUOTAS.reserve.assert_called_once_with( self.context, gigabytes=1, shares=1) quota.QUOTAS.commit.assert_called_once_with( self.context, 'reservation') db_driver.share_get.assert_called_once_with( self.context, share_id) db_driver.share_update.assert_called_once_with( self.context, share_id, {'host': snapshot['share']['host']})
def test_create(self): date = datetime.datetime(1, 1, 1, 1, 1, 1) self.mock_utcnow.return_value = date share = fake_share( "fakeid", user_id=self.context.user_id, project_id=self.context.project_id, status="creating" ) options = share.copy() for name in ("id", "export_location", "host", "launched_at", "terminated_at"): options.pop(name, None) with mock.patch.object(db_driver, "share_create", mock.Mock(return_value=share)): self.api.create(self.context, "nfs", "1", "fakename", "fakedesc", availability_zone="fakeaz") db_driver.share_create.assert_called_once_with(self.context, options)
def test_delete_error(self): date = datetime.datetime(2, 2, 2, 2, 2, 2) self.mock_utcnow.return_value = date share = fake_share('fakeid', status='error') options = {'status': 'deleting', 'terminated_at': date} deleting_share = share.copy() deleting_share.update(options) with mock.patch.object(db_driver, 'share_update', mock.Mock(return_value=deleting_share)): self.api.delete(self.context, share) db_driver.share_update.assert_called_once_with( self.context, share['id'], options) self.share_rpcapi.delete_share.assert_called_once_with( self.context, deleting_share)
def test_delete_error(self): date = datetime.datetime(2, 2, 2, 2, 2, 2) self.mock_utcnow.return_value = 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()
def test_create_from_snapshot_available(self): date = datetime.datetime(1, 1, 1, 1, 1, 1) self.mock_utcnow.return_value = 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'], 'volume_type': None, 'snapshot_id': share['snapshot_id'], } with mock.patch.object(db_driver, 'share_create', mock.Mock(return_value=share)): self.api.create(self.context, 'nfs', '1', 'fakename', 'fakedesc', snapshot=snapshot, availability_zone='fakeaz') self.scheduler_rpcapi.create_share.assert_called_once_with( self.context, 'manila-share', share['id'], share['snapshot_id'], request_spec=request_spec, filter_properties={}) db_driver.share_create.assert_called_once_with( self.context, options) share_api.policy.check_policy.assert_called_once_with( self.context, 'share', 'create') quota.QUOTAS.reserve.assert_called_once_with(self.context, gigabytes=1, shares=1) quota.QUOTAS.commit.assert_called_once_with( self.context, 'reservation')
def test_delete_available(self): date = datetime.datetime(2, 2, 2, 2, 2, 2) timeutils.set_time_override(override_time=date) share = fake_share('fakeid', status='available') 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()
def test_create(self): date = datetime.datetime(1, 1, 1, 1, 1, 1) self.mock_utcnow.return_value = date share = fake_share('fakeid', user_id=self.context.user_id, project_id=self.context.project_id, status='creating') options = share.copy() for name in ('id', 'export_location', 'host', 'launched_at', 'terminated_at'): options.pop(name, None) with mock.patch.object(db_driver, 'share_create', mock.Mock(return_value=share)): self.api.create(self.context, 'nfs', '1', 'fakename', 'fakedesc', availability_zone='fakeaz') db_driver.share_create.assert_called_once_with( self.context, options)
def test_delete_error(self): date = datetime.datetime(2, 2, 2, 2, 2, 2) self.mock_utcnow.return_value = 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()
def test_create_glusterfs(self): date = datetime.datetime(1, 1, 1, 1, 1, 1) self.mock_utcnow.return_value = date share = fake_share('fakeid', user_id=self.context.user_id, project_id=self.context.project_id, status='creating') options = share.copy() for name in ('id', 'export_location', 'host', 'launched_at', 'terminated_at'): options.pop(name, None) with mock.patch.object(db_driver, 'share_create', mock.Mock(return_value=share)): options.update(share_proto='glusterfs') self.api.create(self.context, 'glusterfs', '1', 'fakename', 'fakedesc', availability_zone='fakeaz') db_driver.share_create.assert_called_once_with( self.context, options)
def test_create_from_snapshot_without_host_restriction(self): CONF.set_default("use_scheduler_creating_share_from_snapshot", True) date = datetime.datetime(1, 1, 1, 1, 1, 1) self.mock_utcnow.return_value = 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'], 'volume_type': None, 'snapshot_id': share['snapshot_id'], } self.stubs.Set(db_driver, 'share_create', mock.Mock(return_value=share)) self.stubs.Set(db_driver, 'share_update', mock.Mock(return_value=share)) self.api.create(self.context, 'nfs', '1', 'fakename', 'fakedesc', snapshot=snapshot, availability_zone='fakeaz') self.scheduler_rpcapi.create_share.assert_called_once_with( self.context, 'manila-share', share['id'], share['snapshot_id'], request_spec=request_spec, filter_properties={}) db_driver.share_create.assert_called_once_with( self.context, options) share_api.policy.check_policy.assert_called_once_with( self.context, 'share', 'create') quota.QUOTAS.reserve.assert_called_once_with( self.context, gigabytes=1, shares=1) quota.QUOTAS.commit.assert_called_once_with( self.context, 'reservation')
def test_create_from_snapshot_available(self): date = datetime.datetime(1, 1, 1, 1, 1, 1) self.mock_utcnow.return_value = 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"], "volume_type": None, "snapshot_id": share["snapshot_id"], } with mock.patch.object(db_driver, "share_create", mock.Mock(return_value=share)): self.api.create( self.context, "nfs", "1", "fakename", "fakedesc", snapshot=snapshot, availability_zone="fakeaz" ) self.scheduler_rpcapi.create_share.assert_called_once_with( self.context, "manila-share", share["id"], share["snapshot_id"], request_spec=request_spec, filter_properties={}, ) db_driver.share_create.assert_called_once_with(self.context, options) share_api.policy.check_policy.assert_called_once_with(self.context, "share", "create") quota.QUOTAS.reserve.assert_called_once_with(self.context, gigabytes=1, shares=1) quota.QUOTAS.commit.assert_called_once_with(self.context, "reservation")
def test_create_from_snapshot_with_volume_type_different(self): # Prepare data for test date = datetime.datetime(1, 1, 1, 1, 1, 1) self.mock_utcnow.return_value = date share_id = 'fake_share_id' snapshot = fake_snapshot('fakesnapshotid', share_id=share_id, status='available') volume_type = {'id': 'fake_volume_type'} share = fake_share(share_id, user_id=self.context.user_id, project_id=self.context.project_id, snapshot_id=snapshot['id'], status='creating', volume_type_id=volume_type['id'][1:]) options = share.copy() for name in ('id', 'export_location', 'host', 'launched_at', 'terminated_at'): options.pop(name, None) self.stubs.Set(db_driver, 'share_create', mock.Mock(return_value=share)) self.stubs.Set(db_driver, 'share_get', mock.Mock(return_value=share)) # Call tested method self.assertRaises(exception.InvalidInput, self.api.create, self.context, 'nfs', '1', 'fakename', 'fakedesc', snapshot=snapshot, availability_zone='fakeaz', volume_type=volume_type) # Verify results share_api.policy.check_policy.assert_called_once_with( self.context, 'share', 'create') self.scheduler_rpcapi.create_share.assert_has_calls([]) db_driver.share_create.assert_has_calls([]) quota.QUOTAS.reserve.assert_has_calls([]) quota.QUOTAS.commit.assert_has_calls([]) db_driver.share_get.assert_called_once_with( self.context, share_id)