From 15064c7a4246216a135498720959673d68b5871a Mon Sep 17 00:00:00 2001 From: Matt Clay Date: Tue, 9 Mar 2021 19:28:28 -0800 Subject: [PATCH] Update `resource_prefix` syntax for ansible-test. --- changelogs/fragments/ansible-test-resource-prefix.yml | 4 ++++ test/lib/ansible_test/_internal/ci/azp.py | 2 -- test/lib/ansible_test/_internal/ci/local.py | 7 ++++--- test/lib/ansible_test/_internal/cloud/__init__.py | 1 + 4 files changed, 9 insertions(+), 5 deletions(-) create mode 100644 changelogs/fragments/ansible-test-resource-prefix.yml diff --git a/changelogs/fragments/ansible-test-resource-prefix.yml b/changelogs/fragments/ansible-test-resource-prefix.yml new file mode 100644 index 00000000000..15b4b9f1ee1 --- /dev/null +++ b/changelogs/fragments/ansible-test-resource-prefix.yml @@ -0,0 +1,4 @@ +minor_changes: + - ansible-test - The generated ``resource_prefix`` variable now meets the host name syntax requirements specified in RFC 1123 and RFC 952. + The value used for local tests now places the random number before the hostname component, rather than after. + If the resulting value is too long, it will be truncated. diff --git a/test/lib/ansible_test/_internal/ci/azp.py b/test/lib/ansible_test/_internal/ci/azp.py index f2a9d206cc7..807c115bf1b 100644 --- a/test/lib/ansible_test/_internal/ci/azp.py +++ b/test/lib/ansible_test/_internal/ci/azp.py @@ -73,8 +73,6 @@ class AzurePipelines(CIProvider): except KeyError as ex: raise MissingEnvironmentVariable(name=ex.args[0]) - prefix = re.sub(r'[^a-zA-Z0-9]+', '-', prefix).lower() - return prefix def get_base_branch(self): # type: () -> str diff --git a/test/lib/ansible_test/_internal/ci/local.py b/test/lib/ansible_test/_internal/ci/local.py index 83ebb9d81df..5886601b962 100644 --- a/test/lib/ansible_test/_internal/ci/local.py +++ b/test/lib/ansible_test/_internal/ci/local.py @@ -58,9 +58,10 @@ class Local(CIProvider): def generate_resource_prefix(self): # type: () -> str """Return a resource prefix specific to this CI provider.""" - node = re.sub(r'[^a-zA-Z0-9]+', '-', platform.node().split('.')[0]).lower() - - prefix = 'ansible-test-%s-%d' % (node, random.randint(10000000, 99999999)) + prefix = 'ansible-test-%d-%s' % ( + random.randint(10000000, 99999999), + platform.node().split('.')[0], + ) return prefix diff --git a/test/lib/ansible_test/_internal/cloud/__init__.py b/test/lib/ansible_test/_internal/cloud/__init__.py index 04f592c4e79..08a1183e06d 100644 --- a/test/lib/ansible_test/_internal/cloud/__init__.py +++ b/test/lib/ansible_test/_internal/cloud/__init__.py @@ -313,6 +313,7 @@ class CloudProvider(CloudBase): def setup(self): """Setup the cloud resource before delegation and register a cleanup callback.""" self.resource_prefix = self.ci_provider.generate_resource_prefix() + self.resource_prefix = re.sub(r'[^a-zA-Z0-9]+', '-', self.resource_prefix)[:63].lower().rstrip('-') atexit.register(self.cleanup)