def test_reconfigure_if_no_intersection(self, m_get_inst, m_set_sel, m_dpkg_r): data = {'set1': 'pkga pkga/q1 mybool false'} m_get_inst.return_value = ["adduser", "apparmor", "pkgb", "cloud-init", 'zdog'] m_set_sel.return_value = None apt_config.apply_debconf_selections({'debconf_selections': data}) self.assertTrue(m_get_inst.called) self.assertEqual(m_dpkg_r.call_count, 0)
def test_set_sel_call_has_expected_input(self, m_get_inst, m_set_sel): data = { 'set1': 'pkga pkga/q1 mybool false', 'set2': ('pkgb\tpkgb/b1\tstr\tthis is a string\n' 'pkgc\tpkgc/ip\tstring\t10.0.0.1')} lines = '\n'.join(data.values()).split('\n') m_get_inst.return_value = ["adduser", "apparmor"] m_set_sel.return_value = None apt_config.apply_debconf_selections({'debconf_selections': data}) self.assertTrue(m_get_inst.called) self.assertEqual(m_set_sel.call_count, 1) # assumes called with *args value. selections = m_set_sel.call_args_list[0][0][0].decode() missing = [l for l in lines if l not in selections.splitlines()] self.assertEqual([], missing)
def test_reconfigure_if_intersection(self, m_get_inst, m_set_sel, m_dpkg_r): data = { 'set1': 'pkga pkga/q1 mybool false', 'set2': ('pkgb\tpkgb/b1\tstr\tthis is a string\n' 'pkgc\tpkgc/ip\tstring\t10.0.0.1'), 'cloud-init': ('cloud-init cloud-init/datasources' 'multiselect MAAS')} m_set_sel.return_value = None m_get_inst.return_value = ["adduser", "apparmor", "pkgb", "cloud-init", 'zdog'] apt_config.apply_debconf_selections({'debconf_selections': data}) # reconfigure should be called with the intersection # of (packages in config, packages installed) self.assertEqual(m_dpkg_r.call_count, 1) # assumes called with *args (dpkg_reconfigure([a,b,c], target=)) packages = m_dpkg_r.call_args_list[0][0][0] self.assertEqual(set(['cloud-init', 'pkgb']), set(packages))
def test_no_set_sel_if_none_to_set(self, m_set_sel): apt_config.apply_debconf_selections({'foo': 'bar'}) m_set_sel.assert_not_called()