def _set_apt_repos(chroot, repos, proxies=None, direct_repo_addrs=None): """Configure APT to use the specified repositories Set apt-sources for chroot and update metadata in Manager. :param chroot: path to OS to operate on :param repos: list of DEBRepo objects :param proxies: dict protocol:uri format :param direct_repo_addrs: list of addreses which should be bypassed by proxy """ LOG.debug("For set apt repositories will be used proxies: %s and" " no_proxy: %s", proxies, direct_repo_addrs) for repo in repos: LOG.debug( 'Adding repository source: name={name}, uri={uri}, ' 'suite={suite}, section={section}'.format( name=repo.name, uri=repo.uri, suite=repo.suite, section=repo.section)) bu.add_apt_source(name=repo.name, uri=repo.uri, suite=repo.suite, section=repo.section, chroot=chroot) LOG.debug( 'Adding repository preference: name={name}, ' 'priority={priority}'.format(name=repo.name, priority=repo.priority)) if repo.priority is not None: bu.add_apt_preference( name=repo.name, priority=repo.priority, suite=repo.suite, section=repo.section, chroot=chroot, uri=repo.uri, proxies=proxies, direct_repo_addrs=direct_repo_addrs)
def test_add_apt_preference_no_sections(self, mock_get, mock_path): with mock.patch('six.moves.builtins.open', create=True) as mock_open: file_handle_mock = mock_open.return_value.__enter__.return_value bu.add_apt_preference('name1', 123, 'test-archive', '', 'chroot', 'http://test-uri') calls_args = [ c[0][0] for c in file_handle_mock.write.call_args_list ] self.assertEqual(len(calls_args), 4) self.assertEqual(calls_args[0], 'Package: *\n') self.assertEqual(calls_args[1], 'Pin: release ') self.assertIn("l=TestLabel", calls_args[2]) self.assertIn("n=testcodename", calls_args[2]) self.assertIn("a=test-archive", calls_args[2]) self.assertIn("o=TestOrigin", calls_args[2]) self.assertNotIn("c=", calls_args[2]) self.assertEqual(calls_args[3], 'Pin-Priority: 123\n') expected_mock_path_calls = [ mock.call('http://test-uri', 'test-archive', 'Release'), mock.call('chroot', 'etc/apt/preferences.d', 'fuel-image-name1.pref') ] self.assertEqual(expected_mock_path_calls, mock_path.join.call_args_list)
def test_add_apt_preference_no_sections(self, mock_get, mock_path): with mock.patch('six.moves.builtins.open', create=True) as mock_open: file_handle_mock = mock_open.return_value.__enter__.return_value bu.add_apt_preference( 'name1', 123, 'test-archive', '', 'chroot', 'http://test-uri' ) calls_args = [ c[0][0] for c in file_handle_mock.write.call_args_list ] self.assertEqual(len(calls_args), 4) self.assertEqual(calls_args[0], 'Package: *\n') self.assertEqual(calls_args[1], 'Pin: release ') self.assertIn("l=TestLabel", calls_args[2]) self.assertIn("n=testcodename", calls_args[2]) self.assertIn("a=test-archive", calls_args[2]) self.assertIn("o=TestOrigin", calls_args[2]) self.assertNotIn("c=", calls_args[2]) self.assertEqual(calls_args[3], 'Pin-Priority: 123\n') expected_mock_path_calls = [ mock.call('http://test-uri', 'test-archive', 'Release'), mock.call('chroot', 'etc/apt/preferences.d', 'fuel-image-name1.pref')] self.assertEqual(expected_mock_path_calls, mock_path.join.call_args_list)
def test_add_apt_preference_multuple_sections(self, mock_get, mock_path): with mock.patch('six.moves.builtins.open', create=True) as mock_open: file_handle_mock = mock_open.return_value.__enter__.return_value fake_sections = ['section2', 'section3'] bu.add_apt_preference('name3', 234, 'test-archive', ' '.join(fake_sections), 'chroot', 'http://test-uri') calls_args = [ c[0][0] for c in file_handle_mock.write.call_args_list ] calls_package = [c for c in calls_args if c == 'Package: *\n'] calls_pin = [c for c in calls_args if c == 'Pin: release '] calls_pin_p = [c for c in calls_args if c == 'Pin-Priority: 234\n'] first_section = [ c for c in calls_args if 'c={0}'.format(fake_sections[0]) in c ] second_section = [ c for c in calls_args if 'c={0}'.format(fake_sections[1]) in c ] self.assertEqual(len(calls_package), 1) self.assertEqual(len(calls_pin), 1) self.assertEqual(len(calls_pin_p), 1) self.assertEqual(len(first_section), 0) self.assertEqual(len(second_section), 0) for pin_line in calls_args[2::4]: self.assertIn("l=TestLabel", pin_line) self.assertIn("n=testcodename", pin_line) self.assertIn("a=test-archive", pin_line) self.assertIn("o=TestOrigin", pin_line) expected_mock_path_calls = [ mock.call('http://test-uri', 'dists', 'test-archive', 'Release'), mock.call('chroot', 'etc/apt/preferences.d', 'fuel-image-name3.pref') ] self.assertEqual(expected_mock_path_calls, mock_path.join.call_args_list)
def test_add_apt_preference_multuple_sections(self, mock_get, mock_path): with mock.patch('six.moves.builtins.open', create=True) as mock_open: file_handle_mock = mock_open.return_value.__enter__.return_value fake_sections = ['section2', 'section3'] bu.add_apt_preference('name3', 234, 'test-archive', ' '.join(fake_sections), 'chroot', 'http://test-uri') calls_args = [ c[0][0] for c in file_handle_mock.write.call_args_list ] calls_package = [c for c in calls_args if c == 'Package: *\n'] calls_pin = [c for c in calls_args if c == 'Pin: release '] calls_pin_p = [c for c in calls_args if c == 'Pin-Priority: 234\n'] first_section = [ c for c in calls_args if 'c={0}'.format(fake_sections[0]) in c ] second_section = [ c for c in calls_args if 'c={0}'.format(fake_sections[1]) in c ] self.assertEqual(len(calls_package), 1) self.assertEqual(len(calls_pin), 1) self.assertEqual(len(calls_pin_p), 1) self.assertEqual(len(first_section), 0) self.assertEqual(len(second_section), 0) for pin_line in calls_args[2::4]: self.assertIn("l=TestLabel", pin_line) self.assertIn("n=testcodename", pin_line) self.assertIn("a=test-archive", pin_line) self.assertIn("o=TestOrigin", pin_line) expected_mock_path_calls = [ mock.call('http://test-uri', 'dists', 'test-archive', 'Release'), mock.call('chroot', 'etc/apt/preferences.d', 'fuel-image-name3.pref')] self.assertEqual(expected_mock_path_calls, mock_path.join.call_args_list)
def _set_apt_repos(chroot, repos, proxies=None, direct_repo_addrs=None): """Configure APT to use the specified repositories Set apt-sources for chroot and update metadata in Manager. :param chroot: path to OS to operate on :param repos: list of DEBRepo objects :param proxies: dict protocol:uri format :param direct_repo_addrs: list of addreses which should be bypassed by proxy """ LOG.debug( "For set apt repositories will be used proxies: %s and" " no_proxy: %s", proxies, direct_repo_addrs) for repo in repos: LOG.debug('Adding repository source: name={name}, uri={uri}, ' 'suite={suite}, section={section}'.format( name=repo.name, uri=repo.uri, suite=repo.suite, section=repo.section)) bu.add_apt_source(name=repo.name, uri=repo.uri, suite=repo.suite, section=repo.section, chroot=chroot) LOG.debug('Adding repository preference: name={name}, ' 'priority={priority}'.format(name=repo.name, priority=repo.priority)) if repo.priority is not None: bu.add_apt_preference(name=repo.name, priority=repo.priority, suite=repo.suite, section=repo.section, chroot=chroot, uri=repo.uri, proxies=proxies, direct_repo_addrs=direct_repo_addrs)