test/api: Refactor checkout_cas_version()
Signed-off-by: Rafal Stefanowski <rafal.stefanowski@intel.com>
This commit is contained in:
parent
07e913a05f
commit
9f66143b70
@ -1,5 +1,5 @@
|
|||||||
#
|
#
|
||||||
# Copyright(c) 2019-2021 Intel Corporation
|
# Copyright(c) 2019-2022 Intel Corporation
|
||||||
# SPDX-License-Identifier: BSD-3-Clause
|
# SPDX-License-Identifier: BSD-3-Clause
|
||||||
#
|
#
|
||||||
|
|
||||||
@ -7,6 +7,7 @@ import os
|
|||||||
|
|
||||||
from core.test_run import TestRun
|
from core.test_run import TestRun
|
||||||
from connection.local_executor import LocalExecutor
|
from connection.local_executor import LocalExecutor
|
||||||
|
from test_utils.output import CmdException
|
||||||
|
|
||||||
|
|
||||||
def get_current_commit_hash(from_dut: bool = False):
|
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
|
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():
|
def get_release_tags():
|
||||||
repo_path = os.path.join(TestRun.usr.working_dir, ".git")
|
repo_path = os.path.join(TestRun.usr.working_dir, ".git")
|
||||||
output = TestRun.executor.run_expect_success(f"git --git-dir={repo_path} tag").stdout
|
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):
|
def checkout_cas_version(cas_version):
|
||||||
from api.cas.version import CasVersion
|
commit_hash = get_commit_hash(cas_version)
|
||||||
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):
|
|
||||||
TestRun.LOGGER.info(f"Checkout CAS to {commit_hash}")
|
TestRun.LOGGER.info(f"Checkout CAS to {commit_hash}")
|
||||||
|
|
||||||
output = TestRun.executor.run(
|
output = TestRun.executor.run(
|
||||||
f"cd {TestRun.usr.working_dir} && "
|
f"cd {TestRun.usr.working_dir} && "
|
||||||
f"git checkout --force {commit_hash}")
|
f"git checkout --force {commit_hash}")
|
||||||
if output.exit_code != 0:
|
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(
|
output = TestRun.executor.run(
|
||||||
f"cd {TestRun.usr.working_dir} && "
|
f"cd {TestRun.usr.working_dir} && "
|
||||||
f"git submodule update")
|
f"git submodule update --force")
|
||||||
if output.exit_code != 0:
|
if output.exit_code != 0:
|
||||||
raise CmdException(f"Failed to update submodules", output)
|
raise CmdException(f"Failed to update submodules", output)
|
||||||
|
Loading…
Reference in New Issue
Block a user