示例#1
0
    def test_distint_imports_on_py_file(self):
        """Case: PY file can define a variable IMPORTS that can contain both TaskDeclaration and TaskAliasDeclaration
        """

        with NamedTemporaryFile() as tmp_file:
            tmp_file.write(b'''
            from rkd.syntax import TaskAliasDeclaration as Task
            
            IMPORTS = [
                TaskAliasDeclaration(':hello', [':test'])
            ]
            ''')

            with unittest.mock.patch('rkd.context.os.path.isfile',
                                     return_value=True):
                with unittest.mock.patch(
                        'rkd.context.SourceFileLoader.load_module'
                ) as src_loader_method:

                    class TestImported:
                        IMPORTS = []
                        TASKS = []

                    src_loader_method.return_value = TestImported()
                    src_loader_method.return_value.IMPORTS = [
                        TaskAliasDeclaration(':hello', [':test'])
                    ]
                    src_loader_method.return_value.TASKS = []

                    ctx_factory = ContextFactory(NullSystemIO())
                    ctx = ctx_factory._load_from_py(tmp_file.name)

                    self.assertIn(':hello', ctx._task_aliases)
示例#2
0
    def test_context_resolves_recursively_task_aliases(self):
        ctx = ApplicationContext([TaskDeclaration(InitTask())], [
            TaskAliasDeclaration(':deeper', [':init', ':init']),
            TaskAliasDeclaration(':deep', [':init', ':deeper'])
        ],
                                 directory='')

        ctx.compile()
        task = ctx.find_task_by_name(':deep')
        task: GroupDeclaration

        # :deeper = :init
        # :deep = :init :deeper = :init :init :init
        self.assertEqual(':init', task.get_declarations()[0].to_full_name())
        self.assertEqual(':init', task.get_declarations()[1].to_full_name())
        self.assertEqual(':init', task.get_declarations()[2].to_full_name())
示例#3
0
    def test_distinct_imports_separtes_lists(self):
        """A successful case for distinct_imports()"""

        imports, aliases = distinct_imports('hello', [
            TaskDeclaration(TaskForTesting()),
            TaskAliasDeclaration(':hello', [':test'])
        ])

        self.assertTrue(isinstance(imports[0], TaskDeclaration))
        self.assertTrue(isinstance(aliases[0], TaskAliasDeclaration))
示例#4
0
    def test_distinct_imports_on_yaml_file(self):
        """Case: YAML file can import a module that contains imports() method
        And that method returns list of Union[TaskDeclaration, TaskAliasDeclaration]
        """

        with NamedTemporaryFile() as tmp_file:
            tmp_file.write(b'''
            version: org.riotkit.rkd/yaml/v1
            imports:
                - fictional
            ''')

            with unittest.mock.patch(
                    'rkd.context.YamlSyntaxInterpreter.parse') as parse_method:
                parse_method.return_value = ([
                    TaskAliasDeclaration(':hello', [':test'])
                ], [])

                ctx_factory = ContextFactory(NullSystemIO())
                ctx = ctx_factory._load_from_yaml(
                    os.path.dirname(tmp_file.name),
                    os.path.basename(tmp_file.name))

                self.assertIn(':hello', ctx._task_aliases)
示例#5
0
def imports():
    return [
        TaskDeclaration(ListContainersTask()),
        TaskDeclaration(StartTask()),
        TaskDeclaration(UpgradeTask()),
        TaskDeclaration(StopTask()),
        TaskDeclaration(StopAndRemoveTask()),
        TaskDeclaration(ListDefinedServices()),
        TaskDeclaration(ServiceUpTask()),
        TaskDeclaration(ServiceStopTask()),
        TaskDeclaration(WaitForServiceTask()),
        TaskDeclaration(ServiceRemoveTask()),
        TaskDeclaration(GetContainerNameTask()),
        TaskDeclaration(ExecTask()),
        TaskDeclaration(LogsTask()),
        TaskDeclaration(AnalyzeServiceTask()),
        TaskDeclaration(InspectContainerTask()),
        TaskDeclaration(PullTask()),
        TaskDeclaration(RestartTask()),
        TaskDeclaration(ListConfigsTask()),
        TaskDeclaration(EnableConfigTask()),
        TaskDeclaration(DisableConfigTask()),
        TaskDeclaration(DumpComposeArguments()),
        TaskDeclaration(DumpComposeConfigTask()),

        # production-related
        TaskDeclaration(ReloadGatewayTask()),
        TaskDeclaration(ShowSSLStatusTask()),
        TaskDeclaration(ForceReloadSSLTask()),
        TaskDeclaration(MaintenanceOnTask()),
        TaskDeclaration(MaintenanceOffTask()),
        TaskDeclaration(DeploymentTask()),
        TaskDeclaration(SSHTask()),
        TaskDeclaration(UpdateFilesTask()),
        TaskDeclaration(CreateExampleDeploymentFileTask()),
        TaskDeclaration(ManageVagrantTask()),
        TaskDeclaration(EditVaultTask()),
        TaskDeclaration(EncryptVaultTask()),
        TaskDeclaration(EnvEncryptTask()),

        # git
        TaskDeclaration(FetchRepositoryTask()),
        TaskDeclaration(FetchAllRepositories()),
        TaskDeclaration(SetPermissionsForWritableDirectoriesTask()),
        TaskDeclaration(ListRepositoriesTask()),
        TaskDeclaration(CooperativeSyncTask()),
        TaskDeclaration(CooperativeInstallTask()),
        TaskDeclaration(CreateHarborStructureTask()),
        TaskDeclaration(CooperativeSnippetWizardTask()),
        TaskDeclaration(CooperativeSnippetInstallTask()),
        TaskDeclaration(GetEnvTask()),
        TaskDeclaration(SetEnvTask()),
        TaskDeclaration(FileRendererTask()),
        TaskDeclaration(RenderDirectoryTask()),

        # templates
        TaskAliasDeclaration(
            ':harbor:templates:render', [
                ':j2:directory-to-directory', '--source=templates',
                '--target=./'
            ],
            description='Render templates stored in containers/templates ' +
            'into root directory, with preserving the tree structure')
    ]