From b189119586d1d3cf176c31402daa4b34830ec48b Mon Sep 17 00:00:00 2001 From: not4win Date: Tue, 18 Aug 2020 21:20:37 +0530 Subject: sdv-prevalidation: added src, mapping, documentation, Dockerfile, and server files Signed-off-by: Ashwin Nayak Change-Id: I81ae24169a5f8ff79d2c129f30daf5c9f04e5da9 --- sdv/docker/sdvconfig/validation/__init__.py | 24 +++ sdv/docker/sdvconfig/validation/hardware.py | 214 ++++++++++++++++++++++++ sdv/docker/sdvconfig/validation/info.py | 202 +++++++++++++++++++++++ sdv/docker/sdvconfig/validation/network.py | 242 ++++++++++++++++++++++++++++ sdv/docker/sdvconfig/validation/platform.py | 93 +++++++++++ sdv/docker/sdvconfig/validation/software.py | 159 ++++++++++++++++++ sdv/docker/sdvconfig/validation/storage.py | 160 ++++++++++++++++++ 7 files changed, 1094 insertions(+) create mode 100644 sdv/docker/sdvconfig/validation/__init__.py create mode 100644 sdv/docker/sdvconfig/validation/hardware.py create mode 100644 sdv/docker/sdvconfig/validation/info.py create mode 100644 sdv/docker/sdvconfig/validation/network.py create mode 100644 sdv/docker/sdvconfig/validation/platform.py create mode 100644 sdv/docker/sdvconfig/validation/software.py create mode 100644 sdv/docker/sdvconfig/validation/storage.py (limited to 'sdv/docker/sdvconfig/validation') diff --git a/sdv/docker/sdvconfig/validation/__init__.py b/sdv/docker/sdvconfig/validation/__init__.py new file mode 100644 index 0000000..7554676 --- /dev/null +++ b/sdv/docker/sdvconfig/validation/__init__.py @@ -0,0 +1,24 @@ +#!/usr/bin/env python + +# Copyright (C) 2020 Ashwin Nayak +# +# 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. + +""" validation package """ + +from .hardware import HardwareValidation +from .info import InfoValidation +from .network import NetworkValidation +from .platform import PlatformValidation +from .software import SoftwareValidation +from .storage import StorageValidation diff --git a/sdv/docker/sdvconfig/validation/hardware.py b/sdv/docker/sdvconfig/validation/hardware.py new file mode 100644 index 0000000..b01d871 --- /dev/null +++ b/sdv/docker/sdvconfig/validation/hardware.py @@ -0,0 +1,214 @@ +#!/usr/bin/env python + +# Copyright (C) 2020 Ashwin Nayak +# +# 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. + +# pylint: disable=too-many-instance-attributes + +""" program which validates hardware profile """ + + +class HardwareValidation(): + """ perform hardware validation """ + + def __init__(self, json, value, manifest, logger): + # store external values + self.role = "global" + self.json = json + self.value = value + self.logger = logger + # initialize internal values + self.right = 0 + self.wrong = 0 + self.total = 0 + self.result = "" + # initialization functions + self.manifest = manifest + self.validate_hardware() + + def get_values(self): + """ return set of right wrong and total """ + return self.right, self.wrong, self.total, self.result + + def comparison(self, key, profile, pdf_val, man_val): + """ do comparison and print results""" + self.total += 1 + self.logger.debug("key:%s, profile:%s, pdf_val:%s, man_val:%s, role:%s", + key, profile, pdf_val, man_val, self.role) + + if pdf_val == "": + self.result += ("No value exists for pdf-key:{} of profile:{} and role:{}\n"\ + .format(key, profile, self.role)) + elif man_val == []: + self.result += ("No value exists for manifest-key:{} of profile:{} and role:{}\n"\ + .format(key, profile, self.role)) + elif str(pdf_val) not in man_val: + self.result += ( + "The pdf and manifest values do not match for key:{} profile:{} role:{}\n".format( + key, profile, self.role)) + self.result += ("the pdf val:{} and manifest val:{}\n".format(pdf_val, man_val)) + self.wrong += 1 + else: + self.result += ( + "The pdf and manifest values do match for key:{} profile:{} role:{}\n".format( + key, profile, self.role)) + self.right += 1 + + def validate_bios_profile(self, value): + """ validate bios profile """ + val = "" + profile = 'bios_profile' + keys = [ + 'bios_version', + 'bios_mode', + 'bootstrap_proto', + 'hyperthreading_enabled', + 'bios_setting'] + + self.logger.info("Starting with the validation of bios profile name:%s", value) + + for key in self.json[profile]: + if key["profile_name"] == value: + val = key + break + + if val == "": + self.logger.error("Not able to find bios profile name: %s", value) + else: + for key in keys: + try: + temp1 = val[key] + temp2 = self.manifest.find_val(self.role, profile, key) + self.comparison(key, profile, temp1, temp2) + except KeyError: + self.logger.error("Not able to find key: %s in bios profile: %s", key, value) + + self.logger.info("Completed with the validation of bios profile name:%s", value) + + def validate_processor_profile(self, value): + """ validate processor profile """ + val = "" + profile = 'processor_profiles' + keys = ['speed', 'model', 'architecture'] + + self.logger.info("Starting with the validation of processor profile:%s", value) + + for key in self.json[profile]: + if key["profile_name"] == self.value: + val = key + break + + if val == "": + self.logger.error("Not able to find processor profile name: %s", value) + else: + val = val["profile_info"] + for key in keys: + try: + temp1 = val[key] + temp2 = self.manifest.find_val(self.role, profile, key) + self.comparison(key, profile, temp1, temp2) + except KeyError: + self.logger.error( + "Not able to find key: %s in processor profile: %s", key, value) + self.logger.info("Completed with the validation of processor profile:%s", value) + + def validate_disks_profile(self, value): + """ validate disks profile """ + val = "" + profile = 'disks_profiles' + keys = ['address', 'dev_type', 'rotation', 'bus'] + + self.logger.info("Starting with the validation of disks profile:%s", value) + + for key in self.json[profile]: + if key["profile_name"] == self.value: + val = key + break + + if val == "": + self.logger.error("Not able to find disk profile name: %s", value) + else: + val = val["profile_info"] + for vals in val: + for key in keys: + try: + temp1 = vals[key] + temp2 = self.manifest.find_val(self.role, profile, key) + self.comparison(key, profile, temp1, temp2) + except KeyError: + self.logger.error( + "Not able to find key: %s in disk profile: %s", key, value) + self.logger.info("Completed with the validation of disks profile:%s", value) + + def validate_nic_profile(self, value): + """ validate nic profile """ + val = "" + profile = 'nic_profiles' + keys = ['address', 'dev_type', 'bus', 'sriov_capable', 'numa_id'] + + self.logger.info("Starting with the validation of nic profile:%s", value) + + for key in self.json[profile]: + if key["profile_name"] == self.value: + val = key + break + + if val == "": + self.logger.error("Not able to find nic profile name: %s", value) + else: + val = val["profile_info"] + + for vals in val: + for key in keys: + try: + temp1 = vals[key] + temp2 = self.manifest.find_val(self.role, profile, key) + self.comparison(key, profile, temp1, temp2) + except KeyError: + self.logger.error("Not able to find key: %s in nic profile: %s", key, value) + self.logger.info("Completed with the validation of nic profile:%s", value) + + def validate_hardware(self): + """ validate hardware """ + # find hardware profile with given key + val = "" + profile = 'hardware_profiles' + keys = ['manufacturer', 'model', 'generation', 'memory'] + + self.logger.info("Starting with the validation of hardware profile:%s", self.value) + + for key in self.json[profile]: + if key["profile_name"] == self.value: + val = key + break + + if val == "": + self.logger.error("Not able to find hardware profile name: %s", self.value) + else: + val = val["profile_info"] + + for key in keys: + try: + temp1 = val[key] + temp2 = self.manifest.find_val(self.role, profile, key) + self.comparison(key, profile, temp1, temp2) + except KeyError: + self.logger.error( + "Not able to find key: %s in hardware profile: %s", key, self.value) + self.logger.info("Completed with the validation of hardware profile:%s", self.value) + + self.validate_bios_profile(val["bios_profile"]) + self.validate_processor_profile(val["processor_profile"]) + self.validate_disks_profile(val["disks_profile"]) + self.validate_nic_profile(val["nics_profile"]) diff --git a/sdv/docker/sdvconfig/validation/info.py b/sdv/docker/sdvconfig/validation/info.py new file mode 100644 index 0000000..2d2b498 --- /dev/null +++ b/sdv/docker/sdvconfig/validation/info.py @@ -0,0 +1,202 @@ +#!/usr/bin/env python + +# Copyright (C) 2020 Ashwin Nayak +# +# 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. + +# pylint: disable=too-many-instance-attributes, too-many-statements + +""" validate general info of pdf """ + + +class InfoValidation(): + """ perform hardware validation """ + + def __init__(self, json, manifest, logger): + # store external state + self.role = 'masters' + self.json = json + self.logger = logger + self.manifest = manifest + # initialize internal state + self.right = 0 + self.wrong = 0 + self.total = 0 + self.result = "" + # initialization function + self.validate() + + def get_values(self): + """ return set of right wrong and total """ + return self.right, self.wrong, self.total, self.result + + def comparison(self, key, profile, pdf_val, man_val): + """ do comparison and print results""" + self.total += 1 + self.logger.debug("key:%s, profile:%s, pdf_val:%s, man_val:%s, role:%s", + key, profile, pdf_val, man_val, self.role) + + if pdf_val == "": + self.result += ("No value exists for pdf-key:{} of profile:{} and role:{}\n"\ + .format(key, profile, self.role)) + elif man_val == []: + self.result += ("No value exists for manifest-key:{} of profile:{} and role:{}\n"\ + .format(key, profile, self.role)) + elif str(pdf_val) not in man_val: + self.result += ( + "The pdf and manifest values do not match for key:{} profile:{} role:{}\n".format( + key, profile, self.role)) + self.result += ("the pdf val:{} and manifest val:{}\n".format(pdf_val, man_val)) + self.wrong += 1 + else: + self.result += ( + "The pdf and manifest values do match for key:{} profile:{} role:{}\n".format( + key, profile, self.role)) + self.right += 1 + + def validate(self): + """ validate all infos """ + self.logger.info("starting info validation") + val = "" + profile = 'management_info' + keys = ['owner', 'area_name', 'area_center_name', 'room_id', 'city', 'resource_pool_name'] + + val = self.json[profile] + + for key in keys: + temp1 = val[key] + temp2 = self.manifest.find_val(self.role, profile, key) + self.comparison(key, profile, temp1, temp2) + + val = "" + profile = 'ntp_info' + keys = ['primary_ip', 'primary_zone', 'secondary_ip', 'secondary_zone'] + + val = self.json[profile] + + for key in keys: + temp1 = val[key] + temp2 = self.manifest.find_val(self.role, profile, key) + self.comparison(key, profile, temp1, temp2) + + val = "" + profile = 'syslog_info' + keys = ["server_ip", "transport"] + + val = self.json[profile] + + for key in keys: + temp1 = val[key] + temp2 = self.manifest.find_val(self.role, profile, key) + self.comparison(key, profile, temp1, temp2) + + # val = "" + # profile = 'ldap_info' + # keys = ["base_url", "url", "auth_path", "common_name", "subdomain", "domain"] + + # val = self.json[profile] + # for key in keys: + # temp1 = val[key] + # temp2 = self.manifest.find_val(self.role, profile, key) + # self.comparison(key, profile, temp1, temp2) + + val = "" + profile = 'proxy_info' + keys = ["address", "port", "user", "password"] + + val = self.json[profile] + for key in keys: + temp1 = val[key] + temp2 = self.manifest.find_val(self.role, profile, key) + self.comparison(key, profile, temp1, temp2) + + val = "" + profile = 'vim_info' + keys = [ + "vim_name", + "vim_id", + "vendor", + "version", + "installer", + "deployment_style", + "container_orchestrator", + "storage_type"] + + val = self.json[profile] + + for key in keys: + temp1 = val[key] + temp2 = self.manifest.find_val(self.role, profile, key) + self.comparison(key, profile, temp1, temp2) + + val = "" + profile = 'deployment_info' + keys = [ + "high_availability", + "introspection", + "deployment_type", + "installer_used", + "workload_vnf", + "workload_cnf", + "sdn_controller", + "sdn_controller_version", + "sdn_controller_nbapps", + "vnfm", + "vnfm_version", + "data_plane_used", + "ironic_deploy_interface", + "external_storage_cluster", + "bl_str_connect_method", + "cpu_allocation_ratio"] + + val = self.json[profile] + + for key in keys: + temp1 = val[key] + temp2 = self.manifest.find_val(self.role, profile, key) + self.comparison(key, profile, temp1, temp2) + + val = "" + profile = 'jumphost_info' + keys = ["ip", "name"] + + val = self.json[profile] + + for key in keys: + temp1 = val[key] + temp2 = self.manifest.find_val(self.role, profile, key) + self.comparison(key, profile, temp1, temp2) + + # val = "" + # profile = 'rack_info.rack_details' + # keys = ["rack_name","rack_description", "raack_az"] + + # val = self.json["rack_info"]["rack_split"] + + # for key in keys: + # temp1 = val[key] + # temp2 = self.manifest.find_val(self.role, profile, key) + # self.comparison(key, profile, temp1, temp2) + + # val = "" + # profile = 'storage_cluster_info' + # keys = ["name", "cluster_type", "cluster_id", "auth_type", "username", "password", \ + # "certificate_location", "client_key", "public_cidr", "cluster_cidr"] + + # val = self.json[profile] + + # for key in keys: + # temp1 = val[key] + # temp2 = self.manifest.find_val(self.role, profile, key) + # self.comparison(key, profile, temp1, temp2) + self.logger.info("completing info validation") diff --git a/sdv/docker/sdvconfig/validation/network.py b/sdv/docker/sdvconfig/validation/network.py new file mode 100644 index 0000000..35c6b5d --- /dev/null +++ b/sdv/docker/sdvconfig/validation/network.py @@ -0,0 +1,242 @@ +#!/usr/bin/env python + +# Copyright (C) 2020 Ashwin Nayak +# +# 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. + +# pylint: disable=too-many-instance-attributes, too-many-arguments, too-many-branches + +""" program which validates network profile """ + + +class NetworkValidation(): + """ perform network validation """ + + def __init__(self, role, json, value, manifest, logger): + # store external state + self.role = role + self.json = json + self.value = value + self.logger = logger + self.manifest = manifest + # initialize internal state + self.right = 0 + self.wrong = 0 + self.total = 0 + self.result = "" + # initialization functions + self.validate_network() + + def get_values(self): + """ return set of right wrong and total """ + return self.right, self.wrong, self.total, self.result + + def comparison(self, key, profile, pdf_val, man_val, role): + """ do comparison and print results""" + self.total += 1 + self.logger.debug("key:%s, profile:%s, pdf_val:%s, man_val:%s, role:%s", + key, profile, pdf_val, man_val, role) + + if pdf_val == "": + self.result += ("No value exists for pdf-key:{} of profile:{} and role:{}\n"\ + .format(key, profile, role)) + elif man_val == []: + self.result += ("No value exists for manifest-key:{} of profile:{} and role:{}\n"\ + .format(key, profile, role)) + elif str(pdf_val) not in man_val: + self.result += ( + "The pdf and manifest values do not match for key:{} profile:{} role:{}\n".format( + key, profile, role)) + self.result += ("the pdf val:{} and manifest val:{}\n".format(pdf_val, man_val)) + self.wrong += 1 + else: + self.result += ( + "The pdf and manifest values do match for key:{} profile:{} role:{}\n".format( + key, profile, role)) + self.right += 1 + + def validate_networks(self, value): + """ validate network link """ + self.logger.info("Starting with the validation of networks profile:%s", value) + val = "" + profile = 'networks' + keys = [ + 'name', + 'tunnel_type', + 'tunnel_id', + 'tunnel_id_range', + 'mtu', + 'routedomain', + 'cidr', + 'dns', + 'v6_cidr'] + + self.logger.info("Starting with the validation of network profile:%s", value) + + for key in self.json[profile]: + if key["name"] == value: + val = key + break + + if val == "": + self.logger.error("Not able to find network profile name: %s", value) + else: + for key in keys: + try: + temp1 = val[key] + temp2 = self.manifest.find_val(value, profile, key) + self.comparison(key, profile, temp1, temp2, value) + except KeyError: + self.logger.error("Not able to find key: %s in network profile: %s", key, value) + + keys = ["name", "ip"] + + for item in val["vips"]: + for key in keys: + try: + temp1 = item[key] + temp2 = self.manifest.find_val(value, profile + '.vips', key) + self.comparison(key, profile, temp1, temp2, value) + except KeyError: + self.logger.error( + "Not able to find key: %s in network.vips profile: %s", key, value) + + keys = ["subnet", "gateway", "metric", "routedomain"] + + for item in val["routes"]: + for key in keys: + try: + temp1 = item[key] + temp2 = self.manifest.find_val(value, profile + '.routes', key) + self.comparison(key, profile, temp1, temp2, value) + except KeyError: + self.logger.error( + "Not able to find key: %s in network.routes profile: %s", key, value) + + keys = ["type", "start", "end"] + + for item in val["allocation_pools"]: + for key in keys: + try: + temp1 = item[key] + temp2 = self.manifest.find_val(value, profile + '.allocation_pools', key) + self.comparison(key, profile, temp1, temp2, value) + except KeyError: + self.logger.error( + "Not able to find key: %s in network.allocation_pools profile: %s"\ + , key, value) + + keys = ["type", "start", "end"] + + for item in val["v6_allocation_pools"]: + for key in keys: + try: + temp1 = item[key] + temp2 = self.manifest.find_val(value, profile + '.v6_allocation_pools', key) + self.comparison(key, profile, temp1, temp2, value) + except KeyError: + self.logger.error( + "Not able to find key: %s in network.v6_allocation_pools profile: %s"\ + , key, value) + self.logger.info("Completed with the validation of networks profile:%s", value) + + def validate_network_link(self, value): + """ validate network link """ + self.logger.info("Starting with the validation of network link:%s", value) + val = "" + profile = 'network_link' + keys = [ + 'name', + 'type', + 'bonding_mode', + 'mtu', + 'linkspeed', + 'trunking_mode', + 'trunking_default_nw', + 'vid', + 'vf_count'] + + self.logger.info("Starting with the validation of network link:%s", value) + + for key in self.json[profile]: + if key["name"] == value: + val = key + break + + if val == "": + self.logger.error("Not able to find network link name: %s", value) + else: + val = val["profile_info"] + + for key in keys: + try: + temp1 = val[key] + temp2 = self.manifest.find_val(value, profile, key) + self.comparison(key, profile, temp1, temp2, value) + except KeyError: + self.logger.error( + "Not able to find key: %s in network link profile: %s", key, value) + + keys = ["key", "value"] + + for key in keys: + try: + temp1 = val["metadata"][key] + temp2 = self.manifest.find_val(value, profile + '.metadata', key) + self.comparison(key, profile, temp1, temp2, value) + except KeyError: + self.logger.error( + "Not able to find key: %s in network link.metadata profile: %s", key, value) + + keys = ["name", "type"] + + for key in keys: + try: + temp1 = val["members"][key] + temp2 = self.manifest.find_val(value, profile + '.members', key) + self.comparison(key, profile, temp1, temp2, value) + except KeyError: + self.logger.error( + "Not able to find key: %s in network link.metadata profile: %s", key, value) + self.logger.info("completed with the validation of network link:%s", value) + + def validate_network(self): + """ validate network """ + # find in interface mapping profile with given key + val = "" + profile = 'interface_mapping_profiles' + + self.logger.info("Starting with the validation of interface mapping profile:%s", self.value) + + for key in self.json[profile]: + if key["profile_name"] == self.value: + val = key + break + + if val == "": + self.logger.error("Not able to find interface profile name: %s", self.value) + else: + val = val["profile_data"] + + for item in val: + try: + self.validate_network_link(item["interface_name"]) + self.logger.info("networks:%s", item["networks"]) + for smaller_item in item["networks"]: + self.validate_networks(smaller_item["name"]) + except KeyError: + self.logger.exception( + "Not able to find key in interface mapping profile profile:%s", self.value) + self.logger.info( + "Completed with the validation of interface mapping profile:%s", + self.value) diff --git a/sdv/docker/sdvconfig/validation/platform.py b/sdv/docker/sdvconfig/validation/platform.py new file mode 100644 index 0000000..9453505 --- /dev/null +++ b/sdv/docker/sdvconfig/validation/platform.py @@ -0,0 +1,93 @@ +#!/usr/bin/env python + +# Copyright (C) 2020 Ashwin Nayak +# +# 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. + +# pylint: disable=too-many-instance-attributes, too-many-arguments + +""" program which validates platform profile """ + + +class PlatformValidation(): + """ perform hardware validation """ + + def __init__(self, role, json, value, manifest, logger): + # store external values + self.role = role + self.json = json + self.value = value + self.logger = logger + self.manifest = manifest + # intialize internal values + self.right = 0 + self.wrong = 0 + self.total = 0 + self.result = "" + # initialization functions + self.validate() + + def get_values(self): + """ return set of right wrong and total """ + return self.right, self.wrong, self.total, self.result + + def comparison(self, key, profile, pdf_val, man_val): + """ do comparison and print results""" + self.total += 1 + self.logger.debug("key:%s, profile:%s, pdf_val:%s, man_val:%s, role:%s", + key, profile, pdf_val, man_val, self.role) + + if pdf_val == "": + self.result += ("No value exists for pdf-key:{} of profile:{} and role:{}\n"\ + .format(key, profile, self.role)) + elif man_val == []: + self.result += ("No value exists for manifest-key:{} of profile:{} and role:{}\n"\ + .format(key, profile, self.role)) + elif str(pdf_val) not in man_val: + self.result += ( + "The pdf and manifest values do not match for key:{} profile:{} role:{}\n".format( + key, profile, self.role)) + self.result += ("the pdf val:{} and manifest val:{}\n".format(pdf_val, man_val)) + self.wrong += 1 + else: + self.result += ( + "The pdf and manifest values do match for key:{} profile:{} role:{}\n".format( + key, profile, self.role)) + self.right += 1 + + def validate(self): + """ validate platform profile """ + val = "" + profile = 'platform_profiles' + keys = ['os', 'rt_kvm', 'kernel_version', 'kernel_parameters', 'isolated_cpus', + 'vnf_cores', + 'iommu', 'vswitch_daemon_cores', 'vswitch_type', 'vswitch_uio_driver', + 'vswitch_mem_channels', 'vswitch_socket_memory', 'vswitch_pmd_cores', + 'vswitch_dpdk_lcores', 'vswitch_dpdk_rxqs', 'vswitch_options'] + + for key in self.json[profile]: + if key["profile_name"] == self.value: + val = key + break + + if val == "": + self.logger.error("Not able to find platform profile name: %s", self.value) + else: + for key in keys: + try: + temp1 = val[key] + temp2 = self.manifest.find_val(self.role, profile, key) + self.comparison(key, profile, temp1, temp2) + except KeyError: + self.logger.error( + "Not able to find key: %s in platform profile: %s", key, self.value) diff --git a/sdv/docker/sdvconfig/validation/software.py b/sdv/docker/sdvconfig/validation/software.py new file mode 100644 index 0000000..9603a22 --- /dev/null +++ b/sdv/docker/sdvconfig/validation/software.py @@ -0,0 +1,159 @@ +#!/usr/bin/env python + +# Copyright (C) 2020 Ashwin Nayak +# +# 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. + +# pylint: disable=too-many-instance-attributes, too-many-arguments + +""" program which validates software profile """ + +import os + + +class SoftwareValidation(): + """ perform hardware validation """ + + def __init__(self, role, json, value, manifest, global_dir, type_dir, man_dir, logger): + # store external values + self.role = role + self.json = json + self.logger = logger + self.manifest = manifest + # initialize internal values + self.right = 0 + self.wrong = 0 + self.total = 0 + self.result = "" + self.software_list = [] + # intialization functions + self.get_software_list(global_dir, type_dir, man_dir) + self.validate(value) + + def get_software_list(self, global_dir, type_dir, man_dir): + """ get a list of all softwares by checking the global softwares, + type and site specific softwares used """ + dirs = [global_dir, type_dir, man_dir] + + try: + for direc in dirs: + for dirpath, dirnames, filenames in os.walk(direc): + for filename in [f for f in filenames if f.endswith(".yaml")]: + temp = filename.split('.')[0] + temp = temp.split('-')[0] + self.software_list.append(temp) + except FileNotFoundError: + self.logger.exception(" error in accessing dirs ") + raise + + def get_values(self): + """ return set of right wrong and total """ + return self.right, self.wrong, self.total, self.result + + def comparison(self, key, profile, pdf_val, man_val): + """ do comparison and print results""" + self.total += 1 + self.logger.debug("key:%s, profile:%s, pdf_val:%s, man_val:%s, role:%s", + key, profile, pdf_val, man_val, self.role) + + if pdf_val == "": + self.result += ("No value exists for pdf-key:{} of profile:{} and role:{}\n". + format(key, profile, self.role)) + elif man_val == []: + self.result += ("No value exists for manifest-key:{} of profile:{} and role:{}\n". + format(key, profile, self.role)) + elif str(pdf_val) not in man_val: + self.result += ( + "The pdf and manifest values do not match for key:{} profile:{} role:{}\n".format( + key, profile, self.role)) + self.result += ("the pdf val:{} and manifest val:{}\n".format(pdf_val, man_val)) + self.wrong += 1 + else: + self.result += ( + "The pdf and manifest values do match for key:{} profile:{} role:{}\n".format( + key, profile, self.role)) + self.right += 1 + + def validate(self, value): + """ validate software profile """ + self.logger.info("started with the validation of software set:%s", value) + val = "" + profile = 'software_set' + # keys = ["none"] + + for key in self.json[profile]: + if key["set_name"] == value: + val = key + break + self.logger.info("completed with the validation of software set:%s", value) + + self.validate_undercloud(val["undercloud_profile"]) + self.validate_infrastructure(val["infrasw_profile"]) + self.validate_openstack(val["openstack_profile"]) + + def validate_undercloud(self, value): + """ validate undercloud sw """ + self.logger.info("started with the validation of undercloud:%s", value) + val = "" + profile = 'undercloud_sw_profiles' + keys = ["name", "version"] + + for key in self.json[profile]: + if key["profile_name"] == value: + val = key + break + + for val in val["sw_list"]: + for _, key in enumerate(keys): + temp1 = val[key] + temp2 = self.software_list + self.comparison(key, profile, temp1, temp2) + self.logger.info("completed with the validation of undercloud:%s", value) + + def validate_infrastructure(self, value): + """ validate infra sw """ + self.logger.info("started with the validation of infra_sw:%s", value) + val = "" + profile = 'infra_sw_profiles' + keys = ["name", "version"] + + for key in self.json[profile]: + if key["profile_name"] == value: + val = key + break + + for val in val["sw_list"]: + for _, key in enumerate(keys): + temp1 = val[key] + temp2 = self.software_list + self.comparison(key, profile, temp1, temp2) + self.logger.info("completed with the validation of infra_sw:%s", value) + + def validate_openstack(self, value): + """ validate openstack sw """ + self.logger.info("started with the validation of opensatck_sw:%s", value) + val = "" + profile = 'openstack_sw_profiles' + keys = ["name", "version"] + + for key in self.json[profile]: + if key["profile_name"] == value: + val = key + break + + for val in val["sw_list"]: + for _, key in enumerate(keys): + temp1 = val[key] + temp2 = self.software_list + self.comparison(key, profile, temp1, temp2) + self.logger.info("completed with the validation of openstack_sw:%s", value) diff --git a/sdv/docker/sdvconfig/validation/storage.py b/sdv/docker/sdvconfig/validation/storage.py new file mode 100644 index 0000000..8b26351 --- /dev/null +++ b/sdv/docker/sdvconfig/validation/storage.py @@ -0,0 +1,160 @@ +#!/usr/bin/env python + +# Copyright (C) 2020 Ashwin Nayak +# +# 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. + +# pylint: disable=too-many-instance-attributes, too-many-arguments, too-many-branches, too-many-statements + +""" program which validates storage profile """ + + +class StorageValidation(): + """ perform hardware validation """ + + def __init__(self, role, json, value, manifest, logger): + # saving external state + self.role = role + self.json = json + self.value = value + self.logger = logger + self.manifest = manifest + # initialzing internal state + self.right = 0 + self.wrong = 0 + self.total = 0 + self.result = "" + # initialization function + self.validate() + + def get_values(self): + """ return set of right wrong and total """ + return self.right, self.wrong, self.total, self.result + + def comparison(self, key, profile, pdf_val, man_val): + """ do comparison and print results""" + self.total += 1 + self.logger.debug("key:%s, profile:%s, pdf_val:%s, man_val:%s, role:%s", + key, profile, pdf_val, man_val, self.role) + + if pdf_val == "": + self.result += ("No value exists for pdf-key:{} of profile:{} and role:{}\n"\ + .format(key, profile, self.role)) + elif man_val == []: + self.result += ("No value exists for manifest-key:{} of profile:{} and role:{}\n"\ + .format(key, profile, self.role)) + elif str(pdf_val) not in man_val: + self.result += ( + "The pdf and manifest values do not match for key:{} profile:{} role:{}\n".format( + key, profile, self.role)) + self.result += ("the pdf val:{} and manifest val:{}\n".format(pdf_val, man_val)) + self.wrong += 1 + else: + self.result += ( + "The pdf and manifest values do match for key:{} profile:{} role:{}\n".format( + key, profile, self.role)) + self.right += 1 + + def validate(self): + """ validate storage profile """ + val = "" + profile = 'storage_profile' + keys = ['bootdrive'] + + self.logger.info("Starting with the validation of storage profile: %s", self.value) + + for key in self.json[profile]: + if key["name"] == self.value: + val = key + break + + if val == "": + self.logger.error("Not able to find storage profile name: %s", self.value) + else: + for key in keys: + try: + temp1 = val[key] + temp2 = self.manifest.find_val(self.role, profile, key) + self.comparison(key, profile, temp1, temp2) + except KeyError: + self.logger.error( + "Not able to find key: %s in storage profile: %s", key, self.value) + + # redefining keys for bd_partitions + keys = ["name", "size", "bootable"] + for valx in val["bd_partitions"]: + for _, key in enumerate(keys): + try: + temp1 = valx[key] + temp2 = self.manifest.find_val(self.role, profile + '.bd_partitions', key) + self.comparison(key, profile, temp1, temp2) + except KeyError: + self.logger.error( + "Not able to find key: %s in storage profile-bd_partitions: %s"\ + , key, self.value) + + # redefining keys for bd_comparisonpartitions.filesystem + keys = ["mountpoint", "fstype", "mount_options"] + for valx in val["bd_partitions"]: + for _, key in enumerate(keys): + try: + temp1 = valx["filesystem"][key] + temp2 = self.manifest.find_val( + self.role, profile + '.bd_partitions.filesystem', key) + self.comparison(key, profile, temp1, temp2) + except KeyError: + self.logger.error( + "Not able to find key: %s in storage profile-filesystem: %s"\ + , key, self.value) + + # redefining keys for data_devices + keys_1 = ["name", "size"] + keys_2 = ["mountpoint", "fstype", "mount_options"] + + for val1 in val["data_devices"]: + for val2 in val1["partitions"]: + for _, key in enumerate(keys_1): + try: + temp1 = val2[key] + temp2 = self.manifest.find_val( + self.role, profile + '.data_devices', key) + self.comparison(key, profile, temp1, temp2) + except KeyError: + self.logger.error( + "Not able to find key: %s in storage profile-data_devices: %s"\ + , key, self.value) + for _, key in enumerate(keys_2): + try: + temp1 = val2["filesystem"][key] + temp2 = self.manifest.find_val( + self.role, profile + '.data_devices', key) + self.comparison(key, profile, temp1, temp2) + except KeyError: + self.logger.error( + "Not able to find key: %s in storage profile-data_devices: %s"\ + , key, self.value) + + # redefining keys for journal_devices + keys = ["name"] + for valx in val["journal_devices"]: + for _, key in enumerate(keys): + try: + temp1 = valx[key] + temp2 = self.manifest.find_val(self.role, profile + '.journal_devices', key) + self.comparison(key, profile, temp1, temp2) + except KeyError: + self.logger.error( + "Not able to find key: %s in storage profile-journal_devices: %s"\ + , key, self.value) + + self.logger.info("completed with the validation of storage profile: %s", self.value) -- cgit 1.2.3-korg