Skip to content

Commit 2a28605

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "Add --cluster option to volume migration"
2 parents e7ccdec + 78e0bf0 commit 2a28605

3 files changed

Lines changed: 88 additions & 6 deletions

File tree

openstackclient/tests/unit/volume/v3/test_volume.py

Lines changed: 60 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1723,9 +1723,10 @@ def test_volume_migrate(self):
17231723
host="host@backend-name#pool",
17241724
force_host_copy=False,
17251725
lock_volume=False,
1726+
cluster=None,
17261727
)
17271728

1728-
def test_volume_migrate_with_option(self):
1729+
def test_volume_migrate_with_host(self):
17291730
arglist = [
17301731
"--force-host-copy",
17311732
"--lock-volume",
@@ -1752,9 +1753,66 @@ def test_volume_migrate_with_option(self):
17521753
host="host@backend-name#pool",
17531754
force_host_copy=True,
17541755
lock_volume=True,
1756+
cluster=None,
17551757
)
17561758

1757-
def test_volume_migrate_without_host(self):
1759+
def test_volume_migrate_with_cluster(self):
1760+
self.set_volume_api_version('3.16')
1761+
arglist = [
1762+
"--cluster",
1763+
"cluster@backend-name#pool",
1764+
self.volume.id,
1765+
]
1766+
verifylist = [
1767+
(
1768+
"cluster",
1769+
"cluster@backend-name#pool",
1770+
),
1771+
("volume", self.volume.id),
1772+
]
1773+
1774+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
1775+
1776+
result = self.cmd.take_action(parsed_args)
1777+
self.assertIsNone(result)
1778+
1779+
self.volume_sdk_client.find_volume.assert_called_with(
1780+
self.volume.id, ignore_missing=False
1781+
)
1782+
self.volume_sdk_client.migrate_volume.assert_called_once_with(
1783+
self.volume.id,
1784+
host=None,
1785+
force_host_copy=False,
1786+
lock_volume=False,
1787+
cluster="cluster@backend-name#pool",
1788+
)
1789+
1790+
def test_volume_migrate_with_cluster_pre_v316(self):
1791+
self.set_volume_api_version('3.15')
1792+
arglist = [
1793+
"--cluster",
1794+
"cluster@backend-name#pool",
1795+
self.volume.id,
1796+
]
1797+
verifylist = [
1798+
(
1799+
"cluster",
1800+
"cluster@backend-name#pool",
1801+
),
1802+
("volume", self.volume.id),
1803+
]
1804+
1805+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
1806+
1807+
self.assertRaises(
1808+
exceptions.CommandError,
1809+
self.cmd.take_action,
1810+
parsed_args,
1811+
)
1812+
1813+
self.volume_sdk_client.migrate_volume.assert_not_called()
1814+
1815+
def test_volume_migrate_without_host_and_cluster(self):
17581816
arglist = [
17591817
self.volume.id,
17601818
]
@@ -1771,7 +1829,6 @@ def test_volume_migrate_without_host(self):
17711829
arglist,
17721830
verifylist,
17731831
)
1774-
17751832
self.volume_sdk_client.find_volume.assert_not_called()
17761833
self.volume_sdk_client.migrate_volume.assert_not_called()
17771834

openstackclient/volume/v3/volume.py

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -743,14 +743,22 @@ def get_parser(self, prog_name):
743743
metavar="<volume>",
744744
help=_("Volume to migrate (name or ID)"),
745745
)
746-
parser.add_argument(
746+
destination_group = parser.add_mutually_exclusive_group(required=True)
747+
destination_group.add_argument(
747748
'--host',
748749
metavar="<host>",
749-
required=True,
750750
help=_(
751751
"Destination host (takes the form: host@backend-name#pool)"
752752
),
753753
)
754+
destination_group.add_argument(
755+
'--cluster',
756+
metavar="<cluster>",
757+
help=_(
758+
"Destination cluster to migrate the volume to "
759+
"(requires --os-volume-api-version 3.16 or higher)"
760+
),
761+
)
754762
parser.add_argument(
755763
'--force-host-copy',
756764
action="store_true",
@@ -768,19 +776,29 @@ def get_parser(self, prog_name):
768776
"(possibly by another operation)"
769777
),
770778
)
771-
# TODO(stephenfin): Add --cluster argument
772779
return parser
773780

774781
def take_action(self, parsed_args):
775782
volume_client = self.app.client_manager.sdk_connection.volume
776783
volume = volume_client.find_volume(
777784
parsed_args.volume, ignore_missing=False
778785
)
786+
787+
if parsed_args.cluster and not sdk_utils.supports_microversion(
788+
volume_client, '3.16'
789+
):
790+
msg = _(
791+
"--os-volume-api-version 3.16 or greater is required to "
792+
"support the volume migration with cluster"
793+
)
794+
raise exceptions.CommandError(msg)
795+
779796
volume_client.migrate_volume(
780797
volume.id,
781798
host=parsed_args.host,
782799
force_host_copy=parsed_args.force_host_copy,
783800
lock_volume=parsed_args.lock_volume,
801+
cluster=parsed_args.cluster,
784802
)
785803

786804

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
features:
3+
- |
4+
The ``volume migration`` command now supports the ``--cluster``
5+
optional argument, allowing volumes to be migrated to a destination
6+
cluster. This feature requires Cinder API microversion 3.16 or
7+
higher and is mutually exclusive with the ``--host`` option.

0 commit comments

Comments
 (0)