Skip to content

Commit 78e0bf0

Browse files
author
hongp
committed
Add --cluster option to volume migration
This patch adds the '--cluster' optional argument to the 'volume migration' command. This allows users to migrate volumes to a destination cluster instead of a specific host, which is particularly useful in Active-Active configurations. The '--cluster' option requires Cinder API microversion 3.16 or higher. The '--host' and '--cluster' options are mutually exclusive; one of them must be provided for the migration to start. Change-Id: Ibd45ac35e39a2a9f88a39f8041c06c4469727098 Signed-off-by: hongp <inyong.hong@samsung.com>
1 parent 0a93733 commit 78e0bf0

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
@@ -1702,9 +1702,10 @@ def test_volume_migrate(self):
17021702
host="host@backend-name#pool",
17031703
force_host_copy=False,
17041704
lock_volume=False,
1705+
cluster=None,
17051706
)
17061707

1707-
def test_volume_migrate_with_option(self):
1708+
def test_volume_migrate_with_host(self):
17081709
arglist = [
17091710
"--force-host-copy",
17101711
"--lock-volume",
@@ -1731,9 +1732,66 @@ def test_volume_migrate_with_option(self):
17311732
host="host@backend-name#pool",
17321733
force_host_copy=True,
17331734
lock_volume=True,
1735+
cluster=None,
17341736
)
17351737

1736-
def test_volume_migrate_without_host(self):
1738+
def test_volume_migrate_with_cluster(self):
1739+
self.set_volume_api_version('3.16')
1740+
arglist = [
1741+
"--cluster",
1742+
"cluster@backend-name#pool",
1743+
self.volume.id,
1744+
]
1745+
verifylist = [
1746+
(
1747+
"cluster",
1748+
"cluster@backend-name#pool",
1749+
),
1750+
("volume", self.volume.id),
1751+
]
1752+
1753+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
1754+
1755+
result = self.cmd.take_action(parsed_args)
1756+
self.assertIsNone(result)
1757+
1758+
self.volume_sdk_client.find_volume.assert_called_with(
1759+
self.volume.id, ignore_missing=False
1760+
)
1761+
self.volume_sdk_client.migrate_volume.assert_called_once_with(
1762+
self.volume.id,
1763+
host=None,
1764+
force_host_copy=False,
1765+
lock_volume=False,
1766+
cluster="cluster@backend-name#pool",
1767+
)
1768+
1769+
def test_volume_migrate_with_cluster_pre_v316(self):
1770+
self.set_volume_api_version('3.15')
1771+
arglist = [
1772+
"--cluster",
1773+
"cluster@backend-name#pool",
1774+
self.volume.id,
1775+
]
1776+
verifylist = [
1777+
(
1778+
"cluster",
1779+
"cluster@backend-name#pool",
1780+
),
1781+
("volume", self.volume.id),
1782+
]
1783+
1784+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
1785+
1786+
self.assertRaises(
1787+
exceptions.CommandError,
1788+
self.cmd.take_action,
1789+
parsed_args,
1790+
)
1791+
1792+
self.volume_sdk_client.migrate_volume.assert_not_called()
1793+
1794+
def test_volume_migrate_without_host_and_cluster(self):
17371795
arglist = [
17381796
self.volume.id,
17391797
]
@@ -1750,7 +1808,6 @@ def test_volume_migrate_without_host(self):
17501808
arglist,
17511809
verifylist,
17521810
)
1753-
17541811
self.volume_sdk_client.find_volume.assert_not_called()
17551812
self.volume_sdk_client.migrate_volume.assert_not_called()
17561813

openstackclient/volume/v3/volume.py

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -736,14 +736,22 @@ def get_parser(self, prog_name):
736736
metavar="<volume>",
737737
help=_("Volume to migrate (name or ID)"),
738738
)
739-
parser.add_argument(
739+
destination_group = parser.add_mutually_exclusive_group(required=True)
740+
destination_group.add_argument(
740741
'--host',
741742
metavar="<host>",
742-
required=True,
743743
help=_(
744744
"Destination host (takes the form: host@backend-name#pool)"
745745
),
746746
)
747+
destination_group.add_argument(
748+
'--cluster',
749+
metavar="<cluster>",
750+
help=_(
751+
"Destination cluster to migrate the volume to "
752+
"(requires --os-volume-api-version 3.16 or higher)"
753+
),
754+
)
747755
parser.add_argument(
748756
'--force-host-copy',
749757
action="store_true",
@@ -761,19 +769,29 @@ def get_parser(self, prog_name):
761769
"(possibly by another operation)"
762770
),
763771
)
764-
# TODO(stephenfin): Add --cluster argument
765772
return parser
766773

767774
def take_action(self, parsed_args):
768775
volume_client = self.app.client_manager.sdk_connection.volume
769776
volume = volume_client.find_volume(
770777
parsed_args.volume, ignore_missing=False
771778
)
779+
780+
if parsed_args.cluster and not sdk_utils.supports_microversion(
781+
volume_client, '3.16'
782+
):
783+
msg = _(
784+
"--os-volume-api-version 3.16 or greater is required to "
785+
"support the volume migration with cluster"
786+
)
787+
raise exceptions.CommandError(msg)
788+
772789
volume_client.migrate_volume(
773790
volume.id,
774791
host=parsed_args.host,
775792
force_host_copy=parsed_args.force_host_copy,
776793
lock_volume=parsed_args.lock_volume,
794+
cluster=parsed_args.cluster,
777795
)
778796

779797

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)