Exemple #1
0
    def test_get_admin_export_location(self):
        el_data = {
            'path': '/admin/export/location',
            'is_admin_only': True,
            'metadata': {
                'foo': 'bar'
            },
        }
        db.share_export_locations_update(self.ctxt['admin'],
                                         self.share_instance_id, el_data, True)
        index_result = self.controller.index(self.req, self.share['id'])
        el_id = index_result['export_locations'][0]['id']

        # Not found for member
        member_req = self._get_request(use_admin_context=False)
        self.assertRaises(
            exc.HTTPForbidden,
            self.controller.show,
            member_req,
            self.share['id'],
            el_id,
        )

        # Ok for admin
        el = self.controller.show(self.req, self.share['id'], el_id)
        for k, v in el.items():
            self.assertEqual(v, el[k])
    def test_index(self, version):
        url = '/share_instances'
        if (api_version_request.APIVersionRequest(version) >=
                api_version_request.APIVersionRequest('2.35')):
            url += "?export_location_path=/admin/export/location"
        req = self._get_request(url, version=version)
        req_context = req.environ['manila.context']
        share_instances_count = 3
        test_instances = [
            db_utils.create_share(size=s + 1).instance
            for s in range(0, share_instances_count)
        ]

        db.share_export_locations_update(
            self.admin_context, test_instances[0]['id'],
            '/admin/export/location', False)

        actual_result = self.controller.index(req)

        if (api_version_request.APIVersionRequest(version) >=
                api_version_request.APIVersionRequest('2.35')):
            test_instances = test_instances[:1]
        self._validate_ids_in_share_instances_list(
            test_instances, actual_result['share_instances'])
        self.mock_policy_check.assert_called_once_with(
            req_context, self.resource_name, 'index')
    def test_index(self, version):
        url = '/share_instances'
        if (api_version_request.APIVersionRequest(version) >=
                api_version_request.APIVersionRequest('2.35')):
            url += "?export_location_path=/admin/export/location"
        req = self._get_request(url, version=version)
        req_context = req.environ['manila.context']
        share_instances_count = 3
        test_instances = [
            db_utils.create_share(size=s + 1).instance
            for s in range(0, share_instances_count)
        ]

        db.share_export_locations_update(self.admin_context,
                                         test_instances[0]['id'],
                                         '/admin/export/location', False)

        actual_result = self.controller.index(req)

        if (api_version_request.APIVersionRequest(version) >=
                api_version_request.APIVersionRequest('2.35')):
            test_instances = test_instances[:1]
        self._validate_ids_in_share_instances_list(
            test_instances, actual_result['share_instances'])
        self.mock_policy_check.assert_called_once_with(req_context,
                                                       self.resource_name,
                                                       'index')
 def setUp(self):
     super(self.__class__, self).setUp()
     self.controller = export_locations.ShareInstanceExportLocationController()
     self.resource_name = self.controller.resource_name
     self.ctxt = {
         "admin": context.RequestContext("admin", "fake", True),
         "user": context.RequestContext("fake", "fake"),
     }
     self.mock_policy_check = self.mock_object(policy, "check_policy", mock.Mock(return_value=True))
     self.share = db_utils.create_share()
     self.share_instance_id = self.share.instance.id
     self.req = self._get_request()
     paths = ["fake1/1/", "fake2/2", "fake3/3"]
     db.share_export_locations_update(self.ctxt["admin"], self.share_instance_id, paths, False)
Exemple #5
0
 def setUp(self):
     super(self.__class__, self).setUp()
     self.controller = (export_locations.ShareExportLocationController())
     self.resource_name = self.controller.resource_name
     self.ctxt = {
         'admin': context.RequestContext('admin', 'fake', True),
         'user': context.RequestContext('fake', 'fake'),
     }
     self.mock_policy_check = self.mock_object(policy, 'check_policy',
                                               mock.Mock(return_value=True))
     self.share = db_utils.create_share()
     self.share_instance_id = self.share.instance.id
     self.req = self._get_request()
     paths = ['fake1/1/', 'fake2/2', 'fake3/3']
     db.share_export_locations_update(self.ctxt['admin'],
                                      self.share_instance_id, paths, False)
 def setUp(self):
     super(self.__class__, self).setUp()
     self.controller = (
         export_locations.ShareExportLocationController())
     self.resource_name = self.controller.resource_name
     self.ctxt = {
         'admin': context.RequestContext('admin', 'fake', True),
         'user': context.RequestContext('fake', 'fake'),
     }
     self.mock_policy_check = self.mock_object(
         policy, 'check_policy', mock.Mock(return_value=True))
     self.share = db_utils.create_share()
     self.share_instance_id = self.share.instance.id
     self.req = self._get_request()
     paths = ['fake1/1/', 'fake2/2', 'fake3/3']
     db.share_export_locations_update(
         self.ctxt['admin'], self.share_instance_id, paths, False)
    def test_list_and_show_with_non_replicas(self):
        non_replicated_share = db_utils.create_share()
        instance_id = non_replicated_share.instance.id
        exports = [
            {'path': 'myshare.mydomain/non-replicated-share',
             'is_admin_only': False},
            {'path': 'myshare.mydomain/non-replicated-share-2',
             'is_admin_only': False},
        ]
        db.share_export_locations_update(self.ctxt, instance_id, exports)
        updated_exports = db.share_export_locations_get_by_share_id(
            self.ctxt, non_replicated_share.id)

        self.assertRaises(exc.HTTPNotFound, self.controller.index, self.req,
                          instance_id)

        for export in updated_exports:
            self.assertRaises(exc.HTTPNotFound, self.controller.show, self.req,
                              instance_id, export['id'])
Exemple #8
0
    def test_list_export_locations_replicated_share(self, version):
        """Test the export locations API changes between 2.46 and 2.47

        For API version <= 2.46, non-active replica export locations are
        included in the API response. They are not included in and beyond
        version 2.47.
        """
        # Setup data
        share = db_utils.create_share(
            replication_type=constants.REPLICATION_TYPE_READABLE,
            replica_state=constants.REPLICA_STATE_ACTIVE)
        active_replica_id = share.instance.id
        exports = [
            {
                'path': 'myshare.mydomain/active-replica-exp1',
                'is_admin_only': False
            },
            {
                'path': 'myshare.mydomain/active-replica-exp2',
                'is_admin_only': False
            },
        ]
        db.share_export_locations_update(self.ctxt['user'], active_replica_id,
                                         exports)

        # Replicas
        share_replica2 = db_utils.create_share_replica(
            share_id=share.id, replica_state=constants.REPLICA_STATE_IN_SYNC)
        share_replica3 = db_utils.create_share_replica(
            share_id=share.id,
            replica_state=constants.REPLICA_STATE_OUT_OF_SYNC)
        replica2_exports = [{
            'path': 'myshare.mydomain/insync-replica-exp',
            'is_admin_only': False
        }]
        replica3_exports = [{
            'path': 'myshare.mydomain/outofsync-replica-exp',
            'is_admin_only': False
        }]
        db.share_export_locations_update(self.ctxt['user'], share_replica2.id,
                                         replica2_exports)
        db.share_export_locations_update(self.ctxt['user'], share_replica3.id,
                                         replica3_exports)

        req = self._get_request(version=version)
        index_result = self.controller.index(req, share['id'])

        actual_paths = [el['path'] for el in index_result['export_locations']]
        if self.is_microversion_ge(version, '2.47'):
            self.assertEqual(2, len(index_result['export_locations']))
            self.assertNotIn('myshare.mydomain/insync-replica-exp',
                             actual_paths)
            self.assertNotIn('myshare.mydomain/outofsync-replica-exp',
                             actual_paths)
        else:
            self.assertEqual(4, len(index_result['export_locations']))
            self.assertIn('myshare.mydomain/insync-replica-exp', actual_paths)
            self.assertIn('myshare.mydomain/outofsync-replica-exp',
                          actual_paths)
Exemple #9
0
    def test_list_and_show_with_non_replicas(self):
        non_replicated_share = db_utils.create_share()
        instance_id = non_replicated_share.instance.id
        exports = [
            {
                'path': 'myshare.mydomain/non-replicated-share',
                'is_admin_only': False
            },
            {
                'path': 'myshare.mydomain/non-replicated-share-2',
                'is_admin_only': False
            },
        ]
        db.share_export_locations_update(self.ctxt, instance_id, exports)
        updated_exports = db.share_export_locations_get_by_share_id(
            self.ctxt, non_replicated_share.id)

        self.assertRaises(exc.HTTPNotFound, self.controller.index, self.req,
                          instance_id)

        for export in updated_exports:
            self.assertRaises(exc.HTTPNotFound, self.controller.show, self.req,
                              instance_id, export['id'])
    def test_get_admin_export_location(self):
        el_data = {
            'path': '/admin/export/location',
            'is_admin_only': True,
            'metadata': {'foo': 'bar'},
        }
        db.share_export_locations_update(
            self.ctxt['admin'], self.share_instance_id, el_data, True)
        index_result = self.controller.index(self.req, self.share['id'])
        el_uuid = index_result['export_locations'][0]['uuid']

        # Not found for member
        member_req = self._get_request(use_admin_context=False)
        self.assertRaises(
            exc.HTTPForbidden,
            self.controller.show,
            member_req, self.share['id'], el_uuid,
        )

        # Ok for admin
        el = self.controller.show(self.req, self.share['id'], el_uuid)
        for k, v in el.items():
            self.assertEqual(v, el[k])
    def test_list_export_locations_replicated_share(self, version):
        """Test the export locations API changes between 2.46 and 2.47

        For API version <= 2.46, non-active replica export locations are
        included in the API response. They are not included in and beyond
        version 2.47.
        """
        # Setup data
        share = db_utils.create_share(
            replication_type=constants.REPLICATION_TYPE_READABLE,
            replica_state=constants.REPLICA_STATE_ACTIVE)
        active_replica_id = share.instance.id
        exports = [
            {'path': 'myshare.mydomain/active-replica-exp1',
             'is_admin_only': False},
            {'path': 'myshare.mydomain/active-replica-exp2',
             'is_admin_only': False},
        ]
        db.share_export_locations_update(
            self.ctxt['user'], active_replica_id, exports)

        # Replicas
        share_replica2 = db_utils.create_share_replica(
            share_id=share.id, replica_state=constants.REPLICA_STATE_IN_SYNC)
        share_replica3 = db_utils.create_share_replica(
            share_id=share.id,
            replica_state=constants.REPLICA_STATE_OUT_OF_SYNC)
        replica2_exports = [
            {'path': 'myshare.mydomain/insync-replica-exp',
             'is_admin_only': False}
        ]
        replica3_exports = [
            {'path': 'myshare.mydomain/outofsync-replica-exp',
             'is_admin_only': False}
        ]
        db.share_export_locations_update(
            self.ctxt['user'], share_replica2.id, replica2_exports)
        db.share_export_locations_update(
            self.ctxt['user'], share_replica3.id, replica3_exports)

        req = self._get_request(version=version)
        index_result = self.controller.index(req, share['id'])

        actual_paths = [el['path'] for el in index_result['export_locations']]
        if self.is_microversion_ge(version, '2.47'):
            self.assertEqual(2, len(index_result['export_locations']))
            self.assertNotIn(
                'myshare.mydomain/insync-replica-exp', actual_paths)
            self.assertNotIn(
                'myshare.mydomain/outofsync-replica-exp', actual_paths)
        else:
            self.assertEqual(4, len(index_result['export_locations']))
            self.assertIn('myshare.mydomain/insync-replica-exp', actual_paths)
            self.assertIn(
                'myshare.mydomain/outofsync-replica-exp', actual_paths)
Exemple #12
0
    def setUp(self):
        super(ShareReplicaExportLocationsAPITest, self).setUp()
        self.controller = (
            export_locations.ShareReplicaExportLocationController())
        self.resource_name = 'share_replica_export_location'
        self.ctxt = context.RequestContext('fake', 'fake')
        self.mock_policy_check = self.mock_object(policy, 'check_policy',
                                                  mock.Mock(return_value=True))
        self.share = db_utils.create_share(
            replication_type=constants.REPLICATION_TYPE_READABLE,
            replica_state=constants.REPLICA_STATE_ACTIVE)
        self.active_replica_id = self.share.instance.id
        self.req = self._get_request()
        exports = [
            {
                'path': 'myshare.mydomain/active-replica-exp1',
                'is_admin_only': False
            },
            {
                'path': 'myshare.mydomain/active-replica-exp2',
                'is_admin_only': False
            },
        ]
        db.share_export_locations_update(self.ctxt, self.active_replica_id,
                                         exports)

        # Replicas
        self.share_replica2 = db_utils.create_share_replica(
            share_id=self.share.id,
            replica_state=constants.REPLICA_STATE_IN_SYNC)
        self.share_replica3 = db_utils.create_share_replica(
            share_id=self.share.id,
            replica_state=constants.REPLICA_STATE_OUT_OF_SYNC)
        replica2_exports = [{
            'path': 'myshare.mydomain/insync-replica-exp',
            'is_admin_only': False
        }, {
            'path': 'myshare.mydomain/insync-replica-exp2',
            'is_admin_only': False
        }]
        replica3_exports = [{
            'path': 'myshare.mydomain/outofsync-replica-exp',
            'is_admin_only': False
        }, {
            'path': 'myshare.mydomain/outofsync-replica-exp2',
            'is_admin_only': False
        }]
        db.share_export_locations_update(self.ctxt, self.share_replica2.id,
                                         replica2_exports)
        db.share_export_locations_update(self.ctxt, self.share_replica3.id,
                                         replica3_exports)
    def setUp(self):
        super(ShareReplicaExportLocationsAPITest, self).setUp()
        self.controller = (
            export_locations.ShareReplicaExportLocationController())
        self.resource_name = 'share_replica_export_location'
        self.ctxt = context.RequestContext('fake', 'fake')
        self.mock_policy_check = self.mock_object(
            policy, 'check_policy', mock.Mock(return_value=True))
        self.share = db_utils.create_share(
            replication_type=constants.REPLICATION_TYPE_READABLE,
            replica_state=constants.REPLICA_STATE_ACTIVE)
        self.active_replica_id = self.share.instance.id
        self.req = self._get_request()
        exports = [
            {'path': 'myshare.mydomain/active-replica-exp1',
             'is_admin_only': False},
            {'path': 'myshare.mydomain/active-replica-exp2',
             'is_admin_only': False},
        ]
        db.share_export_locations_update(
            self.ctxt, self.active_replica_id, exports)

        # Replicas
        self.share_replica2 = db_utils.create_share_replica(
            share_id=self.share.id,
            replica_state=constants.REPLICA_STATE_IN_SYNC)
        self.share_replica3 = db_utils.create_share_replica(
            share_id=self.share.id,
            replica_state=constants.REPLICA_STATE_OUT_OF_SYNC)
        replica2_exports = [
            {'path': 'myshare.mydomain/insync-replica-exp',
             'is_admin_only': False},
            {'path': 'myshare.mydomain/insync-replica-exp2',
             'is_admin_only': False}
        ]
        replica3_exports = [
            {'path': 'myshare.mydomain/outofsync-replica-exp',
             'is_admin_only': False},
            {'path': 'myshare.mydomain/outofsync-replica-exp2',
             'is_admin_only': False}
        ]
        db.share_export_locations_update(
            self.ctxt, self.share_replica2.id, replica2_exports)
        db.share_export_locations_update(
            self.ctxt, self.share_replica3.id, replica3_exports)