Skip to content

Commit ad3e266

Browse files
authored
Merge pull request #231 from 14rcole/check-for-deprecated-apis
[CVP-2252] Add checks for deprecated APIs to midstream pipeline
2 parents b681777 + bb6b519 commit ad3e266

File tree

2 files changed

+82
-6
lines changed

2 files changed

+82
-6
lines changed

Dockerfiles/midstream/unit_tests.py

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def get_error_message_content(output_file=".errormessage"):
3131

3232
# Running the container with correctly set environment variables, default channel missing, all tasks should pass
3333
def test_positive_missing_default_channel(self):
34-
self.env["IMAGE_TO_TEST"] = "quay.io/cvpops/test-operator:missing-default-channel-v1"
34+
self.env["IMAGE_TO_TEST"] = "quay.io/cvpops/test-operator:missing-default-channel-v2"
3535
result = subprocess.run(self.exec_cmd,
3636
shell=True,
3737
env=self.env,
@@ -80,10 +80,27 @@ def test_negative_image_to_test_not_set(self):
8080
"Result code not found in %s" % message)
8181
self.assertEqual(102, result.returncode)
8282
self.assertTrue(os.path.exists(OUTPUT_DIR+".errormessage"))
83-
83+
84+
# Run with a test-operator which fails the deprecated image check in the
85+
# bundle image validation job
86+
def test_default_negative(self):
87+
self.env["IMAGE_TO_TEST"] = "quay.io/cvpops/test-operator:test-default-negative-v1"
88+
result = subprocess.run(self.exec_cmd,
89+
shell=True,
90+
env=self.env,
91+
cwd=OUTPUT_DIR)
92+
self.assertEqual(70, result.returncode)
93+
# check if the .errormessage file generated is empty
94+
self.assertTrue(os.stat("/tmp/.errormessage").st_size != 0)
95+
# check if the .errormessage exists since its a logger file
96+
self.assertTrue(os.path.exists(OUTPUT_DIR+".errormessage"))
97+
message = self.get_error_message_content()
98+
self.assertIn("this bundle is using APIs which were deprecated and removed in v1.22", message,
99+
"Deprecated APIs error not found in '%s'" % message)
100+
84101
# Run with a test-operator which passes the bundle image validation job
85102
def test_default_positive(self):
86-
self.env["IMAGE_TO_TEST"] = "quay.io/cvpops/test-operator:v1.0-16"
103+
self.env["IMAGE_TO_TEST"] = "quay.io/cvpops/test-operator:test-default-positive-v1"
87104
result = subprocess.run(self.exec_cmd,
88105
shell=True,
89106
env=self.env,

roles/validate_operator_bundle/tasks/main.yml

Lines changed: 62 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,69 @@
2828
bundle_validate: "{{ operator_work_dir }}"
2929
when: not run_upstream|bool
3030

31-
- name: "Set the operatorhub checks if enabled"
31+
- name: "list work_dir"
32+
shell: "ls {{ work_dir }}"
33+
34+
- name: "Check whether bundle supports v4.9 or higher"
35+
block:
36+
- name: Get skopeo inspect json
37+
shell: "cat {{ work_dir }}/bundle-skopeo-inspect.json"
38+
register: bundle_skopeo_inspect_json
39+
40+
- name: Convert json to map
41+
set_fact:
42+
bundle_skopeo_inspect_map: "{{ bundle_skopeo_inspect_json.stdout | from_json }}"
43+
44+
- name: Determine ocp version annotation
45+
set_fact:
46+
ocp_version_annotation: "{{ bundle_skopeo_inspect_map['Labels']['com.redhat.openshift.versions'] }}"
47+
48+
- name: "Determine OCP version range"
49+
uri:
50+
url: "https://catalog.redhat.com/api/containers/v1/operators/indices?sort_by=data.ocp_version&ocp_versions_range={{ ocp_version_annotation }}&organization=redhat-operators"
51+
method: GET
52+
headers:
53+
Accept: "application/json"
54+
status_code: 200
55+
return_content: true
56+
register: supported_indices_json
57+
retries: 10
58+
ignore_errors: true
59+
60+
- name: "Fail if Pyxis response is not 200"
61+
fail:
62+
msg: "Error collecting OCP version range from Pyxis. Error message: {{ supported_indices_json.content }}"
63+
when: supported_indices_json.status != 200
64+
65+
- name: "Convert output to map"
66+
set_fact:
67+
supported_indices: "{{ supported_indices_json.content | from_json }}"
68+
69+
- name: debug
70+
debug:
71+
msg: "Indices: {{ supported_indices['data'] }}"
72+
73+
- name: "Set support_v4_9 to false if there are no supported versions"
74+
set_fact:
75+
support_v4_9: false
76+
when: supported_indices['data']|length==0
77+
78+
- name: "Parse values returned from Pyxis"
79+
set_fact:
80+
highest_index: "{{ supported_indices['data'] | last }}"
81+
when: supported_indices['data']|length>0
82+
83+
- name: "Determine if v4.9 is supported"
84+
set_fact:
85+
support_v4_9: "{{ highest_index['ocp_version'] is version('4.9', '>=') }}"
86+
when:
87+
- highest_index is defined
88+
- highest_index['ocp_version']|length>0
89+
90+
- name: "Set the operatorhub checks if bundle supports v4.9 or greater"
3291
set_fact:
33-
select_optional_tests: "--select-optional name=operatorhub"
34-
when: run_operatorhub_checks|bool
92+
select_optional_tests: "--select-optional name=operatorhub --optional-values=k8s-version=1.22"
93+
when: support_v4_9
3594

3695
- name: "Validate the operator bundle manifest and metadata with operator-sdk bundle validate"
3796
shell: "{{ operator_sdk_bin_path }} bundle validate {{ select_optional_tests }} --verbose {{ bundle_validate }} 2>&1"

0 commit comments

Comments
 (0)