From 26687730b3c0f9c95fadfd378c9887cbd0c16ba4 Mon Sep 17 00:00:00 2001 From: Jaromir Wysoglad Date: Mon, 16 Oct 2023 02:46:34 -0400 Subject: [PATCH] Fix zuul testing This change fixes python 3.8 unit tests. Unfortunately using grouping parentheses in with statements is a python 3.9+ feature. I had to replace the parentheses with a less elegant "\" to escape continuation lines. I also included a .zuul.yaml, without which this couldn't get merged and a .gitreview for convinience. The telemetry-dsvm-* tests are non-voting for now. There isn't any relevant test for this repositary there as of right now, those will get added in the next few weeks. And unfortunately all the telemetry-dsvm-* tests fail due to pyparsing version mismatch right now. Once I or anyone else adds relevant tests to the telemetry tempest plugin, we can make the tests voting here. Co-authored-by: Martin Magr Co-authored-by: Erno Kuvaja Change-Id: Icc7b0229bca0664ee7fd60e3932df8f599beb500 --- .gitignore | 60 +++++++++++++++++++- .gitreview | 5 ++ .zuul.yaml | 41 +++++++++++++ observabilityclient/tests/unit/test_cli.py | 44 +++++++------- observabilityclient/tests/unit/test_utils.py | 34 +++++------ requirements.txt | 2 +- 6 files changed, 143 insertions(+), 43 deletions(-) create mode 100644 .gitreview create mode 100644 .zuul.yaml diff --git a/.gitignore b/.gitignore index b62bb99..3041f8d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,58 @@ -*\.egg-info -*\.py[co] -\.eggs +*.py[cod] + +# C extensions +*.so + +# Packages +*.egg +*.egg-info dist +build +.eggs +eggs +parts +bin +var +sdist +develop-eggs +.installed.cfg +lib +lib64 + +# Installer logs +pip-log.txt + +# Unit test / coverage reports +.coverage +.tox +nosetests.xml +.stestr/ +.venv + +# Translations +*.mo + +# Mr Developer +.mr.developer.cfg +.project +.pydevproject + +# Complexity +output/*.html +output/*/index.html + +# Sphinx +doc/build +releasenotes/build + +# pbr generates these +AUTHORS +ChangeLog + +# Editors +*~ +.*.swp +.*sw? + +# generated docs +doc/source/ref/ diff --git a/.gitreview b/.gitreview new file mode 100644 index 0000000..45314a6 --- /dev/null +++ b/.gitreview @@ -0,0 +1,5 @@ +[gerrit] +host=review.opendev.org +port=29418 +project=openstack/python-observabilityclient.git +defaultbranch=master diff --git a/.zuul.yaml b/.zuul.yaml new file mode 100644 index 0000000..9da640a --- /dev/null +++ b/.zuul.yaml @@ -0,0 +1,41 @@ +- project: + queue: telemetry + templates: + - openstack-python3-jobs + - check-requirements + #- release-notes-jobs-python3 + check: + jobs: + - telemetry-dsvm-integration: + irrelevant-files: &pobsc-irrelevant-files + - ^(test-|)requirements.txt$ + - ^setup.cfg$ + - ^.*\.rst$ + - ^releasenotes/.*$ + - ^observabilityclient/tests/.*$ + - ^tools/.*$ + - ^tox.ini$ + voting: false + - telemetry-dsvm-integration-ipv6-only: + irrelevant-files: *pobsc-irrelevant-files + voting: false + - telemetry-dsvm-integration-centos-9s: + irrelevant-files: *pobsc-irrelevant-files + voting: false + - telemetry-dsvm-integration-centos-9s-fips: + irrelevant-files: *pobsc-irrelevant-files + voting: false + gate: + jobs: + - telemetry-dsvm-integration: + irrelevant-files: *pobsc-irrelevant-files + voting: false + - telemetry-dsvm-integration-ipv6-only: + irrelevant-files: *pobsc-irrelevant-files + voting: false + - telemetry-dsvm-integration-centos-9s: + irrelevant-files: *pobsc-irrelevant-files + voting: false + - telemetry-dsvm-integration-centos-9s-fips: + irrelevant-files: *pobsc-irrelevant-files + voting: false diff --git a/observabilityclient/tests/unit/test_cli.py b/observabilityclient/tests/unit/test_cli.py index ee698a1..0d56fd8 100644 --- a/observabilityclient/tests/unit/test_cli.py +++ b/observabilityclient/tests/unit/test_cli.py @@ -35,10 +35,10 @@ class CliTest(testtools.TestCase): expected = (['metric_name'], [['name1'], ['name2'], ['name3']]) cli_list = cli.List(mock.Mock(), mock.Mock()) - with (mock.patch.object(metric_utils, 'get_client', - return_value=self.client), - mock.patch.object(self.client.query, 'list', - return_value=metric_names) as m): + with mock.patch.object(metric_utils, 'get_client', + return_value=self.client), \ + mock.patch.object(self.client.query, 'list', + return_value=metric_names) as m: ret1 = cli_list.take_action(args_enabled) m.assert_called_with(disable_rbac=False) @@ -61,10 +61,10 @@ class CliTest(testtools.TestCase): cli_show = cli.Show(mock.Mock(), mock.Mock()) - with (mock.patch.object(metric_utils, 'get_client', - return_value=self.client), - mock.patch.object(self.client.query, 'show', - return_value=prom_metric) as m): + with mock.patch.object(metric_utils, 'get_client', + return_value=self.client), \ + mock.patch.object(self.client.query, 'show', + return_value=prom_metric) as m: ret1 = cli_show.take_action(args_enabled) m.assert_called_with('metric_name', disable_rbac=False) @@ -91,10 +91,10 @@ class CliTest(testtools.TestCase): cli_query = cli.Query(mock.Mock(), mock.Mock()) - with (mock.patch.object(metric_utils, 'get_client', - return_value=self.client), - mock.patch.object(self.client.query, 'query', - return_value=prom_metric) as m): + with mock.patch.object(metric_utils, 'get_client', + return_value=self.client), \ + mock.patch.object(self.client.query, 'query', + return_value=prom_metric) as m: ret1 = cli_query.take_action(args_enabled) m.assert_called_with(query, disable_rbac=False) @@ -111,9 +111,9 @@ class CliTest(testtools.TestCase): cli_delete = cli.Delete(mock.Mock(), mock.Mock()) - with (mock.patch.object(metric_utils, 'get_client', - return_value=self.client), - mock.patch.object(self.client.query, 'delete') as m): + with mock.patch.object(metric_utils, 'get_client', + return_value=self.client), \ + mock.patch.object(self.client.query, 'delete') as m: cli_delete.take_action(args) m.assert_called_with(matches, 0, 10) @@ -121,9 +121,9 @@ class CliTest(testtools.TestCase): def test_clean_combstones(self): cli_clean_tombstones = cli.CleanTombstones(mock.Mock(), mock.Mock()) - with (mock.patch.object(metric_utils, 'get_client', - return_value=self.client), - mock.patch.object(self.client.query, 'clean_tombstones') as m): + with mock.patch.object(metric_utils, 'get_client', + return_value=self.client), \ + mock.patch.object(self.client.query, 'clean_tombstones') as m: cli_clean_tombstones.take_action({}) m.assert_called_once() @@ -132,10 +132,10 @@ class CliTest(testtools.TestCase): cli_snapshot = cli.Snapshot(mock.Mock(), mock.Mock()) file_name = 'some_file_name' - with (mock.patch.object(metric_utils, 'get_client', - return_value=self.client), - mock.patch.object(self.client.query, 'snapshot', - return_value=file_name) as m): + with mock.patch.object(metric_utils, 'get_client', + return_value=self.client), \ + mock.patch.object(self.client.query, 'snapshot', + return_value=file_name) as m: ret = cli_snapshot.take_action({}) m.assert_called_once() diff --git a/observabilityclient/tests/unit/test_utils.py b/observabilityclient/tests/unit/test_utils.py index be65b11..3386033 100644 --- a/observabilityclient/tests/unit/test_utils.py +++ b/observabilityclient/tests/unit/test_utils.py @@ -26,8 +26,8 @@ class GetConfigFileTest(testtools.TestCase): super(GetConfigFileTest, self).setUp() def test_current_dir(self): - with (mock.patch.object(os.path, 'exists', return_value=True), - mock.patch.object(metric_utils, 'open') as m): + with mock.patch.object(os.path, 'exists', return_value=True), \ + mock.patch.object(metric_utils, 'open') as m: metric_utils.get_config_file() m.assert_called_with(metric_utils.CONFIG_FILE_NAME, 'r') @@ -50,35 +50,35 @@ class GetPrometheusClientTest(testtools.TestCase): self.config_file = mock.mock_open(read_data=config_data)("name", 'r') def test_get_prometheus_client_from_file(self): - with (mock.patch.object(metric_utils, 'get_config_file', - return_value=self.config_file), - mock.patch.object(prometheus_client.PrometheusAPIClient, - "__init__", return_value=None) as m): + with mock.patch.object(metric_utils, 'get_config_file', + return_value=self.config_file), \ + mock.patch.object(prometheus_client.PrometheusAPIClient, + "__init__", return_value=None) as m: metric_utils.get_prometheus_client() m.assert_called_with("somehost:1234") def test_get_prometheus_client_env_overide(self): - with (mock.patch.dict(os.environ, {'PROMETHEUS_HOST': 'env_overide'}), - mock.patch.object(metric_utils, 'get_config_file', - return_value=self.config_file), - mock.patch.object(prometheus_client.PrometheusAPIClient, - "__init__", return_value=None) as m): + with mock.patch.dict(os.environ, {'PROMETHEUS_HOST': 'env_overide'}), \ + mock.patch.object(metric_utils, 'get_config_file', + return_value=self.config_file), \ + mock.patch.object(prometheus_client.PrometheusAPIClient, + "__init__", return_value=None) as m: metric_utils.get_prometheus_client() m.assert_called_with("env_overide:1234") def test_get_prometheus_client_no_config_file(self): patched_env = {'PROMETHEUS_HOST': 'env_overide', 'PROMETHEUS_PORT': 'env_port'} - with (mock.patch.dict(os.environ, patched_env), - mock.patch.object(prometheus_client.PrometheusAPIClient, - "__init__", return_value=None) as m): + with mock.patch.dict(os.environ, patched_env), \ + mock.patch.object(prometheus_client.PrometheusAPIClient, + "__init__", return_value=None) as m: metric_utils.get_prometheus_client() m.assert_called_with("env_overide:env_port") def test_get_prometheus_client_missing_configuration(self): - with (mock.patch.dict(os.environ, {}), - mock.patch.object(prometheus_client.PrometheusAPIClient, - "__init__", return_value=None)): + with mock.patch.dict(os.environ, {}), \ + mock.patch.object(prometheus_client.PrometheusAPIClient, + "__init__", return_value=None): self.assertRaises(metric_utils.ConfigurationError, metric_utils.get_prometheus_client) diff --git a/requirements.txt b/requirements.txt index ac645ff..3f333b7 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,3 @@ osc-lib>=1.0.1 # Apache-2.0 keystoneauth1>=1.0.0 -cliff!=1.16.0,>=1.14.0 # Apache-2.0 +cliff>=1.14.0 # Apache-2.0