def test_dpkg_reconfigure_does_reconfigure(self, m_subp): target = "/foo-target" # due to the way the cleaners are called (via dictionary reference) # mocking clean_cloud_init directly does not work. So we mock # the CONFIG_CLEANERS dictionary and assert our cleaner is called. ci_cleaner = mock.MagicMock() with mock.patch.dict("curtin.commands.apt_config.CONFIG_CLEANERS", values={'cloud-init': ci_cleaner}, clear=True): apt_config.dpkg_reconfigure(['pkga', 'cloud-init'], target=target) # cloud-init is actually the only package we have a cleaner for # so for now, its the only one that should reconfigured self.assertTrue(m_subp.called) ci_cleaner.assert_called_with(target) self.assertEqual(m_subp.call_count, 1) found = m_subp.call_args_list[0][0][0] expected = ['dpkg-reconfigure', '--frontend=noninteractive', 'cloud-init'] self.assertEqual(expected, found)
def test_dpkg_reconfigure_not_done_if_no_cleaners(self, m_subp): apt_config.dpkg_reconfigure(['pkgfoo', 'pkgbar']) m_subp.assert_not_called()
def test_dpkg_reconfigure_not_done_on_no_data(self, m_subp): apt_config.dpkg_reconfigure([]) m_subp.assert_not_called()