Add sharing_strategy in Share API

We add shareing_strategy option in Share API because sharing_strategy must be ALL_DESCENDANTS for sharedWith path [/orgs/default].

Change-Id: Ib982237f12d10c2b9f1163393697817397916207
Signed-off-by: Yun-Tang Hsu <hsuy@vmware.com>
This commit is contained in:
Yun-Tang Hsu 2024-07-02 14:48:39 -07:00
parent a797301b8e
commit c5d39d4e8b
4 changed files with 33 additions and 18 deletions

View File

@ -7508,9 +7508,11 @@ class TestPolicyShare(NsxPolicyLibTestCase):
share_id,
description=description,
tenant=TEST_TENANT)
expected_def = core_defs.ShareDef(share_id=share_id,
description=description,
tenant=TEST_TENANT)
expected_def = core_defs.ShareDef(
share_id=share_id,
description=description,
tenant=TEST_TENANT,
sharing_strategy=constants.DEFAULT_SHARING_STRATEGY)
self.assert_called_with_def(api_call, expected_def)
self.assertEqual(share_id, result)
@ -7525,10 +7527,12 @@ class TestPolicyShare(NsxPolicyLibTestCase):
shared_with=shared_with,
description=description,
tenant=TEST_TENANT)
expected_def = core_defs.ShareDef(share_id=share_id,
shared_with=shared_with,
description=description,
tenant=TEST_TENANT)
expected_def = core_defs.ShareDef(
share_id=share_id,
shared_with=shared_with,
description=description,
sharing_strategy=constants.DEFAULT_SHARING_STRATEGY,
tenant=TEST_TENANT)
self.assert_called_with_def(api_call, expected_def)
self.assertIsNotNone(result)
@ -7567,9 +7571,11 @@ class TestPolicyShare(NsxPolicyLibTestCase):
self.resourceApi.update(share_id,
description=description,
tenant=TEST_TENANT)
expected_def = core_defs.ShareDef(share_id=share_id,
description=description,
tenant=TEST_TENANT)
expected_def = core_defs.ShareDef(
share_id=share_id,
description=description,
sharing_strategy=constants.DEFAULT_SHARING_STRATEGY,
tenant=TEST_TENANT)
self.assert_called_with_def(update_call, expected_def)

View File

@ -112,3 +112,5 @@ ADV_RULE_TIER1_IPSEC_LOCAL_ENDPOINT = 'TIER1_IPSEC_LOCAL_ENDPOINT'
IPSEC_VPN_RULE_PROTECT = 'PROTECT'
IPSEC_VPN_RULE_BYPASS = 'BYPASS'
DEFAULT_SHARING_STRATEGY = 'ALL_DESCENDANTS'

View File

@ -383,7 +383,9 @@ class ShareDef(ResourceDef):
body,
'shared_with',
body_attr='sharedWith')
self._set_attrs_if_specified(body, ['description', 'tags'])
self._set_attrs_if_specified(
body,
['description', 'tags', 'sharing_strategy'])
return body

View File

@ -5309,20 +5309,23 @@ class NsxPolicyShareApi(NsxPolicyResourceBase):
def entry_def(self):
return core_defs.ShareDef
def create_or_overwrite(self, share_id,
shared_with=IGNORE,
name=IGNORE,
description=IGNORE,
tags=IGNORE,
tenant=constants.POLICY_INFRA_TENANT):
def create_or_overwrite(
self,
share_id,
shared_with=IGNORE,
name=IGNORE,
description=IGNORE,
tags=IGNORE,
sharing_strategy=constants.DEFAULT_SHARING_STRATEGY,
tenant=constants.POLICY_INFRA_TENANT):
share_id = self._init_obj_uuid(share_id)
share_def = self._init_def(share_id=share_id,
shared_with=shared_with,
sharing_strategy=sharing_strategy,
name=name,
description=description,
tags=tags,
tenant=tenant)
self._create_or_store(share_def)
return share_id
@ -5344,9 +5347,11 @@ class NsxPolicyShareApi(NsxPolicyResourceBase):
name=IGNORE,
description=IGNORE,
tags=IGNORE,
sharing_strategy=constants.DEFAULT_SHARING_STRATEGY,
tenant=constants.POLICY_INFRA_TENANT):
self._update(share_id=share_id,
shared_with=shared_with,
sharing_strategy=sharing_strategy,
name=name,
description=description,
tags=tags,