Пример #1
0
    def test_create_snapshot(self):
        date = datetime.datetime(1, 1, 1, 1, 1, 1)
        self.mock_utcnow.return_value = 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.policy, "check_policy")
        share_api.policy.check_policy(self.context, "share", "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)
Пример #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)
Пример #3
0
 def _create_snapshot(status="creating", size=0, share_id=None):
     """Create a snapshot object."""
     snapshot = {}
     snapshot['share_proto'] = "NFS"
     snapshot['size'] = size
     snapshot['share_id'] = share_id
     snapshot['user_id'] = 'fake'
     snapshot['project_id'] = 'fake'
     snapshot['status'] = status
     return db.share_snapshot_create(context.get_admin_context(), snapshot)
Пример #4
0
 def _create_snapshot(status="creating", size=0, share_id=None):
     """Create a snapshot object."""
     snapshot = {}
     snapshot['share_proto'] = "NFS"
     snapshot['size'] = size
     snapshot['share_id'] = share_id
     snapshot['user_id'] = 'fake'
     snapshot['project_id'] = 'fake'
     snapshot['status'] = status
     return db.share_snapshot_create(context.get_admin_context(), snapshot)
Пример #5
0
 def test_snapshot_reset_status(self):
     # snapshot in 'error_deleting'
     share = db.share_create(self.admin_context, {})
     snapshot = db.share_snapshot_create(self.admin_context,
         {'status': 'error_deleting', 'share_id': share['id']})
     req = webob.Request.blank('/v1/fake/snapshots/%s/action' %
                               snapshot['id'])
     req.method = 'POST'
     req.headers['content-type'] = 'application/json'
     # request status of 'error'
     req.body = jsonutils.dumps({'os-reset_status': {'status': 'error'}})
     # attach admin context to request
     req.environ['manila.context'] = self.admin_context
     resp = req.get_response(app())
     # request is accepted
     self.assertEqual(resp.status_int, 202)
     snapshot = db.share_snapshot_get(self.admin_context, snapshot['id'])
     # status changed to 'error'
     self.assertEqual(snapshot['status'], 'error')
Пример #6
0
 def setUp(self):
     self.context = context.get_admin_context()
     shr = {}
     shr['host'] = 'fake_host'
     shr['availability_zone'] = CONF.storage_availability_zone
     shr['status'] = "available"
     share = db.share_create(self.context, shr)
     acs = {}
     acs['access_type'] = "ip"
     acs['access_to'] = "123.123.123.123"
     acs['share_id'] = share['id']
     access = db.share_access_create(self.context, acs)
     snap = {}
     snap['share_id'] = share['id']
     snapshot = db.share_snapshot_create(self.context, snap)
     self.fake_share = jsonutils.to_primitive(share)
     self.fake_access = jsonutils.to_primitive(access)
     self.fake_snapshot = jsonutils.to_primitive(snapshot)
     super(ShareRpcAPITestCase, self).setUp()
Пример #7
0
def create_snapshot(**kwargs):
    """Create a snapshot object."""
    with_share = kwargs.pop('with_share', False)

    share = None
    if with_share:
        share = create_share(status=constants.STATUS_AVAILABLE,
                             size=kwargs.get('size', 0))

    snapshot = {
        'share_proto': "NFS",
        'size': 0,
        'share_id': share['id'] if with_share else None,
        'user_id': 'fake',
        'project_id': 'fake',
        'status': 'creating',
        'provider_location': 'fake',
    }
    snapshot.update(kwargs)
    return db.share_snapshot_create(context.get_admin_context(), snapshot)
Пример #8
0
def create_snapshot(**kwargs):
    """Create a snapshot object."""
    with_share = kwargs.pop('with_share', False)

    share = None
    if with_share:
        share = create_share(status=constants.STATUS_AVAILABLE,
                             size=kwargs.get('size', 0))

    snapshot = {
        'share_proto': "NFS",
        'size': 0,
        'share_id': share['id'] if with_share else None,
        'user_id': 'fake',
        'project_id': 'fake',
        'status': 'creating',
        'provider_location': 'fake',
    }
    snapshot.update(kwargs)
    return db.share_snapshot_create(context.get_admin_context(), snapshot)
Пример #9
0
 def test_invalid_status_for_snapshot(self):
     # snapshot in 'available'
     share = db.share_create(self.admin_context, {})
     snapshot = db.share_snapshot_create(self.admin_context,
         {'status': 'available', 'share_id': share['id']})
     req = webob.Request.blank('/v1/fake/snapshots/%s/action' %
                               snapshot['id'])
     req.method = 'POST'
     req.headers['content-type'] = 'application/json'
     # 'attaching' is not a valid status for snapshots
     req.body = jsonutils.dumps({'os-reset_status': {'status':
                                                     'attaching'}})
     # attach admin context to request
     req.environ['manila.context'] = self.admin_context
     resp = req.get_response(app())
     # request is accepted
     self.assertEqual(resp.status_int, 400)
     snapshot = db.share_snapshot_get(self.admin_context, snapshot['id'])
     # status is still 'available'
     self.assertEqual(snapshot['status'], 'available')
Пример #10
0
 def test_snapshot_reset_status(self):
     # snapshot in 'error_deleting'
     share = db.share_create(self.admin_context, {})
     snapshot = db.share_snapshot_create(self.admin_context, {
         'status': 'error_deleting',
         'share_id': share['id']
     })
     req = webob.Request.blank('/v1/fake/snapshots/%s/action' %
                               snapshot['id'])
     req.method = 'POST'
     req.headers['content-type'] = 'application/json'
     # request status of 'error'
     req.body = jsonutils.dumps({'os-reset_status': {'status': 'error'}})
     # attach admin context to request
     req.environ['manila.context'] = self.admin_context
     resp = req.get_response(app())
     # request is accepted
     self.assertEqual(resp.status_int, 202)
     snapshot = db.share_snapshot_get(self.admin_context, snapshot['id'])
     # status changed to 'error'
     self.assertEqual(snapshot['status'], 'error')
Пример #11
0
 def test_invalid_status_for_snapshot(self):
     # snapshot in 'available'
     share = db.share_create(self.admin_context, {})
     snapshot = db.share_snapshot_create(self.admin_context,
                                         {
                                             'status': 'available',
                                             'share_id': share['id']
                                         })
     req = webob.Request.blank('/v1/fake/snapshots/%s/action' %
                               snapshot['id'])
     req.method = 'POST'
     req.headers['content-type'] = 'application/json'
     # 'attaching' is not a valid status for snapshots
     req.body = jsonutils.dumps({'os-reset_status': {'status':
                                                     'attaching'}})
     # attach admin context to request
     req.environ['manila.context'] = self.admin_context
     resp = req.get_response(app())
     # request is accepted
     self.assertEqual(resp.status_int, 400)
     snapshot = db.share_snapshot_get(self.admin_context, snapshot['id'])
     # status is still 'available'
     self.assertEqual(snapshot['status'], 'available')
Пример #12
0
 def setUp(self):
     super(ShareRpcAPITestCase, self).setUp()
     self.context = context.get_admin_context()
     shr = {}
     shr['host'] = 'fake_host'
     shr['availability_zone'] = CONF.storage_availability_zone
     shr['status'] = "available"
     share = db.share_create(self.context, shr)
     acs = {}
     acs['access_type'] = "ip"
     acs['access_to'] = "123.123.123.123"
     acs['share_id'] = share['id']
     access = db.share_access_create(self.context, acs)
     snap = {}
     snap['share_id'] = share['id']
     snapshot = db.share_snapshot_create(self.context, snap)
     server = {'id': 'fake_share_server_id', 'host': 'fake_host'}
     share_server = db.share_server_create(self.context, server)
     self.fake_share = jsonutils.to_primitive(share)
     self.fake_access = jsonutils.to_primitive(access)
     self.fake_snapshot = jsonutils.to_primitive(snapshot)
     self.fake_share_server = jsonutils.to_primitive(share_server)
     self.ctxt = context.RequestContext('fake_user', 'fake_project')
     self.rpcapi = share_rpcapi.ShareAPI()