From fedd6507aea5875d4606c909004eaed40f0cc195 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adolfo=20G=C3=B3mez=20Garc=C3=ADa?= Date: Mon, 25 Mar 2024 05:01:09 +0100 Subject: [PATCH] Fixed openstack tests (due to incorrect initial states of some tests) --- server/src/uds/core/environment.py | 2 +- server/tests/services/openstack/fixtures.py | 4 ++-- server/tests/services/openstack/test_userservice_fixed.py | 6 ++++++ 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/server/src/uds/core/environment.py b/server/src/uds/core/environment.py index 098d30f84..fddb0b4d1 100644 --- a/server/src/uds/core/environment.py +++ b/server/src/uds/core/environment.py @@ -170,7 +170,7 @@ class Environment: Obtains an environment with an unique identifier @return: An environment with an unique identifier """ - return Environment('#_#' + str(id(owner)) + '#^#') + return Environment('#_#' + str(owner) + '#^#') @staticmethod def temporary_environment() -> 'Environment': diff --git a/server/tests/services/openstack/fixtures.py b/server/tests/services/openstack/fixtures.py index ce572fd58..1d697a045 100644 --- a/server/tests/services/openstack/fixtures.py +++ b/server/tests/services/openstack/fixtures.py @@ -115,7 +115,7 @@ SERVERS_LIST: list[openstack_types.ServerInfo] = [ fault=None, admin_pass='', ) - for n in range(1, 16) + for n in range(1, 32) ] IMAGES_LIST: list[openstack_types.ImageInfo] = [ @@ -359,7 +359,7 @@ SERVICES_FIXED_VALUES_DICT: typing.Final[gui.ValuesDictType] = { 'token': 'token', 'region': random.choice(REGIONS_LIST).id, 'project': random.choice(PROJECTS_LIST).id, - 'machines': [i.id for i in random.sample(SERVERS_LIST, 4)], + 'machines': [i.id for i in random.sample(SERVERS_LIST, 10)], # 'prov_uuid': str(uuid.uuid4()), # Not stored on db, so not needed } diff --git a/server/tests/services/openstack/test_userservice_fixed.py b/server/tests/services/openstack/test_userservice_fixed.py index 783b812fa..08019e6a8 100644 --- a/server/tests/services/openstack/test_userservice_fixed.py +++ b/server/tests/services/openstack/test_userservice_fixed.py @@ -40,6 +40,8 @@ from . import fixtures from ...utils.test import UDSTransactionTestCase from ...utils.generators import limited_iterator +from uds.services.OpenStack.openstack import types as openstack_types + # We use transactions on some related methods (storage access, etc...) class TestOpenstackFixedService(UDSTransactionTestCase): @@ -92,6 +94,10 @@ class TestOpenstackFixedService(UDSTransactionTestCase): self.assertEqual(set(), assigned_machines) # set_ready, machine is "stopped" in this test, so must return RUNNING + # ensure cache is empty, may affect from other tests + userservice.cache.clear() + # Also that machine is stopped + fixtures.get_id(fixtures.SERVERS_LIST, userservice._vmid).power_state = openstack_types.PowerState.SHUTDOWN state = userservice.set_ready() self.assertEqual(state, types.states.TaskState.RUNNING)