Skip to content

Commit

Permalink
Resolve 'double' async loop issue with get_app_ips()
Browse files Browse the repository at this point in the history
Bug [1] indicated a fault in the logic for get_app_ips() where the code
went sync -> async -> sync -> async and thus ended up trying to reuse
the same event loop.
  • Loading branch information
ajkavanagh committed Jan 11, 2022
1 parent 1e926f5 commit c510eb4
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 4 deletions.
1 change: 0 additions & 1 deletion tests-extended/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ tests_options:
log-to-stdout: false
log-to-python-logging: true
python-logging-level: info
logger-name: DEFAULT
raise-exceptions: true
upload:
- type: InfluxDB
Expand Down
2 changes: 1 addition & 1 deletion tests/bundles/first.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ applications:
num_units: 2
ubuntu:
charm: cs:ubuntu
num_units: 1
num_units: 3
2 changes: 1 addition & 1 deletion tests/bundles/second.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ applications:
num_units: 2
ubuntu:
charm: cs:ubuntu
num_units: 1
num_units: 3
1 change: 1 addition & 0 deletions tests/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ configure:
- zaza.charm_tests.noop.setup.basic_setup
tests:
- zaza.charm_tests.noop.tests.NoopTest
- zaza.charm_tests.libjuju.tests.RegressionTest
tests_options:
force_deploy:
first
Expand Down
16 changes: 16 additions & 0 deletions zaza/charm_tests/libjuju/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Copyright 2022 Canonical Ltd.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Collection of regression tests checking zaza/libjuju integration."""

42 changes: 42 additions & 0 deletions zaza/charm_tests/libjuju/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/usr/bin/env python3

# Copyright 2018 Canonical Ltd.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Test regression libjuju / zaza integration."""

import logging
import unittest

import zaza.model


class RegressionTest(unittest.TestCase):
"""Regression Tests."""

def test_get_unit_public_address(self):
"""Verify get_unit_public_address()."""
logging.info('Verify that get_unit_public_address() function works.')
units = zaza.model.get_units('ubuntu')
ips = [zaza.model.get_unit_public_address(unit) for unit in units]
for ip in ips:
self.assertIsNotNone(ip)

def test_get_app_ips(self):
"""Verify that get_app_ips() doesn't invoke to async loops."""
logging.info('Verify that get_app_ips() works.')
ips = zaza.model.get_app_ips('ubuntu')
for ip in ips:
self.assertIsNotNone(ip)

3 changes: 2 additions & 1 deletion zaza/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -697,7 +697,8 @@ async def async_get_app_ips(application_name, model_name=None):
:rtype: [str, str,...]
"""
return [await u.get_public_address()
for u in get_units(application_name, model_name=model_name)]
for u in await async_get_units(
application_name, model_name=model_name)]


get_app_ips = sync_wrapper(async_get_app_ips)
Expand Down

0 comments on commit c510eb4

Please sign in to comment.