예제 #1
0
    def test_validate_config_when_is_valid_shell_selections(self):
        result = validate_workflow_configuration({
            'name': 'Test Flow',
            'author': 'Computational Plant Science Lab',
            'image': 'docker://alpine',
            'commands': 'echo "Hello, world!"',
            'shell': 'bash'
        })
        self.assertTrue(result[0])

        result = validate_workflow_configuration({
            'name': 'Test Flow',
            'author': 'Computational Plant Science Lab',
            'image': 'docker://alpine',
            'commands': 'echo "Hello, world!"',
            'shell': 'sh'
        })
        self.assertTrue(result[0])

        result = validate_workflow_configuration({
            'name': 'Test Flow',
            'author': 'Computational Plant Science Lab',
            'image': 'docker://alpine',
            'commands': 'echo "Hello, world!"',
            'shell': 'zsh'
        })
        self.assertTrue(result[0])
예제 #2
0
 def test_validate_config_when_is_not_valid_missing_commands(self):
     result = validate_workflow_configuration({
         'name': 'Test Flow',
         'author': 'Computational Plant Science Lab',
         'image': 'docker://alpine',
     })
     self.assertFalse(result[0])
     self.assertTrue('Missing attribute \'commands\'' in result[1])
예제 #3
0
 def test_validate_config_when_is_not_valid_commands_wrong_type(self):
     result = validate_workflow_configuration({
         'name': 'Test Flow',
         'author': 'Computational Plant Science Lab',
         'image': 'docker://alpine',
         'commands': True
     })
     self.assertFalse(result[0])
     self.assertTrue('Attribute \'commands\' must be a str' in result[1])
예제 #4
0
async def list_connectable_repos_by_org(owner: str, token: str, timeout: int = 15) -> List[dict]:
    headers = {
        "Authorization": f"token {token}",
        "Accept": "application/vnd.github.mercy-preview+json"  # so repo topics will be returned
    }
    async with httpx.AsyncClient(headers=headers, timeout=timeout) as client:
        workflows = []
        org_repos = await list_repositories(owner, token)

        # TODO refactor to send reqs in parallel
        for repository in org_repos:
            branches = await list_repo_branches(owner, repository['name'], token)
            for branch in branches:
                response = await client.get(
                    f"https://raw.githubusercontent.com/{owner}/{repository['name']}/{branch['name']}/plantit.yaml",
                    headers={
                        "Authorization": f"token {token}",
                        "Accept": "application/vnd.github.mercy-preview+json"  # so repo topics will be returned
                    })

                if response.status_code == 404:
                    logger.debug(f"No plantit.yaml in {owner}/{repository['name']}/{branch['name']}")
                    continue
                if response.status_code != 200:
                    logger.warning(f"Failed to retrieve plantit.yaml from {owner}/{repository['name']}/{branch['name']}")
                    continue
                else: logger.debug(f"Found plantit.yaml in {owner}/{repository['name']}/{branch['name']}")


                repository['organization'] = owner

                try:
                    config = yaml.safe_load(response.text)
                    valid, errors = validate_workflow_configuration(config)
                    workflows.append({
                        'repo': repository,
                        'config': config,
                        'branch': branch,
                        'validation': {
                            'is_valid': valid,
                            'errors': errors
                        },
                        'example': owner == 'Computational-Plant-Science' and 'example' in repository['name'].lower()
                    })
                except Exception:
                    workflows.append({
                        'repo': repository,
                        'config': {},
                        'branch': branch,
                        'validation': {
                            'is_valid': False,
                            'errors': [traceback.format_exc()]
                        },
                        'example': False
                    })

        return workflows
예제 #5
0
 def test_validate_config_when_is_valid_with_no_input_and_empty_output(
         self):
     result = validate_workflow_configuration({
         'name': 'Test Flow',
         'author': 'Computational Plant Science Lab',
         'image': 'docker://alpine',
         'commands': 'echo "Hello, world!"',
         'output': {}
     })
     self.assertTrue(result[0])
예제 #6
0
 def test_validate_config_when_is_not_valid_mount_empty(self):
     result = validate_workflow_configuration({
         'name': 'Test Flow',
         'author': 'Computational Plant Science Lab',
         'image': True,
         'commands': 'echo "Hello, world!"',
         'mount': [],
     })
     self.assertFalse(result[0])
     self.assertTrue('Attribute \'mount\' must not be empty' in result[1])
예제 #7
0
 def test_validate_config_when_is_not_valid_missing_name(self):
     valid, errors = validate_workflow_configuration({
         'author':
         'Computational Plant Science Lab',
         'image':
         'docker://alpine',
         'commands':
         'echo "Hello, world!"'
     })
     self.assertFalse(valid)
     self.assertTrue('Missing attribute \'name\'' in errors)
예제 #8
0
 def test_validate_config_when_is_not_valid_missing_image(self):
     result = validate_workflow_configuration({
         'name':
         'Test Flow',
         'author':
         'Computational Plant Science Lab',
         'commands':
         'echo "Hello, world!"'
     })
     self.assertFalse(result[0])
     self.assertTrue('Missing attribute \'image\'' in result[1])
예제 #9
0
 def test_validate_config_when_is_valid_with_no_input_path_and_empty_output(
         self):
     result = validate_workflow_configuration({
         'name': 'Test Flow',
         'author': 'Computational Plant Science Lab',
         'image': 'docker://alpine',
         'commands': 'cat $INPUT',
         'input': {
             'kind': 'file'
         },
         'output': {}
     })
     self.assertTrue(result[0])
예제 #10
0
 def test_validate_config_when_is_valid_and_input_kind_matches_path(self):
     result = validate_workflow_configuration({
         'name': 'Test Flow',
         'author': 'Computational Plant Science Lab',
         'image': 'docker://alpine',
         'commands': 'cat $INPUT',
         'input': {
             'path':
             '/iplant/home/shared/iplantcollaborative/testing_tools/cowsay/cowsay.txt',
             'kind': 'file'
         },
         'output': {}
     })
     self.assertTrue(result[0])
예제 #11
0
async def get_repo_bundle(owner: str, name: str, branch: str, github_token: str, cyverse_token: str) -> dict:
    tasks = [get_repo(owner, name, github_token), get_repo_config(owner, name, github_token, branch)]
    responses = await asyncio.gather(*tasks, return_exceptions=True)
    repo = responses[0]
    config = responses[1]
    valid, errors = validate_workflow_configuration(config)
    return {
        'repo': repo,
        'config': config,
        'validation': {
            'is_valid': valid,
            'errors': errors
        }
    }
예제 #12
0
 def test_validate_config_when_is_not_valid_unsupported_shell(self):
     result = validate_workflow_configuration({
         'name':
         'Test Flow',
         'author':
         'Computational Plant Science Lab',
         'image':
         'docker://alpine',
         'commands':
         'echo "Hello, world!"',
         'shell':
         'not a supported shell'
     })
     self.assertFalse(result[0])
     self.assertTrue(
         'Attribute \'shell\' must be \'sh\', \'bash\', or \'zsh\'' in
         result[1])
 def test_validate_config_when_is_valid_with_input_directory_and_nonempty_output(
         self):
     result = validate_workflow_configuration({
         'name': 'Test Flow',
         'author': 'Computational Plant Science Lab',
         'image': 'docker://alpine',
         'commands': 'ls "$INPUT" | tee output.txt',
         'input': {
             'path':
             '/iplant/home/shared/iplantcollaborative/testing_tools/cowsay',
             'kind': 'directory'
         },
         'output': {
             'path': 'outputdir'
         }
     })
     self.assertTrue(result)
 def test_validate_config_when_is_valid_with_input_file_and_empty_output(
         self):
     result = validate_workflow_configuration({
         'name': 'Test Flow',
         'author': 'Computational Plant Science Lab',
         'image': 'docker://alpine',
         'commands': 'echo "Hello, world!"',
         'input': {
             'path':
             '/iplant/home/shared/iplantcollaborative/testing_tools/cowsay/cowsay.txt',
             'kind': 'file'
         },
         'output': {
             'path': ''
         }
     })
     self.assertTrue(result)