def test_run_via_ssh(self): _unit = "app/2" _cmd = "hostname" generic_utils.run_via_ssh(_unit, _cmd) self.subprocess.check_call.assert_called_once_with( ['juju', 'ssh', _unit, 'sudo ' + _cmd])
def do_release_upgrade(unit_name): """Run do-release-upgrade noninteractive. :param unit_name: Unit Name :type unit_name: str :returns: None :rtype: None """ logging.info('Upgrading ' + unit_name) # NOTE: It is necessary to run this via juju ssh rather than juju run due # to timeout restrictions and error handling. os_utils.run_via_ssh( unit_name, 'DEBIAN_FRONTEND=noninteractive ' 'do-release-upgrade -f DistUpgradeViewNonInteractive')
def wrap_do_release_upgrade(unit_name, from_series="trusty", to_series="xenial", files=None, workaround_script=None): """Wrap do release upgrade. In a production environment this step would be run administratively. For testing purposes we need this automated. :param unit_name: Unit Name :type unit_name: 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 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 """ # Pre upgrade hacks # There are a few necessary hacks to accomplish an automated upgrade # to overcome some packaging bugs. # Copy scripts if files: logging.info("SCP files") for _file in files: logging.info("SCP {}".format(_file)) model.scp_to_unit(unit_name, _file, os.path.basename(_file)) # Run Script if workaround_script: logging.info("Running workaround script") os_utils.run_via_ssh(unit_name, workaround_script) # Actually do the do_release_upgrade do_release_upgrade(unit_name)