Merge "Client support force extend share with v2.64"

This commit is contained in:
Zuul 2021-12-27 09:41:19 +00:00 committed by Gerrit Code Review
commit af5270a37b
3 changed files with 46 additions and 1 deletions

View File

@ -390,17 +390,22 @@ class SharesV2Client(shares_client.SharesClient):
###############
def extend_share(self, share_id, new_size, version=LATEST_MICROVERSION,
action_name=None):
action_name=None, force=False):
if action_name is None:
if utils.is_microversion_gt(version, "2.6"):
action_name = 'extend'
else:
action_name = 'os-extend'
post_body = {
action_name: {
"new_size": new_size,
}
}
if utils.is_microversion_gt(version, "2.63"):
post_body[action_name]["force"] = force
body = json.dumps(post_body)
resp, body = self.post(
"shares/%s/action" % share_id, body, version=version)

View File

@ -181,3 +181,29 @@ class AdminActionsTest(base.BaseSharesAdminTest):
self.assertNotEmpty(share_server)
else:
self.assertEmpty(share_server)
@decorators.idempotent_id('83d94560-e9b4-47c1-b21e-400531528e27')
@tc.attr(base.TAG_POSITIVE, base.TAG_BACKEND)
@utils.skip_if_microversion_not_supported("2.64")
@testtools.skipUnless(
CONF.share.run_extend_tests,
"Share extend tests are disabled.")
@ddt.data(True, False)
def test_extend_share_force(self, force_flag):
# Force extend were supported from v2.64
# If a admin tries to do force extend, it should be success
share = self.create_share(share_type_id=self.share_type_id,
cleanup_in_class=False)
new_size = int(share['size']) + 1
# force extend share and wait for active status
self.admin_shares_v2_client.extend_share(share['id'], new_size,
force=force_flag)
waiters.wait_for_resource_status(
self.shares_client, share['id'], 'available')
# check new size
share_get = self.shares_v2_client.get_share(share['id'])['share']
msg = ("Share could not be extended. Expected %s, got %s." % (
new_size, share_get['size']))
self.assertEqual(new_size, share_get['size'], msg)

View File

@ -121,6 +121,20 @@ class SharesActionsNegativeTest(base.BaseSharesMixedTest):
share['id'],
new_size)
@decorators.idempotent_id('f9d2ba94-4032-d17a-b4ab-a2b67f650a39')
@tc.attr(base.TAG_NEGATIVE, base.TAG_API_WITH_BACKEND)
@utils.skip_if_microversion_not_supported("2.64")
@testtools.skipUnless(
CONF.share.run_extend_tests,
"Share extend tests are disabled.")
def test_share_force_extend_non_admin_user(self):
# only admin cloud force extend share with micversion >= 2.64
# non-admin will get unauthorized error.
new_size = int(self.share['size']) + 1
self.assertRaises(lib_exc.Forbidden,
self.shares_v2_client.extend_share, self.share['id'],
new_size, force=True)
@decorators.idempotent_id('99d42f94-8da1-4c04-ad5b-9738d6acc139')
@tc.attr(base.TAG_NEGATIVE, base.TAG_API_WITH_BACKEND)
@testtools.skipUnless(