Add tempest coverage for share type access operations
Manila allows to make share type as private and set access to some projects by its ID. This functionality is not covered at all by tempest tests. Change-Id: I8ab83da87372b97b55dae5de6e649fbf44e068e3 Closes-Bug: #1440169
This commit is contained in:
parent
52750a0824
commit
516bd65a94
|
@ -120,3 +120,59 @@ class ShareTypesAdminTest(base.BaseSharesAdminTest):
|
|||
self.assertEqual(share_name, get["name"])
|
||||
self.assertEqual(share["id"], get["id"])
|
||||
self.assertEqual(shr_type_name, get["share_type"])
|
||||
|
||||
def test_private_share_type_access(self):
|
||||
name = data_utils.rand_name("tempest-manila")
|
||||
extra_specs = self.add_required_extra_specs_to_dict({"key": "value", })
|
||||
project_id = self.shares_client.tenant_id
|
||||
|
||||
# Create private share type
|
||||
resp, st_create = self.create_share_type(
|
||||
name, False, extra_specs=extra_specs)
|
||||
self.assertIn(int(resp["status"]), self.HTTP_SUCCESS)
|
||||
self.assertEqual(name, st_create['share_type']['name'])
|
||||
st_id = st_create["share_type"]["id"]
|
||||
|
||||
# It should not be listed without access
|
||||
resp, st_list = self.shares_client.list_share_types()
|
||||
self.assertIn(int(resp["status"]), self.HTTP_SUCCESS)
|
||||
sts = st_list["share_types"]
|
||||
self.assertFalse(any(st_id in st["id"] for st in sts))
|
||||
|
||||
# List projects that have access for share type - none expected
|
||||
resp, access = self.shares_client.list_access_to_share_type(st_id)
|
||||
self.assertIn(int(resp["status"]), self.HTTP_SUCCESS)
|
||||
self.assertEqual([], access)
|
||||
|
||||
# Add project access to share type
|
||||
resp, access = self.shares_client.add_access_to_share_type(
|
||||
st_id, project_id)
|
||||
self.assertIn(int(resp["status"]), self.HTTP_SUCCESS)
|
||||
|
||||
# Now it should be listed
|
||||
resp, st_list = self.shares_client.list_share_types()
|
||||
self.assertIn(int(resp["status"]), self.HTTP_SUCCESS)
|
||||
sts = st_list["share_types"]
|
||||
self.assertTrue(any(st_id in st["id"] for st in sts))
|
||||
|
||||
# List projects that have access for share type - one expected
|
||||
resp, access = self.shares_client.list_access_to_share_type(st_id)
|
||||
self.assertIn(int(resp["status"]), self.HTTP_SUCCESS)
|
||||
expected = [{'share_type_id': st_id, 'project_id': project_id}, ]
|
||||
self.assertEqual(expected, access)
|
||||
|
||||
# Remove project access from share type
|
||||
resp, access = self.shares_client.remove_access_from_share_type(
|
||||
st_id, project_id)
|
||||
self.assertIn(int(resp["status"]), self.HTTP_SUCCESS)
|
||||
|
||||
# It should not be listed without access
|
||||
resp, st_list = self.shares_client.list_share_types()
|
||||
self.assertIn(int(resp["status"]), self.HTTP_SUCCESS)
|
||||
sts = st_list["share_types"]
|
||||
self.assertFalse(any(st_id in st["id"] for st in sts))
|
||||
|
||||
# List projects that have access for share type - none expected
|
||||
resp, access = self.shares_client.list_access_to_share_type(st_id)
|
||||
self.assertIn(int(resp["status"]), self.HTTP_SUCCESS)
|
||||
self.assertEqual([], access)
|
||||
|
|
|
@ -447,11 +447,11 @@ class BaseSharesTest(test.BaseTestCase):
|
|||
return resp, ss
|
||||
|
||||
@classmethod
|
||||
def create_share_type(cls, name, client=None, cleanup_in_class=True,
|
||||
**kwargs):
|
||||
def create_share_type(cls, name, is_public=True, client=None,
|
||||
cleanup_in_class=True, **kwargs):
|
||||
if client is None:
|
||||
client = cls.shares_client
|
||||
resp, st = client.create_share_type(name, **kwargs)
|
||||
resp, st = client.create_share_type(name, is_public, **kwargs)
|
||||
resource = {
|
||||
"type": "share_type",
|
||||
"id": st["share_type"]["id"],
|
||||
|
|
|
@ -533,10 +533,11 @@ class SharesClient(service_client.ServiceClient):
|
|||
resp, body = self.get(uri)
|
||||
return resp, self._parse_resp(body)
|
||||
|
||||
def create_share_type(self, name, **kwargs):
|
||||
def create_share_type(self, name, is_public=True, **kwargs):
|
||||
post_body = {
|
||||
'name': name,
|
||||
'extra_specs': kwargs.get('extra_specs'),
|
||||
'os-share-type-access:is_public': is_public,
|
||||
}
|
||||
post_body = json.dumps({'share_type': post_body})
|
||||
resp, body = self.post('types', post_body)
|
||||
|
@ -549,6 +550,24 @@ class SharesClient(service_client.ServiceClient):
|
|||
resp, body = self.get("types/%s" % share_type_id)
|
||||
return resp, self._parse_resp(body)
|
||||
|
||||
def add_access_to_share_type(self, share_type_id, project_id):
|
||||
uri = 'types/%s/action' % share_type_id
|
||||
post_body = {'project': project_id}
|
||||
post_body = json.dumps({'addProjectAccess': post_body})
|
||||
return self.post(uri, post_body)
|
||||
|
||||
def remove_access_from_share_type(self, share_type_id, project_id):
|
||||
uri = 'types/%s/action' % share_type_id
|
||||
post_body = {'project': project_id}
|
||||
post_body = json.dumps({'removeProjectAccess': post_body})
|
||||
return self.post(uri, post_body)
|
||||
|
||||
def list_access_to_share_type(self, share_type_id):
|
||||
uri = 'types/%s/os-share-type-access' % share_type_id
|
||||
resp, body = self.get(uri)
|
||||
# [{"share_type_id": "%st_id%", "project_id": "%project_id%"}, ]
|
||||
return resp, self._parse_resp(body)
|
||||
|
||||
###############
|
||||
|
||||
def create_share_type_extra_specs(self, share_type_id, extra_specs):
|
||||
|
|
Loading…
Reference in New Issue