X-Git-Url: https://gerrit.akraino.org/r/gitweb?p=ta%2Fcm-plugins.git;a=blobdiff_plain;f=validators%2Fsrc%2FPerformanceProfilesValidation.py;fp=validators%2Fsrc%2FPerformanceProfilesValidation.py;h=1d9743011514cc4554cb7352ed0dd8829f28db83;hp=34bea2e8151d33808d7f5e2fd48bb03357d34b00;hb=8ebf04fe5d34337fcbd700d9d7c80eae57ba28a7;hpb=24d618be517a31349dffea80f538290b1989ee10 diff --git a/validators/src/PerformanceProfilesValidation.py b/validators/src/PerformanceProfilesValidation.py index 34bea2e..1d97430 100644 --- a/validators/src/PerformanceProfilesValidation.py +++ b/validators/src/PerformanceProfilesValidation.py @@ -20,6 +20,7 @@ from cmframework.apis import cmvalidator class PerformanceProfilesValidation(cmvalidator.CMValidator): + DOMAIN = 'cloud.performance_profiles' SUBSCRIPTION = r'^cloud\.performance_profiles$' HUGEPAGESZ = 'hugepagesz' @@ -30,20 +31,24 @@ class PerformanceProfilesValidation(cmvalidator.CMValidator): CAAS_CPU_POOLS = 'caas_cpu_pools' CAAS_CPU_POOL_ATTRIBUTES = ['exclusive_pool_percentage', 'shared_pool_percentage'] CAAS_CPU_POOL_SHARE = 'caas_cpu_pool_share' + TUNING = 'tuning' NUMA0 = 'numa0' NUMA1 = 'numa1' NUMA_VALUES = [NUMA0, NUMA1] HUGEPAGESZ_VALUES = ['2M', '1G'] + TUNING_OPTIONS = ['low_latency', 'standard'] INFO_HUGEPAGESZ = 'Valid values: %s' % HUGEPAGESZ_VALUES INFO_HUGEPAGES = 'Must be positive integer' INFO_CPUS = 'Must be zero or positive integer' INFO_PLATFORM_CPUS = 'Platform requires at least one core from NUMA0' + INFO_TUNING = 'Valid tuning options are %s' % TUNING_OPTIONS ERR_MISSING_DATA = 'Performance profiles validation input does not contain {} data' ERR_INVALID_VALUE = 'Invalid %s value in performance profile {}: %s' + ERR_INVALID_CONFIG = 'Invalid {} config (not a dict)' ERR_HUGEPAGESZ = ERR_INVALID_VALUE % (HUGEPAGESZ, INFO_HUGEPAGESZ) ERR_DEFAULT_HUGEPAGESZ = ERR_INVALID_VALUE % (DEFAULT_HUGEPAGESZ, INFO_HUGEPAGESZ) @@ -55,6 +60,7 @@ class PerformanceProfilesValidation(cmvalidator.CMValidator): ERR_CPU_POOL_RATIO = 'caas_cpu_pools total cpu percentage exceeded' ERR_CAAS_CPU_POOL_TYPE = 'caas_cpu_pools percentage values should be integer' ERR_CAAS_DEFAULT_POOL = 'caas_cpu_pool_share value should be integer between 0 and 100' + ERR_TUNING = "Invalid %s value in {}. %s" % (TUNING, INFO_TUNING) @staticmethod def raise_error(context, err_type): @@ -67,12 +73,13 @@ class PerformanceProfilesValidation(cmvalidator.CMValidator): conf = self.get_conf(props) if isinstance(conf, dict): self.validate(conf) + elif conf: + self.raise_error(self.DOMAIN, self.ERR_INVALID_CONFIG) def get_conf(self, props): - domain = 'cloud.performance_profiles' - if not isinstance(props, dict) or domain not in props: - self.raise_error(domain, self.ERR_MISSING_DATA) - return json.loads(props[domain]) + if not isinstance(props, dict) or self.DOMAIN not in props: + self.raise_error(self.DOMAIN, self.ERR_MISSING_DATA) + return json.loads(props[self.DOMAIN]) def validate(self, conf): for profile, entries in conf.iteritems(): @@ -98,6 +105,8 @@ class PerformanceProfilesValidation(cmvalidator.CMValidator): self.validate_caas_cpu_pools(profile, value) elif key == self.CAAS_CPU_POOL_SHARE: self.validate_caas_cpu_pool_share(value) + elif key == self.TUNING: + self.validate_tuning(profile, value) def validate_hugepagesz(self, profile, value): if value not in self.HUGEPAGESZ_VALUES: @@ -146,6 +155,10 @@ class PerformanceProfilesValidation(cmvalidator.CMValidator): if sum_ratio > 100: self.raise_error(profile, self.ERR_CPU_POOL_RATIO) + def validate_tuning(self, profile, option): + if option not in self.TUNING_OPTIONS: + self.raise_error(profile, self.ERR_TUNING) + def allowed_attributes(self, profile, entries, allowed_attributes): for key in entries.keys(): if key not in allowed_attributes: