Skip to content

Commit 5e5f12b

Browse files
committed
volume: Migrate 'volume migrate' to SDK
Change-Id: I99af5fce0c2c184e300dfbf5624b91eeed38c94b Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
1 parent 504cbd2 commit 5e5f12b

File tree

4 files changed

+83
-53
lines changed

4 files changed

+83
-53
lines changed

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

Lines changed: 34 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1293,69 +1293,80 @@ def test_volume_list_backward_compatibility(self):
12931293
self.assertIn(self.mock_volume.name, each_volume)
12941294

12951295

1296-
class TestVolumeMigrate(TestVolume):
1297-
_volume = volume_fakes.create_one_volume()
1298-
1296+
class TestVolumeMigrate(volume_fakes.TestVolume):
12991297
def setUp(self):
13001298
super().setUp()
13011299

1302-
self.volumes_mock.get.return_value = self._volume
1303-
self.volumes_mock.migrate_volume.return_value = None
1304-
# Get the command object to test
1300+
self.volume = sdk_fakes.generate_fake_resource(_volume.Volume)
1301+
self.volume_sdk_client.find_volume.return_value = self.volume
1302+
self.volume_sdk_client.migrate_volume.return_value = None
1303+
13051304
self.cmd = volume.MigrateVolume(self.app, None)
13061305

13071306
def test_volume_migrate(self):
13081307
arglist = [
13091308
"--host",
13101309
"host@backend-name#pool",
1311-
self._volume.id,
1310+
self.volume.id,
13121311
]
13131312
verifylist = [
13141313
("force_host_copy", False),
13151314
("lock_volume", False),
13161315
("host", "host@backend-name#pool"),
1317-
("volume", self._volume.id),
1316+
("volume", self.volume.id),
13181317
]
13191318
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
13201319

13211320
result = self.cmd.take_action(parsed_args)
1322-
self.volumes_mock.get.assert_called_once_with(self._volume.id)
1323-
self.volumes_mock.migrate_volume.assert_called_once_with(
1324-
self._volume.id, "host@backend-name#pool", False, False
1325-
)
13261321
self.assertIsNone(result)
13271322

1323+
self.volume_sdk_client.find_volume.assert_called_with(
1324+
self.volume.id, ignore_missing=False
1325+
)
1326+
self.volume_sdk_client.migrate_volume.assert_called_once_with(
1327+
self.volume.id,
1328+
host="host@backend-name#pool",
1329+
force_host_copy=False,
1330+
lock_volume=False,
1331+
)
1332+
13281333
def test_volume_migrate_with_option(self):
13291334
arglist = [
13301335
"--force-host-copy",
13311336
"--lock-volume",
13321337
"--host",
13331338
"host@backend-name#pool",
1334-
self._volume.id,
1339+
self.volume.id,
13351340
]
13361341
verifylist = [
13371342
("force_host_copy", True),
13381343
("lock_volume", True),
13391344
("host", "host@backend-name#pool"),
1340-
("volume", self._volume.id),
1345+
("volume", self.volume.id),
13411346
]
13421347
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
13431348

13441349
result = self.cmd.take_action(parsed_args)
1345-
self.volumes_mock.get.assert_called_once_with(self._volume.id)
1346-
self.volumes_mock.migrate_volume.assert_called_once_with(
1347-
self._volume.id, "host@backend-name#pool", True, True
1348-
)
13491350
self.assertIsNone(result)
13501351

1352+
self.volume_sdk_client.find_volume.assert_called_with(
1353+
self.volume.id, ignore_missing=False
1354+
)
1355+
self.volume_sdk_client.migrate_volume.assert_called_once_with(
1356+
self.volume.id,
1357+
host="host@backend-name#pool",
1358+
force_host_copy=True,
1359+
lock_volume=True,
1360+
)
1361+
13511362
def test_volume_migrate_without_host(self):
13521363
arglist = [
1353-
self._volume.id,
1364+
self.volume.id,
13541365
]
13551366
verifylist = [
13561367
("force_host_copy", False),
13571368
("lock_volume", False),
1358-
("volume", self._volume.id),
1369+
("volume", self.volume.id),
13591370
]
13601371

13611372
self.assertRaises(
@@ -1366,6 +1377,9 @@ def test_volume_migrate_without_host(self):
13661377
verifylist,
13671378
)
13681379

1380+
self.volume_sdk_client.find_volume.assert_not_called()
1381+
self.volume_sdk_client.migrate_volume.assert_not_called()
1382+
13691383

13701384
class TestVolumeSet(TestVolume):
13711385
volume_type = volume_fakes.create_one_volume_type()

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

Lines changed: 32 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1665,71 +1665,79 @@ def test_volume_list_backward_compatibility(self):
16651665

16661666

16671667
class TestVolumeMigrate(volume_fakes.TestVolume):
1668-
_volume = volume_fakes.create_one_volume()
1669-
16701668
def setUp(self):
16711669
super().setUp()
16721670

1673-
self.volumes_mock = self.volume_client.volumes
1674-
self.volumes_mock.reset_mock()
1671+
self.volume = sdk_fakes.generate_fake_resource(_volume.Volume)
1672+
self.volume_sdk_client.find_volume.return_value = self.volume
1673+
self.volume_sdk_client.migrate_volume.return_value = None
16751674

1676-
self.volumes_mock.get.return_value = self._volume
1677-
self.volumes_mock.migrate_volume.return_value = None
1678-
# Get the command object to test
16791675
self.cmd = volume.MigrateVolume(self.app, None)
16801676

16811677
def test_volume_migrate(self):
16821678
arglist = [
16831679
"--host",
16841680
"host@backend-name#pool",
1685-
self._volume.id,
1681+
self.volume.id,
16861682
]
16871683
verifylist = [
16881684
("force_host_copy", False),
16891685
("lock_volume", False),
16901686
("host", "host@backend-name#pool"),
1691-
("volume", self._volume.id),
1687+
("volume", self.volume.id),
16921688
]
16931689
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
16941690

16951691
result = self.cmd.take_action(parsed_args)
1696-
self.volumes_mock.get.assert_called_once_with(self._volume.id)
1697-
self.volumes_mock.migrate_volume.assert_called_once_with(
1698-
self._volume.id, "host@backend-name#pool", False, False
1699-
)
17001692
self.assertIsNone(result)
17011693

1694+
self.volume_sdk_client.find_volume.assert_called_with(
1695+
self.volume.id, ignore_missing=False
1696+
)
1697+
self.volume_sdk_client.migrate_volume.assert_called_once_with(
1698+
self.volume.id,
1699+
host="host@backend-name#pool",
1700+
force_host_copy=False,
1701+
lock_volume=False,
1702+
)
1703+
17021704
def test_volume_migrate_with_option(self):
17031705
arglist = [
17041706
"--force-host-copy",
17051707
"--lock-volume",
17061708
"--host",
17071709
"host@backend-name#pool",
1708-
self._volume.id,
1710+
self.volume.id,
17091711
]
17101712
verifylist = [
17111713
("force_host_copy", True),
17121714
("lock_volume", True),
17131715
("host", "host@backend-name#pool"),
1714-
("volume", self._volume.id),
1716+
("volume", self.volume.id),
17151717
]
17161718
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
17171719

17181720
result = self.cmd.take_action(parsed_args)
1719-
self.volumes_mock.get.assert_called_once_with(self._volume.id)
1720-
self.volumes_mock.migrate_volume.assert_called_once_with(
1721-
self._volume.id, "host@backend-name#pool", True, True
1722-
)
17231721
self.assertIsNone(result)
17241722

1723+
self.volume_sdk_client.find_volume.assert_called_with(
1724+
self.volume.id, ignore_missing=False
1725+
)
1726+
self.volume_sdk_client.migrate_volume.assert_called_once_with(
1727+
self.volume.id,
1728+
host="host@backend-name#pool",
1729+
force_host_copy=True,
1730+
lock_volume=True,
1731+
)
1732+
17251733
def test_volume_migrate_without_host(self):
17261734
arglist = [
1727-
self._volume.id,
1735+
self.volume.id,
17281736
]
17291737
verifylist = [
17301738
("force_host_copy", False),
17311739
("lock_volume", False),
1732-
("volume", self._volume.id),
1740+
("volume", self.volume.id),
17331741
]
17341742

17351743
self.assertRaises(
@@ -1740,6 +1748,9 @@ def test_volume_migrate_without_host(self):
17401748
verifylist,
17411749
)
17421750

1751+
self.volume_sdk_client.find_volume.assert_not_called()
1752+
self.volume_sdk_client.migrate_volume.assert_not_called()
1753+
17431754

17441755
class TestVolumeSet(volume_fakes.TestVolume):
17451756
volume_type = volume_fakes.create_one_volume_type()

openstackclient/volume/v2/volume.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -613,13 +613,15 @@ def get_parser(self, prog_name):
613613
return parser
614614

615615
def take_action(self, parsed_args):
616-
volume_client = self.app.client_manager.volume
617-
volume = utils.find_resource(volume_client.volumes, parsed_args.volume)
618-
volume_client.volumes.migrate_volume(
616+
volume_client = self.app.client_manager.sdk_connection.volume
617+
volume = volume_client.find_volume(
618+
parsed_args.volume, ignore_missing=False
619+
)
620+
volume_client.migrate_volume(
619621
volume.id,
620-
parsed_args.host,
621-
parsed_args.force_host_copy,
622-
parsed_args.lock_volume,
622+
host=parsed_args.host,
623+
force_host_copy=parsed_args.force_host_copy,
624+
lock_volume=parsed_args.lock_volume,
623625
)
624626

625627

openstackclient/volume/v3/volume.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -761,16 +761,19 @@ def get_parser(self, prog_name):
761761
"(possibly by another operation)"
762762
),
763763
)
764+
# TODO(stephenfin): Add --cluster argument
764765
return parser
765766

766767
def take_action(self, parsed_args):
767-
volume_client = self.app.client_manager.volume
768-
volume = utils.find_resource(volume_client.volumes, parsed_args.volume)
769-
volume_client.volumes.migrate_volume(
768+
volume_client = self.app.client_manager.sdk_connection.volume
769+
volume = volume_client.find_volume(
770+
parsed_args.volume, ignore_missing=False
771+
)
772+
volume_client.migrate_volume(
770773
volume.id,
771-
parsed_args.host,
772-
parsed_args.force_host_copy,
773-
parsed_args.lock_volume,
774+
host=parsed_args.host,
775+
force_host_copy=parsed_args.force_host_copy,
776+
lock_volume=parsed_args.lock_volume,
774777
)
775778

776779

0 commit comments

Comments
 (0)