Beispiel #1
0
    def test_can_run_puppet_manifest_mode(self, mock_run, mock_copy_dir):
        class DummyGuest(Guest):
            name = 'dummy'

        host = Host()
        guest = DummyGuest(unittest.mock.Mock())
        mock_run.return_value = 0
        provisioner = PuppetProvisioner('./', host, [guest], {
            'manifest_file': 'test_site.pp',
            'manifests_path': 'test_manifests'
        })
        provisioner.provision()

        assert mock_copy_dir.call_count == 1
        assert mock_copy_dir.call_args_list[0][0][0] == Path('test_manifests')
        assert mock_copy_dir.call_args_list[0][0][1] == PurePosixPath(
            provisioner._guest_manifests_path)

        assert mock_run.call_count == 2
        assert mock_run.call_args_list[0][0][0] == ['which', 'puppet']
        assert mock_run.call_args_list[1][0][0] == [
            'sh', '-c',
            'puppet apply --detailed-exitcodes --manifestdir {} {}'.format(
                PurePosixPath(provisioner._guest_manifests_path),
                PurePosixPath(provisioner._guest_manifests_path) /
                'test_site.pp')
        ]
Beispiel #2
0
    def test_can_run_puppet_environment_mode(self, mock_run, mock_copy_dir):
        class DummyGuest(Guest):
            name = 'dummy'

        host = Host()
        guest = DummyGuest(unittest.mock.Mock())
        mock_run.return_value = 0
        provisioner = PuppetProvisioner(
            './', host, [guest], {
                'environment': 'test_production',
                'environment_path': 'test_environments'
            })
        provisioner.provision()

        assert mock_copy_dir.call_count == 1
        assert mock_copy_dir.call_args_list[0][0][0] == Path(
            'test_environments')
        assert mock_copy_dir.call_args_list[0][0][1] == PurePosixPath(
            provisioner._guest_environment_path)

        assert mock_run.call_count == 2
        assert mock_run.call_args_list[0][0][0] == ['which', 'puppet']
        assert mock_run.call_args_list[1][0][0] == [
            'sh', '-c', 'puppet apply --detailed-exitcodes '
            '--environmentpath {} --environment {}'.format(
                PurePosixPath(provisioner._guest_environment_path),
                'test_production')
        ]
Beispiel #3
0
    def test_can_set_module_path(self, mock_run, mock_copy_dir):
        class DummyGuest(Guest):
            name = 'dummy'

        host = Host()
        guest = DummyGuest(unittest.mock.Mock())
        mock_run.return_value = 0
        provisioner = PuppetProvisioner(
            './', host, [guest], {
                'manifest_file': 'mani.pp',
                'manifests_path': 'test_manifests',
                'module_path': 'test-puppet-modules'
            })
        provisioner.provision()

        assert mock_copy_dir.call_count == 2
        assert (Path('test-puppet-modules'),
                PurePosixPath(provisioner._guest_module_path)) in {
                    mock_copy_dir.call_args_list[0][0],
                    mock_copy_dir.call_args_list[1][0]
                }

        assert mock_run.call_count == 2
        assert mock_run.call_args_list[1][0][0] == [
            'sh', '-c',
            "puppet apply --modulepath {}:{} --detailed-exitcodes --manifestdir {} {}"
            .format(
                PurePosixPath(provisioner._guest_module_path),
                PurePosixPath(provisioner._guest_default_module_path),
                PurePosixPath(provisioner._guest_manifests_path),
                PurePosixPath(provisioner._guest_manifests_path) / 'mani.pp')
        ]
Beispiel #4
0
    def test_can_set_hiera_config_path(self, mock_run, mock_copy_dir,
                                       mock_copy_file):
        class DummyGuest(Guest):
            name = 'dummy'

        host = Host()
        guest = DummyGuest(unittest.mock.Mock())
        mock_run.return_value = 0
        provisioner = PuppetProvisioner(
            './', host, [guest], {
                'manifest_file': 'site.pp',
                'manifests_path': 'test_manifests',
                'hiera_config_path': 'hiera.yaml'
            })
        provisioner.provision()

        assert mock_copy_file.call_count == 1
        assert mock_copy_file.call_args_list[0][0][0] == Path('hiera.yaml')
        assert mock_copy_file.call_args_list[0][0][1] == PurePosixPath(
            provisioner._guest_hiera_file)

        assert mock_run.call_count == 2
        assert mock_run.call_args_list[1][0][0] == [
            'sh', '-c',
            "puppet apply --hiera_config={} --detailed-exitcodes --manifestdir {} {}"
            .format(
                PurePosixPath(provisioner._guest_hiera_file),
                PurePosixPath(provisioner._guest_manifests_path),
                PurePosixPath(provisioner._guest_manifests_path) / 'site.pp')
        ]
Beispiel #5
0
    def test_raise_error_if_puppet_is_not_found(self, mock_run,
                                                mock_copy_file):
        class DummyGuest(Guest):
            name = 'dummy'

        host = Host()
        guest = DummyGuest(unittest.mock.Mock())
        mock_run.return_value = 1  # Mock the error
        provisioner = PuppetProvisioner('./', host, [guest], {
            'manifest_file': 'test_site.pp',
            'manifests_path': 'test_manifests'
        })
        with pytest.raises(ProvisionFailed):
            provisioner.provision()
        assert mock_run.call_count == 1
        assert mock_run.call_args[0] == (['which', 'puppet'], )
        assert mock_copy_file.call_count == 0
Beispiel #6
0
    def test_can_set_options(self, mock_run, mock_copy_dir):
        class DummyGuest(Guest):
            name = 'dummy'

        host = Host()
        guest = DummyGuest(unittest.mock.Mock())
        mock_run.return_value = 0
        provisioner = PuppetProvisioner(
            './', host, [guest], {
                'manifest_file': 'site.pp',
                'manifests_path': 'test_manifests',
                'options': '--a --c="test space" --b'
            })
        provisioner.provision()
        assert mock_run.call_count == 2
        assert mock_run.call_args_list[1][0][0] == [
            'sh', '-c', """puppet apply --a '--c=test space' --b """
            """--detailed-exitcodes --manifestdir {} {}""".format(
                PurePosixPath(provisioner._guest_manifests_path),
                PurePosixPath(provisioner._guest_manifests_path) / 'site.pp')
        ]
Beispiel #7
0
    def test_can_set_environment_variables(self, mock_run, mock_copy_dir):
        class DummyGuest(Guest):
            name = 'dummy'

        host = Host()
        guest = DummyGuest(unittest.mock.Mock())
        mock_run.return_value = 0
        provisioner = PuppetProvisioner(
            './', host, [guest], {
                'manifest_file': 'site.pp',
                'manifests_path': 'test_manifests',
                'environment_variables': {
                    'FOO': 'bah',
                    'BAR': 'baz baz'
                }
            })
        provisioner.provision()
        assert mock_run.call_count == 2
        assert mock_run.call_args_list[1][0][0] == [
            'sh', '-c', "BAR='baz baz' FOO=bah "
            "puppet apply --detailed-exitcodes --manifestdir {} {}".format(
                PurePosixPath(provisioner._guest_manifests_path),
                PurePosixPath(provisioner._guest_manifests_path) / 'site.pp')
        ]