Ejemplo n.º 1
0
    def test_var_dir_should_be_path_to_stateroot_var_for_randomly_generated_stateroot(
            self):
        cfg = Config(Source.url('url'), 'ref')

        self.assertEqual(
            cfg.var_dir, os.path.join('/ostree', 'deploy', cfg.stateroot,
                                      'var'))
Ejemplo n.º 2
0
    def test_should_not_error_if_instance_is_created_without_deployment_name_set(
            self):
        cfg = Config(Source.url('url'), 'ref', stateroot='test')

        step = MountVar(cfg)

        self.assertIsNotNone(step)
Ejemplo n.º 3
0
    def test_var_dir_should_include_sysroot(self):
        sysroot = os.path.join('/mnt', 'rootfs')
        cfg = Config(Source.url('url'), 'ref', sysroot=sysroot)

        self.assertEqual(
            cfg.var_dir,
            os.path.join(sysroot, 'ostree', 'deploy', cfg.stateroot, 'var'))
Ejemplo n.º 4
0
    def test_should_return_HttpRemote_if_url_source(self):
        cfg = Config(Source.url('http://example.com/ostree'), 'ref')

        steps = get_steps(cfg)

        self.assertEqual(len(steps), 1)
        self.assertIsInstance(steps[0], HttpRemote)
Ejemplo n.º 5
0
    def test_should_return_FileRemote_if_path_source(self):
        cfg = Config(Source.path('/ostree/repo'), 'ref')

        steps = get_steps(cfg)

        self.assertEqual(len(steps), 1)
        self.assertIsInstance(steps[0], FileRemote)
Ejemplo n.º 6
0
    def test_should_raise_exception_if_nothing_was_added_to_deployments_dir(
            self):
        cfg = Config(Source.url('url'), 'ref')

        step = Deploy(cfg)
        with self.assertRaises(DeployError):
            step.run()
Ejemplo n.º 7
0
class TestBuiltinProvisioner(TestCase):
    cfg = Config(Source.url('url'), 'ref', stateroot='test')
    cfg.set_deployment_name('test-deploy.0')
    deploy_dir = os.path.join('/', 'ostree', 'deploy', 'test', 'deploy',
                              'test-deploy.0')

    def test_title_should_be_str_instance(self):
        self.assertIsInstance(
            BuiltinProvisioner(mock.Mock(), mock.Mock()).title, str)

    @mock.patch('deploy_ostree.steps.provisioners.builtin.run')
    def test_should_run_provisioner_script_with_no_arguments(
            self, run_mock: mock.Mock):
        provisioner = ProvisionerConfig('etc-fstab', {})

        BuiltinProvisioner(self.cfg, provisioner).run()

        run_mock.assert_called_once_with(
            [os.path.join(PROVISIONERS_DIR, 'etc-fstab'), self.deploy_dir],
            check=True,
            env={})

    @mock.patch('deploy_ostree.steps.provisioners.builtin.run')
    def test_should_run_provisioner_script_with_specified_sysroot(
            self, run_mock: mock.Mock):
        sysroot = os.path.join('/mnt', 'rootfs')
        cfg = Config(Source.url('url'),
                     'ref',
                     stateroot='test',
                     sysroot=sysroot)
        cfg.set_deployment_name('test-deploy.0')
        provisioner = ProvisionerConfig('etc-fstab', {})

        BuiltinProvisioner(cfg, provisioner).run()

        run_mock.assert_called_once_with([
            os.path.join(PROVISIONERS_DIR, 'etc-fstab'),
            os.path.join(sysroot, 'ostree', 'deploy', 'test', 'deploy',
                         'test-deploy.0')
        ],
                                         check=True,
                                         env={})

    @mock.patch('deploy_ostree.steps.provisioners.builtin.run')
    def test_should_run_provisioner_script_with_arguments(
            self, run_mock: mock.Mock):
        provisioner = ProvisionerConfig('create-user', {
            'username': '******',
            'password': '******'
        })

        BuiltinProvisioner(self.cfg, provisioner).run()

        run_mock.assert_called_once_with(
            [os.path.join(PROVISIONERS_DIR, 'create-user'), self.deploy_dir],
            check=True,
            env={
                'DEPLOY_OSTREE_username': '******',
                'DEPLOY_OSTREE_password': '******'
            })
Ejemplo n.º 8
0
    def test_deployment_path_should_return_path_after_setting_name(self):
        cfg = Config(Source.url('url'), 'ref', stateroot='test-stateroot')
        cfg.set_deployment_name('deployment-name')

        self.assertEqual(
            cfg.deployment_dir,
            os.path.join('/ostree', 'deploy', 'test-stateroot', 'deploy',
                         'deployment-name'))
Ejemplo n.º 9
0
    def test_deployment_dir_should_include_sysroot(self):
        sysroot = os.path.join('/mnt', 'rootfs')
        cfg = Config(Source.url('url'), 'ref', sysroot=sysroot)
        cfg.set_deployment_name('0123deployment.0')

        self.assertEqual(
            cfg.deployment_dir,
            os.path.join(sysroot, 'ostree', 'deploy', cfg.stateroot, 'deploy',
                         '0123deployment.0'))
Ejemplo n.º 10
0
    def test_should_pull_ref(self, run_mock: mock.Mock):
        cfg = Config(Source.url('url'),
                     'fedora/28/x86_64/workstation',
                     remote='ostree-remote')

        PullRef(cfg).run()

        run_mock.assert_called_once_with([
            'ostree', 'pull',
            '--repo=%s' % os.path.join('/ostree', 'repo'), 'ostree-remote',
            'fedora/28/x86_64/workstation'
        ],
                                         check=True)
Ejemplo n.º 11
0
    def test_should_unmount_on_cleanup(self, run_mock: mock.Mock):
        cfg = Config(Source.url('url'), 'ref', stateroot='test')
        cfg.set_deployment_name('test-deploy.0')

        MountVar(cfg).cleanup()

        run_mock.assert_called_once_with([
            'umount',
            '-l',
            os.path.join('/ostree', 'deploy', 'test', 'deploy',
                         'test-deploy.0', 'var'),
        ],
                                         check=True)
Ejemplo n.º 12
0
    def test_should_add_ostree_remote_for_url_in_config(
            self, mock_run: mock.Mock):
        cfg = Config(Source.url('https://example.com/ostree'),
                     'debian/9/i386/desktop',
                     remote='remote-name')

        HttpRemote(cfg).run()

        mock_run.assert_called_once_with([
            'ostree', 'remote', 'add',
            '--repo=%s' % os.path.join('/ostree', 'repo'), '--no-gpg-verify',
            'remote-name', 'https://example.com/ostree'
        ],
                                         check=True)
Ejemplo n.º 13
0
    def test_should_delete_ostree_remote(self, mock_run: mock.Mock):
        cfg = Config(Source.url('url'), 'ref', remote='remote-name')

        DeleteRemote(cfg).run()

        mock_run.assert_called_once_with([
            'ostree',
            'remote',
            'delete',
            '--repo=%s' % os.path.join('/ostree', 'repo'),
            '--if-exists',
            'remote-name',
        ],
                                         check=True)
Ejemplo n.º 14
0
    def test_should_return_BuiltinProvisioner_per_configured_provisioner(self):
        cfg = Config(Source.url('url'),
                     'ref',
                     stateroot='test',
                     default_provisioners=[
                         ProvisionerConfig('create-user', {}),
                         ProvisionerConfig('etc-fstab', {'arg': 'value'}),
                     ])

        steps = get_steps(cfg)

        self.assertEqual(len(steps), 2)
        self.assertIsInstance(steps[0], BuiltinProvisioner)
        self.assertIsInstance(steps[1], BuiltinProvisioner)
Ejemplo n.º 15
0
    def test_should_add_ostree_remote_for_path_in_config(
            self, mock_run: mock.Mock):
        cfg = Config(Source.path('/srv/ostree/debian/repo'),
                     'debian/9/i386/desktop',
                     remote='remote-name')

        FileRemote(cfg).run()

        mock_run.assert_called_once_with([
            'ostree', 'remote', 'add',
            '--repo=%s' % os.path.join('/ostree', 'repo'), '--no-gpg-verify',
            'remote-name', 'file:///srv/ostree/debian/repo'
        ],
                                         check=True)
Ejemplo n.º 16
0
    def test_should_bind_mount_var_into_deployment(self, run_mock: mock.Mock):
        cfg = Config(Source.url('url'), 'ref', stateroot='test')
        cfg.set_deployment_name('test-deploy.0')

        MountVar(cfg).run()

        run_mock.assert_called_once_with([
            'mount',
            '-o',
            'bind',
            os.path.join('/ostree', 'deploy', 'test', 'var'),
            os.path.join('/ostree', 'deploy', 'test', 'deploy',
                         'test-deploy.0', 'var'),
        ],
                                         check=True)
Ejemplo n.º 17
0
def should_not_create_stateroot_if_path_exists():
    sysroot = Path('/', 'mnt', 'rootfs')
    cfg = Config(Source.url('url'),
                 'ref',
                 stateroot='stateroot-name',
                 sysroot=str(sysroot))

    with ExitStack() as stack:
        exists = stack.enter_context(
            mock.patch('os.path.exists', mock.Mock(return_value=True)))
        run = stack.enter_context(
            mock.patch('deploy_ostree.steps.create_stateroot.run'))
        CreateStateroot(cfg).run()

    exists.assert_called_once_with('/mnt/rootfs/ostree/deploy/stateroot-name')
    run.assert_not_called()
Ejemplo n.º 18
0
    def test_should_add_ostree_remote_with_absolute_path(
            self, mock_run: mock.Mock):
        cfg = Config(Source.path('repo'),
                     'debian/9/i386/desktop',
                     remote='remote-name',
                     base_dir='ostree')
        repo_abs_path = os.path.join(os.getcwd(), 'ostree', 'repo')

        FileRemote(cfg).run()

        mock_run.assert_called_once_with([
            'ostree', 'remote', 'add',
            '--repo=%s' % os.path.join('/ostree', 'repo'), '--no-gpg-verify',
            'remote-name',
            'file://%s' % repo_abs_path
        ],
                                         check=True)
Ejemplo n.º 19
0
    def test_should_run_provisioner_script_with_specified_sysroot(
            self, run_mock: mock.Mock):
        sysroot = os.path.join('/mnt', 'rootfs')
        cfg = Config(Source.url('url'),
                     'ref',
                     stateroot='test',
                     sysroot=sysroot)
        cfg.set_deployment_name('test-deploy.0')
        provisioner = ProvisionerConfig('etc-fstab', {})

        BuiltinProvisioner(cfg, provisioner).run()

        run_mock.assert_called_once_with([
            os.path.join(PROVISIONERS_DIR, 'etc-fstab'),
            os.path.join(sysroot, 'ostree', 'deploy', 'test', 'deploy',
                         'test-deploy.0')
        ],
                                         check=True,
                                         env={})
Ejemplo n.º 20
0
    def test_should_mount_with_specified_sysroot(self, run_mock: mock.Mock):
        sysroot = os.path.join('/mnt', 'rootfs')
        cfg = Config(Source.url('url'),
                     'ref',
                     stateroot='test',
                     sysroot=sysroot)
        cfg.set_deployment_name('test-deploy.0')

        MountVar(cfg).run()

        run_mock.assert_called_once_with([
            'mount',
            '-o',
            'bind',
            os.path.join(sysroot, 'ostree', 'deploy', 'test', 'var'),
            os.path.join(sysroot, 'ostree', 'deploy', 'test', 'deploy',
                         'test-deploy.0', 'var'),
        ],
                                         check=True)
Ejemplo n.º 21
0
    def test_should_deploy_commit_and_set_deployment_folder(self, run_mock):
        cfg = Config(
            Source.url('url'),
            'fedora/28/x86_64/atomic-host',
            remote='fedora-atomic',
            stateroot='atomic-host',
            root_filesystem='/dev/mapper/atomic-root',
        )

        Deploy(cfg).run()

        run_mock.assert_called_once_with([
            'ostree', 'admin', 'deploy', '--sysroot=/', '--os=atomic-host',
            'fedora-atomic:fedora/28/x86_64/atomic-host',
            '--karg=root=/dev/mapper/atomic-root'
        ],
                                         check=True)
        self.assertEqual(
            cfg.deployment_dir,
            os.path.join('/ostree', 'deploy', 'atomic-host', 'deploy',
                         'abcdef.1'))
Ejemplo n.º 22
0
    def test_should_deploy_into_specified_sysroot(self, listdir_mock,
                                                  run_mock):
        sysroot = os.path.join('/mnt', 'rootfs')
        cfg = Config(Source.url('url'),
                     'ref',
                     remote='remote',
                     stateroot='test-stateroot',
                     sysroot=sysroot,
                     root_filesystem='/dev/mapper/atomic-root')
        listdir_mock.side_effect = [[], ['deploy', 'deploy.origin']]

        Deploy(cfg).run()

        listdir_mock.assert_called_with(
            os.path.join(sysroot, 'ostree', 'deploy', 'test-stateroot',
                         'deploy'))
        run_mock.assert_called_once_with([
            'ostree', 'admin', 'deploy',
            '--sysroot=%s' % sysroot, '--os=test-stateroot', 'remote:ref',
            '--karg=root=/dev/mapper/atomic-root'
        ],
                                         check=True)
Ejemplo n.º 23
0
    def test_should_add_additional_kernel_args(self, run_mock):
        cfg = Config(
            Source.url('url'),
            'ref',
            remote='remote',
            stateroot='os',
            kernel_args=['quiet', 'splash'],
            root_filesystem='/dev/rootfs',
        )

        Deploy(cfg).run()

        run_mock.assert_called_once_with([
            'ostree',
            'admin',
            'deploy',
            '--sysroot=/',
            '--os=os',
            'remote:ref',
            '--karg=root=/dev/rootfs',
            '--karg-append=quiet',
            '--karg-append=splash',
        ],
                                         check=True)
Ejemplo n.º 24
0
    def test_repo_dir_should_include_sysroot(self):
        sysroot = os.path.join('/mnt', 'rootfs')
        cfg = Config(Source.url('url'), 'ref', sysroot=sysroot)

        self.assertEqual(cfg.ostree_repo,
                         os.path.join(sysroot, 'ostree', 'repo'))
Ejemplo n.º 25
0
    def test_deployment_path_should_raise_exception_if_name_is_not_set(self):
        cfg = Config(Source.url('url'), 'ref')

        with self.assertRaises(RuntimeError):
            cfg.deployment_dir
Ejemplo n.º 26
0
    def test_var_dir_should_be_path_to_stateroot_var(self):
        cfg = Config(Source.url('url'), 'ref', stateroot='test-stateroot')

        self.assertEqual(
            cfg.var_dir,
            os.path.join('/ostree', 'deploy', 'test-stateroot', 'var'))
Ejemplo n.º 27
0
    def test_repo_dir_should_default_to_system_ostree_repo(self):
        cfg = Config(Source.url('url'), 'ref')

        self.assertEqual(cfg.ostree_repo, os.path.join('/ostree', 'repo'))
Ejemplo n.º 28
0
    def test_stateroot_should_be_randomly_generated_if_not_specified(self):
        cfg1 = Config(Source.url('url'), 'ref')
        cfg2 = Config(Source.url('url'), 'ref')

        self.assertNotEqual(cfg1.stateroot, cfg2.stateroot)
Ejemplo n.º 29
0
def test_fstab_should_default_to_system_fstab():
    cfg = Config(Source.url('url'), 'ref')

    assert cfg.fstab == Path('/', 'etc', 'fstab')
Ejemplo n.º 30
0
    def test_default_root_filesystem_should_be_determined_by_get_root_fs(self):
        cfg = Config(Source.url('url'), 'ref')

        self.assertEqual(cfg.root_filesystem, '/dev/sda1')