diff options
Diffstat (limited to 'openstackclient/tests/compute/v2/fakes.py')
| -rw-r--r-- | openstackclient/tests/compute/v2/fakes.py | 59 |
1 files changed, 48 insertions, 11 deletions
diff --git a/openstackclient/tests/compute/v2/fakes.py b/openstackclient/tests/compute/v2/fakes.py index 70fc386f..62a46b1d 100644 --- a/openstackclient/tests/compute/v2/fakes.py +++ b/openstackclient/tests/compute/v2/fakes.py @@ -76,17 +76,6 @@ QUOTA = { QUOTA_columns = tuple(sorted(QUOTA)) QUOTA_data = tuple(QUOTA[x] for x in sorted(QUOTA)) -service_host = 'host_test' -service_binary = 'compute_test' -service_status = 'enabled' -service_disabled_reason = 'earthquake' -SERVICE = { - 'host': service_host, - 'binary': service_binary, - 'status': service_status, - 'disabled_reason': service_disabled_reason, -} - class FakeAggregate(object): """Fake one aggregate.""" @@ -523,6 +512,54 @@ class FakeServer(object): return mock.MagicMock(side_effect=servers) +class FakeService(object): + """Fake one or more services.""" + + @staticmethod + def create_one_service(attrs=None): + """Create a fake service. + + :param Dictionary attrs: + A dictionary with all attributes + :return: + A FakeResource object, with id, name, ram, vcpus, properties + """ + attrs = attrs or {} + + # Set default attributes. + service_info = { + 'host': 'host-' + uuid.uuid4().hex, + 'binary': 'binary-' + uuid.uuid4().hex, + 'status': 'enabled', + 'disabled_reason': 'earthquake', + } + + # Overwrite default attributes. + service_info.update(attrs) + + service = fakes.FakeResource(info=copy.deepcopy(service_info), + loaded=True) + + return service + + @staticmethod + def create_services(attrs=None, count=2): + """Create multiple fake services. + + :param Dictionary attrs: + A dictionary with all attributes + :param int count: + The number of services to fake + :return: + A list of FakeResource objects faking the services + """ + services = [] + for i in range(0, count): + services.append(FakeService.create_one_service(attrs)) + + return services + + class FakeFlavor(object): """Fake one or more flavors.""" |
