Skip to content

Commit 25b06c9

Browse files
Merge pull request openshift#6966 from shiftstack/openstack_manifest_junit
openstack-manifests: Export JUnit results
2 parents e1728c8 + 8801811 commit 25b06c9

File tree

16 files changed

+176
-178
lines changed

16 files changed

+176
-178
lines changed

hack/openstack/test-manifests.sh

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,14 @@ while getopts a:c:e:f:i:t:pr:h o; do
8989
done
9090
readonly api_fip os_cloud external_network compute_flavor openshift_install tests_dir persist run
9191

92+
declare python_venv
93+
if [[ -w './bin' ]]; then
94+
python_venv="$(realpath './bin/venv')"
95+
else
96+
python_venv="$(mktemp -d)"
97+
fi
98+
readonly python_venv
99+
92100
declare -a temp_dirs
93101
cleanup() {
94102
if [[ "$persist" == 'NO' ]]; then
@@ -101,13 +109,21 @@ trap cleanup EXIT
101109

102110
validate_configuration
103111

112+
python -m venv "$python_venv"
113+
# shellcheck source=/dev/null
114+
source "${python_venv}/bin/activate"
115+
pip install unittest-xml-reporting pyyaml
116+
104117
>&2 echo "Running the tests from '${tests_dir}' against the Installer binary '${openshift_install}'."
105118

119+
export JUNIT_DIR="${ARTIFACT_DIR:-.}/junit"
120+
mkdir -p "$JUNIT_DIR"
121+
106122
declare result='PASS'
107123
for testcase in "${tests_dir}"/* ; do
108124
if [ -d "$testcase" ] && [[ "$testcase" =~ $run ]]; then
109125
echo
110-
echo "*** TEST CASE: $(basename "${testcase}")"
126+
echo "*** TEST CASE: $(basename -- "$testcase")"
111127
assets_dir="$(mktemp -d)"
112128
if [[ "$persist" != 'NO' ]]; then
113129
echo "Generated assets for this test can be found in ${assets_dir}"
@@ -117,6 +133,12 @@ for testcase in "${tests_dir}"/* ; do
117133
fill_install_config "${testcase}/install-config.yaml" > "${assets_dir}/install-config.yaml"
118134
"$openshift_install" --log-level warn create manifests --dir "$assets_dir"
119135
for t in "${testcase}"/test_*; do
136+
declare JUNIT_FILE test_name
137+
test_name="$(basename -- "$t")"
138+
test_name="${test_name#test_}"
139+
test_name="${test_name%.*}"
140+
JUNIT_FILE="${JUNIT_DIR}/$(basename -- "${testcase}")_${test_name}.xml"
141+
export JUNIT_FILE
120142
if $t "$assets_dir"; then
121143
echo "PASS: '$t'"
122144
else

scripts/openstack/manifest-tests/cinder-availability-zones/test_machines.py

Lines changed: 51 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,25 @@
22
# -*- coding: utf-8 -*-
33

44
import unittest
5+
import xmlrunner
56

7+
import os
68
import sys
79
import glob
810
import yaml
911

1012
ASSETS_DIR = ""
1113

12-
EXPECTED_MACHINES_NUMBER = 10
14+
EXPECTED_MASTER_REPLICAS = 10
15+
EXPECTED_WORKER_REPLICAS = 1000
16+
1317
EXPECTED_MASTER_ZONE_NAMES = ["MasterAZ1", "MasterAZ2", "MasterAZ3"]
18+
EXPECTED_WORKER_ZONE_NAMES = ["ComputeAZ1", "ComputeAZ2", "ComputeAZ3"]
19+
1420
EXPECTED_VOLUME_ZONE_NAMES = ["VolumeAZ1", "VolumeAZ2", "VolumeAZ3"]
1521

1622

17-
class TestVolumeAZMachines(unittest.TestCase):
23+
class CinderAvailabilityZonesMachines(unittest.TestCase):
1824
def setUp(self):
1925
"""Parse the Machines into a Python data structure."""
2026
self.machines = []
@@ -35,7 +41,7 @@ def test_zone_names(self):
3541

3642
def test_total_instance_number(self):
3743
"""Assert that there are as many Machines as required ControlPlane replicas."""
38-
self.assertEqual(len(self.machines), EXPECTED_MACHINES_NUMBER)
44+
self.assertEqual(len(self.machines), EXPECTED_MASTER_REPLICAS)
3945

4046
def test_replica_distribution(self):
4147
"""Assert that machines are evenly distributed across volume azs."""
@@ -52,6 +58,47 @@ def test_replica_distribution(self):
5258
self.assertTrue(-2 < replicas - setpoint < 2)
5359

5460

61+
class CinderAvailabilityZonesMachinesets(unittest.TestCase):
62+
def setUp(self):
63+
"""Parse the MachineSets into a Python data structure."""
64+
self.machinesets = []
65+
for machineset_path in glob.glob(
66+
f'{ASSETS_DIR}/openshift/99_openshift-cluster-api_worker-machineset-*.yaml'
67+
):
68+
with open(machineset_path) as f:
69+
self.machinesets.append(yaml.load(f, Loader=yaml.FullLoader))
70+
71+
def test_machineset_zone_name(self):
72+
"""Assert that there is exactly one MachineSet per volume availability zone."""
73+
found = []
74+
for machineset in self.machinesets:
75+
master_zone = machineset["spec"]["template"]["spec"]["providerSpec"]["value"]["availabilityZone"]
76+
volume_zone = machineset["spec"]["template"]["spec"]["providerSpec"]["value"]["rootVolume"]["availabilityZone"]
77+
self.assertIn(volume_zone, EXPECTED_VOLUME_ZONE_NAMES)
78+
self.assertNotIn(volume_zone, found)
79+
self.assertEqual(master_zone[-3:], volume_zone[-3:])
80+
found.append(volume_zone)
81+
self.assertEqual(len(self.machinesets), len(EXPECTED_VOLUME_ZONE_NAMES))
82+
83+
def test_total_replica_number(self):
84+
"""Assert that replicas spread across the MachineSets add up to the expected number."""
85+
total_found = 0
86+
for machineset in self.machinesets:
87+
total_found += machineset["spec"]["replicas"]
88+
self.assertEqual(total_found, EXPECTED_WORKER_REPLICAS)
89+
90+
def test_replica_distribution(self):
91+
"""Assert that replicas are evenly distributed across machinesets."""
92+
setpoint = 0
93+
for machineset in self.machinesets:
94+
replicas = machineset["spec"]["replicas"]
95+
if setpoint == 0:
96+
setpoint = replicas
97+
else:
98+
self.assertTrue(-2 < replicas - setpoint < 2)
99+
100+
55101
if __name__ == '__main__':
56102
ASSETS_DIR = sys.argv.pop()
57-
unittest.main(verbosity=2)
103+
with open(os.environ.get('JUNIT_FILE', '/dev/null'), 'wb') as output:
104+
unittest.main(testRunner=xmlrunner.XMLTestRunner(output=output), failfast=False, buffer=False, catchbreak=False, verbosity=2)

scripts/openstack/manifest-tests/cinder-availability-zones/test_machinesets.py

Lines changed: 0 additions & 59 deletions
This file was deleted.

scripts/openstack/manifest-tests/failure-domains/test_machines.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,18 @@
22
# -*- coding: utf-8 -*-
33

44
import unittest
5+
import xmlrunner
56

67
import os
78
import sys
89
import glob
910
import yaml
1011

1112
ASSETS_DIR = ""
12-
INSTALLCONFIG_PATH = ""
13+
INSTALLCONFIG_PATH = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'install-config.yaml')
1314

1415

15-
class TestMachines(unittest.TestCase):
16+
class FailureDomainsMachines(unittest.TestCase):
1617
def setUp(self):
1718
"""Parse the expected values from install-config and collect Machine resources."""
1819
self.machines = []
@@ -123,5 +124,5 @@ def test_storage_zone_names(self):
123124

124125
if __name__ == '__main__':
125126
ASSETS_DIR = sys.argv.pop()
126-
INSTALLCONFIG_PATH = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'install-config.yaml')
127-
unittest.main(verbosity=2)
127+
with open(os.environ.get('JUNIT_FILE', '/dev/null'), 'wb') as output:
128+
unittest.main(testRunner=xmlrunner.XMLTestRunner(output=output), failfast=False, buffer=False, catchbreak=False, verbosity=2)

scripts/openstack/manifest-tests/default-stable-lb/install-config.yaml renamed to scripts/openstack/manifest-tests/lb-default-stable/install-config.yaml

File renamed without changes.

scripts/openstack/manifest-tests/default-stable-lb/test_cluster-infra.py renamed to scripts/openstack/manifest-tests/lb-default-stable/test_cluster-infra.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,16 @@
22
# -*- coding: utf-8 -*-
33

44
import unittest
5+
import xmlrunner
56

7+
import os
68
import sys
79
import glob
810
import yaml
911

1012
ASSETS_DIR = ""
1113

12-
class TestClusterInfraObject(unittest.TestCase):
14+
class DefaultStableLoadBalancerClusterInfraObject(unittest.TestCase):
1315
def setUp(self):
1416
"""Parse the Cluster Infrastructure object into a Python data structure."""
1517
self.machines = []
@@ -24,4 +26,5 @@ def test_load_balancer(self):
2426

2527
if __name__ == '__main__':
2628
ASSETS_DIR = sys.argv.pop()
27-
unittest.main(verbosity=2)
29+
with open(os.environ.get('JUNIT_FILE', '/dev/null'), 'wb') as output:
30+
unittest.main(testRunner=xmlrunner.XMLTestRunner(output=output), failfast=False, buffer=False, catchbreak=False, verbosity=2)

scripts/openstack/manifest-tests/default-techpreview-lb/install-config.yaml renamed to scripts/openstack/manifest-tests/lb-default-techpreview/install-config.yaml

File renamed without changes.

scripts/openstack/manifest-tests/default-techpreview-lb/test_cluster-infra.py renamed to scripts/openstack/manifest-tests/lb-default-techpreview/test_cluster-infra.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,16 @@
22
# -*- coding: utf-8 -*-
33

44
import unittest
5+
import xmlrunner
56

7+
import os
68
import sys
79
import glob
810
import yaml
911

1012
ASSETS_DIR = ""
1113

12-
class TestClusterInfraObject(unittest.TestCase):
14+
class DefaultTechPreviewLoadBalancerClusterInfraObject(unittest.TestCase):
1315
def setUp(self):
1416
"""Parse the Cluster Infrastructure object into a Python data structure."""
1517
self.machines = []
@@ -24,4 +26,5 @@ def test_load_balancer(self):
2426

2527
if __name__ == '__main__':
2628
ASSETS_DIR = sys.argv.pop()
27-
unittest.main(verbosity=2)
29+
with open(os.environ.get('JUNIT_FILE', '/dev/null'), 'wb') as output:
30+
unittest.main(testRunner=xmlrunner.XMLTestRunner(output=output), failfast=False, buffer=False, catchbreak=False, verbosity=2)

scripts/openstack/manifest-tests/openshift-managed-lb/install-config.yaml renamed to scripts/openstack/manifest-tests/lb-managed/install-config.yaml

File renamed without changes.

scripts/openstack/manifest-tests/openshift-managed-lb/test_cluster-infra.py renamed to scripts/openstack/manifest-tests/lb-managed/test_cluster-infra.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,24 @@
22
# -*- coding: utf-8 -*-
33

44
import unittest
5+
import xmlrunner
56

7+
import os
68
import sys
79
import glob
810
import yaml
911

1012
ASSETS_DIR = ""
1113

12-
class TestClusterInfraObject(unittest.TestCase):
14+
class ManagedLoadBalancer(unittest.TestCase):
1315
def setUp(self):
1416
"""Parse the Cluster Infrastructure object into a Python data structure."""
1517
self.machines = []
1618
cluster_infra = f'{ASSETS_DIR}/manifests/cluster-infrastructure-02-config.yml'
1719
with open(cluster_infra) as f:
1820
self.cluster_infra = yaml.load(f, Loader=yaml.FullLoader)
1921

20-
def test_load_balancer(self):
22+
def test_cluster_infra_object(self):
2123
"""Assert that the Cluster infrastructure object contains the LoadBalancer configuration."""
2224
self.assertIn("loadBalancer", self.cluster_infra["status"]["platformStatus"]["openstack"])
2325

@@ -29,4 +31,5 @@ def test_load_balancer(self):
2931

3032
if __name__ == '__main__':
3133
ASSETS_DIR = sys.argv.pop()
32-
unittest.main(verbosity=2)
34+
with open(os.environ.get('JUNIT_FILE', '/dev/null'), 'wb') as output:
35+
unittest.main(testRunner=xmlrunner.XMLTestRunner(output=output), failfast=False, buffer=False, catchbreak=False, verbosity=2)

0 commit comments

Comments
 (0)