From 42aa16780845500a32a07f44df3a2d5b29880366 Mon Sep 17 00:00:00 2001 From: Billy Olsen Date: Mon, 18 Mar 2024 12:27:04 -0700 Subject: [PATCH 1/2] Use zaza.model.run_on_unit for ca checks Existing code uses the python libjuju unit.run in order to execute a wait check for ca readiness across the units. The behavior of libjuju changed between 2.x and 3.x and causes this functionality to break. This is abstracted and handled in the zaza library, so use that code instead as it properly handles the differences. Signed-off-by: Billy Olsen (cherry picked from commit a64d2c6b031d36fc8eab1a80903ed89a8e4e0a6f) --- .../utilities/test_zaza_utilities_openstack.py | 13 +++++++++---- zaza/openstack/utilities/openstack.py | 8 ++++++-- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/unit_tests/utilities/test_zaza_utilities_openstack.py b/unit_tests/utilities/test_zaza_utilities_openstack.py index 70c5cb72b..206a0a1f4 100644 --- a/unit_tests/utilities/test_zaza_utilities_openstack.py +++ b/unit_tests/utilities/test_zaza_utilities_openstack.py @@ -1701,6 +1701,7 @@ def _get_action_output(stdout, code, stderr=None): 'Stderr': stderr, 'Stdout': stdout}} return action + results = { '/tmp/missing.cert': _get_action_output( '', @@ -1708,12 +1709,16 @@ def _get_action_output(stdout, code, stderr=None): 'cat: /tmp/missing.cert: No such file or directory'), '/tmp/good.cert': _get_action_output('CERTIFICATE', '0')} - async def _run(command, timeout=None): - return results[command.split()[-1]] + self.patch_object(openstack_utils.zaza.model, "async_run_on_unit") + + async def _run_on_unit(unit_name, command, model_name=None, + timeout=None): + return results[command.split()[-1]].data.get('results') + + self.async_run_on_unit.side_effect = _run_on_unit + self.unit1 = mock.MagicMock() self.unit2 = mock.MagicMock() - self.unit2.run.side_effect = _run - self.unit1.run.side_effect = _run self.units = [self.unit1, self.unit2] _units = mock.MagicMock() _units.units = self.units diff --git a/zaza/openstack/utilities/openstack.py b/zaza/openstack/utilities/openstack.py index c015dfd97..6ec2324c1 100644 --- a/zaza/openstack/utilities/openstack.py +++ b/zaza/openstack/utilities/openstack.py @@ -242,8 +242,12 @@ async def _check_ca_present(model, ca_files): for ca_file in ca_files: for unit in units: try: - output = await unit.run('cat {}'.format(ca_file)) - contents = output.data.get('results').get('Stdout', '') + output = await zaza.model.async_run_on_unit( + unit.name, + 'cat {}'.format(ca_file), + model_name=model_name + ) + contents = output.get('Stdout', '') if ca_cert not in contents: break # libjuju throws a generic error for connection failure. So we From e5f27be0680224f70ee6ee74bedba6bbfc4287da Mon Sep 17 00:00:00 2001 From: Edward Hope-Morley Date: Fri, 3 Jul 2026 15:21:09 +0100 Subject: [PATCH 2/2] Convert TEST_*_PROXY to *_proxy env vars If TEST_{NO,HTTP,HTTPS}_PROXY are provided, convert them to http_proxy etc so that code will use them. This will apply to all code under zaza.openstack. (cherry picked from commit 4b4ececeb070cb32fb57cf8e980cee789ba405d2) --- zaza/openstack/__init__.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/zaza/openstack/__init__.py b/zaza/openstack/__init__.py index 37c946da2..461422490 100644 --- a/zaza/openstack/__init__.py +++ b/zaza/openstack/__init__.py @@ -13,3 +13,17 @@ # limitations under the License. """OpenStack specific zaza functionality.""" +import os + + +def _set_proxy_vars(): + # Set proxy vars if provided so that all code gets to use it. + for key, val in os.environ.items(): + if not key.startswith('TEST_') or 'PROXY' not in key: + continue + + _key = key.partition('TEST_')[2] + os.environ[_key.lower()] = val + + +_set_proxy_vars()