Commit 6c0fc6df authored by Scott Moser's avatar Scott Moser

tests: fix apt tests to run inside ubuntu build environment

This just mocks out use of lsb_release as it is not available
in a build environment.
Additionally mocks out use of getkeybyid.  This admittedly
makes the test for a long key fingerprint not useful as it was
broken only inside getkeybyid.

Also fix 'make yaml' for cloud-config.txt
parent bc9bd58d
......@@ -125,11 +125,11 @@ add_apt_repo_match: '^[\w-]+:\w'
# better merging between multiple input files than a list like:
# cloud-config1
# sources:
s1: {'key': 'key1', 'source': 'source1'}
# s1: {'key': 'key1', 'source': 'source1'}
# cloud-config2
# sources:
s2: {'key': 'key2'}
s1: {filename: 'foo'}
# s2: {'key': 'key2'}
# s1: {filename: 'foo'}
# this would be merged to
#sources:
# s1:
......
......@@ -103,8 +103,9 @@ class TestAptSourceConfigSourceList(t_help.FilesystemMockingTestCase):
with mock.patch.object(templater, 'render_to_file') as mocktmpl:
with mock.patch.object(os.path, 'isfile',
return_value=True) as mockisfile:
cc_apt_configure.handle("notimportant", cfg, mycloud,
LOG, None)
with mock.patch.object(util, 'rename'):
cc_apt_configure.handle("notimportant", cfg, mycloud,
LOG, None)
mockisfile.assert_any_call(
('/etc/cloud/templates/sources.list.%s.tmpl' % distro))
......
......@@ -43,6 +43,8 @@ class TestAptSourceConfig(TestCase):
"""TestAptSourceConfig
Main Class to test apt_source configs
"""
release = "fantastic"
def setUp(self):
super(TestAptSourceConfig, self).setUp()
self.tmp = tempfile.mkdtemp()
......@@ -55,8 +57,12 @@ class TestAptSourceConfig(TestCase):
self.fallbackfn = os.path.join(self.tmp, "etc/apt/sources.list.d/",
"cloud_config_sources.list")
@staticmethod
def _get_default_params():
patcher = mock.patch("cloudinit.config.cc_apt_configure.get_release")
get_rel = patcher.start()
get_rel.return_value = self.release
self.addCleanup(patcher.stop)
def _get_default_params(self):
"""get_default_params
Get the most basic default mrror and release info to be used in tests
"""
......@@ -438,7 +444,7 @@ class TestAptSourceConfig(TestCase):
def test_apt_src_keyid_real(self):
"""test_apt_src_keyid_real
Test specification of a keyid without source incl
up to addition of the key (nothing but add_key_raw mocked)
up to addition of the key (add_key_raw, getkeybyid mocked)
"""
keyid = "03683F77"
params = self._get_default_params()
......@@ -446,7 +452,9 @@ class TestAptSourceConfig(TestCase):
'filename': self.aptlistfile}
with mock.patch.object(cc_apt_configure, 'add_key_raw') as mockobj:
cc_apt_configure.add_sources([cfg], params)
with mock.patch.object(cc_apt_configure, 'getkeybyid') as gkbi:
gkbi.return_value = EXPECTEDKEY
cc_apt_configure.add_sources([cfg], params)
mockobj.assert_called_with(EXPECTEDKEY)
......@@ -464,7 +472,9 @@ class TestAptSourceConfig(TestCase):
'filename': self.aptlistfile}
with mock.patch.object(cc_apt_configure, 'add_key_raw') as mockobj:
cc_apt_configure.add_sources([cfg], params)
with mock.patch.object(cc_apt_configure, 'getkeybyid') as gkbi:
gkbi.return_value = EXPECTEDKEY
cc_apt_configure.add_sources([cfg], params)
mockobj.assert_called_with(EXPECTEDKEY)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment