From 78de470efe211331c47cd529354a3e683c6931f1 Mon Sep 17 00:00:00 2001 From: Jan Hutar Date: Thu, 9 Nov 2023 08:18:11 +0100 Subject: [PATCH 1/6] fix: DOCKERFILE_HADOLINT: DL4000 error: MAINTAINER is deprecated --- Containerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Containerfile b/Containerfile index 7417e32..ba77259 100644 --- a/Containerfile +++ b/Containerfile @@ -1,5 +1,5 @@ FROM registry.fedoraproject.org/fedora:36 -MAINTAINER "Jan Hutar" +LABEL maintainer="jhutar@redhat.com" RUN dnf -y install python3-boto3 python3-virtualenv python3-pip python3-psycopg2 python3-requests python3-psutil python3-pyyaml postgresql git-core dumb-init 'dnf-command(builddep)' \ && dnf -y builddep python3-requests python3-psutil \ From 1dcf12e56e1e6123379fefa4ab49206d960c2cc1 Mon Sep 17 00:00:00 2001 From: Jan Hutar Date: Thu, 9 Nov 2023 08:30:32 +0100 Subject: [PATCH 2/6] fix: jscpd: Clone found --- core/opl/status_data_updater.py | 27 ++++++++++++--------------- opl/status_data_updater.py | 27 ++++++++++++--------------- 2 files changed, 24 insertions(+), 30 deletions(-) diff --git a/core/opl/status_data_updater.py b/core/opl/status_data_updater.py index ec84f57..60477ee 100755 --- a/core/opl/status_data_updater.py +++ b/core/opl/status_data_updater.py @@ -120,11 +120,7 @@ def doit_list(args): table = [] for item in response["hits"]["hits"]: - logging.debug( - f"Loading data from document ID {item['_id']} with field id={item['_source']['id'] if 'id' in item['_source'] else None}" - ) - tmpfile = tempfile.NamedTemporaryFile(prefix=item["_id"], delete=False).name - sd = opl.status_data.StatusData(tmpfile, data=item["_source"]) + sd = _create_sd_from_es_response(item) row = [ sd.get("id"), sd.get("started"), @@ -146,11 +142,7 @@ def doit_change(args): source = response["hits"]["hits"][0] es_type = source["_type"] es_id = source["_id"] - logging.debug( - f"Loading data from document ID {source['_id']} with field id={source['_source']['id']}" - ) - tmpfile = tempfile.NamedTemporaryFile(prefix=source["_id"], delete=False).name - sd = opl.status_data.StatusData(tmpfile, data=source["_source"]) + sd = _create_sd_from_es_response(source) for item in args.change_set: if item == "": @@ -274,6 +266,15 @@ def _get_rp_launch_results(session, args, launch): return results +def _create_sd_from_es_response(response): + """Convert ElasticSearch response data structure to StatusData object.""" + logging.debug( + f"Loading data from document ID {response['_id']} with field id={response['_source']['id'] if 'id' in response['_source'] else None}" + ) + tmpfile = tempfile.NamedTemporaryFile(prefix=response["_id"], delete=False).name + return opl.status_data.StatusData(tmpfile, data=response["_source"]) + + def _get_es_result_for_rp_result(session, args, run_id, result): if args.rp_project == "satcpt": # OK, I agree we need a better way here. @@ -303,11 +304,7 @@ def _get_es_result_for_rp_result(session, args, run_id, result): raise Exception(f"Failed to find test result in ES for {run_id}") es_type = source["_type"] es_id = source["_id"] - logging.debug( - f"Loading data from document ID {source['_id']} with field id={source['_source']['id']}" - ) - tmpfile = tempfile.NamedTemporaryFile(prefix=source["_id"], delete=False).name - sd = opl.status_data.StatusData(tmpfile, data=source["_source"]) + sd = _create_sd_from_es_response(source) return (sd, es_type, es_id) diff --git a/opl/status_data_updater.py b/opl/status_data_updater.py index ec84f57..60477ee 100755 --- a/opl/status_data_updater.py +++ b/opl/status_data_updater.py @@ -120,11 +120,7 @@ def doit_list(args): table = [] for item in response["hits"]["hits"]: - logging.debug( - f"Loading data from document ID {item['_id']} with field id={item['_source']['id'] if 'id' in item['_source'] else None}" - ) - tmpfile = tempfile.NamedTemporaryFile(prefix=item["_id"], delete=False).name - sd = opl.status_data.StatusData(tmpfile, data=item["_source"]) + sd = _create_sd_from_es_response(item) row = [ sd.get("id"), sd.get("started"), @@ -146,11 +142,7 @@ def doit_change(args): source = response["hits"]["hits"][0] es_type = source["_type"] es_id = source["_id"] - logging.debug( - f"Loading data from document ID {source['_id']} with field id={source['_source']['id']}" - ) - tmpfile = tempfile.NamedTemporaryFile(prefix=source["_id"], delete=False).name - sd = opl.status_data.StatusData(tmpfile, data=source["_source"]) + sd = _create_sd_from_es_response(source) for item in args.change_set: if item == "": @@ -274,6 +266,15 @@ def _get_rp_launch_results(session, args, launch): return results +def _create_sd_from_es_response(response): + """Convert ElasticSearch response data structure to StatusData object.""" + logging.debug( + f"Loading data from document ID {response['_id']} with field id={response['_source']['id'] if 'id' in response['_source'] else None}" + ) + tmpfile = tempfile.NamedTemporaryFile(prefix=response["_id"], delete=False).name + return opl.status_data.StatusData(tmpfile, data=response["_source"]) + + def _get_es_result_for_rp_result(session, args, run_id, result): if args.rp_project == "satcpt": # OK, I agree we need a better way here. @@ -303,11 +304,7 @@ def _get_es_result_for_rp_result(session, args, run_id, result): raise Exception(f"Failed to find test result in ES for {run_id}") es_type = source["_type"] es_id = source["_id"] - logging.debug( - f"Loading data from document ID {source['_id']} with field id={source['_source']['id']}" - ) - tmpfile = tempfile.NamedTemporaryFile(prefix=source["_id"], delete=False).name - sd = opl.status_data.StatusData(tmpfile, data=source["_source"]) + sd = _create_sd_from_es_response(source) return (sd, es_type, es_id) From a4dd113028d0a32548d7ad160f09621bda4a759c Mon Sep 17 00:00:00 2001 From: Jan Hutar Date: Thu, 9 Nov 2023 08:43:05 +0100 Subject: [PATCH 3/6] fix: jscpd: Clone found --- tests/test_cluster_read.py | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/tests/test_cluster_read.py b/tests/test_cluster_read.py index b393680..48ff917 100755 --- a/tests/test_cluster_read.py +++ b/tests/test_cluster_read.py @@ -130,30 +130,20 @@ def test_copy_from(self): string = """ - name: somevalue constant: Hello world - - name: mycopyfrom + - name: mycopyfrom_exists copy_from: somevalue + - name: mycopyfrom_missing + copy_from: somevalue_that_does_not_exist """ ri = opl.cluster_read.RequestedInfo(string) k, v = next(ri) self.assertEqual(k, "somevalue") self.assertEqual(v, "Hello world") k, v = next(ri) - self.assertEqual(k, "mycopyfrom") - self.assertEqual(v, "Hello world") - - def test_copy_from_negative(self): - string = """ - - name: somevalue - constant: Hello world - - name: mycopyfrom - copy_from: somevalue_that_does_not_exist - """ - ri = opl.cluster_read.RequestedInfo(string) - k, v = next(ri) - self.assertEqual(k, "somevalue") + self.assertEqual(k, "mycopyfrom_exists") self.assertEqual(v, "Hello world") k, v = next(ri) - self.assertEqual(k, "mycopyfrom") + self.assertEqual(k, "mycopyfrom_missing") self.assertEqual(v, None) def test_wrong_config(self): From e1fedf5da75d128de34c0c3dff8154fc000ebb3f Mon Sep 17 00:00:00 2001 From: Jan Hutar Date: Thu, 9 Nov 2023 08:45:40 +0100 Subject: [PATCH 4/6] fix: jscpd: Clone found --- tests/test_status_data.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/test_status_data.py b/tests/test_status_data.py index fa8f3e1..be8d039 100755 --- a/tests/test_status_data.py +++ b/tests/test_status_data.py @@ -210,21 +210,21 @@ def test_set_subtree_json(self): with tempfile.NamedTemporaryFile(delete=False, suffix=".json") as f: f_name = f.name f.write(b'{"hello":"world","foo":42,"bar":{"baz":1}}') - self.status_data.set_subtree_json("results.xxx", f_name) + self.status_data.set_subtree_json("results.xxx_json", f_name) os.unlink(f_name) - self.assertEqual(self.status_data.get("results.xxx.hello"), "world") - self.assertEqual(self.status_data.get("results.xxx.foo"), 42) - self.assertEqual(self.status_data.get("results.xxx.bar.baz"), 1) + self.assertEqual(self.status_data.get("results.xxx_json.hello"), "world") + self.assertEqual(self.status_data.get("results.xxx_json.foo"), 42) + self.assertEqual(self.status_data.get("results.xxx_json.bar.baz"), 1) def test_set_subtree_yaml(self): with tempfile.NamedTemporaryFile(delete=False, suffix=".yaml") as f: f_name = f.name f.write(b"hello: world\nfoo: 42\nbar:\n baz: 1") - self.status_data.set_subtree_json("results.xxx", f_name) + self.status_data.set_subtree_json("results.xxx_yaml", f_name) os.unlink(f_name) - self.assertEqual(self.status_data.get("results.xxx.hello"), "world") - self.assertEqual(self.status_data.get("results.xxx.foo"), 42) - self.assertEqual(self.status_data.get("results.xxx.bar.baz"), 1) + self.assertEqual(self.status_data.get("results.xxx_yaml.hello"), "world") + self.assertEqual(self.status_data.get("results.xxx_yaml.foo"), 42) + self.assertEqual(self.status_data.get("results.xxx_yaml.bar.baz"), 1) def test_remove_simple(self): self.status_data.set("results.xxx", "should not be here") From 41e2bb081864350af0df0cb126bdefcafb9577db Mon Sep 17 00:00:00 2001 From: Jan Hutar Date: Thu, 9 Nov 2023 08:48:05 +0100 Subject: [PATCH 5/6] fix: pylint: E0102: method already defined line 77 (function-redefined) --- tests/test_status_data.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_status_data.py b/tests/test_status_data.py index be8d039..fd65a76 100755 --- a/tests/test_status_data.py +++ b/tests/test_status_data.py @@ -86,7 +86,7 @@ def test_datetime(self): self.assertEqual(self.status_data.get_date("aaa"), now_plus2) self.assertEqual(self.status_data.get_date("bbb"), now_utc) - def test_datetime(self): + def test_datetime_format(self): refference = datetime.datetime( 2020, 12, From 926cccfdd7946731b61dc26be4cbaa2035ef79a3 Mon Sep 17 00:00:00 2001 From: Jan Hutar Date: Thu, 9 Nov 2023 08:49:28 +0100 Subject: [PATCH 6/6] fix: flake8: F841 local variable 'status_data' is assigned to but never used --- tests/test_status_data.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_status_data.py b/tests/test_status_data.py index fd65a76..209cced 100755 --- a/tests/test_status_data.py +++ b/tests/test_status_data.py @@ -239,7 +239,7 @@ def test_remove_missing(self): def test_file_on_http(self): with self.assertRaises(requests.exceptions.ConnectionError): - status_data = opl.status_data.StatusData( + _ = opl.status_data.StatusData( "http://does.not.exist/status-data-file.json" )