Skip to content

Commit 7da4473

Browse files
mbuechsegarloff
andauthored
brush up mandatory-iaas-services.py (#888)
* brush up mandatory-iaas-services.py resolves #862 * Acquiesce flake8 Signed-off-by: Matthias Büchse <[email protected]> Co-authored-by: Kurt Garloff <[email protected]>
1 parent bf5a998 commit 7da4473

File tree

1 file changed

+16
-17
lines changed

1 file changed

+16
-17
lines changed

Tests/iaas/mandatory-services/mandatory-iaas-services.py

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,7 @@ def s3_conn(creds, conn=None):
7777
cacert = conn.config.config.get("cacert")
7878
# TODO: Handle self-signed certs (from ca_cert in openstack config)
7979
if cacert:
80-
print("WARNING: Trust all Certificates in S3, "
81-
f"OpenStack uses {cacert}", file=sys.stderr)
80+
logger.warning(f"Trust all Certificates in S3, OpenStack uses {cacert}")
8281
vrfy = False
8382
return boto3.resource('s3', aws_access_key_id=creds["AK"],
8483
aws_secret_access_key=creds["SK"],
@@ -111,7 +110,7 @@ def s3_from_env(creds, fieldnm, env, prefix=""):
111110
if env in os.environ:
112111
creds[fieldnm] = prefix + os.environ[env]
113112
if fieldnm not in creds:
114-
print(f"WARNING: s3_creds[{fieldnm}] not set", file=sys.stderr)
113+
logger.warning(f"s3_creds[{fieldnm}] not set")
115114

116115

117116
def s3_from_ostack(creds, conn, endpoint):
@@ -140,23 +139,21 @@ def s3_from_ostack(creds, conn, endpoint):
140139
creds["AK"] = ak
141140
creds["SK"] = sk
142141
except BaseException as exc:
143-
print(f"WARNING: ec2 creds creation failed: {exc!s}", file=sys.stderr)
144-
# pass
142+
logger.warning(f"ec2 creds creation failed: {exc!s}")
145143

146144

147145
def check_for_s3_and_swift(conn: openstack.connection.Connection, s3_credentials=None):
148146
# If we get credentials, we assume that there is no Swift and only test s3
149147
if s3_credentials:
150148
try:
151149
s3 = s3_conn(s3_credentials)
152-
except Exception as e:
153-
print(str(e))
154-
logger.error("FAIL: Connection to s3 failed.")
150+
except Exception:
151+
logger.debug("details", exc_info=True)
152+
logger.error("Connection to S3 failed.")
155153
return 1
156-
s3_buckets = list_s3_buckets(s3)
154+
s3_buckets = list_s3_buckets(s3) or create_bucket(s3, TESTCONTNAME)
157155
if not s3_buckets:
158-
s3_buckets = create_bucket(s3, TESTCONTNAME)
159-
assert s3_buckets
156+
raise RuntimeError("failed to create S3 bucket")
160157
if s3_buckets == [TESTCONTNAME]:
161158
del_bucket(s3, TESTCONTNAME)
162159
# everything worked, and we don't need to test for Swift:
@@ -179,20 +176,22 @@ def check_for_s3_and_swift(conn: openstack.connection.Connection, s3_credentials
179176
s3_from_env(s3_creds, "AK", "S3_ACCESS_KEY_ID")
180177
s3_from_env(s3_creds, "SK", "S3_SECRET_ACCESS_KEY")
181178

179+
# This is to be used for local debugging purposes ONLY
180+
# logger.info(f"using credentials {s3_creds}")
181+
182182
s3 = s3_conn(s3_creds, conn)
183-
s3_buckets = list_s3_buckets(s3)
183+
s3_buckets = list_s3_buckets(s3) or create_bucket(s3, TESTCONTNAME)
184184
if not s3_buckets:
185-
s3_buckets = create_bucket(s3, TESTCONTNAME)
186-
assert s3_buckets
185+
raise RuntimeError("failed to create S3 bucket")
187186

188187
# If we got till here, s3 is working, now swift
189188
swift_containers = list_containers(conn)
190189
# if not swift_containers:
191190
# swift_containers = create_container(conn, TESTCONTNAME)
192191
result = 0
193192
if Counter(s3_buckets) != Counter(swift_containers):
194-
logger.warning("S3 buckets and Swift Containers differ:\n"
195-
f"S3: {sorted(s3_buckets)}\nSW: {sorted(swift_containers)}")
193+
logger.error("S3 buckets and Swift Containers differ:\n"
194+
f"S3: {sorted(s3_buckets)}\nSW: {sorted(swift_containers)}")
196195
result = 1
197196
else:
198197
logger.info("SUCCESS: S3 and Swift exist and agree")
@@ -235,7 +234,7 @@ def main():
235234
format="%(levelname)s: %(message)s",
236235
level=logging.DEBUG if args.debug else logging.INFO,
237236
)
238-
openstack.enable_logging(debug=args.debug)
237+
openstack.enable_logging(debug=False)
239238

240239
# parse cloud name for lookup in clouds.yaml
241240
cloud = args.os_cloud or os.environ.get("OS_CLOUD", None)

0 commit comments

Comments
 (0)