Migrate backup commands to SDK
This patch migrates the following backup commands to SDK: * Create Backup * Show Backup * List Backup * Restore Backup * Delete Backup Change-Id: Icfadd65b92f4cd343bc327d33e29767bc9b969f9
This commit is contained in:
parent
7ea78b6ef6
commit
bfd6170b03
@ -18,6 +18,7 @@ from unittest import mock
|
|||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
from cinderclient import api_versions
|
from cinderclient import api_versions
|
||||||
|
from openstack.block_storage.v3 import backup as _backup
|
||||||
from openstack.block_storage.v3 import volume
|
from openstack.block_storage.v3 import volume
|
||||||
from osc_lib.cli import format_columns
|
from osc_lib.cli import format_columns
|
||||||
|
|
||||||
@ -543,7 +544,17 @@ def create_one_backup(attrs=None):
|
|||||||
|
|
||||||
# Set default attributes.
|
# Set default attributes.
|
||||||
backup_info = {
|
backup_info = {
|
||||||
|
"created_at": 'time-' + uuid.uuid4().hex,
|
||||||
|
"data_timestamp": 'time-' + uuid.uuid4().hex,
|
||||||
"id": 'backup-id-' + uuid.uuid4().hex,
|
"id": 'backup-id-' + uuid.uuid4().hex,
|
||||||
|
"encryption_key_id": None,
|
||||||
|
"fail_reason": "Service not found for creating backup.",
|
||||||
|
"has_dependent_backups": False,
|
||||||
|
"is_incremental": False,
|
||||||
|
"metadata": {},
|
||||||
|
"project_id": uuid.uuid4().hex,
|
||||||
|
"updated_at": 'time-' + uuid.uuid4().hex,
|
||||||
|
"user_id": uuid.uuid4().hex,
|
||||||
"name": 'backup-name-' + uuid.uuid4().hex,
|
"name": 'backup-name-' + uuid.uuid4().hex,
|
||||||
"volume_id": 'volume-id-' + uuid.uuid4().hex,
|
"volume_id": 'volume-id-' + uuid.uuid4().hex,
|
||||||
"snapshot_id": 'snapshot-id' + uuid.uuid4().hex,
|
"snapshot_id": 'snapshot-id' + uuid.uuid4().hex,
|
||||||
@ -558,7 +569,7 @@ def create_one_backup(attrs=None):
|
|||||||
# Overwrite default attributes.
|
# Overwrite default attributes.
|
||||||
backup_info.update(attrs)
|
backup_info.update(attrs)
|
||||||
|
|
||||||
backup = fakes.FakeResource(info=copy.deepcopy(backup_info), loaded=True)
|
backup = _backup.Backup(**backup_info)
|
||||||
return backup
|
return backup
|
||||||
|
|
||||||
|
|
||||||
|
@ -16,14 +16,14 @@ from unittest import mock
|
|||||||
from unittest.mock import call
|
from unittest.mock import call
|
||||||
|
|
||||||
from cinderclient import api_versions
|
from cinderclient import api_versions
|
||||||
|
from openstack import utils as sdk_utils
|
||||||
from osc_lib import exceptions
|
from osc_lib import exceptions
|
||||||
from osc_lib import utils
|
|
||||||
|
|
||||||
from openstackclient.tests.unit.volume.v2 import fakes as volume_fakes
|
from openstackclient.tests.unit.volume.v2 import fakes as volume_fakes
|
||||||
from openstackclient.volume.v2 import volume_backup
|
from openstackclient.volume.v2 import volume_backup
|
||||||
|
|
||||||
|
|
||||||
class TestBackup(volume_fakes.TestVolume):
|
class TestBackupLegacy(volume_fakes.TestVolume):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super().setUp()
|
super().setUp()
|
||||||
|
|
||||||
@ -37,6 +37,31 @@ class TestBackup(volume_fakes.TestVolume):
|
|||||||
self.restores_mock.reset_mock()
|
self.restores_mock.reset_mock()
|
||||||
|
|
||||||
|
|
||||||
|
class TestBackup(volume_fakes.TestVolume):
|
||||||
|
def setUp(self):
|
||||||
|
super().setUp()
|
||||||
|
|
||||||
|
self.app.client_manager.sdk_connection = mock.Mock()
|
||||||
|
self.app.client_manager.sdk_connection.volume = mock.Mock()
|
||||||
|
self.sdk_client = self.app.client_manager.sdk_connection.volume
|
||||||
|
patcher = mock.patch.object(
|
||||||
|
sdk_utils, 'supports_microversion', return_value=True
|
||||||
|
)
|
||||||
|
self.addCleanup(patcher.stop)
|
||||||
|
self.supports_microversion_mock = patcher.start()
|
||||||
|
self._set_mock_microversion(
|
||||||
|
self.app.client_manager.volume.api_version.get_string()
|
||||||
|
)
|
||||||
|
|
||||||
|
def _set_mock_microversion(self, mock_v):
|
||||||
|
"""Set a specific microversion for the mock supports_microversion()."""
|
||||||
|
self.supports_microversion_mock.reset_mock(return_value=True)
|
||||||
|
self.supports_microversion_mock.side_effect = (
|
||||||
|
lambda _, v: api_versions.APIVersion(v)
|
||||||
|
<= api_versions.APIVersion(mock_v)
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class TestBackupCreate(TestBackup):
|
class TestBackupCreate(TestBackup):
|
||||||
volume = volume_fakes.create_one_volume()
|
volume = volume_fakes.create_one_volume()
|
||||||
snapshot = volume_fakes.create_one_snapshot()
|
snapshot = volume_fakes.create_one_snapshot()
|
||||||
@ -45,36 +70,22 @@ class TestBackupCreate(TestBackup):
|
|||||||
)
|
)
|
||||||
|
|
||||||
columns = (
|
columns = (
|
||||||
'availability_zone',
|
|
||||||
'container',
|
|
||||||
'description',
|
|
||||||
'id',
|
'id',
|
||||||
'name',
|
'name',
|
||||||
'object_count',
|
|
||||||
'size',
|
|
||||||
'snapshot_id',
|
|
||||||
'status',
|
|
||||||
'volume_id',
|
'volume_id',
|
||||||
)
|
)
|
||||||
data = (
|
data = (
|
||||||
new_backup.availability_zone,
|
|
||||||
new_backup.container,
|
|
||||||
new_backup.description,
|
|
||||||
new_backup.id,
|
new_backup.id,
|
||||||
new_backup.name,
|
new_backup.name,
|
||||||
new_backup.object_count,
|
|
||||||
new_backup.size,
|
|
||||||
new_backup.snapshot_id,
|
|
||||||
new_backup.status,
|
|
||||||
new_backup.volume_id,
|
new_backup.volume_id,
|
||||||
)
|
)
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super().setUp()
|
super().setUp()
|
||||||
|
|
||||||
self.volumes_mock.get.return_value = self.volume
|
self.sdk_client.find_volume.return_value = self.volume
|
||||||
self.snapshots_mock.get.return_value = self.snapshot
|
self.sdk_client.find_snapshot.return_value = self.snapshot
|
||||||
self.backups_mock.create.return_value = self.new_backup
|
self.sdk_client.create_backup.return_value = self.new_backup
|
||||||
|
|
||||||
# Get the command object to test
|
# Get the command object to test
|
||||||
self.cmd = volume_backup.CreateVolumeBackup(self.app, None)
|
self.cmd = volume_backup.CreateVolumeBackup(self.app, None)
|
||||||
@ -106,8 +117,8 @@ class TestBackupCreate(TestBackup):
|
|||||||
|
|
||||||
columns, data = self.cmd.take_action(parsed_args)
|
columns, data = self.cmd.take_action(parsed_args)
|
||||||
|
|
||||||
self.backups_mock.create.assert_called_with(
|
self.sdk_client.create_backup.assert_called_with(
|
||||||
self.new_backup.volume_id,
|
volume_id=self.new_backup.volume_id,
|
||||||
container=self.new_backup.container,
|
container=self.new_backup.container,
|
||||||
name=self.new_backup.name,
|
name=self.new_backup.name,
|
||||||
description=self.new_backup.description,
|
description=self.new_backup.description,
|
||||||
@ -119,9 +130,7 @@ class TestBackupCreate(TestBackup):
|
|||||||
self.assertEqual(self.data, data)
|
self.assertEqual(self.data, data)
|
||||||
|
|
||||||
def test_backup_create_with_properties(self):
|
def test_backup_create_with_properties(self):
|
||||||
self.app.client_manager.volume.api_version = api_versions.APIVersion(
|
self._set_mock_microversion('3.43')
|
||||||
'3.43'
|
|
||||||
)
|
|
||||||
|
|
||||||
arglist = [
|
arglist = [
|
||||||
"--property",
|
"--property",
|
||||||
@ -138,8 +147,8 @@ class TestBackupCreate(TestBackup):
|
|||||||
|
|
||||||
columns, data = self.cmd.take_action(parsed_args)
|
columns, data = self.cmd.take_action(parsed_args)
|
||||||
|
|
||||||
self.backups_mock.create.assert_called_with(
|
self.sdk_client.create_backup.assert_called_with(
|
||||||
self.new_backup.volume_id,
|
volume_id=self.new_backup.volume_id,
|
||||||
container=None,
|
container=None,
|
||||||
name=None,
|
name=None,
|
||||||
description=None,
|
description=None,
|
||||||
@ -151,9 +160,7 @@ class TestBackupCreate(TestBackup):
|
|||||||
self.assertEqual(self.data, data)
|
self.assertEqual(self.data, data)
|
||||||
|
|
||||||
def test_backup_create_with_properties_pre_v343(self):
|
def test_backup_create_with_properties_pre_v343(self):
|
||||||
self.app.client_manager.volume.api_version = api_versions.APIVersion(
|
self._set_mock_microversion('3.42')
|
||||||
'3.42'
|
|
||||||
)
|
|
||||||
|
|
||||||
arglist = [
|
arglist = [
|
||||||
"--property",
|
"--property",
|
||||||
@ -174,9 +181,7 @@ class TestBackupCreate(TestBackup):
|
|||||||
self.assertIn("--os-volume-api-version 3.43 or greater", str(exc))
|
self.assertIn("--os-volume-api-version 3.43 or greater", str(exc))
|
||||||
|
|
||||||
def test_backup_create_with_availability_zone(self):
|
def test_backup_create_with_availability_zone(self):
|
||||||
self.app.client_manager.volume.api_version = api_versions.APIVersion(
|
self._set_mock_microversion('3.51')
|
||||||
'3.51'
|
|
||||||
)
|
|
||||||
|
|
||||||
arglist = [
|
arglist = [
|
||||||
"--availability-zone",
|
"--availability-zone",
|
||||||
@ -191,8 +196,8 @@ class TestBackupCreate(TestBackup):
|
|||||||
|
|
||||||
columns, data = self.cmd.take_action(parsed_args)
|
columns, data = self.cmd.take_action(parsed_args)
|
||||||
|
|
||||||
self.backups_mock.create.assert_called_with(
|
self.sdk_client.create_backup.assert_called_with(
|
||||||
self.new_backup.volume_id,
|
volume_id=self.new_backup.volume_id,
|
||||||
container=None,
|
container=None,
|
||||||
name=None,
|
name=None,
|
||||||
description=None,
|
description=None,
|
||||||
@ -204,9 +209,7 @@ class TestBackupCreate(TestBackup):
|
|||||||
self.assertEqual(self.data, data)
|
self.assertEqual(self.data, data)
|
||||||
|
|
||||||
def test_backup_create_with_availability_zone_pre_v351(self):
|
def test_backup_create_with_availability_zone_pre_v351(self):
|
||||||
self.app.client_manager.volume.api_version = api_versions.APIVersion(
|
self._set_mock_microversion('3.50')
|
||||||
'3.50'
|
|
||||||
)
|
|
||||||
|
|
||||||
arglist = [
|
arglist = [
|
||||||
"--availability-zone",
|
"--availability-zone",
|
||||||
@ -241,8 +244,8 @@ class TestBackupCreate(TestBackup):
|
|||||||
|
|
||||||
columns, data = self.cmd.take_action(parsed_args)
|
columns, data = self.cmd.take_action(parsed_args)
|
||||||
|
|
||||||
self.backups_mock.create.assert_called_with(
|
self.sdk_client.create_backup.assert_called_with(
|
||||||
self.new_backup.volume_id,
|
volume_id=self.new_backup.volume_id,
|
||||||
container=self.new_backup.container,
|
container=self.new_backup.container,
|
||||||
name=None,
|
name=None,
|
||||||
description=self.new_backup.description,
|
description=self.new_backup.description,
|
||||||
@ -259,8 +262,8 @@ class TestBackupDelete(TestBackup):
|
|||||||
def setUp(self):
|
def setUp(self):
|
||||||
super().setUp()
|
super().setUp()
|
||||||
|
|
||||||
self.backups_mock.get = volume_fakes.get_backups(self.backups)
|
self.sdk_client.find_backup = volume_fakes.get_backups(self.backups)
|
||||||
self.backups_mock.delete.return_value = None
|
self.sdk_client.delete_backup.return_value = None
|
||||||
|
|
||||||
# Get the command object to mock
|
# Get the command object to mock
|
||||||
self.cmd = volume_backup.DeleteVolumeBackup(self.app, None)
|
self.cmd = volume_backup.DeleteVolumeBackup(self.app, None)
|
||||||
@ -272,7 +275,9 @@ class TestBackupDelete(TestBackup):
|
|||||||
|
|
||||||
result = self.cmd.take_action(parsed_args)
|
result = self.cmd.take_action(parsed_args)
|
||||||
|
|
||||||
self.backups_mock.delete.assert_called_with(self.backups[0].id, False)
|
self.sdk_client.delete_backup.assert_called_with(
|
||||||
|
self.backups[0].id, ignore_missing=False, force=False
|
||||||
|
)
|
||||||
self.assertIsNone(result)
|
self.assertIsNone(result)
|
||||||
|
|
||||||
def test_backup_delete_with_force(self):
|
def test_backup_delete_with_force(self):
|
||||||
@ -285,7 +290,9 @@ class TestBackupDelete(TestBackup):
|
|||||||
|
|
||||||
result = self.cmd.take_action(parsed_args)
|
result = self.cmd.take_action(parsed_args)
|
||||||
|
|
||||||
self.backups_mock.delete.assert_called_with(self.backups[0].id, True)
|
self.sdk_client.delete_backup.assert_called_with(
|
||||||
|
self.backups[0].id, ignore_missing=False, force=True
|
||||||
|
)
|
||||||
self.assertIsNone(result)
|
self.assertIsNone(result)
|
||||||
|
|
||||||
def test_delete_multiple_backups(self):
|
def test_delete_multiple_backups(self):
|
||||||
@ -301,8 +308,8 @@ class TestBackupDelete(TestBackup):
|
|||||||
|
|
||||||
calls = []
|
calls = []
|
||||||
for b in self.backups:
|
for b in self.backups:
|
||||||
calls.append(call(b.id, False))
|
calls.append(call(b.id, ignore_missing=False, force=False))
|
||||||
self.backups_mock.delete.assert_has_calls(calls)
|
self.sdk_client.delete_backup.assert_has_calls(calls)
|
||||||
self.assertIsNone(result)
|
self.assertIsNone(result)
|
||||||
|
|
||||||
def test_delete_multiple_backups_with_exception(self):
|
def test_delete_multiple_backups_with_exception(self):
|
||||||
@ -318,7 +325,7 @@ class TestBackupDelete(TestBackup):
|
|||||||
|
|
||||||
find_mock_result = [self.backups[0], exceptions.CommandError]
|
find_mock_result = [self.backups[0], exceptions.CommandError]
|
||||||
with mock.patch.object(
|
with mock.patch.object(
|
||||||
utils, 'find_resource', side_effect=find_mock_result
|
self.sdk_client, 'find_backup', side_effect=find_mock_result
|
||||||
) as find_mock:
|
) as find_mock:
|
||||||
try:
|
try:
|
||||||
self.cmd.take_action(parsed_args)
|
self.cmd.take_action(parsed_args)
|
||||||
@ -326,12 +333,14 @@ class TestBackupDelete(TestBackup):
|
|||||||
except exceptions.CommandError as e:
|
except exceptions.CommandError as e:
|
||||||
self.assertEqual('1 of 2 backups failed to delete.', str(e))
|
self.assertEqual('1 of 2 backups failed to delete.', str(e))
|
||||||
|
|
||||||
find_mock.assert_any_call(self.backups_mock, self.backups[0].id)
|
find_mock.assert_any_call(self.backups[0].id, ignore_missing=False)
|
||||||
find_mock.assert_any_call(self.backups_mock, 'unexist_backup')
|
find_mock.assert_any_call('unexist_backup', ignore_missing=False)
|
||||||
|
|
||||||
self.assertEqual(2, find_mock.call_count)
|
self.assertEqual(2, find_mock.call_count)
|
||||||
self.backups_mock.delete.assert_called_once_with(
|
self.sdk_client.delete_backup.assert_called_once_with(
|
||||||
self.backups[0].id, False
|
self.backups[0].id,
|
||||||
|
ignore_missing=False,
|
||||||
|
force=False,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -383,10 +392,11 @@ class TestBackupList(TestBackup):
|
|||||||
def setUp(self):
|
def setUp(self):
|
||||||
super().setUp()
|
super().setUp()
|
||||||
|
|
||||||
self.volumes_mock.list.return_value = [self.volume]
|
self.sdk_client.volumes.return_value = [self.volume]
|
||||||
self.backups_mock.list.return_value = self.backups
|
self.sdk_client.backups.return_value = self.backups
|
||||||
self.volumes_mock.get.return_value = self.volume
|
self.sdk_client.find_volume.return_value = self.volume
|
||||||
self.backups_mock.get.return_value = self.backups[0]
|
self.sdk_client.find_backup.return_value = self.backups[0]
|
||||||
|
|
||||||
# Get the command to test
|
# Get the command to test
|
||||||
self.cmd = volume_backup.ListVolumeBackup(self.app, None)
|
self.cmd = volume_backup.ListVolumeBackup(self.app, None)
|
||||||
|
|
||||||
@ -405,16 +415,13 @@ class TestBackupList(TestBackup):
|
|||||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||||
columns, data = self.cmd.take_action(parsed_args)
|
columns, data = self.cmd.take_action(parsed_args)
|
||||||
|
|
||||||
search_opts = {
|
self.sdk_client.find_volume.assert_not_called()
|
||||||
"name": None,
|
self.sdk_client.find_backup.assert_not_called()
|
||||||
"status": None,
|
self.sdk_client.backups.assert_called_with(
|
||||||
"volume_id": None,
|
name=None,
|
||||||
'all_tenants': False,
|
status=None,
|
||||||
}
|
volume_id=None,
|
||||||
self.volumes_mock.get.assert_not_called()
|
all_tenants=False,
|
||||||
self.backups_mock.get.assert_not_called()
|
|
||||||
self.backups_mock.list.assert_called_with(
|
|
||||||
search_opts=search_opts,
|
|
||||||
marker=None,
|
marker=None,
|
||||||
limit=None,
|
limit=None,
|
||||||
)
|
)
|
||||||
@ -449,16 +456,17 @@ class TestBackupList(TestBackup):
|
|||||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||||
columns, data = self.cmd.take_action(parsed_args)
|
columns, data = self.cmd.take_action(parsed_args)
|
||||||
|
|
||||||
search_opts = {
|
self.sdk_client.find_volume.assert_called_once_with(
|
||||||
"name": self.backups[0].name,
|
self.volume.id, ignore_missing=False
|
||||||
"status": "error",
|
)
|
||||||
"volume_id": self.volume.id,
|
self.sdk_client.find_backup.assert_called_once_with(
|
||||||
'all_tenants': True,
|
self.backups[0].id, ignore_missing=False
|
||||||
}
|
)
|
||||||
self.volumes_mock.get.assert_called_once_with(self.volume.id)
|
self.sdk_client.backups.assert_called_with(
|
||||||
self.backups_mock.get.assert_called_once_with(self.backups[0].id)
|
name=self.backups[0].name,
|
||||||
self.backups_mock.list.assert_called_with(
|
status="error",
|
||||||
search_opts=search_opts,
|
volume_id=self.volume.id,
|
||||||
|
all_tenants=True,
|
||||||
marker=self.backups[0].id,
|
marker=self.backups[0].id,
|
||||||
limit=3,
|
limit=3,
|
||||||
)
|
)
|
||||||
@ -475,19 +483,20 @@ class TestBackupRestore(TestBackup):
|
|||||||
def setUp(self):
|
def setUp(self):
|
||||||
super().setUp()
|
super().setUp()
|
||||||
|
|
||||||
self.backups_mock.get.return_value = self.backup
|
self.sdk_client.find_backup.return_value = self.backup
|
||||||
self.volumes_mock.get.return_value = self.volume
|
self.sdk_client.find_volume.return_value = self.volume
|
||||||
self.restores_mock.restore.return_value = (
|
self.sdk_client.restore_backup.return_value = (
|
||||||
volume_fakes.create_one_volume(
|
volume_fakes.create_one_volume(
|
||||||
{'id': self.volume['id']},
|
{'id': self.volume['id']},
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
# Get the command object to mock
|
# Get the command object to mock
|
||||||
self.cmd = volume_backup.RestoreVolumeBackup(self.app, None)
|
self.cmd = volume_backup.RestoreVolumeBackup(self.app, None)
|
||||||
|
|
||||||
def test_backup_restore(self):
|
def test_backup_restore(self):
|
||||||
self.volumes_mock.get.side_effect = exceptions.CommandError()
|
self.sdk_client.find_volume.side_effect = exceptions.CommandError()
|
||||||
self.volumes_mock.find.side_effect = exceptions.CommandError()
|
# self.sdk_client.side_effect = exceptions.CommandError()
|
||||||
arglist = [self.backup.id]
|
arglist = [self.backup.id]
|
||||||
verifylist = [
|
verifylist = [
|
||||||
("backup", self.backup.id),
|
("backup", self.backup.id),
|
||||||
@ -496,16 +505,16 @@ class TestBackupRestore(TestBackup):
|
|||||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||||
|
|
||||||
result = self.cmd.take_action(parsed_args)
|
result = self.cmd.take_action(parsed_args)
|
||||||
self.restores_mock.restore.assert_called_with(
|
self.sdk_client.restore_backup.assert_called_with(
|
||||||
self.backup.id,
|
self.backup.id,
|
||||||
None,
|
volume_id=None,
|
||||||
None,
|
name=None,
|
||||||
)
|
)
|
||||||
self.assertIsNotNone(result)
|
self.assertIsNotNone(result)
|
||||||
|
|
||||||
def test_backup_restore_with_volume(self):
|
def test_backup_restore_with_volume(self):
|
||||||
self.volumes_mock.get.side_effect = exceptions.CommandError()
|
self.sdk_client.find_volume.side_effect = exceptions.CommandError()
|
||||||
self.volumes_mock.find.side_effect = exceptions.CommandError()
|
# self.volumes_mock.find.side_effect = exceptions.CommandError()
|
||||||
arglist = [
|
arglist = [
|
||||||
self.backup.id,
|
self.backup.id,
|
||||||
self.backup.volume_id,
|
self.backup.volume_id,
|
||||||
@ -517,10 +526,10 @@ class TestBackupRestore(TestBackup):
|
|||||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||||
|
|
||||||
result = self.cmd.take_action(parsed_args)
|
result = self.cmd.take_action(parsed_args)
|
||||||
self.restores_mock.restore.assert_called_with(
|
self.sdk_client.restore_backup.assert_called_with(
|
||||||
self.backup.id,
|
self.backup.id,
|
||||||
None,
|
volume_id=None,
|
||||||
self.backup.volume_id,
|
name=self.backup.volume_id,
|
||||||
)
|
)
|
||||||
self.assertIsNotNone(result)
|
self.assertIsNotNone(result)
|
||||||
|
|
||||||
@ -538,10 +547,10 @@ class TestBackupRestore(TestBackup):
|
|||||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||||
|
|
||||||
result = self.cmd.take_action(parsed_args)
|
result = self.cmd.take_action(parsed_args)
|
||||||
self.restores_mock.restore.assert_called_with(
|
self.sdk_client.restore_backup.assert_called_with(
|
||||||
self.backup.id,
|
self.backup.id,
|
||||||
self.volume.id,
|
volume_id=self.volume.id,
|
||||||
None,
|
name=None,
|
||||||
)
|
)
|
||||||
self.assertIsNotNone(result)
|
self.assertIsNotNone(result)
|
||||||
|
|
||||||
@ -563,7 +572,7 @@ class TestBackupRestore(TestBackup):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class TestBackupSet(TestBackup):
|
class TestBackupSet(TestBackupLegacy):
|
||||||
backup = volume_fakes.create_one_backup(
|
backup = volume_fakes.create_one_backup(
|
||||||
attrs={'metadata': {'wow': 'cool'}},
|
attrs={'metadata': {'wow': 'cool'}},
|
||||||
)
|
)
|
||||||
@ -793,7 +802,7 @@ class TestBackupSet(TestBackup):
|
|||||||
self.assertIn("--os-volume-api-version 3.43 or greater", str(exc))
|
self.assertIn("--os-volume-api-version 3.43 or greater", str(exc))
|
||||||
|
|
||||||
|
|
||||||
class TestBackupUnset(TestBackup):
|
class TestBackupUnset(TestBackupLegacy):
|
||||||
backup = volume_fakes.create_one_backup(
|
backup = volume_fakes.create_one_backup(
|
||||||
attrs={'metadata': {'foo': 'bar'}},
|
attrs={'metadata': {'foo': 'bar'}},
|
||||||
)
|
)
|
||||||
@ -859,34 +868,54 @@ class TestBackupShow(TestBackup):
|
|||||||
backup = volume_fakes.create_one_backup()
|
backup = volume_fakes.create_one_backup()
|
||||||
|
|
||||||
columns = (
|
columns = (
|
||||||
'availability_zone',
|
"availability_zone",
|
||||||
'container',
|
"container",
|
||||||
'description',
|
"created_at",
|
||||||
'id',
|
"data_timestamp",
|
||||||
'name',
|
"description",
|
||||||
'object_count',
|
"encryption_key_id",
|
||||||
'size',
|
"fail_reason",
|
||||||
'snapshot_id',
|
"has_dependent_backups",
|
||||||
'status',
|
"id",
|
||||||
'volume_id',
|
"is_incremental",
|
||||||
|
"metadata",
|
||||||
|
"name",
|
||||||
|
"object_count",
|
||||||
|
"project_id",
|
||||||
|
"size",
|
||||||
|
"snapshot_id",
|
||||||
|
"status",
|
||||||
|
"updated_at",
|
||||||
|
"user_id",
|
||||||
|
"volume_id",
|
||||||
)
|
)
|
||||||
data = (
|
data = (
|
||||||
backup.availability_zone,
|
backup.availability_zone,
|
||||||
backup.container,
|
backup.container,
|
||||||
|
backup.created_at,
|
||||||
|
backup.data_timestamp,
|
||||||
backup.description,
|
backup.description,
|
||||||
|
backup.encryption_key_id,
|
||||||
|
backup.fail_reason,
|
||||||
|
backup.has_dependent_backups,
|
||||||
backup.id,
|
backup.id,
|
||||||
|
backup.is_incremental,
|
||||||
|
backup.metadata,
|
||||||
backup.name,
|
backup.name,
|
||||||
backup.object_count,
|
backup.object_count,
|
||||||
|
backup.project_id,
|
||||||
backup.size,
|
backup.size,
|
||||||
backup.snapshot_id,
|
backup.snapshot_id,
|
||||||
backup.status,
|
backup.status,
|
||||||
|
backup.updated_at,
|
||||||
|
backup.user_id,
|
||||||
backup.volume_id,
|
backup.volume_id,
|
||||||
)
|
)
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super().setUp()
|
super().setUp()
|
||||||
|
|
||||||
self.backups_mock.get.return_value = self.backup
|
self.sdk_client.get_backup.return_value = self.backup
|
||||||
# Get the command object to test
|
# Get the command object to test
|
||||||
self.cmd = volume_backup.ShowVolumeBackup(self.app, None)
|
self.cmd = volume_backup.ShowVolumeBackup(self.app, None)
|
||||||
|
|
||||||
@ -896,7 +925,7 @@ class TestBackupShow(TestBackup):
|
|||||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||||
|
|
||||||
columns, data = self.cmd.take_action(parsed_args)
|
columns, data = self.cmd.take_action(parsed_args)
|
||||||
self.backups_mock.get.assert_called_with(self.backup.id)
|
self.sdk_client.get_backup.assert_called_with(self.backup.id)
|
||||||
|
|
||||||
self.assertEqual(self.columns, columns)
|
self.assertEqual(self.columns, columns)
|
||||||
self.assertEqual(self.data, data)
|
self.assertEqual(self.data, data)
|
||||||
|
@ -20,6 +20,7 @@ import logging
|
|||||||
|
|
||||||
from cinderclient import api_versions
|
from cinderclient import api_versions
|
||||||
from cliff import columns as cliff_columns
|
from cliff import columns as cliff_columns
|
||||||
|
from openstack import utils as sdk_utils
|
||||||
from osc_lib.cli import parseractions
|
from osc_lib.cli import parseractions
|
||||||
from osc_lib.command import command
|
from osc_lib.command import command
|
||||||
from osc_lib import exceptions
|
from osc_lib import exceptions
|
||||||
@ -126,23 +127,23 @@ class CreateVolumeBackup(command.ShowOne):
|
|||||||
return parser
|
return parser
|
||||||
|
|
||||||
def take_action(self, parsed_args):
|
def take_action(self, parsed_args):
|
||||||
volume_client = self.app.client_manager.volume
|
volume_client = self.app.client_manager.sdk_connection.volume
|
||||||
|
|
||||||
volume_id = utils.find_resource(
|
volume_id = volume_client.find_volume(
|
||||||
volume_client.volumes,
|
|
||||||
parsed_args.volume,
|
parsed_args.volume,
|
||||||
|
ignore_missing=False,
|
||||||
).id
|
).id
|
||||||
|
|
||||||
kwargs = {}
|
kwargs = {}
|
||||||
|
|
||||||
if parsed_args.snapshot:
|
if parsed_args.snapshot:
|
||||||
kwargs['snapshot_id'] = utils.find_resource(
|
kwargs['snapshot_id'] = volume_client.find_snapshot(
|
||||||
volume_client.volume_snapshots,
|
|
||||||
parsed_args.snapshot,
|
parsed_args.snapshot,
|
||||||
|
ignore_missing=False,
|
||||||
).id
|
).id
|
||||||
|
|
||||||
if parsed_args.properties:
|
if parsed_args.properties:
|
||||||
if volume_client.api_version < api_versions.APIVersion('3.43'):
|
if not sdk_utils.supports_microversion(volume_client, '3.43'):
|
||||||
msg = _(
|
msg = _(
|
||||||
'--os-volume-api-version 3.43 or greater is required to '
|
'--os-volume-api-version 3.43 or greater is required to '
|
||||||
'support the --property option'
|
'support the --property option'
|
||||||
@ -152,7 +153,7 @@ class CreateVolumeBackup(command.ShowOne):
|
|||||||
kwargs['metadata'] = parsed_args.properties
|
kwargs['metadata'] = parsed_args.properties
|
||||||
|
|
||||||
if parsed_args.availability_zone:
|
if parsed_args.availability_zone:
|
||||||
if volume_client.api_version < api_versions.APIVersion('3.51'):
|
if not sdk_utils.supports_microversion(volume_client, '3.51'):
|
||||||
msg = _(
|
msg = _(
|
||||||
'--os-volume-api-version 3.51 or greater is required to '
|
'--os-volume-api-version 3.51 or greater is required to '
|
||||||
'support the --availability-zone option'
|
'support the --availability-zone option'
|
||||||
@ -161,8 +162,13 @@ class CreateVolumeBackup(command.ShowOne):
|
|||||||
|
|
||||||
kwargs['availability_zone'] = parsed_args.availability_zone
|
kwargs['availability_zone'] = parsed_args.availability_zone
|
||||||
|
|
||||||
backup = volume_client.backups.create(
|
columns = (
|
||||||
volume_id,
|
"id",
|
||||||
|
"name",
|
||||||
|
"volume_id",
|
||||||
|
)
|
||||||
|
backup = volume_client.create_backup(
|
||||||
|
volume_id=volume_id,
|
||||||
container=parsed_args.container,
|
container=parsed_args.container,
|
||||||
name=parsed_args.name,
|
name=parsed_args.name,
|
||||||
description=parsed_args.description,
|
description=parsed_args.description,
|
||||||
@ -170,8 +176,8 @@ class CreateVolumeBackup(command.ShowOne):
|
|||||||
incremental=parsed_args.incremental,
|
incremental=parsed_args.incremental,
|
||||||
**kwargs,
|
**kwargs,
|
||||||
)
|
)
|
||||||
backup._info.pop("links", None)
|
data = utils.get_dict_properties(backup, columns)
|
||||||
return zip(*sorted(backup._info.items()))
|
return (columns, data)
|
||||||
|
|
||||||
|
|
||||||
class DeleteVolumeBackup(command.Command):
|
class DeleteVolumeBackup(command.Command):
|
||||||
@ -194,16 +200,19 @@ class DeleteVolumeBackup(command.Command):
|
|||||||
return parser
|
return parser
|
||||||
|
|
||||||
def take_action(self, parsed_args):
|
def take_action(self, parsed_args):
|
||||||
volume_client = self.app.client_manager.volume
|
volume_client = self.app.client_manager.sdk_connection.volume
|
||||||
result = 0
|
result = 0
|
||||||
|
|
||||||
for i in parsed_args.backups:
|
for i in parsed_args.backups:
|
||||||
try:
|
try:
|
||||||
backup_id = utils.find_resource(
|
backup_id = volume_client.find_backup(
|
||||||
volume_client.backups,
|
i, ignore_missing=False
|
||||||
i,
|
|
||||||
).id
|
).id
|
||||||
volume_client.backups.delete(backup_id, parsed_args.force)
|
volume_client.delete_backup(
|
||||||
|
backup_id,
|
||||||
|
ignore_missing=False,
|
||||||
|
force=parsed_args.force,
|
||||||
|
)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
result += 1
|
result += 1
|
||||||
LOG.error(
|
LOG.error(
|
||||||
@ -298,7 +307,7 @@ class ListVolumeBackup(command.Lister):
|
|||||||
return parser
|
return parser
|
||||||
|
|
||||||
def take_action(self, parsed_args):
|
def take_action(self, parsed_args):
|
||||||
volume_client = self.app.client_manager.volume
|
volume_client = self.app.client_manager.sdk_connection.volume
|
||||||
|
|
||||||
columns = ('id', 'name', 'description', 'status', 'size')
|
columns = ('id', 'name', 'description', 'status', 'size')
|
||||||
column_headers = ('ID', 'Name', 'Description', 'Status', 'Size')
|
column_headers = ('ID', 'Name', 'Description', 'Status', 'Size')
|
||||||
@ -309,7 +318,7 @@ class ListVolumeBackup(command.Lister):
|
|||||||
# Cache the volume list
|
# Cache the volume list
|
||||||
volume_cache = {}
|
volume_cache = {}
|
||||||
try:
|
try:
|
||||||
for s in volume_client.volumes.list():
|
for s in volume_client.volumes():
|
||||||
volume_cache[s.id] = s
|
volume_cache[s.id] = s
|
||||||
except Exception:
|
except Exception:
|
||||||
# Just forget it if there's any trouble
|
# Just forget it if there's any trouble
|
||||||
@ -322,9 +331,9 @@ class ListVolumeBackup(command.Lister):
|
|||||||
filter_volume_id = None
|
filter_volume_id = None
|
||||||
if parsed_args.volume:
|
if parsed_args.volume:
|
||||||
try:
|
try:
|
||||||
filter_volume_id = utils.find_resource(
|
filter_volume_id = volume_client.find_volume(
|
||||||
volume_client.volumes,
|
|
||||||
parsed_args.volume,
|
parsed_args.volume,
|
||||||
|
ignore_missing=False,
|
||||||
).id
|
).id
|
||||||
except exceptions.CommandError:
|
except exceptions.CommandError:
|
||||||
# Volume with that ID does not exist, but search for backups
|
# Volume with that ID does not exist, but search for backups
|
||||||
@ -338,19 +347,16 @@ class ListVolumeBackup(command.Lister):
|
|||||||
|
|
||||||
marker_backup_id = None
|
marker_backup_id = None
|
||||||
if parsed_args.marker:
|
if parsed_args.marker:
|
||||||
marker_backup_id = utils.find_resource(
|
marker_backup_id = volume_client.find_backup(
|
||||||
volume_client.backups,
|
|
||||||
parsed_args.marker,
|
parsed_args.marker,
|
||||||
|
ignore_missing=False,
|
||||||
).id
|
).id
|
||||||
|
|
||||||
search_opts = {
|
data = volume_client.backups(
|
||||||
'name': parsed_args.name,
|
name=parsed_args.name,
|
||||||
'status': parsed_args.status,
|
status=parsed_args.status,
|
||||||
'volume_id': filter_volume_id,
|
volume_id=filter_volume_id,
|
||||||
'all_tenants': parsed_args.all_projects,
|
all_tenants=parsed_args.all_projects,
|
||||||
}
|
|
||||||
data = volume_client.backups.list(
|
|
||||||
search_opts=search_opts,
|
|
||||||
marker=marker_backup_id,
|
marker=marker_backup_id,
|
||||||
limit=parsed_args.limit,
|
limit=parsed_args.limit,
|
||||||
)
|
)
|
||||||
@ -399,16 +405,19 @@ class RestoreVolumeBackup(command.ShowOne):
|
|||||||
return parser
|
return parser
|
||||||
|
|
||||||
def take_action(self, parsed_args):
|
def take_action(self, parsed_args):
|
||||||
volume_client = self.app.client_manager.volume
|
volume_client = self.app.client_manager.sdk_connection.volume
|
||||||
|
|
||||||
backup = utils.find_resource(volume_client.backups, parsed_args.backup)
|
backup = volume_client.find_backup(
|
||||||
|
parsed_args.backup,
|
||||||
|
ignore_missing=False,
|
||||||
|
)
|
||||||
|
|
||||||
volume_name = None
|
volume_name = None
|
||||||
volume_id = None
|
volume_id = None
|
||||||
try:
|
try:
|
||||||
volume_id = utils.find_resource(
|
volume_id = volume_client.find_volume(
|
||||||
volume_client.volumes,
|
|
||||||
parsed_args.volume,
|
parsed_args.volume,
|
||||||
|
ignore_missing=False,
|
||||||
).id
|
).id
|
||||||
except Exception:
|
except Exception:
|
||||||
volume_name = parsed_args.volume
|
volume_name = parsed_args.volume
|
||||||
@ -422,10 +431,10 @@ class RestoreVolumeBackup(command.ShowOne):
|
|||||||
)
|
)
|
||||||
raise exceptions.CommandError(msg % parsed_args.volume)
|
raise exceptions.CommandError(msg % parsed_args.volume)
|
||||||
|
|
||||||
return volume_client.restores.restore(
|
return volume_client.restore_backup(
|
||||||
backup.id,
|
backup.id,
|
||||||
volume_id,
|
volume_id=volume_id,
|
||||||
volume_name,
|
name=volume_name,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -630,7 +639,29 @@ class ShowVolumeBackup(command.ShowOne):
|
|||||||
return parser
|
return parser
|
||||||
|
|
||||||
def take_action(self, parsed_args):
|
def take_action(self, parsed_args):
|
||||||
volume_client = self.app.client_manager.volume
|
volume_client = self.app.client_manager.sdk_connection.volume
|
||||||
backup = utils.find_resource(volume_client.backups, parsed_args.backup)
|
backup = volume_client.get_backup(parsed_args.backup)
|
||||||
backup._info.pop("links", None)
|
columns = (
|
||||||
return zip(*sorted(backup._info.items()))
|
"availability_zone",
|
||||||
|
"container",
|
||||||
|
"created_at",
|
||||||
|
"data_timestamp",
|
||||||
|
"description",
|
||||||
|
"encryption_key_id",
|
||||||
|
"fail_reason",
|
||||||
|
"has_dependent_backups",
|
||||||
|
"id",
|
||||||
|
"is_incremental",
|
||||||
|
"metadata",
|
||||||
|
"name",
|
||||||
|
"object_count",
|
||||||
|
"project_id",
|
||||||
|
"size",
|
||||||
|
"snapshot_id",
|
||||||
|
"status",
|
||||||
|
"updated_at",
|
||||||
|
"user_id",
|
||||||
|
"volume_id",
|
||||||
|
)
|
||||||
|
data = utils.get_dict_properties(backup, columns)
|
||||||
|
return (columns, data)
|
||||||
|
@ -0,0 +1,10 @@
|
|||||||
|
---
|
||||||
|
features:
|
||||||
|
- |
|
||||||
|
Migrated the following backup commands to SDK:
|
||||||
|
|
||||||
|
* Create Backup
|
||||||
|
* Show Backup
|
||||||
|
* List Backup
|
||||||
|
* Restore Backup
|
||||||
|
* Delete Backup
|
Loading…
Reference in New Issue
Block a user