Make opencas plugin as singleton class
This commit is contained in:
parent
5d643a48d8
commit
eedb4ded7c
@ -10,12 +10,12 @@ from connection.local_executor import LocalExecutor
|
|||||||
def get_current_commit_hash():
|
def get_current_commit_hash():
|
||||||
local_executor = LocalExecutor()
|
local_executor = LocalExecutor()
|
||||||
return local_executor.run(
|
return local_executor.run(
|
||||||
f"cd {TestRun.plugins['opencas']['repo_dir']} &&"
|
f"cd {TestRun.plugins['opencas'].repo_dir} &&"
|
||||||
f'git show HEAD -s --pretty=format:"%H"').stdout
|
f'git show HEAD -s --pretty=format:"%H"').stdout
|
||||||
|
|
||||||
|
|
||||||
def get_current_commit_message():
|
def get_current_commit_message():
|
||||||
local_executor = LocalExecutor()
|
local_executor = LocalExecutor()
|
||||||
return local_executor.run(
|
return local_executor.run(
|
||||||
f"cd {TestRun.plugins['opencas']['repo_dir']} &&"
|
f"cd {TestRun.plugins['opencas'].repo_dir} &&"
|
||||||
f'git show HEAD -s --pretty=format:"%B"').stdout
|
f'git show HEAD -s --pretty=format:"%B"').stdout
|
||||||
|
@ -13,13 +13,13 @@ from core.test_run import TestRun
|
|||||||
def install_opencas():
|
def install_opencas():
|
||||||
TestRun.LOGGER.info("Copying Open CAS repository to DUT")
|
TestRun.LOGGER.info("Copying Open CAS repository to DUT")
|
||||||
TestRun.executor.rsync(
|
TestRun.executor.rsync(
|
||||||
f"{TestRun.plugins['opencas']['repo_dir']}/",
|
f"{TestRun.plugins['opencas'].repo_dir}/",
|
||||||
f"{TestRun.plugins['opencas']['working_dir']}/",
|
f"{TestRun.plugins['opencas'].working_dir}/",
|
||||||
delete=True)
|
delete=True)
|
||||||
|
|
||||||
TestRun.LOGGER.info("Building Open CAS")
|
TestRun.LOGGER.info("Building Open CAS")
|
||||||
output = TestRun.executor.run(
|
output = TestRun.executor.run(
|
||||||
f"cd {TestRun.plugins['opencas']['working_dir']} && "
|
f"cd {TestRun.plugins['opencas'].working_dir} && "
|
||||||
"./configure && "
|
"./configure && "
|
||||||
"make -j")
|
"make -j")
|
||||||
if output.exit_code != 0:
|
if output.exit_code != 0:
|
||||||
@ -28,7 +28,7 @@ def install_opencas():
|
|||||||
|
|
||||||
TestRun.LOGGER.info("Installing Open CAS")
|
TestRun.LOGGER.info("Installing Open CAS")
|
||||||
output = TestRun.executor.run(
|
output = TestRun.executor.run(
|
||||||
f"cd {TestRun.plugins['opencas']['working_dir']} && "
|
f"cd {TestRun.plugins['opencas'].working_dir} && "
|
||||||
f"make install")
|
f"make install")
|
||||||
if output.exit_code != 0:
|
if output.exit_code != 0:
|
||||||
TestRun.exception(
|
TestRun.exception(
|
||||||
@ -50,7 +50,7 @@ def uninstall_opencas():
|
|||||||
TestRun.exception("Open CAS is not properly installed")
|
TestRun.exception("Open CAS is not properly installed")
|
||||||
else:
|
else:
|
||||||
TestRun.executor.run(
|
TestRun.executor.run(
|
||||||
f"cd {TestRun.plugins['opencas']['working_dir']} && "
|
f"cd {TestRun.plugins['opencas'].working_dir} && "
|
||||||
f"make uninstall")
|
f"make uninstall")
|
||||||
if output.exit_code != 0:
|
if output.exit_code != 0:
|
||||||
TestRun.exception(
|
TestRun.exception(
|
||||||
|
@ -1 +1 @@
|
|||||||
Subproject commit b0081604becc2b9ae23e0de5c29427c59966d68d
|
Subproject commit b3f62cb3d65ea42c05f297340ca5a1e9ef70fab0
|
@ -18,6 +18,7 @@ from api.cas import casadm
|
|||||||
from api.cas import git
|
from api.cas import git
|
||||||
from test_utils.os_utils import Udev
|
from test_utils.os_utils import Udev
|
||||||
from log.logger import create_log, Log
|
from log.logger import create_log, Log
|
||||||
|
from test_utils.singleton import Singleton
|
||||||
|
|
||||||
plugins_dir = os.path.join(os.path.dirname(__file__), "../plugins")
|
plugins_dir = os.path.join(os.path.dirname(__file__), "../plugins")
|
||||||
sys.path.append(plugins_dir)
|
sys.path.append(plugins_dir)
|
||||||
@ -27,6 +28,13 @@ except ImportError:
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class OpencasPlugin(metaclass=Singleton):
|
||||||
|
def __init__(self, repo_dir, working_dir):
|
||||||
|
self.repo_dir = repo_dir
|
||||||
|
self.working_dir = working_dir
|
||||||
|
self.already_updated = False
|
||||||
|
|
||||||
|
|
||||||
def pytest_runtest_setup(item):
|
def pytest_runtest_setup(item):
|
||||||
# There should be dut config file added to config package and
|
# There should be dut config file added to config package and
|
||||||
# pytest should be executed with option --dut-config=conf_name'.
|
# pytest should be executed with option --dut-config=conf_name'.
|
||||||
@ -63,11 +71,10 @@ def pytest_runtest_setup(item):
|
|||||||
if 'test_wrapper' in sys.modules:
|
if 'test_wrapper' in sys.modules:
|
||||||
test_wrapper.try_setup_serial_log(dut_config)
|
test_wrapper.try_setup_serial_log(dut_config)
|
||||||
|
|
||||||
TestRun.plugins['opencas'] = {
|
TestRun.plugins['opencas'] = OpencasPlugin(
|
||||||
'repo_dir': os.path.join(os.path.dirname(__file__), "../../.."),
|
repo_dir=os.path.join(os.path.dirname(__file__), "../../.."),
|
||||||
'working_dir': dut_config['working_dir'],
|
working_dir=dut_config['working_dir'])
|
||||||
'already_updated': False
|
|
||||||
}
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
TestRun.LOGGER.exception(f"{str(e)}\n{traceback.format_exc()}")
|
TestRun.LOGGER.exception(f"{str(e)}\n{traceback.format_exc()}")
|
||||||
TestRun.LOGGER.info(f"DUT info: {TestRun.dut}")
|
TestRun.LOGGER.info(f"DUT info: {TestRun.dut}")
|
||||||
@ -161,11 +168,11 @@ def base_prepare(item):
|
|||||||
except Exception:
|
except Exception:
|
||||||
pass # TODO: Reboot DUT if test is executed remotely
|
pass # TODO: Reboot DUT if test is executed remotely
|
||||||
|
|
||||||
if get_force_param(item) and not TestRun.plugins['opencas']['already_updated']:
|
if get_force_param(item) and not TestRun.plugins['opencas'].already_updated:
|
||||||
installer.reinstall_opencas()
|
installer.reinstall_opencas()
|
||||||
elif not installer.check_if_installed():
|
elif not installer.check_if_installed():
|
||||||
installer.install_opencas()
|
installer.install_opencas()
|
||||||
TestRun.plugins['opencas']['already_updated'] = True
|
TestRun.plugins['opencas'].already_updated = True
|
||||||
from api.cas import init_config
|
from api.cas import init_config
|
||||||
init_config.create_default_init_config()
|
init_config.create_default_init_config()
|
||||||
TestRun.LOGGER.add_build_info(f'Commit hash:')
|
TestRun.LOGGER.add_build_info(f'Commit hash:')
|
||||||
|
Loading…
Reference in New Issue
Block a user