Esempio n. 1
0
    def test_allow_access(self, ip_address, version):
        share = db_utils.create_share(mount_snapshot_support=True)
        snapshot = db_utils.create_snapshot(
            status=constants.STATUS_AVAILABLE, share_id=share['id'])

        access = {
            'id': 'fake_id',
            'access_type': 'ip',
            'access_to': ip_address,
            'state': 'new',
        }

        get = self.mock_object(share_api.API, 'get',
                               mock.Mock(return_value=share))
        get_snapshot = self.mock_object(share_api.API, 'get_snapshot',
                                        mock.Mock(return_value=snapshot))
        allow_access = self.mock_object(share_api.API, 'snapshot_allow_access',
                                        mock.Mock(return_value=access))
        body = {'allow_access': access}
        req = fakes.HTTPRequest.blank('/snapshots/%s/action' % snapshot['id'],
                                      version=version)

        actual = self.controller.allow_access(req, snapshot['id'], body)

        self.assertEqual(access, actual['snapshot_access'])
        get.assert_called_once_with(utils.IsAMatcher(context.RequestContext),
                                    share['id'])
        get_snapshot.assert_called_once_with(
            utils.IsAMatcher(context.RequestContext), snapshot['id'])
        allow_access.assert_called_once_with(
            utils.IsAMatcher(context.RequestContext), snapshot,
            access['access_type'], access['access_to'])
Esempio n. 2
0
 def setUp(self):
     super(ShareRpcAPITestCase, self).setUp()
     self.context = context.get_admin_context()
     share = db_utils.create_share(
         availability_zone=CONF.storage_availability_zone,
         status=constants.STATUS_AVAILABLE)
     snapshot = db_utils.create_snapshot(share_id=share['id'])
     share_replica = db_utils.create_share_replica(
         id='fake_replica',
         share_id='fake_share_id',
         host='fake_host',
     )
     share_server = db_utils.create_share_server()
     share_group = {'id': 'fake_share_group_id', 'host': 'fake_host'}
     share_group_snapshot = {'id': 'fake_share_group_id'}
     host = 'fake_host'
     self.fake_share = jsonutils.to_primitive(share)
     # mock out the getattr on the share db model object since jsonutils
     # doesn't know about those extra attributes to pull in
     self.fake_share['instance'] = jsonutils.to_primitive(share.instance)
     self.fake_share_replica = jsonutils.to_primitive(share_replica)
     self.fake_snapshot = jsonutils.to_primitive(snapshot)
     self.fake_snapshot['share_instance'] = jsonutils.to_primitive(
         snapshot.instance)
     self.fake_share_server = jsonutils.to_primitive(share_server)
     self.fake_share_group = jsonutils.to_primitive(share_group)
     self.fake_share_group_snapshot = jsonutils.to_primitive(
         share_group_snapshot)
     self.fake_host = jsonutils.to_primitive(host)
     self.ctxt = context.RequestContext('fake_user', 'fake_project')
     self.rpcapi = share_rpcapi.ShareAPI()
Esempio n. 3
0
    def test_allow_access_share_without_mount_snap_support(self):
        share = db_utils.create_share(mount_snapshot_support=False)
        snapshot = db_utils.create_snapshot(
            status=constants.STATUS_AVAILABLE, share_id=share['id'])

        access = {
            'id': 'fake_id',
            'access_type': 'ip',
            'access_to': '1.1.1.1',
            'state': 'new',
        }

        get_snapshot = self.mock_object(share_api.API, 'get_snapshot',
                                        mock.Mock(return_value=snapshot))
        get = self.mock_object(share_api.API, 'get',
                               mock.Mock(return_value=share))

        body = {'allow_access': access}
        req = fakes.HTTPRequest.blank('/snapshots/%s/action' % snapshot['id'],
                                      version='2.32')

        self.assertRaises(webob.exc.HTTPBadRequest,
                          self.controller.allow_access, req,
                          snapshot['id'], body)

        get.assert_called_once_with(utils.IsAMatcher(context.RequestContext),
                                    share['id'])
        get_snapshot.assert_called_once_with(
            utils.IsAMatcher(context.RequestContext), snapshot['id'])
Esempio n. 4
0
 def setUp(self):
     super(ShareRpcAPITestCase, self).setUp()
     self.context = context.get_admin_context()
     share = db_utils.create_share(
         availability_zone=CONF.storage_availability_zone,
         status=constants.STATUS_AVAILABLE
     )
     access = db_utils.create_access(share_id=share['id'])
     snapshot = db_utils.create_snapshot(share_id=share['id'])
     share_replica = db_utils.create_share_replica(
         id='fake_replica',
         share_id='fake_share_id',
         host='fake_host',
     )
     share_server = db_utils.create_share_server()
     cg = {'id': 'fake_cg_id', 'host': 'fake_host'}
     cgsnapshot = {'id': 'fake_cg_id'}
     host = {'host': 'fake_host', 'capabilities': 1}
     self.fake_share = jsonutils.to_primitive(share)
     # mock out the getattr on the share db model object since jsonutils
     # doesn't know about those extra attributes to pull in
     self.fake_share['instance'] = jsonutils.to_primitive(share.instance)
     self.fake_share_replica = jsonutils.to_primitive(share_replica)
     self.fake_access = jsonutils.to_primitive(access)
     self.fake_snapshot = jsonutils.to_primitive(snapshot)
     self.fake_share_server = jsonutils.to_primitive(share_server)
     self.fake_cg = jsonutils.to_primitive(cg)
     self.fake_cgsnapshot = jsonutils.to_primitive(cgsnapshot)
     self.fake_host = jsonutils.to_primitive(host)
     self.ctxt = context.RequestContext('fake_user', 'fake_project')
     self.rpcapi = share_rpcapi.ShareAPI()
Esempio n. 5
0
    def test_deny_access(self):
        share = db_utils.create_share(mount_snapshot_support=True)
        snapshot = db_utils.create_snapshot(
            status=constants.STATUS_AVAILABLE, share_id=share['id'])
        access = db_utils.create_snapshot_access(
            share_snapshot_id=snapshot['id'])

        get = self.mock_object(share_api.API, 'get',
                               mock.Mock(return_value=share))
        get_snapshot = self.mock_object(share_api.API, 'get_snapshot',
                                        mock.Mock(return_value=snapshot))
        access_get = self.mock_object(share_api.API, 'snapshot_access_get',
                                      mock.Mock(return_value=access))
        deny_access = self.mock_object(share_api.API, 'snapshot_deny_access')

        body = {'deny_access': {'access_id': access.id}}
        req = fakes.HTTPRequest.blank('/snapshots/%s/action' % snapshot['id'],
                                      version='2.32')

        resp = self.controller.deny_access(req, snapshot['id'], body)

        self.assertEqual(202, resp.status_int)
        get.assert_called_once_with(utils.IsAMatcher(context.RequestContext),
                                    share['id'])
        get_snapshot.assert_called_once_with(
            utils.IsAMatcher(context.RequestContext), snapshot['id'])
        access_get.assert_called_once_with(
            utils.IsAMatcher(context.RequestContext),
            body['deny_access']['access_id'])
        deny_access.assert_called_once_with(
            utils.IsAMatcher(context.RequestContext), snapshot, access)
Esempio n. 6
0
    def test_allow_access_exists_exception(self):
        share = db_utils.create_share(mount_snapshot_support=True)
        snapshot = db_utils.create_snapshot(
            status=constants.STATUS_AVAILABLE, share_id=share['id'])
        req = fakes.HTTPRequest.blank('/snapshots/%s/action' % snapshot['id'],
                                      version='2.32')
        access = {
            'id': 'fake_id',
            'access_type': 'ip',
            'access_to': '1.1.1.1',
            'state': 'new',
        }
        msg = "Share snapshot access exists."

        get = self.mock_object(share_api.API, 'get', mock.Mock(
            return_value=share))
        get_snapshot = self.mock_object(share_api.API, 'get_snapshot',
                                        mock.Mock(return_value=snapshot))
        allow_access = self.mock_object(
            share_api.API, 'snapshot_allow_access', mock.Mock(
                side_effect=exception.ShareSnapshotAccessExists(msg)))

        body = {'allow_access': access}

        self.assertRaises(webob.exc.HTTPBadRequest,
                          self.controller.allow_access, req,
                          snapshot['id'], body)

        get.assert_called_once_with(utils.IsAMatcher(context.RequestContext),
                                    share['id'])
        get_snapshot.assert_called_once_with(
            utils.IsAMatcher(context.RequestContext), snapshot['id'])
        allow_access.assert_called_once_with(
            utils.IsAMatcher(context.RequestContext), snapshot,
            access['access_type'], access['access_to'])
Esempio n. 7
0
    def test_deny_access_access_rule_not_found(self):
        share = db_utils.create_share(mount_snapshot_support=True)
        snapshot = db_utils.create_snapshot(
            status=constants.STATUS_AVAILABLE, share_id=share['id'])
        access = db_utils.create_snapshot_access(
            share_snapshot_id=snapshot['id'])
        wrong_access = {
            'access_type': 'fake_type',
            'access_to': 'fake_IP',
            'share_snapshot_id': 'fake_id'
        }

        get = self.mock_object(share_api.API, 'get',
                               mock.Mock(return_value=share))
        get_snapshot = self.mock_object(share_api.API, 'get_snapshot',
                                        mock.Mock(return_value=snapshot))
        access_get = self.mock_object(share_api.API, 'snapshot_access_get',
                                      mock.Mock(return_value=wrong_access))

        body = {'deny_access': {'access_id': access.id}}
        req = fakes.HTTPRequest.blank('/snapshots/%s/action' % snapshot['id'],
                                      version='2.32')

        self.assertRaises(webob.exc.HTTPBadRequest,
                          self.controller.deny_access, req, snapshot['id'],
                          body)
        get.assert_called_once_with(utils.IsAMatcher(context.RequestContext),
                                    share['id'])
        get_snapshot.assert_called_once_with(
            utils.IsAMatcher(context.RequestContext), snapshot['id'])
        access_get.assert_called_once_with(
            utils.IsAMatcher(context.RequestContext),
            body['deny_access']['access_id'])
Esempio n. 8
0
 def setUp(self):
     super(ShareRpcAPITestCase, self).setUp()
     self.context = context.get_admin_context()
     share = db_utils.create_share(
         availability_zone=CONF.storage_availability_zone,
         status=constants.STATUS_AVAILABLE)
     access = db_utils.create_access(share_id=share['id'])
     snapshot = db_utils.create_snapshot(share_id=share['id'])
     share_replica = db_utils.create_share_replica(
         id='fake_replica',
         share_id='fake_share_id',
     )
     share_server = db_utils.create_share_server()
     cg = {'id': 'fake_cg_id', 'host': 'fake_host'}
     cgsnapshot = {'id': 'fake_cg_id'}
     host = {'host': 'fake_host', 'capabilities': 1}
     self.fake_share = jsonutils.to_primitive(share)
     self.fake_share_replica = jsonutils.to_primitive(share_replica)
     self.fake_access = jsonutils.to_primitive(access)
     self.fake_snapshot = jsonutils.to_primitive(snapshot)
     self.fake_share_server = jsonutils.to_primitive(share_server)
     self.fake_cg = jsonutils.to_primitive(cg)
     self.fake_cgsnapshot = jsonutils.to_primitive(cgsnapshot)
     self.fake_host = jsonutils.to_primitive(host)
     self.ctxt = context.RequestContext('fake_user', 'fake_project')
     self.rpcapi = share_rpcapi.ShareAPI()
Esempio n. 9
0
    def test_allow_access_share_without_mount_snap_support(self):
        share = db_utils.create_share(mount_snapshot_support=False)
        snapshot = db_utils.create_snapshot(
            status=constants.STATUS_AVAILABLE, share_id=share['id'])

        access = {
            'id': 'fake_id',
            'access_type': 'ip',
            'access_to': '1.1.1.1',
            'state': 'new',
        }

        get_snapshot = self.mock_object(share_api.API, 'get_snapshot',
                                        mock.Mock(return_value=snapshot))
        get = self.mock_object(share_api.API, 'get',
                               mock.Mock(return_value=share))

        body = {'allow_access': access}
        req = fakes.HTTPRequest.blank('/snapshots/%s/action' % snapshot['id'],
                                      version='2.32')

        self.assertRaises(webob.exc.HTTPBadRequest,
                          self.controller.allow_access, req,
                          snapshot['id'], body)

        get.assert_called_once_with(utils.IsAMatcher(context.RequestContext),
                                    share['id'])
        get_snapshot.assert_called_once_with(
            utils.IsAMatcher(context.RequestContext), snapshot['id'])
Esempio n. 10
0
    def test_deny_access(self):
        share = db_utils.create_share(mount_snapshot_support=True)
        snapshot = db_utils.create_snapshot(
            status=constants.STATUS_AVAILABLE, share_id=share['id'])
        access = db_utils.create_snapshot_access(
            share_snapshot_id=snapshot['id'])

        get = self.mock_object(share_api.API, 'get',
                               mock.Mock(return_value=share))
        get_snapshot = self.mock_object(share_api.API, 'get_snapshot',
                                        mock.Mock(return_value=snapshot))
        access_get = self.mock_object(share_api.API, 'snapshot_access_get',
                                      mock.Mock(return_value=access))
        deny_access = self.mock_object(share_api.API, 'snapshot_deny_access')

        body = {'deny_access': {'access_id': access.id}}
        req = fakes.HTTPRequest.blank('/snapshots/%s/action' % snapshot['id'],
                                      version='2.32')

        resp = self.controller.deny_access(req, snapshot['id'], body)

        self.assertEqual(202, resp.status_int)
        get.assert_called_once_with(utils.IsAMatcher(context.RequestContext),
                                    share['id'])
        get_snapshot.assert_called_once_with(
            utils.IsAMatcher(context.RequestContext), snapshot['id'])
        access_get.assert_called_once_with(
            utils.IsAMatcher(context.RequestContext),
            body['deny_access']['access_id'])
        deny_access.assert_called_once_with(
            utils.IsAMatcher(context.RequestContext), snapshot, access)
Esempio n. 11
0
    def test_deny_access_access_rule_not_found(self):
        share = db_utils.create_share(mount_snapshot_support=True)
        snapshot = db_utils.create_snapshot(
            status=constants.STATUS_AVAILABLE, share_id=share['id'])
        access = db_utils.create_snapshot_access(
            share_snapshot_id=snapshot['id'])
        wrong_access = {
            'access_type': 'fake_type',
            'access_to': 'fake_IP',
            'share_snapshot_id': 'fake_id'
        }

        get = self.mock_object(share_api.API, 'get',
                               mock.Mock(return_value=share))
        get_snapshot = self.mock_object(share_api.API, 'get_snapshot',
                                        mock.Mock(return_value=snapshot))
        access_get = self.mock_object(share_api.API, 'snapshot_access_get',
                                      mock.Mock(return_value=wrong_access))

        body = {'deny_access': {'access_id': access.id}}
        req = fakes.HTTPRequest.blank('/snapshots/%s/action' % snapshot['id'],
                                      version='2.32')

        self.assertRaises(webob.exc.HTTPBadRequest,
                          self.controller.deny_access, req, snapshot['id'],
                          body)
        get.assert_called_once_with(utils.IsAMatcher(context.RequestContext),
                                    share['id'])
        get_snapshot.assert_called_once_with(
            utils.IsAMatcher(context.RequestContext), snapshot['id'])
        access_get.assert_called_once_with(
            utils.IsAMatcher(context.RequestContext),
            body['deny_access']['access_id'])
Esempio n. 12
0
    def test_allow_access_exists_exception(self):
        share = db_utils.create_share(mount_snapshot_support=True)
        snapshot = db_utils.create_snapshot(
            status=constants.STATUS_AVAILABLE, share_id=share['id'])
        req = fakes.HTTPRequest.blank('/snapshots/%s/action' % snapshot['id'],
                                      version='2.32')
        access = {
            'id': 'fake_id',
            'access_type': 'ip',
            'access_to': '1.1.1.1',
            'state': 'new',
        }
        msg = "Share snapshot access exists."

        get = self.mock_object(share_api.API, 'get', mock.Mock(
            return_value=share))
        get_snapshot = self.mock_object(share_api.API, 'get_snapshot',
                                        mock.Mock(return_value=snapshot))
        allow_access = self.mock_object(
            share_api.API, 'snapshot_allow_access', mock.Mock(
                side_effect=exception.ShareSnapshotAccessExists(msg)))

        body = {'allow_access': access}

        self.assertRaises(webob.exc.HTTPBadRequest,
                          self.controller.allow_access, req,
                          snapshot['id'], body)

        get.assert_called_once_with(utils.IsAMatcher(context.RequestContext),
                                    share['id'])
        get_snapshot.assert_called_once_with(
            utils.IsAMatcher(context.RequestContext), snapshot['id'])
        allow_access.assert_called_once_with(
            utils.IsAMatcher(context.RequestContext), snapshot,
            access['access_type'], access['access_to'])
Esempio n. 13
0
 def _setup_snapshot_data(self, snapshot=None, version='2.7'):
     if snapshot is None:
         share = db_utils.create_share()
         snapshot = db_utils.create_snapshot(
             status=constants.STATUS_AVAILABLE, share_id=share['id'])
     req = fakes.HTTPRequest.blank('/v2/fake/snapshots/%s/action' %
                                   snapshot['id'], version=version)
     return snapshot, req
Esempio n. 14
0
 def _setup_snapshot_data(self, snapshot=None, version='2.7'):
     if snapshot is None:
         share = db_utils.create_share()
         snapshot = db_utils.create_snapshot(
             status=constants.STATUS_AVAILABLE, share_id=share['id'])
     path = '/v2/fake/snapshots/%s/action' % snapshot['id']
     req = fakes.HTTPRequest.blank(path, script_name=path, version=version)
     return snapshot, req
Esempio n. 15
0
 def _setup_snapshot_data(self, snapshot=None):
     if snapshot is None:
         share = db_utils.create_share()
         snapshot = db_utils.create_snapshot(
             status=constants.STATUS_AVAILABLE, share_id=share['id'])
     req = fakes.HTTPRequest.blank('/v1/fake/snapshots/%s/action' %
                                   snapshot['id'])
     return snapshot, req
Esempio n. 16
0
    def test_instance_and_proxified_properties(self):

        in_sync_replica_instance = db_utils.create_share_instance(
            status=constants.STATUS_AVAILABLE,
            share_id='fake_id',
            replica_state=constants.REPLICA_STATE_IN_SYNC)
        active_replica_instance = db_utils.create_share_instance(
            status=constants.STATUS_AVAILABLE,
            share_id='fake_id',
            replica_state=constants.REPLICA_STATE_ACTIVE)
        out_of_sync_replica_instance = db_utils.create_share_instance(
            status=constants.STATUS_ERROR,
            share_id='fake_id',
            replica_state=constants.REPLICA_STATE_OUT_OF_SYNC)
        non_replica_instance = db_utils.create_share_instance(
            status=constants.STATUS_CREATING, share_id='fake_id')
        share_instances = [
            in_sync_replica_instance,
            active_replica_instance,
            out_of_sync_replica_instance,
            non_replica_instance,
        ]
        share = db_utils.create_share(instances=share_instances)
        snapshot_instance_list = [
            db_utils.create_snapshot_instance(
                'fake_snapshot_id',
                status=constants.STATUS_CREATING,
                share_instance_id=out_of_sync_replica_instance['id']),
            db_utils.create_snapshot_instance(
                'fake_snapshot_id',
                status=constants.STATUS_ERROR,
                share_instance_id=in_sync_replica_instance['id']),
            db_utils.create_snapshot_instance(
                'fake_snapshot_id',
                status=constants.STATUS_AVAILABLE,
                provider_location='hogsmeade:snapshot1',
                progress='87%',
                share_instance_id=active_replica_instance['id']),
            db_utils.create_snapshot_instance(
                'fake_snapshot_id',
                status=constants.STATUS_MANAGING,
                share_instance_id=non_replica_instance['id']),
        ]
        snapshot = db_utils.create_snapshot(id='fake_snapshot_id',
                                            share_id=share['id'],
                                            instances=snapshot_instance_list)

        # Proxified properties
        self.assertEqual(constants.STATUS_AVAILABLE, snapshot['status'])
        self.assertEqual(constants.STATUS_ERROR, snapshot['aggregate_status'])
        self.assertEqual('hogsmeade:snapshot1', snapshot['provider_location'])
        self.assertEqual('87%', snapshot['progress'])

        # Snapshot properties
        expected_share_name = '-'.join(['share', share['id']])
        self.assertEqual(expected_share_name, snapshot['share_name'])
        self.assertEqual(active_replica_instance['id'],
                         snapshot['instance']['share_instance_id'])
Esempio n. 17
0
    def test_deny_access_data_not_found_exception(self):
        share = db_utils.create_share(mount_snapshot_support=True)
        snapshot = db_utils.create_snapshot(
            status=constants.STATUS_AVAILABLE, share_id=share['id'])
        req = fakes.HTTPRequest.blank('/snapshots/%s/action' % snapshot['id'],
                                      version='2.32')
        body = {}

        self.assertRaises(webob.exc.HTTPBadRequest,
                          self.controller.deny_access, req,
                          snapshot['id'], body)
Esempio n. 18
0
    def test_deny_access_data_not_found_exception(self):
        share = db_utils.create_share(mount_snapshot_support=True)
        snapshot = db_utils.create_snapshot(
            status=constants.STATUS_AVAILABLE, share_id=share['id'])
        req = fakes.HTTPRequest.blank('/snapshots/%s/action' % snapshot['id'],
                                      version='2.32')
        body = {}

        self.assertRaises(webob.exc.HTTPBadRequest,
                          self.controller.deny_access, req,
                          snapshot['id'], body)
Esempio n. 19
0
 def setUp(self):
     super(SnapshotAccessTestCase, self).setUp()
     self.driver = self.mock_class("manila.share.driver.ShareDriver",
                                   mock.Mock())
     self.snapshot_access = snapshot_access.ShareSnapshotInstanceAccess(
         db, self.driver)
     self.context = context.get_admin_context()
     share = db_utils.create_share()
     self.snapshot = db_utils.create_snapshot(share_id=share['id'])
     self.snapshot_instance = db_utils.create_snapshot_instance(
         snapshot_id=self.snapshot['id'],
         share_instance_id=self.snapshot['share']['instance']['id'])
Esempio n. 20
0
    def test_instance_and_proxified_properties(self):

        in_sync_replica_instance = db_utils.create_share_instance(
            status=constants.STATUS_AVAILABLE, share_id='fake_id',
            replica_state=constants.REPLICA_STATE_IN_SYNC)
        active_replica_instance = db_utils.create_share_instance(
            status=constants.STATUS_AVAILABLE, share_id='fake_id',
            replica_state=constants.REPLICA_STATE_ACTIVE)
        out_of_sync_replica_instance = db_utils.create_share_instance(
            status=constants.STATUS_ERROR, share_id='fake_id',
            replica_state=constants.REPLICA_STATE_OUT_OF_SYNC)
        non_replica_instance = db_utils.create_share_instance(
            status=constants.STATUS_CREATING, share_id='fake_id')
        share_instances = [
            in_sync_replica_instance, active_replica_instance,
            out_of_sync_replica_instance, non_replica_instance,
        ]
        share = db_utils.create_share(instances=share_instances)
        snapshot_instance_list = [
            db_utils.create_snapshot_instance(
                'fake_snapshot_id',
                status=constants.STATUS_CREATING,
                share_instance_id=out_of_sync_replica_instance['id']),
            db_utils.create_snapshot_instance(
                'fake_snapshot_id',
                status=constants.STATUS_ERROR,
                share_instance_id=in_sync_replica_instance['id']),
            db_utils.create_snapshot_instance(
                'fake_snapshot_id',
                status=constants.STATUS_AVAILABLE,
                provider_location='hogsmeade:snapshot1',
                progress='87%',
                share_instance_id=active_replica_instance['id']),
            db_utils.create_snapshot_instance(
                'fake_snapshot_id',
                status=constants.STATUS_MANAGING,
                share_instance_id=non_replica_instance['id']),
        ]
        snapshot = db_utils.create_snapshot(
            id='fake_snapshot_id', share_id=share['id'],
            instances=snapshot_instance_list)

        # Proxified properties
        self.assertEqual(constants.STATUS_AVAILABLE, snapshot['status'])
        self.assertEqual(constants.STATUS_ERROR, snapshot['aggregate_status'])
        self.assertEqual('hogsmeade:snapshot1', snapshot['provider_location'])
        self.assertEqual('87%', snapshot['progress'])

        # Snapshot properties
        expected_share_name = '-'.join(['share', share['id']])
        self.assertEqual(expected_share_name, snapshot['share_name'])
        self.assertEqual(active_replica_instance['id'],
                         snapshot['instance']['share_instance_id'])
Esempio n. 21
0
 def setUp(self):
     super(SnapshotAccessTestCase, self).setUp()
     self.driver = self.mock_class("manila.share.driver.ShareDriver",
                                   mock.Mock())
     self.snapshot_access = snapshot_access.ShareSnapshotInstanceAccess(
         db, self.driver)
     self.context = context.get_admin_context()
     share = db_utils.create_share()
     self.snapshot = db_utils.create_snapshot(share_id=share['id'])
     self.snapshot_instance = db_utils.create_snapshot_instance(
         snapshot_id=self.snapshot['id'],
         share_instance_id=self.snapshot['share']['instance']['id'])
Esempio n. 22
0
    def test_same_backend_different_pool(self):
        share = db_utils.create_share(host="host1@AAA#pool1",
                                      status=constants.STATUS_AVAILABLE)
        snapshot = db_utils.create_snapshot(share_id=share['id'])
        self.mock_object(db_api, 'share_snapshot_get',
                         mock.Mock(return_value=snapshot))

        host_state = fakes.FakeHostState('host1@AAA#pool2', {})
        weight_properties = self._create_weight_properties(
            snapshot_id=snapshot['id'], snapshot_host=share['host'])

        weight = self.weigher._weigh_object(host_state, weight_properties)
        self.assertEqual(75, weight)
Esempio n. 23
0
    def test_allow_access_empty_parameters(self):
        share = db_utils.create_share(mount_snapshot_support=True)
        snapshot = db_utils.create_snapshot(status=constants.STATUS_AVAILABLE,
                                            share_id=share['id'])

        access = {'id': 'fake_id', 'access_type': '', 'access_to': ''}

        body = {'allow_access': access}
        req = fakes.HTTPRequest.blank('/snapshots/%s/action' % snapshot['id'],
                                      version='2.32')

        self.assertRaises(webob.exc.HTTPBadRequest,
                          self.controller.allow_access, req, snapshot['id'],
                          body)
Esempio n. 24
0
    def test_allow_access_empty_parameters(self):
        share = db_utils.create_share(mount_snapshot_support=True)
        snapshot = db_utils.create_snapshot(
            status=constants.STATUS_AVAILABLE, share_id=share['id'])

        access = {'id': 'fake_id',
                  'access_type': '',
                  'access_to': ''}

        body = {'allow_access': access}
        req = fakes.HTTPRequest.blank('/snapshots/%s/action' % snapshot['id'],
                                      version='2.32')

        self.assertRaises(webob.exc.HTTPBadRequest,
                          self.controller.allow_access, req,
                          snapshot['id'], body)
Esempio n. 25
0
 def test_snapshot_reset_status(self):
     # snapshot in 'error_deleting'
     share = db_utils.create_share()
     snapshot = db_utils.create_snapshot(status=constants.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 = six.b(jsonutils.dumps({"os-reset_status": {"status": constants.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"], constants.STATUS_ERROR)
Esempio n. 26
0
 def test_invalid_status_for_snapshot(self):
     # snapshot in 'available'
     share = db_utils.create_share()
     snapshot = db_utils.create_snapshot(status=constants.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 = six.b(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"], constants.STATUS_AVAILABLE)
Esempio n. 27
0
    def setUp(self):
        super(ShareRpcAPITestCase, self).setUp()
        self.context = context.get_admin_context()

        share = db_utils.create_share(
            availability_zone=CONF.storage_availability_zone,
            status=constants.STATUS_AVAILABLE
        )
        access = db_utils.create_access(share_id=share['id'])
        snapshot = db_utils.create_snapshot(share_id=share['id'])
        share_server = db_utils.create_share_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()
Esempio n. 28
0
    def test_access_list(self):
        share = db_utils.create_share(mount_snapshot_support=True)
        snapshot = db_utils.create_snapshot(status=constants.STATUS_AVAILABLE,
                                            share_id=share['id'])

        expected = []

        self.mock_object(share_api.API, 'get', mock.Mock(return_value=share))
        self.mock_object(share_api.API, 'get_snapshot',
                         mock.Mock(return_value=snapshot))
        self.mock_object(share_api.API, 'snapshot_access_get_all',
                         mock.Mock(return_value=expected))

        id = 'fake_snap_id'
        req = fakes.HTTPRequest.blank('/snapshots/%s/action' % id,
                                      version='2.32')

        actual = self.controller.access_list(req, id)

        self.assertEqual(expected, actual['snapshot_access_list'])
Esempio n. 29
0
    def test_access_list(self):
        share = db_utils.create_share(mount_snapshot_support=True)
        snapshot = db_utils.create_snapshot(
            status=constants.STATUS_AVAILABLE, share_id=share['id'])

        expected = []

        self.mock_object(share_api.API, 'get',
                         mock.Mock(return_value=share))
        self.mock_object(share_api.API, 'get_snapshot',
                         mock.Mock(return_value=snapshot))
        self.mock_object(share_api.API, 'snapshot_access_get_all',
                         mock.Mock(return_value=expected))

        id = 'fake_snap_id'
        req = fakes.HTTPRequest.blank('/snapshots/%s/action' % id,
                                      version='2.32')

        actual = self.controller.access_list(req, id)

        self.assertEqual(expected, actual['snapshot_access_list'])
Esempio n. 30
0
    def test_different_backend_same_availability_zone(self):
        share = db_utils.create_share(
            host="host1@AAA#pool1", status=constants.STATUS_AVAILABLE,
            availability_zone=fakes.FAKE_AZ_1['name'])
        snapshot = db_utils.create_snapshot(share_id=share['id'])

        self.mock_object(db_api, 'share_snapshot_get',
                         mock.Mock(return_value=snapshot))
        self.mock_object(db_api, 'availability_zone_get',
                         mock.Mock(return_value=type(
                             'FakeAZ', (object, ), {
                                 'id': fakes.FAKE_AZ_1['id'],
                                 'name': fakes.FAKE_AZ_1['name'],
                             })))
        host_state = fakes.FakeHostState('host2@BBB#pool1', {})
        weight_properties = self._create_weight_properties(
            snapshot_id=snapshot['id'], snapshot_host=share['host'],
            availability_zone_id='zone1')

        weight = self.weigher._weigh_object(host_state, weight_properties)
        self.assertEqual(50, weight)
    def setUp(self):
        super(ShareSnapshotInstanceExportLocationsAPITest, self).setUp()
        self.controller = (
            exp_loc.ShareSnapshotInstanceExportLocationController())

        self.share = db_utils.create_share()
        self.snapshot = db_utils.create_snapshot(
            status=constants.STATUS_AVAILABLE, share_id=self.share['id'])
        self.snapshot_instance = db_utils.create_snapshot_instance(
            'fake_snapshot_id_1',
            status=constants.STATUS_CREATING,
            share_instance_id=self.share['instance']['id'])

        self.values = {
            'share_snapshot_instance_id': self.snapshot_instance['id'],
            'path': 'fake/user_path',
            'is_admin_only': True,
        }
        self.el = db_api.share_snapshot_instance_export_location_create(
            context.get_admin_context(), self.values)
        self.req = self._get_request()
Esempio n. 32
0
 def setUp(self):
     super(ShareRpcAPITestCase, self).setUp()
     self.context = context.get_admin_context()
     share = db_utils.create_share(
         availability_zone=CONF.storage_availability_zone, status=constants.STATUS_AVAILABLE
     )
     access = db_utils.create_access(share_id=share["id"])
     snapshot = db_utils.create_snapshot(share_id=share["id"])
     share_server = db_utils.create_share_server()
     cg = {"id": "fake_cg_id", "host": "fake_host"}
     cgsnapshot = {"id": "fake_cg_id"}
     host = {"host": "fake_host", "capabilities": 1}
     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.fake_cg = jsonutils.to_primitive(cg)
     self.fake_cgsnapshot = jsonutils.to_primitive(cgsnapshot)
     self.fake_host = jsonutils.to_primitive(host)
     self.ctxt = context.RequestContext("fake_user", "fake_project")
     self.rpcapi = share_rpcapi.ShareAPI()
    def setUp(self):
        super(ShareSnapshotInstanceExportLocationsAPITest, self).setUp()
        self.controller = (
            exp_loc.ShareSnapshotInstanceExportLocationController())

        self.share = db_utils.create_share()
        self.snapshot = db_utils.create_snapshot(
            status=constants.STATUS_AVAILABLE,
            share_id=self.share['id'])
        self.snapshot_instance = db_utils.create_snapshot_instance(
            'fake_snapshot_id_1',
            status=constants.STATUS_CREATING,
            share_instance_id=self.share['instance']['id'])

        self.values = {
            'share_snapshot_instance_id': self.snapshot_instance['id'],
            'path': 'fake/user_path',
            'is_admin_only': True,
        }
        self.el = db_api.share_snapshot_instance_export_location_create(
            context.get_admin_context(), self.values)
        self.req = self._get_request()