Esempio n. 1
0
 def setUp(self):
     kwargs = {
         'data_dir': tempfile.mkdtemp(prefix='cloud_build'),
         'config': 'tests/minimal_config.yaml',
     }
     self.kwargs = kwargs
     self.cb = CB(**kwargs)
Esempio n. 2
0
 def test_sign_requires_key(self):
     with mock.patch('subprocess.call', call.Call()):
         regex = 'key.*config'
         cloud_build = CB(
             config='tests/minimal_config.yaml',
             data_dir=self.kwargs['data_dir'],
         )
         cloud_build.create_images(no_tests=True)
         self.assertRaisesRegex(Error, regex, cloud_build.sign)
Esempio n. 3
0
    def test_packages_images(self):
        with mock.patch('subprocess.call', Call()):
            cb = CB(data_dir=self.data_dir, config='tests/packages_image.yaml')
            cb.ensure_mkimage_profiles()

            conf = cb.work_dir / self.conf_mk
            lines = conf.read_text().splitlines()

            for package_line in self.package_lines:
                self.assertIn(package_line, lines)
Esempio n. 4
0
 def test_run_after_sync_local_commands(self):
     cb = CB(
         config='tests/test_run_after_sync_local_commands.yaml',
         data_dir=self.data_dir,
     )
     cb.create_images(no_tests=True)
     regex = r'\[\'kick'
     self.assertRaisesRegex(Exception,
                            regex,
                            cb.sync,
                            create_remote_dirs=True)
Esempio n. 5
0
 def test_do_force_rebuild(self):
     tarball = self.data_dir / 'out/docker_Sisyphus-x86_64.tar.xz'
     tarball.touch()
     del self.cb
     cb = CB(
         config='tests/test_rebuild.yaml',
         data_dir=self.data_dir,
         config_override={'rebuild_after': {'days': 0}},
     )
     msg = 'Do not try to rebuild when force_rebuild'
     with self.assertRaises(BuildError, msg=msg):
         cb.create_images(no_tests=True)
Esempio n. 6
0
    def setUpClass(cls):
        cls.work_dir = Path('/tmp/cloud-build')
        os.makedirs(cls.work_dir / 'external_files/p9/x86_64', exist_ok=True)
        (cls.work_dir / 'external_files/p9/x86_64/README').write_text('README')
        config = cls.work_dir / 'config.yaml'
        branch = cls.branch
        arch = cls.arch
        remote = Path('/tmp/cloud-build/images')
        if branch:
            remote = remote / '{branch}'
        if arch:
            remote = remote / '{arch}'
        remote = (remote / 'cloud').as_posix()
        change(
            'tests/test_integration_images.yaml',
            config,
            'remote',
            remote,
        )

        with ExitStack() as stack:
            stack.enter_context(mock.patch('subprocess.call', Call()))

            cloud_build = CB(
                config=config,
                data_dir=(cls.work_dir / 'cloud_build').as_posix(),
            )
            cloud_build.create_images(no_tests=True)
            cloud_build.copy_external_files()
            cloud_build.sign()
            cloud_build.sync(create_remote_dirs=True)

        images_dir = cls.work_dir / 'images'
        cls.images_dir = images_dir
        images = defaultdict(lambda: defaultdict(list))

        if branch:
            for branch in os.listdir(images_dir):
                if arch:
                    for arch in os.listdir(images_dir / branch):
                        images[branch][arch] = os.listdir(images_dir / branch /
                                                          arch / 'cloud')
                else:
                    images[branch]['arch'] = os.listdir(images_dir / branch /
                                                        'cloud')
        elif arch:
            for arch in os.listdir(images_dir):
                images['branch'][arch] = os.listdir(images_dir / arch /
                                                    'cloud')
        else:
            images['branch']['arch'] = os.listdir(images_dir / 'cloud')
        cls._images = images
Esempio n. 7
0
 def test_bad_size(self):
     with mock.patch('subprocess.call', call.Call()):
         regex = 'Bad size.*'
         cloud_build = CB(
             config='tests/test_bad_size.yaml',
             data_dir=self.kwargs['data_dir'],
         )
         self.assertRaisesRegex(Error,
                                regex,
                                cloud_build.create_images,
                                no_tests=True)
Esempio n. 8
0
class TestUtils(TestCase):
    def setUp(self):
        kwargs = {
            'data_dir': tempfile.mkdtemp(prefix='cloud_build'),
            'config': 'tests/minimal_config.yaml',
        }
        self.kwargs = kwargs
        self.cb = CB(**kwargs)

    def tearDown(self):
        shutil.rmtree(self.kwargs['data_dir'])

    def test_conver_size_lower_case(self):
        self.assertEqual(self.cb.convert_size('200k'), '204800')

    def test_conver_size_upper_case(self):
        self.assertEqual(self.cb.convert_size('1M'), '1048576')

    def test_conver_size_real(self):
        self.assertEqual(self.cb.convert_size('0.1G'), '107374182')
Esempio n. 9
0
 def test_skiped_build(self):
     with mock.patch('subprocess.call'):
         cloud_build = CB(
             config='tests/minimal_config.yaml',
             data_dir=self.kwargs['data_dir'],
             built_images_dir=self.images_dir,
         )
         regex = r'build.*skip'
         self.assertRaisesRegex(Error,
                                regex,
                                cloud_build.create_images,
                                no_tests=True)
Esempio n. 10
0
 def test_dont_run_after_sync_local_commands(self):
     cb = CB(
         config='tests/minimal_config.yaml',
         data_dir=self.data_dir,
     )
     cb.create_images(no_tests=True)
     cb.sync(create_remote_dirs=False)
Esempio n. 11
0
class TestRebuild(TestCase):
    def setUp(self):
        self.data_dir = Path(tempfile.mkdtemp(prefix='cloud_build'))
        self.cb = CB(
            config='tests/test_rebuild.yaml',
            data_dir=self.data_dir,
        )

    def tearDown(self):
        shutil.rmtree(self.data_dir)

    @mock.patch('subprocess.call', call.Call(decorators=DS))
    def test_do_rebuild(self):
        tarball = self.data_dir / 'out/docker_Sisyphus-x86_64.tar.xz'
        tarball.touch()
        two_hours_ago = time.time() - 2*60*60
        os.utime(tarball, times=(two_hours_ago, two_hours_ago))
        msg = 'Do not try to rebuild with outdated cache'
        with self.assertRaises(BuildError, msg=msg):
            self.cb.create_images(no_tests=True)

    @mock.patch('subprocess.call', call.Call(decorators=DS))
    def test_do_force_rebuild(self):
        tarball = self.data_dir / 'out/docker_Sisyphus-x86_64.tar.xz'
        tarball.touch()
        del self.cb
        cb = CB(
            config='tests/test_rebuild.yaml',
            data_dir=self.data_dir,
            config_override={'rebuild_after': {'days': 0}},
        )
        msg = 'Do not try to rebuild when force_rebuild'
        with self.assertRaises(BuildError, msg=msg):
            cb.create_images(no_tests=True)

    @mock.patch('subprocess.call', call.Call(decorators=DS))
    def test_dont_rebuild(self):
        tarball = self.data_dir / 'out/docker_Sisyphus-x86_64.tar.xz'
        tarball.touch()
        msg = 'Try to rebuild with valid cache'
        try:
            self.cb.create_images(no_tests=True)
        except BuildError:
            self.fail(msg)

    @mock.patch('subprocess.call', call.Call())
    def test_dont_create_image_when_rebuild(self):
        tarball = self.data_dir / 'out/docker_Sisyphus-x86_64.tar.xz'
        tarball.touch()
        self.cb.create_images(no_tests=True)
        image = (
            self.data_dir
            / 'images'
            / 'alt-sisyphus-rootfs-minimal-x86_64.tar.xz'
        )
        msg = 'Do not create image when rebuild'
        if not image.exists():
            self.fail(msg)
Esempio n. 12
0
 def test_sign_override_key(self):
     with mock.patch('subprocess.call', call.Call()):
         cloud_build = CB(
             config='tests/minimal_config.yaml',
             data_dir=self.kwargs['data_dir'],
             config_override={'key': 0},
         )
         cloud_build.create_images(no_tests=True)
         cloud_build.sign()
Esempio n. 13
0
    def test_try_build_all_zero_rc(self):
        def cond(args):
            return args[1].endswith('aarch64')

        ds = {'make': [call.return_d(0, cond=cond), call.nop_d(cond=cond)]}
        with mock.patch('subprocess.call', call.Call(decorators=ds)):
            cloud_build = CB(
                config='tests/test_try_build_all.yaml',
                data_dir=self.kwargs['data_dir'],
            )
            regex = r'build.*:'
            self.assertRaisesRegex(MultipleBuildErrors,
                                   regex,
                                   cloud_build.create_images,
                                   no_tests=True)
Esempio n. 14
0
    def test_override_required_parameters_in_config(self):
        self.config = tempfile.mktemp(prefix='cb_conf')
        config_override = {
            'remote': '/var/empty',
            'images': {},
            'branches': {},
        }
        with open('tests/minimal_config.yaml') as f:
            cfg = yaml.safe_load(f)

        for parameter in ['remote', 'images', 'branches']:
            with open(self.config, 'w') as f:
                yaml.safe_dump(update(cfg, {parameter: None}), f)

            self.kwargs.update(config=self.config)
            self.kwargs.update(config_override=config_override)
            CB(**self.kwargs)
Esempio n. 15
0
 def test_no_delete_true(self):
     cb = CB(
         config='tests/test_no_delete_true.yaml',
         data_dir=self.data_dir,
     )
     other_file = self.images_dir / 'other_file.txt'
     other_file.write_text('Some text')
     cb.create_images(no_tests=True)
     cb.sync(create_remote_dirs=True)
     del cb
     msg = 'Other files shoud not be deleted if no_delete'
     if not other_file.exists():
         self.fail(msg)
Esempio n. 16
0
    def setUpClass(cls):
        cls.work_dir = Path('/tmp/cloud-build')
        os.makedirs(cls.work_dir, exist_ok=True)
        renamer(cls.work_dir)

        with ExitStack() as stack:
            stack.enter_context(mock.patch('subprocess.call', Call()))

            cloud_build = CB(
                config='tests/test_rename.yaml',
                data_dir=(cls.work_dir / 'cloud_build').as_posix(),
            )
            cloud_build.create_images(no_tests=True)
            cloud_build.sync(create_remote_dirs=True)

        images_dir = cls.work_dir / 'images'
        cls.images = os.listdir(images_dir)
Esempio n. 17
0
 def setUp(self):
     self.data_dir = Path(tempfile.mkdtemp(prefix='cloud_build'))
     self.cb = CB(
         config='tests/test_rebuild.yaml',
         data_dir=self.data_dir,
     )
Esempio n. 18
0
 def test_run_already_running(self):
     self.kwargs.update(config='tests/minimal_config.yaml')
     cb = CB(**self.kwargs)  # noqa F841
     regex = 'already running'
     self.assertRaisesRegex(Error, regex, CB, **self.kwargs)