Skip to content
This repository was archived by the owner on Nov 19, 2018. It is now read-only.

Commit da3d652

Browse files
author
Tang Chen
committed
Define FakeFloatingIP class in tests/compute for nova network commands
"ip floating list" command is not available for Neutron now because the implementation is incorrect. The FloatingIP objects returned from Nova and Neutron network are quite different. So they need different FakeFloatingIP class to do the tests. This patch copies class FakeFloatingIP in tests/network to tests/compute for Nova network tests. Will fix the problem in "ip floating list" command and change FakeFloatingIP in tests/network to fit Neutron network tests. Change-Id: Ia29d257868e0f1dc6cd7cfe3819875e5913f76ec Partial-Bug: 1519502 Partially implements: blueprint neutron-client
1 parent c875380 commit da3d652

2 files changed

Lines changed: 81 additions & 2 deletions

File tree

openstackclient/tests/compute/v2/fakes.py

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,3 +446,82 @@ def create_availability_zones(attrs={}, methods={}, count=2):
446446
availability_zones.append(availability_zone)
447447

448448
return availability_zones
449+
450+
451+
class FakeFloatingIP(object):
452+
"""Fake one or more floating ip."""
453+
454+
@staticmethod
455+
def create_one_floating_ip(attrs={}, methods={}):
456+
"""Create a fake floating ip.
457+
458+
:param Dictionary attrs:
459+
A dictionary with all attributes
460+
:param Dictionary methods:
461+
A dictionary with all methods
462+
:return:
463+
A FakeResource object, with id, ip, and so on
464+
"""
465+
# Set default attributes.
466+
floating_ip_attrs = {
467+
'id': 'floating-ip-id-' + uuid.uuid4().hex,
468+
'ip': '1.0.9.0',
469+
'fixed_ip': '2.0.9.0',
470+
'instance_id': 'server-id-' + uuid.uuid4().hex,
471+
'pool': 'public',
472+
}
473+
474+
# Overwrite default attributes.
475+
floating_ip_attrs.update(attrs)
476+
477+
# Set default methods.
478+
floating_ip_methods = {}
479+
480+
# Overwrite default methods.
481+
floating_ip_methods.update(methods)
482+
483+
floating_ip = fakes.FakeResource(
484+
info=copy.deepcopy(floating_ip_attrs),
485+
methods=copy.deepcopy(floating_ip_methods),
486+
loaded=True)
487+
return floating_ip
488+
489+
@staticmethod
490+
def create_floating_ips(attrs={}, methods={}, count=2):
491+
"""Create multiple fake floating ips.
492+
493+
:param Dictionary attrs:
494+
A dictionary with all attributes
495+
:param Dictionary methods:
496+
A dictionary with all methods
497+
:param int count:
498+
The number of floating ips to fake
499+
:return:
500+
A list of FakeResource objects faking the floating ips
501+
"""
502+
floating_ips = []
503+
for i in range(0, count):
504+
floating_ips.append(FakeFloatingIP.create_one_floating_ip(
505+
attrs,
506+
methods
507+
))
508+
return floating_ips
509+
510+
@staticmethod
511+
def get_floating_ips(floating_ips=None, count=2):
512+
"""Get an iterable MagicMock object with a list of faked floating ips.
513+
514+
If floating_ips list is provided, then initialize the Mock object
515+
with the list. Otherwise create one.
516+
517+
:param List floating ips:
518+
A list of FakeResource objects faking floating ips
519+
:param int count:
520+
The number of floating ips to fake
521+
:return:
522+
An iterable Mock object with side_effect set to a list of faked
523+
floating ips
524+
"""
525+
if floating_ips is None:
526+
floating_ips = FakeFloatingIP.create_floating_ips(count)
527+
return mock.MagicMock(side_effect=floating_ips)

openstackclient/tests/network/v2/test_floating_ip.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ def setUp(self):
110110
class TestDeleteFloatingIPCompute(TestFloatingIPCompute):
111111

112112
# The floating ip to be deleted.
113-
floating_ip = network_fakes.FakeFloatingIP.create_one_floating_ip()
113+
floating_ip = compute_fakes.FakeFloatingIP.create_one_floating_ip()
114114

115115
def setUp(self):
116116
super(TestDeleteFloatingIPCompute, self).setUp()
@@ -145,7 +145,7 @@ def test_floating_ip_delete(self):
145145
class TestListFloatingIPCompute(TestFloatingIPCompute):
146146

147147
# The floating ips to be list up
148-
floating_ips = network_fakes.FakeFloatingIP.create_floating_ips(count=3)
148+
floating_ips = compute_fakes.FakeFloatingIP.create_floating_ips(count=3)
149149

150150
columns = ('ID', 'Floating IP', 'Fixed IP', 'Server ID', 'Pool')
151151

0 commit comments

Comments
 (0)