python-observabilityclient 0.1.0__tar.gz → 0.2.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. {python-observabilityclient-0.1.0 → python-observabilityclient-0.2.0}/.zuul.yaml +25 -0
  2. {python-observabilityclient-0.1.0 → python-observabilityclient-0.2.0}/AUTHORS +2 -0
  3. {python-observabilityclient-0.1.0 → python-observabilityclient-0.2.0}/ChangeLog +19 -0
  4. {python-observabilityclient-0.1.0 → python-observabilityclient-0.2.0}/PKG-INFO +4 -4
  5. python-observabilityclient-0.2.0/observabilityclient/i18n.py +21 -0
  6. {python-observabilityclient-0.1.0 → python-observabilityclient-0.2.0}/observabilityclient/prometheus_client.py +12 -5
  7. python-observabilityclient-0.2.0/observabilityclient/tests/functional/base.py +188 -0
  8. python-observabilityclient-0.2.0/observabilityclient/tests/functional/test_cli.py +161 -0
  9. python-observabilityclient-0.2.0/observabilityclient/tests/functional/test_python_api.py +94 -0
  10. {python-observabilityclient-0.1.0 → python-observabilityclient-0.2.0}/observabilityclient/tests/unit/test_cli.py +42 -18
  11. {python-observabilityclient-0.1.0 → python-observabilityclient-0.2.0}/observabilityclient/tests/unit/test_rbac.py +1 -2
  12. {python-observabilityclient-0.1.0 → python-observabilityclient-0.2.0}/observabilityclient/tests/unit/test_utils.py +72 -1
  13. {python-observabilityclient-0.1.0 → python-observabilityclient-0.2.0}/observabilityclient/utils/metric_utils.py +16 -11
  14. python-observabilityclient-0.2.0/observabilityclient/v1/__init__.py +0 -0
  15. {python-observabilityclient-0.1.0 → python-observabilityclient-0.2.0}/observabilityclient/v1/base.py +2 -1
  16. {python-observabilityclient-0.1.0 → python-observabilityclient-0.2.0}/observabilityclient/v1/cli.py +9 -10
  17. {python-observabilityclient-0.1.0 → python-observabilityclient-0.2.0}/observabilityclient/v1/rbac.py +1 -1
  18. {python-observabilityclient-0.1.0 → python-observabilityclient-0.2.0}/python_observabilityclient.egg-info/PKG-INFO +4 -4
  19. {python-observabilityclient-0.1.0 → python-observabilityclient-0.2.0}/python_observabilityclient.egg-info/SOURCES.txt +7 -1
  20. python-observabilityclient-0.2.0/python_observabilityclient.egg-info/pbr.json +1 -0
  21. {python-observabilityclient-0.1.0 → python-observabilityclient-0.2.0}/setup.cfg +3 -3
  22. python-observabilityclient-0.2.0/test-requirements.txt +2 -0
  23. python-observabilityclient-0.2.0/tools/fix_ca_bundle.sh +41 -0
  24. python-observabilityclient-0.2.0/tox.ini +84 -0
  25. python-observabilityclient-0.1.0/.github/workflows/unit_tests.yml +0 -23
  26. python-observabilityclient-0.1.0/python_observabilityclient.egg-info/pbr.json +0 -1
  27. python-observabilityclient-0.1.0/tox.ini +0 -47
  28. {python-observabilityclient-0.1.0 → python-observabilityclient-0.2.0}/LICENSE +0 -0
  29. {python-observabilityclient-0.1.0 → python-observabilityclient-0.2.0}/README.md +0 -0
  30. {python-observabilityclient-0.1.0 → python-observabilityclient-0.2.0}/observabilityclient/__init__.py +0 -0
  31. {python-observabilityclient-0.1.0 → python-observabilityclient-0.2.0}/observabilityclient/client.py +0 -0
  32. {python-observabilityclient-0.1.0 → python-observabilityclient-0.2.0}/observabilityclient/plugin.py +0 -0
  33. {python-observabilityclient-0.1.0/observabilityclient/tests/unit → python-observabilityclient-0.2.0/observabilityclient/tests/functional}/__init__.py +0 -0
  34. {python-observabilityclient-0.1.0/observabilityclient/utils → python-observabilityclient-0.2.0/observabilityclient/tests/unit}/__init__.py +0 -0
  35. {python-observabilityclient-0.1.0 → python-observabilityclient-0.2.0}/observabilityclient/tests/unit/test_prometheus_client.py +0 -0
  36. {python-observabilityclient-0.1.0 → python-observabilityclient-0.2.0}/observabilityclient/tests/unit/test_python_api.py +0 -0
  37. {python-observabilityclient-0.1.0/observabilityclient/v1 → python-observabilityclient-0.2.0/observabilityclient/utils}/__init__.py +0 -0
  38. {python-observabilityclient-0.1.0 → python-observabilityclient-0.2.0}/observabilityclient/v1/client.py +0 -0
  39. {python-observabilityclient-0.1.0 → python-observabilityclient-0.2.0}/observabilityclient/v1/python_api.py +0 -0
  40. {python-observabilityclient-0.1.0 → python-observabilityclient-0.2.0}/pyproject.toml +0 -0
  41. {python-observabilityclient-0.1.0 → python-observabilityclient-0.2.0}/python_observabilityclient.egg-info/dependency_links.txt +0 -0
  42. {python-observabilityclient-0.1.0 → python-observabilityclient-0.2.0}/python_observabilityclient.egg-info/entry_points.txt +0 -0
  43. {python-observabilityclient-0.1.0 → python-observabilityclient-0.2.0}/python_observabilityclient.egg-info/not-zip-safe +0 -0
  44. {python-observabilityclient-0.1.0 → python-observabilityclient-0.2.0}/python_observabilityclient.egg-info/requires.txt +0 -0
  45. {python-observabilityclient-0.1.0 → python-observabilityclient-0.2.0}/python_observabilityclient.egg-info/top_level.txt +0 -0
  46. {python-observabilityclient-0.1.0 → python-observabilityclient-0.2.0}/requirements.txt +0 -0
  47. {python-observabilityclient-0.1.0 → python-observabilityclient-0.2.0}/setup.py +0 -0
  48. {python-observabilityclient-0.1.0 → python-observabilityclient-0.2.0}/tools/install_deps.sh +0 -0
@@ -1,3 +1,24 @@
1
+ - job:
2
+ # TODO(jwysogla): Include these tests in the
3
+ # telemetry-dsvm-integration jobs
4
+ name: observabilityclient-dsvm-functional
5
+ parent: devstack-tox-functional
6
+ description: |
7
+ Devstack-based functional tests for observabilityclient.
8
+ required-projects:
9
+ - openstack/python-observabilityclient
10
+ - openstack/ceilometer
11
+ - infrawatch/sg-core
12
+ timeout: 4200
13
+ vars:
14
+ devstack_localrc:
15
+ USE_PYTHON3: True
16
+ PROMETHEUS_SERVICE_SCRAPE_TARGETS: prometheus,sg-core
17
+ CEILOMETER_BACKEND: sg-core
18
+ devstack_plugins:
19
+ sg-core: https://github.com/infrawatch/sg-core
20
+ ceilometer: https://opendev.org/openstack/ceilometer
21
+
1
22
  - project:
2
23
  queue: telemetry
3
24
  templates:
@@ -25,6 +46,8 @@
25
46
  - telemetry-dsvm-integration-centos-9s-fips:
26
47
  irrelevant-files: *pobsc-irrelevant-files
27
48
  voting: false
49
+ - observabilityclient-dsvm-functional:
50
+ irrelevant-files: *pobsc-irrelevant-files
28
51
  gate:
29
52
  jobs:
30
53
  - telemetry-dsvm-integration:
@@ -39,3 +62,5 @@
39
62
  - telemetry-dsvm-integration-centos-9s-fips:
40
63
  irrelevant-files: *pobsc-irrelevant-files
41
64
  voting: false
65
+ - observabilityclient-dsvm-functional:
66
+ irrelevant-files: *pobsc-irrelevant-files
@@ -1,5 +1,6 @@
1
1
  Chris Sibbitt <csibbitt@redhat.com>
2
2
  Erno Kuvaja <jokke@usr.fi>
3
+ Ghanshyam Mann <gmann@ghanshyammann.com>
3
4
  Jaromir Wysoglad <jwysogla@redhat.com>
4
5
  Jaromír Wysoglad <jwysogla@redhat.com>
5
6
  Leif Madsen <leif@leifmadsen.com>
@@ -7,3 +8,4 @@ Leif Madsen <lmadsen@redhat.com>
7
8
  Marihan Girgis mgirgisf@redhat.com
8
9
  Martin Magr <mmagr@redhat.com>
9
10
  Martin Mágr <mmagr@redhat.com>
11
+ Takashi Kajinami <kajinamit@oss.nttdata.com>
@@ -1,6 +1,25 @@
1
1
  CHANGES
2
2
  =======
3
3
 
4
+ 0.2.0
5
+ -----
6
+
7
+ * Sort column order in cli output
8
+ * Fix table formatter
9
+ * Remove AUTHORS file
10
+ * Add TLS support
11
+
12
+ 0.1.1
13
+ -----
14
+
15
+ * Update python classifier in setup.cfg
16
+ * Add functional tests
17
+ * Fix cli commands
18
+ * Add i18n.py and use it in v1/base.py and v1/cli.py
19
+ * Fix "\_" is shadowing Python builtin
20
+ * Flake8 changes
21
+ * Remove .github/
22
+
4
23
  0.1.0
5
24
  -----
6
25
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: python-observabilityclient
3
- Version: 0.1.0
3
+ Version: 0.2.0
4
4
  Summary: OpenStack Observability Client
5
5
  Home-page: https://infrawatch.github.io/documentation/
6
6
  Author: OpenStack
@@ -71,10 +71,10 @@ Classifier: Programming Language :: Python
71
71
  Classifier: Programming Language :: Python :: Implementation :: CPython
72
72
  Classifier: Programming Language :: Python :: 3 :: Only
73
73
  Classifier: Programming Language :: Python :: 3
74
- Classifier: Programming Language :: Python :: 3.6
75
- Classifier: Programming Language :: Python :: 3.7
76
74
  Classifier: Programming Language :: Python :: 3.8
77
75
  Classifier: Programming Language :: Python :: 3.9
78
- Requires-Python: >=3.6
76
+ Classifier: Programming Language :: Python :: 3.10
77
+ Classifier: Programming Language :: Python :: 3.11
78
+ Requires-Python: >=3.8
79
79
  Description-Content-Type: text/markdown; charset=UTF-8
80
80
  Provides-Extra: test
@@ -0,0 +1,21 @@
1
+ # Copyright 2023 OpenStack Foundation
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License"); you may
4
+ # not use this file except in compliance with the License. You may obtain
5
+ # a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11
+ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12
+ # License for the specific language governing permissions and limitations
13
+ # under the License.
14
+ #
15
+
16
+ import oslo_i18n
17
+
18
+ _translators = oslo_i18n.TranslatorFactory(domain='observabilityclient')
19
+
20
+ # The primary translation function using the well-known name "_"
21
+ _ = _translators.primary
@@ -15,6 +15,7 @@
15
15
  import logging
16
16
 
17
17
  import requests
18
+ import simplejson
18
19
 
19
20
 
20
21
  LOG = logging.getLogger(__name__)
@@ -27,9 +28,15 @@ class PrometheusAPIClientError(Exception):
27
28
  def __str__(self) -> str:
28
29
  if self.resp.status_code != requests.codes.ok:
29
30
  if self.resp.status_code != 204:
30
- decoded = self.resp.json()
31
- if 'error' in decoded:
32
- return f'[{self.resp.status_code}] {decoded["error"]}'
31
+ try:
32
+ decoded = self.resp.json()
33
+ if 'error' in decoded:
34
+ return f'[{self.resp.status_code}] {decoded["error"]}'
35
+ except simplejson.errors.JSONDecodeError:
36
+ # If an https endpoint is accessed as http,
37
+ # we get 400 status with plain text instead of
38
+ # json and decoding it raises exception.
39
+ return f'[{self.resp.status_code}] {self.resp.text}'
33
40
  return f'[{self.resp.status_code}] {self.resp.reason}'
34
41
  else:
35
42
  decoded = self.resp.json()
@@ -47,14 +54,14 @@ class PrometheusAPIClientError(Exception):
47
54
  return f'[{decoded.status}]'
48
55
 
49
56
 
50
- class PrometheusMetric:
57
+ class PrometheusMetric(object):
51
58
  def __init__(self, input):
52
59
  self.timestamp = input['value'][0]
53
60
  self.labels = input['metric']
54
61
  self.value = input['value'][1]
55
62
 
56
63
 
57
- class PrometheusAPIClient:
64
+ class PrometheusAPIClient(object):
58
65
  def __init__(self, host):
59
66
  self._host = host
60
67
  self._session = requests.Session()
@@ -0,0 +1,188 @@
1
+ # Licensed under the Apache License, Version 2.0 (the "License"); you may
2
+ # not use this file except in compliance with the License. You may obtain
3
+ # a copy of the License at
4
+ #
5
+ # http://www.apache.org/licenses/LICENSE-2.0
6
+ #
7
+ # Unless required by applicable law or agreed to in writing, software
8
+ # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9
+ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10
+ # License for the specific language governing permissions and limitations
11
+ # under the License.
12
+
13
+ # base.py file taken and modified from the openstackclient functional tests
14
+
15
+ import json
16
+ import logging
17
+ import os
18
+ import shlex
19
+ import subprocess
20
+
21
+ from observabilityclient import client
22
+
23
+ from keystoneauth1 import loading
24
+ from keystoneauth1 import session
25
+ import os_client_config
26
+ from tempest.lib.cli import output_parser
27
+ from tempest.lib import exceptions
28
+ import testtools
29
+
30
+ ADMIN_CLOUD = os.environ.get('OS_ADMIN_CLOUD', 'devstack-admin')
31
+ LOG = logging.getLogger(__name__)
32
+
33
+
34
+ class PythonAPITestCase(testtools.TestCase):
35
+ def _getKeystoneSession(self):
36
+ conf = os_client_config.OpenStackConfig()
37
+ creds = conf.get_one_cloud(cloud=ADMIN_CLOUD).get_auth_args()
38
+ ks_creds = dict(
39
+ auth_url=creds["auth_url"],
40
+ username=creds["username"],
41
+ password=creds["password"],
42
+ project_name=creds["project_name"],
43
+ user_domain_id=creds["user_domain_id"],
44
+ project_domain_id=creds["project_domain_id"])
45
+ loader = loading.get_plugin_loader("password")
46
+ auth = loader.load_from_options(**ks_creds)
47
+ return session.Session(auth=auth)
48
+
49
+ def setUp(self):
50
+ super(PythonAPITestCase, self).setUp()
51
+ self.client = client.Client(
52
+ 1,
53
+ self._getKeystoneSession()
54
+ )
55
+
56
+
57
+ def execute(cmd, fail_ok=False, merge_stderr=False):
58
+ """Execute specified command for the given action."""
59
+ LOG.debug('Executing: %s', cmd)
60
+ cmdlist = shlex.split(cmd)
61
+ stdout = subprocess.PIPE
62
+ stderr = subprocess.STDOUT if merge_stderr else subprocess.PIPE
63
+
64
+ proc = subprocess.Popen(cmdlist, stdout=stdout, stderr=stderr)
65
+
66
+ result_out, result_err = proc.communicate()
67
+ result_out = result_out.decode('utf-8')
68
+ LOG.debug('stdout: %s', result_out)
69
+ LOG.debug('stderr: %s', result_err)
70
+
71
+ if not fail_ok and proc.returncode != 0:
72
+ raise exceptions.CommandFailed(
73
+ proc.returncode,
74
+ cmd,
75
+ result_out,
76
+ result_err,
77
+ )
78
+
79
+ return result_out
80
+
81
+
82
+ class CliTestCase(testtools.TestCase):
83
+ @classmethod
84
+ def openstack(
85
+ cls,
86
+ cmd,
87
+ *,
88
+ cloud=ADMIN_CLOUD,
89
+ fail_ok=False,
90
+ parse_output=False,
91
+ ):
92
+ """Execute observabilityclient command for the given action.
93
+
94
+ :param cmd: A string representation of the command to execute.
95
+ :param cloud: The cloud to execute against. This can be a string, empty
96
+ string, or None. A string results in '--os-auth-type $cloud', an
97
+ empty string results in the '--os-auth-type' option being
98
+ omitted, and None resuts in '--os-auth-type none' for legacy
99
+ reasons.
100
+ :param fail_ok: If failure is permitted. If False (default), a command
101
+ failure will result in `~tempest.lib.exceptions.CommandFailed`
102
+ being raised.
103
+ :param parse_output: If true, pass the '-f json' parameter and decode
104
+ the output.
105
+ :returns: The output from the command.
106
+ :raises: `~tempest.lib.exceptions.CommandFailed` if the command failed
107
+ and ``fail_ok`` was ``False``.
108
+ """
109
+ auth_args = []
110
+ if cloud is None:
111
+ # Execute command with no auth
112
+ auth_args.append('--os-auth-type none')
113
+ elif cloud != '':
114
+ # Execute command with an explicit cloud specified
115
+ auth_args.append(f'--os-cloud {cloud}')
116
+
117
+ format_args = []
118
+ if parse_output:
119
+ format_args.append('-f json')
120
+
121
+ output = execute(
122
+ ' '.join(['openstack'] + auth_args + [cmd] + format_args),
123
+ fail_ok=fail_ok,
124
+ )
125
+
126
+ if parse_output:
127
+ return json.loads(output)
128
+ else:
129
+ return output
130
+
131
+ @classmethod
132
+ def assertOutput(cls, expected, actual):
133
+ if expected != actual:
134
+ raise Exception(expected + ' != ' + actual)
135
+
136
+ @classmethod
137
+ def assertInOutput(cls, expected, actual):
138
+ if expected not in actual:
139
+ raise Exception(expected + ' not in ' + actual)
140
+
141
+ @classmethod
142
+ def assertNotInOutput(cls, expected, actual):
143
+ if expected in actual:
144
+ raise Exception(expected + ' in ' + actual)
145
+
146
+ @classmethod
147
+ def assertsOutputNotNone(cls, observed):
148
+ if observed is None:
149
+ raise Exception('No output observed')
150
+
151
+ def assert_table_structure(self, items, field_names):
152
+ """Verify that all items have keys listed in field_names."""
153
+ for item in items:
154
+ for field in field_names:
155
+ self.assertIn(field, item)
156
+
157
+ def assert_show_fields(self, show_output, field_names):
158
+ """Verify that all items have keys listed in field_names."""
159
+ # field_names = ['name', 'description']
160
+ # show_output = [{'name': 'fc2b98d8faed4126b9e371eda045ade2'},
161
+ # {'description': 'description-821397086'}]
162
+ # this next line creates a flattened list of all 'keys' (like 'name',
163
+ # and 'description' out of the output
164
+ all_headers = [item for sublist in show_output for item in sublist]
165
+ for field_name in field_names:
166
+ self.assertIn(field_name, all_headers)
167
+
168
+ def parse_show_as_object(self, raw_output):
169
+ """Return a dict with values parsed from cli output."""
170
+ items = self.parse_show(raw_output)
171
+ o = {}
172
+ for item in items:
173
+ o.update(item)
174
+ return o
175
+
176
+ def parse_show(self, raw_output):
177
+ """Return list of dicts with item values parsed from cli output."""
178
+ items = []
179
+ table_ = output_parser.table(raw_output)
180
+ for row in table_['values']:
181
+ item = {}
182
+ item[row[0]] = row[1]
183
+ items.append(item)
184
+ return items
185
+
186
+ def parse_listing(self, raw_output):
187
+ """Return list of dicts with basic item parsed from cli output."""
188
+ return output_parser.listing(raw_output)
@@ -0,0 +1,161 @@
1
+ # Licensed under the Apache License, Version 2.0 (the "License"); you may
2
+ # not use this file except in compliance with the License. You may obtain
3
+ # a copy of the License at
4
+ #
5
+ # http://www.apache.org/licenses/LICENSE-2.0
6
+ #
7
+ # Unless required by applicable law or agreed to in writing, software
8
+ # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9
+ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10
+ # License for the specific language governing permissions and limitations
11
+ # under the License.
12
+
13
+ from observabilityclient.tests.functional import base
14
+ import time
15
+
16
+
17
+ class CliTestFunctionalRBACDisabled(base.CliTestCase):
18
+ """Functional tests for cli commands with disabled RBAC."""
19
+
20
+ def test_list(self):
21
+ cmd_output = self.openstack(
22
+ 'metric list --disable-rbac',
23
+ parse_output=True,
24
+ )
25
+ name_list = [item.get('metric_name') for item in cmd_output]
26
+ self.assertIn(
27
+ 'up',
28
+ name_list
29
+ )
30
+
31
+ def test_show(self):
32
+ cmd_output = self.openstack(
33
+ 'metric show up --disable-rbac',
34
+ parse_output=True,
35
+ )
36
+ for metric in cmd_output:
37
+ self.assertEqual(
38
+ "up",
39
+ metric["__name__"]
40
+ )
41
+ self.assertEqual(
42
+ "1",
43
+ metric["value"]
44
+ )
45
+
46
+ def test_query(self):
47
+ cmd_output = self.openstack(
48
+ 'metric query up --disable-rbac',
49
+ parse_output=True,
50
+ )
51
+ for metric in cmd_output:
52
+ self.assertEqual(
53
+ "up",
54
+ metric["__name__"]
55
+ )
56
+ self.assertEqual(
57
+ "1",
58
+ metric["value"]
59
+ )
60
+
61
+
62
+ class CliTestFunctionalRBACEnabled(base.CliTestCase):
63
+ """Functional tests for cli commands with enabled RBAC."""
64
+
65
+ def test_list(self):
66
+ cmd_output = self.openstack(
67
+ 'metric list',
68
+ parse_output=True,
69
+ )
70
+ name_list = [item.get('metric_name') for item in cmd_output]
71
+ self.assertIn(
72
+ 'ceilometer_image_size',
73
+ name_list
74
+ )
75
+ self.assertNotIn(
76
+ 'up',
77
+ name_list
78
+ )
79
+
80
+ def test_show(self):
81
+ cmd_output = self.openstack(
82
+ 'metric show ceilometer_image_size',
83
+ parse_output=True,
84
+ )
85
+ for metric in cmd_output:
86
+ self.assertEqual(
87
+ "ceilometer_image_size",
88
+ metric["__name__"]
89
+ )
90
+ self.assertEqual(
91
+ "sg-core",
92
+ metric["job"]
93
+ )
94
+
95
+ def test_query(self):
96
+ cmd_output = self.openstack(
97
+ 'metric query ceilometer_image_size',
98
+ parse_output=True,
99
+ )
100
+ for metric in cmd_output:
101
+ self.assertEqual(
102
+ "ceilometer_image_size",
103
+ metric["__name__"]
104
+ )
105
+ self.assertEqual(
106
+ "sg-core",
107
+ metric["job"]
108
+ )
109
+
110
+
111
+ class CliTestFunctionalAdminCommands(base.CliTestCase):
112
+ """Functional tests for cli admin commands."""
113
+
114
+ def test_delete(self):
115
+ test_start_time = int(time.time())
116
+ query_before = self.openstack(
117
+ f'metric query prometheus_ready@{test_start_time} --disable-rbac',
118
+ parse_output=True,
119
+ )
120
+
121
+ values = [item.get("__name__") for item in query_before]
122
+ # Check, that the metric is present before the deletion
123
+ self.assertIn(
124
+ "prometheus_ready",
125
+ values
126
+ )
127
+
128
+ self.openstack(
129
+ 'metric delete prometheus_ready --disable-rbac',
130
+ parse_output=False,
131
+ )
132
+
133
+ query_after = self.openstack(
134
+ f'metric query prometheus_ready@{test_start_time} --disable-rbac',
135
+ parse_output=True,
136
+ )
137
+ values = [item.get("__name__") for item in query_after]
138
+ # Check, that the metric is not present after the deletion
139
+ self.assertNotIn(
140
+ "prometheus_ready",
141
+ values
142
+ )
143
+
144
+ def test_clean_tombstones(self):
145
+ # NOTE(jwysogla) There is not much to check here
146
+ # except for the fact, that the command doesn't
147
+ # raise an exception. Prometheus doesn't send any
148
+ # data back and we don't have a reliable way to query
149
+ # prometheus that this command did something.
150
+ self.openstack('metric clean-tombstones')
151
+
152
+ def test_snapshot(self):
153
+ cmd_output = self.openstack(
154
+ 'metric snapshot',
155
+ parse_output=True,
156
+ )
157
+ for name in cmd_output:
158
+ self.assertInOutput(
159
+ time.strftime('%Y%m%d'),
160
+ name.get("Snapshot file name")
161
+ )
@@ -0,0 +1,94 @@
1
+ # Copyright 2023 Red Hat, Inc.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License"); you may
4
+ # not use this file except in compliance with the License. You may obtain
5
+ # a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11
+ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12
+ # License for the specific language governing permissions and limitations
13
+ # under the License.
14
+
15
+ from observabilityclient.tests.functional import base
16
+
17
+ import time
18
+
19
+
20
+ class PythonAPITestFunctionalRBACDisabled(base.PythonAPITestCase):
21
+ def test_list(self):
22
+ ret = self.client.query.list(disable_rbac=True)
23
+
24
+ self.assertIn("up", ret)
25
+
26
+ def test_show(self):
27
+ ret = self.client.query.show("up", disable_rbac=True)
28
+
29
+ for metric in ret:
30
+ self.assertEqual("up", metric.labels["__name__"])
31
+ self.assertEqual("1", metric.value)
32
+
33
+ def test_query(self):
34
+ ret = self.client.query.query("up", disable_rbac=True)
35
+
36
+ for metric in ret:
37
+ self.assertEqual("up", metric.labels["__name__"])
38
+ self.assertEqual("1", metric.value)
39
+
40
+
41
+ class PythonAPITestFunctionalRBACEnabled(base.PythonAPITestCase):
42
+ def test_list(self):
43
+ ret = self.client.query.list(disable_rbac=False)
44
+
45
+ self.assertIn("ceilometer_image_size", ret)
46
+ self.assertNotIn("up", ret)
47
+
48
+ def test_show(self):
49
+ ret = self.client.query.show("ceilometer_image_size",
50
+ disable_rbac=False)
51
+
52
+ for metric in ret:
53
+ self.assertEqual("ceilometer_image_size",
54
+ metric.labels["__name__"])
55
+ self.assertEqual("sg-core",
56
+ metric.labels["job"])
57
+
58
+ def test_query(self):
59
+ ret = self.client.query.query("ceilometer_image_size",
60
+ disable_rbac=False)
61
+
62
+ for metric in ret:
63
+ self.assertEqual("ceilometer_image_size",
64
+ metric.labels["__name__"])
65
+ self.assertEqual("sg-core", metric.labels["job"])
66
+
67
+
68
+ class PythonAPITestFunctionalAdminCommands(base.PythonAPITestCase):
69
+ def test_delete(self):
70
+ now = time.time()
71
+ metric_name = "prometheus_build_info"
72
+ query = f"{metric_name}@{now}"
73
+
74
+ query_before = self.client.query.query(query, disable_rbac=True)
75
+
76
+ for metric in query_before:
77
+ self.assertEqual(metric_name, metric.labels["__name__"])
78
+
79
+ self.client.query.delete(metric_name)
80
+
81
+ query_after = self.client.query.query(query, disable_rbac=True)
82
+ self.assertEqual([], query_after)
83
+
84
+ def test_clean_tombstones(self):
85
+ # NOTE(jwysogla) There is not much to check here
86
+ # except for the fact, that the command doesn't
87
+ # raise an exception. Prometheus doesn't send any
88
+ # data back and we don't have a reliable way to query
89
+ # prometheus that this command did something.
90
+ self.client.query.clean_tombstones()
91
+
92
+ def test_snapshot(self):
93
+ ret = self.client.query.snapshot()
94
+ self.assertIn(time.strftime("%Y%m%d"), ret)