From 9f66143b7024f3be37764f918ec39af261bde94a Mon Sep 17 00:00:00 2001 From: Rafal Stefanowski Date: Tue, 16 Aug 2022 15:29:14 +0200 Subject: [PATCH] test/api: Refactor checkout_cas_version() Signed-off-by: Rafal Stefanowski --- test/functional/api/cas/git.py | 38 +++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/test/functional/api/cas/git.py b/test/functional/api/cas/git.py index f6af519..0a69dd3 100644 --- a/test/functional/api/cas/git.py +++ b/test/functional/api/cas/git.py @@ -1,5 +1,5 @@ # -# Copyright(c) 2019-2021 Intel Corporation +# Copyright(c) 2019-2022 Intel Corporation # SPDX-License-Identifier: BSD-3-Clause # @@ -7,6 +7,7 @@ import os from core.test_run import TestRun from connection.local_executor import LocalExecutor +from test_utils.output import CmdException def get_current_commit_hash(from_dut: bool = False): @@ -25,6 +26,21 @@ def get_current_commit_message(): f'git show HEAD -s --pretty=format:"%B"').stdout +def get_commit_hash(cas_version, from_dut: bool = False): + executor = TestRun.executor if from_dut else LocalExecutor() + repo_path = TestRun.usr.working_dir if from_dut else TestRun.usr.repo_dir + + output = executor.run( + f"cd {repo_path} && " + f"git rev-parse {cas_version}") + if output.exit_code != 0: + raise CmdException(f"Failed to resolve '{cas_version}' to commit hash", output) + + TestRun.LOGGER.info(f"Resolved '{cas_version}' as commit {output.stdout}") + + return output.stdout + + def get_release_tags(): repo_path = os.path.join(TestRun.usr.working_dir, ".git") output = TestRun.executor.run_expect_success(f"git --git-dir={repo_path} tag").stdout @@ -36,29 +52,17 @@ def get_release_tags(): def checkout_cas_version(cas_version): - from api.cas.version import CasVersion - if isinstance(cas_version, CasVersion): - output = TestRun.executor.run( - f"cd {TestRun.usr.working_dir} && " - f"git rev-parse {cas_version}") - if output.exit_code != 0: - raise CmdException(f"Failed to resolve {cas_version} tag to commit hash", output) - TestRun.LOGGER.info(f"Resolved {cas_version} as commit {output.stdout}") - cas_version = output.stdout - - _checkout_cas_commit(cas_version) - - -def _checkout_cas_commit(commit_hash): + commit_hash = get_commit_hash(cas_version) TestRun.LOGGER.info(f"Checkout CAS to {commit_hash}") + output = TestRun.executor.run( f"cd {TestRun.usr.working_dir} && " f"git checkout --force {commit_hash}") if output.exit_code != 0: - raise CmdException(f"Failed to checkout to CAS {commit_hash}", output) + raise CmdException(f"Failed to checkout to {commit_hash}", output) output = TestRun.executor.run( f"cd {TestRun.usr.working_dir} && " - f"git submodule update") + f"git submodule update --force") if output.exit_code != 0: raise CmdException(f"Failed to update submodules", output)