diff options
author | 2019-11-07 00:29:38 +0100 | |
---|---|---|
committer | 2019-11-07 00:49:25 +0100 | |
commit | 45baa7718c820bc712f24afa4bfa7d8d2ec2b4eb (patch) | |
tree | 073ce9fd9b1766f89992fc3cfb8efe84c08dc122 /xtesting/core | |
parent | 74b74a19de77d9ac1ddeb7f1b638011d6241d1cb (diff) |
Create Bucket if it doesn't exist
Xtesting Ansible Role no longer creates bucket after starting Minio
[1].
[1] https://github.com/collivier/ansible-role-xtesting/commit/8c62525bb0d0b5f8dcc2c4436711d5d075de8811
Change-Id: I1ad473ce55f9c00df8e558fdc67f571ee0a1875c
Signed-off-by: Cédric Ollivier <cedric.ollivier@orange.com>
(cherry picked from commit 7ddcfae7ff8a20fac21f5ba2b923e8e5cbce19e5)
Diffstat (limited to 'xtesting/core')
-rw-r--r-- | xtesting/core/testcase.py | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/xtesting/core/testcase.py b/xtesting/core/testcase.py index 2db0f5c3..386c9d86 100644 --- a/xtesting/core/testcase.py +++ b/xtesting/core/testcase.py @@ -15,11 +15,12 @@ import json import logging import os import re -import requests +import sys import boto3 import botocore import prettytable +import requests import six from six.moves import urllib @@ -245,7 +246,7 @@ class TestCase(object): return TestCase.EX_PUSH_TO_DB_ERROR return TestCase.EX_OK - def publish_artifacts(self): + def publish_artifacts(self): # pylint: disable=too-many-locals """Push the artifacts to the S3 repository. It allows publishing the artifacts. @@ -272,13 +273,26 @@ class TestCase(object): b3resource = boto3.resource( 's3', endpoint_url=os.environ["S3_ENDPOINT_URL"]) dst_s3_url = os.environ["S3_DST_URL"] - bucket = urllib.parse.urlparse(dst_s3_url).netloc + bucket_name = urllib.parse.urlparse(dst_s3_url).netloc + try: + b3resource.meta.client.head_bucket(Bucket=bucket_name) + except botocore.exceptions.ClientError as exc: + error_code = exc.response['Error']['Code'] + if error_code == '404': + # pylint: disable=no-member + b3resource.create_bucket(Bucket=bucket_name) + else: + typ, value, traceback = sys.exc_info() + six.reraise(typ, value, traceback) + except Exception: # pylint: disable=broad-except + typ, value, traceback = sys.exc_info() + six.reraise(typ, value, traceback) path = urllib.parse.urlparse(dst_s3_url).path.strip("/") output_str = "\n" for root, _, files in os.walk(self.dir_results): for pub_file in files: # pylint: disable=no-member - b3resource.Bucket(bucket).upload_file( + b3resource.Bucket(bucket_name).upload_file( os.path.join(root, pub_file), os.path.join(path, os.path.relpath( os.path.join(root, pub_file), |