From 41b606c2ca54b2b9b72b2b5f7a95179b130bccb1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20=27sil2100=27=20Zemczak?= Date: Mon, 19 Jul 2021 12:49:29 +0200 Subject: [PATCH] Commit fixes from staging testing: add required region name parameter. --- britney.conf | 1 + britney.conf.template | 1 + britney2/policies/autopkgtest.py | 19 ++++++++++--------- tests/__init__.py | 1 + tests/test_autopkgtest.py | 4 ++++ 5 files changed, 17 insertions(+), 9 deletions(-) diff --git a/britney.conf b/britney.conf index ee4fc89..d73b012 100644 --- a/britney.conf +++ b/britney.conf @@ -108,6 +108,7 @@ ADT_SWIFT_USER = ADT_SWIFT_PASS = ADT_SWIFT_AUTH_URL = ADT_SWIFT_TENANT = +ADT_SWIFT_REGION = # List of launchpad users/teams that should have read access to any private # result logs ADT_PRIVATE_SHARED = diff --git a/britney.conf.template b/britney.conf.template index 7c21e5f..e58b9c4 100644 --- a/britney.conf.template +++ b/britney.conf.template @@ -130,6 +130,7 @@ ADT_SWIFT_USER = ADT_SWIFT_PASS = ADT_SWIFT_AUTH_URL = ADT_SWIFT_TENANT = +ADT_SWIFT_REGION = # List of launchpad users/teams that should have read access to any private # result logs ADT_PRIVATE_SHARED = diff --git a/britney2/policies/autopkgtest.py b/britney2/policies/autopkgtest.py index bbfc2f3..f647261 100644 --- a/britney2/policies/autopkgtest.py +++ b/britney2/policies/autopkgtest.py @@ -211,7 +211,8 @@ class AutopkgtestPolicy(BasePolicy): if self.options.adt_swift_user: if (not self.options.adt_swift_pass or not self.options.adt_swift_auth_url or - not self.options.adt_swift_tenant): + not self.options.adt_swift_tenant or + not self.options.adt_swift_region): raise RuntimeError('Incomplete swift credentials given') # once swift credentials are given, the results will be published @@ -228,10 +229,8 @@ class AutopkgtestPolicy(BasePolicy): import swiftclient - if '/v2.0' in self.options.adt_swift_auth_url: - auth_version = '2.0' - else: - auth_version = '1' + if '/v2.0' not in self.options.adt_swift_auth_url: + raise RuntimeError('Unsupported swift auth version') self.logger.info('Creating an authenticated swift connection for user %s', self.options.adt_swift_user) self.swift_conn = swiftclient.Connection( @@ -239,7 +238,8 @@ class AutopkgtestPolicy(BasePolicy): user=self.options.adt_swift_user, key=self.options.adt_swift_pass, tenant_name=self.options.adt_swift_tenant, - auth_version=auth_version + auth_version='2.0', + os_options={'region_name': self.options.adt_swift_region} ) else: if any('@' in ppa for ppa in self.options.adt_ppas): @@ -910,12 +910,12 @@ class AutopkgtestPolicy(BasePolicy): from swiftclient.exceptions import ClientException try: - _, result_paths = self.swift_conn.get_container( + _, returned_paths = self.swift_conn.get_container( self.swift_container, query_string=urllib.parse.urlencode(query)) except ClientException as e: # 401 "Unauthorized" is swift's way of saying "container does not exist" - if e.http_status == '401' or e.http_status == '404': + if e.http_status == 401 or e.http_status == 404: self.logger.info('fetch_swift_results: %s does not exist yet or is inaccessible', self.swift_container) return # Other status codes are usually a transient @@ -924,6 +924,7 @@ class AutopkgtestPolicy(BasePolicy): # fail hard on this and let the next run retry. self.logger.error('Failure to fetch swift results from %s: %s', self.swift_container, str(e)) sys.exit(1) + result_paths = [p['subdir'] for p in returned_paths] else: url = os.path.join(swift_url, self.swift_container) url += '?' + urllib.parse.urlencode(query) @@ -977,7 +978,7 @@ class AutopkgtestPolicy(BasePolicy): except ClientException as e: self.logger.error('Failure to fetch %s from container %s: %s', url, container, str(e)) - if e.http_status == '404': + if e.http_status == 404: return sys.exit(1) tar_bytes = io.BytesIO(contents) diff --git a/tests/__init__.py b/tests/__init__.py index acbe475..86146a5 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -399,6 +399,7 @@ ADT_SWIFT_USER = ADT_SWIFT_PASS = ADT_SWIFT_AUTH_URL = ADT_SWIFT_TENANT = +ADT_SWIFT_REGION = ADT_PRIVATE_SHARED = ADT_PRIVATE_URL = ADT_CI_URL = https://autopkgtest.ubuntu.com/ diff --git a/tests/test_autopkgtest.py b/tests/test_autopkgtest.py index 281889a..8235a0c 100644 --- a/tests/test_autopkgtest.py +++ b/tests/test_autopkgtest.py @@ -2560,6 +2560,8 @@ class AT(TestAutopkgtestBase): print('ADT_SWIFT_PASS = pass') elif line.startswith('ADT_SWIFT_TENANT'): print('ADT_SWIFT_TENANT = tenant') + elif line.startswith('ADT_SWIFT_REGION'): + print('ADT_SWIFT_REGION = region') elif line.startswith('ADT_SWIFT_AUTH_URL'): print('ADT_SWIFT_AUTH_URL = http://127.0.0.1:5000/v2.0/') elif line.startswith('ADT_PRIVATE_SHARED'): @@ -2632,6 +2634,8 @@ class AT(TestAutopkgtestBase): print('ADT_SWIFT_PASS = pass') elif line.startswith('ADT_SWIFT_TENANT'): print('ADT_SWIFT_TENANT = tenant') + elif line.startswith('ADT_SWIFT_REGION'): + print('ADT_SWIFT_REGION = region') elif line.startswith('ADT_SWIFT_AUTH_URL'): print('ADT_SWIFT_AUTH_URL = http://127.0.0.1:5000/v2.0/') elif line.startswith('ADT_PRIVATE_URL'):