Beispiel #1
0
 def test_return_empty_list_if_package_not_available(self):
   g = None
   a = Apt(_mock_run(
     ['apt-cache', 'madison', 'cloud-init'],
     CompletedProcess(
       'N: Unable to locate package cloud-init', '', 1, 'cmd')))
   assert a.list_available_versions(g, 'cloud-init') == set()
Beispiel #2
0
  def test_skip_lines_from_madison_with_unexpected_syntax(self):
    g = None
    stdout = '\n'.join([
      'cloud-init | 21.3-1-g6803368d-0ubuntu1~20.04.3 | repo',
      'cloud-init | extra bar | repo | not-recognized',
      'cloud-init | missing bar',
      'no bar',
    ])

    a = Apt(_mock_run(['apt-cache', 'madison', 'cloud-init'],
                      CompletedProcess(stdout, '', 0, 'cmd')))
    assert a.list_available_versions(g, 'cloud-init') == {
      '21.3-1-g6803368d-0ubuntu1~20.04.3'}
Beispiel #3
0
  def test_return_versions_if_available(self):
    g = None
    stdout = '\n'.join([
      'cloud-init | 21.3-1-g6803368d-0ubuntu1~20.04.3 | repo',
      'cloud-init | 20.1-10-g71af48df-0ubuntu5 | repo',
      'cloud-init | 0.7.5-0ubuntu1.23 | repo',
    ])

    a = Apt(_mock_run(['apt-cache', 'madison', 'cloud-init'],
                      CompletedProcess(stdout, '', 0, 'cmd')))
    assert a.list_available_versions(g, 'cloud-init') == {
      '21.3-1-g6803368d-0ubuntu1~20.04.3',
      '20.1-10-g71af48df-0ubuntu5',
      '0.7.5-0ubuntu1.23'}
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)