-
Notifications
You must be signed in to change notification settings - Fork 168
/
.functional_ci_setup.py
executable file
·180 lines (161 loc) · 5.89 KB
/
.functional_ci_setup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
#!/usr/bin/env python
import argparse
import base64
import binascii
import os
import yaml
from os import environ as env
from configparser import ConfigParser
from semantic_version import Version
def parse_args():
parser = argparse.ArgumentParser()
parser.add_argument(
"--skip-aws",
dest="aws",
action="store_false",
)
parser.add_argument(
"--skip-pull-secret",
dest="pull_secret",
action="store_false",
)
parser.add_argument(
"--skip-ocsci-conf",
dest="ocsci_conf",
action="store_false",
)
parser.add_argument(
"--skip-bugzilla-conf",
dest="bugzilla_conf",
action="store_false",
)
return parser.parse_args()
def write_aws_creds():
aws_profile = env["AWS_PROFILE"]
# Write the credentials file
creds = ConfigParser()
creds[aws_profile] = dict(
aws_access_key_id=env["AWS_ACCESS_KEY_ID"],
aws_secret_access_key=env["AWS_SECRET_ACCESS_KEY"],
)
creds_path = env["AWS_SHARED_CREDENTIALS_FILE"]
os.makedirs(
os.path.dirname(creds_path),
exist_ok=True,
)
with open(creds_path, "w") as creds_file:
creds.write(creds_file)
# Write the config file
conf = ConfigParser()
conf[aws_profile] = dict(
region=env["AWS_REGION"],
output="text",
)
conf_path = env["AWS_CONFIG_FILE"]
os.makedirs(
os.path.dirname(conf_path),
exist_ok=True,
)
with open(conf_path, "w") as conf_file:
conf.write(conf_file)
def write_pull_secret():
secret_dir = os.path.abspath(os.path.join(".", "data"))
os.makedirs(secret_dir, exist_ok=True)
secret = env["PULL_SECRET"]
# In Jenkins, this is a JSON string. In GitLab CI, the JSON will be
# base64-encoded.
try:
secret = base64.b64decode(secret).decode()
except (binascii.Error, UnicodeDecodeError):
pass
with open(os.path.join(secret_dir, "pull-secret"), "w") as secret_file:
secret_file.write(secret)
with open(os.path.join(secret_dir, "auth.yaml"), "w") as auth_file:
auth = dict(quay=dict(access_token=env["QUAY_TOKEN"]))
auth_file.write(yaml.safe_dump(auth))
def get_ocsci_conf(upgrade_run=False, pre_upgrade=False):
if pre_upgrade and not upgrade_run:
raise ValueError("pre_upgrade implies upgrade_run")
cluster_user = env["CLUSTER_USER"]
pipeline_id = env["BUILD_ID"]
conf_obj = dict(
RUN=dict(
log_dir=os.path.join(env["WORKSPACE"], "logs"),
),
ENV_DATA=dict(
platform="AWS",
cluster_name=f"{cluster_user}-ocs-ci-{pipeline_id}",
region=env["AWS_REGION"],
base_domain=env["AWS_DOMAIN"],
worker_instance_type="m5.4xlarge",
cluster_namespace="openshift-storage",
),
DEPLOYMENT=dict(),
REPORTING=dict(
gather_on_deploy_failure=True,
),
)
if env.get("DOWNSTREAM") == "true":
conf_obj["REPORTING"]["us_ds"] = "DS"
if env.get("SMTP_SERVER"):
conf_obj["REPORTING"]["email"] = dict(smtp_server=env["SMTP_SERVER"])
if env.get("SAVE_MEM_REPORT").lower() == "true":
conf_obj["REPORTING"]["save_mem_report"] = True
if upgrade_run:
version = Version.coerce(env["OCS_REGISTRY_IMAGE"].split(":")[1]).truncate(
"minor"
)
preup_version = f"{version.major}.{version.minor - 1}"
# ocs-ci needs ENV_DATA.ocs_version to be equal to the *pre-upgrade*
# version even during the upgrade phase.
conf_obj["ENV_DATA"]["ocs_version"] = preup_version
if pre_upgrade:
ocp_version = ocp_version = f"{version.major}.{version.minor}-ga"
conf_obj["DEPLOYMENT"]["ocp_version"] = ocp_version
conf_obj["DEPLOYMENT"]["installer_version"] = ocp_version
conf_obj["RUN"]["client_version"] = ocp_version
else:
conf_obj["UPGRADE"] = dict(
upgrade_ocs_registry_image=env["OCS_REGISTRY_IMAGE"],
upgrade_to_latest=False,
)
else:
conf_obj["DEPLOYMENT"] = dict(ocs_registry_image=env["OCS_REGISTRY_IMAGE"])
if env.get("OCP_VERSION"):
conf_obj["DEPLOYMENT"]["ocp_version"] = env["OCP_VERSION"]
return conf_obj
def write_ocsci_conf():
upgrade = bool(env.get("UPGRADE"))
ocp_conf = get_ocsci_conf(upgrade_run=upgrade, pre_upgrade=upgrade)
ocp_conf["ENV_DATA"]["skip_ocs_deployment"] = True
ocp_conf_path = os.path.join(env["WORKSPACE"], "ocs-ci-ocp.yaml")
with open(ocp_conf_path, "w") as ocp_conf_file:
ocp_conf_file.write(yaml.safe_dump(ocp_conf))
if upgrade:
ocs_pre_conf = get_ocsci_conf(upgrade_run=True, pre_upgrade=True)
ocs_pre_conf["ENV_DATA"]["skip_ocp_deployment"] = True
ocs_pre_conf_path = os.path.join(env["WORKSPACE"], "ocs-ci-pre-ocs.yaml")
with open(ocs_pre_conf_path, "w") as ocs_pre_conf_file:
ocs_pre_conf_file.write(yaml.safe_dump(ocs_pre_conf))
ocs_conf = get_ocsci_conf(upgrade_run=upgrade, pre_upgrade=False)
ocs_conf["ENV_DATA"]["skip_ocp_deployment"] = True
ocs_conf_path = os.path.join(env["WORKSPACE"], "ocs-ci-ocs.yaml")
with open(ocs_conf_path, "w") as ocs_conf_file:
ocs_conf_file.write(yaml.safe_dump(ocs_conf))
test_conf = get_ocsci_conf(upgrade_run=False)
test_conf_path = os.path.join(env["WORKSPACE"], "ocs-ci-test.yaml")
with open(test_conf_path, "w") as test_conf_file:
test_conf_file.write(yaml.safe_dump(test_conf))
def write_bugzilla_conf():
with open("bugzilla.cfg", "w") as bz_cfg_file:
bz_cfg_file.write(env["BUGZILLA_CFG"])
if __name__ == "__main__":
args = parse_args()
if args.aws:
write_aws_creds()
if args.pull_secret:
write_pull_secret()
if args.ocsci_conf:
write_ocsci_conf()
if args.bugzilla_conf:
write_bugzilla_conf()