def test_set_origin(self): "application, origin='openstack-origin', pocket='distro'):" self.patch_object(generic_utils.model, "set_application_config") _application = "application" _origin = "source" _pocket = "cloud:fake-cloud" generic_utils.set_origin(_application, origin=_origin, pocket=_pocket) self.set_application_config.assert_called_once_with( _application, {_origin: _pocket})
def series_upgrade(unit_name, machine_num, from_series="trusty", to_series="xenial", origin='openstack-origin', files=None, workaround_script=None, post_upgrade_functions=None): """Perform series upgrade on a unit. :param unit_name: Unit Name :type unit_name: str :param machine_num: Machine number :type machine_num: str :param from_series: The series from which to upgrade :type from_series: str :param to_series: The series to which to upgrade :type to_series: str :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 """ logging.info("Series upgrade {}".format(unit_name)) application = unit_name.split('/')[0] os_utils.set_dpkg_non_interactive_on_unit(unit_name) dist_upgrade(unit_name) model.block_until_all_units_idle() logging.info("Prepare series upgrade on {}".format(machine_num)) model.prepare_series_upgrade(machine_num, to_series=to_series) logging.info( "Waiting for workload status 'blocked' on {}".format(unit_name)) model.block_until_unit_wl_status(unit_name, "blocked") logging.info("Waiting for model idleness") model.block_until_all_units_idle() wrap_do_release_upgrade(unit_name, from_series=from_series, to_series=to_series, files=files, workaround_script=workaround_script) logging.info("Reboot {}".format(unit_name)) os_utils.reboot(unit_name) logging.info( "Waiting for workload status 'blocked' on {}".format(unit_name)) model.block_until_unit_wl_status(unit_name, "blocked") logging.info("Waiting for model idleness") model.block_until_all_units_idle() logging.info("Set origin on {}".format(application)) # Allow for charms which have neither source nor openstack-origin if origin: os_utils.set_origin(application, origin) model.block_until_all_units_idle() logging.info("Complete series upgrade on {}".format(machine_num)) model.complete_series_upgrade(machine_num) model.block_until_all_units_idle() logging.info( "Running run_post_upgrade_functions {}".format(post_upgrade_functions)) run_post_upgrade_functions(post_upgrade_functions) logging.info( "Waiting for workload status 'active' on {}".format(unit_name)) model.block_until_unit_wl_status(unit_name, "active") model.block_until_all_units_idle() # This step may be performed by juju in the future logging.info("Set series on {} to {}".format(application, to_series)) model.set_series(application, to_series)
def series_upgrade_application(application, pause_non_leader_primary=True, pause_non_leader_subordinate=True, from_series="trusty", to_series="xenial", origin='openstack-origin', completed_machines=[], files=None, workaround_script=None, post_upgrade_functions=None): """Series upgrade application. Wrap all the functionality to handle series upgrade for a given application. Including pausing non-leader units. :param application: Name of application to upgrade series :type application: str :param pause_non_leader_primary: Whether the non-leader applications should be paused :type pause_non_leader_primary: bool :param pause_non_leader_subordinate: Whether the non-leader subordinate hacluster applications should be paused :type pause_non_leader_subordinate: bool :param from_series: The series from which to upgrade :type from_series: str :param to_series: The series to which to upgrade :type to_series: str :param origin: The configuration setting variable name for changing origin source. (openstack-origin or source) :type origin: str :param completed_machines: List of completed machines which do no longer require series upgrade. :type completed_machines: list :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 """ status = model.get_status().applications[application] # For some applications (percona-cluster) the leader unit must upgrade # first. For API applications the non-leader haclusters must be paused # before upgrade. Finally, for some applications this is arbitrary but # generalized. leader = None non_leaders = [] for unit in status["units"]: if status["units"][unit].get("leader"): leader = unit else: non_leaders.append(unit) # Pause the non-leaders for unit in non_leaders: if pause_non_leader_subordinate: if status["units"][unit].get("subordinates"): for subordinate in status["units"][unit]["subordinates"]: _app = subordinate.split('/')[0] if _app in SUBORDINATE_PAUSE_RESUME_BLACKLIST: logging.info( "Skipping pausing {} - blacklisted".format( subordinate)) else: logging.info("Pausing {}".format(subordinate)) model.run_action(subordinate, "pause", action_params={}) if pause_non_leader_primary: logging.info("Pausing {}".format(unit)) model.run_action(unit, "pause", action_params={}) machine = status["units"][leader]["machine"] # Series upgrade the leader logging.info("Series upgrade leader: {}".format(leader)) if machine not in completed_machines: series_upgrade(leader, machine, from_series=from_series, to_series=to_series, origin=origin, workaround_script=workaround_script, files=files, post_upgrade_functions=post_upgrade_functions) completed_machines.append(machine) else: logging.info("Skipping unit: {}. Machine: {} already upgraded." "But setting origin on the application {}".format( unit, machine, application)) logging.info("Set origin on {}".format(application)) os_utils.set_origin(application, origin) model.block_until_all_units_idle() # Series upgrade the non-leaders for unit in non_leaders: machine = status["units"][unit]["machine"] if machine not in completed_machines: logging.info("Series upgrade non-leader unit: {}".format(unit)) series_upgrade(unit, machine, from_series=from_series, to_series=to_series, origin=origin, workaround_script=workaround_script, files=files, post_upgrade_functions=post_upgrade_functions) completed_machines.append(machine) else: logging.info("Skipping unit: {}. Machine: {} already upgraded. " "But setting origin on the application {}".format( unit, machine, application)) logging.info("Set origin on {}".format(application)) os_utils.set_origin(application, origin) model.block_until_all_units_idle()