示例#1
0
 def test_return_true_when_package_installed(self):
   stdout = dedent("""
   Package: python3
   Status: install ok installed
   Priority: optional
   Section: python
   Installed-Size: 89
   Maintainer: Matthias Klose <*****@*****.**>
   Architecture: amd64
   Multi-Arch: allowed
   Source: python3-defaults
   Version: 3.9.2-3
   Replaces: python3-minimal (<< 3.1.2-2)
   Provides: python3-profiler
   Depends: python3.9 (>= 3.9.2-0~), libpython3-stdlib (= 3.9.2-3)
   Pre-Depends: python3-minimal (= 3.9.2-3)
   Suggests: python3-doc (>= 3.9.2-3), python3-tk (>= 3.9.2-0~),
   Description: interactive high-level object-oriented languag
    Python, the high-level, interactive object oriented language,
    includes an extensive class library with lots of goodies for
    network programming, system administration, sounds and graphics.
    .
    This package is a dependency package, which depends on Debian's default
    Python 3 version (currently v3.9).
   Homepage: https://www.python.org/
   Cnf-Extra-Commands: python
   Cnf-Priority-Bonus: 5""").strip()
   g = None
   a = Apt(_mock_run(['dpkg', '-s', 'python3'],
                     CompletedProcess(stdout, 'stderr', 0, 'cmd')))
   assert a.get_package_version(g, 'python3') == '3.9.2-3'
示例#2
0
 def test_return_empty_string_when_version_not_detected(self):
   stdout = dedent("""
   Package: python3
   Cnf-Priority-Bonus: 5""").strip()
   g = None
   a = Apt(_mock_run(['dpkg', '-s', 'python3'],
                     CompletedProcess(stdout, 'stderr', 0, 'cmd')))
   assert a.get_package_version(g, 'python3') == ''
示例#3
0
def setup_cloud_init(g: guestfs.GuestFS):
    """ Install cloud-init if not present, and configure to the cloud provider.

  Args:
    g: A mounted GuestFS instance.
  """
    a = Apt(run)
    curr_version = a.get_package_version(g, 'cloud-init')
    available_versions = a.list_available_versions(g, 'cloud-init')
    # Try to avoid installing 21.3-1, which conflicts which the guest agent.
    # On first boot, systemd reaches a deadlock deadlock and doest start
    # its unit. If a version other than 21.3-1 isn't explicitly found, *and*
    # cloud-init isn't currently installed, then this allows apt to pick the
    # version to install.
    version_to_install = Apt.determine_version_to_install(
        curr_version, available_versions, {'21.3-1'})
    pkg_to_install = ''
    if version_to_install:
        pkg_to_install = 'cloud-init=' + version_to_install
    elif curr_version == '':
        pkg_to_install = 'cloud-init'
    # If this block doesn't execute, it means that cloud-init was found
    # on the system, but there wasn't an upgrade candidate. Therefore
    # leave the version that's currently installed.
    if pkg_to_install:
        logging.info(pkg_to_install)
        utils.install_apt_packages(g, pkg_to_install)
    # Ubuntu 14.04's version of cloud-init doesn't have `clean`.
    if g.gcp_image_major > '14':
        run(g, 'cloud-init clean')
    # Remove cloud-init configs that may conflict with GCE's.
    #
    # - subiquity disables automatic network configuration
    #     https://bugs.launchpad.net/ubuntu/+source/cloud-init/+bug/1871975
    for cfg in [
            'azure', 'curtin', 'waagent', 'walinuxagent', 'aws', 'amazon',
            'subiquity'
    ]:
        run(g, 'rm -f /etc/cloud/cloud.cfg.d/*%s*' % cfg)
    g.write('/etc/cloud/cloud.cfg.d/91-gce-system.cfg', cloud_init_config)
示例#4
0
 def test_return_empty_string_when_package_not_installed(self):
   g = None
   a = Apt(_mock_run(['dpkg', '-s', 'cloud-init'],
                     CompletedProcess('stdout', 'stderr', 1, 'cmd')))
   assert a.get_package_version(g, 'cloud-init') == ''