def test_global_defaults(self):
        tssc_config = Config({
            Config.TSSC_CONFIG_KEY: {
                'global-defaults': {
                    'test1': 'global-default-1',
                    'test2': 'global-default-2'
                },
                'step-foo': [{
                    'implementer': 'foo1',
                    'config': {
                        'test1': 'foo'
                    }
                }]
            }
        })

        step_config = tssc_config.get_step_config('step-foo')
        sub_step = step_config.get_sub_step('foo1')

        self.assertEqual(
            sub_step.global_defaults, {
                'test1':
                ConfigValue('global-default-1', None,
                            ["tssc-config", "global-defaults", "test1"]),
                'test2':
                ConfigValue('global-default-2', None,
                            ["tssc-config", "global-defaults", "test2"])
            })
    def test_convert_leaves_to_values_mixed_leaves(self):
        source_values = {
            Config.TSSC_CONFIG_KEY: {
                'step-foo': [{
                    'implementer': ConfigValue('foo1', None, None),
                    'config': {
                        'test1': ConfigValue('foo', None, None),
                        'test': 'not a tssc config value object'
                    }
                }]
            }
        }

        converted = ConfigValue.convert_leaves_to_values(source_values)

        self.assertEqual(
            converted, {
                Config.TSSC_CONFIG_KEY: {
                    'step-foo': [{
                        'implementer': 'foo1',
                        'config': {
                            'test1': 'foo',
                            'test': 'not a tssc config value object'
                        }
                    }]
                }
            })
    def test_convert_leaves_to_config_values_0(self):
        source = {
            Config.TSSC_CONFIG_KEY: {
                'step-foo': [{
                    'implementer': 'foo1',
                    'config': {
                        'test1': 'foo'
                    }
                }]
            }
        }

        ConfigValue.convert_leaves_to_config_values(
            values=source[Config.TSSC_CONFIG_KEY],
            parent_source=source,
            path_parts=[Config.TSSC_CONFIG_KEY])

        expected = {
            Config.TSSC_CONFIG_KEY: {
                'step-foo': [{
                    'implementer': ConfigValue('foo1', None, None),
                    'config': {
                        'test1': ConfigValue('foo', None, None)
                    }
                }]
            }
        }

        self.assertEqual(source, expected)
Ejemplo n.º 4
0
    def test_list_of_config_value(self, container_registry_login_mock):
        registries = [
            ConfigValue({
                'uri': 'registry.redhat.io',
                'username': '******',
                'password': '******'
            }),
            ConfigValue({
                'uri': 'registry.internal.example.xyz',
                'username': '******',
                'password': '******'
            })
        ]

        container_registries_login(registries)

        calls = [
            call(container_registry_uri='registry.redhat.io',
                 container_registry_username='******',
                 container_registry_password='******',
                 container_registry_tls_verify=True,
                 containers_config_auth_file=None),
            call(container_registry_uri='registry.internal.example.xyz',
                 container_registry_username='******',
                 container_registry_password='******',
                 container_registry_tls_verify=True,
                 containers_config_auth_file=None)
        ]
        container_registry_login_mock.assert_has_calls(calls)
    def test_convert_leaves_to_values_all_config_value_leaves(self):
        source_values = {
            Config.TSSC_CONFIG_KEY: {
                'step-foo': [{
                    'implementer': ConfigValue('foo1', None, None),
                    'config': {
                        'test1': ConfigValue('foo', None, None)
                    }
                }]
            }
        }

        converted = ConfigValue.convert_leaves_to_values(source_values)

        self.assertEqual(
            converted, {
                Config.TSSC_CONFIG_KEY: {
                    'step-foo': [{
                        'implementer': 'foo1',
                        'config': {
                            'test1': 'foo',
                        }
                    }]
                }
            })
Ejemplo n.º 6
0
 def _generate_maven_settings(self):
     # ----- build settings.xml
     maven_servers = ConfigValue.convert_leaves_to_values(
         self.get_config_value('maven-servers'))
     maven_repositories = ConfigValue.convert_leaves_to_values(
         self.get_config_value('maven-repositories'))
     maven_mirrors = ConfigValue.convert_leaves_to_values(
         self.get_config_value('maven-mirrors'))
     return generate_maven_settings(self.get_working_dir(), maven_servers,
                                    maven_repositories, maven_mirrors)
    def test_value_decyrpt(self, sops_mock):
        encrypted_config_file_path = os.path.join(
            os.path.dirname(__file__), 'decryptors', 'files',
            'tssc-config-secret-stuff.yml')

        config_value = ConfigValue(
            value=
            'ENC[AES256_GCM,data:UGKfnzsSrciR7GXZJhOCMmFrz3Y6V3pZsd3P,iv:yuReqA+n+rRXVHMc+2US5t7yPx54sooZSXWV4KLjDIs=,tag:jueP7/ZWLfYrEuhh+4eS8g==,type:str]',
            parent_source=encrypted_config_file_path,
            path_parts=[
                'tssc-config', 'global-environment-defaults', 'DEV',
                'kube-api-token'
            ])

        DecryptionUtils.register_config_value_decryptor(SOPS())

        sops_mock.side_effect = create_sops_side_effect('mock decrypted value')
        decrypted_value = config_value.value
        sops_mock.assert_called_once_with(
            '--decrypt',
            '--extract=["tssc-config"]["global-environment-defaults"]["DEV"]["kube-api-token"]',
            None,
            encrypted_config_file_path,
            _in=None,
            _out=Any(StringIO),
            _err=Any(StringIO))
        self.assertEqual(decrypted_value, 'mock decrypted value')
    def test_value_path_given_no_inital_value_path_parts(self):
        source = {
            Config.TSSC_CONFIG_KEY: {
                'step-foo': [{
                    'implementer': 'foo1',
                    'config': {
                        'test1': 'foo'
                    }
                }]
            }
        }

        ConfigValue.convert_leaves_to_config_values(values=source,
                                                    parent_source=source)

        self.assertEqual(
            source[Config.TSSC_CONFIG_KEY]['step-foo'][0]['config']
            ['test1'].path_parts,
            ['tssc-config', 'step-foo', 0, 'config', 'test1'])
    def test_global_environment_defaults(self):
        tssc_config = Config({
            Config.TSSC_CONFIG_KEY: {
                'global-environment-defaults': {
                    'env1': {
                        'test1': 'global-env1-default-1',
                        'test2': 'global-env1-default-2'
                    },
                    'env2': {
                        'test1': 'global-env2-default-1',
                        'test2': 'global-env2-default-2'
                    }
                },
                'step-foo': [{
                    'implementer': 'foo1',
                    'config': {
                        'test1': 'foo'
                    }
                }]
            }
        })

        step_config = tssc_config.get_step_config('step-foo')
        sub_step = step_config.get_sub_step('foo1')

        self.assertEqual(
            ConfigValue.convert_leaves_to_values(
                sub_step.get_global_environment_defaults('env1')), {
                    'environment-name': 'env1',
                    'test1': 'global-env1-default-1',
                    'test2': 'global-env1-default-2'
                })
        self.assertEqual(
            ConfigValue.convert_leaves_to_values(
                sub_step.get_global_environment_defaults('env2')), {
                    'environment-name': 'env2',
                    'test1': 'global-env2-default-1',
                    'test2': 'global-env2-default-2'
                })
    def test__repr__(self):
        source = {
            Config.TSSC_CONFIG_KEY: {
                'step-foo': [{
                    'implementer': 'foo1',
                    'config': {
                        'test1': 'foo'
                    }
                }]
            }
        }

        ConfigValue.convert_leaves_to_config_values(
            values=source[Config.TSSC_CONFIG_KEY],
            parent_source=source,
            path_parts=[Config.TSSC_CONFIG_KEY])

        self.assertEqual(
            str(source[Config.TSSC_CONFIG_KEY]['step-foo'][0]['config']
                ['test1']),
            "ConfigValue(value=foo, value_path='['tssc-config', 'step-foo', 0, 'config', 'test1']')"
        )
Ejemplo n.º 11
0
    def test_configvalue_params(self, which_mock, container_command_mock):
        which_mock.side_effect = create_which_side_effect(
            cmd='buildah', cmd_path='/mock/buildah')

        container_registry_login(
            container_registry_uri=ConfigValue('registry.example.xyz'),
            container_registry_username=ConfigValue('example'),
            container_registry_password=ConfigValue('nope'),
            container_registry_tls_verify=ConfigValue(True),
            containers_config_auth_file=ConfigValue('/tmp/test/auth.json'))

        container_command_mock.bake.assert_called_once()
        container_command_mock.bake().login.bake.assert_called_once_with(
            password_stdin=True,
            username='******',
            tls_verify='true',
            authfile='/tmp/test/auth.json')
        container_command_mock.bake().login.bake().assert_called_once_with(
            'registry.example.xyz',
            _in='nope',
            _out=Any(IOBase),
            _err=Any(IOBase),
            _tee='err')
Ejemplo n.º 12
0
    def _update_values_yaml(self, repo_directory,
                            values_file_repo_relative_path):  # pylint: disable=too-many-locals
        env = Environment(loader=FileSystemLoader(
            self.get_config_value('values-yaml-directory')),
                          trim_blocks=True,
                          lstrip_blocks=True)

        argocd_app_name = self._get_app_name()
        version = self._get_image_version()
        container_image_uri = self.__get_container_image_uri()
        timestamp = str(datetime.now())
        repo_branch = self._get_repo_branch()
        endpoint_url = self._get_endpoint_url()
        jinja_runtime_step_config = {
            'container_image_uri': container_image_uri,
            'image_version': version,
            'timestamp': timestamp,
            'repo_branch': repo_branch,
            'deployment_namespace': argocd_app_name,
            'endpoint_url': endpoint_url
        }

        copy_of_runtime_step_config = ConfigValue.convert_leaves_to_values(
            self.get_copy_of_runtime_step_config())
        for key in copy_of_runtime_step_config:
            jinja_runtime_step_config[key.replace(
                '-', '_')] = copy_of_runtime_step_config[key]

        template = env.get_template(
            self.get_config_value('values-yaml-template'))

        rendered_values_file = self.write_working_file(
            'values.yml',
            bytes(template.render(jinja_runtime_step_config), 'utf-8'))

        try:
            shutil.copyfile(
                rendered_values_file,
                os.path.join(repo_directory, values_file_repo_relative_path))
        except (shutil.SameFileError, OSError, IOError) as error:
            raise RuntimeError(
                "Error copying {values_file} file: {all}".format(
                    values_file=values_file_repo_relative_path,
                    all=error)) from error
Ejemplo n.º 13
0
    def test_add_or_update_sub_step_config_exising_sub_step(self):
        tssc_config = Config([
            {
                Config.TSSC_CONFIG_KEY: {
                    'step-foo': [
                        {
                            'implementer': 'foo1',
                            'config': {
                                'test1': 'foo'
                            }
                        }
                    ]

                }
            },
            {
                Config.TSSC_CONFIG_KEY: {
                    'step-foo': [
                        {
                            'implementer': 'foo1',
                            'config': {
                                'test2': 'foo'
                            }
                        }
                    ]

                }
            },
        ])

        step_config = tssc_config.get_step_config('step-foo')
        self.assertEqual(len(step_config.sub_steps), 1)

        self.assertEqual(
            ConfigValue.convert_leaves_to_values(
                step_config.get_sub_step('foo1').sub_step_config
            ),
            {
                'test1': 'foo',
                'test2': 'foo'
            }
        )
    def test_get_sub_step_env_config(self):
        tssc_config = Config({
            Config.TSSC_CONFIG_KEY: {
                'step-foo': [{
                    'implementer': 'foo1',
                    'config': {
                        'test1': 'foo'
                    },
                    'environment-config': {
                        'env1': {
                            'test2': 'bar'
                        }
                    }
                }]
            }
        })

        step_config = tssc_config.get_step_config('step-foo')
        sub_step = step_config.get_sub_step('foo1')

        self.assertEqual(
            ConfigValue.convert_leaves_to_values(
                sub_step.get_sub_step_env_config('env1')), {'test2': 'bar'})
    def test_get_copy_of_runtime_step_config_default_global_defaults_global_env_defaults_sub_step_config_sub_step_env_config_step_config_overrides(
            self):
        tssc_config = Config({
            Config.TSSC_CONFIG_KEY: {
                'global-defaults': {
                    'global-default-unique-0': 'global-default',
                    'global-default-override-by-global-env-default-0':
                    'global-default-override-me',
                    'global-default-override-by-step-config-0':
                    'global-default-override-me',
                    'global-default-override-by-step-env-config-0':
                    'global-default-override-me',
                    'global-default-override-by-step-config-override-0':
                    'global-default-override-me',
                    'default-overriden-by-global-default': 'global-default',
                },
                'global-environment-defaults': {
                    'env1': {
                        'global-default-override-by-global-env-default-0':
                        'global-environment-defaults-1',
                        'global-env-default-env1-unique-0':
                        'global-environment-defaults-1',
                        'global-env-default-override-by-step-config':
                        'global-environment-defaults-1',
                        'default-overriden-by-global-env-default':
                        'global-environment-defaults-1'
                    },
                    'env2': {
                        'global-default-override-by-global-env-default-0':
                        'global-environment-defaults-2',
                        'global-env-default-env2-unique-0':
                        'global-environment-defaults-2',
                        'global-env-default-override-by-step-config':
                        'global-environment-defaults-2',
                        'default-overriden-by-global-env-default':
                        'global-environment-defaults-2'
                    }
                },
                'step-foo': [{
                    'implementer': 'foo1',
                    'config': {
                        'step-foo-foo1-unique-0': 'step-foo-foo1',
                        'step-foo-foo1-override-by-step-env-config':
                        'step-foo-foo-override-me',
                        'step-foo-foo1-override-by-step-override':
                        'step-foo-foo-override-me',
                        'global-default-override-by-step-config-0':
                        'step-foo-foo1',
                        'global-env-default-override-by-step-config':
                        'step-foo-foo1',
                        'default-overriden-by-step-config': 'step-foo-foo1'
                    },
                    'environment-config': {
                        'env1': {
                            'step-foo-foo1-override-by-step-env-config':
                            'step-foo-foo-env1',
                            'global-default-override-by-step-env-config-0':
                            'step-foo-foo-env1',
                            'step-foo-foo1-env1-unique-0':
                            'step-foo-foo-env1',
                            'step-foo-foo1-env-specific':
                            'step-foo-foo-env1',
                            'default-overriden-by-step-env-config':
                            'step-foo-foo-env1',
                        },
                        'env2': {
                            'step-foo-foo1-override-by-step-env-config':
                            'step-foo-foo-env2',
                            'global-default-override-by-step-env-config-0':
                            'step-foo-foo-env2',
                            'step-foo-foo1-env2-unique-0':
                            'step-foo-foo-env2',
                            'step-foo-foo1-env-specific':
                            'step-foo-foo-env2',
                            'default-overriden-by-step-env-config':
                            'step-foo-foo-env2',
                        }
                    }
                }]
            }
        })

        tssc_config.set_step_config_overrides(
            'step-foo', {
                'global-default-override-by-step-config-override-0':
                'step-foo-step-config-override',
                'step-foo-foo1-override-by-step-override':
                'step-foo-step-config-override',
                'step-config-override-unique-0':
                'step-config-override-unique',
                'default-overriden-by-step-config-overrides':
                'step-foo-step-config-override'
            })

        step_config = tssc_config.get_step_config('step-foo')
        sub_step = step_config.get_sub_step('foo1')

        defaults = {
            'default-unique': 'not-overriden-default',
            'default-overriden-by-global-default': 'override-me',
            'default-overriden-by-global-env-default': 'override-me',
            'default-overriden-by-step-config': 'override-me',
            'default-overriden-by-step-env-config': 'override-me',
            'default-overriden-by-step-config-overrides': 'override-me'
        }

        runtime_step_config_no_given_env = sub_step.get_copy_of_runtime_step_config(
            None, defaults)
        self.assertEqual(
            ConfigValue.convert_leaves_to_values(
                runtime_step_config_no_given_env), {
                    'global-default-unique-0':
                    'global-default',
                    'global-default-override-by-global-env-default-0':
                    'global-default-override-me',
                    'global-default-override-by-step-config-0':
                    'step-foo-foo1',
                    'global-default-override-by-step-env-config-0':
                    'global-default-override-me',
                    'step-foo-foo1-unique-0':
                    'step-foo-foo1',
                    'step-foo-foo1-override-by-step-env-config':
                    'step-foo-foo-override-me',
                    'global-default-override-by-step-config-override-0':
                    'step-foo-step-config-override',
                    'step-foo-foo1-override-by-step-override':
                    'step-foo-step-config-override',
                    'step-config-override-unique-0':
                    'step-config-override-unique',
                    'global-env-default-override-by-step-config':
                    'step-foo-foo1',
                    'default-unique':
                    'not-overriden-default',
                    'default-overriden-by-global-default':
                    'global-default',
                    'default-overriden-by-global-env-default':
                    'override-me',
                    'default-overriden-by-step-config':
                    'step-foo-foo1',
                    'default-overriden-by-step-env-config':
                    'override-me',
                    'default-overriden-by-step-config-overrides':
                    'step-foo-step-config-override'
                })

        runtime_step_config_env1 = sub_step.get_copy_of_runtime_step_config(
            'env1', defaults)
        self.assertEqual(
            ConfigValue.convert_leaves_to_values(runtime_step_config_env1), {
                'environment-name':
                'env1',
                'global-default-unique-0':
                'global-default',
                'global-default-override-by-global-env-default-0':
                'global-environment-defaults-1',
                'global-default-override-by-step-config-0':
                'step-foo-foo1',
                'global-default-override-by-step-env-config-0':
                'step-foo-foo-env1',
                'step-foo-foo1-unique-0':
                'step-foo-foo1',
                'step-foo-foo1-override-by-step-env-config':
                'step-foo-foo-env1',
                'global-default-override-by-step-config-override-0':
                'step-foo-step-config-override',
                'step-foo-foo1-override-by-step-override':
                'step-foo-step-config-override',
                'step-config-override-unique-0':
                'step-config-override-unique',
                'global-env-default-override-by-step-config':
                'step-foo-foo1',
                'global-env-default-env1-unique-0':
                'global-environment-defaults-1',
                'step-foo-foo1-env1-unique-0':
                'step-foo-foo-env1',
                'step-foo-foo1-env-specific':
                'step-foo-foo-env1',
                'default-unique':
                'not-overriden-default',
                'default-overriden-by-global-default':
                'global-default',
                'default-overriden-by-global-env-default':
                'global-environment-defaults-1',
                'default-overriden-by-step-config':
                'step-foo-foo1',
                'default-overriden-by-step-env-config':
                'step-foo-foo-env1',
                'default-overriden-by-step-config-overrides':
                'step-foo-step-config-override'
            })

        runtime_step_config_env2 = sub_step.get_copy_of_runtime_step_config(
            'env2', defaults)
        self.assertEqual(
            ConfigValue.convert_leaves_to_values(runtime_step_config_env2), {
                'environment-name':
                'env2',
                'global-default-unique-0':
                'global-default',
                'global-default-override-by-global-env-default-0':
                'global-environment-defaults-2',
                'global-default-override-by-step-config-0':
                'step-foo-foo1',
                'global-default-override-by-step-env-config-0':
                'step-foo-foo-env2',
                'step-foo-foo1-unique-0':
                'step-foo-foo1',
                'step-foo-foo1-override-by-step-env-config':
                'step-foo-foo-env2',
                'global-default-override-by-step-config-override-0':
                'step-foo-step-config-override',
                'step-foo-foo1-override-by-step-override':
                'step-foo-step-config-override',
                'step-config-override-unique-0':
                'step-config-override-unique',
                'global-env-default-override-by-step-config':
                'step-foo-foo1',
                'global-env-default-env2-unique-0':
                'global-environment-defaults-2',
                'step-foo-foo1-env2-unique-0':
                'step-foo-foo-env2',
                'step-foo-foo1-env-specific':
                'step-foo-foo-env2',
                'default-unique':
                'not-overriden-default',
                'default-overriden-by-global-default':
                'global-default',
                'default-overriden-by-global-env-default':
                'global-environment-defaults-2',
                'default-overriden-by-step-config':
                'step-foo-foo1',
                'default-overriden-by-step-env-config':
                'step-foo-foo-env2',
                'default-overriden-by-step-config-overrides':
                'step-foo-step-config-override'
            })
    def test__eq__is_not_equal_different_objects(self):
        test1 = ConfigValue('foo1', None, None)
        test2 = "foo1"

        self.assertNotEqual(test1, test2)
    def test__eq__is_not_equal_both_tssc_config_value_objects(self):
        test1 = ConfigValue('foo1', None, None)
        test2 = ConfigValue('foo2', None, None)

        self.assertNotEqual(test1, test2)
    def test__eq__is_equal_diff_source_and_path_parts(self):
        test1 = ConfigValue('foo1', "does not matter for equality", ['a', 'b'])
        test2 = ConfigValue('foo1', "really does not matter for equality",
                            ['1', '2'])

        self.assertEqual(test1, test2)
    def test__eq__is_equal_diff_path_parts(self):
        test1 = ConfigValue('foo1', None, ['a', 'b'])
        test2 = ConfigValue('foo1', None, ['1', '2'])

        self.assertEqual(test1, test2)
    def test__eq__is_equal_basic(self):
        test1 = ConfigValue('foo1', None, None)
        test2 = ConfigValue('foo1', None, None)

        self.assertEqual(test1, test2)
    def test__eq__is_equal_diff_source(self):
        test1 = ConfigValue('foo1', "does not matter for equality", None)
        test2 = ConfigValue('foo1', "really does not matter for equality",
                            None)

        self.assertEqual(test1, test2)