We must have async functions for the before/after callables
This commit is contained in:
@@ -12,8 +12,10 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import asyncio
|
||||
import mock
|
||||
import unittest
|
||||
import sys
|
||||
|
||||
import zaza.openstack.charm_tests.mysql.utils as mysql_utils
|
||||
|
||||
@@ -21,11 +23,17 @@ import zaza.openstack.charm_tests.mysql.utils as mysql_utils
|
||||
class TestMysqlUtils(unittest.TestCase):
|
||||
"""Test class to encapsulate testing Mysql test utils."""
|
||||
|
||||
def setUp(self):
|
||||
super(TestMysqlUtils, self).setUp()
|
||||
if sys.version_info < (3, 6, 0):
|
||||
raise unittest.SkipTest("Can't AsyncMock in py35")
|
||||
|
||||
@mock.patch.object(mysql_utils, 'model')
|
||||
def test_mysql_complete_cluster_series_upgrade(self, mock_model):
|
||||
run_action_on_leader = mock.MagicMock()
|
||||
mock_model.run_action_on_leader = run_action_on_leader
|
||||
mysql_utils.complete_cluster_series_upgrade()
|
||||
run_action_on_leader = mock.AsyncMock()
|
||||
mock_model.async_run_action_on_leader = run_action_on_leader
|
||||
asyncio.get_event_loop().run_until_complete(
|
||||
mysql_utils.complete_cluster_series_upgrade())
|
||||
run_action_on_leader.assert_called_once_with(
|
||||
'mysql',
|
||||
'complete-cluster-series-upgrade',
|
||||
|
||||
@@ -12,8 +12,10 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import asyncio
|
||||
import mock
|
||||
import unittest
|
||||
import sys
|
||||
|
||||
import zaza.openstack.charm_tests.rabbitmq_server.utils as rabbit_utils
|
||||
|
||||
@@ -21,11 +23,17 @@ import zaza.openstack.charm_tests.rabbitmq_server.utils as rabbit_utils
|
||||
class TestRabbitUtils(unittest.TestCase):
|
||||
"""Test class to encapsulate testing Mysql test utils."""
|
||||
|
||||
def setUp(self):
|
||||
super(TestRabbitUtils, self).setUp()
|
||||
if sys.version_info < (3, 6, 0):
|
||||
raise unittest.SkipTest("Can't AsyncMock in py35")
|
||||
|
||||
@mock.patch.object(rabbit_utils.zaza, 'model')
|
||||
def test_rabbit_complete_cluster_series_upgrade(self, mock_model):
|
||||
run_action_on_leader = mock.MagicMock()
|
||||
mock_model.run_action_on_leader = run_action_on_leader
|
||||
rabbit_utils.complete_cluster_series_upgrade()
|
||||
run_action_on_leader = mock.AsyncMock()
|
||||
mock_model.async_run_action_on_leader = run_action_on_leader
|
||||
asyncio.get_event_loop().run_until_complete(
|
||||
rabbit_utils.complete_cluster_series_upgrade())
|
||||
run_action_on_leader.assert_called_once_with(
|
||||
'rabbitmq-server',
|
||||
'complete-cluster-series-upgrade',
|
||||
|
||||
@@ -62,22 +62,6 @@ class Test_ParallelSeriesUpgradeSync(ut_utils.BaseTestCase):
|
||||
# self.patch_object(upgrade_utils, "model")
|
||||
# self.model.get_status.return_value = self.juju_status
|
||||
|
||||
@mock.patch.object(upgrade_utils.cl_utils, 'get_class')
|
||||
def test_run_post_application_upgrade_functions(self, mock_get_class):
|
||||
called = mock.MagicMock()
|
||||
mock_get_class.return_value = called
|
||||
upgrade_utils.run_post_application_upgrade_functions(['my.thing'])
|
||||
mock_get_class.assert_called_once_with('my.thing')
|
||||
called.assert_called()
|
||||
|
||||
@mock.patch.object(upgrade_utils.cl_utils, 'get_class')
|
||||
def test_run_pre_upgrade_functions(self, mock_get_class):
|
||||
called = mock.MagicMock()
|
||||
mock_get_class.return_value = called
|
||||
upgrade_utils.run_pre_upgrade_functions('1', ['my.thing'])
|
||||
mock_get_class.assert_called_once_with('my.thing')
|
||||
called.assert_called_once_with('1')
|
||||
|
||||
def test_get_leader_and_non_leaders(self):
|
||||
expected = ({
|
||||
'app/0': {
|
||||
@@ -193,6 +177,26 @@ class TestParallelSeriesUpgrade(AioTestCase):
|
||||
self.async_run_action = mock.AsyncMock()
|
||||
self.model.async_run_action = self.async_run_action
|
||||
|
||||
@mock.patch.object(upgrade_utils.cl_utils, 'get_class')
|
||||
async def test_run_post_application_upgrade_functions(
|
||||
self,
|
||||
mock_get_class
|
||||
):
|
||||
called = mock.AsyncMock()
|
||||
mock_get_class.return_value = called
|
||||
await upgrade_utils.run_post_application_upgrade_functions(
|
||||
['my.thing'])
|
||||
mock_get_class.assert_called_once_with('my.thing')
|
||||
called.assert_called()
|
||||
|
||||
@mock.patch.object(upgrade_utils.cl_utils, 'get_class')
|
||||
async def test_run_pre_upgrade_functions(self, mock_get_class):
|
||||
called = mock.AsyncMock()
|
||||
mock_get_class.return_value = called
|
||||
await upgrade_utils.run_pre_upgrade_functions('1', ['my.thing'])
|
||||
mock_get_class.assert_called_once_with('my.thing')
|
||||
called.assert_called_once_with('1')
|
||||
|
||||
@mock.patch.object(upgrade_utils.os_utils, 'async_set_origin')
|
||||
@mock.patch.object(upgrade_utils, 'run_post_application_upgrade_functions')
|
||||
@mock.patch.object(
|
||||
|
||||
@@ -17,10 +17,10 @@
|
||||
import zaza.model as model
|
||||
|
||||
|
||||
def complete_cluster_series_upgrade():
|
||||
async def complete_cluster_series_upgrade():
|
||||
"""Run the complete-cluster-series-upgrade action on the lead unit."""
|
||||
# TODO: Make this work across either mysql or percona-cluster names
|
||||
model.run_action_on_leader(
|
||||
await model.async_run_action_on_leader(
|
||||
'mysql',
|
||||
'complete-cluster-series-upgrade',
|
||||
action_params={})
|
||||
|
||||
@@ -586,9 +586,9 @@ def _post_check_unit_cluster_nodes(unit, nodes, unit_node_names):
|
||||
return errors
|
||||
|
||||
|
||||
def complete_cluster_series_upgrade():
|
||||
async def complete_cluster_series_upgrade():
|
||||
"""Run the complete-cluster-series-upgrade action on the lead unit."""
|
||||
zaza.model.run_action_on_leader(
|
||||
await zaza.model.async_run_action_on_leader(
|
||||
'rabbitmq-server',
|
||||
'complete-cluster-series-upgrade',
|
||||
action_params={})
|
||||
|
||||
@@ -66,6 +66,20 @@ def mojo_unseal_by_unit():
|
||||
zaza.model.run_on_unit(unit_name, './hooks/update-status')
|
||||
|
||||
|
||||
async def async_mojo_unseal_by_unit():
|
||||
"""Unseal any units reported as sealed using mojo cacert."""
|
||||
cacert = zaza.openstack.utilities.generic.get_mojo_cacert_path()
|
||||
vault_creds = vault_utils.get_credentails()
|
||||
for client in vault_utils.get_clients(cacert=cacert):
|
||||
if client.hvac_client.is_sealed():
|
||||
client.hvac_client.unseal(vault_creds['keys'][0])
|
||||
unit_name = await juju_utils.async_get_unit_name_from_ip_address(
|
||||
client.addr,
|
||||
'vault')
|
||||
await zaza.model.async_run_on_unit(
|
||||
unit_name, './hooks/update-status')
|
||||
|
||||
|
||||
def auto_initialize(cacert=None, validation_application='keystone'):
|
||||
"""Auto initialize vault for testing.
|
||||
|
||||
|
||||
@@ -93,7 +93,7 @@ def app_config(charm_name):
|
||||
'pause_non_leader_subordinate': True,
|
||||
'post_upgrade_functions': [
|
||||
('zaza.openstack.charm_tests.vault.setup.'
|
||||
'mojo_unseal_by_unit')]
|
||||
'async_mojo_unseal_by_unit')]
|
||||
},
|
||||
'mongodb': {
|
||||
'origin': None,
|
||||
@@ -338,7 +338,8 @@ async def serial_series_upgrade(
|
||||
leader_machine,
|
||||
files=files, workaround_script=workaround_script,
|
||||
post_upgrade_functions=post_upgrade_functions)
|
||||
run_post_application_upgrade_functions(post_application_upgrade_functions)
|
||||
await run_post_application_upgrade_functions(
|
||||
post_application_upgrade_functions)
|
||||
|
||||
|
||||
async def series_upgrade_machine(
|
||||
@@ -372,10 +373,10 @@ async def series_upgrade_machine(
|
||||
await async_do_release_upgrade(machine)
|
||||
await reboot(machine)
|
||||
await series_upgrade_utils.async_complete_series_upgrade(machine)
|
||||
series_upgrade_utils.run_post_upgrade_functions(post_upgrade_functions)
|
||||
await run_post_upgrade_functions(post_upgrade_functions)
|
||||
|
||||
|
||||
def run_pre_upgrade_functions(machine, pre_upgrade_functions):
|
||||
async def run_pre_upgrade_functions(machine, pre_upgrade_functions):
|
||||
"""Execute list supplied functions.
|
||||
|
||||
Each of the supplied functions will be called with a single
|
||||
@@ -389,10 +390,10 @@ def run_pre_upgrade_functions(machine, pre_upgrade_functions):
|
||||
if pre_upgrade_functions:
|
||||
for func in pre_upgrade_functions:
|
||||
logging.info("Running {}".format(func))
|
||||
cl_utils.get_class(func)(machine)
|
||||
await cl_utils.get_class(func)(machine)
|
||||
|
||||
|
||||
def run_post_application_upgrade_functions(post_upgrade_functions):
|
||||
async def run_post_upgrade_functions(post_upgrade_functions):
|
||||
"""Execute list supplied functions.
|
||||
|
||||
:param post_upgrade_functions: List of functions
|
||||
@@ -401,7 +402,19 @@ def run_post_application_upgrade_functions(post_upgrade_functions):
|
||||
if post_upgrade_functions:
|
||||
for func in post_upgrade_functions:
|
||||
logging.info("Running {}".format(func))
|
||||
cl_utils.get_class(func)()
|
||||
await cl_utils.get_class(func)()
|
||||
|
||||
|
||||
async def run_post_application_upgrade_functions(post_upgrade_functions):
|
||||
"""Execute list supplied functions.
|
||||
|
||||
:param post_upgrade_functions: List of functions
|
||||
:type post_upgrade_functions: [function, function, ...]
|
||||
"""
|
||||
if post_upgrade_functions:
|
||||
for func in post_upgrade_functions:
|
||||
logging.info("Running {}".format(func))
|
||||
await cl_utils.get_class(func)()
|
||||
|
||||
|
||||
async def maybe_pause_things(
|
||||
|
||||
Reference in New Issue
Block a user