Fixes create share from snapshot in OSC

This patch set adds the capability of creating
a share from snapshot in the openstack client.

This bug was fixed for the GHC2020 OSD by the
$author, Maari Tamm, Sol K, Priya, Zuleinis and Hieu.

Change-Id: If32d55d52cd0c04a10fd0f1b2ac19fad843cecf6
Closes-Bug: #1888327
This commit is contained in:
Cloud User
2020-10-01 22:11:21 +00:00
committed by Maari Tamm
parent 3cc12ce444
commit 07898faca6
2 changed files with 43 additions and 4 deletions

View File

@@ -206,11 +206,12 @@ class CreateShare(command.ShowOne):
if parsed_args.snapshot_id: if parsed_args.snapshot_id:
snapshot = apiutils.find_resource(share_client.share_snapshots, snapshot = apiutils.find_resource(share_client.share_snapshots,
parsed_args.snapshot_id) parsed_args.snapshot_id)
snapshot_id = snapshot.id
size = max(size or 0, snapshot.size) size = max(size or 0, snapshot.size)
body = { body = {
'share_proto': parsed_args.share_proto, 'share_proto': parsed_args.share_proto,
'size': parsed_args.size, 'size': size,
'snapshot_id': snapshot_id, 'snapshot_id': snapshot_id,
'name': parsed_args.name, 'name': parsed_args.name,
'description': parsed_args.description, 'description': parsed_args.description,

View File

@@ -41,6 +41,9 @@ class TestShare(manila_fakes.TestShare):
self.users_mock = self.app.client_manager.identity.users self.users_mock = self.app.client_manager.identity.users
self.users_mock.reset_mock() self.users_mock.reset_mock()
self.snapshots_mock = self.app.client_manager.share.share_snapshots
self.snapshots_mock.reset_mock()
def setup_shares_mock(self, count): def setup_shares_mock(self, count):
shares = manila_fakes.FakeShare.create_shares(count=count) shares = manila_fakes.FakeShare.create_shares(count=count)
@@ -61,6 +64,9 @@ class TestShareCreate(TestShare):
self.shares_mock.create.return_value = self.new_share self.shares_mock.create.return_value = self.new_share
self.shares_mock.get.return_value = self.new_share self.shares_mock.get.return_value = self.new_share
self.share_snapshot = (
manila_fakes.FakeShareSnapshot.create_one_snapshot())
self.snapshots_mock.get.return_value = self.share_snapshot
# Get the command object to test # Get the command object to test
self.cmd = osc_shares.CreateShare(self.app, None) self.cmd = osc_shares.CreateShare(self.app, None)
@@ -146,9 +152,41 @@ class TestShareCreate(TestShare):
self.assertCountEqual(self.columns, columns) self.assertCountEqual(self.columns, columns)
self.assertCountEqual(self.datalist, data) self.assertCountEqual(self.datalist, data)
# TODO(vkmc) Add test with snapshot when def test_share_create_with_snapshot(self):
# we implement snapshot support in OSC """Verifies create share from snapshot."""
# def test_share_create_with_snapshot(self):
arglist = [
self.new_share.share_proto,
str(self.new_share.size),
'--snapshot-id', self.share_snapshot.id
]
verifylist = [
('share_proto', self.new_share.share_proto),
('size', self.new_share.size),
('snapshot_id', self.share_snapshot.id)
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
columns, data = self.cmd.take_action(parsed_args)
self.shares_mock.create.assert_called_with(
availability_zone=None,
description=None,
is_public=False,
metadata={},
name=None,
share_group_id=None,
share_network=None,
share_proto=self.new_share.share_proto,
share_type=None,
size=self.new_share.size,
snapshot_id=self.share_snapshot.id
)
self.assertCountEqual(self.columns, columns)
self.assertCountEqual(self.datalist, data)
def test_share_create_wait(self): def test_share_create_wait(self):