From ce9ca9775f12cf0e3087ae41c295bcda267275f1 Mon Sep 17 00:00:00 2001 From: Olivier Gayot Date: Fri, 17 Feb 2023 11:09:47 +0100 Subject: 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 --- tests/unittests/test_curthooks.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'tests/unittests/test_curthooks.py') 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 -- cgit v1.2.3