From bf5c52c71415336ff29212a13cad58ae7f5d3d31 Mon Sep 17 00:00:00 2001 From: oharan2 Date: Wed, 6 Sep 2023 11:55:26 +0300 Subject: [PATCH 1/5] Update catalog_source class constructor and documentation --- ocp_resources/catalog_source.py | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/ocp_resources/catalog_source.py b/ocp_resources/catalog_source.py index ae896c67c2..7d8af60799 100644 --- a/ocp_resources/catalog_source.py +++ b/ocp_resources/catalog_source.py @@ -1,34 +1,32 @@ -from ocp_resources.constants import TIMEOUT_4MINUTES from ocp_resources.resource import NamespacedResource class CatalogSource(NamespacedResource): + """ + https://olm.operatorframework.io/docs/concepts/crds/catalogsource/ + """ + api_group = NamespacedResource.ApiGroup.OPERATORS_COREOS_COM def __init__( self, - name=None, - namespace=None, - client=None, source_type=None, image=None, display_name=None, publisher=None, - teardown=True, - yaml_file=None, - delete_timeout=TIMEOUT_4MINUTES, update_strategy_registry_poll_interval=None, **kwargs, ): - super().__init__( - name=name, - namespace=namespace, - client=client, - teardown=teardown, - yaml_file=yaml_file, - delete_timeout=delete_timeout, - **kwargs, - ) + """ + Args: + source_type (str): Name of the source type. + image (str): Image index for the catalog. + display_name (str): Display name for the catalog in the web console and CLI. + publisher (str): Name of the publisher. + update_strategy_registry_poll_interval (str, optional): Time interval between checks of the latest + catalog_source version. + """ + super().__init__(**kwargs) self.source_type = source_type self.image = image self.display_name = display_name @@ -50,7 +48,6 @@ def to_dict(self): } } ) - if self.update_strategy_registry_poll_interval: self.res["spec"].update( { From 7866a969e091a58b175ebcce2a2d53999a749f81 Mon Sep 17 00:00:00 2001 From: oharan2 Date: Mon, 11 Sep 2023 14:50:56 +0300 Subject: [PATCH 2/5] Add to_dict parameter validtion --- ocp_resources/catalog_source.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/ocp_resources/catalog_source.py b/ocp_resources/catalog_source.py index 7d8af60799..ea1f05e538 100644 --- a/ocp_resources/catalog_source.py +++ b/ocp_resources/catalog_source.py @@ -38,6 +38,9 @@ def __init__( def to_dict(self): super().to_dict() if not self.yaml_file: + if not any([self.source_type,self.image,self.display_name,self.publisher]): + raise ValueError("Passing yaml_file or all parameters 'source_type', 'image', 'display_name' " + "and 'publisher' is required.") self.res.update( { "spec": { From b596b34bb44d72dadcbca792ae5c4e550b95de6f Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 11 Sep 2023 11:51:24 +0000 Subject: [PATCH 3/5] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- ocp_resources/catalog_source.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/ocp_resources/catalog_source.py b/ocp_resources/catalog_source.py index ea1f05e538..07acff78d0 100644 --- a/ocp_resources/catalog_source.py +++ b/ocp_resources/catalog_source.py @@ -38,9 +38,13 @@ def __init__( def to_dict(self): super().to_dict() if not self.yaml_file: - if not any([self.source_type,self.image,self.display_name,self.publisher]): - raise ValueError("Passing yaml_file or all parameters 'source_type', 'image', 'display_name' " - "and 'publisher' is required.") + if not any( + [self.source_type, self.image, self.display_name, self.publisher] + ): + raise ValueError( + "Passing yaml_file or all parameters 'source_type', 'image'," + " 'display_name' and 'publisher' is required." + ) self.res.update( { "spec": { From 5f40cffc1497d7b17b8fc31b738118b64569551d Mon Sep 17 00:00:00 2001 From: oharan2 Date: Mon, 11 Sep 2023 14:53:11 +0300 Subject: [PATCH 4/5] Fix logic --- ocp_resources/catalog_source.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ocp_resources/catalog_source.py b/ocp_resources/catalog_source.py index ea1f05e538..c2a5fdbdb1 100644 --- a/ocp_resources/catalog_source.py +++ b/ocp_resources/catalog_source.py @@ -38,7 +38,7 @@ def __init__( def to_dict(self): super().to_dict() if not self.yaml_file: - if not any([self.source_type,self.image,self.display_name,self.publisher]): + if not all([self.source_type, self.image, self.display_name, self.publisher]): raise ValueError("Passing yaml_file or all parameters 'source_type', 'image', 'display_name' " "and 'publisher' is required.") self.res.update( From dbbed5edfac861d0e62649b0567dd778a40c407e Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 11 Sep 2023 11:54:38 +0000 Subject: [PATCH 5/5] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- ocp_resources/catalog_source.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/ocp_resources/catalog_source.py b/ocp_resources/catalog_source.py index c2a5fdbdb1..1e03861c98 100644 --- a/ocp_resources/catalog_source.py +++ b/ocp_resources/catalog_source.py @@ -38,9 +38,13 @@ def __init__( def to_dict(self): super().to_dict() if not self.yaml_file: - if not all([self.source_type, self.image, self.display_name, self.publisher]): - raise ValueError("Passing yaml_file or all parameters 'source_type', 'image', 'display_name' " - "and 'publisher' is required.") + if not all( + [self.source_type, self.image, self.display_name, self.publisher] + ): + raise ValueError( + "Passing yaml_file or all parameters 'source_type', 'image'," + " 'display_name' and 'publisher' is required." + ) self.res.update( { "spec": {