Fix tests for 'share-network' param in share replica create

Fix suggestions from
https://review.opendev.org/c/openstack/manila/+/804578

Closes-Bug: #1925486
Change-Id: I92d5ed80fb659526dff795cf474826bed45a1d19
This commit is contained in:
Kiran Pawar 2022-08-30 08:10:24 +00:00
parent 73848870a5
commit ba5455cbd6
4 changed files with 21 additions and 15 deletions

View File

@ -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(

View File

@ -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.")

View File

@ -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)

View File

@ -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,