Skip to content

Commit 98d98bf

Browse files
committed
Modified dependency on custom py-pure-client
1 parent e042130 commit 98d98bf

File tree

11 files changed

+95
-79
lines changed

11 files changed

+95
-79
lines changed

setup.cfg

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,8 @@ install_requires =
5151
importlib-metadata; python_version<"3.8"
5252
sanic
5353
prometheus-client
54-
py-pure-client
55-
56-
54+
# temporary workaround for Pure Python SDK
55+
py-pure-client @ git+https://github.com/genegr/py-pure-client.git
5756

5857
[options.packages.find]
5958
where = src

src/pure_fa_openmetrics_exporter/pure_fa_exporter.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
from sanic import Sanic
66
from sanic.log import logger
7-
from sanic.response import text, html, raw
7+
from sanic.response import text, html, raw, empty
88
from sanic.exceptions import SanicException
99
from sanic.handlers import ErrorHandler
1010
from prometheus_client import generate_latest, CollectorRegistry
@@ -104,6 +104,10 @@ async def flasharray_handler(request, tag):
104104
registry = CollectorRegistry()
105105
collector = FlasharrayCollector
106106
endpoint = request.args.get('endpoint', None)
107+
if not endpoint:
108+
return empty(status=400)
109+
if (len(request.args.keys()) > 1):
110+
return empty(status=400)
107111
fa_client = FlasharrayClient(endpoint, request.token, app.ctx.disable_cert_warn)
108112
registry.register(collector(fa_client, request=tag))
109113
resp = generate_latest(registry)

tests/conftest.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import pytest
22
from pypureclient import PureError
33
from pure_fa_openmetrics_exporter.flasharray_client import client
4+
from pure_fa_openmetrics_exporter import pure_fa_exporter
5+
from sanic_testing.testing import SanicTestClient
46

5-
@pytest.fixture()
6-
def fa_client(scope="session"):
7+
@pytest.fixture(scope="session")
8+
def fa_client():
79
try:
810
c = client.FlasharrayClient(
911
target = '10.225.112.90',
@@ -12,3 +14,18 @@ def fa_client(scope="session"):
1214
except PureError as pe:
1315
pytest.fail("Could not connect to flasharray {0}".format(pe))
1416
yield c
17+
18+
@pytest.fixture()
19+
def api_token():
20+
return 'b5cb29e7-a93c-b40a-b02f-da2b90c8c65e'
21+
22+
@pytest.fixture()
23+
def endpoint():
24+
return '10.225.112.90'
25+
26+
@pytest.fixture(scope="session")
27+
def app_client():
28+
app = pure_fa_exporter.app
29+
app.ctx.disable_cert_warn = True
30+
client = SanicTestClient(app)
31+
return client

tests/functional/test_01_home.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import pytest
2+
from httpx import Headers
23

3-
def test_home(client):
4-
rv = client.get("/")
5-
assert b'/metrics' in rv.data
4+
def test_home(app_client, api_token):
5+
h = Headers({'Authorization': "Bearer " + api_token})
6+
_, res = app_client.get('/', headers = h)
7+
assert res.status_code == 200

tests/functional/test_02_array.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import pytest
2-
from flask import request
2+
from httpx import Headers
33

4-
def test_array(client):
5-
rv = client.get('/metrics/array')
6-
assert b'purefa_info{array_name=' in rv.data
4+
def test_array(app_client, endpoint, api_token):
5+
h = Headers({'Authorization': "Bearer " + api_token})
6+
_, res = app_client.get('/metrics/array?endpoint=' + endpoint, headers = h)
7+
assert 'purefa_info{array_name=' in res.text

tests/functional/test_03_volumes.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
11
import pytest
2+
from httpx import Headers
23

3-
def test_volumes(client):
4-
rv = client.get("/metrics/volumes")
5-
for e in ['purefa_volume_space_datareduction_ratio',
4+
def test_volumes(app_client, endpoint, api_token):
5+
h = Headers({'Authorization': "Bearer " + api_token})
6+
_, res = app_client.get('/metrics/volumes?endpoint=' + endpoint, headers = h)
7+
for e in ['purefa_volume_space_data_reduction_ratio',
68
'purefa_volume_space_size_bytes',
7-
'purefa_volume_space_bytes',
8-
'shared',
9+
'purefa_volume_space_used_bytes',
910
'snapshots',
1011
'snapshots_effective',
11-
'system',
12-
'thin_provisioning',
1312
'total_effective',
1413
'total_physical',
1514
'total_provisioned',
16-
'total_reduction',
1715
'unique',
1816
'virtual',
1917
'purefa_volume_performance_latency_usec',
@@ -28,7 +26,6 @@ def test_volumes(client):
2826
'san_usec_per_write_op',
2927
'service_usec_per_mirrored_write_op',
3028
'service_usec_per_read_op',
31-
'service_usec_per_read_op_cache_reduction',
3229
'service_usec_per_write_op',
3330
'usec_per_mirrored_write_op',
3431
'usec_per_read_op',
@@ -43,4 +40,4 @@ def test_volumes(client):
4340
'bytes_per_write',
4441
'bytes_per_op',
4542
'bytes_per_mirrored_write']:
46-
assert b"e" in rv.data
43+
assert e in res.text

tests/functional/test_04_hosts.py

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
11
import pytest
2+
from httpx import Headers
23

4+
def test_hosts(app_client, endpoint, api_token):
5+
h = Headers({'Authorization': "Bearer " + api_token})
6+
_, res = app_client.get('/metrics/hosts?endpoint=' + endpoint, headers = h)
37

4-
def test_hosts(client):
5-
rv = client.get("/metrics/hosts")
6-
for e in ['purefa_host_space_datareduction_ratio',
8+
for e in ['purefa_host_space_data_reduction_ratio',
79
'purefa_host_space_size_bytes',
8-
'purefa_host_space_bytes'
9-
'shared',
10+
'purefa_host_space_used_bytes',
1011
'snapshots',
11-
'system',
12-
'thin_provisioning',
1312
'total_physical',
1413
'total_provisioned',
15-
'total_reduction',
16-
'unique'
14+
'unique',
1715
'purefa_host_performance_latency_usec',
1816
'purefa_host_performance_bandwidth_bytes',
1917
'purefa_host_performance_iops',
@@ -25,7 +23,6 @@ def test_hosts(client):
2523
'san_usec_per_mirrored_write_op',
2624
'service_usec_per_mirrored_write_op',
2725
'service_usec_per_read_op',
28-
'service_usec_per_read_op_cache_reduction',
2926
'service_usec_per_write_op',
3027
'usec_per_read_op',
3128
'usec_per_write_op',
@@ -36,4 +33,4 @@ def test_hosts(client):
3633
'read_bytes_per_sec',
3734
'write_bytes_per_sec',
3835
'mirrored_write_bytes_per_sec']:
39-
assert b"e" in rv.data
36+
assert e in res.text

tests/functional/test_05_pods.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
11
import pytest
2+
from httpx import Headers
23

4+
def test_pods(app_client, endpoint, api_token):
5+
h = Headers({'Authorization': "Bearer " + api_token})
6+
_, res = app_client.get('/metrics/pods?endpoint=' + endpoint, headers = h)
37

4-
def test_pods(client):
5-
rv = client.get("/metrics/pods")
6-
for e in ['purefa_pod_space_datareduction_ratio',
8+
for e in ['purefa_pod_space_data_reduction_ratio',
79
'purefa_pod_space_size_bytes',
8-
'purefa_pod_space_bytes',
10+
'purefa_pod_space_used_bytes',
911
'replication',
1012
'shared',
1113
'snapshots',
12-
'system',
13-
'thin_provisioning',
1414
'total_physical',
1515
'total_provisioned',
16-
'total_reduction',
1716
'unique',
1817
'purefa_pod_performance_latency_usec',
1918
'purefa_pod_performance_bandwidth_bytes',
@@ -27,7 +26,6 @@ def test_pods(client):
2726
'san_usec_per_write_op',
2827
'service_usec_per_mirrored_write_op',
2928
'service_usec_per_read_op',
30-
'service_usec_per_read_op_cache_reduction',
3129
'service_usec_per_write_op',
3230
'usec_per_mirrored_write_op',
3331
'usec_per_read_op',
@@ -36,5 +34,5 @@ def test_pods(client):
3634
'read_bytes_per_sec',
3735
'write_bytes_per_sec',
3836
'mirrored_write_bytes_per_sec']:
39-
assert b"e" in rv.data
37+
assert e in res.text
4038

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,23 @@
11
import pytest
2+
from httpx import Headers
23

3-
4-
def test_directories(client):
5-
rv = client.get("/metrics/directories")
6-
for e in ['purefa_directory_space_datareduction_ratio',
4+
def test_directories(app_client, endpoint, api_token):
5+
h = Headers({'Authorization': "Bearer " + api_token})
6+
_, res = app_client.get('/metrics/directories?endpoint=' + endpoint, headers = h)
7+
for e in ['purefa_directory_space_data_reduction_ratio',
78
'purefa_directory_space_size_bytes',
8-
'purefa_directory_space_bytes',
9+
'purefa_directory_space_used_bytes',
910
'name',
1011
'filesystem',
1112
'path',
1213
'space',
13-
'shared',
1414
'snapshots',
15-
'system',
16-
'thin_provisioning',
1715
'total_physical',
18-
'total_provisioned',
19-
'total_reduction',
2016
'unique',
2117
'purefa_directory_performance_latency_usec',
2218
'purefa_directory_performance_bandwidth_bytes',
2319
'purefa_directory_performance_iops',
24-
'purefa_directory_performance_avg_block_bytes'
20+
'purefa_directory_performance_avg_block_bytes',
2521
'usec_per_read_op',
2622
'usec_per_write_op',
2723
'usec_per_other_op',
@@ -33,5 +29,5 @@ def test_directories(client):
3329
'bytes_per_op',
3430
'bytes_per_read',
3531
'bytes_per_write']:
36-
assert b"e" in rv.data
32+
assert e in res.text
3733

tests/functional/test_07_errors.py

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import pytest
2+
from httpx import Headers
23

3-
4-
def test_not_existing_endpoint(client):
5-
rv = client.get("/not-existing")
6-
assert rv.status_code == 404
4+
def test_not_existing_endpoint(app_client, api_token):
5+
h = Headers({'Authorization': "Bearer " + api_token})
6+
_, res = app_client.get('/not-existing', headers = h)
7+
assert res.status_code == 404
78

89
@pytest.mark.parametrize("test_input,expected",
910
[('/metrics/array/', 404),
@@ -16,31 +17,33 @@ def test_not_existing_endpoint(client):
1617
('/metrics/directories/not-a-dir', 404),
1718
('/metrics/pods/', 404),
1819
('/metrics/pods/not-a-pod', 404)])
19-
def test_wrong_endpoint(client, test_input, expected):
20-
rv = client.get(test_input)
21-
assert rv.status_code == expected
20+
def test_wrong_endpoint(app_client, api_token, test_input, expected):
21+
h = Headers({'Authorization': "Bearer " + api_token})
22+
_, res = app_client.get(test_input, headers = h)
23+
assert res.status_code == expected
2224

2325
@pytest.mark.parametrize("test_input,expected",
2426
[('/', 405),
2527
('/metrics/array', 405),
26-
('/metrics/array/', 404),
28+
('/metrics/array/', 405),
2729
('/metrics/array/not-an-array', 404),
2830
('/metrics/volumes', 405),
29-
('/metrics/volumes/', 404),
31+
('/metrics/volumes/', 405),
3032
('/metrics/volumes/not-a-volume', 404),
3133
('/metrics/hosts', 405),
32-
('/metrics/hosts/', 404),
34+
('/metrics/hosts/', 405),
3335
('/metrics/hosts/not-a-host', 404),
3436
('/metrics/directories', 405),
35-
('/metrics/directories/', 404),
37+
('/metrics/directories/', 405),
3638
('/metrics/directories/not-a-dir', 404),
3739
('/metrics/pods', 405),
38-
('/metrics/pods/', 404),
40+
('/metrics/pods/', 405),
3941
('/metrics/pods/not-a-pod', 404)])
40-
def test_post_put_del(client, test_input, expected):
41-
rv = client.post(test_input)
42-
assert rv.status_code == expected
43-
rv = client.put(test_input)
44-
assert rv.status_code == expected
45-
rv = client.delete(test_input)
46-
assert rv.status_code == expected
42+
def test_post_put_del(app_client, api_token, test_input, expected):
43+
h = Headers({'Authorization': "Bearer " + api_token})
44+
_, res = app_client.post(test_input, headers = h)
45+
assert res.status_code == expected
46+
_, res = app_client.put(test_input)
47+
assert res.status_code == expected
48+
_, res = app_client.delete(test_input)
49+
assert res.status_code == expected

0 commit comments

Comments
 (0)