Skip to content

Commit ab6b9dc

Browse files
Jenkinsopenstack-gerrit
authored andcommitted
Merge "Fix unset commands to pass normally when nothing specified"
2 parents 578cd12 + fd876e4 commit ab6b9dc

7 files changed

Lines changed: 571 additions & 5 deletions

File tree

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

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,8 @@ def __init__(self, **kwargs):
449449
self.volume_types.resource_class = fakes.FakeResource(None, {})
450450
self.transfers = mock.Mock()
451451
self.transfers.resource_class = fakes.FakeResource(None, {})
452+
self.volume_snapshots = mock.Mock()
453+
self.volume_snapshots.resource_class = fakes.FakeResource(None, {})
452454
self.auth_token = kwargs['token']
453455
self.management_url = kwargs['endpoint']
454456

@@ -546,3 +548,79 @@ def get_types(types=None, count=2):
546548
types = FakeType.create_types(count)
547549

548550
return mock.Mock(side_effect=types)
551+
552+
553+
class FakeSnapshot(object):
554+
"""Fake one or more snapshot."""
555+
556+
@staticmethod
557+
def create_one_snapshot(attrs=None):
558+
"""Create a fake snapshot.
559+
560+
:param Dictionary attrs:
561+
A dictionary with all attributes
562+
:return:
563+
A FakeResource object with id, name, description, etc.
564+
"""
565+
attrs = attrs or {}
566+
567+
# Set default attributes.
568+
snapshot_info = {
569+
"id": 'snapshot-id-' + uuid.uuid4().hex,
570+
"display_name": 'snapshot-name-' + uuid.uuid4().hex,
571+
"display_description": 'snapshot-description-' + uuid.uuid4().hex,
572+
"size": 10,
573+
"status": "available",
574+
"metadata": {"foo": "bar"},
575+
"created_at": "2015-06-03T18:49:19.000000",
576+
"volume_id": 'vloume-id-' + uuid.uuid4().hex,
577+
}
578+
579+
# Overwrite default attributes.
580+
snapshot_info.update(attrs)
581+
582+
snapshot_method = {'update': None}
583+
584+
snapshot = fakes.FakeResource(
585+
info=copy.deepcopy(snapshot_info),
586+
methods=copy.deepcopy(snapshot_method),
587+
loaded=True)
588+
return snapshot
589+
590+
@staticmethod
591+
def create_snapshots(attrs=None, count=2):
592+
"""Create multiple fake snapshots.
593+
594+
:param Dictionary attrs:
595+
A dictionary with all attributes
596+
:param int count:
597+
The number of snapshots to fake
598+
:return:
599+
A list of FakeResource objects faking the snapshots
600+
"""
601+
snapshots = []
602+
for i in range(0, count):
603+
snapshot = FakeSnapshot.create_one_snapshot(attrs)
604+
snapshots.append(snapshot)
605+
606+
return snapshots
607+
608+
@staticmethod
609+
def get_snapshots(snapshots=None, count=2):
610+
"""Get an iterable MagicMock object with a list of faked snapshots.
611+
612+
If snapshots list is provided, then initialize the Mock object with the
613+
list. Otherwise create one.
614+
615+
:param List volumes:
616+
A list of FakeResource objects faking snapshots
617+
:param Integer count:
618+
The number of snapshots to be faked
619+
:return
620+
An iterable Mock object with side_effect set to a list of faked
621+
snapshots
622+
"""
623+
if snapshots is None:
624+
snapshots = FakeSnapshot.create_snapshots(count)
625+
626+
return mock.Mock(side_effect=snapshots)

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -517,3 +517,16 @@ def test_qos_unset_with_properties(self):
517517
['iops', 'foo']
518518
)
519519
self.assertIsNone(result)
520+
521+
def test_qos_unset_nothing(self):
522+
arglist = [
523+
volume_fakes.qos_id,
524+
]
525+
526+
verifylist = [
527+
('qos_spec', volume_fakes.qos_id),
528+
]
529+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
530+
531+
result = self.cmd.take_action(parsed_args)
532+
self.assertIsNone(result)

0 commit comments

Comments
 (0)