diff --git a/manila/api/v2/share_replicas.py b/manila/api/v2/share_replicas.py index 638c422462..64f6c53cf1 100644 --- a/manila/api/v2/share_replicas.py +++ b/manila/api/v2/share_replicas.py @@ -191,7 +191,7 @@ class ShareReplicationController(wsgi.Controller, wsgi.AdminActionsMixin): common.check_share_network_is_active(share_network) except exception.ShareNetworkNotFound: msg = _("No share network exists with ID %s.") - raise exc.HTTPNotFound(explanation=msg % share_network_id) + raise exc.HTTPBadRequest(explanation=msg % share_network_id) try: new_replica = self.share_api.create_share_replica( diff --git a/manila/share/api.py b/manila/share/api.py index 98b8119a33..5b0a183c14 100644 --- a/manila/share/api.py +++ b/manila/share/api.py @@ -644,17 +644,18 @@ class API(base.Base): parent_share_network_id = share.get('share_network_id') if (parent_share_network_id and share_network_id and parent_share_network_id != share_network_id): - parent_share_services = ( + parent_security_services = ( self.db.security_service_get_all_by_share_network( context, parent_share_network_id)) - share_services = ( + security_services = ( self.db.security_service_get_all_by_share_network( context, share_network_id)) - for service in parent_share_services: - if service not in share_services: - msg = _("Share and its replica can't be in" - "different authentication domains.") - raise exception.InvalidInput(reason=msg) + parent_ss = set([s['id'] for s in parent_security_services]) + ss = set([s['id'] for s in security_services]) + if ss != parent_ss: + msg = _("Share and its replica can't be in " + "different authentication domains.") + raise exception.InvalidInput(reason=msg) if not share.get('replication_type'): msg = _("Replication not supported for share %s.") diff --git a/manila/tests/api/v2/test_share_replicas.py b/manila/tests/api/v2/test_share_replicas.py index 80613a5a48..c0358d5ca7 100644 --- a/manila/tests/api/v2/test_share_replicas.py +++ b/manila/tests/api/v2/test_share_replicas.py @@ -396,11 +396,10 @@ class ShareReplicasApiTest(test.TestCase): self.mock_policy_check.assert_called_once_with( self.member_context, self.resource_name, 'create') - @ddt.data('2.72') - def test_create_invalid_network_id(self, microversion): + def test_create_invalid_network_id(self): fake_replica, _ = self._get_fake_replica( replication_type='writable') - req = self._get_request(microversion, False) + req = self._get_request("2.72", False) req_context = req.environ['manila.context'] body = { @@ -419,7 +418,7 @@ class ShareReplicasApiTest(test.TestCase): mock.Mock(side_effect=exception.ShareNetworkNotFound( share_network_id='FAKE_NETID'))) - self.assertRaises(exc.HTTPNotFound, + self.assertRaises(exc.HTTPBadRequest, self.controller.create, req, body) self.assertFalse(mock__view_builder_call.called) diff --git a/manila/tests/db/sqlalchemy/test_api.py b/manila/tests/db/sqlalchemy/test_api.py index 3941f96d7c..f4d54e48b8 100644 --- a/manila/tests/db/sqlalchemy/test_api.py +++ b/manila/tests/db/sqlalchemy/test_api.py @@ -3191,19 +3191,25 @@ class SecurityServiceDatabaseAPITestCase(BaseDatabaseAPITestCase): 'wrong id') def test_get_all_by_share_network(self): + dict1 = security_service_dict + dict2 = security_service_dict.copy() + dict2['id'] = 'fake id 2' db_api.security_service_create(self.fake_context, - security_service_dict) + dict1) + db_api.security_service_create(self.fake_context, + dict2) share_nw_dict = {'id': 'fake network id', 'project_id': 'fake project', 'user_id': 'fake_user_id'} db_api.share_network_create(self.fake_context, share_nw_dict) db_api.share_network_add_security_service( self.fake_context, - share_nw_dict['id'], security_service_dict['id']) + share_nw_dict['id'], dict1['id']) result = db_api.security_service_get_all_by_share_network( self.fake_context, share_nw_dict['id']) - self._check_expected_fields(result[0], security_service_dict) + self._check_expected_fields(result[0], dict1) + self.assertEqual(1, len(result)) def test_delete(self): db_api.security_service_create(self.fake_context,