Merge "Always take into account config file values"

This commit is contained in:
Jenkins
2015-07-31 14:13:22 +00:00
committed by Gerrit Code Review
6 changed files with 128 additions and 111 deletions

View File

@@ -17,7 +17,6 @@ import shutil
import signal
import mock
from oslo.config import cfg
import unittest2
from fuel_agent import errors
@@ -26,9 +25,6 @@ from fuel_agent.utils import hardware as hu
from fuel_agent.utils import utils
CONF = cfg.CONF
class BuildUtilsTestCase(unittest2.TestCase):
_fake_ubuntu_release = '''
@@ -169,7 +165,8 @@ class BuildUtilsTestCase(unittest2.TestCase):
def test_do_post_inst(self, mock_exec, mock_files, mock_clean, mock_path,
mock_open):
mock_path.join.return_value = 'fake_path'
bu.do_post_inst('chroot')
bu.do_post_inst('chroot', allow_unsigned_file='fake_unsigned',
force_ipv4_file='fake_force_ipv4')
file_handle_mock = mock_open.return_value.__enter__.return_value
file_handle_mock.write.assert_called_once_with('manual\n')
mock_exec_expected_calls = [
@@ -179,7 +176,9 @@ class BuildUtilsTestCase(unittest2.TestCase):
mock.call('chroot', 'chroot', 'update-rc.d', 'puppet', 'disable')]
self.assertEqual(mock_exec_expected_calls, mock_exec.call_args_list)
mock_files.assert_called_once_with('chroot', ['usr/sbin/policy-rc.d'])
mock_clean.assert_called_once_with('chroot')
mock_clean.assert_called_once_with('chroot',
allow_unsigned_file='fake_unsigned',
force_ipv4_file='fake_force_ipv4')
mock_path_join_expected_calls = [
mock.call('chroot', 'etc/shadow'),
mock.call('chroot', 'etc/init/mcollective.override')]
@@ -455,18 +454,21 @@ class BuildUtilsTestCase(unittest2.TestCase):
def test_pre_apt_get(self, mock_path, mock_clean):
with mock.patch('six.moves.builtins.open', create=True) as mock_open:
file_handle_mock = mock_open.return_value.__enter__.return_value
bu.pre_apt_get('chroot')
bu.pre_apt_get('chroot', allow_unsigned_file='fake_unsigned',
force_ipv4_file='fake_force_ipv4')
expected_calls = [
mock.call('APT::Get::AllowUnauthenticated 1;\n'),
mock.call('Acquire::ForceIPv4 "true";\n')]
self.assertEqual(expected_calls,
file_handle_mock.write.call_args_list)
mock_clean.assert_called_once_with('chroot')
mock_clean.assert_called_once_with('chroot',
allow_unsigned_file='fake_unsigned',
force_ipv4_file='fake_force_ipv4')
expected_join_calls = [
mock.call('chroot', 'etc/apt/apt.conf.d',
CONF.allow_unsigned_file),
'fake_unsigned'),
mock.call('chroot', 'etc/apt/apt.conf.d',
CONF.force_ipv4_file)]
'fake_force_ipv4')]
self.assertEqual(expected_join_calls, mock_path.join.call_args_list)
@mock.patch('gzip.open')

View File

@@ -71,7 +71,7 @@ class TestManager(unittest2.TestCase):
mock_gu.grub1_cfg.assert_called_once_with(
kernel_params='fake_kernel_params root=UUID= ',
initrd='guessed_initrd', kernel='guessed_kernel',
chroot='/tmp/target')
chroot='/tmp/target', grub_timeout=5)
mock_gu.grub1_install.assert_called_once_with(
['/dev/sda', '/dev/sdb', '/dev/sdc'],
'/dev/sda3', chroot='/tmp/target')
@@ -100,7 +100,8 @@ class TestManager(unittest2.TestCase):
self.assertFalse(mock_gu.grub2_install.called)
mock_gu.grub1_cfg.assert_called_once_with(
kernel_params='fake_kernel_params root=UUID= ',
initrd='initrd_name', kernel='kernel_name', chroot='/tmp/target')
initrd='initrd_name', kernel='kernel_name', chroot='/tmp/target',
grub_timeout=5)
mock_gu.grub1_install.assert_called_once_with(
['/dev/sda', '/dev/sdb', '/dev/sdc'],
'/dev/sda3', chroot='/tmp/target')
@@ -183,7 +184,8 @@ class TestManager(unittest2.TestCase):
'nomodeset root=UUID=fake_UUID ',
initrd='guessed_initrd',
chroot='/tmp/target',
kernel='guessed_kernel')
kernel='guessed_kernel',
grub_timeout=5)
mock_gu.grub1_install.assert_called_once_with(
['/dev/sda', '/dev/sdb', '/dev/sdc'],
'/dev/sda3', chroot='/tmp/target')
@@ -207,7 +209,7 @@ class TestManager(unittest2.TestCase):
mock_gu.grub2_cfg.assert_called_once_with(
kernel_params=' console=ttyS0,9600 console=tty0 rootdelay=90 '
'nomodeset root=UUID=fake_UUID ',
chroot='/tmp/target')
chroot='/tmp/target', grub_timeout=5)
mock_gu.grub2_install.assert_called_once_with(
['/dev/sda', '/dev/sdb', '/dev/sdc'],
chroot='/tmp/target')
@@ -798,10 +800,14 @@ class TestImageBuild(unittest2.TestCase):
mock.call('/fake/img-boot.img.gz')],
mock_os.path.exists.call_args_list)
self.assertEqual([mock.call(dir=CONF.image_build_dir,
suffix=CONF.image_build_suffix)] * 2,
suffix=CONF.image_build_suffix,
size=CONF.sparse_file_size)] * 2,
mock_bu.create_sparse_tmp_file.call_args_list)
self.assertEqual([mock.call()] * 2,
mock_bu.get_free_loop_device.call_args_list)
self.assertEqual(
[mock.call(loop_device_major_number=CONF.loop_device_major_number,
max_loop_devices_count=CONF.max_loop_devices_count),
] * 2,
mock_bu.get_free_loop_device.call_args_list)
self.assertEqual([mock.call('/tmp/img', '/dev/loop0'),
mock.call('/tmp/img-boot', '/dev/loop1')],
mock_bu.attach_file_to_loop.call_args_list)
@@ -817,9 +823,12 @@ class TestImageBuild(unittest2.TestCase):
self.assertEqual([mock.call('/tmp/imgdir')] * 2,
mock_bu.suppress_services_start.call_args_list)
mock_bu.run_debootstrap.assert_called_once_with(
uri='http://fakeubuntu', suite='trusty', chroot='/tmp/imgdir')
uri='http://fakeubuntu', suite='trusty', chroot='/tmp/imgdir',
attempts=CONF.fetch_packages_attempts)
mock_bu.set_apt_get_env.assert_called_once_with()
mock_bu.pre_apt_get.assert_called_once_with('/tmp/imgdir')
mock_bu.pre_apt_get.assert_called_once_with(
'/tmp/imgdir', allow_unsigned_file=CONF.allow_unsigned_file,
force_ipv4_file=CONF.force_ipv4_file)
self.assertEqual([
mock.call(name='ubuntu',
uri='http://fakeubuntu',
@@ -864,8 +873,12 @@ class TestImageBuild(unittest2.TestCase):
mock_utils.execute.call_args_list)
mock_fu.mount_bind.assert_called_once_with('/tmp/imgdir', '/proc')
mock_bu.run_apt_get.assert_called_once_with(
'/tmp/imgdir', packages=['fakepackage1', 'fakepackage2'])
mock_bu.do_post_inst.assert_called_once_with('/tmp/imgdir')
'/tmp/imgdir', packages=['fakepackage1', 'fakepackage2'],
attempts=CONF.fetch_packages_attempts)
mock_bu.do_post_inst.assert_called_once_with(
'/tmp/imgdir', allow_unsigned_file=CONF.allow_unsigned_file,
force_ipv4_file=CONF.force_ipv4_file)
signal_calls = mock_bu.stop_chrooted_processes.call_args_list
self.assertEqual(2 * [mock.call('/tmp/imgdir', signal=signal.SIGTERM),
mock.call('/tmp/imgdir', signal=signal.SIGKILL)],
@@ -892,8 +905,10 @@ class TestImageBuild(unittest2.TestCase):
mock.call('/tmp/img-boot', 10),
mock.call('/fake/img-boot.img.gz', 1)],
mock_utils.calculate_md5.call_args_list)
self.assertEqual([mock.call('/tmp/img', 'gzip'),
mock.call('/tmp/img-boot', 'gzip')],
self.assertEqual([mock.call('/tmp/img', 'gzip',
chunk_size=CONF.data_chunk_size),
mock.call('/tmp/img-boot', 'gzip',
chunk_size=CONF.data_chunk_size)],
mock_bu.containerize.call_args_list)
mock_open.assert_called_once_with('/fake/img.yaml', 'w')
self.assertEqual(