From 42af6fa2ef682d28d12952831aa0c74fd647daad Mon Sep 17 00:00:00 2001 From: opensource-tnbt Date: Sat, 1 Aug 2020 22:12:02 +0530 Subject: SDV: Reorganize subprojects This patch reorganizes the subprojects. Pylint Fixes. Additional Configurations Signed-off-by: Sridhar K. N. Rao Change-Id: I021f33f035d7b2dcfded230ca40337afdac183e8 --- .gitignore | 56 +++++ sdv/NwLinksValid/nwlinksvalidator.py | 6 +- sdv/ResourceModelValid/__init__.py | 17 ++ sdv/ResourceModelValid/resmodvalidator.py | 34 +++ sdv/SoftwarePostSecurityValid/__init__.py | 19 ++ .../swpostsecurityvalidator.py | 36 +++ sdv/SoftwarePostStateValid/__init__.py | 19 ++ sdv/SoftwarePostStateValid/swpoststatevalidator.py | 36 +++ sdv/SoftwarePostValid/__init__.py | 19 -- sdv/SoftwarePostValid/swpostvalidator.py | 42 ---- sdv/SoftwarePreConfigValid/__init__.py | 19 ++ sdv/SoftwarePreConfigValid/swpreconfigvalidator.py | 34 +++ sdv/SoftwarePreUrlsValid/__init__.py | 19 ++ sdv/SoftwarePreUrlsValid/airship.py | 155 ++++++++++++ sdv/SoftwarePreUrlsValid/swpreurlsvalidator.py | 34 +++ sdv/SoftwarePreValid/__init__.py | 19 -- sdv/SoftwarePreValid/airship.py | 267 --------------------- sdv/SoftwarePreValid/swprevalidator.py | 42 ---- sdv/conf/00_common.conf | 7 +- sdv/conf/01_swpreurlsvalid.conf | 24 ++ sdv/conf/01_swprevalid.conf | 33 --- sdv/conf/02_swpostvalid.conf | 4 - sdv/conf/02_swpreconfigvalid.conf | 20 ++ sdv/conf/03_nwlinksvalid.conf | 1 - sdv/conf/03_swpoststatevalid.conf | 26 ++ sdv/conf/04_swpostsecurityvalid.conf | 16 ++ sdv/conf/05_nwlinksvalid.conf | 15 ++ sdv/conf/06_resmodvalid.conf | 15 ++ sdv/core/component_factory.py | 33 ++- sdv/core/loader/loader.py | 157 +++++++++--- sdv/valid | 185 +++++++++++--- 31 files changed, 906 insertions(+), 503 deletions(-) create mode 100644 .gitignore create mode 100755 sdv/ResourceModelValid/__init__.py create mode 100644 sdv/ResourceModelValid/resmodvalidator.py create mode 100755 sdv/SoftwarePostSecurityValid/__init__.py create mode 100644 sdv/SoftwarePostSecurityValid/swpostsecurityvalidator.py create mode 100755 sdv/SoftwarePostStateValid/__init__.py create mode 100644 sdv/SoftwarePostStateValid/swpoststatevalidator.py delete mode 100755 sdv/SoftwarePostValid/__init__.py delete mode 100644 sdv/SoftwarePostValid/swpostvalidator.py create mode 100755 sdv/SoftwarePreConfigValid/__init__.py create mode 100644 sdv/SoftwarePreConfigValid/swpreconfigvalidator.py create mode 100755 sdv/SoftwarePreUrlsValid/__init__.py create mode 100644 sdv/SoftwarePreUrlsValid/airship.py create mode 100644 sdv/SoftwarePreUrlsValid/swpreurlsvalidator.py delete mode 100755 sdv/SoftwarePreValid/__init__.py delete mode 100644 sdv/SoftwarePreValid/airship.py delete mode 100644 sdv/SoftwarePreValid/swprevalidator.py create mode 100644 sdv/conf/01_swpreurlsvalid.conf delete mode 100644 sdv/conf/01_swprevalid.conf delete mode 100644 sdv/conf/02_swpostvalid.conf create mode 100644 sdv/conf/02_swpreconfigvalid.conf delete mode 100644 sdv/conf/03_nwlinksvalid.conf create mode 100644 sdv/conf/03_swpoststatevalid.conf create mode 100644 sdv/conf/04_swpostsecurityvalid.conf create mode 100644 sdv/conf/05_nwlinksvalid.conf create mode 100644 sdv/conf/06_resmodvalid.conf diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..05a1aa0 --- /dev/null +++ b/.gitignore @@ -0,0 +1,56 @@ +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*.confc + +# C extensions +*.so + +# Distribution / packaging +.Python +env/ +build/ +develop-eggs/ +dist/ +eggs/ +lib64/ +parts/ +sdist/ +var/ +*.egg-info/ +.installed.cfg +*.egg + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.coverage +.cache +nosetests.xml +coverage.xml + +# Translations +*.mo +*.pot + +# Log files: +*.log + +# Sphinx documentation + +# PyBuilder +target/ + +# SublimeText +*.sublime-project +*.sublime-workspace diff --git a/sdv/NwLinksValid/nwlinksvalidator.py b/sdv/NwLinksValid/nwlinksvalidator.py index 5e06590..314567b 100644 --- a/sdv/NwLinksValid/nwlinksvalidator.py +++ b/sdv/NwLinksValid/nwlinksvalidator.py @@ -29,10 +29,6 @@ class INwLinksValidator(): """ Default Validation values """ return True - def validate_compute_node_links(self): + def validate(self): """ Validating Compute Node Links""" raise NotImplementedError('Please call an implementation.') - - def validate_control_node_links(self): - """ Validating Controller Node Links""" - raise NotImplementedError('Please call an implementation.') diff --git a/sdv/ResourceModelValid/__init__.py b/sdv/ResourceModelValid/__init__.py new file mode 100755 index 0000000..b3aebfd --- /dev/null +++ b/sdv/ResourceModelValid/__init__.py @@ -0,0 +1,17 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not 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. + +"""Nework-Links Validator interface and helpers. +""" + +# flake8: noqa +from ResourceModelValid.resmodvalidator import * diff --git a/sdv/ResourceModelValid/resmodvalidator.py b/sdv/ResourceModelValid/resmodvalidator.py new file mode 100644 index 0000000..bc2ab9e --- /dev/null +++ b/sdv/ResourceModelValid/resmodvalidator.py @@ -0,0 +1,34 @@ +# Copyright 2020 Spirent Communications. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not 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. + +""" +Abstract class for N/W Lnks Prevalidations. +Implementors, please inherit from this class. +""" + + +class IResModValidator(): + """ Model for a Links Validator """ + def __init__(self): + """ Initialization of the Interface """ + self._default_resmod_validation = None + + @property + def validation_resmod_defaults(self): + """ Default Validation values """ + return True + + def validate(self): + """ Validating Resource Modelling""" + raise NotImplementedError('Please call an implementation.') diff --git a/sdv/SoftwarePostSecurityValid/__init__.py b/sdv/SoftwarePostSecurityValid/__init__.py new file mode 100755 index 0000000..2d85d6c --- /dev/null +++ b/sdv/SoftwarePostSecurityValid/__init__.py @@ -0,0 +1,19 @@ +# Copyright 2015 Intel Corporation. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not 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. + +"""Sw Validator interface and helpers. +""" + +# flake8: noqa +from SoftwarePostSecurityValid.swpostsecurityvalidator import * diff --git a/sdv/SoftwarePostSecurityValid/swpostsecurityvalidator.py b/sdv/SoftwarePostSecurityValid/swpostsecurityvalidator.py new file mode 100644 index 0000000..0f40261 --- /dev/null +++ b/sdv/SoftwarePostSecurityValid/swpostsecurityvalidator.py @@ -0,0 +1,36 @@ +# Copyright 2020 Spirent Communications. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not 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. + +""" +Abstract class for Software Postvalidations. +Implementors, please inherit from this class. +""" + + +class ISwPostSecurityValidator(): + """ Model for a Sw Validator """ + def __init__(self): + """ Initialization of the Interface """ + self._default_security_validation = None + + @property + def validation_security_defaults(self): + """ Default Validation values """ + return True + + def validate(self): + """ + Validating Mandatory Configuration + """ + raise NotImplementedError('Please call an implementation.') diff --git a/sdv/SoftwarePostStateValid/__init__.py b/sdv/SoftwarePostStateValid/__init__.py new file mode 100755 index 0000000..5349f90 --- /dev/null +++ b/sdv/SoftwarePostStateValid/__init__.py @@ -0,0 +1,19 @@ +# Copyright 2015 Intel Corporation. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not 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. + +"""Sw Validator interface and helpers. +""" + +# flake8: noqa +from SoftwarePostStateValid.swpoststatevalidator import * diff --git a/sdv/SoftwarePostStateValid/swpoststatevalidator.py b/sdv/SoftwarePostStateValid/swpoststatevalidator.py new file mode 100644 index 0000000..0c01034 --- /dev/null +++ b/sdv/SoftwarePostStateValid/swpoststatevalidator.py @@ -0,0 +1,36 @@ +# Copyright 2020 Spirent Communications. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not 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. + +""" +Abstract class for Software Postvalidations. +Implementors, please inherit from this class. +""" + + +class ISwPostStateValidator(): + """ Model for a Sw Validator """ + def __init__(self): + """ Initialization of the Interface """ + self._default_swpoststate_validation = None + + @property + def validation_swpoststate_defaults(self): + """ Default Validation values """ + return True + + def validate(self): + """ + Validating State + """ + raise NotImplementedError('Please call an implementation.') diff --git a/sdv/SoftwarePostValid/__init__.py b/sdv/SoftwarePostValid/__init__.py deleted file mode 100755 index 0a964b6..0000000 --- a/sdv/SoftwarePostValid/__init__.py +++ /dev/null @@ -1,19 +0,0 @@ -# Copyright 2015 Intel Corporation. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not 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. - -"""Sw Validator interface and helpers. -""" - -# flake8: noqa -from SoftwarePostValid.swpostvalidator import * diff --git a/sdv/SoftwarePostValid/swpostvalidator.py b/sdv/SoftwarePostValid/swpostvalidator.py deleted file mode 100644 index 4776123..0000000 --- a/sdv/SoftwarePostValid/swpostvalidator.py +++ /dev/null @@ -1,42 +0,0 @@ -# Copyright 2020 Spirent Communications. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not 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. - -""" -Abstract class for Software Postvalidations. -Implementors, please inherit from this class. -""" - - -class ISwPostValidator(): - """ Model for a Sw Validator """ - def __init__(self): - """ Initialization of the Interface """ - self._default_swpost_validation = None - - @property - def validation_swpost_defaults(self): - """ Default Validation values """ - return True - - def validate_configuration_mandatory(self): - """ - Validating Mandatory Configuration - """ - raise NotImplementedError('Please call an implementation.') - - def validate_configuration_optional(self): - """ - Validating Optional Configuration - """ - raise NotImplementedError('Please call an implementation.') diff --git a/sdv/SoftwarePreConfigValid/__init__.py b/sdv/SoftwarePreConfigValid/__init__.py new file mode 100755 index 0000000..7eb24f9 --- /dev/null +++ b/sdv/SoftwarePreConfigValid/__init__.py @@ -0,0 +1,19 @@ +# Copyright 2020 Spirent Communications. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not 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. + +"""Sw Validator interface and helpers. +""" + +# flake8: noqa +from SoftwarePreConfigValid.swpreconfigvalidator import * diff --git a/sdv/SoftwarePreConfigValid/swpreconfigvalidator.py b/sdv/SoftwarePreConfigValid/swpreconfigvalidator.py new file mode 100644 index 0000000..a423354 --- /dev/null +++ b/sdv/SoftwarePreConfigValid/swpreconfigvalidator.py @@ -0,0 +1,34 @@ +# Copyright 2020 Spirent Communications. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not 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. + +""" +Abstract class for Software Prevalidations. +Implementors, please inherit from this class. +""" + + +class ISwPreConfigValidator(): + """ Model for a Sw Validator """ + def __init__(self): + """ Initialization of the Interface """ + self._default_swpreconfig_validation = None + + @property + def validation_swpreconfig_defaults(self): + """ Default Validation values """ + return True + + def validate(self): + """ Validate Mandatory Configurations """ + raise NotImplementedError('Please call an implementation.') diff --git a/sdv/SoftwarePreUrlsValid/__init__.py b/sdv/SoftwarePreUrlsValid/__init__.py new file mode 100755 index 0000000..c1f68ac --- /dev/null +++ b/sdv/SoftwarePreUrlsValid/__init__.py @@ -0,0 +1,19 @@ +# Copyright 2020 Spirent Communications. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not 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. + +"""Sw Validator interface and helpers. +""" + +# flake8: noqa +from SoftwarePreUrlsValid.swpreurlsvalidator import * diff --git a/sdv/SoftwarePreUrlsValid/airship.py b/sdv/SoftwarePreUrlsValid/airship.py new file mode 100644 index 0000000..324eaf1 --- /dev/null +++ b/sdv/SoftwarePreUrlsValid/airship.py @@ -0,0 +1,155 @@ +# Copyright 2020 Spirent Communications. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not 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. + +""" +Airship implementation of Software Predeployment Validation +""" + +import os +import shutil +from pathlib import Path +import git +import urllib3 +from conf import settings +from SoftwarePreUrlsValid import swpreurlsvalidator + + +def check_link(link): + """ + Function the check the availability of Hyperlinks + """ + timeout = urllib3.util.Timeout(connect=5.0, read=7.0) + http = urllib3.PoolManager(timeout=timeout) + try: + http.request('HEAD', link) + except urllib3.exceptions.LocationValueError as err: + print(err.args) + return False + except urllib3.exceptions.MaxRetryError as err: + print(err.args) + return False + except urllib3.exceptions.RequestError as err: + print(err.args) + return False + except urllib3.exceptions.ConnectTimeoutError as err: + print(err.args) + return False + except urllib3.exceptions.PoolError as err: + print(err.args) + return False + except urllib3.exceptions.HTTPError as err: + print(err.args) + return False + return True + + +class Airship(swpreurlsvalidator.ISwPreUrlsValidator): + """ + Ariship Sw Validation + """ + def __init__(self): + """ Airship class constructor """ + super().__init__() + self.url = settings.getValue('AIRSHIP_MANIFEST_URL') + self.branch = settings.getValue('AIRSHIP_MANIFEST_BRANCH') + self.dl_path = settings.getValue('AIRSHIP_MANIFEST_DOWNLOAD_PATH') + self.site_name = settings.getValue('AIRSHIP_MANIFEST_SITE_NAME') + self.manifest = None + self.dirpath = Path(self.dl_path, 'airship') + self.tmdirpath = Path(self.dl_path, 'treasuremap') + self.locations = [] + + def clone_repo(self): + """ + Cloning the repos + """ + git.Repo.clone_from(self.url, + self.dirpath, + branch=self.branch) + git.Repo.clone_from('https://github.com/airshipit/treasuremap', + self.tmdirpath, + branch=settings.getValue( + 'AIRSHIP_TREASUREMAP_VERSION')) + + def cleanup_manifest(self): + """ + Remove existing manifests + """ + # Next Remove any manifest files, if it exists + if self.dirpath.exists() and self.dirpath.is_dir(): + shutil.rmtree(self.dirpath) + if self.tmdirpath.exists() and self.tmdirpath.is_dir(): + shutil.rmtree(self.tmdirpath) + + def manifest_exists_locally(self): + """ + Check if manifests exists locally + """ + if self.dirpath.exists() and self.dirpath.is_dir(): + return True + return False + + def validate(self): + """ + Hyperlink Validation + """ + self.cleanup_manifest() + # Next, clone the repo to the provided path. + self.clone_repo() + + if self.dirpath.exists() and self.dirpath.is_dir(): + # Get the file(s) where links are defined. + self.find_locations( + os.path.join(self.dirpath, 'type', + 'cntt', 'software', + 'config', 'versions.yaml')) + for location in self.locations: + if check_link(location): + print("The Link: %s is VALID" % (location)) + else: + print("The Link: %s is INVALID" % (location)) + + # pylint: disable=consider-using-enumerate + def find_locations(self, yamlfile): + """ + Find all the hyperlinks in the manifests + """ + with open(yamlfile, 'r') as filep: + lines = filep.readlines() + for index in range(len(lines)): + line = lines[index].strip() + if line.startswith('location:'): + link = line.split(":", 1)[1] + if "opendev" in link: + if ((len(lines) > index+1) and + (lines[index+1].strip().startswith( + 'reference:'))): + ref = lines[index+1].split(":", 1)[1] + link = link + '/commit/' + ref.strip() + if link.strip() not in self.locations: + print(link) + self.locations.append(link.strip()) + if 'docker.' in line: + link = line.split(":", 1)[1] + link = link.replace('"', '') + parts = link.split('/') + if len(parts) == 3: + link = ('https://index.' + + parts[0].strip() + + '/v1/repositories/' + + parts[1] + '/' + parts[2].split(':')[0] + + '/tags/' + parts[2].split(':')[-1]) + if link.strip() not in self.locations: + print(link) + self.locations.append(link.strip()) diff --git a/sdv/SoftwarePreUrlsValid/swpreurlsvalidator.py b/sdv/SoftwarePreUrlsValid/swpreurlsvalidator.py new file mode 100644 index 0000000..31604ee --- /dev/null +++ b/sdv/SoftwarePreUrlsValid/swpreurlsvalidator.py @@ -0,0 +1,34 @@ +# Copyright 2020 Spirent Communications. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not 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. + +""" +Abstract class for Software Prevalidations. +Implementors, please inherit from this class. +""" + + +class ISwPreUrlsValidator(): + """ Model for a Sw Validator """ + def __init__(self): + """ Initialization of the Interface """ + self._default_swpre_validation = None + + @property + def validation_swpreurls_defaults(self): + """ Default Validation values """ + return True + + def validate(self): + """ Validate Hyperlinks""" + raise NotImplementedError('Please call an implementation.') diff --git a/sdv/SoftwarePreValid/__init__.py b/sdv/SoftwarePreValid/__init__.py deleted file mode 100755 index 8307b66..0000000 --- a/sdv/SoftwarePreValid/__init__.py +++ /dev/null @@ -1,19 +0,0 @@ -# Copyright 2020 Spirent Communications. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not 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. - -"""Sw Validator interface and helpers. -""" - -# flake8: noqa -from SoftwarePreValid.swprevalidator import * diff --git a/sdv/SoftwarePreValid/airship.py b/sdv/SoftwarePreValid/airship.py deleted file mode 100644 index bd93aa2..0000000 --- a/sdv/SoftwarePreValid/airship.py +++ /dev/null @@ -1,267 +0,0 @@ -# Copyright 2020 Spirent Communications. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not 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. - -""" -Airship implementation of Software Predeployment Validation -""" - -import os -import shutil -from pathlib import Path -import git -import urllib3 -import yaml -from conf import settings -from SoftwarePreValid import swprevalidator - - -def check_link(link): - """ - Function the check the availability of Hyperlinks - """ - timeout = urllib3.util.Timeout(connect=5.0, read=7.0) - http = urllib3.PoolManager(timeout=timeout) - try: - http.request('HEAD', link) - except urllib3.exceptions.LocationValueError as err: - print(err.args) - return False - except urllib3.exceptions.MaxRetryError as err: - print(err.args) - return False - except urllib3.exceptions.RequestError as err: - print(err.args) - return False - except urllib3.exceptions.ConnectTimeoutError as err: - print(err.args) - return False - except urllib3.exceptions.PoolError as err: - print(err.args) - return False - except urllib3.exceptions.HTTPError as err: - print(err.args) - return False - return True - - -class Airship(swprevalidator.ISwPreValidator): - """ - Ariship Sw Validation - """ - def __init__(self): - """ Airship class constructor """ - super().__init__() - self.url = settings.getValue('AIRSHIP_MANIFEST_URL') - self.branch = settings.getValue('AIRSHIP_MANIFEST_BRANCH') - self.dl_path = settings.getValue('AIRSHIP_MANIFEST_DOWNLOAD_PATH') - self.site_name = settings.getValue('AIRSHIP_MANIFEST_SITE_NAME') - self.manifest = None - self.dirpath = Path(self.dl_path, 'airship') - self.tmdirpath = Path(self.dl_path, 'treasuremap') - self.locations = [] - - def clone_repo(self): - """ - Cloning the repos - """ - git.Repo.clone_from(self.url, - self.dirpath, - branch=self.branch) - git.Repo.clone_from('https://github.com/airshipit/treasuremap', - self.tmdirpath, - branch=settings.getValue( - 'AIRSHIP_TREASUREMAP_VERSION')) - - def cleanup_manifest(self): - """ - Remove existing manifests - """ - # Next Remove any manifest files, if it exists - if self.dirpath.exists() and self.dirpath.is_dir(): - shutil.rmtree(self.dirpath) - if self.tmdirpath.exists() and self.tmdirpath.is_dir(): - shutil.rmtree(self.tmdirpath) - - def manifest_exists_locally(self): - """ - Check if manifests exists locally - """ - if self.dirpath.exists() and self.dirpath.is_dir(): - return True - return False - - def validate_hyperlinks(self): - """ - Hyperlink Validation - """ - self.cleanup_manifest() - # Next, clone the repo to the provided path. - self.clone_repo() - - if self.dirpath.exists() and self.dirpath.is_dir(): - # Get the file(s) where links are defined. - self.find_locations( - os.path.join(self.dirpath, 'type', - 'cntt', 'software', - 'config', 'versions.yaml')) - for location in self.locations: - if check_link(location): - print("The Link: %s is VALID" % (location)) - else: - print("The Link: %s is INVALID" % (location)) - - # pylint: disable=consider-using-enumerate - def find_locations(self, yamlfile): - """ - Find all the hyperlinks in the manifests - """ - with open(yamlfile, 'r') as filep: - lines = filep.readlines() - for index in range(len(lines)): - line = lines[index].strip() - if line.startswith('location:'): - link = line.split(":", 1)[1] - if "opendev" in link: - if ((len(lines) > index+1) and - (lines[index+1].strip().startswith( - 'reference:'))): - ref = lines[index+1].split(":", 1)[1] - link = link + '/commit/' + ref.strip() - if link.strip() not in self.locations: - print(link) - self.locations.append(link.strip()) - if 'docker.' in line: - link = line.split(":", 1)[1] - link = link.replace('"', '') - parts = link.split('/') - if len(parts) == 3: - link = ('https://index.' + - parts[0].strip() + - '/v1/repositories/' + - parts[1] + '/' + parts[2].split(':')[0] + - '/tags/' + parts[2].split(':')[-1]) - if link.strip() not in self.locations: - print(link) - self.locations.append(link.strip()) - - # pylint: disable=too-many-nested-blocks, too-many-boolean-expressions - def validate_configuration_mandatory(self): - """ - Configuration checking of mandatory parameters - """ - if not self.manifest_exists_locally(): - self.clone_repo() - # We will perform validation one-by-one: - # The Operating System Flavor - os_done = False - os_filename = os.path.join(self.tmdirpath, - 'global', - 'software', - 'charts', - 'ucp', - 'drydock', - 'maas.yaml') - with open(os_filename, 'r') as osref: - osfiles = yaml.load_all(osref, Loader=yaml.FullLoader) - for osf in osfiles: - if ('data' in osf and - 'values' in osf['data'] and - 'conf' in osf['data']['values'] and - 'maas' in osf['data']['values']['conf'] and - 'images' in osf['data']['values']['conf']['maas'] and - ('default_os' in - osf['data']['values']['conf']['maas']['images'])): - if (settings.getValue('OPERATING_SYSTEM') in - osf['data']['values']['conf']['maas']['images'][ - 'default_os']): - print('Operating System is VALID') - os_done = True - if not os_done: - print("Operating System is INVALID") - - filesdir = os.path.join(self.dirpath, - 'site', - self.site_name, - 'profiles', - 'host') - hostprofile = None - os_ver_done = False - if os.path.isdir(filesdir): - for filename in os.listdir(filesdir): - filename = os.path.join(filesdir, filename) - with open(filename, 'r') as fileref: - hostprofile = yaml.load(fileref, Loader=yaml.FullLoader) - if 'data' in hostprofile: - if 'platform' in hostprofile['data']: - if 'image' in hostprofile['data']['platform']: - if (hostprofile['data']['platform']['image'] in - settings.getValue('OS_VERSION_NAME')): - print('Operating System Version is VALID') - os_ver_done = True - break - if not os_ver_done: - print("Operating System Version is INVALID") - # Virtualization - Hugepages and CPU Isolation - hugepages_size_done = False - hugepages_count_done = False - filesdir = os.path.join(self.dirpath, - 'type', - 'cntt', - 'profiles', - 'hardware') - if os.path.isdir(filesdir): - for filename in os.listdir(filesdir): - filename = os.path.join(filesdir, filename) - with open(filename, 'r') as fileref: - hwprofile = yaml.load(fileref, Loader=yaml.FullLoader) - if ('data' in hwprofile and - 'hugepages' in hwprofile['data'] and - 'dpdk' in hwprofile['data']['hugepages']): - if ('size' in hwprofile['data']['hugepages']['dpdk'] and - (settings.getValue('HUGEPAGES_SIZE') in - hwprofile['data']['hugepages']['dpdk']['size'])): - print('Hugepages Size is VALID') - else: - print('Hugepages Size is INVALID') - hugepages_size_done = True - if ('count' in hwprofile['data']['hugepages']['dpdk'] and - (settings.getValue('HUGEPAGES_COUNT') == - hwprofile['data']['hugepages']['dpdk']['count'])): - print('Hugepages COUNT is VALID') - else: - print('Hugepages COUNT is INVALID') - hugepages_count_done = True - if hugepages_size_done and hugepages_count_done: - break - - # Virtual Switch - Switch and Configuration - # Openstack-Version - filename = os.path.join(self.tmdirpath, - 'global', - 'software', - 'config', - 'versions.yaml') - if os.path.exists(filename): - if settings.getValue('OPENSTACK_VERSION') in open(filename).read(): - print('Openstack Version is valid') - else: - print('Openstack version if INVALID') - # Openstack Services - # Bootstrap - - def validate_configuration_optional(self): - """ - Validate Optional COnfigurations - """ - return False diff --git a/sdv/SoftwarePreValid/swprevalidator.py b/sdv/SoftwarePreValid/swprevalidator.py deleted file mode 100644 index bef141b..0000000 --- a/sdv/SoftwarePreValid/swprevalidator.py +++ /dev/null @@ -1,42 +0,0 @@ -# Copyright 2020 Spirent Communications. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not 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. - -""" -Abstract class for Software Prevalidations. -Implementors, please inherit from this class. -""" - - -class ISwPreValidator(): - """ Model for a Sw Validator """ - def __init__(self): - """ Initialization of the Interface """ - self._default_swpre_validation = None - - @property - def validation_swpre_defaults(self): - """ Default Validation values """ - return True - - def validate_hyperlinks(self): - """ Validate Hyperlinks""" - raise NotImplementedError('Please call an implementation.') - - def validate_configuration_mandatory(self): - """ Validate Mandatory Configurations """ - raise NotImplementedError('Please call an implementation.') - - def validate_configuration_optional(self): - """ Validate Optional Configurations """ - raise NotImplementedError('Please call an implementation.') diff --git a/sdv/conf/00_common.conf b/sdv/conf/00_common.conf index 5326ecb..f5e8a23 100644 --- a/sdv/conf/00_common.conf +++ b/sdv/conf/00_common.conf @@ -8,9 +8,12 @@ LOG_FILE_DEFAULT = 'valid-overall.log' ROOT_DIR = os.path.normpath(os.path.join( os.path.dirname(os.path.realpath(__file__)), '../')) -SW_PRE_VALID_DIR = os.path.join(ROOT_DIR, 'SoftwarePreValid') -SW_POST_VALID_DIR = os.path.join(ROOT_DIR, 'SoftwarePostValid') +SW_PRE_URLS_VALID_DIR = os.path.join(ROOT_DIR, 'SoftwarePreUrlsValid') +SW_PRE_CONFIG_VALID_DIR = os.path.join(ROOT_DIR, 'SoftwarePreConfigValid') +SW_POST_STATE_VALID_DIR = os.path.join(ROOT_DIR, 'SoftwarePostStateValid') +SW_POST_SECURITY_VALID_DIR = os.path.join(ROOT_DIR, 'SoftwarePostSecurityValid') NW_LINKS_VALID_DIR = os.path.join(ROOT_DIR, 'NwLinksValid') +RES_MOD_VALID_DIR = os.path.join(ROOT_DIR, 'ResourceModelValid') # 'debug', 'info', 'warning', 'error', 'critical' VERBOSITY = 'warning' diff --git a/sdv/conf/01_swpreurlsvalid.conf b/sdv/conf/01_swpreurlsvalid.conf new file mode 100644 index 0000000..ddce229 --- /dev/null +++ b/sdv/conf/01_swpreurlsvalid.conf @@ -0,0 +1,24 @@ +# Copyright 2020 Spirent Communications. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not 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. + +# Modify this value to any Installer projects that have +# manifests (templates and configuration files) +SW_PRE_URLS_VALIDATOR = 'Airship' + +# Airship Specific configurations. +AIRSHIP_MANIFEST_URL = 'https://gerrit.opnfv.org/gerrit/airship' +AIRSHIP_MANIFEST_BRANCH = 'master' +AIRSHIP_MANIFEST_DOWNLOAD_PATH = '/tmp' +AIRSHIP_MANIFEST_SITE_NAME = 'intel-pod10' +AIRSHIP_TREASUREMAP_VERSION = 'v1.7' diff --git a/sdv/conf/01_swprevalid.conf b/sdv/conf/01_swprevalid.conf deleted file mode 100644 index 46043ce..0000000 --- a/sdv/conf/01_swprevalid.conf +++ /dev/null @@ -1,33 +0,0 @@ - -# Modify this value to any Installer projects that have -# manifests (templates and configuration files) -SW_PRE_VALIDATOR = 'Airship' - -# Mandatory Requirements [ Configuration Check ] -OPENSTACK_VERSION = 'ocata' -OPERATING_SYSTEM = 'centos' -OS_VERSION_NAME = 'xenial' -HUGEPAGES_SIZE = '1G' -HUGEPAGES_COUNT = 32 -OPENSTACK_CUSTOM_SERVICE_LIST = ['barbican', 'sahara'] -VIRTUAL_SWITCH_COMPUTE = 'ovs' -VIRTUAL_SWITCH_VERSION = '2.9.2' -BOOTSTRAP_PROTOCOL = 'pxe' -CPU_ISOLATION = '2-19,22-39' - -# Airship Specific configurations. -AIRSHIP_MANIFEST_URL = 'https://gerrit.opnfv.org/gerrit/airship' -AIRSHIP_MANIFEST_BRANCH = 'master' -AIRSHIP_MANIFEST_DOWNLOAD_PATH = '/tmp' -AIRSHIP_MANIFEST_SITE_NAME = 'intel-pod10' -AIRSHIP_TREASUREMAP_VERSION = 'v1.7' - - -# Optional Requirements [Could be Installer Specific ] -OVS_DPDK_ARGUMENTS = 'test' -OVERCLOUD_LOGGING_CLIENT = 'fluentd' -OVERCLOUD_MONITORING_CLIENT = 'collectd' -LMA_SERVER_MONITORING = 'prometheus' -LMA_SERVER_LOGGING = 'efk' -OPENSTACK_CONTAINER_ORCHESTRATION = 'kubernetes' -AIRSHIP_MANIFEST_VERSION = 1.7 diff --git a/sdv/conf/02_swpostvalid.conf b/sdv/conf/02_swpostvalid.conf deleted file mode 100644 index 1ed9279..0000000 --- a/sdv/conf/02_swpostvalid.conf +++ /dev/null @@ -1,4 +0,0 @@ - -# Modify this value to any Installer projects that have -# manifests (templates and configuration files) -SW_POST_VALIDATOR = 'Airship' diff --git a/sdv/conf/02_swpreconfigvalid.conf b/sdv/conf/02_swpreconfigvalid.conf new file mode 100644 index 0000000..bbadfcc --- /dev/null +++ b/sdv/conf/02_swpreconfigvalid.conf @@ -0,0 +1,20 @@ +# Copyright 2020 Spirent Communications. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not 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. + +SW_PRE_CONFIG_VALIDATOR = 'ConfVal' +MANIFEST_URL = "" +MANIFEST_DIR = "" +PDF_FILE_URL = "" +PDF_FILE_PATH = "" +INSTALLER = "Airship" diff --git a/sdv/conf/03_nwlinksvalid.conf b/sdv/conf/03_nwlinksvalid.conf deleted file mode 100644 index 6e83066..0000000 --- a/sdv/conf/03_nwlinksvalid.conf +++ /dev/null @@ -1 +0,0 @@ -NW_LINKS_VALIDATOR = 'lldpd' diff --git a/sdv/conf/03_swpoststatevalid.conf b/sdv/conf/03_swpoststatevalid.conf new file mode 100644 index 0000000..c98ed98 --- /dev/null +++ b/sdv/conf/03_swpoststatevalid.conf @@ -0,0 +1,26 @@ +# Copyright 2020 Spirent Communications. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not 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. + +SW_POST_STATE_VALIDATOR = 'Airship' + +# For the K8S based deployment Type +CLUSTER_INFO_FILE_PATH = "" +CLUSTER_ACCESS_FILE_PATH = "" + +# For Containers-without K8S and VMs based Deployment. +OVERCLOUD_INFO_FILE_PATH = "" +OVERCLOUD_ACCESS_FILE_PATH = "" + +# Any validation specific information is added in this file. +VALIDATION_CONFIG_FILE_PATH = "" diff --git a/sdv/conf/04_swpostsecurityvalid.conf b/sdv/conf/04_swpostsecurityvalid.conf new file mode 100644 index 0000000..5482612 --- /dev/null +++ b/sdv/conf/04_swpostsecurityvalid.conf @@ -0,0 +1,16 @@ +# Copyright 2020 Spirent Communications. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not 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. +# + +SW_POST_SECURITY_VALIDATOR = 'Airship' diff --git a/sdv/conf/05_nwlinksvalid.conf b/sdv/conf/05_nwlinksvalid.conf new file mode 100644 index 0000000..755e623 --- /dev/null +++ b/sdv/conf/05_nwlinksvalid.conf @@ -0,0 +1,15 @@ +# Copyright 2020 Spirent Communications. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not 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. + +NW_LINKS_VALIDATOR = 'lldpd' diff --git a/sdv/conf/06_resmodvalid.conf b/sdv/conf/06_resmodvalid.conf new file mode 100644 index 0000000..9a1a110 --- /dev/null +++ b/sdv/conf/06_resmodvalid.conf @@ -0,0 +1,15 @@ +# Copyright 2020 Spirent Communications. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not 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. + +RES_MOD_VALIDATOR = 'custom' diff --git a/sdv/core/component_factory.py b/sdv/core/component_factory.py index 396aa28..813c6f2 100644 --- a/sdv/core/component_factory.py +++ b/sdv/core/component_factory.py @@ -17,16 +17,31 @@ Create Components. """ -def create_swprevalidator(swprevalidator_class): - """ Create Pre-Validators""" - return swprevalidator_class() +def create_swpreurlsvalidator(swpreurlsvalidator_class): + """ Create Pre-Links Validators""" + return swpreurlsvalidator_class() -def create_swpostvalidator(swpostvalidator_class): - """ Create Post-Validators""" - return swpostvalidator_class() +def create_swpoststatevalidator(swpoststatevalidator_class): + """ Create Post-State Validators""" + return swpoststatevalidator_class() -def create_linkvalidator(linkprevalidator_class): - """ Create Link-Validators""" - return linkprevalidator_class() +def create_nwlinksvalidator(nwlinksvalidator_class): + """ Create NW Link-Validators""" + return nwlinksvalidator_class() + + +def create_swpreconfigvalidator(swpreconfigvalidator_class): + """ Create Pre-Config Validators""" + return swpreconfigvalidator_class() + + +def create_swpostsecurityvalidator(swpostsecurityvalidator_class): + """ Create Post-Security Validators""" + return swpostsecurityvalidator_class() + + +def create_resmodvalidator(resmodvalidator_class): + """ Create Resource-Model Validators""" + return resmodvalidator_class() diff --git a/sdv/core/loader/loader.py b/sdv/core/loader/loader.py index c9f8e96..8840f26 100644 --- a/sdv/core/loader/loader.py +++ b/sdv/core/loader/loader.py @@ -19,9 +19,12 @@ Implementors, please inherit from this class. from conf import settings from core.loader.loader_servant import LoaderServant -from SoftwarePreValid.swprevalidator import ISwPreValidator -from SoftwarePostValid.swpostvalidator import ISwPostValidator +from SoftwarePreUrlsValid.swpreurlsvalidator import ISwPreUrlsValidator +from SoftwarePreConfigValid.swpreconfigvalidator import ISwPreConfigValidator +from SoftwarePostStateValid.swpoststatevalidator import ISwPostStateValidator +from SoftwarePostSecurityValid.swpostsecurityvalidator import ISwPostSecurityValidator from NwLinksValid.nwlinksvalidator import INwLinksValidator +from ResourceModelValid.resmodvalidator import IResModValidator # pylint: disable=too-many-public-methods @@ -37,70 +40,134 @@ class Loader(): created. It is up to creator to maintain object life cycle if this behavior is unwanted. """ - self._swprevalidator_loader = LoaderServant( - settings.getValue('SW_PRE_VALID_DIR'), - settings.getValue('SW_PRE_VALIDATOR'), - ISwPreValidator) - self._swpostvalidator_loader = LoaderServant( - settings.getValue('SW_POST_VALID_DIR'), - settings.getValue('SW_POST_VALIDATOR'), - ISwPostValidator) + self._swpreurlsvalidator_loader = LoaderServant( + settings.getValue('SW_PRE_URLS_VALID_DIR'), + settings.getValue('SW_PRE_URLS_VALIDATOR'), + ISwPreUrlsValidator) + self._swpreconfigvalidator_loader = LoaderServant( + settings.getValue('SW_PRE_CONFIG_VALID_DIR'), + settings.getValue('SW_PRE_CONFIG_VALIDATOR'), + ISwPreConfigValidator) + self._swpoststatevalidator_loader = LoaderServant( + settings.getValue('SW_POST_STATE_VALID_DIR'), + settings.getValue('SW_POST_STATE_VALIDATOR'), + ISwPostStateValidator) + self._swpostsecurityvalidator_loader = LoaderServant( + settings.getValue('SW_POST_SECURITY_VALID_DIR'), + settings.getValue('SW_POST_SECURITY_VALIDATOR'), + ISwPostSecurityValidator) self._nwlinksvalidator_loader = LoaderServant( settings.getValue('NW_LINKS_VALID_DIR'), settings.getValue('NW_LINKS_VALIDATOR'), INwLinksValidator) + self._resmodvalidator_loader = LoaderServant( + settings.getValue('RES_MOD_VALID_DIR'), + settings.getValue('RES_MOD_VALIDATOR'), + IResModValidator) - def get_swprevalidator(self): + def get_swpreurlsvalidator(self): """ Returns a new instance configured Software Validator - :return: ISwPreValidator implementation if available, None otherwise + :return: ISwPreUrlsValidator implementation if available, None otherwise """ - return self._swprevalidator_loader.get_class()() + return self._swpreurlsvalidator_loader.get_class()() - def get_swprevalidator_class(self): + def get_swpreurlsvalidator_class(self): """Returns type of currently configured Software Validator. - :return: Type of ISwPreValidator implementation if available. + :return: Type of ISwPreUrlsValidator implementation if available. None otherwise. """ - return self._swprevalidator_loader.get_class() + return self._swpreurlsvalidator_loader.get_class() - def get_swprevalidators(self): + def get_swpreurlsvalidators(self): """ Get Prevalidators """ - return self._swprevalidator_loader.get_classes() + return self._swpreurlsvalidator_loader.get_classes() - def get_swprevalidators_printable(self): + def get_swpreurlsvalidators_printable(self): """ Get Prevalidators for printing """ - return self._swprevalidator_loader.get_classes_printable() + return self._swpreurlsvalidator_loader.get_classes_printable() - def get_swpostvalidator(self): + def get_swpreconfigvalidator(self): """ Returns a new instance configured Software Validator - :return: ISwPostValidator implementation if available, None otherwise + :return: ISwPreConfigValidator implementation if available, None otherwise """ - return self._swpostvalidator_loader.get_class()() + return self._swpreconfigvalidator_loader.get_class()() - def get_swpostvalidator_class(self): + def get_swpreconfigvalidator_class(self): """Returns type of currently configured Software Validator. - :return: Type of ISwPostValidator implementation if available. + :return: Type of ISwPreConfigValidator implementation if available. None otherwise. """ - return self._swpostvalidator_loader.get_class() + return self._swpreconfigvalidator_loader.get_class() - def get_swpostvalidators(self): + def get_swpreconfigvalidators(self): + """ + Get Prevalidators + """ + return self._swpreconfigvalidator_loader.get_classes() + + def get_swpreconfigvalidators_printable(self): + """ + Get Prevalidators for printing + """ + return self._swpreconfigvalidator_loader.get_classes_printable() + + def get_swpoststatevalidator(self): + """ Returns a new instance configured Software Validator + :return: ISwPostStateValidator implementation if available, None otherwise + """ + return self._swpoststatevalidator_loader.get_class()() + + def get_swpoststatevalidator_class(self): + """Returns type of currently configured Software Validator. + + :return: Type of ISwPostStateValidator implementation if available. + None otherwise. + """ + return self._swpoststatevalidator_loader.get_class() + + def get_swpoststatevalidators(self): + """ + Get Postvalidators + """ + return self._swpoststatevalidator_loader.get_classes() + + def get_swpoststatevalidators_printable(self): + """ + Get Postvalidators for printing + """ + return self._swpoststatevalidator_loader.get_classes_printable() + + def get_swpostsecurityvalidator(self): + """ Returns a new instance configured Software Validator + :return: ISwPostSecurityValidator implementation if available, None otherwise + """ + return self._swpostsecurityvalidator_loader.get_class()() + + def get_swpostsecurityvalidator_class(self): + """Returns type of currently configured Software Validator. + + :return: Type of ISwPostSecurityValidator implementation if available. + None otherwise. + """ + return self._swpostsecurityvalidator_loader.get_class() + + def get_swpostsecurityvalidators(self): """ Get Postvalidators """ - return self._swpostvalidator_loader.get_classes() + return self._swpostsecurityvalidator_loader.get_classes() - def get_swpostvalidators_printable(self): + def get_swpostsecurityvalidators_printable(self): """ Get Postvalidators for printing """ - return self._swpostvalidator_loader.get_classes_printable() + return self._swpostsecurityvalidator_loader.get_classes_printable() def get_nwlinksvalidator(self): """ Returns a new instance configured Nw-Links Validator @@ -116,14 +183,40 @@ class Loader(): """ return self._nwlinksvalidator_loader.get_class() - def get_nwlinkvalidators(self): + def get_nwlinksvalidators(self): """ Get Linkvalidators """ return self._nwlinksvalidator_loader.get_classes() - def get_nwlinkvalidators_printable(self): + def get_nwlinksvalidators_printable(self): """ Get Linkvalidators for printing """ return self._nwlinksvalidator_loader.get_classes_printable() + + def get_resmodvalidator(self): + """ Returns a new instance configured Nw-Links Validator + :return: IResModValidator implementation if available, None otherwise + """ + return self._resmodvalidator_loader.get_class()() + + def get_resmodvalidator_class(self): + """Returns type of currently configured Nw-Links Validator. + + :return: Type of ResModValidator implementation if available. + None otherwise. + """ + return self._resmodvalidator_loader.get_class() + + def get_resmodvalidators(self): + """ + Get ResoureModelValidators + """ + return self._resmodvalidator_loader.get_classes() + + def get_resmodvalidators_printable(self): + """ + Get ResoureModelValidators for printing + """ + return self._resmodvalidator_loader.get_classes_printable() diff --git a/sdv/valid b/sdv/valid index 1a9a252..e06afdd 100755 --- a/sdv/valid +++ b/sdv/valid @@ -42,21 +42,46 @@ def parse_arguments(): """ Parse command line arguments. """ + class _SplitValidationTypesAction(argparse.Action): + """ + Parse and split '--test-params' arguments. + + This expects either a single list validation types + e.g: --validation-type 'configuration, state' + """ + def __call__(self, parser, namespace, values, option_string=None): + values = values.strip() + input_list = values.split(',') + print(input_list) + parameter_list = [] + for vtype in input_list: + vtype = vtype.strip() + if vtype: + vtype = vtype.lower() + parameter_list.append(str(vtype)) + # results = {'_PARAMS_LIST':parameter_list} + setattr(namespace, self.dest, parameter_list) + parser = argparse.ArgumentParser(prog=__file__, formatter_class= argparse.ArgumentDefaultsHelpFormatter) parser.add_argument('--version', action='version', version='%(prog)s 0.1') parser.add_argument('--list-validations', action='store_true', help='list all validations') - parser.add_argument('--list-swpredepv', action='store_true', - help='list all Software pre-dep validations and exit') - parser.add_argument('--list-swpostdepv', action='store_true', - help='list all Software post-dep validations and exit') - parser.add_argument('--list-nwlinksv', action='store_true', - help='list all Link validations and exit') - parser.add_argument('exact_validation_name', nargs='*', help='Exact names of\ - validations to run. E.g "valid nwlinks"\ - runs only nwlink-validations.\ - To run all omit positional arguments') + parser.add_argument('--list-vurls', action='store_true', + help='list all Software pre-dep Hyperlinks validations and exit') + parser.add_argument('--list-vconfig', action='store_true', + help='list all Software pre-dep Configuration validations and exit') + parser.add_argument('--list-vstate', action='store_true', + help='list all Software post-dep State validations and exit') + parser.add_argument('--list-vsecurity', action='store_true', + help='list all Software post-dep Security validations and exit') + parser.add_argument('--list-vnwlinks', action='store_true', + help='list all Network-Links validations and exit') + parser.add_argument('--list-vresmod', action='store_true', + help='list all Resource-Model validations and exit') + parser.add_argument('--validation', action=_SplitValidationTypesAction, + help='The type of Validation to perform - resmod, nwlinks,\ + urls, configuration, state, security') args = vars(parser.parse_args()) return args @@ -89,24 +114,72 @@ def handle_list_options(args): :param args: A dictionary with all CLI arguments """ - if args['list_swpredepv']: - print(Loader().get_swprevalidators_printable()) + if args['list_vurls']: + print(Loader().get_swpreurlsvalidators_printable()) sys.exit(0) - if args['list_swpostdepv']: - print(Loader().get_swpostvalidators_printable()) + if args['list_vconfig']: + print(Loader().get_swpreconfigvalidators_printable()) sys.exit(0) - if args['list_nwlinksv']: - print(Loader().get_nwlinkvalidators_printable()) + if args['list_vstate']: + print(Loader().get_swpoststatevalidators_printable()) sys.exit(0) + if args['list_vsecurity']: + print(Loader().get_swpostsecurityvalidators_printable()) + sys.exit(0) + + if args['list_vnwlinks']: + print(Loader().get_nwlinksvalidators_printable()) + sys.exit(0) + + +# Sflo: questions/3041986/apt-command-line-interface-like-yes-no-input +def sanity_check(question, default="yes"): + """Ask a yes/no question via raw_input() and return their answer. + + "question" is a string that is presented to the user. + "default" is the presumed answer if the user just hits . + It must be "yes" (the default), "no" or None (meaning + an answer is required of the user). + + The "answer" return value is True for "yes" or False for "no". + """ + valid = {"yes": True, "y": True, "ye": True, + "no": False, "n": False} + if default is None: + prompt = " [y/n] " + elif default == "yes": + prompt = " [Y/n] " + elif default == "no": + prompt = " [y/N] " + else: + raise ValueError("invalid default answer: '%s'" % default) + + while True: + sys.stdout.write(question + prompt) + choice = input().lower() + if default is not None and choice == '': + return valid[default] + elif choice in valid: + return valid[choice] + else: + sys.stdout.write("Please respond with 'yes' or 'no' " + "(or 'y' or 'n').\n") + def main(): """Main function. """ args = parse_arguments() + if not sanity_check("Have you configured the testcases ?"): + print("Please configure testcases and rerun") + sys.exit(1) + + print(args) + # define the timestamp to be used by logs and results date = datetime.datetime.fromtimestamp(time.time()) timestamp = date.strftime('%Y-%m-%d_%H-%M-%S') @@ -129,18 +202,74 @@ def main(): configure_logging(settings.getValue('VERBOSITY')) loader = Loader() - swprevalidators = loader.get_swprevalidators() - if settings.getValue('SW_PRE_VALIDATOR') not in swprevalidators: - _LOGGER.error('There are no swvalidators matching \'%s\' found in' - ' \'%s\'. Exiting...', settings.getValue('SW_PRE_VALIDATOR'), - settings.getValue('SW_PRE_VALID_DIR')) - sys.exit(1) - swv_pre_ctrl = component_factory.create_swprevalidator( - loader.get_swprevalidator_class()) - # First validate hyperlinks - swv_pre_ctrl.validate_hyperlinks() - # Next validate mandatory configuration - swv_pre_ctrl.validate_configuration_mandatory() + validations = settings.getValue('VALIDATIONS') + + # Get the Validation Types. + if args['validation']: + validations = args.validation_type + + validator_objs = [] + for validation in validations: + if 'urls' in validation: + validators = loader.get_swpreurlsvalidators() + if settings.getValue('SW_PRE_URLS_VALIDATOR') not in validators: + _LOGGER.error('There are no urls validators matching \'%s\' found in' + ' \'%s\'. Exiting...', settings.getValue('SW_PRE_URLS_VALIDATOR'), + settings.getValue('SW_PRE_URLS_VALID_DIR')) + sys.exit(1) + validator_ctrl = component_factory.create_swpreurlsvalidator( + loader.get_swpreurlsvalidator_class()) + validator_objs.append(validator_ctrl) + if 'configuration' in validation: + validators = loader.get_swpreconfigvalidators() + if settings.getValue('SW_PRE_CONFIG_VALIDATOR') not in validators: + _LOGGER.error('There are no configvalidators matching \'%s\' found in' + ' \'%s\'. Exiting...', settings.getValue('SW_PRE_CONFIG_VALIDATOR'), + settings.getValue('SW_PRE_CONFIG_VALID_DIR')) + sys.exit(1) + validator_ctrl = component_factory.create_swpreconfigvalidator( + loader.get_swpreconfigvalidator_class()) + validator_objs.append(validator_ctrl) + if 'state' in validation: + validators = loader.get_swpoststatevalidators() + if settings.getValue('SW_POST_STATE_VALIDATOR') not in validators: + _LOGGER.error('There are no statevalidators matching \'%s\' found in' + ' \'%s\'. Exiting...', settings.getValue('SW_POST_STATE_VALIDATOR'), + settings.getValue('SW_POST_STATE_VALID_DIR')) + sys.exit(1) + validator_ctrl = component_factory.create_swpoststatevalidator( + loader.get_swpoststatevalidator_class()) + validator_objs.append(validator_ctrl) + if 'security' in validation: + validators = loader.get_swpostsecurityvalidators() + if settings.getValue('SW_POST_SECURITY_VALIDATOR') not in validators: + _LOGGER.error('There are no securityvalidators matching \'%s\' found in' + ' \'%s\'. Exiting...', settings.getValue('SW_POST_SECURITY_VALIDATOR'), + settings.getValue('SW_POST_SECURITY_VALID_DIR')) + sys.exit(1) + validator_ctrl = component_factory.create_swpostsecurityvalidator( + loader.get_swpostsecurityvalidator_class()) + validator_objs.append(validator_ctrl) + if 'nwlinks' in validation: + validators = loader.get_nwlinksvalidators() + if settings.getValue('NW_LINKS_VALIDATOR') not in validators: + _LOGGER.error('There are no nwlinksvalidators matching \'%s\' found in' + ' \'%s\'. Exiting...', settings.getValue('NW_LINKS_VALIDATOR'), + settings.getValue('NW_LINKS_VALID_DIR')) + sys.exit(1) + validator_ctrl = component_factory.create_nwlinksvalidator( + loader.get_nwlinksvalidator_class()) + validator_objs.append(validator_ctrl) + if 'resmod' in validation: + validators = loader.get_resmodvalidators() + if settings.getValue('RES_MOD_VALIDATOR') not in validators: + _LOGGER.error('There are no resmodvalidators matching \'%s\' found in' + ' \'%s\'. Exiting...', settings.getValue('RES_MOD_VALIDATOR'), + settings.getValue('RES_MOD_VALID_DIR')) + sys.exit(1) + validator_ctrl = component_factory.create_resmodvalidator( + loader.get_resmodvalidator_class()) + validator_objs.append(validator_ctrl) if __name__ == "__main__": -- cgit 1.2.3-korg