Ejemplo n.º 1
0
    def test_get_platform_info_trusty(self):
        """get_platform_info handles trusty /etc/os-release parsing."""
        tdir = self.tmp_dir()
        release_file = os.path.join(tdir, 'os-release')
        util.write_file(release_file, OS_RELEASE_TRUSTY)
        parse_dict = util.parse_os_release(release_file)

        def fake_subp(cmd):
            if cmd == ['uname', '-r']:
                return 'kernel-ver', ''
            if cmd == ['uname', '-i']:
                return 'arm64', ''
            assert False, 'Unexpected command: %s' % cmd

        expected = {
            'arch': 'arm64',
            'distribution': 'Ubuntu',
            'kernel': 'kernel-ver',
            'release': '14.04',
            'series': 'trusty',
            'type': 'Linux'
        }
        with mock.patch('uaclient.util.parse_os_release') as m_parse:
            with mock.patch('uaclient.util.subp') as m_subp:
                m_parse.return_value = parse_dict
                m_subp.side_effect = fake_subp
                self.assertEqual(expected, util.get_platform_info())
Ejemplo n.º 2
0
    def test_get_platform_info_with_version(self, series, release,
                                            os_release_content, tmpdir):
        release_file = tmpdir.join('os-release')
        release_file.write(os_release_content)
        parse_dict = util.parse_os_release(release_file.strpath)

        def fake_subp(cmd):
            if cmd == ['uname', '-r']:
                return 'kernel-ver', ''
            if cmd == ['uname', '-i']:
                return 'arm64', ''
            assert False, 'Unexpected command: %s' % cmd

        expected = {
            'arch': 'arm64',
            'distribution': 'Ubuntu',
            'kernel': 'kernel-ver',
            'release': release,
            'series': series,
            'type': 'Linux'
        }

        with mock.patch('uaclient.util.parse_os_release') as m_parse:
            with mock.patch('uaclient.util.subp') as m_subp:
                m_parse.return_value = parse_dict
                m_subp.side_effect = fake_subp
                assert expected == util.get_platform_info()
Ejemplo n.º 3
0
    def test_get_platform_info_with_version(self, series, release, version,
                                            os_release_content, tmpdir):
        release_file = tmpdir.join("os-release")
        release_file.write(os_release_content)
        parse_dict = util.parse_os_release(release_file.strpath)

        expected = {
            "arch": "arm64",
            "distribution": "Ubuntu",
            "kernel": "kernel-ver",
            "release": release,
            "series": series,
            "type": "Linux",
            "version": version,
        }

        with mock.patch("uaclient.util.parse_os_release") as m_parse:
            with mock.patch("uaclient.util.os.uname") as m_uname:
                with mock.patch("uaclient.util.subp") as m_subp:
                    m_parse.return_value = parse_dict
                    # (sysname, nodename, release, version, machine)
                    m_uname.return_value = posix.uname_result(
                        ("", "", "kernel-ver", "", "aarch64"))
                    m_subp.return_value = ("arm64\n", "")
                    assert expected == util.get_platform_info()
Ejemplo n.º 4
0
def process_contract_delta_after_apt_lock() -> None:
    logging.debug("Check whether to upgrade-lts-contract")
    cfg = UAConfig()
    if not cfg.is_attached:
        logging.debug("Skipping upgrade-lts-contract. Machine is unattached")
        return
    out, _err = subp(["lsof", "/var/lib/apt/lists/lock"], rcs=[0, 1])
    msg = "Starting upgrade-lts-contract."
    if out:
        msg += " Retrying every 10 seconds waiting on released apt lock"
    print(msg)
    logging.debug(msg)

    current_version = parse_os_release()["VERSION_ID"]
    current_release = version_to_codename.get(current_version)

    if current_release is None:
        msg = "Unable to get release codename for version: {}".format(
            current_version)
        print(msg)
        logging.warning(msg)
        sys.exit(1)

    past_release = current_codename_to_past_codename.get(current_release)
    if past_release is None:
        msg = "Could not find past release for: {}".format(current_release)
        print(msg)
        logging.warning(msg)
        sys.exit(1)

    past_entitlements = UAConfig(series=past_release).entitlements
    new_entitlements = UAConfig(series=current_release).entitlements

    retry_count = 0
    while out:
        # Loop until apt hold is released at the end of `do-release-upgrade`
        time.sleep(10)
        out, _err = subp(["lsof", "/var/lib/apt/lists/lock"], rcs=[0, 1])
        retry_count += 1

    msg = "upgrade-lts-contract processing contract deltas: {} -> {}".format(
        past_release, current_release)
    print(msg)
    logging.debug(msg)

    process_entitlements_delta(
        cfg=cfg,
        past_entitlements=past_entitlements,
        new_entitlements=new_entitlements,
        allow_enable=True,
        series_overrides=False,
    )
    msg = "upgrade-lts-contract succeeded after {} retries".format(retry_count)
    print(msg)
    logging.debug(msg)
Ejemplo n.º 5
0
def process_contract_delta_after_apt_lock() -> None:
    setup_logging(logging.INFO, logging.DEBUG)
    logging.debug("Check whether to upgrade-lts-contract")
    if not UAConfig().is_attached:
        logging.debug("Skiping upgrade-lts-contract. Machine is unattached")
        return
    out, _err = subp(["lsof", "/var/lib/apt/lists/lock"], rcs=[0, 1])
    msg = "Starting upgrade-lts-contract."
    if out:
        msg += " Retrying every 10 seconds waiting on released apt lock"
    print(msg)
    logging.debug(msg)

    current_version = parse_os_release()["VERSION_ID"]
    current_release = version_to_codename[current_version]

    if current_release == "trusty":
        msg = "Unable to execute upgrade-lts-contract.py on trusty"
        print(msg)
        logging.warning(msg)
        sys.exit(1)

    past_release = current_codename_to_past_codename[current_release]
    past_entitlements = UAConfig(series=past_release).entitlements
    new_entitlements = UAConfig(series=current_release).entitlements

    retry_count = 0
    while out:
        # Loop until that apt hold is released (at the end of the do-release-upgrade operation
        # when a reboot is suggested)
        time.sleep(10)
        out, _err = subp(["lsof", "/var/lib/apt/lists/lock"], rcs=[0, 1])
        retry_count += 1

    msg = "upgrade-lts-contract processing contract deltas: {} -> {}".format(
        past_release, current_release)
    print(msg)
    logging.debug(msg)

    process_entitlements_delta(
        past_entitlements=past_entitlements,
        new_entitlements=new_entitlements,
        allow_enable=True,
        series_overrides=False,
    )
    msg = "upgrade-lts-contract succeeded after {} retries".format(retry_count)
    print(msg)
    logging.debug(msg)
Ejemplo n.º 6
0
 def test_parse_os_release(self, tmpdir):
     """parse_os_release returns a dict of values from /etc/os-release."""
     release_file = tmpdir.join('os-release')
     release_file.write(OS_RELEASE_TRUSTY)
     expected = {
         'BUG_REPORT_URL': 'http://bugs.launchpad.net/ubuntu/',
         'HOME_URL': 'http://www.ubuntu.com/',
         'ID': 'ubuntu',
         'ID_LIKE': 'debian',
         'NAME': 'Ubuntu',
         'PRETTY_NAME': 'Ubuntu 14.04.5 LTS',
         'SUPPORT_URL': 'http://help.ubuntu.com/',
         'VERSION': '14.04.5 LTS, Trusty Tahr',
         'VERSION_ID': '14.04'
     }
     assert expected == util.parse_os_release(release_file.strpath)
Ejemplo n.º 7
0
 def test_parse_os_release(self, tmpdir):
     """parse_os_release returns a dict of values from /etc/os-release."""
     release_file = tmpdir.join("os-release")
     release_file.write(OS_RELEASE_TRUSTY)
     expected = {
         "BUG_REPORT_URL": "http://bugs.launchpad.net/ubuntu/",
         "HOME_URL": "http://www.ubuntu.com/",
         "ID": "ubuntu",
         "ID_LIKE": "debian",
         "NAME": "Ubuntu",
         "PRETTY_NAME": "Ubuntu 14.04.5 LTS",
         "SUPPORT_URL": "http://help.ubuntu.com/",
         "VERSION": "14.04.5 LTS, Trusty Tahr",
         "VERSION_ID": "14.04",
     }
     assert expected == util.parse_os_release(release_file.strpath)
Ejemplo n.º 8
0
 def test_parse_os_release(self):
     """parse_os_release returns a dict of values from /etc/os-release."""
     tdir = self.tmp_dir()
     release_file = os.path.join(tdir, 'os-release')
     util.write_file(release_file, OS_RELEASE_TRUSTY)
     expected = {
         'BUG_REPORT_URL': 'http://bugs.launchpad.net/ubuntu/',
         'HOME_URL': 'http://www.ubuntu.com/',
         'ID': 'ubuntu',
         'ID_LIKE': 'debian',
         'NAME': 'Ubuntu',
         'PRETTY_NAME': 'Ubuntu 14.04.5 LTS',
         'SUPPORT_URL': 'http://help.ubuntu.com/',
         'VERSION': '14.04.5 LTS, Trusty Tahr',
         'VERSION_ID': '14.04'
     }
     self.assertEqual(expected, util.parse_os_release(release_file))