def prepare_image(self):
     try:
         # Configure it with environment variables.
         env = {}
         if self.args.project is not None:
             env['PROJECT'] = self.args.project
         if self.args.suite is not None:
             env['SUITE'] = self.args.suite
         if self.args.arch is not None:
             env['ARCH'] = self.args.arch
         if self.args.subproject is not None:
             env['SUBPROJECT'] = self.args.subproject
         if self.args.subarch is not None:
             env['SUBARCH'] = self.args.subarch
         if self.args.with_proposed is not None:
             env['PROPOSED'] = self.args.with_proposed
         if self.args.extra_ppas is not None:
             env['EXTRA_PPAS'] = self.args.extra_ppas
         # Only genereate a single rootfs tree for classic image creation.
         env['IMAGEFORMAT'] = 'none'
         live_build(self.unpackdir, env)
     except CalledProcessError:
         if self.args.debug:
             _logger.exception('Full debug traceback follows')
         self.exitcode = 1
         # Stop the state machine right here by not appending a next step.
     else:
         super().prepare_image()
Example #2
0
 def test_live_build_no_cross_build(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'))
         env = OrderedDict()
         env['PROJECT'] = 'ubuntu-server'
         env['SUITE'] = 'xenial'
         env['ARCH'] = 'armhf'
         live_build(root_dir, env, enable_cross_build=False)
         # Make sure that if we explicity disable cross-building, no
         # cross-build arguments are passed to lb config
         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'])
Example #3
0
    def prepare_image(self):
        if not self.args.filesystem:
            try:
                # Configure it with environment variables.
                env = {}
                if self.args.project is not None:
                    env['PROJECT'] = self.args.project
                if self.args.suite is not None:
                    env['SUITE'] = self.args.suite
                if self.args.arch is not None:
                    env['ARCH'] = self.args.arch
                if self.args.subproject is not None:
                    env['SUBPROJECT'] = self.args.subproject
                if self.args.subarch is not None:
                    env['SUBARCH'] = self.args.subarch
                if self.args.with_proposed:
                    env['PROPOSED'] = '1'
                if self.args.extra_ppas is not None:
                    env['EXTRA_PPAS'] = '******'.join(self.args.extra_ppas)
                # Only generate a single rootfs tree for classic images.
                env['IMAGEFORMAT'] = 'none'
                # ensure ARCH is set
                if self.args.arch is None:
                    env['ARCH'] = get_host_arch()
                live_build(self.unpackdir, env)
            except CalledProcessError:
                if self.args.debug:
                    _logger.exception('Full debug traceback follows')
                self.exitcode = 1
                # Stop the state machine here by not appending a next step.
                return

        super().prepare_image()
 def test_live_build_no_cross_build(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'))
         env = OrderedDict()
         env['PROJECT'] = 'ubuntu-server'
         env['SUITE'] = 'xenial'
         env['ARCH'] = 'armhf'
         live_build(root_dir, env, enable_cross_build=False)
         # Make sure that if we explicity disable cross-building, no
         # cross-build arguments are passed to lb config
         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'])
Example #5
0
 def test_live_build_cross_build(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-fake'))
         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', '/usr/bin/qemu-arm-static-fake',
              '--architectures', 'armhf'])
         self.assertEqual(
             mock.call_args_list[2],
             ['sudo',
              'PROJECT=ubuntu-server', 'SUITE=xenial', 'ARCH=armhf',
              'lb', 'build'])
 def test_live_build_cross_build(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-fake'))
         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', '/usr/bin/qemu-arm-static-fake',
              '--architectures', 'armhf'])
         self.assertEqual(
             mock.call_args_list[2],
             ['sudo',
              'PROJECT=ubuntu-server', 'SUITE=xenial', 'ARCH=armhf',
              'lb', 'build'])
Example #7
0
 def test_live_build_with_full_args(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'))
         env = OrderedDict()
         env['PROJECT'] = 'ubuntu-cpc'
         env['SUITE'] = 'xenial'
         env['ARCH'] = 'amd64'
         env['SUBPROJECT'] = 'live'
         env['SUBARCH'] = 'ubuntu-cpc'
         env['PROPOSED'] = 'true'
         env['IMAGEFORMAT'] = 'ext4'
         env['EXTRA_PPAS'] = '******'
         live_build(root_dir, env)
         self.assertEqual(len(mock.call_args_list), 3)
         self.assertEqual(mock.call_args_list[1], [
             'sudo', 'PROJECT=ubuntu-cpc', 'SUITE=xenial', 'ARCH=amd64',
             'SUBPROJECT=live', 'SUBARCH=ubuntu-cpc', 'PROPOSED=true',
             'IMAGEFORMAT=ext4', 'EXTRA_PPAS=foo1/bar1 foo2', 'lb', 'config'
         ])
         self.assertEqual(mock.call_args_list[2], [
             'sudo', 'PROJECT=ubuntu-cpc', 'SUITE=xenial', 'ARCH=amd64',
             'SUBPROJECT=live', 'SUBARCH=ubuntu-cpc', 'PROPOSED=true',
             'IMAGEFORMAT=ext4', 'EXTRA_PPAS=foo1/bar1 foo2', 'lb', 'build'
         ])
Example #8
0
 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 prepare_image(self):
        if not self.args.filesystem:
            try:
                # Configure it with environment variables.
                env = {}
                if self.args.project is not None:
                    env['PROJECT'] = self.args.project
                if self.args.suite is not None:
                    env['SUITE'] = self.args.suite
                if self.args.arch is not None:
                    env['ARCH'] = self.args.arch
                if self.args.subproject is not None:
                    env['SUBPROJECT'] = self.args.subproject
                if self.args.subarch is not None:
                    env['SUBARCH'] = self.args.subarch
                if self.args.with_proposed:
                    env['PROPOSED'] = '1'
                if self.args.extra_ppas is not None:
                    env['EXTRA_PPAS'] = '******'.join(self.args.extra_ppas)
                # Only generate a single rootfs tree for classic images.
                env['IMAGEFORMAT'] = 'none'
                # ensure ARCH is set
                if self.args.arch is None:
                    env['ARCH'] = get_host_arch()
                live_build(self.unpackdir, env)
            except CalledProcessError:
                if self.args.debug:
                    _logger.exception('Full debug traceback follows')
                self.exitcode = 1
                # Stop the state machine here by not appending a next step.
                return

        super().prepare_image()
Example #10
0
 def test_live_build_cross_build_no_static(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=None))
         env = OrderedDict()
         env['PROJECT'] = 'ubuntu-server'
         env['SUITE'] = 'xenial'
         env['ARCH'] = 'armhf'
         with self.assertRaises(DependencyError) as cm:
             live_build(root_dir, env)
         self.assertEqual(len(mock.call_args_list), 1)
         self.assertEqual(cm.exception.name, 'qemu-arm-static')
Example #11
0
 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')
Example #12
0
 def test_live_build_cross_build_no_static(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=None))
         env = OrderedDict()
         env['PROJECT'] = 'ubuntu-server'
         env['SUITE'] = 'xenial'
         env['ARCH'] = 'armhf'
         with self.assertRaises(DependencyError) as cm:
             live_build(root_dir, env)
         self.assertEqual(len(mock.call_args_list), 1)
         self.assertEqual(
             cm.exception.name, 'qemu-arm-static')
Example #13
0
 def test_live_build_with_full_args(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'))
         env = OrderedDict()
         env['PROJECT'] = 'ubuntu-cpc'
         env['SUITE'] = 'xenial'
         env['ARCH'] = 'amd64'
         env['SUBPROJECT'] = 'live'
         env['SUBARCH'] = 'ubuntu-cpc'
         env['PROPOSED'] = 'true'
         env['IMAGEFORMAT'] = 'ext4'
         env['EXTRA_PPAS'] = '******'
         live_build(root_dir, env)
         self.assertEqual(len(mock.call_args_list), 3)
         self.assertEqual(
             mock.call_args_list[1],
             ['sudo',
              'PROJECT=ubuntu-cpc', 'SUITE=xenial', 'ARCH=amd64',
              'SUBPROJECT=live', 'SUBARCH=ubuntu-cpc', 'PROPOSED=true',
              'IMAGEFORMAT=ext4', 'EXTRA_PPAS=foo1/bar1 foo2',
              'lb', 'config'])
         self.assertEqual(
             mock.call_args_list[2],
             ['sudo',
              'PROJECT=ubuntu-cpc', 'SUITE=xenial', 'ARCH=amd64',
              'SUBPROJECT=live', 'SUBARCH=ubuntu-cpc', 'PROPOSED=true',
              'IMAGEFORMAT=ext4', 'EXTRA_PPAS=foo1/bar1 foo2',
              'lb', 'build'])
Example #14
0
 def test_live_build(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))
         env = OrderedDict()
         env['PROJECT'] = 'ubuntu-server'
         env['SUITE'] = 'xenial'
         env['ARCH'] = 'amd64'
         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=amd64',
              'lb', 'config'])
         self.assertEqual(
             mock.call_args_list[2],
             ['sudo',
              'PROJECT=ubuntu-server', 'SUITE=xenial', 'ARCH=amd64',
              'lb', 'build'])