def dist_upgrade(unit_name): """Run dist-upgrade on unit after update package db. :param unit_name: Unit Name :type unit_name: str :returns: None :rtype: None """ logging.info('Updating package db ' + unit_name) update_cmd = 'sudo apt update' model.run_on_unit(unit_name, update_cmd) logging.info('Updating existing packages ' + unit_name) dist_upgrade_cmd = ( """sudo DEBIAN_FRONTEND=noninteractive apt --assume-yes """ """-o "Dpkg::Options::=--force-confdef" """ """-o "Dpkg::Options::=--force-confold" dist-upgrade""") model.run_on_unit(unit_name, dist_upgrade_cmd) rdict = model.run_on_unit(unit_name, "cat /var/run/reboot-required") if "Stdout" in rdict and "restart" in rdict["Stdout"].lower(): logging.info("dist-upgrade required reboot {}".format(unit_name)) os_utils.reboot(unit_name) logging.info("Waiting for workload status 'unknown' on {}" .format(unit_name)) model.block_until_unit_wl_status(unit_name, "unknown") logging.info("Waiting for workload status to return to normal on {}" .format(unit_name)) model.block_until_unit_wl_status( unit_name, "unknown", negate_match=True) logging.info("Waiting for model idleness") # pause for a big time.sleep(5.0) model.block_until_all_units_idle()
def _reboot_vgpu_units(self): vgpu_unit_names = self._get_vgpu_unit_names() for vgpu_unit_name in vgpu_unit_names: logging.info('Rebooting {} ...'.format(vgpu_unit_name)) generic_utils.reboot(vgpu_unit_name) zaza.model.block_until_unit_wl_status(vgpu_unit_name, "unknown") for vgpu_unit_name in vgpu_unit_names: zaza.model.block_until_unit_wl_status(vgpu_unit_name, "active") zaza.model.block_until_all_units_idle()
def test_reboot(self): _unit = "app/2" generic_utils.reboot(_unit) self.subprocess.check_call.assert_called_once_with( ['juju', 'ssh', _unit, 'sudo', 'reboot', '&&', 'exit'])
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)