diff --git a/Makefile b/Makefile index 8ceefc4..959c3eb 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,7 @@ PROJECTPATH = $(dir $(realpath $(firstword $(MAKEFILE_LIST)))) VENV := .venv VENV_PIP := $(PROJECTPATH)/$(VENV)/bin/pip -VENV_PYTHON := $(PROJECTPATH)/$(VENV)/bin/python2.7 +VENV_PYTHON := $(PROJECTPATH)/$(VENV)/bin/python3 EXTRA_PY := $(PROJECTPATH)/prometheus-openstack-exporter @@ -43,5 +43,5 @@ test-python: $(VENV) $(VENV_PYTHON) -m unittest discover tests $(VENV): - virtualenv --system-site-packages -p python2.7 $(PROJECTPATH)/$(VENV) + virtualenv --system-site-packages -p python3 $(PROJECTPATH)/$(VENV) $(VENV_PIP) install -I -r requirements.txt diff --git a/prometheus-openstack-exporter b/prometheus-openstack-exporter index 6ebd7d0..9010f35 100755 --- a/prometheus-openstack-exporter +++ b/prometheus-openstack-exporter @@ -29,16 +29,16 @@ import logging.handlers import pickle import random import traceback -import urlparse -from BaseHTTPServer import BaseHTTPRequestHandler -from BaseHTTPServer import HTTPServer -from SocketServer import ForkingMixIn +import urllib.parse +from http.server import BaseHTTPRequestHandler +from http.server import HTTPServer from os import environ as env from os import path, rename +from socketserver import ForkingMixIn from threading import Thread from time import sleep, time -from cinderclient.v2 import client as cinder_client +from cinderclient.v3 import client as cinder_client from netaddr import IPRange @@ -159,7 +159,7 @@ def get_clients(): cinder = cinder_client.Client(session=sess_admin, endpoint_type=interface) else: - raise (ValueError("Invalid OS_IDENTITY_API_VERSION=%s" % ks_version)) + raise ValueError log.debug("Client setup done, keystone ver {}".format(ks_version)) return (keystone, nova, neutron, cinder) @@ -405,7 +405,7 @@ class Neutron: labels, registry=self.registry, ) - for k, v in ips.items(): + for k, v in list(ips.items()): metrics.labels(*k).set(v) self.gen_subnet_size() return generate_latest(self.registry) @@ -439,7 +439,7 @@ class Cinder: ) if not self.use_nova_volumes: return - for t, q in self.prodstack["volume_quotas"].items(): + for t, q in list(self.prodstack["volume_quotas"].items()): if t in self.tenant_map: tenant = self.tenant_map[t] else: @@ -743,7 +743,7 @@ class Nova: ["cloud", "tenant", "tenant_id", "type"], registry=self.registry, ) - for t, q in self.prodstack["nova_quotas"].items(): + for t, q in list(self.prodstack["nova_quotas"].items()): if t in self.tenant_map: tenant = self.tenant_map[t] else: @@ -989,7 +989,7 @@ class SwiftAccountUsage: registry=self.registry, ) - for tenant_name, tenant_id in self.keystone_tenants_map.iteritems(): + for tenant_name, tenant_id in self.keystone_tenants_map.items(): account = self.reseller_prefix + tenant_id bytes_used = self._get_account_usage(account) @@ -1047,7 +1047,7 @@ class OpenstackExporterHandler(BaseHTTPRequestHandler): BaseHTTPRequestHandler.__init__(self, *args, **kwargs) def do_GET(self): # noqa: D102, N802 - url = urlparse.urlparse(self.path) + url = urllib.parse.urlparse(self.path) if url.path == "/metrics": try: collectors = [ @@ -1055,7 +1055,7 @@ class OpenstackExporterHandler(BaseHTTPRequestHandler): for collector in get_collectors(config.get("enabled_collectors")) ] log.debug("Collecting stats..") - output = "" + output = bytes() for collector in collectors: output += collector.get_stats() if data_gatherer: diff --git a/requirements.txt b/requirements.txt index 8b88616..b247272 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,4 +4,5 @@ mock prometheus-client python-neutronclient python-novaclient +python-cinderclient swift diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml index c689b7e..6ae8945 100644 --- a/snap/snapcraft.yaml +++ b/snap/snapcraft.yaml @@ -1,5 +1,5 @@ name: prometheus-openstack-exporter -base: core +base: core20 version: git summary: Exposes high level OpenStack metrics to Prometheus. description: | @@ -15,10 +15,10 @@ apps: parts: prometheus-openstack-exporter: plugin: python - python-version: python2 source: . build-packages: - build-essential + - liberasurecode-dev stage-packages: - libdb5.3 - liberasurecode-dev diff --git a/tests/test_SwiftAccountUsage.py b/tests/test_SwiftAccountUsage.py index 8766b33..a4471a2 100644 --- a/tests/test_SwiftAccountUsage.py +++ b/tests/test_SwiftAccountUsage.py @@ -22,7 +22,7 @@ def test__get_account_usage(self, _config, _requests_head, _get_account_ring): "device": "sdb", "id": 0, "ip": "10.24.0.18", - "meta": u"", + "meta": "", "port": 6002, "region": 1, "replication_ip": "10.24.0.18", @@ -34,7 +34,7 @@ def test__get_account_usage(self, _config, _requests_head, _get_account_ring): "device": "sdd", "id": 50, "ip": "10.24.0.71", - "meta": u"", + "meta": "", "port": 6002, "region": 1, "replication_ip": "10.24.0.71", @@ -46,7 +46,7 @@ def test__get_account_usage(self, _config, _requests_head, _get_account_ring): "device": "sdi", "id": 59, "ip": "10.24.0.72", - "meta": u"", + "meta": "", "port": 6002, "region": 1, "replication_ip": "10.24.0.72",