From a5907fa6d5f18865d61acc56355ec082d409f9da Mon Sep 17 00:00:00 2001 From: Sean McGinnis Date: Wed, 16 Mar 2016 19:06:08 +0000 Subject: [PATCH] Revert "Cleanup for Replication v2: remove 'replication-promote'" Forgot this was a replication v1 command. We need to keep v1 support around in the client for users with a new client and old service. This reverts commit 9685009da2311d871bd90c7705d842dac7e7ed53. Change-Id: Ifad5ddb021d98b0fc973bc9ea478baccc60f912f --- cinderclient/tests/unit/v2/fakes.py | 5 +++++ cinderclient/tests/unit/v2/test_shell.py | 5 +++++ cinderclient/tests/unit/v2/test_volumes.py | 8 ++++++++ cinderclient/v2/shell.py | 11 +++++++++++ cinderclient/v2/volumes.py | 4 ++++ 5 files changed, 33 insertions(+) diff --git a/cinderclient/tests/unit/v2/fakes.py b/cinderclient/tests/unit/v2/fakes.py index b02a6fcae..7798c2995 100644 --- a/cinderclient/tests/unit/v2/fakes.py +++ b/cinderclient/tests/unit/v2/fakes.py @@ -455,6 +455,8 @@ class FakeHTTPClient(base_client.HTTPClient): assert list(body[action]) == ['bootable'] elif action == 'os-unmanage': assert body[action] is None + elif action == 'os-promote-replica': + assert body[action] is None elif action == 'os-reenable-replica': assert body[action] is None elif action == 'os-set_image_metadata': @@ -1085,6 +1087,9 @@ class FakeHTTPClient(base_client.HTTPClient): snapshot.update(kw['body']['snapshot']) return (202, {}, {'snapshot': snapshot}) + def post_os_promote_replica_1234(self, **kw): + return (202, {}, {}) + def post_os_reenable_replica_1234(self, **kw): return (202, {}, {}) diff --git a/cinderclient/tests/unit/v2/test_shell.py b/cinderclient/tests/unit/v2/test_shell.py index 453d8493b..3364b71fc 100644 --- a/cinderclient/tests/unit/v2/test_shell.py +++ b/cinderclient/tests/unit/v2/test_shell.py @@ -1029,6 +1029,11 @@ class ShellTest(utils.TestCase): self.assert_called('POST', '/volumes/1234/action', body={'os-unmanage': None}) + def test_replication_promote(self): + self.run_command('replication-promote 1234') + self.assert_called('POST', '/volumes/1234/action', + body={'os-promote-replica': None}) + def test_replication_reenable(self): self.run_command('replication-reenable 1234') self.assert_called('POST', '/volumes/1234/action', diff --git a/cinderclient/tests/unit/v2/test_volumes.py b/cinderclient/tests/unit/v2/test_volumes.py index cd47c800c..11fc40994 100644 --- a/cinderclient/tests/unit/v2/test_volumes.py +++ b/cinderclient/tests/unit/v2/test_volumes.py @@ -281,6 +281,14 @@ class VolumesTest(utils.TestCase): cs.assert_called('POST', '/os-snapshot-manage', {'snapshot': expected}) self._assert_request_id(vol) + def test_replication_promote(self): + v = cs.volumes.get('1234') + self._assert_request_id(v) + vol = cs.volumes.promote(v) + cs.assert_called('POST', '/volumes/1234/action', + {'os-promote-replica': None}) + self._assert_request_id(vol) + def test_replication_reenable(self): v = cs.volumes.get('1234') self._assert_request_id(v) diff --git a/cinderclient/v2/shell.py b/cinderclient/v2/shell.py index 3716fa755..a854ec6eb 100644 --- a/cinderclient/v2/shell.py +++ b/cinderclient/v2/shell.py @@ -2236,6 +2236,17 @@ def do_unmanage(cs, args): cs.volumes.unmanage(volume.id) +@utils.arg('volume', metavar='', + help='Name or ID of the volume to promote. ' + 'The volume should have the replica volume created with ' + 'source-replica argument.') +@utils.service_type('volumev2') +def do_replication_promote(cs, args): + """Promote a secondary volume to primary for a relationship.""" + volume = utils.find_volume(cs, args.volume) + cs.volumes.promote(volume.id) + + @utils.arg('volume', metavar='', help='Name or ID of the volume to reenable replication. ' 'The replication-status of the volume should be inactive.') diff --git a/cinderclient/v2/volumes.py b/cinderclient/v2/volumes.py index f1fb193b7..bab4796c8 100644 --- a/cinderclient/v2/volumes.py +++ b/cinderclient/v2/volumes.py @@ -587,6 +587,10 @@ class VolumeManager(base.ManagerWithFind): """Unmanage a volume.""" return self._action('os-unmanage', volume, None) + def promote(self, volume): + """Promote secondary to be primary in relationship.""" + return self._action('os-promote-replica', volume, None) + def reenable(self, volume): """Sync the secondary volume with primary for a relationship.""" return self._action('os-reenable-replica', volume, None)