canonical-ubuntu-qa team mailing list archive
-
canonical-ubuntu-qa team
-
Mailing list archive
-
Message #02135
[Merge] ~andersson123/autopkgtest-cloud:integration-tests into autopkgtest-cloud:master
Tim Andersson has proposed merging ~andersson123/autopkgtest-cloud:integration-tests into autopkgtest-cloud:master.
Requested reviews:
Canonical's Ubuntu QA (canonical-ubuntu-qa)
For more details, see:
https://code.launchpad.net/~andersson123/autopkgtest-cloud/+git/autopkgtest-cloud/+merge/457239
--
Your team Canonical's Ubuntu QA is requested to review the proposed merge of ~andersson123/autopkgtest-cloud:integration-tests into autopkgtest-cloud:master.
diff --git a/charms/focal/autopkgtest-cloud-worker/autopkgtest-cloud/tools/check-config-files b/charms/focal/autopkgtest-cloud-worker/autopkgtest-cloud/tools/check-config-files
new file mode 100755
index 0000000..5b511c0
--- /dev/null
+++ b/charms/focal/autopkgtest-cloud-worker/autopkgtest-cloud/tools/check-config-files
@@ -0,0 +1,212 @@
+#!/usr/bin/python3
+import os
+import subprocess
+
+import swiftclient
+from influxdb import InfluxDBClient
+
+bos_arches = ["arm64", "ppc64el", "s390x"]
+
+centres = {
+ "bos01": bos_arches,
+ "bos02": bos_arches,
+ "lcy02": None,
+}
+
+openstack_cmd = "openstack project list"
+
+openstack_commands = [
+ "openstack project list",
+ "openstack server list",
+ "openstack network list",
+ "openstack image list",
+]
+
+openstack_vars = [
+ "OS_USERNAME",
+ "OS_TENANT_NAME",
+ "OS_PASSWORD",
+ "OS_AUTH_URL",
+ "OS_REGION_NAME",
+]
+
+influx_vars = [
+ "INFLUXDB_HOSTNAME",
+ "INFLUXDB_PORT",
+ "INFLUXDB_USERNAME",
+ "INFLUXDB_PASSWORD",
+ "INFLUXDB_DATABASE",
+ "INFLUXDB_CONTEXT",
+]
+
+rabbit_vars = [
+ "RABBIT_HOST",
+ "RABBIT_USER",
+ "RABBIT_PASSWORD",
+]
+
+swift_vars = [
+ "SWIFT_AUTH_URL",
+ "SWIFT_AUTH_VERSION",
+ "SWIFT_PASSWORD",
+ "SWIFT_PROJECT_DOMAIN_NAME",
+ "SWIFT_PROJECT_NAME",
+ "SWIFT_REGION",
+ "SWIFT_TENANT",
+ "SWIFT_USER_DOMAIN_NAME",
+ "SWIFT_USERNAME",
+]
+
+worker_args = [
+ "[autopkgtest]",
+ "[virt]",
+ "checkout_dir",
+ "releases",
+ "setup_command",
+ "setup_command2",
+ "per_package_config_dir",
+ "architectures",
+ "package_size_default",
+ "package_size_big",
+ "args",
+]
+
+
+def check_cloudrcs(centres, openstack_commands, openstack_vars):
+ for centre, arches in centres.items():
+ for arch in arches:
+ if arch is None:
+ this_path = "~/cloudrcs/" + centre + ".rc"
+ else:
+ this_path = "~/cloudrcs/" + centre + "-" + arch + ".rc"
+ if not os.path.isfile(this_path):
+ return False
+ with open(this_path, "r") as f:
+ rc_file = f.read()
+ # check the correct variables are present
+ vars = []
+ for line in rc_file.splitlines():
+ if "export" in line:
+ this_line = line.split(" ")
+ var, value = this_line.split("=")
+ vars.append(var)
+ os.environ[var] = value
+ for var in openstack_vars:
+ if var not in rc_file:
+ return False
+ # check the below properly once I know exception type with a try except
+ for command in openstack_commands:
+ _ = subprocess.run(command.split(" "), check=True)
+ return True
+
+
+def check_influx_creds(influx_file, influx_keys):
+ creds = check_env_file_and_keys(influx_file, influx_keys)
+ for cred in creds.splitlines():
+ if "=" in cred:
+ var, value = cred.split("=")
+ os.environ[var] = value
+ influx_client = InfluxDBClient(
+ os.environ["INFLUXDB_HOSTNAME"],
+ os.environ["INFLUXDB_PORT"],
+ os.environ["INFLUXDB_USERNAME"],
+ os.environ["INFLUXDB_PASSWORD"],
+ os.environ["INFLUXDB_DATABASE"],
+ )
+ influx_client.ping()
+ return True
+
+
+def check_env_file_and_keys(file, file_keys):
+ mypath = os.path.expanduser("~/" + file)
+ if not os.path.isfile(mypath):
+ raise FileNotFoundError("file %s doesn't exist" % file)
+ with open(mypath, "r") as f:
+ myf = f.read()
+ for k in file_keys:
+ if k not in myf:
+ raise KeyError("key %s not found in %s" % (k, file))
+ return myf
+
+
+def check_mirror_rc(mirror_file, mirror_vars):
+ _ = check_env_file_and_keys(mirror_file, mirror_vars)
+
+
+def check_rabbitmq_creds(rabbit_file, rabbit_vars):
+ _ = check_env_file_and_keys(rabbit_file, rabbit_vars)
+
+
+def check_net_name(net_file, net_vars):
+ _ = check_env_file_and_keys(net_file, net_vars)
+
+
+def check_swift_creds(swift_file, swift_vars):
+ creds = check_env_file_and_keys(swift_file, swift_vars)
+ for line in creds.splitlines():
+ var, value = line.split("=")
+ os.environ[var] = value
+ swift_creds = {
+ "authurl": os.environ["SWIFT_AUTH_URL"],
+ "user": os.environ["SWIFT_USERNAME"],
+ "key": os.environ["SWIFT_PASSWORD"],
+ "os_options": {
+ "region_name": os.environ["SWIFT_REGION"],
+ "project_domain_name": os.environ["SWIFT_PROJECT_DOMAIN_NAME"],
+ "project_name": os.environ["SWIFT_PROJECT_NAME"],
+ "user_domain_name": os.environ["SWIFT_USER_DOMAIN_NAME"],
+ },
+ "auth_version": os.environ["SWIFT_AUTH_VERSION"],
+ }
+ swift_conn = swiftclient.Connection(**swift_creds)
+ _ = swift_conn.get_account()
+ swiftclient.Connection(**swift_creds).close()
+ return True
+
+
+def check_worker_conf_files(worker_args, centres):
+ for centre, arches in centres.items():
+ if arches is not None:
+ for a in arches:
+ workerfile = "-".join(["worker", centre, a]) + ".conf"
+ _ = check_env_file_and_keys(workerfile, worker_args)
+
+
+files_and_keys = {
+ "influx.cred": {
+ "vars": influx_vars,
+ "func": check_influx_creds,
+ },
+ "rabbitmq.cred": {
+ "vars": rabbit_vars,
+ "func": check_rabbitmq_creds,
+ },
+ "swift-password.cred": {
+ "vars": swift_vars,
+ "func": check_swift_creds,
+ },
+ "mirror.rc": {
+ "vars": ["MIRROR"],
+ "func": check_mirror_rc,
+ },
+ "net-name.rc": {
+ "vars": ["NET_NAME"],
+ "func": check_net_name,
+ },
+ "worker-configs": {
+ "vars": (worker_args, centres),
+ "func": check_worker_conf_files,
+ },
+ "cloudrcs": {
+ "vars": (centres, openstack_commands, openstack_vars),
+ "func": check_cloudrcs,
+ },
+}
+
+
+if __name__ == "__main__":
+ for file, item in files_and_keys.items():
+ if "." in file:
+ item["func"](file, item["vars"])
+ else:
+ item["func"](item["vars"])
References