Skip to content

Commit 524af4a

Browse files
committed
volume: Add missing 'volume backup *' options
Add a couple of missing options to each command: volume backup create --no-incremental --property --availability-zone volume backup set --property Most of these are version dependent so we add the relevant version checks as part of this work. While we're here, we also make the formatting a little easier on the eye in places. Change-Id: I328d5c981cb32b2ee9a4b1bd43aa36b22347ff63 Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
1 parent 0eddab3 commit 524af4a

4 files changed

Lines changed: 337 additions & 54 deletions

File tree

doc/source/cli/data/cinder.csv

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ backup-list,volume backup list,Lists all backups.
1515
backup-reset-state,volume backup set --state,Explicitly updates the backup state.
1616
backup-restore,volume backup restore,Restores a backup.
1717
backup-show,volume backup show,Show backup details.
18-
backup-update,,Updates a backup. (Supported by API versions 3.9 - 3.latest)
18+
backup-update,volume backup set,Updates a backup. (Supported by API versions 3.9 - 3.latest)
1919
cgsnapshot-create,consistency group snapshot create,Creates a cgsnapshot.
2020
cgsnapshot-delete,consistency group snapshot delete,Removes one or more cgsnapshots.
2121
cgsnapshot-list,consistency group snapshot list,Lists all cgsnapshots.

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

Lines changed: 150 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from unittest import mock
1616
from unittest.mock import call
1717

18+
from cinderclient import api_versions
1819
from osc_lib import exceptions
1920
from osc_lib import utils
2021

@@ -114,6 +115,104 @@ def test_backup_create(self):
114115
self.assertEqual(self.columns, columns)
115116
self.assertEqual(self.data, data)
116117

118+
def test_backup_create_with_properties(self):
119+
self.app.client_manager.volume.api_version = \
120+
api_versions.APIVersion('3.43')
121+
122+
arglist = [
123+
"--property", "foo=bar",
124+
"--property", "wow=much-cool",
125+
self.new_backup.volume_id,
126+
]
127+
verifylist = [
128+
("properties", {"foo": "bar", "wow": "much-cool"}),
129+
("volume", self.new_backup.volume_id),
130+
]
131+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
132+
133+
columns, data = self.cmd.take_action(parsed_args)
134+
135+
self.backups_mock.create.assert_called_with(
136+
self.new_backup.volume_id,
137+
container=None,
138+
name=None,
139+
description=None,
140+
force=False,
141+
incremental=False,
142+
metadata={"foo": "bar", "wow": "much-cool"},
143+
)
144+
self.assertEqual(self.columns, columns)
145+
self.assertEqual(self.data, data)
146+
147+
def test_backup_create_with_properties_pre_v343(self):
148+
self.app.client_manager.volume.api_version = \
149+
api_versions.APIVersion('3.42')
150+
151+
arglist = [
152+
"--property", "foo=bar",
153+
"--property", "wow=much-cool",
154+
self.new_backup.volume_id,
155+
]
156+
verifylist = [
157+
("properties", {"foo": "bar", "wow": "much-cool"}),
158+
("volume", self.new_backup.volume_id),
159+
]
160+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
161+
162+
exc = self.assertRaises(
163+
exceptions.CommandError,
164+
self.cmd.take_action,
165+
parsed_args)
166+
self.assertIn("--os-volume-api-version 3.43 or greater", str(exc))
167+
168+
def test_backup_create_with_availability_zone(self):
169+
self.app.client_manager.volume.api_version = \
170+
api_versions.APIVersion('3.51')
171+
172+
arglist = [
173+
"--availability-zone", "my-az",
174+
self.new_backup.volume_id,
175+
]
176+
verifylist = [
177+
("availability_zone", "my-az"),
178+
("volume", self.new_backup.volume_id),
179+
]
180+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
181+
182+
columns, data = self.cmd.take_action(parsed_args)
183+
184+
self.backups_mock.create.assert_called_with(
185+
self.new_backup.volume_id,
186+
container=None,
187+
name=None,
188+
description=None,
189+
force=False,
190+
incremental=False,
191+
availability_zone="my-az",
192+
)
193+
self.assertEqual(self.columns, columns)
194+
self.assertEqual(self.data, data)
195+
196+
def test_backup_create_with_availability_zone_pre_v351(self):
197+
self.app.client_manager.volume.api_version = \
198+
api_versions.APIVersion('3.50')
199+
200+
arglist = [
201+
"--availability-zone", "my-az",
202+
self.new_backup.volume_id,
203+
]
204+
verifylist = [
205+
("availability_zone", "my-az"),
206+
("volume", self.new_backup.volume_id),
207+
]
208+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
209+
210+
exc = self.assertRaises(
211+
exceptions.CommandError,
212+
self.cmd.take_action,
213+
parsed_args)
214+
self.assertIn("--os-volume-api-version 3.51 or greater", str(exc))
215+
117216
def test_backup_create_without_name(self):
118217
arglist = [
119218
"--description", self.new_backup.description,
@@ -136,7 +235,6 @@ def test_backup_create_without_name(self):
136235
description=self.new_backup.description,
137236
force=False,
138237
incremental=False,
139-
snapshot_id=None,
140238
)
141239
self.assertEqual(self.columns, columns)
142240
self.assertEqual(self.data, data)
@@ -240,18 +338,18 @@ class TestBackupList(TestBackup):
240338
backups = volume_fakes.FakeBackup.create_backups(
241339
attrs={'volume_id': volume.name}, count=3)
242340

243-
columns = [
341+
columns = (
244342
'ID',
245343
'Name',
246344
'Description',
247345
'Status',
248346
'Size',
249-
]
250-
columns_long = columns + [
347+
)
348+
columns_long = columns + (
251349
'Availability Zone',
252350
'Volume',
253351
'Container',
254-
]
352+
)
255353

256354
data = []
257355
for b in backups:
@@ -403,6 +501,9 @@ def setUp(self):
403501
self.cmd = volume_backup.SetVolumeBackup(self.app, None)
404502

405503
def test_backup_set_name(self):
504+
self.app.client_manager.volume.api_version = \
505+
api_versions.APIVersion('3.9')
506+
406507
arglist = [
407508
'--name', 'new_name',
408509
self.backup.id,
@@ -420,7 +521,30 @@ def test_backup_set_name(self):
420521
self.backup.id, **{'name': 'new_name'})
421522
self.assertIsNone(result)
422523

524+
def test_backup_set_name_pre_v39(self):
525+
self.app.client_manager.volume.api_version = \
526+
api_versions.APIVersion('3.8')
527+
528+
arglist = [
529+
'--name', 'new_name',
530+
self.backup.id,
531+
]
532+
verifylist = [
533+
('name', 'new_name'),
534+
('backup', self.backup.id),
535+
]
536+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
537+
538+
exc = self.assertRaises(
539+
exceptions.CommandError,
540+
self.cmd.take_action,
541+
parsed_args)
542+
self.assertIn("--os-volume-api-version 3.9 or greater", str(exc))
543+
423544
def test_backup_set_description(self):
545+
self.app.client_manager.volume.api_version = \
546+
api_versions.APIVersion('3.9')
547+
424548
arglist = [
425549
'--description', 'new_description',
426550
self.backup.id,
@@ -444,6 +568,27 @@ def test_backup_set_description(self):
444568
)
445569
self.assertIsNone(result)
446570

571+
def test_backup_set_description_pre_v39(self):
572+
self.app.client_manager.volume.api_version = \
573+
api_versions.APIVersion('3.8')
574+
575+
arglist = [
576+
'--description', 'new_description',
577+
self.backup.id,
578+
]
579+
verifylist = [
580+
('name', None),
581+
('description', 'new_description'),
582+
('backup', self.backup.id),
583+
]
584+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
585+
586+
exc = self.assertRaises(
587+
exceptions.CommandError,
588+
self.cmd.take_action,
589+
parsed_args)
590+
self.assertIn("--os-volume-api-version 3.9 or greater", str(exc))
591+
447592
def test_backup_set_state(self):
448593
arglist = [
449594
'--state', 'error',

0 commit comments

Comments
 (0)