Skip to content

Commit 1c49a1f

Browse files
Huanxuan AoDean Troyer
authored andcommitted
Fix NoneType error for volume snapshot create command
In volume snapshot command, <volume> is the same as <snapshot-name> when --volume is not specified, but <volume> cannot be None, so when <snapshot-name> is not specified (<snapshot-name> is None), a NoneType error appears. So make <snapshot-name> no longer optional, it should be always present. Change-Id: I3d9f10753a8ef601e70816421c160598e2cc811f Closes-bug: #1659894
1 parent bf1f47c commit 1c49a1f

7 files changed

Lines changed: 42 additions & 38 deletions

File tree

doc/source/backwards-incompatible.rst

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,21 @@ Backwards Incompatible Changes
2727
.. * Remove in: <5.0>
2828
.. * Commit: <tbd>
2929
30+
Release 3.10
31+
------------
32+
33+
1. The positional argument ``<snapshot-name>`` of the ``volume snapshot create``
34+
command is no longer optional.
35+
36+
Previously when the ``--volume`` option was
37+
present ``<snapshot-name>`` defaulted to the ``--volume`` value. When the
38+
``--volume`` option is not present now it defaults to the value of
39+
``<snapshot-name>``.
40+
41+
* As of: 3.10
42+
* Bug: 1659894
43+
* Commit: https://review.openstack.org/440497
44+
3045
Release 3.0
3146
-----------
3247

doc/source/command-objects/volume-snapshot.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ Create new volume snapshot
4949
.. _volume_snapshot_create-snapshot-name:
5050
.. describe:: <snapshot-name>
5151
52-
Name of the new snapshot (default to None)
52+
Name of the new snapshot
5353
5454
volume snapshot delete
5555
----------------------

openstackclient/tests/unit/volume/v1/test_snapshot.py

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
from osc_lib import exceptions
1919
from osc_lib import utils
2020

21+
from openstackclient.tests.unit import utils as tests_utils
2122
from openstackclient.tests.unit.volume.v1 import fakes as volume_fakes
2223
from openstackclient.volume.v1 import volume_snapshot
2324

@@ -98,26 +99,17 @@ def test_snapshot_create(self):
9899
def test_snapshot_create_without_name(self):
99100
arglist = [
100101
"--volume", self.new_snapshot.volume_id,
101-
"--description", self.new_snapshot.display_description,
102-
"--force"
103102
]
104103
verifylist = [
105104
("volume", self.new_snapshot.volume_id),
106-
("description", self.new_snapshot.display_description),
107-
("force", True)
108105
]
109-
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
110-
111-
columns, data = self.cmd.take_action(parsed_args)
112-
113-
self.snapshots_mock.create.assert_called_with(
114-
self.new_snapshot.volume_id,
115-
True,
116-
None,
117-
self.new_snapshot.display_description,
106+
self.assertRaises(
107+
tests_utils.ParserException,
108+
self.check_parser,
109+
self.cmd,
110+
arglist,
111+
verifylist,
118112
)
119-
self.assertEqual(self.columns, columns)
120-
self.assertEqual(self.data, data)
121113

122114
def test_snapshot_create_without_volume(self):
123115
arglist = [

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

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
from osc_lib import utils
2121

2222
from openstackclient.tests.unit.identity.v3 import fakes as project_fakes
23+
from openstackclient.tests.unit import utils as tests_utils
2324
from openstackclient.tests.unit.volume.v2 import fakes as volume_fakes
2425
from openstackclient.volume.v2 import volume_snapshot
2526

@@ -107,27 +108,17 @@ def test_snapshot_create(self):
107108
def test_snapshot_create_without_name(self):
108109
arglist = [
109110
"--volume", self.new_snapshot.volume_id,
110-
"--description", self.new_snapshot.description,
111-
"--force"
112111
]
113112
verifylist = [
114113
("volume", self.new_snapshot.volume_id),
115-
("description", self.new_snapshot.description),
116-
("force", True)
117114
]
118-
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
119-
120-
columns, data = self.cmd.take_action(parsed_args)
121-
122-
self.snapshots_mock.create.assert_called_with(
123-
self.new_snapshot.volume_id,
124-
force=True,
125-
name=None,
126-
description=self.new_snapshot.description,
127-
metadata=None,
115+
self.assertRaises(
116+
tests_utils.ParserException,
117+
self.check_parser,
118+
self.cmd,
119+
arglist,
120+
verifylist,
128121
)
129-
self.assertEqual(self.columns, columns)
130-
self.assertEqual(self.data, data)
131122

132123
def test_snapshot_create_without_volume(self):
133124
arglist = [
@@ -156,17 +147,19 @@ def test_snapshot_create_without_volume(self):
156147
self.assertEqual(self.columns, columns)
157148
self.assertEqual(self.data, data)
158149

159-
def test_snapshot_create_without_remote_source(self):
150+
def test_snapshot_create_with_remote_source(self):
160151
arglist = [
161152
'--remote-source', 'source-name=test_source_name',
162153
'--remote-source', 'source-id=test_source_id',
163154
'--volume', self.new_snapshot.volume_id,
155+
self.new_snapshot.name,
164156
]
165157
ref_dict = {'source-name': 'test_source_name',
166158
'source-id': 'test_source_id'}
167159
verifylist = [
168160
('remote_source', ref_dict),
169161
('volume', self.new_snapshot.volume_id),
162+
("snapshot_name", self.new_snapshot.name),
170163
]
171164
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
172165

@@ -175,7 +168,7 @@ def test_snapshot_create_without_remote_source(self):
175168
self.snapshots_mock.manage.assert_called_with(
176169
volume_id=self.new_snapshot.volume_id,
177170
ref=ref_dict,
178-
name=None,
171+
name=self.new_snapshot.name,
179172
description=None,
180173
metadata=None,
181174
)

openstackclient/volume/v1/volume_snapshot.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@ def get_parser(self, prog_name):
3838
parser.add_argument(
3939
'snapshot_name',
4040
metavar='<snapshot-name>',
41-
nargs="?",
42-
help=_('Name of the snapshot (default to None)'),
41+
help=_('Name of the new snapshot'),
4342
)
4443
parser.add_argument(
4544
'--volume',

openstackclient/volume/v2/volume_snapshot.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@ def get_parser(self, prog_name):
3838
parser.add_argument(
3939
"snapshot_name",
4040
metavar="<snapshot-name>",
41-
nargs="?",
42-
help=_("Name of the new snapshot (default to None)")
41+
help=_("Name of the new snapshot"),
4342
)
4443
parser.add_argument(
4544
"--volume",
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
fixes:
3+
- |
4+
Now the positional parameter ``<snapshot-name>`` of ``volume snapshot create``
5+
command is no longer optional, it should be always present.
6+
[Bug `1659894 <https://bugs.launchpad.net/bugs/1659894>`_]

0 commit comments

Comments
 (0)