summaryrefslogtreecommitdiff
path: root/tests/unittests/test_handler/test_handler_apt_source_v3.py
diff options
context:
space:
mode:
authorzsdc <taras@vyos.io>2020-03-11 21:20:58 +0200
committerzsdc <taras@vyos.io>2020-03-11 21:22:23 +0200
commitc6627bc05a57645e6af8b9a5a67e452d9f37e487 (patch)
treeb754b3991e5e57a9ae9155819f73fa0cbd4be269 /tests/unittests/test_handler/test_handler_apt_source_v3.py
parentca9a4eb26b41c204d1bd3a15586b14a5dde950bb (diff)
parent13e82554728b1cb524438163784e5b955c7c5ed0 (diff)
downloadvyos-cloud-init-c6627bc05a57645e6af8b9a5a67e452d9f37e487.tar.gz
vyos-cloud-init-c6627bc05a57645e6af8b9a5a67e452d9f37e487.zip
Cloud-init: T2117: Updated to 20.1
- Merge 20.1 version from the Canonical repository - Removed unneeded changes in datasources (now only OVF datasource is not equal to upstream's version) - Adapted cc_vyos module to new Cloud-init version - Changed Jenkinsfile to use build scripts, provided by upstream
Diffstat (limited to 'tests/unittests/test_handler/test_handler_apt_source_v3.py')
-rw-r--r--tests/unittests/test_handler/test_handler_apt_source_v3.py45
1 files changed, 27 insertions, 18 deletions
diff --git a/tests/unittests/test_handler/test_handler_apt_source_v3.py b/tests/unittests/test_handler/test_handler_apt_source_v3.py
index 90fe6eed..90949b6d 100644
--- a/tests/unittests/test_handler/test_handler_apt_source_v3.py
+++ b/tests/unittests/test_handler/test_handler_apt_source_v3.py
@@ -11,13 +11,8 @@ import shutil
import socket
import tempfile
-from unittest import TestCase
-
-try:
- from unittest import mock
-except ImportError:
- import mock
-from mock import call
+from unittest import TestCase, mock
+from unittest.mock import call
from cloudinit import cloud
from cloudinit import distros
@@ -453,14 +448,14 @@ class TestAptSourceConfig(t_help.FilesystemMockingTestCase):
self.assertFalse(os.path.isfile(self.aptlistfile2))
self.assertFalse(os.path.isfile(self.aptlistfile3))
- @mock.patch("cloudinit.config.cc_apt_configure.util.get_architecture")
- def test_apt_v3_list_rename(self, m_get_architecture):
+ @mock.patch("cloudinit.config.cc_apt_configure.util.get_dpkg_architecture")
+ def test_apt_v3_list_rename(self, m_get_dpkg_architecture):
"""test_apt_v3_list_rename - Test find mirror and apt list renaming"""
pre = "/var/lib/apt/lists"
# filenames are archive dependent
arch = 's390x'
- m_get_architecture.return_value = arch
+ m_get_dpkg_architecture.return_value = arch
component = "ubuntu-ports"
archive = "ports.ubuntu.com"
@@ -487,16 +482,17 @@ class TestAptSourceConfig(t_help.FilesystemMockingTestCase):
with mock.patch.object(os, 'rename') as mockren:
with mock.patch.object(glob, 'glob',
return_value=[fromfn]):
- cc_apt_configure.rename_apt_lists(mirrors, TARGET)
+ cc_apt_configure.rename_apt_lists(mirrors, TARGET, arch)
mockren.assert_any_call(fromfn, tofn)
- @mock.patch("cloudinit.config.cc_apt_configure.util.get_architecture")
- def test_apt_v3_list_rename_non_slash(self, m_get_architecture):
+ @mock.patch("cloudinit.config.cc_apt_configure.util.get_dpkg_architecture")
+ def test_apt_v3_list_rename_non_slash(self, m_get_dpkg_architecture):
target = os.path.join(self.tmp, "rename_non_slash")
apt_lists_d = os.path.join(target, "./" + cc_apt_configure.APT_LISTS)
- m_get_architecture.return_value = 'amd64'
+ arch = 'amd64'
+ m_get_dpkg_architecture.return_value = arch
mirror_path = "some/random/path/"
primary = "http://test.ubuntu.com/" + mirror_path
@@ -532,7 +528,7 @@ class TestAptSourceConfig(t_help.FilesystemMockingTestCase):
fpath = os.path.join(apt_lists_d, opre + suff)
util.write_file(fpath, content=fpath)
- cc_apt_configure.rename_apt_lists(mirrors, target)
+ cc_apt_configure.rename_apt_lists(mirrors, target, arch)
found = sorted(os.listdir(apt_lists_d))
self.assertEqual(expected, found)
@@ -625,10 +621,12 @@ class TestAptSourceConfig(t_help.FilesystemMockingTestCase):
self.assertEqual(mirrors['SECURITY'],
smir)
- @mock.patch("cloudinit.config.cc_apt_configure.util.get_architecture")
- def test_apt_v3_get_def_mir_non_intel_no_arch(self, m_get_architecture):
+ @mock.patch("cloudinit.config.cc_apt_configure.util.get_dpkg_architecture")
+ def test_apt_v3_get_def_mir_non_intel_no_arch(
+ self, m_get_dpkg_architecture
+ ):
arch = 'ppc64el'
- m_get_architecture.return_value = arch
+ m_get_dpkg_architecture.return_value = arch
expected = {'PRIMARY': 'http://ports.ubuntu.com/ubuntu-ports',
'SECURITY': 'http://ports.ubuntu.com/ubuntu-ports'}
self.assertEqual(expected, cc_apt_configure.get_default_mirrors())
@@ -998,6 +996,17 @@ deb http://ubuntu.com/ubuntu/ xenial-proposed main""")
class TestDebconfSelections(TestCase):
+ @mock.patch("cloudinit.config.cc_apt_configure.util.subp")
+ def test_set_sel_appends_newline_if_absent(self, m_subp):
+ """Automatically append a newline to debconf-set-selections config."""
+ selections = b'some/setting boolean true'
+ cc_apt_configure.debconf_set_selections(selections=selections)
+ cc_apt_configure.debconf_set_selections(selections=selections + b'\n')
+ m_call = mock.call(
+ ['debconf-set-selections'], data=selections + b'\n', capture=True,
+ target=None)
+ self.assertEqual([m_call, m_call], m_subp.call_args_list)
+
@mock.patch("cloudinit.config.cc_apt_configure.debconf_set_selections")
def test_no_set_sel_if_none_to_set(self, m_set_sel):
cc_apt_configure.apply_debconf_selections({'foo': 'bar'})