Merge pull request #177 from katlapinka/opencas-plugin-as-singleton

Make opencas plugin as singleton class
This commit is contained in:
Michał Mielewczyk 2019-11-06 11:44:44 +01:00 committed by GitHub
commit 07d8fdbf01
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 22 additions and 15 deletions

View File

@ -10,12 +10,12 @@ from connection.local_executor import LocalExecutor
def get_current_commit_hash():
local_executor = LocalExecutor()
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
def get_current_commit_message():
local_executor = LocalExecutor()
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

View File

@ -13,13 +13,13 @@ from core.test_run import TestRun
def install_opencas():
TestRun.LOGGER.info("Copying Open CAS repository to DUT")
TestRun.executor.rsync(
f"{TestRun.plugins['opencas']['repo_dir']}/",
f"{TestRun.plugins['opencas']['working_dir']}/",
f"{TestRun.plugins['opencas'].repo_dir}/",
f"{TestRun.plugins['opencas'].working_dir}/",
delete=True)
TestRun.LOGGER.info("Building Open CAS")
output = TestRun.executor.run(
f"cd {TestRun.plugins['opencas']['working_dir']} && "
f"cd {TestRun.plugins['opencas'].working_dir} && "
"./configure && "
"make -j")
if output.exit_code != 0:
@ -28,7 +28,7 @@ def install_opencas():
TestRun.LOGGER.info("Installing Open CAS")
output = TestRun.executor.run(
f"cd {TestRun.plugins['opencas']['working_dir']} && "
f"cd {TestRun.plugins['opencas'].working_dir} && "
f"make install")
if output.exit_code != 0:
TestRun.exception(
@ -50,7 +50,7 @@ def uninstall_opencas():
TestRun.exception("Open CAS is not properly installed")
else:
TestRun.executor.run(
f"cd {TestRun.plugins['opencas']['working_dir']} && "
f"cd {TestRun.plugins['opencas'].working_dir} && "
f"make uninstall")
if output.exit_code != 0:
TestRun.exception(

@ -1 +1 @@
Subproject commit b0081604becc2b9ae23e0de5c29427c59966d68d
Subproject commit b3f62cb3d65ea42c05f297340ca5a1e9ef70fab0

View File

@ -18,6 +18,7 @@ from api.cas import casadm
from api.cas import git
from test_utils.os_utils import Udev
from log.logger import create_log, Log
from test_utils.singleton import Singleton
plugins_dir = os.path.join(os.path.dirname(__file__), "../plugins")
sys.path.append(plugins_dir)
@ -27,6 +28,13 @@ except ImportError:
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):
# There should be dut config file added to config package and
# 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:
test_wrapper.try_setup_serial_log(dut_config)
TestRun.plugins['opencas'] = {
'repo_dir': os.path.join(os.path.dirname(__file__), "../../.."),
'working_dir': dut_config['working_dir'],
'already_updated': False
}
TestRun.plugins['opencas'] = OpencasPlugin(
repo_dir=os.path.join(os.path.dirname(__file__), "../../.."),
working_dir=dut_config['working_dir'])
except Exception as e:
TestRun.LOGGER.exception(f"{str(e)}\n{traceback.format_exc()}")
TestRun.LOGGER.info(f"DUT info: {TestRun.dut}")
@ -161,11 +168,11 @@ def base_prepare(item):
except Exception:
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()
elif not installer.check_if_installed():
installer.install_opencas()
TestRun.plugins['opencas']['already_updated'] = True
TestRun.plugins['opencas'].already_updated = True
from api.cas import init_config
init_config.create_default_init_config()
TestRun.LOGGER.add_build_info(f'Commit hash:')