summaryrefslogtreecommitdiff
path: root/tests/unittests/test_curthooks.py
diff options
context:
space:
mode:
authorOlivier Gayot <[email protected]>2023-02-17 11:09:47 +0100
committerOlivier Gayot <[email protected]>2023-02-20 15:23:37 +0100
commitce9ca9775f12cf0e3087ae41c295bcda267275f1 (patch)
treea84ff266af3c220a51424ec561027b3dcb06ec36 /tests/unittests/test_curthooks.py
parent5af09277662422d7301a67e547d2115ee103e072 (diff)
apt-config: fix curthooks unconditionally triggering apt-config
The following commit: 1257a38f translate old curtin apt features to new format introduced the ability to translate old top level keys related to apt features (e.g., debconf_selections, apt-proxy, apt-mirrors) to the new format where they are stored as children of 'apt'. apt: debconf_selections: => debconf_selections: foobar foobar Sadly, by doing so, it introduced a regression, making curthooks call apt_config.handle_apt unconditionally. The curthooks.do_apt_config function only calls apt_config.handle_apt if the configuration does not contain the 'apt' key or if the 'apt' key has the value None (i.e., null in YAML). When implementing the translation from old to new configuration format, we accidentally forced the 'apt' key to exist and coerced it to dictionary. This effectively defeats the condition in curthooks.do_apt_config. Fixed by making sure we only create the apt key if needed when doing the translation. Signed-off-by: Olivier Gayot <[email protected]>
Diffstat (limited to 'tests/unittests/test_curthooks.py')
-rw-r--r--tests/unittests/test_curthooks.py33
1 files changed, 33 insertions, 0 deletions
diff --git a/tests/unittests/test_curthooks.py b/tests/unittests/test_curthooks.py
index c13434cf..9e4fa877 100644
--- a/tests/unittests/test_curthooks.py
+++ b/tests/unittests/test_curthooks.py
@@ -2268,4 +2268,37 @@ class TestUefiFindGrubDeviceIds(CiTestCase):
self._sconfig(cfg)))
+class TestDoAptConfig(CiTestCase):
+ def setUp(self):
+ super(TestDoAptConfig, self).setUp()
+ self.handle_apt_sym = 'curtin.commands.curthooks.apt_config.handle_apt'
+
+ def test_no_apt_config(self):
+ with patch(self.handle_apt_sym) as m_handle_apt:
+ curthooks.do_apt_config({}, target="/")
+ m_handle_apt.assert_not_called()
+
+ def test_apt_config_none(self):
+ with patch(self.handle_apt_sym) as m_handle_apt:
+ curthooks.do_apt_config({"apt": None}, target="/")
+ m_handle_apt.assert_not_called()
+
+ def test_apt_config_dict(self):
+ with patch(self.handle_apt_sym) as m_handle_apt:
+ curthooks.do_apt_config({"apt": {}}, target="/")
+ m_handle_apt.assert_called()
+
+ def test_with_apt_config(self):
+ with patch(self.handle_apt_sym) as m_handle_apt:
+ curthooks.do_apt_config(
+ {"apt": {"proxy": {"http_proxy": "http://proxy:3128"}}},
+ target="/")
+ m_handle_apt.assert_called_once()
+
+ def test_with_debconf_selections(self):
+ # debconf_selections are translated to apt config
+ with patch(self.handle_apt_sym) as m_handle_apt:
+ curthooks.do_apt_config({"debconf_selections": "foo"}, target="/")
+ m_handle_apt.assert_called_once()
+
# vi: ts=4 expandtab syntax=python