diff options
author | Zuul <zuul@review.opendev.org> | 2021-07-20 17:06:47 +0000 |
---|---|---|
committer | Gerrit Code Review <review@openstack.org> | 2021-07-20 17:06:47 +0000 |
commit | e03111dea33d671661d01eadbb068d6ee6987cec (patch) | |
tree | 2c7cf253f3df337f7aa2da23d800108dd3142e2c | |
parent | 6ebee33bf219d42fcd0d4bf2a8c0819bddb24f3c (diff) | |
parent | d714249ca9e95297f5e53c9dcc0af9ba58d0ab6d (diff) | |
download | python-cinderclient-e03111dea33d671661d01eadbb068d6ee6987cec.tar.gz |
Merge "Make instance_uuid optional in attachment create"8.0.0
-rw-r--r-- | cinderclient/tests/unit/v3/fakes.py | 14 | ||||
-rw-r--r-- | cinderclient/tests/unit/v3/test_attachments.py | 11 | ||||
-rw-r--r-- | cinderclient/tests/unit/v3/test_shell.py | 40 | ||||
-rw-r--r-- | cinderclient/v3/attachments.py | 5 | ||||
-rw-r--r-- | cinderclient/v3/shell.py | 2 | ||||
-rw-r--r-- | releasenotes/notes/attachment-create-optional-server-id-9299d9da2b62b263.yaml | 10 |
6 files changed, 79 insertions, 3 deletions
diff --git a/cinderclient/tests/unit/v3/fakes.py b/cinderclient/tests/unit/v3/fakes.py index 7429af2..d39dd4b 100644 --- a/cinderclient/tests/unit/v3/fakes.py +++ b/cinderclient/tests/unit/v3/fakes.py @@ -29,6 +29,16 @@ fake_attachment = {'attachment': { 'instance': 'e84fda45-4de4-4ce4-8f39-fc9d3b0aa05e', 'volume_id': '557ad76c-ce54-40a3-9e91-c40d21665cc3', }} +fake_attachment_without_instance_id = {'attachment': { + 'status': 'reserved', + 'detached_at': '', + 'connection_info': {}, + 'attached_at': '', + 'attach_mode': None, + 'id': 'a232e9ae', + 'instance': None, + 'volume_id': '557ad76c-ce54-40a3-9e91-c40d21665cc3', }} + fake_attachment_list = {'attachments': [ {'instance': 'instance_1', 'name': 'attachment-1', @@ -310,7 +320,9 @@ class FakeHTTPClient(fakes_base.FakeHTTPClient): # def post_attachments(self, **kw): - return (200, {}, fake_attachment) + if kw['body']['attachment'].get('instance_uuid'): + return (200, {}, fake_attachment) + return (200, {}, fake_attachment_without_instance_id) def get_attachments(self, **kw): return (200, {}, fake_attachment_list) diff --git a/cinderclient/tests/unit/v3/test_attachments.py b/cinderclient/tests/unit/v3/test_attachments.py index 1802334..acf0646 100644 --- a/cinderclient/tests/unit/v3/test_attachments.py +++ b/cinderclient/tests/unit/v3/test_attachments.py @@ -31,6 +31,17 @@ class AttachmentsTest(utils.TestCase): cs.assert_called('POST', '/attachments') self.assertEqual(fakes.fake_attachment['attachment'], att) + def test_create_attachment_without_instance_uuid(self): + cs = fakes.FakeClient(api_versions.APIVersion('3.27')) + att = cs.attachments.create( + 'e84fda45-4de4-4ce4-8f39-fc9d3b0aa05e', + {}, + None, + 'null') + cs.assert_called('POST', '/attachments') + self.assertEqual( + fakes.fake_attachment_without_instance_id['attachment'], att) + def test_complete_attachment(self): cs = fakes.FakeClient(api_versions.APIVersion('3.44')) att = cs.attachments.complete('a232e9ae') diff --git a/cinderclient/tests/unit/v3/test_shell.py b/cinderclient/tests/unit/v3/test_shell.py index a5b76fe..e7a1660 100644 --- a/cinderclient/tests/unit/v3/test_shell.py +++ b/cinderclient/tests/unit/v3/test_shell.py @@ -388,6 +388,25 @@ class ShellTest(utils.TestCase): {'cmd': 'abc 1233', 'body': {'instance_uuid': '1233', 'connector': {}, + 'volume_uuid': '1234'}}, + {'cmd': '1234', + 'body': {'connector': {}, + 'volume_uuid': '1234'}}, + {'cmd': '1234 ' + '--connect True ' + '--ip 10.23.12.23 --host server01 ' + '--platform x86_xx ' + '--ostype 123 ' + '--multipath true ' + '--mountpoint /123 ' + '--initiator aabbccdd', + 'body': {'connector': {'ip': '10.23.12.23', + 'host': 'server01', + 'os_type': '123', + 'multipath': 'true', + 'mountpoint': '/123', + 'initiator': 'aabbccdd', + 'platform': 'x86_xx'}, 'volume_uuid': '1234'}}) @mock.patch('cinderclient.utils.find_resource') @ddt.unpack @@ -429,6 +448,27 @@ class ShellTest(utils.TestCase): 'body': {'instance_uuid': '1233', 'connector': {}, 'volume_uuid': '1234', + 'mode': 'ro'}}, + {'cmd': '1234', + 'body': {'connector': {}, + 'volume_uuid': '1234', + 'mode': 'ro'}}, + {'cmd': '1234 ' + '--connect True ' + '--ip 10.23.12.23 --host server01 ' + '--platform x86_xx ' + '--ostype 123 ' + '--multipath true ' + '--mountpoint /123 ' + '--initiator aabbccdd', + 'body': {'connector': {'ip': '10.23.12.23', + 'host': 'server01', + 'os_type': '123', + 'multipath': 'true', + 'mountpoint': '/123', + 'initiator': 'aabbccdd', + 'platform': 'x86_xx'}, + 'volume_uuid': '1234', 'mode': 'ro'}}) @mock.patch('cinderclient.utils.find_resource') @ddt.unpack diff --git a/cinderclient/v3/attachments.py b/cinderclient/v3/attachments.py index e1e9290..5067962 100644 --- a/cinderclient/v3/attachments.py +++ b/cinderclient/v3/attachments.py @@ -27,11 +27,12 @@ class VolumeAttachmentManager(base.ManagerWithFind): resource_class = VolumeAttachment @api_versions.wraps('3.27') - def create(self, volume_id, connector, instance_id, mode='null'): + def create(self, volume_id, connector, instance_id=None, mode='null'): """Create a attachment for specified volume.""" body = {'attachment': {'volume_uuid': volume_id, - 'instance_uuid': instance_id, 'connector': connector}} + if instance_id: + body['attachment']['instance_uuid'] = instance_id if self.api_version >= api_versions.APIVersion("3.54"): if mode and mode != 'null': body['attachment']['mode'] = mode diff --git a/cinderclient/v3/shell.py b/cinderclient/v3/shell.py index afbe369..7ffba81 100644 --- a/cinderclient/v3/shell.py +++ b/cinderclient/v3/shell.py @@ -2297,6 +2297,8 @@ def do_attachment_show(cs, args): help='Name or ID of volume or volumes to attach.') @utils.arg('server_id', metavar='<server_id>', + nargs='?', + default=None, help='ID of server attaching to.') @utils.arg('--connect', metavar='<connect>', diff --git a/releasenotes/notes/attachment-create-optional-server-id-9299d9da2b62b263.yaml b/releasenotes/notes/attachment-create-optional-server-id-9299d9da2b62b263.yaml new file mode 100644 index 0000000..1193582 --- /dev/null +++ b/releasenotes/notes/attachment-create-optional-server-id-9299d9da2b62b263.yaml @@ -0,0 +1,10 @@ +--- +fixes: + - | + When attaching to a host, we don't need a server id + so it shouldn't be mandatory to be supplied with + attachment-create operation. + The server_id parameter is made optional so we can + create attachments without passing it. + The backward compatibility is maintained so we can pass + it like how we currently do if required.
\ No newline at end of file |