Skip to content

Commit

Permalink
Fix apt default test
Browse files Browse the repository at this point in the history
The apt default test wasn't ported over from cloud-tests correctly.
Fix it so it works as it did in the cloud tests.

Also add openstack specific test for apt configuration with no uri.
  • Loading branch information
TheRealFalcon committed Mar 16, 2021
1 parent f35181f commit a7beda3
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 6 deletions.
42 changes: 36 additions & 6 deletions tests/integration_tests/modules/test_apt.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import pytest

from cloudinit.url_helper import readurl
from tests.integration_tests.instances import IntegrationInstance


Expand Down Expand Up @@ -200,30 +201,41 @@ def test_os_pipelining(self, class_client: IntegrationInstance):
assert conf_exists is False


DEFAULT_DATA = """\
_DEFAULT_DATA = """\
#cloud-config
apt:
primary:
- arches:
- default
{uri}
security:
- arches:
- default
"""
DEFAULT_DATA = _DEFAULT_DATA.format(uri='')


@pytest.mark.ubuntu
@pytest.mark.user_data(DEFAULT_DATA)
class TestDefaults:
def test_primary(self, class_client: IntegrationInstance):
"""Test apt default primary sources.
@pytest.mark.openstack
def test_primary_on_openstack(self, class_client: IntegrationInstance):
"""Test apt default primary source on openstack.
Ported from
tests/cloud_tests/testcases/modules/apt_configure_primary.py
When no uri is provided.
"""
version = class_client.execute(
'curl http://169.254.169.254'
).split('\n')[-1]
zone = class_client.execute(
'curl http://169.254.169.254/{}/meta-data/placement/'
'availability-zone'.format(version),
)

sources_list = class_client.read_from_file('/etc/apt/sources.list')
assert 'deb http://archive.ubuntu.com/ubuntu' in sources_list
assert '{}.clouds.archive.ubuntu.com'.format(zone) in sources_list

@pytest.mark.user_data(DEFAULT_DATA)
def test_security(self, class_client: IntegrationInstance):
"""Test apt default security sources.
Expand All @@ -239,6 +251,24 @@ def test_security(self, class_client: IntegrationInstance):
)


DEFAULT_DATA_WITH_URI = _DEFAULT_DATA.format(
uri='uri: "http://something.random.invalid/ubuntu"'
)


@pytest.mark.user_data(DEFAULT_DATA_WITH_URI)
def test_default_primary_with_uri(client: IntegrationInstance):
"""Test apt default primary sources.
Ported from
tests/cloud_tests/testcases/modules/apt_configure_primary.py
"""
sources_list = client.read_from_file('/etc/apt/sources.list')
assert 'archive.ubuntu.com' not in sources_list

assert 'something.random.invalid' in sources_list


DISABLED_DATA = """\
#cloud-config
apt:
Expand Down
1 change: 1 addition & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ markers =
gce: test will only run on GCE platform
azure: test will only run on Azure platform
oci: test will only run on OCI platform
openstack: test will only run on openstack
lxd_config_dict: set the config_dict passed on LXD instance creation
lxd_container: test will only run in LXD container
lxd_use_exec: `execute` will use `lxc exec` instead of SSH
Expand Down

0 comments on commit a7beda3

Please sign in to comment.