Пример #1
0
def test_build_skipped_exit_code(no_flake8: bool, no_xsoar_linter: bool, no_bandit: bool, no_mypy: bool,
                                 no_pylint: bool, no_vulture: bool,
                                 no_test: bool, no_pwsh_analyze: bool, no_pwsh_test: bool, docker_engine: bool,
                                 expected_value: int):
    from demisto_sdk.commands.lint.helpers import build_skipped_exit_code
    env_var = os.environ.get('CI')
    # On you local env
    if not env_var:
        assert expected_value == build_skipped_exit_code(no_flake8, no_bandit, no_mypy, no_pylint, no_vulture,
                                                         no_xsoar_linter, no_test,
                                                         no_pwsh_analyze, no_pwsh_test, docker_engine)
    # On circle runs
    else:
        assert 0 == build_skipped_exit_code(no_flake8, no_bandit, no_mypy, no_pylint, no_vulture, no_xsoar_linter,
                                            no_test,
                                            no_pwsh_analyze, no_pwsh_test, docker_engine)
Пример #2
0
def test_build_skipped_exit_code(no_flake8: bool, no_bandit: bool, no_mypy: bool, no_pylint: bool, no_vulture: bool,
                                 no_test: bool, no_pwsh_analyze: bool, no_pwsh_test: bool, docker_engine: bool,
                                 expected_value: int):
    from demisto_sdk.commands.lint.helpers import build_skipped_exit_code

    assert expected_value == build_skipped_exit_code(no_flake8, no_bandit, no_mypy, no_pylint, no_vulture, no_test,
                                                     no_pwsh_analyze, no_pwsh_test, docker_engine)
Пример #3
0
    def run_dev_packages(self, parallel: int, no_flake8: bool, no_bandit: bool,
                         no_mypy: bool, no_pylint: bool, no_vulture: bool,
                         no_test: bool, no_pwsh_analyze: bool,
                         no_pwsh_test: bool, keep_container: bool,
                         test_xml: str, failure_report: str) -> int:
        """ Runs the Lint command on all given packages.

        Args:
            parallel(int): Whether to run command on multiple threads
            no_flake8(bool): Whether to skip flake8
            no_bandit(bool): Whether to skip bandit
            no_mypy(bool): Whether to skip mypy
            no_vulture(bool): Whether to skip vulture
            no_pylint(bool): Whether to skip pylint
            no_test(bool): Whether to skip pytest
            no_pwsh_analyze(bool): Whether to skip powershell code analyzing
            no_pwsh_test(bool): whether to skip powershell tests
            keep_container(bool): Whether to keep the test container
            test_xml(str): Path for saving pytest xml results
            failure_report(str): Path for store failed packs report

        Returns:
            int: exit code by fail exit codes by var EXIT_CODES
        """
        lint_status: Dict = {
            "fail_packs_flake8": [],
            "fail_packs_bandit": [],
            "fail_packs_mypy": [],
            "fail_packs_vulture": [],
            "fail_packs_pylint": [],
            "fail_packs_pytest": [],
            "fail_packs_pwsh_analyze": [],
            "fail_packs_pwsh_test": [],
            "fail_packs_image": [],
        }

        # Python or powershell or both
        pkgs_type = []

        # Detailed packages status
        pkgs_status = {}

        # Skiped lint and test codes
        skipped_code = build_skipped_exit_code(
            no_flake8=no_flake8,
            no_bandit=no_bandit,
            no_mypy=no_mypy,
            no_vulture=no_vulture,
            no_pylint=no_pylint,
            no_test=no_test,
            no_pwsh_analyze=no_pwsh_analyze,
            no_pwsh_test=no_pwsh_test,
            docker_engine=self._facts["docker_engine"])

        with concurrent.futures.ThreadPoolExecutor(
                max_workers=parallel) as executor:
            return_exit_code: int = 0
            results = []
            # Executing lint checks in different threads
            for pack in self._pkgs:
                linter: Linter = Linter(
                    pack_dir=pack,
                    content_repo="" if not self._facts["content_repo"] else
                    Path(self._facts["content_repo"].working_dir),
                    req_2=self._facts["requirements_2"],
                    req_3=self._facts["requirements_3"],
                    docker_engine=self._facts["docker_engine"])
                results.append(
                    executor.submit(fn=linter.run_dev_packages,
                                    no_flake8=no_flake8,
                                    no_bandit=no_bandit,
                                    no_mypy=no_mypy,
                                    no_vulture=no_vulture,
                                    no_pylint=no_pylint,
                                    no_test=no_test,
                                    no_pwsh_analyze=no_pwsh_analyze,
                                    no_pwsh_test=no_pwsh_test,
                                    modules=self._facts["test_modules"],
                                    keep_container=keep_container,
                                    test_xml=test_xml))
            try:
                for future in concurrent.futures.as_completed(results):
                    pkg_status = future.result()
                    pkgs_status[pkg_status["pkg"]] = pkg_status
                    if pkg_status["exit_code"]:
                        for check, code in EXIT_CODES.items():
                            if pkg_status["exit_code"] & code:
                                lint_status[f"fail_packs_{check}"].append(
                                    pkg_status["pkg"])
                        if not return_exit_code & pkg_status["exit_code"]:
                            return_exit_code += pkg_status["exit_code"]
                    if pkg_status["pack_type"] not in pkgs_type:
                        pkgs_type.append(pkg_status["pack_type"])
            except KeyboardInterrupt:
                print_warning("Stop demisto-sdk lint - Due to 'Ctrl C' signal")
                try:
                    executor.shutdown(wait=False)
                except Exception:
                    pass
                return 1
            except Exception as e:
                print_warning(f"Stop demisto-sdk lint - Due to Exception {e}")
                try:
                    executor.shutdown(wait=False)
                except Exception:
                    pass
                return 1

        self._report_results(lint_status=lint_status,
                             pkgs_status=pkgs_status,
                             return_exit_code=return_exit_code,
                             skipped_code=int(skipped_code),
                             pkgs_type=pkgs_type)
        self._create_failed_packs_report(lint_status=lint_status,
                                         path=failure_report)

        return return_exit_code