forked from red-hat-storage/ocs-ci
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.functional_ci_setup.py
executable file
·140 lines (122 loc) · 3.78 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
#!/usr/bin/env python
import argparse
import base64
import binascii
import os
import yaml
from os import environ as env
from configparser import ConfigParser
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.join(env['WORKSPACE'], '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)
def get_ocsci_conf():
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",
),
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'])
conf_obj['DEPLOYMENT'] = dict(
ocs_registry_image=env['OCS_REGISTRY_IMAGE'],
)
return conf_obj
def write_ocsci_conf():
ocp_conf = get_ocsci_conf()
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))
ocs_conf = get_ocsci_conf()
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))
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()