From patchwork Wed Mar 9 17:23:29 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guilherme Salgado X-Patchwork-Id: 474 Return-Path: Delivered-To: unknown Received: from imap.gmail.com (74.125.159.109) by localhost6.localdomain6 with IMAP4-SSL; 08 Jun 2011 14:42:58 -0000 Delivered-To: patches@linaro.org Received: by 10.224.60.68 with SMTP id o4cs66491qah; Wed, 9 Mar 2011 09:23:32 -0800 (PST) Received: by 10.227.196.67 with SMTP id ef3mr5967236wbb.185.1299691411124; Wed, 09 Mar 2011 09:23:31 -0800 (PST) Received: from adelie.canonical.com (adelie.canonical.com [91.189.90.139]) by mx.google.com with ESMTP id g9si3752514wbe.89.2011.03.09.09.23.29; Wed, 09 Mar 2011 09:23:31 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of bounces@canonical.com designates 91.189.90.139 as permitted sender) client-ip=91.189.90.139; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of bounces@canonical.com designates 91.189.90.139 as permitted sender) smtp.mail=bounces@canonical.com Received: from loganberry.canonical.com ([91.189.90.37]) by adelie.canonical.com with esmtp (Exim 4.71 #1 (Debian)) id 1PxN6f-0000Me-Oq for ; Wed, 09 Mar 2011 17:23:29 +0000 Received: from loganberry.canonical.com (localhost [127.0.0.1]) by loganberry.canonical.com (Postfix) with ESMTP id BA0052E80E2 for ; Wed, 9 Mar 2011 17:23:29 +0000 (UTC) MIME-Version: 1.0 X-Launchpad-Project: linaro-image-tools X-Launchpad-Branch: ~linaro-maintainers/linaro-image-tools/trunk X-Launchpad-Message-Rationale: Subscriber X-Launchpad-Branch-Revision-Number: 296 X-Launchpad-Notification-Type: branch-revision To: Linaro Patch Tracker From: noreply@launchpad.net Subject: [Branch ~linaro-maintainers/linaro-image-tools/trunk] Rev 296: Change cmd_runner.run() to always pass -E to sudo Message-Id: <20110309172329.20089.71251.launchpad@loganberry.canonical.com> Date: Wed, 09 Mar 2011 17:23:29 -0000 Reply-To: noreply@launchpad.net Sender: bounces@canonical.com Errors-To: bounces@canonical.com Precedence: bulk X-Generated-By: Launchpad (canonical.com); Revision="12532"; Instance="initZopeless config overlay" X-Launchpad-Hash: 630fa115ffbebe302c8eeef87f5ba0473b64023f Merge authors: Guilherme Salgado (salgado) Related merge proposals: https://code.launchpad.net/~salgado/linaro-image-tools/bug-673570/+merge/52696 proposed by: Guilherme Salgado (salgado) review: Approve - James Westby (james-w) ------------------------------------------------------------ revno: 296 [merge] committer: Guilherme Salgado branch nick: trunk timestamp: Wed 2011-03-09 14:20:18 -0300 message: Change cmd_runner.run() to always pass -E to sudo modified: linaro_media_create/cmd_runner.py linaro_media_create/tests/test_media_create.py --- lp:linaro-image-tools https://code.launchpad.net/~linaro-maintainers/linaro-image-tools/trunk You are subscribed to branch lp:linaro-image-tools. To unsubscribe from this branch go to https://code.launchpad.net/~linaro-maintainers/linaro-image-tools/trunk/+edit-subscription === modified file 'linaro_media_create/cmd_runner.py' --- linaro_media_create/cmd_runner.py 2011-01-29 16:33:38 +0000 +++ linaro_media_create/cmd_runner.py 2011-03-09 15:11:28 +0000 @@ -38,10 +38,7 @@ assert isinstance(args, (list, tuple)), ( "The command to run must be a list or tuple, found: %s" % type(args)) if as_root and os.getuid() != 0: - args = args[:] - # TODO: We might want to always use 'sudo -E' here to avoid problems - # like https://launchpad.net/bugs/673570 - args.insert(0, 'sudo') + args = ['sudo', '-E'] + args return Popen(args, stdin=stdin, stdout=stdout, stderr=stderr) === modified file 'linaro_media_create/tests/test_media_create.py' --- linaro_media_create/tests/test_media_create.py 2011-03-09 15:55:56 +0000 +++ linaro_media_create/tests/test_media_create.py 2011-03-09 17:18:18 +0000 @@ -104,6 +104,9 @@ ) +sudo_args = 'sudo -E' + + def preferred_tools_dir(): prefer_dir = None # running from bzr checkout? @@ -172,7 +175,7 @@ fixture = self.useFixture(MockCmdRunnerPopenFixture()) install_package_providing('mkfs.vfat') self.assertEqual( - ['sudo apt-get install dosfstools'], + ['%s apt-get install dosfstools' % sudo_args], fixture.mock.commands_executed) def test_not_found_package(self): @@ -217,6 +220,7 @@ self.assertRaises( AssertionError, _get_mlo_file, tempdir) + class TestBootSteps(TestCaseWithFixtures): def setUp(self): @@ -267,7 +271,7 @@ 'install_smdkv310_boot_loader', 'make_flashable_env', 'install_smdkv310_boot_env', 'make_uImage', 'install_smdkv310_uImage', 'make_uInitrd', - 'install_smdkv310_initrd',] + 'install_smdkv310_initrd'] self.assertEqual(expected, self.funcs_calls) def test_ux500_steps(self): @@ -397,8 +401,8 @@ is_live=False, is_lowmem=False, consoles=['ttyXXX'], rootfs_uuid="deadbeef") expected = { - 'bootargs': 'console=tty0 console=ttyAMA0,38400n8 console=ttyXXX ' - 'root=UUID=deadbeef rootwait ro', + 'bootargs': 'console=tty0 console=ttyAMA0,38400n8 ' + 'console=ttyXXX root=UUID=deadbeef rootwait ro', 'bootcmd': 'fatload mmc 0:1 0x60008000 uImage; ' 'fatload mmc 0:1 0x81000000 uInitrd; ' 'bootm 0x60008000 0x81000000'} @@ -477,7 +481,8 @@ expected = { 'bootargs': 'console=tty0 console=ttyO2,115200n8 ' 'root=UUID=deadbeef rootwait ro earlyprintk fixrtc ' - 'nocompcache vram=12M omapfb.mode=dvi:1280x720MR-16@60', + 'nocompcache vram=12M ' + 'omapfb.mode=dvi:1280x720MR-16@60', 'bootcmd': 'fatload mmc 0:1 0x80000000 uImage; ' 'fatload mmc 0:1 0x81600000 uInitrd; ' 'bootm 0x80000000 0x81600000'} @@ -533,10 +538,8 @@ self.useFixture(fixture) get_uuid("/dev/rootfs") self.assertEquals( - [[ - "sudo", "blkid", "-o", "udev", "-p", "-c", "/dev/null", - "/dev/rootfs"]], - fixture.mock.calls) + ["%s blkid -o udev -p -c /dev/null /dev/rootfs" % sudo_args], + fixture.mock.commands_executed) def test_parse_blkid_output(self): output = ( @@ -562,7 +565,8 @@ fixture = self.useFixture(MockCmdRunnerPopenFixture()) self.useFixture(MockSomethingFixture(os, 'getuid', lambda: 1000)) cmd_runner.run(['foo', 'bar'], as_root=True).wait() - self.assertEqual([['sudo', 'foo', 'bar']], fixture.mock.calls) + self.assertEqual( + ['%s foo bar' % sudo_args], fixture.mock.commands_executed) def test_run_as_root_as_root(self): fixture = self.useFixture(MockCmdRunnerPopenFixture()) @@ -609,20 +613,20 @@ fixture = self._mock_Popen() make_uImage('load_addr', 'parts_dir', 'sub_arch', 'boot_disk') expected = [ - 'sudo', 'mkimage', '-A', 'arm', '-O', 'linux', '-T', 'kernel', - '-C', 'none', '-a', 'load_addr', '-e', 'load_addr', '-n', 'Linux', - '-d', 'parts_dir/vmlinuz-*-sub_arch', 'boot_disk/uImage'] - self.assertEqual([expected], fixture.mock.calls) + '%s mkimage -A arm -O linux -T kernel -C none -a load_addr ' + '-e load_addr -n Linux -d parts_dir/vmlinuz-*-sub_arch ' + 'boot_disk/uImage' % sudo_args] + self.assertEqual(expected, fixture.mock.commands_executed) def test_make_uInitrd(self): self._mock_get_file_matching() fixture = self._mock_Popen() make_uInitrd('parts_dir', 'sub_arch', 'boot_disk') expected = [ - 'sudo', 'mkimage', '-A', 'arm', '-O', 'linux', '-T', 'ramdisk', - '-C', 'none', '-a', '0', '-e', '0', '-n', 'initramfs', - '-d', 'parts_dir/initrd.img-*-sub_arch', 'boot_disk/uInitrd'] - self.assertEqual([expected], fixture.mock.calls) + '%s mkimage -A arm -O linux -T ramdisk -C none -a 0 -e 0 ' + '-n initramfs -d parts_dir/initrd.img-*-sub_arch ' + 'boot_disk/uInitrd' % sudo_args] + self.assertEqual(expected, fixture.mock.commands_executed) def test_make_flashable_env_too_small_env(self): env = {'verylong': 'evenlonger'} @@ -642,9 +646,9 @@ imx_file = self.createTempFileAsFixture() install_mx5_boot_loader(imx_file, "boot_device_or_file") expected = [ - 'sudo', 'dd', 'if=%s' % imx_file, 'of=boot_device_or_file', - 'bs=512', 'conv=notrunc', 'seek=2'] - self.assertEqual([expected], fixture.mock.calls) + '%s dd if=%s of=boot_device_or_file bs=512 ' + 'conv=notrunc seek=2' % (sudo_args, imx_file)] + self.assertEqual(expected, fixture.mock.commands_executed) def test_install_mx5_boot_loader_too_large(self): self.useFixture(MockSomethingFixture( @@ -660,9 +664,8 @@ lambda chroot_dir: "%s/MLO" % chroot_dir)) install_omap_boot_loader("chroot_dir", "boot_disk") expected = [ - ['sudo', 'cp', '-v', 'chroot_dir/MLO', 'boot_disk'], - ['sync']] - self.assertEqual(expected, fixture.mock.calls) + '%s cp -v chroot_dir/MLO boot_disk' % sudo_args, 'sync'] + self.assertEqual(expected, fixture.mock.commands_executed) def test_make_boot_script(self): self.useFixture(MockSomethingFixture( @@ -675,11 +678,12 @@ boot_env = {'bootargs': 'mybootargs', 'bootcmd': 'mybootcmd'} make_boot_script(boot_env, boot_script_path) expected = [ - ['sudo', 'cp', '/tmp/random-abxzr', plain_boot_script_path], - ['sudo', 'mkimage', '-A', 'arm', '-O', 'linux', '-T', 'script', - '-C', 'none', '-a', '0', '-e', '0', '-n', 'boot script', - '-d', plain_boot_script_path, boot_script_path]] - self.assertEqual(expected, fixture.mock.calls) + '%s cp /tmp/random-abxzr %s' % ( + sudo_args, plain_boot_script_path), + '%s mkimage -A arm -O linux -T script -C none -a 0 -e 0 ' + '-n boot script -d %s %s' % ( + sudo_args, plain_boot_script_path, boot_script_path)] + self.assertEqual(expected, fixture.mock.commands_executed) def test_get_file_matching(self): prefix = ''.join( @@ -742,14 +746,15 @@ create_partitions(boards.Mx5Config, self.media, 255, 63, '') self.assertEqual( - [['sudo', 'parted', '-s', self.media.path, 'mklabel', 'msdos'], - ['sync']], - popen_fixture.mock.calls) + ['%s parted -s %s mklabel msdos' % (sudo_args, self.media.path), + 'sync'], + popen_fixture.mock.commands_executed) # Notice that we create all partitions in a single sfdisk run because # every time we run sfdisk it actually repartitions the device, # erasing any partitions created previously. self.assertEqual( - [('1,8191,0xDA\n8192,106496,0x0C,*\n114688,,,-', 255, 63, '', self.media.path)], + [('1,8191,0xDA\n8192,106496,0x0C,*\n114688,,,-', 255, 63, '', + self.media.path)], sfdisk_fixture.mock.calls) def test_create_partitions_for_smdkv310(self): @@ -761,9 +766,9 @@ board_configs['smdkv310'], self.media, 255, 63, '') self.assertEqual( - [['sudo', 'parted', '-s', self.media.path, 'mklabel', 'msdos'], - ['sync']], - popen_fixture.mock.calls) + ['%s parted -s %s mklabel msdos' % (sudo_args, self.media.path), + 'sync'], + popen_fixture.mock.commands_executed) # Notice that we create all partitions in a single sfdisk run because # every time we run sfdisk it actually repartitions the device, # erasing any partitions created previously. @@ -779,9 +784,9 @@ board_configs['beagle'], self.media, 255, 63, '') self.assertEqual( - [['sudo', 'parted', '-s', self.media.path, 'mklabel', 'msdos'], - ['sync']], - popen_fixture.mock.calls) + ['%s parted -s %s mklabel msdos' % (sudo_args, self.media.path), + 'sync'], + popen_fixture.mock.commands_executed) self.assertEqual( [('63,106432,0x0C,*\n106496,,,-', 255, 63, '', self.media.path)], sfdisk_fixture.mock.calls) @@ -797,7 +802,7 @@ # Unlike the test for partitioning of a regular block device, in this # case parted was not called as there's no existing partition table # for us to overwrite on the image file. - self.assertEqual([['sync']], popen_fixture.mock.calls) + self.assertEqual(['sync'], popen_fixture.mock.commands_executed) self.assertEqual( [('63,106432,0x0C,*\n106496,,,-', 255, 63, '', tmpfile)], @@ -910,7 +915,8 @@ popen_fixture = self.useFixture(MockCmdRunnerPopenFixture()) ensure_partition_is_not_mounted('/dev/whatever') self.assertEqual( - [['sudo', 'umount', '/dev/whatever']], popen_fixture.mock.calls) + ['%s umount /dev/whatever' % sudo_args], + popen_fixture.mock.commands_executed) def test_ensure_partition_is_not_mounted_for_umounted_partition(self): self.useFixture(MockSomethingFixture( @@ -929,11 +935,11 @@ # it calls losetup correctly. get_boot_and_root_loopback_devices(tmpfile) self.assertEqual( - [['sudo', 'losetup', '-f', '--show', tmpfile, '--offset', - '8388608', '--sizelimit', '8061952'], - ['sudo', 'losetup', '-f', '--show', tmpfile, '--offset', - '16777216', '--sizelimit', '14680064']], - popen_fixture.mock.calls) + ['%s losetup -f --show %s --offset 8388608 --sizelimit 8061952' + % (sudo_args, tmpfile), + '%s losetup -f --show %s --offset 16777216 --sizelimit 14680064' + % (sudo_args, tmpfile)], + popen_fixture.mock.commands_executed) # get_boot_and_root_loopback_devices will also setup two exit handlers # to de-register the loopback devices set up above. @@ -944,8 +950,9 @@ # don't have a device to pass to 'losetup -d', but when a device is # setup it is passed to the atexit handler. self.assertEquals( - [['sudo', 'losetup', '-d', ''], ['sudo', 'losetup', '-d', '']], - popen_fixture.mock.calls) + ['%s losetup -d ' % sudo_args, + '%s losetup -d ' % sudo_args], + popen_fixture.mock.commands_executed) def test_setup_partitions_for_image_file(self): # In practice we could pass an empty image file to setup_partitions, @@ -973,15 +980,15 @@ 'root', 'ext3', True, True, True) self.assertEqual( # This is the call that would create a 2 GiB image file. - [['qemu-img', 'create', '-f', 'raw', tmpfile, '2147483648'], + ['qemu-img create -f raw %s 2147483648' % tmpfile, # This call would partition the image file. - ['sudo', 'sfdisk', '--force', '-D', '-uS', '-H', '255', '-S', - '63', '-C', '261', tmpfile], + '%s sfdisk --force -D -uS -H 255 -S 63 -C 261 %s' % ( + sudo_args, tmpfile), # Make sure changes are written to disk. - ['sync'], - ['sudo', 'mkfs.vfat', '-F', '32', bootfs_dev, '-n', 'boot'], - ['sudo', 'mkfs.ext3', rootfs_dev, '-L', 'root']], - popen_fixture.mock.calls) + 'sync', + '%s mkfs.vfat -F 32 %s -n boot' % (sudo_args, bootfs_dev), + '%s mkfs.ext3 %s -L root' % (sudo_args, rootfs_dev)], + popen_fixture.mock.commands_executed) def test_setup_partitions_for_block_device(self): self.useFixture(MockSomethingFixture( @@ -1001,17 +1008,17 @@ board_configs['beagle'], media, '2G', 'boot', 'root', 'ext3', True, True, True) self.assertEqual( - [['sudo', 'parted', '-s', tmpfile, 'mklabel', 'msdos'], - ['sudo', 'sfdisk', '--force', '-D', '-uS', '-H', '255', '-S', - '63', tmpfile], - ['sync'], + ['%s parted -s %s mklabel msdos' % (sudo_args, tmpfile), + '%s sfdisk --force -D -uS -H 255 -S 63 %s' % ( + sudo_args, tmpfile), + 'sync', # Since the partitions are mounted, setup_partitions will umount # them before running mkfs. - ['sudo', 'umount', bootfs_dev], - ['sudo', 'umount', rootfs_dev], - ['sudo', 'mkfs.vfat', '-F', '32', bootfs_dev, '-n', 'boot'], - ['sudo', 'mkfs.ext3', rootfs_dev, '-L', 'root']], - popen_fixture.mock.calls) + '%s umount %s' % (sudo_args, bootfs_dev), + '%s umount %s' % (sudo_args, rootfs_dev), + '%s mkfs.vfat -F 32 %s -n boot' % (sudo_args, bootfs_dev), + '%s mkfs.ext3 %s -L root' % (sudo_args, rootfs_dev)], + popen_fixture.mock.commands_executed) class TestPopulateBoot(TestCaseWithFixtures): @@ -1023,10 +1030,10 @@ 'chroot_dir/casper', True, False, [], 'chroot_dir', 'rootfs_uuid', 'boot_disk', 'boot_disk/boot_script', 'boot_device_or_file') expected_calls = [ - ["mkdir", "-p", "boot_disk"], - ["sudo", "mount", "boot_partition", "boot_disk"], - ["sync"], - ["sudo", "umount", "boot_disk"]] + 'mkdir -p boot_disk', + '%s mount boot_partition boot_disk' % sudo_args, + 'sync', + '%s umount boot_disk' % sudo_args] def save_args(self, *args): self.saved_args = args @@ -1043,26 +1050,29 @@ def call_populate_boot(self, config, is_live=False): populate_boot( - config, 'chroot_dir', 'rootfs_uuid', 'boot_partition', 'boot_disk', - 'boot_device_or_file', is_live, False, []) + config, 'chroot_dir', 'rootfs_uuid', 'boot_partition', + 'boot_disk', 'boot_device_or_file', is_live, False, []) def test_populate_boot_live(self): self.prepare_config(boards.BoardConfig) self.call_populate_boot(self.config, is_live=True) - self.assertEquals(self.expected_calls, self.popen_fixture.mock.calls) + self.assertEquals( + self.expected_calls, self.popen_fixture.mock.commands_executed) self.assertEquals(self.expected_args_live, self.saved_args) def test_populate_boot_regular(self): self.prepare_config(boards.BoardConfig) self.call_populate_boot(self.config) - self.assertEquals(self.expected_calls, self.popen_fixture.mock.calls) + self.assertEquals( + self.expected_calls, self.popen_fixture.mock.commands_executed) self.assertEquals(self.expected_args, self.saved_args) def test_populate_boot_uboot_flavor(self): self.prepare_config(boards.BoardConfig) self.config.uboot_flavor = "uboot_flavor" self.call_populate_boot(self.config) - self.assertEquals(self.expected_calls, self.popen_fixture.mock.calls) + self.assertEquals( + self.expected_calls, self.popen_fixture.mock.commands_executed) self.assertEquals(self.expected_args, self.saved_args) def test_populate_boot_uboot_in_boot_part(self): @@ -1071,16 +1081,18 @@ self.config.uboot_in_boot_part = True self.call_populate_boot(self.config) expected_calls = self.expected_calls[:] - expected_calls.insert(2, [ - "sudo", "cp", "-v", - "chroot_dir/usr/lib/u-boot/uboot_flavor/u-boot.bin", "boot_disk"]) - self.assertEquals(expected_calls, self.popen_fixture.mock.calls) + expected_calls.insert(2, + '%s cp -v chroot_dir/usr/lib/u-boot/uboot_flavor/u-boot.bin ' + 'boot_disk' % sudo_args) + self.assertEquals( + expected_calls, self.popen_fixture.mock.commands_executed) self.assertEquals(self.expected_args, self.saved_args) def test_populate_boot_no_uboot_flavor(self): self.prepare_config(boards.BoardConfig) self.config.uboot_in_boot_part = True - self.assertRaises(AssertionError, self.call_populate_boot, self.config) + self.assertRaises( + AssertionError, self.call_populate_boot, self.config) class TestPopulateRootFS(TestCaseWithFixtures): @@ -1126,14 +1138,15 @@ self.assertEqual(True, self.create_flash_kernel_config_called) swap_file = os.path.join(root_disk, 'SWAP.swap') expected = [ - ['sudo', 'mount', '/dev/rootfs', root_disk], - ['sudo', 'mv', contents_bin, contents_etc, root_disk], - ['sudo', 'dd', 'if=/dev/zero', 'of=%s' % swap_file, 'bs=1M', - 'count=100'], - ['sudo', 'mkswap', swap_file], - ['sync'], - ['sudo', 'umount', root_disk]] - self.assertEqual(expected, popen_fixture.mock.calls) + '%s mount /dev/rootfs %s' % (sudo_args, root_disk), + '%s mv %s %s %s' % ( + sudo_args, contents_bin, contents_etc, root_disk), + '%s dd if=/dev/zero of=%s bs=1M count=100' % ( + sudo_args, swap_file), + '%s mkswap %s' % (sudo_args, swap_file), + 'sync', + '%s umount %s' % (sudo_args, root_disk)] + self.assertEqual(expected, popen_fixture.mock.commands_executed) def test_create_flash_kernel_config(self): fixture = self.useFixture(MockCmdRunnerPopenFixture()) @@ -1149,9 +1162,9 @@ # list of arguments stored. tmpfile = call[-2] self.assertEqual( - ['sudo', 'mv', '-f', tmpfile, - '%s/etc/flash-kernel.conf' % tempdir], - call) + '%s mv -f %s %s/etc/flash-kernel.conf' % ( + sudo_args, tmpfile, tempdir), + fixture.mock.commands_executed[0]) self.assertEqual('UBOOT_PART=/dev/mmcblk0p1', open(tmpfile).read()) def test_move_contents(self): @@ -1161,8 +1174,8 @@ move_contents(tempdir, '/tmp/') - self.assertEqual([['sudo', 'mv', file1, '/tmp/']], - popen_fixture.mock.calls) + self.assertEqual(['%s mv %s /tmp/' % (sudo_args, file1)], + popen_fixture.mock.commands_executed) def test_has_space_left_for_swap(self): statvfs = os.statvfs('/') @@ -1191,7 +1204,8 @@ # The call moves tmpfile to the given path, so tmpfile is the next to # last in the list of arguments stored. tmpfile = call[-2] - self.assertEqual(['sudo', 'mv', '-f', tmpfile, path], call) + self.assertEqual(['%s mv -f %s %s' % (sudo_args, tmpfile, path)], + fixture.mock.commands_executed) self.assertEqual(data, open(tmpfile).read()) @@ -1279,39 +1293,41 @@ fixture = self.useFixture(MockCmdRunnerPopenFixture()) temporarily_overwrite_file_on_dir('/path/to/file', '/dir', '/tmp/dir') self.assertEquals( - [['sudo', 'mv', '-f', '/dir/file', '/tmp/dir/file'], - ['sudo', 'cp', '/path/to/file', '/dir']], - fixture.mock.calls) + ['%s mv -f /dir/file /tmp/dir/file' % sudo_args, + '%s cp /path/to/file /dir' % sudo_args], + fixture.mock.commands_executed) fixture.mock.calls = [] run_local_atexit_funcs() self.assertEquals( - [['sudo', 'mv', '-f', '/tmp/dir/file', '/dir']], - fixture.mock.calls) + ['%s mv -f /tmp/dir/file /dir' % sudo_args], + fixture.mock.commands_executed) def test_copy_file(self): fixture = self.useFixture(MockCmdRunnerPopenFixture()) copy_file('/path/to/file', '/dir') self.assertEquals( - [['sudo', 'cp', '/path/to/file', '/dir']], - fixture.mock.calls) + ['%s cp /path/to/file /dir' % sudo_args], + fixture.mock.commands_executed) fixture.mock.calls = [] run_local_atexit_funcs() self.assertEquals( - [['sudo', 'rm', '-f', '/dir/file']], fixture.mock.calls) + ['%s rm -f /dir/file' % sudo_args], + fixture.mock.commands_executed) def test_mount_chroot_proc(self): fixture = self.useFixture(MockCmdRunnerPopenFixture()) mount_chroot_proc('chroot') self.assertEquals( - [['sudo', 'mount', 'proc', 'chroot/proc', '-t', 'proc']], - fixture.mock.calls) + ['%s mount proc chroot/proc -t proc' % sudo_args], + fixture.mock.commands_executed) fixture.mock.calls = [] run_local_atexit_funcs() self.assertEquals( - [['sudo', 'umount', '-v', 'chroot/proc']], fixture.mock.calls) + ['%s umount -v chroot/proc' % sudo_args], + fixture.mock.commands_executed) def test_install_hwpack(self): self.useFixture(MockSomethingFixture( @@ -1320,15 +1336,16 @@ force_yes = False install_hwpack('chroot', 'hwpack.tgz', force_yes) self.assertEquals( - [['sudo', 'cp', 'hwpack.tgz', 'chroot'], - ['sudo', 'chroot', 'chroot', 'linaro-hwpack-install', - '/hwpack.tgz']], - fixture.mock.calls) + ['%s cp hwpack.tgz chroot' % sudo_args, + '%s chroot chroot linaro-hwpack-install /hwpack.tgz' + % sudo_args], + fixture.mock.commands_executed) fixture.mock.calls = [] run_local_atexit_funcs() self.assertEquals( - [['sudo', 'rm', '-f', 'chroot/hwpack.tgz']], fixture.mock.calls) + ['%s rm -f chroot/hwpack.tgz' % sudo_args], + fixture.mock.commands_executed) def test_install_hwpacks(self): self.useFixture(MockSomethingFixture( @@ -1343,29 +1360,28 @@ 'hwpack2.tgz') linaro_hwpack_install = find_command( 'linaro-hwpack-install', prefer_dir=prefer_dir) - self.assertEquals( - [['sudo', 'mv', '-f', 'chroot/etc/resolv.conf', - '/tmp/dir/resolv.conf'], - ['sudo', 'cp', '/etc/resolv.conf', 'chroot/etc'], - ['sudo', 'mv', '-f', 'chroot/etc/hosts', '/tmp/dir/hosts'], - ['sudo', 'cp', '/etc/hosts', 'chroot/etc'], - ['sudo', 'cp', '/usr/bin/qemu-arm-static', 'chroot/usr/bin'], - ['sudo', 'cp', linaro_hwpack_install, 'chroot/usr/bin'], - ['sudo', 'mount', 'proc', 'chroot/proc', '-t', 'proc'], - ['sudo', 'cp', 'hwpack1.tgz', 'chroot'], - ['sudo', 'chroot', 'chroot', 'linaro-hwpack-install', - '--force-yes', '/hwpack1.tgz'], - ['sudo', 'cp', 'hwpack2.tgz', 'chroot'], - ['sudo', 'chroot', 'chroot', 'linaro-hwpack-install', - '--force-yes', '/hwpack2.tgz'], - ['sudo', 'rm', '-f', 'chroot/hwpack2.tgz'], - ['sudo', 'rm', '-f', 'chroot/hwpack1.tgz'], - ['sudo', 'umount', '-v', 'chroot/proc'], - ['sudo', 'rm', '-f', 'chroot/usr/bin/linaro-hwpack-install'], - ['sudo', 'rm', '-f', 'chroot/usr/bin/qemu-arm-static'], - ['sudo', 'mv', '-f', '/tmp/dir/hosts', 'chroot/etc'], - ['sudo', 'mv', '-f', '/tmp/dir/resolv.conf', 'chroot/etc']], - fixture.mock.calls) + expected = [ + 'mv -f chroot/etc/resolv.conf /tmp/dir/resolv.conf', + 'cp /etc/resolv.conf chroot/etc', + 'mv -f chroot/etc/hosts /tmp/dir/hosts', + 'cp /etc/hosts chroot/etc', + 'cp /usr/bin/qemu-arm-static chroot/usr/bin', + 'cp %s chroot/usr/bin' % linaro_hwpack_install, + 'mount proc chroot/proc -t proc', + 'cp hwpack1.tgz chroot', + 'chroot chroot linaro-hwpack-install --force-yes /hwpack1.tgz', + 'cp hwpack2.tgz chroot', + 'chroot chroot linaro-hwpack-install --force-yes /hwpack2.tgz', + 'rm -f chroot/hwpack2.tgz', + 'rm -f chroot/hwpack1.tgz', + 'umount -v chroot/proc', + 'rm -f chroot/usr/bin/linaro-hwpack-install', + 'rm -f chroot/usr/bin/qemu-arm-static', + 'mv -f /tmp/dir/hosts chroot/etc', + 'mv -f /tmp/dir/resolv.conf chroot/etc'] + expected = [ + "%s %s" % (sudo_args, line) for line in expected] + self.assertEquals(expected, fixture.mock.commands_executed) def test_run_local_atexit_funcs(self): self.useFixture(MockSomethingFixture( @@ -1404,7 +1420,8 @@ sys, 'stdout', open('/dev/null', 'w'))) self.useFixture(MockCmdRunnerPopenFixture()) self.useFixture(MockSomethingFixture( - linaro_media_create.hwpack, 'install_hwpack', mock_install_hwpack)) + linaro_media_create.hwpack, 'install_hwpack', + mock_install_hwpack)) self.useFixture(MockSomethingFixture( linaro_media_create.hwpack, 'run_local_atexit_funcs', mock_run_local_atexit_functions)) @@ -1427,4 +1444,3 @@ def clear_atexits(): linaro_media_create.hwpack.local_atexit = [] self.addCleanup(clear_atexits) -