From 7c42c56f1f28a2b5245dc0d89be923b59db28642 Mon Sep 17 00:00:00 2001 From: Hasan Acar Date: Tue, 16 Apr 2024 06:26:47 +0000 Subject: [PATCH] fix: Making the gates happy Change-Id: Iddf3469f07486f2c58b46ea993547eecd6df3382 --- bindep.txt | 12 ++++++------ .../collector/checks_d/a10_system_check.py | 13 +++++++++---- monasca_agent/collector/checks_d/cadvisor_host.py | 4 ++-- monasca_agent/collector/checks_d/kibana.py | 5 +++-- monasca_agent/collector/checks_d/kubernetes_api.py | 2 +- monasca_agent/collector/checks_d/nagios_wrapper.py | 2 +- monasca_agent/common/emitter.py | 2 +- monasca_agent/common/util.py | 2 +- tox.ini | 5 +++-- 9 files changed, 27 insertions(+), 20 deletions(-) diff --git a/bindep.txt b/bindep.txt index 1bd7df6b..b5d1b047 100644 --- a/bindep.txt +++ b/bindep.txt @@ -31,8 +31,8 @@ mariadb [platform:rpm] mariadb-devel [platform:rpm] mariadb-server [platform:rpm] memcached -mongodb [platform:dpkg] -mongodb-server [platform:rpm] +mongodb [platform:dpkg !platform:ubuntu-jammy] +mongodb-server [platform:rpm !platform:ubuntu-jammy] mysql-client [platform:dpkg] mysql-server [platform:dpkg] pkg-config [platform:dpkg] @@ -41,14 +41,14 @@ postgresql postgresql-client [platform:dpkg] postgresql-devel [platform:rpm] postgresql-server [platform:rpm] -python-dev [platform:dpkg] +python-dev [platform:dpkg !platform:ubuntu-jammy] python-devel [platform:rpm] -python-libvirt [platform:dpkg !platform:ubuntu-focal] -python-lxml +python-libvirt [platform:dpkg !platform:ubuntu-focal !platform:ubuntu-jammy] +python-lxml [!platform:ubuntu-jammy] python3-all-dev [platform:ubuntu !platform:ubuntu-precise] python3-dev [platform:dpkg] python3-devel [platform:fedora] -python3-libvirt [platform:ubuntu-focal] +python3-libvirt [platform:ubuntu-focal platform:ubuntu-jammy] python3.4 [platform:ubuntu-trusty] python34-devel [platform:centos] python3.5 [platform:ubuntu-xenial] diff --git a/monasca_agent/collector/checks_d/a10_system_check.py b/monasca_agent/collector/checks_d/a10_system_check.py index 09c9b79a..4299f2bb 100644 --- a/monasca_agent/collector/checks_d/a10_system_check.py +++ b/monasca_agent/collector/checks_d/a10_system_check.py @@ -45,7 +45,7 @@ class A10Session(object): payload = {"credentials": {"username": self.username, "password": self.passwd}} try: get_request = requests.post(url=url, headers={"content-type": "application/json"}, - data=json.dumps(payload), verify=False) + data=json.dumps(payload), verify=False, timeout=5) except urllib3.exceptions.SSLError as e: self.log.warning("Caught SSL exception {}".format(e)) @@ -55,8 +55,12 @@ class A10Session(object): def log_out(self, auth_sig): url = "https://" + self.device + "/axapi/v3/logoff" - requests.post(url=url, headers={"Content-type": "application/json", - "Authorization": "A10 %s" % auth_sig}, verify=False) + requests.post( + url=url, + headers={"Content-type": "application/json", "Authorization": "A10 %s" % auth_sig}, + verify=False, + timeout=5, + ) class A10MemoryCheck(AgentCheck): @@ -101,7 +105,8 @@ class A10MemoryCheck(AgentCheck): "Content-type": "application/json", "Authorization": "A10 %s" % self.auth_sig}, - verify=False) + verify=False, + timeout=5) except urllib3.exceptions.SSLError as e: self.log.warning("Caught SSL exception {}".format(e)) diff --git a/monasca_agent/collector/checks_d/cadvisor_host.py b/monasca_agent/collector/checks_d/cadvisor_host.py index 0f0f72d5..51bc0a52 100644 --- a/monasca_agent/collector/checks_d/cadvisor_host.py +++ b/monasca_agent/collector/checks_d/cadvisor_host.py @@ -120,7 +120,7 @@ class CadvisorHost(AgentCheck): self.cadvisor_url = "{}/{}".format(cadvisor_url, "api/v2.0/stats?count=1") dimensions = self._set_dimensions(None, instance) try: - host_metrics = requests.get(self.cadvisor_url, self.connection_timeout).json() + host_metrics = requests.get(self.cadvisor_url, timeout=self.connection_timeout).json() except Exception as e: self.log.error("Error communicating with cAdvisor to collect data - {}".format(e)) else: @@ -130,7 +130,7 @@ class CadvisorHost(AgentCheck): result = urlparse(self.cadvisor_url) self.cadvisor_machine_url = urlunparse(result._replace(path="api/v2.0/machine")) try: - machine_info = requests.get(self.cadvisor_machine_url).json() + machine_info = requests.get(self.cadvisor_machine_url, timeout=5).json() except Exception as ex: self.log.error( "Error communicating with cAdvisor to collect machine data - {}".format(ex)) diff --git a/monasca_agent/collector/checks_d/kibana.py b/monasca_agent/collector/checks_d/kibana.py index 587658c5..9b5df382 100644 --- a/monasca_agent/collector/checks_d/kibana.py +++ b/monasca_agent/collector/checks_d/kibana.py @@ -73,7 +73,8 @@ class Kibana(checks.AgentCheck): def _get_data(self, url): return requests.get( url=url, - headers=util.headers(self.agent_config) + headers=util.headers(self.agent_config), + timeout=5 ).json() def _process_metrics(self, stats, dimensions, instance_metrics): @@ -136,4 +137,4 @@ class Kibana(checks.AgentCheck): ) def _get_kibana_version(self, url): - return requests.head(url=url).headers['kbn-version'] + return requests.head(url=url, timeout=5).headers['kbn-version'] diff --git a/monasca_agent/collector/checks_d/kubernetes_api.py b/monasca_agent/collector/checks_d/kubernetes_api.py index d5b9eb8f..0085276c 100644 --- a/monasca_agent/collector/checks_d/kubernetes_api.py +++ b/monasca_agent/collector/checks_d/kubernetes_api.py @@ -84,7 +84,7 @@ class KubernetesAPI(checks.AgentCheck): if self.kubernetes_connector: return self.kubernetes_connector.get_request(endpoint, as_json=as_json) else: - result = requests.get("{}/{}".format(self.kubernetes_api, endpoint)) + result = requests.get("{}/{}".format(self.kubernetes_api, endpoint), timeout=5) return result.json() if as_json else result def _get_api_health(self): diff --git a/monasca_agent/collector/checks_d/nagios_wrapper.py b/monasca_agent/collector/checks_d/nagios_wrapper.py index f3bbcd72..3de099ea 100644 --- a/monasca_agent/collector/checks_d/nagios_wrapper.py +++ b/monasca_agent/collector/checks_d/nagios_wrapper.py @@ -78,7 +78,7 @@ class WrapNagios(ServicesCheck): last_run_path + 'nagios_wrapper_' + hashlib.md5( - instance['name']).hexdigest() + + instance['name'], usedforsecurity=False).hexdigest() + '.pck') # Load last-run data from shared memory file diff --git a/monasca_agent/common/emitter.py b/monasca_agent/common/emitter.py index f73faa21..165c7879 100644 --- a/monasca_agent/common/emitter.py +++ b/monasca_agent/common/emitter.py @@ -24,7 +24,7 @@ def post_headers(payload): 'User-Agent': 'Mon/Agent', 'Content-Type': 'application/json', 'Accept': 'text/html, */*', - 'Content-MD5': md5(payload).hexdigest() + 'Content-MD5': md5(payload, usedforsecurity=False).hexdigest() } diff --git a/monasca_agent/common/util.py b/monasca_agent/common/util.py index f458d109..16462bfb 100644 --- a/monasca_agent/common/util.py +++ b/monasca_agent/common/util.py @@ -119,7 +119,7 @@ class LaconicFilter(logging.Filter): @staticmethod def hash(msg): - return hashlib.md5(msg).hexdigest() + return hashlib.md5(msg, usedforsecurity=False).hexdigest() def filter(self, record): try: diff --git a/tox.ini b/tox.ini index ce19c03e..c9631fcc 100644 --- a/tox.ini +++ b/tox.ini @@ -1,7 +1,8 @@ [tox] -envlist = py39,pep8,cover +envlist = py3,pep8,cover minversion = 2.5 skipsdist = True +ignore_basepython_conflict = True [testenv] basepython = python3 @@ -15,7 +16,7 @@ deps = -c{env:TOX_CONSTRAINTS_FILE:https://releases.openstack.org/constraints/upper/master} -r{toxinidir}/test-requirements.txt -r{toxinidir}/requirements.txt -whitelist_externals = bash +allowlist_externals = bash find rm install_command = pip install {opts} {packages}