Parameterize workarounds

This commit is contained in:
David Ames
2018-08-21 11:57:05 -07:00
parent 4eb3c2e744
commit c80f057eb6
2 changed files with 59 additions and 23 deletions
@@ -173,17 +173,19 @@ class TestGenericUtils(ut_utils.BaseTestCase):
_unit = "app/2"
_from_series = "xenial"
_to_series = "bionic"
_workaround_script = "scriptname"
_files = ["filename", _workaround_script]
_scp_calls = []
_run_calls = [
mock.call(_unit, "/home/ubuntu/package-workarounds.sh"),
mock.call(_unit, _workaround_script),
mock.call(_unit, "juju-updateseries "
"--from-series={} --to-series={}"
.format(_from_series, _to_series))]
for filename in ["package-workarounds.sh",
"corosync", "corosync.conf"]:
for filename in _files:
_scp_calls.append(mock.call(_unit, filename, filename))
generic_utils.wrap_do_release_upgrade(
_unit, to_series=_to_series, from_series=_from_series)
_unit, to_series=_to_series, from_series=_from_series,
workaround_script=_workaround_script, files=_files)
self.scp_to_unit.assert_has_calls(_scp_calls)
self.run_on_unit.assert_has_calls(_run_calls)
self.do_release_upgrade.assert_called_once_with(_unit)
@@ -221,14 +223,18 @@ class TestGenericUtils(ut_utils.BaseTestCase):
_from_series = "xenial"
_to_series = "bionic"
_origin = "source"
_files = ["filename", "scriptname"]
_workaround_script = "scriptname"
generic_utils.series_upgrade(
_unit, _machine_num, origin=_origin,
to_series=_to_series, from_series=_from_series)
to_series=_to_series, from_series=_from_series,
workaround_script=_workaround_script, files=_files)
self.block_until_all_units_idle.called_with()
self.prepare_series_upgrade.assert_called_once_with(
_machine_num, to_series=_to_series)
self.wrap_do_release_upgrade.assert_called_once_with(
_unit, to_series=_to_series, from_series=_from_series)
_unit, to_series=_to_series, from_series=_from_series,
workaround_script=_workaround_script, files=_files)
self.complete_series_upgrade.assert_called_once_with(_machine_num)
self.set_series.assert_called_once_with(_application, _to_series)
self.update_series.assert_called_once_with(_machine_num, _to_series)
@@ -244,6 +250,8 @@ class TestGenericUtils(ut_utils.BaseTestCase):
_from_series = "xenial"
_to_series = "bionic"
_origin = "source"
_files = ["filename", "scriptname"]
_workaround_script = "scriptname"
# Peers and Subordinates
_run_action_calls = [
mock.call("{}-hacluster/1".format(_application),
@@ -258,7 +266,8 @@ class TestGenericUtils(ut_utils.BaseTestCase):
_series_upgrade_calls.append(
mock.call("{}/{}".format(_application, machine_num),
machine_num, origin=_origin,
from_series=_from_series, to_series=_to_series),
from_series=_from_series, to_series=_to_series,
workaround_script=_workaround_script, files=_files),
)
# Pause primary peers and subordinates
@@ -266,7 +275,8 @@ class TestGenericUtils(ut_utils.BaseTestCase):
_application, origin=_origin,
to_series=_to_series, from_series=_from_series,
pause_non_leader_primary=True,
pause_non_leader_subordinate=True)
pause_non_leader_subordinate=True,
workaround_script=_workaround_script, files=_files),
self.run_action.assert_has_calls(_run_action_calls)
self.series_upgrade.assert_has_calls(_series_upgrade_calls)
@@ -279,6 +289,8 @@ class TestGenericUtils(ut_utils.BaseTestCase):
_from_series = "xenial"
_to_series = "bionic"
_origin = "source"
_files = ["filename", "scriptname"]
_workaround_script = "scriptname"
# Subordinates only
_run_action_calls = [
mock.call("{}-hacluster/1".format(_application),
@@ -291,7 +303,8 @@ class TestGenericUtils(ut_utils.BaseTestCase):
_series_upgrade_calls.append(
mock.call("{}/{}".format(_application, machine_num),
machine_num, origin=_origin,
from_series=_from_series, to_series=_to_series),
from_series=_from_series, to_series=_to_series,
workaround_script=_workaround_script, files=_files),
)
# Pause subordinates
@@ -299,7 +312,8 @@ class TestGenericUtils(ut_utils.BaseTestCase):
_application, origin=_origin,
to_series=_to_series, from_series=_from_series,
pause_non_leader_primary=False,
pause_non_leader_subordinate=True)
pause_non_leader_subordinate=True,
workaround_script=_workaround_script, files=_files),
self.run_action.assert_has_calls(_run_action_calls)
self.series_upgrade.assert_has_calls(_series_upgrade_calls)
@@ -313,11 +327,14 @@ class TestGenericUtils(ut_utils.BaseTestCase):
_to_series = "bionic"
_origin = "source"
_series_upgrade_calls = []
_files = ["filename", "scriptname"]
_workaround_script = "scriptname"
for machine_num in ("0", "1", "2"):
_series_upgrade_calls.append(
mock.call("{}/{}".format(_application, machine_num),
machine_num, origin=_origin,
from_series=_from_series, to_series=_to_series),
from_series=_from_series, to_series=_to_series,
workaround_script=_workaround_script, files=_files),
)
# No Pausiing
@@ -325,6 +342,7 @@ class TestGenericUtils(ut_utils.BaseTestCase):
_application, origin=_origin,
to_series=_to_series, from_series=_from_series,
pause_non_leader_primary=False,
pause_non_leader_subordinate=False)
pause_non_leader_subordinate=False,
workaround_script=_workaround_script, files=_files)
self.run_action.assert_not_called()
self.series_upgrade.assert_has_calls(_series_upgrade_calls)
+29 -11
View File
@@ -172,7 +172,8 @@ def get_yaml_config(config_file):
def series_upgrade_application(application, pause_non_leader_primary=True,
pause_non_leader_subordinate=True,
from_series="trusty", to_series="xenial",
origin='openstack-origin'):
origin='openstack-origin',
files=None, workaround_script=None):
"""Series upgrade application.
Wrap all the functionality to handle series upgrade for a given
@@ -193,6 +194,10 @@ def series_upgrade_application(application, pause_non_leader_primary=True,
:param origin: The configuration setting variable name for changing origin
source. (openstack-origin or source)
:type origin: str
:param files: Workaround files to scp to unit under upgrade
:type files: list
:param workaround_script: Workaround script to run during series upgrade
:type workaround_script: str
:returns: None
:rtype: None
"""
@@ -225,7 +230,8 @@ def series_upgrade_application(application, pause_non_leader_primary=True,
logging.info("Series upgrade leader: {}".format(leader))
series_upgrade(leader, status["units"][leader]["machine"],
from_series=from_series, to_series=to_series,
origin=origin)
origin=origin, workaround_script=workaround_script,
files=files)
# Series upgrade the non-leaders
for unit in non_leaders:
@@ -233,12 +239,14 @@ def series_upgrade_application(application, pause_non_leader_primary=True,
.format(unit))
series_upgrade(unit, status["units"][unit]["machine"],
from_series=from_series, to_series=to_series,
origin=origin)
origin=origin, workaround_script=workaround_script,
files=files)
def series_upgrade(unit_name, machine_num,
from_series="trusty", to_series="xenial",
origin='openstack-origin'):
origin='openstack-origin',
files=None, workaround_script=None):
"""Perform series upgrade on a unit.
:param unit_name: Unit Name
@@ -252,6 +260,10 @@ def series_upgrade(unit_name, machine_num,
:param origin: The configuration setting variable name for changing origin
source. (openstack-origin or source)
:type origin: str
:param files: Workaround files to scp to unit under upgrade
:type files: list
:param workaround_script: Workaround script to run during series upgrade
:type workaround_script: str
:returns: None
:rtype: None
"""
@@ -260,7 +272,8 @@ def series_upgrade(unit_name, machine_num,
logging.info("Watiing for model idleness")
model.block_until_all_units_idle()
wrap_do_release_upgrade(unit_name, from_series=from_series,
to_series=to_series)
to_series=to_series, files=files,
workaround_script=workaround_script)
reboot(unit_name)
# Without the sleep model.block_on_all_units_idle returns to early
logging.info("Sleeping after reboot...")
@@ -292,7 +305,8 @@ def set_origin(application, origin='openstack-origin', pocket='distro'):
def wrap_do_release_upgrade(unit_name, from_series="trusty",
to_series="xenial"):
to_series="xenial",
files=None, workaround_script=None):
"""Wrap do release upgrade.
In a production environment this step would be run administratively.
@@ -304,6 +318,10 @@ def wrap_do_release_upgrade(unit_name, from_series="trusty",
:type from_series: str
:param to_series: The series to which to upgrade
:type to_series: str
:param files: Workaround files to scp to unit under upgrade
:type files: list
:param workaround_script: Workaround script to run during series upgrade
:type workaround_script: str
:returns: None
:rtype: None
"""
@@ -311,13 +329,13 @@ def wrap_do_release_upgrade(unit_name, from_series="trusty",
# There are a few necessary hacks to accomplish an automated upgrade
# to overcome some packaging bugs.
# Copy scripts
_files = ["package-workarounds.sh", "corosync", "corosync.conf"]
for _file in _files:
model.scp_to_unit(unit_name, _file, _file)
if files:
for _file in files:
model.scp_to_unit(unit_name, _file, os.path.basename(_file))
# Run Scripts
model.run_on_unit(
unit_name, "/home/ubuntu/package-workarounds.sh")
if workaround_script:
model.run_on_unit(unit_name, workaround_script)
# Actually do the do_release_upgrade
do_release_upgrade(unit_name)