Ejemplo n.º 1
0
    def wait_for_target(s, progress=None, timeout=30):
        '''
        Wait for the remote system to come up far enough that we can start talking
        (ssh) to it.
        '''
        center('Base::wait_for_system_ex')

        if progress:
            s.progress(progress)

        start = datetime.utcnow()
        cinfo('Starting waiting for \'%s\' at %s' % (s.target, start))

        # Keep spinning until we either timeout or we get back some output from 'uname -vr'
        #
        while True:
            try:
                result, output = s.ssh(
                    'uname -vr',
                    additional_ssh_options="-o BatchMode=yes -o LogLevel=quiet"
                )
                if result == 0 and len(output) > 0:
                    cdebug("exit result is 0")
                    break

            except ShellError as e:

                if 'port 22: Connection refused' in e.output:
                    # Just ignore this, we know that we can connect to the remote host
                    # otherwise we wouldn't have been able to reboot it.
                    #
                    print("** Encountered 'Connection refused'")
                    pass
                else:
                    print("Something else bad happened")
                    cleave('Base::wait_for_system')
                    raise

            now = datetime.utcnow()
            delta = now - start
            if delta.seconds > timeout * 60:
                cinfo('Timed out at: %s' % now)
                raise ErrorExit(
                    'The specified timeout (%d) was reached while waiting for the target system (%s) to come back up.'
                    % (timeout, s.target))

            sleep(60)
            cinfo('Checking at: %s' % datetime.utcnow())

        cleave('Base::wait_for_system_ex')
Ejemplo n.º 2
0
    def provision(s):
        center(s.__class__.__name__ + 'provision')

        reboot = None
        retval = False

        s.wait_for_target(
        )  # Make sure the instance is up before we try to modify it.

        s.fixup_hosts()

        # The very first thing we need to do is make our changes to the apt sources and then dist-upgrade
        # the system. Once we do this the kernels that we install should be the right one.
        #
        s.fixup_apt_sources()
        s.enable_proposed()
        # s.enable_src()
        if s.ppa is not None:
            s.enable_ppa()

        # Disable APT from periodicly running and trying to update the systems.
        #
        s.disable_apt_periodic_updates()

        # If we want an HWE kernel installed on the bare metal then at this point the correct
        # LTS kernel has been installed and it's time to install the HWE kernel.
        #
        if s.hwe:
            s.install_hwe_kernel()
            reboot = 'Rebooting for HWE Kernel'

        if s.debs is not None:
            s.install_custom_debs()
            reboot = 'Rebooting for custom debs'

        if s.flavour == 'generic':
            s.kernel_upgrade()
            reboot = 'Reboot for kenel update'
        if s.flavour != 'generic':
            s.install_kernel_flavour()
            reboot = 'Rebooting for Kernel flavour %s' % s.flavour

        s.mainline_firmware_hack()

        s.install_python_minimal()
        s.install_required_pkgs()

        if reboot:
            s.reboot(progress=reboot)

        if s.lkp:
            s.enable_live_kernel_patching()

        s.progress('Verifying the running kernel version')
        if not s.verify_target():
            cinfo("Target verification failed.")
        else:
            retval = True

        s.progress('That\'s All Folks!')

        cleave(s.__class__.__name__ + 'provision (%s)' % retval)
        return retval
Ejemplo n.º 3
0
    def provision(s):
        center("Enter Metal::provision")

        dist_upgrade = None
        reboot = None
        retval = False

        # If the provisioning type is "manual" then the system has been setup by hand however,
        # go ahead and dist-upgrade it.
        #
        if s.ps.type == "manual":
            # s.dist_upgrade()
            s.reboot(progress="Rebooting for dist-upgrade")
            # As we don't run dist_upgrade() here, it's better to verify the kerenl version first
            if s.xen:
                if not s.verify_xen_target():
                    cinfo("Target verification failed.")
                else:
                    retval = True
            else:
                if not s.verify_target():
                    cinfo("Target verification failed.")
                else:
                    retval = True
            return retval

        s.progress('Provisioner setup')
        if not s.ps.provision():
            raise ErrorExit('Failed to provision the system')

        sleep(60 * 5)

        s.fixup_hosts()

        # The very first thing we need to do is make our changes to the apt sources and then dist-upgrade
        # the system. Once we do this the kernels that we install should be the right one.
        #
        # s.fixup_apt_sources() # This is breaking some systems
        s.remove_90curtin_aptproxy()
        s.enable_proposed()
        s.enable_src()
        if s.ppa is not None:
            s.enable_ppa()
            dist_upgrade = True

        s.reboot(progress="for the pure love of rebooting")

        # Disable APT from periodicly running and trying to update the systems.
        #
        s.disable_apt_periodic_updates()

        # If we want an HWE kernel installed on the bare metal then at this point the correct
        # LTS kernel has been installed and it's time to install the HWE kernel.
        #
        if '~' in s.required_kernel_version:
            s.install_hwe_kernel()
            reboot = 'Rebooting for HWE Kernel'

        if s.xen:
            s.install_xen()
            reboot = 'Rebooting for Xen Kernel'

        if s.debs is not None:
            s.install_custom_debs()
            reboot = 'Rebooting for custom debs'

        # We *always* enable proposed. However, for development series kernels
        # we only update the kernel packages.
        #
        if Ubuntu().is_development_series(s.series):
            s.kernel_upgrade()
            reboot = 'Rebooting for development series kernel'
        else:
            dist_upgrade = True

        s.mainline_firmware_hack()

        s.install_python_minimal()
        s.install_required_pkgs()

        if dist_upgrade:
            s.dist_upgrade()
            if not reboot:
                reboot = 'Rebooting for dist-upgrade'

        if s.flavour != 'generic':
            s.install_kernel_flavour()
            reboot = 'Rebooting for Kernel flavour %s' % s.flavour

        if s.kernel:
            s.install_specific_kernel_version()
            reboot = 'Rebooting for Kernel version %s' % s.kernel

        if reboot:
            s.reboot(progress=reboot)

        if s.lkp:
            s.enable_live_kernel_patching()
        elif s.lkp_snappy:
            s.enable_snappy_client_live_kernel_patching()

        s.progress('Verifying the running kernel version')
        if s.xen:
            if not s.verify_xen_target():
                cinfo("Target verification failed.")
            else:
                retval = True
        else:
            if not s.verify_target():
                cinfo("Target verification failed.")
            else:
                retval = True

        s.progress('That\'s All Folks!')

        cleave("Metal::provision (%s)" % (retval))
        return retval