From ff38bf3403362a63ef83e29d2c29bb11c691bb08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pavel=20Mac=C3=ADk?= Date: Thu, 6 Oct 2022 15:24:02 +0200 Subject: [PATCH] Ensure the desired install plan is approved in acceptance tests (#1250) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Pavel MacĂ­k --- test/acceptance/features/steps/olm.py | 5 +++-- test/acceptance/features/steps/openshift.py | 20 ++++++++++++++----- ...portExistingOperatorBackedServices.feature | 12 +++++------ 3 files changed, 24 insertions(+), 13 deletions(-) diff --git a/test/acceptance/features/steps/olm.py b/test/acceptance/features/steps/olm.py index 4c48a61a50..67d51df41a 100644 --- a/test/acceptance/features/steps/olm.py +++ b/test/acceptance/features/steps/olm.py @@ -52,11 +52,12 @@ def install_catalog_source(self): return self.openshift.wait_for_package_manifest(self.package_name, self.operator_catalog_source_name, self.operator_catalog_channel) def install_operator_subscription(self, csv_version=None, install_mode=InstallMode.Automatic): + csv_version_resolved = self.operator_subscription_csv_version if csv_version is None else csv_version install_sub_output = self.openshift.create_operator_subscription( self.package_name, self.operator_catalog_source_name, self.operator_catalog_channel, self.operator_catalog_namespace, - self.operator_subscription_csv_version if csv_version is None else csv_version, install_mode) + csv_version_resolved, install_mode) if re.search(r'.*subscription.operators.coreos.com/%s\s(unchanged|created)' % self.package_name, install_sub_output) is None: print("Failed to create {} operator subscription".format(self.package_name)) return False - self.openshift.approve_operator_subscription(self.package_name) + self.openshift.approve_operator_subscription(self.package_name, csv_version_resolved) return True diff --git a/test/acceptance/features/steps/openshift.py b/test/acceptance/features/steps/openshift.py index 69c83be388..9e44f51f6f 100644 --- a/test/acceptance/features/steps/openshift.py +++ b/test/acceptance/features/steps/openshift.py @@ -399,7 +399,7 @@ def create_operator_subscription(self, package_name, operator_source_name, chann return self.create_operator_subscription_to_namespace(package_name, self.operators_namespace, operator_source_name, channel, operator_source_namespace, csv_version, install_mode) - def get_install_plan_for_subscription(self, subscription_name, subscription_namespace, csv_version=None): + def get_install_plan_for_subscription(self, subscription_name, subscription_namespace): # wait for install plan cmd = f"{ctx.cli} get subscription {subscription_name} -n {subscription_namespace} -o json | jq -rc '.status.installplan.name'" polling2.poll(target=lambda: tuple(self.cmd.run(cmd)), check_success=lambda o: o[1] == 0 and o[0].startswith( @@ -411,16 +411,26 @@ def get_install_plan_for_subscription(self, subscription_name, subscription_name return install_plan.strip() - def approve_operator_subscription_in_namespace(self, name, namespace): + def approve_operator_subscription_in_namespace(self, name, namespace, csv_version=None): # get the install plan install_plan = self.get_install_plan_for_subscription(name, namespace) + + # patch CSV for install plan + if csv_version is not None: + print(f"Patching {install_plan} install plan for {csv_version} CSV") + patch = f'{{"spec": {{"clusterServiceVersionNames": ["{csv_version}"] }}}}' + cmd = f"{ctx.cli} patch installplan {install_plan} -n {namespace} -p '{patch}' --type=merge" + (output, exit_code) = self.cmd.run(cmd) + assert exit_code == 0, f"Unable to patch CSV version for '{install_plan}' install plan:\n {output}" + # approve install plan + print(f"Approving {install_plan} install plan") cmd = f'{ctx.cli} -n {namespace} patch installplan {install_plan} --type merge --patch \'{{"spec": {{"approved": true}}}}\'' (output, exit_code) = self.cmd.run(cmd) - assert exit_code == 0, f"Unable to patch the '{install_plan} install plan to approve it:\n{output}" + assert exit_code == 0, f"Unable to patch the {install_plan} install plan to approve it:\n{output}" - def approve_operator_subscription(self, name): - self.approve_operator_subscription_in_namespace(name, self.operators_namespace) + def approve_operator_subscription(self, name, csv_version=None): + self.approve_operator_subscription_in_namespace(name, self.operators_namespace, csv_version) def get_resource_list_in_namespace(self, resource_plural, name_pattern, namespace): print(f"Searching for {resource_plural} that matches {name_pattern} in {namespace} namespace") diff --git a/test/acceptance/features/supportExistingOperatorBackedServices.feature b/test/acceptance/features/supportExistingOperatorBackedServices.feature index bdea250cd8..5d807a0066 100644 --- a/test/acceptance/features/supportExistingOperatorBackedServices.feature +++ b/test/acceptance/features/supportExistingOperatorBackedServices.feature @@ -193,7 +193,7 @@ Feature: Support a number of existing operator-backed services out of the box schedule: "0 4 * * *" pxc: size: 1 - image: percona/percona-xtradb-cluster:8.0.27-18.1 + image: docker.io/percona/percona-xtradb-cluster:8.0.27-18.1 volumeSpec: persistentVolumeClaim: resources: @@ -202,10 +202,10 @@ Feature: Support a number of existing operator-backed services out of the box haproxy: enabled: true size: 1 - image: percona/percona-xtradb-cluster-operator:1.11.0-haproxy + image: docker.io/percona/percona-xtradb-cluster-operator:1.11.0-haproxy logcollector: enabled: true - image: percona/percona-xtradb-cluster-operator:1.11.0-logcollector + image: docker.io/percona/percona-xtradb-cluster-operator:1.11.0-logcollector """ * Condition ready=True for PerconaXtraDBCluster/minimal-cluster resource is met When Service Binding is applied @@ -269,7 +269,7 @@ Feature: Support a number of existing operator-backed services out of the box schedule: "0 4 * * *" pxc: size: 1 - image: percona/percona-xtradb-cluster:8.0.27-18.1 + image: docker.io/percona/percona-xtradb-cluster:8.0.27-18.1 volumeSpec: persistentVolumeClaim: resources: @@ -278,10 +278,10 @@ Feature: Support a number of existing operator-backed services out of the box haproxy: enabled: true size: 1 - image: percona/percona-xtradb-cluster-operator:1.11.0-haproxy + image: docker.io/percona/percona-xtradb-cluster-operator:1.11.0-haproxy logcollector: enabled: true - image: percona/percona-xtradb-cluster-operator:1.11.0-logcollector + image: docker.io/percona/percona-xtradb-cluster-operator:1.11.0-logcollector """ When Service Binding is applied """