コード例 #1
0
ファイル: parsers.py プロジェクト: qubole/afctl
    def act_on_configs(cls, args, project_name):
        try:
            # Setting global values.
            if args.type == "global":
                origin = args.o
                token = args.t
                version = args.v
                if args.o is None and args.t is None and args.v is None:
                    origin = input("Git origin for deployment : ")
                    token = input("Personal access token : ")
                    version = input("Input airflow version : ")

                if origin != '' and origin is not None:
                    Utility.update_config(
                        project_name, {'global': {
                            'git': {
                                'origin': origin
                            }
                        }})

                if token != '' and token is not None:
                    Utility.update_config(
                        project_name,
                        {'global': {
                            'git': {
                                'access-token': token
                            }
                        }})

                if version != '' and version is not None:
                    Utility.update_config(
                        project_name, {'global': {
                            'airflow_version': version
                        }})

            # If adding or updating configs.
            elif args.type == 'add' or args.type == 'update':
                if args.d is None:
                    cls.parser.error(
                        colored(
                            "-d argument is required. Check usage. Run 'afctl config -h'",
                            'red'))

                # Sanitize values.
                configs, flag, msg = DeploymentConfig.validate_configs(args)
                if flag:
                    cls.parser.error(colored(msg, 'red'))
                else:
                    if args.type == 'update':
                        Utility.update_config(project_name, configs)
                    if args.type == 'add':
                        Utility.add_configs(['deployment', args.d],
                                            project_name, configs)

            # Showing configs
            elif args.type == 'show':
                Utility.print_file(Utility.project_config(project_name))

        except Exception as e:
            AfctlParserException(e)
コード例 #2
0
ファイル: test_parser_utils.py プロジェクト: qubole/afctl
    def test_add_and_update_configs(self, create_config_file):
        add_config = {'name': {'key1': 'val1', 'key2': 'val2'}}
        Utility.add_configs(['parent', 'child1'], PROJECT_NAME, add_config)
        config_file = os.path.join(PROJECT_CONFIG_DIR, PROJECT_NAME) + '.yml'

        expected_output = """parent:
    child1:
        name:
            key1: val1
            key2: val2
    child2: null
        """

        current_output = open(config_file).read()
        expected_output = expected_output.replace(" ", "")
        current_output = current_output.replace(" ", "")
        assert expected_output == current_output

        add_config = {'name': {'key3': 'val3', 'key4': 'val4'}}
        Utility.add_configs(['parent', 'child2'], PROJECT_NAME, add_config)

        expected_output = """parent:
    child1:
        name:
            key1: val1
            key2: val2
    child2: 
        name:
            key3: val3
            key4: val4
        """
        current_output = open(config_file).read()
        expected_output = expected_output.replace(" ", "")
        current_output = current_output.replace(" ", "")
        assert expected_output == current_output

        update_config = {'parent': {'child2': {'name': {'key3': 'val100'}}}}
        Utility.update_config(PROJECT_NAME, update_config)
        expected_output = """parent:
    child1:
        name:
            key1: val1
            key2: val2
    child2: 
        name:
            key3: val100
            key4: val4
        """
        current_output = open(config_file).read()
        expected_output = expected_output.replace(" ", "")
        current_output = current_output.replace(" ", "")
        assert expected_output == current_output