diff options
| author | Tang Chen <chen.tang@easystack.cn> | 2016-02-16 15:11:19 +0800 |
|---|---|---|
| committer | Tang Chen <chen.tang@easystack.cn> | 2016-02-16 15:14:34 +0800 |
| commit | da3d65299bc168ca86bfb4055d08556715149e0f (patch) | |
| tree | 141f816cd1e4a60ead5cc0c0ee1603a65cc18d19 /openstackclient/tests/compute | |
| parent | c8753808a224a6f286d1ee7833fb905ac916f304 (diff) | |
| download | python-openstackclient-da3d65299bc168ca86bfb4055d08556715149e0f.tar.gz | |
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
Diffstat (limited to 'openstackclient/tests/compute')
| -rw-r--r-- | openstackclient/tests/compute/v2/fakes.py | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/openstackclient/tests/compute/v2/fakes.py b/openstackclient/tests/compute/v2/fakes.py index c5e8f412..00f73748 100644 --- a/openstackclient/tests/compute/v2/fakes.py +++ b/openstackclient/tests/compute/v2/fakes.py @@ -446,3 +446,82 @@ class FakeAvailabilityZone(object): availability_zones.append(availability_zone) return availability_zones + + +class FakeFloatingIP(object): + """Fake one or more floating ip.""" + + @staticmethod + def create_one_floating_ip(attrs={}, methods={}): + """Create a fake floating ip. + + :param Dictionary attrs: + A dictionary with all attributes + :param Dictionary methods: + A dictionary with all methods + :return: + A FakeResource object, with id, ip, and so on + """ + # Set default attributes. + floating_ip_attrs = { + 'id': 'floating-ip-id-' + uuid.uuid4().hex, + 'ip': '1.0.9.0', + 'fixed_ip': '2.0.9.0', + 'instance_id': 'server-id-' + uuid.uuid4().hex, + 'pool': 'public', + } + + # Overwrite default attributes. + floating_ip_attrs.update(attrs) + + # Set default methods. + floating_ip_methods = {} + + # Overwrite default methods. + floating_ip_methods.update(methods) + + floating_ip = fakes.FakeResource( + info=copy.deepcopy(floating_ip_attrs), + methods=copy.deepcopy(floating_ip_methods), + loaded=True) + return floating_ip + + @staticmethod + def create_floating_ips(attrs={}, methods={}, count=2): + """Create multiple fake floating ips. + + :param Dictionary attrs: + A dictionary with all attributes + :param Dictionary methods: + A dictionary with all methods + :param int count: + The number of floating ips to fake + :return: + A list of FakeResource objects faking the floating ips + """ + floating_ips = [] + for i in range(0, count): + floating_ips.append(FakeFloatingIP.create_one_floating_ip( + attrs, + methods + )) + return floating_ips + + @staticmethod + def get_floating_ips(floating_ips=None, count=2): + """Get an iterable MagicMock object with a list of faked floating ips. + + If floating_ips list is provided, then initialize the Mock object + with the list. Otherwise create one. + + :param List floating ips: + A list of FakeResource objects faking floating ips + :param int count: + The number of floating ips to fake + :return: + An iterable Mock object with side_effect set to a list of faked + floating ips + """ + if floating_ips is None: + floating_ips = FakeFloatingIP.create_floating_ips(count) + return mock.MagicMock(side_effect=floating_ips) |
