diff options
author | 2021-09-20 12:45:42 +0530 | |
---|---|---|
committer | 2021-09-20 12:47:36 +0530 | |
commit | bfd37762bdf91a7f89d4ebc259454ddb2f5e7b3d (patch) | |
tree | dba519dd11f94e216079c65d43e4166cf8c5fe5a /sdv/SoftwarePreUrlsValid | |
parent | 43c4b47a9e0d64ffdaa77a743f0be388f49eb558 (diff) |
Cleanup-Update: Remove unused code and update PDF
This patch removes unused code and update the pdf.
Signed-off-by: Sridhar K. N. Rao <sridhar.rao@spirent.com>
Change-Id: I9785c4301869f7b93ccad074cf0ad6ffc77724a0
Diffstat (limited to 'sdv/SoftwarePreUrlsValid')
-rwxr-xr-x | sdv/SoftwarePreUrlsValid/__init__.py | 19 | ||||
-rw-r--r-- | sdv/SoftwarePreUrlsValid/airship.py | 155 | ||||
-rw-r--r-- | sdv/SoftwarePreUrlsValid/swpreurlsvalidator.py | 34 |
3 files changed, 0 insertions, 208 deletions
diff --git a/sdv/SoftwarePreUrlsValid/__init__.py b/sdv/SoftwarePreUrlsValid/__init__.py deleted file mode 100755 index c1f68ac..0000000 --- a/sdv/SoftwarePreUrlsValid/__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 SoftwarePreUrlsValid.swpreurlsvalidator import * diff --git a/sdv/SoftwarePreUrlsValid/airship.py b/sdv/SoftwarePreUrlsValid/airship.py deleted file mode 100644 index 324eaf1..0000000 --- a/sdv/SoftwarePreUrlsValid/airship.py +++ /dev/null @@ -1,155 +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 -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 deleted file mode 100644 index 31604ee..0000000 --- a/sdv/SoftwarePreUrlsValid/swpreurlsvalidator.py +++ /dev/null @@ -1,34 +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 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.') |