Merge "[OSC] Add OSC Functional Tests Share Actions"
This commit is contained in:
commit
3c25e506cf
|
@ -1180,6 +1180,12 @@ class RevertShare(command.Command):
|
|||
help=_('Name or ID of the snapshot to restore. The snapshot '
|
||||
'must be the most recent one known to manila.')
|
||||
)
|
||||
parser.add_argument(
|
||||
'--wait',
|
||||
action='store_true',
|
||||
default=False,
|
||||
help=_('Wait for share revert')
|
||||
)
|
||||
return parser
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
|
@ -1194,6 +1200,14 @@ class RevertShare(command.Command):
|
|||
except Exception as e:
|
||||
raise exceptions.CommandError(_(
|
||||
"Failed to revert share to snapshot: %s" % (e)))
|
||||
if parsed_args.wait:
|
||||
if not oscutils.wait_for_status(
|
||||
status_f=share_client.shares.get,
|
||||
res_id=share.id,
|
||||
success_status=['available']
|
||||
):
|
||||
raise exceptions.CommandError(_(
|
||||
"Share not available after revert attempt."))
|
||||
|
||||
|
||||
class ShareMigrationStart(command.Command):
|
||||
|
|
|
@ -181,7 +181,7 @@ class OSCClientTestBase(base.ClientTestBase):
|
|||
|
||||
if add_cleanup:
|
||||
self.addCleanup(
|
||||
self.openstack, 'share delete %s' % share_object['id']
|
||||
self.openstack, 'share delete %s --wait' % share_object['id']
|
||||
)
|
||||
return share_object
|
||||
|
||||
|
@ -272,3 +272,31 @@ class OSCClientTestBase(base.ClientTestBase):
|
|||
access_rule = self.dict_result('share', cmd)
|
||||
|
||||
return access_rule
|
||||
|
||||
def get_share_export_locations(self, share):
|
||||
cmd = (f'export location list {share}')
|
||||
export_locations = json.loads(self.openstack(f'share {cmd} -f json'))
|
||||
return export_locations
|
||||
|
||||
def create_snapshot(self, share, name=None,
|
||||
description=None, wait=None,
|
||||
force=None, add_cleanup=True):
|
||||
|
||||
name = name or data_utils.rand_name('autotest_snapshot_name')
|
||||
|
||||
cmd = (f'snapshot create {share} --name {name} '
|
||||
f'--description {description} ')
|
||||
if wait:
|
||||
cmd += ' --wait'
|
||||
if force:
|
||||
cmd += ' --force'
|
||||
|
||||
snapshot_object = self.dict_result('share', cmd)
|
||||
self._wait_for_object_status(
|
||||
'share snapshot', snapshot_object['id'], 'available')
|
||||
|
||||
if add_cleanup:
|
||||
self.addCleanup(
|
||||
self.openstack,
|
||||
f'share snapshot delete {snapshot_object["id"]} --wait')
|
||||
return snapshot_object
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
# under the License.
|
||||
|
||||
from manilaclient.tests.functional.osc import base
|
||||
from tempest.lib.common.utils import data_utils
|
||||
|
||||
|
||||
class SharesCLITest(base.OSCClientTestBase):
|
||||
|
@ -90,3 +91,55 @@ class SharesCLITest(base.OSCClientTestBase):
|
|||
self.assertEqual(share['id'], result2['id'])
|
||||
self.assertEqual('None', result2['name'])
|
||||
self.assertEqual("foo='bar'", result2['properties'])
|
||||
|
||||
def test_openstack_share_resize(self):
|
||||
share = self.create_share()
|
||||
self.openstack(f'share resize {share["id"]} 10 --wait ')
|
||||
result = self.dict_result('share', f'show {share["id"]}')
|
||||
self.assertEqual('10', result['size'])
|
||||
|
||||
def test_openstack_share_revert(self):
|
||||
slug = "revert_test"
|
||||
share_type = self.create_share_type(
|
||||
name=data_utils.rand_name(slug),
|
||||
snapshot_support=True,
|
||||
revert_to_snapshot_support=True)
|
||||
share = self.create_share(share_type=share_type['id'], size=10)
|
||||
snapshot = self.create_snapshot(share['id'], wait=True)
|
||||
self.assertEqual(snapshot['size'], share['size'])
|
||||
self.openstack(f'share resize {share["id"]} 15 --wait')
|
||||
result1 = self.dict_result('share', f'show {share["id"]}')
|
||||
self.assertEqual('15', result1["size"])
|
||||
|
||||
self.openstack(f'share revert {snapshot["id"]} --wait')
|
||||
|
||||
result2 = self.dict_result('share', f'show {share["id"]}')
|
||||
|
||||
self.assertEqual('10', result2['size'])
|
||||
|
||||
def test_openstack_share_abandon_adopt(self):
|
||||
share = self.create_share(add_cleanup=False)
|
||||
shares_list = self.listing_result('share', 'list')
|
||||
self.assertIn(share['id'], [item['ID'] for item in shares_list])
|
||||
export_location_obj = self.get_share_export_locations(share['id'])[0]
|
||||
export_location = export_location_obj['Path']
|
||||
source = self.dict_result('share', f'show {share["id"]}')
|
||||
host = source['host']
|
||||
protocol = source['share_proto']
|
||||
share_type = source['share_type']
|
||||
self.openstack(f'share abandon {share["id"]} --wait')
|
||||
|
||||
# verify abandonded
|
||||
self.check_object_deleted('share', share['id'])
|
||||
shares_list_after_delete = self.listing_result('share', 'list')
|
||||
self.assertNotIn(
|
||||
share['id'], [item['ID'] for item in shares_list_after_delete])
|
||||
|
||||
result = self.dict_result(
|
||||
'share', f'adopt {host} {protocol} {export_location} '
|
||||
f'--share-type {share_type} --wait')
|
||||
|
||||
# verify adopted
|
||||
self.assertEqual(host, result['host'])
|
||||
self.assertEqual(protocol, result['share_proto'])
|
||||
self.openstack(f'share delete {result["id"]} --wait')
|
||||
|
|
Loading…
Reference in New Issue