def test_live_build_cross_build_env_path(self): with ExitStack() as resources: tmpdir = resources.enter_context(TemporaryDirectory()) root_dir = os.path.join(tmpdir, 'root_dir') mock = LiveBuildMocker(root_dir) resources.enter_context(LogCapture()) resources.enter_context(patch('ubuntu_image.helpers.run', mock.run)) resources.enter_context( patch('ubuntu_image.helpers.get_host_arch', return_value='amd64')) resources.enter_context( patch('ubuntu_image.helpers.find_executable', return_value='/usr/bin/qemu-arm-static')) resources.enter_context( envar('UBUNTU_IMAGE_QEMU_USER_STATIC_PATH', '/opt/qemu-arm-static')) env = OrderedDict() env['PROJECT'] = 'ubuntu-server' env['SUITE'] = 'xenial' env['ARCH'] = 'armhf' live_build(root_dir, env) self.assertEqual(len(mock.call_args_list), 3) self.assertEqual(mock.call_args_list[1], [ 'sudo', 'PROJECT=ubuntu-server', 'SUITE=xenial', 'ARCH=armhf', 'lb', 'config', '--bootstrap-qemu-arch', 'armhf', '--bootstrap-qemu-static', '/opt/qemu-arm-static', '--architectures', 'armhf' ]) self.assertEqual(mock.call_args_list[2], [ 'sudo', 'PROJECT=ubuntu-server', 'SUITE=xenial', 'ARCH=armhf', 'lb', 'build' ])
def test_live_build_env_livecd(self): with ExitStack() as resources: tmpdir = resources.enter_context(TemporaryDirectory()) auto_dir = os.path.join(tmpdir, 'auto') os.mkdir(auto_dir) with open(os.path.join(auto_dir, 'config'), 'w') as fp: fp.write('DUMMY') root_dir = os.path.join(tmpdir, 'root_dir') mock = LiveBuildMocker(root_dir) resources.enter_context(LogCapture()) resources.enter_context( patch('ubuntu_image.helpers.run', mock.run)) resources.enter_context( envar('UBUNTU_IMAGE_LIVECD_ROOTFS_AUTO_PATH', auto_dir)) env = OrderedDict() env['PROJECT'] = 'ubuntu-server' env['SUITE'] = 'xenial' env['ARCH'] = 'amd64' live_build(root_dir, env) # Make sure that we had no dpkg -L call made. self.assertEqual(len(mock.call_args_list), 2) self.assertEqual( mock.call_args_list[0], ['sudo', 'PROJECT=ubuntu-server', 'SUITE=xenial', 'ARCH=amd64', 'lb', 'config']) self.assertEqual( mock.call_args_list[1], ['sudo', 'PROJECT=ubuntu-server', 'SUITE=xenial', 'ARCH=amd64', 'lb', 'build']) config_path = os.path.join(root_dir, 'auto', 'config') self.assertTrue(os.path.exists(config_path)) with open(os.path.join(config_path), 'r') as fp: self.assertEqual(fp.read(), 'DUMMY')
def test_tmp_okay_for_classic_snap(self): # For reference see: # http://snapcraft.io/docs/reference/env self._resources.enter_context(envar('SNAP_NAME', 'crack-pop')) self._resources.enter_context(chdir('/tmp')) self._resources.enter_context( patch('ubuntu_image.__main__.ModelAssertionBuilder', DoNothingBuilder)) code = main(('snap', '--output-dir', '/tmp/images', '--extra-snaps', '/tmp/extra.snap', '/tmp/model.assertion')) self.assertEqual(code, 0) self.assertTrue(os.path.exists('/tmp/images/pc.img'))
def test_tmp_okay_for_classic_snap(self): # For reference see: # http://snapcraft.io/docs/reference/env self._resources.enter_context(envar('SNAP_NAME', 'crack-pop')) self._resources.enter_context(chdir('/tmp')) self._resources.enter_context(patch( 'ubuntu_image.__main__.ModelAssertionBuilder', DoNothingBuilder)) code = main(('snap', '--output-dir', '/tmp/images', '--extra-snaps', '/tmp/extra.snap', '/tmp/model.assertion')) self.assertEqual(code, 0) self.assertTrue(os.path.exists('/tmp/images/pc.img'))
def test_classic_cross_build_no_static(self): # We need to check that a DependencyError is raised when # find_executable does not find the qemu-<ARCH>-static binary in # PATH (and no path env is set) workdir = self._resources.enter_context(TemporaryDirectory()) livecd_rootfs = self._resources.enter_context(TemporaryDirectory()) auto = os.path.join(livecd_rootfs, 'auto') os.mkdir(auto) self._resources.enter_context(patch( 'ubuntu_image.__main__.ClassicBuilder', CallLBLeaveATraceClassicBuilder)) self._resources.enter_context( envar('UBUNTU_IMAGE_LIVECD_ROOTFS_AUTO_PATH', auto)) self._resources.enter_context( patch('ubuntu_image.helpers.run', return_value=None)) self._resources.enter_context( patch('ubuntu_image.helpers.find_executable', return_value=None)) self._resources.enter_context( patch('ubuntu_image.helpers.get_host_arch', return_value='amd64')) self._resources.enter_context( patch('ubuntu_image.__main__.get_host_distro', return_value='bionic')) self._resources.enter_context( patch('ubuntu_image.classic_builder.check_root_privilege', return_value=None)) mock = self._resources.enter_context(patch( 'ubuntu_image.__main__._logger.error')) code = main(('classic', '--workdir', workdir, '--project', 'ubuntu-cpc', '--arch', 'armhf', self.classic_gadget_tree)) self.assertEqual(code, 1) self.assertFalse(os.path.exists(os.path.join(workdir, 'success'))) self.assertEqual( mock.call_args_list[-1], call('Required dependency qemu-arm-static seems to be missing. ' 'Use UBUNTU_IMAGE_QEMU_USER_STATIC_PATH in case of ' 'non-standard archs or custom paths.'))
def test_live_build_env_livecd(self): with ExitStack() as resources: tmpdir = resources.enter_context(TemporaryDirectory()) auto_dir = os.path.join(tmpdir, 'auto') os.mkdir(auto_dir) with open(os.path.join(auto_dir, 'config'), 'w') as fp: fp.write('DUMMY') root_dir = os.path.join(tmpdir, 'root_dir') mock = LiveBuildMocker(root_dir) resources.enter_context(LogCapture()) resources.enter_context( patch('ubuntu_image.helpers.run', mock.run)) resources.enter_context( patch('ubuntu_image.helpers.get_host_arch', return_value='amd64')) resources.enter_context( envar('UBUNTU_IMAGE_LIVECD_ROOTFS_AUTO_PATH', auto_dir)) env = OrderedDict() env['PROJECT'] = 'ubuntu-server' env['SUITE'] = 'xenial' env['ARCH'] = 'amd64' live_build(root_dir, env) # Make sure that we had no dpkg -L call made. self.assertEqual(len(mock.call_args_list), 2) self.assertEqual( mock.call_args_list[0], ['sudo', 'PROJECT=ubuntu-server', 'SUITE=xenial', 'ARCH=amd64', 'lb', 'config']) self.assertEqual( mock.call_args_list[1], ['sudo', 'PROJECT=ubuntu-server', 'SUITE=xenial', 'ARCH=amd64', 'lb', 'build']) config_path = os.path.join(root_dir, 'auto', 'config') self.assertTrue(os.path.exists(config_path)) with open(os.path.join(config_path), 'r') as fp: self.assertEqual(fp.read(), 'DUMMY')
def test_classic_cross_build_no_static(self): # We need to check that a DependencyError is raised when # find_executable does not find the qemu-<ARCH>-static binary in # PATH (and no path env is set) workdir = self._resources.enter_context(TemporaryDirectory()) livecd_rootfs = self._resources.enter_context(TemporaryDirectory()) auto = os.path.join(livecd_rootfs, 'auto') os.mkdir(auto) self._resources.enter_context(patch( 'ubuntu_image.__main__.ClassicBuilder', CallLBLeaveATraceClassicBuilder)) self._resources.enter_context( envar('UBUNTU_IMAGE_LIVECD_ROOTFS_AUTO_PATH', auto)) self._resources.enter_context( patch('ubuntu_image.helpers.run', return_value=None)) self._resources.enter_context( patch('ubuntu_image.helpers.find_executable', return_value=None)) self._resources.enter_context( patch('ubuntu_image.helpers.get_host_arch', return_value='amd64')) self._resources.enter_context( patch('ubuntu_image.__main__.get_host_distro', return_value='bionic')) self._resources.enter_context( patch('ubuntu_image.classic_builder.check_root_privilege', return_value=None)) mock = self._resources.enter_context(patch( 'ubuntu_image.__main__._logger.error')) code = main(('classic', '--workdir', workdir, '--project', 'ubuntu-cpc', '--arch', 'armhf', self.classic_gadget_tree)) self.assertEqual(code, 1) self.assertFalse(os.path.exists(os.path.join(workdir, 'success'))) self.assertEqual( mock.call_args_list[-1], call('Required dependency qemu-arm-static seems to be missing. ' 'Use UBUNTU_IMAGE_QEMU_USER_STATIC_PATH in case of ' 'non-standard archs or custom paths.'))
def test_live_build_cross_build_env_path(self): with ExitStack() as resources: tmpdir = resources.enter_context(TemporaryDirectory()) root_dir = os.path.join(tmpdir, 'root_dir') mock = LiveBuildMocker(root_dir) resources.enter_context(LogCapture()) resources.enter_context( patch('ubuntu_image.helpers.run', mock.run)) resources.enter_context( patch('ubuntu_image.helpers.get_host_arch', return_value='amd64')) resources.enter_context( patch('ubuntu_image.helpers.find_executable', return_value='/usr/bin/qemu-arm-static')) resources.enter_context( envar('UBUNTU_IMAGE_QEMU_USER_STATIC_PATH', '/opt/qemu-arm-static')) env = OrderedDict() env['PROJECT'] = 'ubuntu-server' env['SUITE'] = 'xenial' env['ARCH'] = 'armhf' live_build(root_dir, env) self.assertEqual(len(mock.call_args_list), 3) self.assertEqual( mock.call_args_list[1], ['sudo', 'PROJECT=ubuntu-server', 'SUITE=xenial', 'ARCH=armhf', 'lb', 'config', '--bootstrap-qemu-arch', 'armhf', '--bootstrap-qemu-static', '/opt/qemu-arm-static', '--architectures', 'armhf']) self.assertEqual( mock.call_args_list[2], ['sudo', 'PROJECT=ubuntu-server', 'SUITE=xenial', 'ARCH=armhf', 'lb', 'build'])