diff --git a/fuel_agent/tests/test_build_utils.py b/fuel_agent/tests/test_build_utils.py index 5d15e286..31b5f81e 100644 --- a/fuel_agent/tests/test_build_utils.py +++ b/fuel_agent/tests/test_build_utils.py @@ -160,7 +160,7 @@ class BuildUtilsTestCase(unittest2.TestCase): @mock.patch.object(bu, 'clean_dirs') def test_clean_apt_settings(self, mock_dirs, mock_files): bu.clean_apt_settings('chroot', 'unsigned', 'force_ipv4', - 'pipeline_depth') + 'pipeline_depth', 'install_rule') mock_dirs.assert_called_once_with( 'chroot', ['etc/apt/preferences.d', 'etc/apt/sources.list.d']) files = set(['etc/apt/sources.list', 'etc/apt/preferences', @@ -169,7 +169,9 @@ class BuildUtilsTestCase(unittest2.TestCase): 'etc/apt/apt.conf.d/%s' % 'pipeline_depth', 'etc/apt/apt.conf.d/01fuel_agent-use-proxy-ftp', 'etc/apt/apt.conf.d/01fuel_agent-use-proxy-http', - 'etc/apt/apt.conf.d/01fuel_agent-use-proxy-https']) + 'etc/apt/apt.conf.d/01fuel_agent-use-proxy-https', + 'etc/apt/apt.conf.d/%s' % 'install_rule', + ]) self.assertEqual('chroot', mock_files.call_args[0][0]) self.assertEqual(files, set(mock_files.call_args[0][1])) @@ -213,7 +215,8 @@ class BuildUtilsTestCase(unittest2.TestCase): hashed_root_password=password, allow_unsigned_file='fake_unsigned', force_ipv4_file='fake_force_ipv4', - pipeline_depth_file='fake_pipeline_depth') + pipeline_depth_file='fake_pipeline_depth', + install_rule_file='fake_install_rule') file_handle_mock = mock_open.return_value.__enter__.return_value file_handle_mock.write.assert_called_once_with('manual\n') @@ -236,7 +239,8 @@ class BuildUtilsTestCase(unittest2.TestCase): 'chroot', allow_unsigned_file='fake_unsigned', force_ipv4_file='fake_force_ipv4', - pipeline_depth_file='fake_pipeline_depth') + pipeline_depth_file='fake_pipeline_depth', + install_rule_file='fake_install_rule') mock_path_join_expected_calls = [ mock.call('chroot', 'etc/shadow'), mock.call('chroot', 'etc/init.d/puppet'), @@ -527,25 +531,33 @@ class BuildUtilsTestCase(unittest2.TestCase): file_handle_mock = mock_open.return_value.__enter__.return_value bu.pre_apt_get('chroot', allow_unsigned_file='fake_unsigned', force_ipv4_file='fake_force_ipv4', - pipeline_depth_file='fake_pipeline_depth') + pipeline_depth_file='fake_pipeline_depth', + install_rule_file='fake_install_rule') expected_calls = [ mock.call('APT::Get::AllowUnauthenticated 1;\n'), mock.call('Acquire::ForceIPv4 "true";\n'), - mock.call('Acquire::http::Pipeline-Depth 0;\n')] + mock.call('Acquire::http::Pipeline-Depth 0;\n'), + mock.call('APT::Install-Recommends "false";\n'), + mock.call('APT::Install-Suggests "false";\n')] self.assertEqual(expected_calls, file_handle_mock.write.call_args_list) mock_clean.assert_called_once_with( 'chroot', allow_unsigned_file='fake_unsigned', force_ipv4_file='fake_force_ipv4', - pipeline_depth_file='fake_pipeline_depth') + pipeline_depth_file='fake_pipeline_depth', + install_rule_file='fake_install_rule') expected_join_calls = [ mock.call('chroot', 'etc/apt/apt.conf.d', 'fake_unsigned'), mock.call('chroot', 'etc/apt/apt.conf.d', 'fake_force_ipv4'), mock.call('chroot', 'etc/apt/apt.conf.d', - 'fake_pipeline_depth')] + 'fake_pipeline_depth'), + mock.call('chroot', 'etc/apt/apt.conf.d', + 'fake_install_rule'), + mock.call('chroot', 'etc/apt/apt.conf.d', + 'fake_install_rule')] self.assertEqual(expected_join_calls, mock_path.join.call_args_list) @mock.patch.object(bu.utils, 'execute') diff --git a/fuel_agent/utils/build.py b/fuel_agent/utils/build.py index eb8cbd30..5d916de1 100644 --- a/fuel_agent/utils/build.py +++ b/fuel_agent/utils/build.py @@ -161,13 +161,15 @@ def remove_files(chroot, files): def clean_apt_settings(chroot, allow_unsigned_file='allow_unsigned_packages', force_ipv4_file='force_ipv4', - pipeline_depth_file='pipeline_depth'): + pipeline_depth_file='pipeline_depth', + install_rule_file='install_rule'): """Cleans apt settings such as package sources and repo pinning.""" files = [DEFAULT_APT_PATH['sources_file'], DEFAULT_APT_PATH['preferences_file'], os.path.join(DEFAULT_APT_PATH['conf_dir'], force_ipv4_file), os.path.join(DEFAULT_APT_PATH['conf_dir'], allow_unsigned_file), - os.path.join(DEFAULT_APT_PATH['conf_dir'], pipeline_depth_file)] + os.path.join(DEFAULT_APT_PATH['conf_dir'], pipeline_depth_file), + os.path.join(DEFAULT_APT_PATH['conf_dir'], install_rule_file)] # also remove proxies for p_file in six.itervalues(PROXY_PROTOCOLS): files.append(os.path.join(DEFAULT_APT_PATH['conf_dir'], p_file)) @@ -193,7 +195,8 @@ def fix_cloud_init_config(config_path): def do_post_inst(chroot, hashed_root_password, allow_unsigned_file='allow_unsigned_packages', force_ipv4_file='force_ipv4', - pipeline_depth_file='pipeline_depth'): + pipeline_depth_file='pipeline_depth', + install_rule_file='install_rule'): # NOTE(agordeev): set up password for root utils.execute('sed', '-i', 's%root:[\*,\!]%root:' + hashed_root_password + '%', @@ -238,7 +241,8 @@ def do_post_inst(chroot, hashed_root_password, utils.execute('chroot', chroot, 'apt-get', 'clean') clean_apt_settings(chroot, allow_unsigned_file=allow_unsigned_file, force_ipv4_file=force_ipv4_file, - pipeline_depth_file=pipeline_depth_file) + pipeline_depth_file=pipeline_depth_file, + install_rule_file=install_rule_file) def stop_chrooted_processes(chroot, signal=sig.SIGTERM, @@ -537,11 +541,13 @@ def set_apt_proxy(chroot, proxies, direct_repo_addr=None): def pre_apt_get(chroot, allow_unsigned_file='allow_unsigned_packages', force_ipv4_file='force_ipv4', pipeline_depth_file='pipeline_depth', + install_rule_file='install_rule', proxies=None, direct_repo_addr=None): """It must be called prior run_apt_get.""" clean_apt_settings(chroot, allow_unsigned_file=allow_unsigned_file, force_ipv4_file=force_ipv4_file, - pipeline_depth_file=pipeline_depth_file) + pipeline_depth_file=pipeline_depth_file, + install_rule_file=install_rule_file) # NOTE(agordeev): allow to install packages without gpg digest with open(os.path.join(chroot, DEFAULT_APT_PATH['conf_dir'], allow_unsigned_file), 'w') as f: @@ -552,7 +558,12 @@ def pre_apt_get(chroot, allow_unsigned_file='allow_unsigned_packages', with open(os.path.join(chroot, DEFAULT_APT_PATH['conf_dir'], pipeline_depth_file), 'w') as f: f.write('Acquire::http::Pipeline-Depth 0;\n') - + with open(os.path.join(chroot, DEFAULT_APT_PATH['conf_dir'], + install_rule_file), 'w') as f: + f.write('APT::Install-Recommends "false";\n') + with open(os.path.join(chroot, DEFAULT_APT_PATH['conf_dir'], + install_rule_file), 'a') as f: + f.write('APT::Install-Suggests "false";\n') if proxies: set_apt_proxy(chroot, proxies, direct_repo_addr)