From 7918d7e7895da4c6ea4b25610780522ac0351d00 Mon Sep 17 00:00:00 2001 From: Your Name Date: Wed, 7 Aug 2019 07:56:51 -0700 Subject: [PATCH] Customize the volume list per layer - Create an input yaml file for the list of volumes that will be mounted to the container when running the tests. - Customize the list of containers for each layer. - Add the posibility to store the bluval-.yaml file outside the validation project and mount it at runtime. Signed-off-by: Cristina Pauna Change-Id: Id3c21cb861879cd3040b06badfb9622429734ce6 --- bluval/README.md | 10 -------- bluval/README.rst | 68 +++++++++++++++++++++++++++++++++++++++++++++++++++++ bluval/blucon.py | 35 ++++++++++++++++++++------- bluval/volumes.yaml | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 162 insertions(+), 18 deletions(-) delete mode 100644 bluval/README.md create mode 100644 bluval/README.rst create mode 100644 bluval/volumes.yaml diff --git a/bluval/README.md b/bluval/README.md deleted file mode 100644 index 0ccd6c5..0000000 --- a/bluval/README.md +++ /dev/null @@ -1,10 +0,0 @@ -# BluVal - -## Installation - -Minimum required python verson is python3.5 - -``` -python3 -m pip install -r requirements.txt -``` - diff --git a/bluval/README.rst b/bluval/README.rst new file mode 100644 index 0000000..56d1282 --- /dev/null +++ b/bluval/README.rst @@ -0,0 +1,68 @@ +.. ############################################################################ +.. Copyright (c) 2019 AT&T, ENEA AB, Nokia and others # +.. # +.. Licensed under the Apache License, Version 2.0 (the "License"); # +.. you maynot use this file except in compliance with the License. # +.. # +.. You may obtain a copy of the License at # +.. http://www.apache.org/licenses/LICENSE-2.0 # +.. # +.. Unless required by applicable law or agreed to in writing, software # +.. distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # +.. WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # +.. See the License for the specific language governing permissions and # +.. limitations under the License. # +.. ############################################################################ + + +Overview +======== +BluVal is a diagnostic toolset framework to validate different layers in the +Akraino infrastructure developed and used in Akraino edge stack. BluVal +integrates different test cases, its development employs a declarative approach +that is version controlled in LF Gerrit. They are integrated in CI/CD tool +chain where peer Jenkins jobs can run the test cases and the results are +reported in LF Repo (Nexus). The test cases cover all blueprint layers in the +cluster. + +Installation and execution +========================== +Bluval tool can be ran directly from the repo, or can be called from a container. + + +When ran directly, minimum requirements are python verson 3.5. To setup the +environment follow the commands below. + +.. code-block:: console + + ns156u@aknode82:~$ git clone https://gerrit.akraino.org/r/validation.git + ns156u@aknode82:~$ cd validation + ns156u@aknode82:~/validation$ python -m venv .py35 + ns156u@aknode82:~/validation$ source .py35/bin/activate + (.py35) ns156u@aknode82:~/validation$ pip install -r bluval/requirements.txt + +To run the tests for a certain blueprint, follow the commands below. Optionally +the layer of testing can be specified too. + +.. code-block:: console + (.py35) ns156u@aknode82:~/validation$ python bluval/bluval.py -l \ + hardware dummy # this will run hardware test cases of dummy blue print + (.py35) ns156u@aknode82:~/validation$ deactivate + + +When ran from a container, docker needs to be installed on the machine. +To run the tests for a certain blueprint, follow the steps below. Optionally +the layer of testing can be specified too. + +Note that before issuing the blucon command, you need to fill in the volumes +that will be mounted in the container. These are locations of the config files +or access files (ssh keys or clients configs) that will be used to connect to +the cluster. Also custom volumes can be added here. + +.. code-block:: console + + ns156u@aknode82:~$ git clone https://gerrit.akraino.org/r/validation.git + ns156u@aknode82:~$ cd validation + ns156u@aknode82:~$ vi bluval/volumes.yaml # fill in the volumes to be \ + mounted in the container + ns156u@aknode82:~$ python3 bluval/blucon.py dummy -l hardware diff --git a/bluval/blucon.py b/bluval/blucon.py index 5d7406b..ececc1f 100644 --- a/bluval/blucon.py +++ b/bluval/blucon.py @@ -29,22 +29,41 @@ import yaml from bluutil import BluvalError from bluutil import ShowStopperError +def get_volumes(layer): + """Create a list with volumes to mount in the container for given layer + """ + mypath = Path(__file__).absolute() + volume_yaml = yaml.safe_load(mypath.parents[0].joinpath("volumes.yaml").open()) + + if layer not in volume_yaml['layers']: + return '' + if volume_yaml['layers'][layer] is None: + return '' + + volume_list = '' + for vol in volume_yaml['layers'][layer]: + if volume_yaml['volumes'][vol]['local'] == '': + continue + volume_list = (volume_list + ' -v ' + + volume_yaml['volumes'][vol]['local'] + ':' + + volume_yaml['volumes'][vol]['target']) + return volume_list + + def invoke_docker(bluprint, layer): """Start docker container for given layer """ - cmd = ("docker run" - " -v $HOME/.ssh:/root/.ssh" - " -v $HOME/.kube/config:/root/.kube/config" - " -v $VALIDATION_HOME/tests/variables.yaml:" - "/opt/akraino/validation/tests/variables.yaml" - " -v $AKRAINO_HOME/results:/opt/akraino/results" + + volume_list = get_volumes('common') + get_volumes(layer) + cmd = ("docker run" + volume_list + " akraino/validation:{0}-latest" - " bin/sh -c" + " /bin/sh -c" " 'cd /opt/akraino/validation " "&& python bluval/bluval.py -l {0} {1}'").format(layer, bluprint) + args = [cmd] try: - print('Invoking {}'.format(args)) + print('\nInvoking {}'.format(args)) subprocess.call(args, shell=True) except OSError: #print('Error while executing {}'.format(args)) diff --git a/bluval/volumes.yaml b/bluval/volumes.yaml new file mode 100644 index 0000000..0e062ea --- /dev/null +++ b/bluval/volumes.yaml @@ -0,0 +1,67 @@ +############################################################################## +# Copyright (c) 2019 AT&T, ENEA AB, Nokia and others # +# # +# Licensed under the Apache License, Version 2.0 (the "License"); # +# you maynot use this file except in compliance with the License. # +# # +# You may obtain a copy of the License at # +# http://www.apache.org/licenses/LICENSE-2.0 # +# # +# Unless required by applicable law or agreed to in writing, software # +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # +# See the License for the specific language governing permissions and # +# limitations under the License. # +############################################################################## + +# Full list of volumes that can be mounted to the containers when running the tests. +# When adding volumes, add file or dir at the end of the keyword to ease identifying +# the type of the volume +# +# When running the tests, fill in the 'local' sections only for the volumes that are +# applicable to your setup + +volumes: + # location of the ssh key to access the cluster + ssh_key_file: + local: '' + target: '/root/.ssh' + # location of the k8s access files (config file, certificates, keys) + kube_config_dir: + local: '' + target: '/root/.kube/' + # location of the customized variables.yaml + custom_variables_file: + local: '' + target: '/opt/akraino/validation/tests/variables.yaml' + # location of the bluval-.yaml file + blueprint_dir: + local: '' + target: '/opt/akraino/validation/bluval' + # location on where to store the results on the local jumpserver + results_dir: + local: '' + target: '/opt/akraino/results' + +# parameters that will be passed to the container at each layer +layers: + # volumes mounted at all layers; volumes specific for a different layer are below + common: + - custom_variables_file + - blueprint_dir + - results_dir + hardware: + - ssh_key_file + os: + - ssh_key_file + networking: + - ssh_key_file + k8s: + - ssh_key_file + - kube_config_dir + k8s_networking: + - ssh_key_File + - kube_config_dir + sds: + sdn: + vim: -- 2.16.6