Repository navigation
Expand file tree
/
Copy pathrun.py
More file actions
executable file
·1598 lines (1367 loc) · 59.9 KB
/
Copy pathrun.py
File metadata and controls
executable file
·1598 lines (1367 loc) · 59.9 KB
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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env python3
import datetime
import importlib
import json
import os
import pickle
import re
import sys
import time
import traceback
from copy import deepcopy
from getpass import getuser
import requests
import yaml
from docopt import docopt
from libcloud.common.types import LibcloudError
import init_suite
from ceph.ceph import Ceph, CephNode
from ceph.clients import WinNode
from ceph.utils import (
cleanup_ceph_nodes,
cleanup_ibmc_ceph_nodes,
create_aws_ceph_nodes,
create_baremetal_ceph_nodes,
create_ceph_nodes,
create_ibmc_ceph_nodes,
create_ocpvirt_ceph_nodes,
create_onecloud_ceph_nodes,
)
from cephci.cluster_info import collect_ceph_coredumps, get_ceph_var_logs
from cephci.utils.build_info import CephTestManifest
from cli.performance.memory_and_cpu_utils import (
start_logging_processes,
stop_logging_process,
upload_mem_and_cpu_logger_script,
)
from compute.aws_ec2 import cleanup_aws_ceph_nodes
from compute.onecloud import cleanup_onecloud_ceph_nodes, expand_private_key_path
from compute.openshift import cleanup_ocpvirt_ceph_nodes, resolve_ocpvirt_credentials
from utility import sosreport
from utility.log import Log
from utility.polarion import post_to_polarion
from utility.retry import retry
from utility.utils import ( # ReportPortal,
check_build_overrides,
compose_container_image,
create_run_dir,
create_unique_test_name,
email_results,
generate_unique_id,
magna_url,
resolve_use_ipv6,
setup_cluster_access,
validate_conf,
validate_image,
)
from utility.xunit import create_xunit_results
doc = """
A simple test suite wrapper that executes tests based on yaml test configuration
Usage:
run.py (--rhbuild BUILD | --release ceph_release)
(--platform <name>)
(--suite <FILE>)...
(--global-conf FILE | --cluster-conf FILE)
[--cloud <openstack> | <ibmc> | <aws> | <baremetal> | <onecloud> | <ocpvirt>]
[--build <name>]
[--inventory FILE]
[--ssh-private-key <path>]
[--ssh-pub-key <path>]
[--osp-cred <file>]
[--rhs-ceph-repo <repo>]
[--add-repo <repo>]
[--kernel-repo <repo>]
[--store | --reuse <file>]
[--skip-cluster]
[--skip-subscription]
[--docker-registry <registry>]
[--docker-image <image>]
[--docker-tag <tag>]
[--insecure-registry]
[--post-results]
[--upstream-build <upstream-build>]
[--log-level <LEVEL>]
[--log-dir <directory-name>]
[--instances-name <name>]
[--osp-image <image>]
[--filestore]
[--use-ec-pool <k,m>]
[--hotfix-repo <repo>]
[--skip-version-compare]
[--custom-config <key>=<value>]...
[--custom-config-file <file>]
[--xunit-results]
[--enable-eus]
[--skip-enabling-rhel-rpms]
[--skip-sos-report]
[--skip-tc <items>]
[--monitor-performance]
[--disable-console-log]
[--product <community> | <redhat> | <ibm>]
run.py --cleanup=name --osp-cred <file> [--cloud <str>]
[--log-level <LEVEL>]
[--custom-config <key>=<value>]...
Options:
-h --help show this screen
-v --version run version
-s <smoke> --suite <smoke> test suite to run
eg: -s smoke or -s rbd
-f <tests> --filter <tests> filter tests based on the patter
eg: -f 'rbd' will run tests that have 'rbd'
--global-conf <file> global cloud configuration file
--cluster-conf <file> cluster configuration file
--inventory <file> hosts inventory file
--ssh-private-key <path> Path to the private key used to access the
systems as cephuser
--ssh-pub-key <path> Path to the public key authorized for
cephuser and root on the systems
--cloud <cloud_type> cloud type (openstack|ibmc|aws|baremetal|onecloud|ocpvirt) [default: openstack]
--osp-cred <file> openstack credentials as separate file
--rhbuild <1.3.0> ceph downstream version
eg: 1.3.0, 2.0, 2.1 etc
Depreciated in favor of --release
--release <ceph_version> Ceph version. It can be download stream or
upstream distinct name.
--build <nightly> Type of build to be use for testing
eg: nightly|stable|released|zX
[default: released]
--upstream-build <upstream-build> eg: quincy|pacific
Depreciated in favor of --release
--platform <rhel-8> select platform version eg., rhel-8, rhel-7
--rhs-ceph-repo <repo> location of rhs-ceph repo
Top level location of compose
--add-repo <repo> Any additional repo's need to be enabled
--kernel-repo <repo> Zstream Kernel Repo location
--store store the current vm state for reuse
--reuse <file> use the stored vm state for rerun
--skip-cluster skip cluster creation from ansible/ceph-deploy
--skip-subscription skip subscription manager if using beta rhel images
--docker-registry <registry> Docker registry, default value is taken from ansible
config
--docker-image <image> Docker image, default value is taken from ansible
config
--docker-tag <tag> Docker tag, default value is 'latest'
--insecure-registry Disable security check for docker registry
--post-results Post results to polarion, needs Polarion IDs
in test suite yamls. Requires config file, see
README.
--log-level <LEVEL> Set logging level
--log-dir <LEVEL> Set log directory
--instances-name <name> Name that will be used for instances creation
--osp-image <image> Image for osp instances, default value is taken from
conf file
--filestore To specify filestore as osd object store
--use-ec-pool <k,m> To use ec pools instead of replicated pools
--hotfix-repo <repo> To run sanity on hotfix build
--skip-version-compare Skip verification that ceph versions change post
upgrade
-c --custom-config <name>=<value> Add a custom config key/value to ceph_conf_overrides
Cephadm ODF/Rook-like profile (opt-in via -c)
apply-odf-defaults=true merges
conf/tentacle/rook/odf_rook_defaults.yaml into
bootstrap --config (OSDMap ratios, ms_bind_msgr1=false,
RBD ms_mode); v2-only mon set-addrs runs at end of
bootstrap.py, after test_cephadm deploy,
tests/ceph_installer/deploy_rook_defaults_ceph.py
after mon apply, and in
tests/cephadm/test_mon.py after mon apply.
apply-odf-topology=true is DO-NOT-USE (legacy
zone CRUSH path); use deploy_rook_defaults_ceph.py
for rack+ssd topology instead.
verify-odf-defaults=true checks config/osd/mon dump.
--custom-config-file <file> Add custom config yaml to ceph_conf_overrides
--xunit-results Create xUnit result file for test suite run
[default: false]
--enable-eus Enables EUS rpms on EUS suppored distro
[default: false]
--skip-enabling-rhel-rpms skip adding rpms from subscription if using beta
rhel images for Interop runs
--skip-sos-report Enables to collect sos-report on test suite failures
[default: false]
--skip-tc <items> skip test case provided in comma seperated fashion
--monitor-performance Monitor performance and CPU usage on all/required nodes
for every test and collects data to specified dir
--disable-console-log To stopping logging to console
[default: false]
--product <product> The edition of Ceph. Accepted values are
community, redhat and ibm
"""
log = Log()
test_names = []
run_summary = {}
class CephCIArgumentError(Exception):
pass
@retry(LibcloudError, tries=5, delay=15)
def create_nodes(
conf,
inventory,
osp_cred,
run_id,
cloud_type="openstack",
instances_name=None,
enable_eus=False,
custom_config=None,
platform=None,
ssh_private_key=None,
ssh_pub_key=None,
):
"""Creates the system under test environment.
Args:
conf Platform
inventory Test environment
osp_cred Platform access information
run_id execution identifier
cloud_type The platform to be used for deployment.
instances_name system names
enable_eus Extended OS support
custom_config list of <key>=<value>
platform RHEL platform (e.g. rhel-9, rhel-10) for OneCloud image selection
ssh_private_key Overrides the private key used to access the systems
ssh_pub_key Public key content authorized for cephuser and root;
used to guarantee root access on the systems
Notes:
use custom_config to specify the environments or configuration to
be used when using generic inventory files. Ensure to prefix the
platform. For exmaple
--custom-config ibmc_vpc=ci-vpc-01
--custom-config ibmc_profile=bx2-2x8
--custom-config ocpvirt_namespace=rdu3_ceph_jenkins
--custom-config ocpvirt_profile=cx1.2xlarge # optional; default o1.large
# or custom sizing (mutually exclusive with ocpvirt_profile):
# --custom-config ocpvirt_cpu=4 --custom-config ocpvirt_memory=16Gi
--custom-config openstack_vm_profile=c1.standard.xl
--custom-config openstack_networks=provider_net_cci_1
--custom-config use_ipv6=true
If these values are not provided then the defaults would be used.
openstack_networks (single or comma-separated) overrides cluster conf for all OpenStack VMs.
The defaults are the ones used in the example.
"""
validate_conf(conf)
validate_image(conf, cloud_type)
if cloud_type == "openstack":
cleanup_ceph_nodes(osp_cred, instances_name)
elif cloud_type == "ibmc":
cleanup_ibmc_ceph_nodes(osp_cred, instances_name, custom_config=None)
elif cloud_type == "aws":
cleanup_aws_ceph_nodes(osp_cred, instances_name, custom_config=None)
elif cloud_type == "onecloud":
cleanup_onecloud_ceph_nodes(
osp_cred, instances_name, custom_config=custom_config
)
elif cloud_type == "ocpvirt":
cleanup_ocpvirt_ceph_nodes(
osp_cred, instances_name, custom_config=custom_config
)
ceph_cluster_dict = {}
clients = []
for cluster in conf.get("globals"):
if cloud_type == "openstack":
ceph_vmnodes = create_ceph_nodes(
cluster,
inventory,
osp_cred,
run_id,
instances_name,
enable_eus=enable_eus,
custom_config=custom_config,
)
elif cloud_type == "ibmc":
ceph_vmnodes = create_ibmc_ceph_nodes(
cluster, inventory, osp_cred, run_id, instances_name, custom_config
)
elif cloud_type == "aws":
ceph_vmnodes = create_aws_ceph_nodes(
cluster, inventory, osp_cred, run_id, instances_name, custom_config
)
elif cloud_type == "onecloud":
ceph_vmnodes = create_onecloud_ceph_nodes(
cluster,
inventory,
osp_cred,
run_id,
instances_name,
custom_config,
platform=platform,
)
elif cloud_type == "ocpvirt":
ceph_vmnodes = create_ocpvirt_ceph_nodes(
cluster, inventory, osp_cred, run_id, instances_name, custom_config
)
elif "baremetal" in cloud_type:
ceph_vmnodes = create_baremetal_ceph_nodes(cluster)
else:
log.error(f"Unknown cloud type: {cloud_type}")
raise AssertionError("Unsupported test environment.")
# Resolve use_ipv6 before building nodes so CephNode can use it for SSH when requested
use_ipv6 = resolve_use_ipv6(custom_config, cloud_type, osp_cred)
ceph_nodes = []
# OneCloud creds: globals.onecloud-credentials (osp-cred) or credentials.cloud.onecloud (cephci.yaml)
onecloud_cfg = {}
if cloud_type == "onecloud":
glbs = osp_cred.get("globals") or {}
onecloud_cfg = (
(glbs.get("onecloud-credentials") if isinstance(glbs, dict) else {})
or ((osp_cred.get("credentials") or {}).get("cloud") or {}).get(
"onecloud"
)
or {}
)
log.info(
"OneCloud auth: private_key_path=%s",
onecloud_cfg.get("private_key_path", "(none)"),
)
for node in ceph_vmnodes.values():
private_key_path = ""
private_key_password = None
bootstrap_key_path = ""
bootstrap_key_password = ""
ssh_username = "cephuser"
root_username = None # None = use default "root"
if cloud_type == "openstack":
glbs = osp_cred.get("globals") or {}
os_cfg = glbs.get("openstack-credentials") or {}
private_key_path = os_cfg.get("private_key_path", "")
private_key_password = os_cfg.get("private_key_password")
private_ip = node.get_private_ip()
ceph_nodename = node.node.name
elif "baremetal" in cloud_type:
private_key_path = node.private_key if node.private_key else ""
private_ip = node.ip_address
ceph_nodename = node.hostname
elif cloud_type == "ibmc":
glbs = osp_cred.get("globals")
ibmc = glbs.get("ibm-credentials")
private_key_path = ibmc.get("private_key_path")
private_ip = node.ip_address
ceph_nodename = node.hostname
elif cloud_type == "aws":
glbs = osp_cred.get("globals")
aws_cfg = glbs.get("aws-credentials")
private_key_path = aws_cfg.get("private_key_path", "")
private_ip = node.ip_address
ceph_nodename = node.hostname
elif cloud_type == "ocpvirt":
ocp_cfg = resolve_ocpvirt_credentials(osp_cred, custom_config)
private_key_path = ocp_cfg.get("private_key_path", "")
private_ip = node.ip_address
ceph_nodename = node.hostname
elif cloud_type == "onecloud":
private_ip = node.ip_address
ceph_nodename = node.hostname
onecloud_ssh_user = onecloud_cfg.get("ssh_user", "onecloud-user")
bootstrap_key_path = expand_private_key_path(
onecloud_cfg.get("bootstrap_key_path", "")
)
bootstrap_key_password = onecloud_cfg.get("bootstrap_key_password", "")
ssh_username = onecloud_ssh_user
root_username = onecloud_ssh_user
private_key_path = onecloud_cfg.get("private_key_path", "")
private_key_password = onecloud_cfg.get("private_key_password")
# SSH access overrides provided via the CLI
if ssh_private_key:
private_key_path = ssh_private_key
private_key_path = (
expand_private_key_path(private_key_path) if private_key_path else ""
)
if node.role == "win-iscsi-clients":
clients.append(
WinNode(ip_address=node.ip_address, private_ip=private_ip)
)
else:
# IPv6 attrs only when available (OpenStack dual-stack); other envs have no ipv6_* on node
ipv6_address = getattr(node, "ipv6_address", None)
ipv6_subnet = getattr(node, "ipv6_subnet", None)
ceph = CephNode(
username=ssh_username,
root_username=root_username,
private_key_path=private_key_path,
private_key_password=private_key_password,
bootstrap_key_path=bootstrap_key_path,
bootstrap_key_password=bootstrap_key_password,
ssh_pub_key=ssh_pub_key,
role=node.role,
no_of_volumes=node.no_of_volumes,
ipv4_address=node.ip_address,
ipv4_subnet=node.subnet,
private_ip=private_ip,
hostname=node.hostname,
ceph_vmnode=node,
ceph_nodename=ceph_nodename,
id=node.id,
ipv6_address=ipv6_address,
ipv6_subnet=ipv6_subnet,
use_ipv6=use_ipv6,
)
ceph_nodes.append(ceph)
cluster_name = cluster.get("ceph-cluster").get("name", "ceph")
ceph_cluster_dict[cluster_name] = Ceph(cluster_name, ceph_nodes)
# Drive IPv6 when requested via --custom-config use_ipv6=true (any infra)
ceph_cluster_dict[cluster_name].use_ipv6 = use_ipv6
# Set the network attributes of the cluster
# ToDo: Support other providers like openstack and IBM-C
if "baremetal" in cloud_type:
ceph_cluster_dict[cluster_name].networks = deepcopy(
cluster.get("ceph-cluster", {}).get("networks", {})
)
# TODO: refactor cluster dict to cluster list
log.info("Done creating osp instances")
log.info("Waiting for Floating IPs to be available")
if cloud_type == "onecloud":
wait_sec = 75
log.info("OneCloud: sleeping %ds for VM readiness", wait_sec)
time.sleep(wait_sec)
else:
log.info("Sleeping 15 Seconds")
time.sleep(15)
for cluster_name, cluster in ceph_cluster_dict.items():
for instance in cluster:
try:
instance.connect()
except BaseException:
raise
return ceph_cluster_dict, clients
def print_results(tc):
header = "\n{name:<30s} {desc:<60s} {duration:<30s} {status:<15s} {comments:>15s}".format(
name="TEST NAME",
desc="TEST DESCRIPTION",
duration="DURATION",
status="STATUS",
comments="COMMENTS",
)
print(header)
for test in tc:
if test.get("duration"):
dur = str(test["duration"])
else:
dur = "0s"
name = test["name"]
desc = test["desc"] or "None"
status = test["status"]
comments = test["comments"]
line = f"{name:<30.30s} {desc:<60.60s} {dur:<30s} {status:<15s} {comments:>15s}"
print(line)
def load_file(file_name):
"""Retrieve yaml data content from file."""
file_path = os.path.abspath(file_name)
with open(file_path, "r") as conf_:
content = yaml.safe_load(conf_)
return content
def configure_ssh_user(inventory: dict, pub_key: str) -> None:
"""
Authorize the provided public key for cephuser and root in the inventory's
cloud-init configuration.
The framework accesses the systems as cephuser (and root for privileged
operations), hence the key is authorized for both. A missing cephuser
entry is created along with its primary group and passwordless sudo
privileges.
Args:
inventory: content of the inventory file
pub_key: public key content (single line) to authorize
"""
instance = inventory.setdefault("instance", {})
try:
cloud_config = yaml.safe_load(instance.get("setup") or "") or {}
except yaml.YAMLError as err:
raise RuntimeError(f"Invalid cloud-config in the inventory: {err}")
if not isinstance(cloud_config, dict):
raise RuntimeError("The inventory instance setup is not a valid cloud-config.")
# Ensure the primary group of cephuser exists
groups = cloud_config.get("groups") or []
if "cephuser" not in groups:
groups.append("cephuser")
cloud_config["groups"] = groups
users = cloud_config.get("users") or []
def _user_entry(name, defaults):
entry = next(
(
user
for user in users
if isinstance(user, dict) and user.get("name") == name
),
None,
)
if entry is None:
entry = {"name": name, **defaults}
users.append(entry)
return entry
ceph_user = _user_entry(
"cephuser",
{
"primary-group": "cephuser",
"sudo": "ALL=(ALL) NOPASSWD:ALL",
"shell": "/bin/bash",
},
)
ceph_keys = ceph_user.setdefault("ssh-authorized-keys", [])
if pub_key not in ceph_keys:
ceph_keys.append(pub_key)
# The framework connects as root as well, hence the key must be authorized
# for root too.
root_user = _user_entry("root", {})
root_keys = root_user.setdefault("ssh-authorized-keys", [])
if pub_key not in root_keys:
root_keys.append(pub_key)
cloud_config["users"] = users
cloud_config["disable_root"] = False
content = yaml.safe_dump(cloud_config, sort_keys=False, default_flow_style=False)
instance["setup"] = f"#cloud-config\n{content}"
def get_tier_level(files: str) -> str:
"""
Retrieves the RHCS QE tier level based on the suite path or filename.
The argument contains "::" as a separate for multiple test suite execution. The
understanding in both the cases is that, the qe stage is provided at the starting
of the filename or directory.
Supported formats are
tier_0/
tier-1/
tier_0_rgw.yhaml
tier-1_cephadm.yaml
Args:
files (str): The suite files passed for execution.
Returns:
(str) Tier level
"""
file = files.split("::")[0]
file_name = file.split("/")[-1]
if file_name.startswith("tier_"):
return "-".join(file_name.split("_")[0:2])
if file_name.startswith("tier-"):
return file_name.split("_")[0]
return "Unknown"
def get_html_page(url: str) -> str:
"""Returns the content of the provided link."""
resp = requests.get(url, verify=False)
try:
if resp.ok:
return resp.text
except BaseException as be: # noqa
log.debug(f"Failed to retrieve contents at {url}")
return ""
def run(args):
import urllib3
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
# Mandatory arguments
rhbuild = args.get("--release") or args["--rhbuild"]
suite_files = args["--suite"]
glb_file = args.get("--global-conf")
if args.get("--cluster-conf"):
glb_file = args["--cluster-conf"]
# Deciders
reuse = args.get("--reuse")
cloud_type = args.get("--cloud")
# These are not mandatory options
inventory_file = args.get("--inventory")
osp_cred_file = args.get("--osp-cred")
# OneCloud: default to osp-cred-ci-2.yaml when --osp-cred not provided
if cloud_type == "onecloud" and osp_cred_file is None:
default_osp_cred = os.path.expanduser("~/osp-cred-ci-2.yaml")
if os.path.exists(default_osp_cred):
osp_cred_file = default_osp_cred
osp_cred = load_file(osp_cred_file) if osp_cred_file else dict()
cleanup_name = args.get("--cleanup")
# Set log directory and get absolute path
console_log_level = args.get("--log-level")
log_directory = args.get("--log-dir")
disable_console_log = args.get("--disable-console-log") or False
post_to_report_portal = args.get("--report-portal")
# Get Perf and CPU mon param
enable_perf_mon = args.get("--monitor-performance") or False
# jenkin job url
jenkin_job_url = os.environ.get("BUILD_URL")
run_id = generate_unique_id(length=6)
run_dir = create_run_dir(run_id, log_directory)
log.configure_logger("startup", run_dir, disable_console_log)
if console_log_level:
log.logger.setLevel(console_log_level.upper())
run_start_time = datetime.datetime.now()
trigger_user = getuser()
build = None
base_url = None
docker_registry = None
docker_image = None
docker_tag = None
ceph_name = None
if cleanup_name and not osp_cred:
raise Exception("Need cloud credentials to perform cleanup.")
if cleanup_name:
if cloud_type == "openstack":
cleanup_ceph_nodes(osp_cred, cleanup_name)
elif cloud_type == "ibmc":
cleanup_ibmc_ceph_nodes(
osp_cred, cleanup_name, custom_config=args.get("--custom-config")
)
elif cloud_type == "aws":
cleanup_aws_ceph_nodes(
osp_cred, cleanup_name, custom_config=args.get("--custom-config")
)
elif cloud_type == "onecloud":
cleanup_onecloud_ceph_nodes(
osp_cred, cleanup_name, custom_config=args.get("--custom-config")
)
elif cloud_type == "ocpvirt":
cleanup_ocpvirt_ceph_nodes(
osp_cred, cleanup_name, custom_config=args.get("--custom-config")
)
else:
log.warning("Unknown cloud type.")
return 0
if glb_file is None and not reuse:
raise Exception("Unable to gather information about cluster layout.")
if (
osp_cred_file is None
and not reuse
and cloud_type in ["openstack", "ibmc", "aws", "ocpvirt"]
):
raise Exception("Require cloud credentials to create cluster.")
if not reuse and cloud_type == "onecloud" and not osp_cred:
raise Exception(
"OneCloud requires credentials. Use --osp-cred <file> or place "
"globals.onecloud-credentials in ~/osp-cred-ci-2.yaml."
)
if (
inventory_file is None
and not reuse
and cloud_type in ["openstack", "ibmc", "aws", "onecloud", "ocpvirt"]
):
raise Exception("Require system configuration information to provision.")
# Required arguments to determine the test build details
product: str = args.get("--product") or "redhat"
release: str = args.get("--release") or rhbuild
platform: str = args["--platform"]
build: str = args.get("--build")
# Upstream
upstream_build = args.get("--upstream-build")
if upstream_build:
product = "community"
release = upstream_build
# FixMe: We should be using product for differentiation.
ibm_build = False
# disable coredump collection by default
collect_coredump = False
crimson = False
# Custom or override configurations
kernel_repo = args.get("--kernel-repo")
custom_config = args.get("--custom-config")
custom_config_file = args.get("--custom-config-file")
# Convert custom_config to a dict
custom_config_dict = {}
if custom_config:
custom_config_dict = {
item.split("=")[0]: item.split("=")[1] for item in custom_config
}
if "ibm-build" in custom_config_dict.keys():
ibm_build = bool(custom_config_dict["ibm-build"])
if ibm_build:
if upstream_build:
msg = "The following are not compatible --upstream-build and"
msg += " --custom-config ibm-build=True. Please rectify."
raise RuntimeError(msg)
product = "ibm"
if "crimson" in custom_config_dict.keys():
crimson = bool(custom_config_dict["crimson"])
# Setting to released by default is not right as there is case wherein it
# would be unavailable. Hence switching accordingly to released or nightly.
if build == "released":
try:
tmp_ctm = CephTestManifest(product, release, "released", platform)
_ = tmp_ctm.build_info
except RuntimeError:
log.debug("Switching to nightly as released section is unavailable.")
build = "nightly"
# Now handle the manifest. At this point we are allowing failures
ctm: CephTestManifest = CephTestManifest(
product, release, build, platform, crimson=crimson
)
base_url = args.get("--rhs-ceph-repo")
docker_registry = args.get("--docker-registry")
docker_image = args.get("--docker-image")
docker_tag = args.get("--docker-tag")
if not check_build_overrides(base_url, docker_registry, docker_image, docker_tag):
# In case the overrides are not valid, we are switching them to other inputs.
base_url = ctm.repository
docker_registry = ctm.ceph_image_dtr
docker_image = ctm.ceph_image_path
docker_tag = ctm.ceph_image_tag
store = args.get("--store") or False
docker_insecure_registry = args.get("--insecure-registry")
post_results = args.get("--post-results")
skip_setup = args.get("--skip-cluster")
skip_tc = args.get("--skip-tc")
if skip_tc:
skip_tc_list = (
[item for item in skip_tc.split(",")] if "," in skip_tc else [skip_tc]
)
else:
skip_tc_list = []
skip_subscription = args.get("--skip-subscription")
instances_name = args.get("--instances-name")
if instances_name:
instances_name = instances_name.replace(".", "-")
osp_image = args.get("--osp-image")
filestore = args.get("--filestore")
ec_pool_vals = args.get("--use-ec-pool")
skip_version_compare = args.get("--skip-version-compare")
xunit_results = args.get("--xunit-results")
enable_eus = args.get("--enable-eus")
skip_enabling_rhel_rpms = args.get("--skip-enabling-rhel-rpms")
skip_sos_report = args.get("--skip-sos-report")
# Pre define the variables for coredump and logs collection.
# By default we don't collect any logs.
collect_coredump = False
collect_ceph_logs = False
if "collect-coredump" in custom_config_dict.keys():
collect_coredump = bool(custom_config_dict["collect-coredump"])
if "collect-ceph-logs" in custom_config_dict.keys():
collect_ceph_logs = bool(custom_config_dict["collect-ceph-logs"])
# load config, suite and inventory yaml files
conf = load_file(glb_file)
suite = init_suite.load_suites(suite_files)
log.debug(f"Found the following valid test suites: {suite['tests']}")
if suite["nan"] and not suite["tests"]:
raise Exception("Please provide valid test suite name")
cli_arguments = f"{sys.executable} {' '.join(sys.argv)}"
log.info(f"The CLI for the current run :\n{cli_arguments}\n")
log.info(f"RPM Compose source - {base_url}")
log.info(
"Red Hat Ceph Image used - %s",
compose_container_image(docker_registry, docker_image, docker_tag),
)
ceph_version = [ctm.ceph_version]
distro = []
clients = []
inventory = None
image_name = None
if inventory_file:
inventory = load_file(inventory_file)
if osp_image and inventory.get("instance", {}).get("create"):
inventory.get("instance").get("create").update({"image-name": osp_image})
inv_create = inventory.get("instance", {}).get("create", {})
image_name = inv_create.get("image-name") or inv_create.get("image_id")
if inv_create and image_name is not None:
distro.append(str(image_name).replace(".iso", ""))
# The framework accesses the systems as cephuser (root for privileged
# operations) with the cloud credentials key by default. The key may be
# overridden via the CLI; the provided public key is then authorized for
# cephuser and root on the systems.
ssh_private_key = args.get("--ssh-private-key")
if ssh_private_key:
ssh_private_key = os.path.expanduser(ssh_private_key)
ssh_pub_key = args.get("--ssh-pub-key")
ssh_keys_overridden = bool(ssh_private_key or ssh_pub_key)
ssh_pub_key_content = None
if ssh_keys_overridden and reuse:
log.warning(
"--ssh-private-key/--ssh-pub-key are ignored with --reuse; the "
"cluster is accessed with the keys it was created with"
)
# Honor the warning: drop the override so the recreate-cluster path
# (which may create fresh nodes) uses the cloud-credentials key that
# the inventory authorizes. The override key was never authorized on
# the reused cluster's nodes, so keeping it would make every connect
# to freshly created nodes time out.
ssh_private_key = None
elif ssh_keys_overridden:
if ssh_private_key and not os.path.isfile(ssh_private_key):
raise RuntimeError(
f"The private key file {ssh_private_key} does not exist."
)
# The public key must be authorized on the systems. Fall back to the
# private key's counterpart when not provided explicitly.
pub_key_path = (
os.path.expanduser(ssh_pub_key) if ssh_pub_key else f"{ssh_private_key}.pub"
)
if not pub_key_path or not os.path.isfile(pub_key_path):
raise RuntimeError(
"Unable to locate the public key. Provide it using --ssh-pub-key or"
" place it alongside the private key as <private-key>.pub"
)
with open(pub_key_path, "r") as pub_key_fh:
ssh_pub_key_content = pub_key_fh.read().strip()
if not ssh_pub_key_content:
raise RuntimeError(f"The public key file {pub_key_path} is empty.")
log.info(
"Using cephuser with private key %s for system access",
ssh_private_key or "(runner default keys)",
)
# Ensure the public key is authorized for cephuser and root in the
# inventories so that the systems are accessible post deployment.
if inventory:
configure_ssh_user(inventory, ssh_pub_key_content)
for cluster in conf.get("globals") or []:
cluster_inventory_path = (cluster.get("ceph-cluster") or {}).get(
"inventory"
)
if not cluster_inventory_path:
continue
cluster_inventory_path = os.path.abspath(cluster_inventory_path)
with open(cluster_inventory_path, "r") as inv_fh:
cluster_inventory = yaml.safe_load(inv_fh) or {}
configure_ssh_user(cluster_inventory, ssh_pub_key_content)
# Node creation reads the cluster inventory from disk, hence the
# updated content is persisted and the reference updated.
updated_path = os.path.join(
run_dir, f"inventory-{os.path.basename(cluster_inventory_path)}"
)
with open(updated_path, "w") as updated_fh:
yaml.safe_dump(cluster_inventory, updated_fh, sort_keys=False)
cluster["ceph-cluster"]["inventory"] = updated_path
log.info("Updated cluster inventory: %s", updated_path)
for cluster in conf.get("globals"):
if cluster.get("ceph-cluster").get("inventory"):
cluster_inventory_path = os.path.abspath(
cluster.get("ceph-cluster").get("inventory")
)
with open(cluster_inventory_path, "r") as inventory_stream:
cluster_inventory = yaml.safe_load(inventory_stream)
inv_create = cluster_inventory.get("instance", {}).get("create", {})
image_name = inv_create.get("image-name") or inv_create.get("image_id")
if image_name is not None:
distro.append(str(image_name).replace(".iso", ""))
# Find the Ceph version
if build not in ["released", "cvp", "upstream", None]:
# By default, we assume the base url is taken from CI_MESSAGE
ver_url = f"{base_url}/compose/Tools/x86_64/os/Packages/"
# Incase we are executing from other environments
# For now, only switch if type is IBMC
if cloud_type and cloud_type.startswith("ibmc"):
ver_url = f"{base_url}/Tools/Packages/"
# Ceph Version
ver_text = get_html_page(url=ver_url)
search_results = re.search(r"ceph-common-(.*?).x86", ver_text)
if search_results:
ceph_version.append(search_results.group(1))
distro = ", ".join(list(set(distro)))
if build == "upstream":
ceph_version.append(upstream_build)
ceph_version = ", ".join(list(set(ceph_version)))
log.info("Testing Ceph Version: %s" % (ceph_version))
suite_name = "::".join(suite_files)
def fetch_test_details(var) -> dict:
"""
Accepts the test and then provides the parameters of that test as a list.
:param var: the test collected from the suite file
:return: Returns a dictionary of the various test params
"""
details = dict()
details["docker-containers-list"] = []
details["name"] = var.get("name")
details["desc"] = var.get("desc")
details["file"] = var.get("module")
details["cli_arguments"] = cli_arguments
details["polarion-id"] = var.get("polarion-id")
polarion_default_url = "https://polarion.engineering.redhat.com/polarion/#/project/CEPH/workitem?id="
details["polarion-id-link"] = "{}{}".format(
polarion_default_url, details["polarion-id"]
)
details["testrail-id"] = var.get("testrail-id")
details["rhbuild"] = rhbuild
details["cloud-type"] = cloud_type
details["ceph-version"] = ceph_version
details["platform"] = platform
details["product"] = product
details["release"] = release
details["distro"] = distro