Skip to content

Commit

Permalink
Merge pull request #110 from drencrom/master
Browse files Browse the repository at this point in the history
Update to python3 and cinder v3
  • Loading branch information
peppepetra authored May 5, 2022
2 parents 8a8e146 + b3ab2fd commit f21a647
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 19 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
24 changes: 12 additions & 12 deletions prometheus-openstack-exporter
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -1047,15 +1047,15 @@ 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 = [
COLLECTORS[collector]()
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:
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ mock
prometheus-client
python-neutronclient
python-novaclient
python-cinderclient
swift
4 changes: 2 additions & 2 deletions snap/snapcraft.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: prometheus-openstack-exporter
base: core
base: core20
version: git
summary: Exposes high level OpenStack metrics to Prometheus.
description: |
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions tests/test_SwiftAccountUsage.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand Down

0 comments on commit f21a647

Please sign in to comment.