Commit 550b2831 authored by Raphael Defosseux's avatar Raphael Defosseux

feat(ci): adding parser and git template yaml file

Signed-off-by: default avatarRaphael Defosseux <raphael.defosseux@eurecom.fr>
parent 751a92ae
...@@ -88,3 +88,9 @@ flake8 oai-ci-test-main.py ...@@ -88,3 +88,9 @@ flake8 oai-ci-test-main.py
``` ```
You shall have no error message. You shall have no error message.
## Usage ##
```bash
python3 ./oai-ci-test-main.py --infra_yaml testinfra-as-code.yaml --tstcfg_yaml test-example.yaml --git_yaml git_info_template.yaml --mode BuildAndTest
```
\ No newline at end of file
...@@ -27,8 +27,9 @@ For more information about the OpenAirInterface (OAI) Software Alliance: ...@@ -27,8 +27,9 @@ For more information about the OpenAirInterface (OAI) Software Alliance:
class CN: class CN:
"""Object class to support any Core Network operations.""" """Object class to support any Core Network operations."""
def __init__(self, infra, config, deployment): def __init__(self, infra, config, deployment, git_info):
self.Deployment = deployment self.Deployment = deployment
self.Infra = infra self.Infra = infra
self.GitInfo = git_info
for key, val in config.items(): for key, val in config.items():
setattr(self, key, val) setattr(self, key, val)
...@@ -27,8 +27,9 @@ For more information about the OpenAirInterface (OAI) Software Alliance: ...@@ -27,8 +27,9 @@ For more information about the OpenAirInterface (OAI) Software Alliance:
class NodeB: class NodeB:
"""Object class to support any RAN (eNB/gNB) operations.""" """Object class to support any RAN (eNB/gNB) operations."""
def __init__(self, infra, config, deployment): def __init__(self, infra, config, deployment, git_info):
self.Deployment = deployment self.Deployment = deployment
self.Infra = infra self.Infra = infra
self.GitInfo = git_info
for key, val in config.items(): for key, val in config.items():
setattr(self, key, val) setattr(self, key, val)
...@@ -27,8 +27,9 @@ For more information about the OpenAirInterface (OAI) Software Alliance: ...@@ -27,8 +27,9 @@ For more information about the OpenAirInterface (OAI) Software Alliance:
class UE: class UE:
"""Object class to support any UE operations.""" """Object class to support any UE operations."""
def __init__(self, infra, config, deployment): def __init__(self, infra, config, deployment, git_info):
self.Deployment = deployment self.Deployment = deployment
self.Infra = infra self.Infra = infra
self.GitInfo = git_info
for key, val in config.items(): for key, val in config.items():
setattr(self, key, val) setattr(self, key, val)
git:
url : GIT_URL
branch : GIT_BRANCH
commit : GIT_COMMIT
merge_request :
status : no
id : MR_IID
src_branch : SRC_BRANCH
src_commit : SRC_COMMIT
...@@ -23,6 +23,8 @@ For more information about the OpenAirInterface (OAI) Software Alliance: ...@@ -23,6 +23,8 @@ For more information about the OpenAirInterface (OAI) Software Alliance:
""" """
import argparse
import yaml import yaml
import cls_cn import cls_cn
...@@ -30,6 +32,46 @@ import cls_ran ...@@ -30,6 +32,46 @@ import cls_ran
import cls_ue import cls_ue
def _parse_args() -> argparse.Namespace:
"""Parse the command line args
Returns:
argparse.Namespace: the created parser
"""
parser = argparse.ArgumentParser(description='OAI CI Test Framework')
# Infra YML filename
parser.add_argument(
'--infra_yaml', '-in',
action='store',
required=True,
help='Setup Infrastructure Yaml File',
)
# Test Configuration YML filename
parser.add_argument(
'--tstcfg_yaml', '-tc',
action='store',
required=True,
help='Test Configuration Yaml File',
)
# Git Information YML filename
parser.add_argument(
'--git_yaml', '-g',
action='store',
required=True,
help='Git Information Yaml File',
)
# Mode
parser.add_argument(
'--mode',
action='store',
required=True,
choices=['BuildAndTest', 'RetrieveLogs'],
help='OAI CI Test Mode',
)
return parser.parse_args()
def get_test_infrastructure(filename): def get_test_infrastructure(filename):
""" """
Load the test infrastructure. Load the test infrastructure.
...@@ -60,14 +102,30 @@ def get_test_config(filename): ...@@ -60,14 +102,30 @@ def get_test_config(filename):
return test_config return test_config
def get_test_objects(key, infrastructure, test_cfg): def get_git_info(filename):
"""
Load the git information data model.
Args:
filename: yaml description file of git information
Returns:
test_config: git information data model
"""
with open(filename, 'r') as git_yml:
git_info = yaml.safe_load(git_yml)
return git_info
def get_test_objects(key, infra, test_cfg, git_info):
""" """
Load the test objects. Load the test objects.
Args: Args:
key: relevant keys to select key: relevant keys to select
infrastructure: infrastructure data model infra: infrastructure data model
test_cfg: test configuration data model test_cfg: test configuration data model
git_info: git information data model
Returns: Returns:
dict_obj: dictionary of objects under test dict_obj: dictionary of objects under test
...@@ -80,25 +138,36 @@ def get_test_objects(key, infrastructure, test_cfg): ...@@ -80,25 +138,36 @@ def get_test_objects(key, infrastructure, test_cfg):
# create dict of Objects under test # create dict of Objects under test
dict_obj = {} dict_obj = {}
for elt in elements: for elt in elements:
deployment = test_cfg['config'][key][key][elt]['Deploy'] deploy = test_cfg['config'][key][key][elt]['Deploy']
# retrieve the infra part of the element under test only # retrieve the infra part of the element under test only
obj_part = infrastructure[part][elt] obj_part = infra[part][elt]
if key == 'RAN': if key == 'RAN':
dict_obj[elt] = cls_ran.NodeB(infrastructure, obj_part, deployment) dict_obj[elt] = cls_ran.NodeB(infra, obj_part, deploy, git_info)
elif key == 'CN': elif key == 'CN':
dict_obj[elt] = cls_cn.CN(infrastructure, obj_part, deployment) dict_obj[elt] = cls_cn.CN(infra, obj_part, deploy, git_info)
elif key == 'UE': elif key == 'UE':
dict_obj[elt] = cls_ue.UE(infrastructure, obj_part, deployment) dict_obj[elt] = cls_ue.UE(infra, obj_part, deploy, git_info)
else: else:
pass pass
return dict_obj return dict_obj
if __name__ == '__main__': if __name__ == '__main__':
testbench = 'testinfra-as-code.yaml' # Parse the arguments to recover the YAML filenames
test = 'test-example.yaml' args = _parse_args()
infrastructure = get_test_infrastructure(testbench) # Retrieve the infrastructure
test_cfg = get_test_config(test) infrastructure = get_test_infrastructure(args.infra_yaml)
RAN = get_test_objects('RAN', infrastructure, test_cfg) # Retrieve the test configuration (ie infra being used and testsuite)
CN = get_test_objects('CN', infrastructure, test_cfg) test_cfg = get_test_config(args.tstcfg_yaml)
UEs = get_test_objects('UE', infrastructure, test_cfg) # Retrieve the git information
git_info = get_git_info(args.git_yaml)
# Populate objects
RAN = get_test_objects('RAN', infrastructure, test_cfg, git_info)
CN = get_test_objects('CN', infrastructure, test_cfg, git_info)
UEs = get_test_objects('UE', infrastructure, test_cfg, git_info)
for key1 in RAN.keys():
print(key1, RAN[key1].Type)
if args.mode == 'BuildAndTest':
print('Mode is BuildAndTest')
if args.mode == 'RetrieveLogs':
print('Mode is RetrieveLogs')
...@@ -7,8 +7,14 @@ ignore = ...@@ -7,8 +7,14 @@ ignore =
WPS110, # Found wrong variable name WPS110, # Found wrong variable name
WPS210, # Found too many local variables WPS210, # Found too many local variables
WPS219, # Found too deep access level WPS219, # Found too deep access level
WPS226, # Found string constant over-use
WPS306, # Found class without a base class WPS306, # Found class without a base class
WPS317, # Found incorrect multi-line parameters
WPS420, # Found wrong keyword WPS420, # Found wrong keyword
WPS421, # Found wrong function
# Darglint warnings
DAR003, # Incorrect indentation
DAR102, # Excess parameter(s) in Docstring
# pydocstyle warnings # pydocstyle warnings
D107, # Missing docstring in __init_ D107, # Missing docstring in __init_
D2, # White space formatting for doc strings D2, # White space formatting for doc strings
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment