Add validation for "caas_oam" networking type
[ta/cm-plugins.git] / validators / src / HostsValidation.py
index 86494e8..9fd3577 100644 (file)
@@ -43,6 +43,7 @@ class HostsValidation(cmvalidator.CMValidator):
     performance_profile_attr = 'cloud.performance_profiles'
     networking_attr = 'cloud.networking'
     MIN_PASSWORD_LENGTH = 8
+    caas_service_profiles = (caas_master_profile, caas_worker_profile)
 
     def get_subscription_info(self):
         logging.debug('get_subscription info called')
@@ -97,6 +98,8 @@ class HostsValidation(cmvalidator.CMValidator):
 
                 self.validate_network_ranges(host_dict, net_profile_dict, networking_dict)
 
+                is_caas_oam_mapped_on_any_hosts = False
+
                 for host_name, host_data in host_dict.iteritems():
                     attr = 'network_profiles'
                     profiles = host_data.get(attr)
@@ -147,6 +150,14 @@ class HostsValidation(cmvalidator.CMValidator):
                             raise validation.ValidationError('%s is not mapped for %s' %
                                                              (subnet_name, host_name))
 
+                    if self.is_host_caas_node(host_data):
+                        subnet_name = 'caas_oam'
+                        if self.network_is_mapped(value_dict.get(profile_name), subnet_name):
+                            is_caas_oam_mapped_on_any_hosts = True
+                        elif is_caas_oam_mapped_on_any_hosts:
+                            raise validation.ValidationError('%s is not mapped for %s' %
+                                                             (subnet_name, host_name))
+
             elif key == self.storage_profile_attr:
                 profile_list = [] if not value_dict else value_dict.keys()
 
@@ -403,12 +414,22 @@ class HostsValidation(cmvalidator.CMValidator):
                                                  (attribute, profile, host))
 
     def validate_hwmgmt(self, hwmgmt, host):
+        # this list may not be comprehensive, but it matches ironic's idea
+        # of valid privileges.  In practice, we'll likely only see OPERATOR
+        # and ADMINISTRATOR.  Case seems to matter here.
+        valid_ipmi_priv = ['USER', 'CALLBACK', 'OPERATOR', 'ADMINISTRATOR']
+
         if not hwmgmt:
             raise validation.ValidationError('Missing hwmgmt configuration for %s' % host)
         if not hwmgmt.get('user'):
             raise validation.ValidationError('Missing hwmgmt username for %s' % host)
         if not hwmgmt.get('password'):
             raise validation.ValidationError('Missing hwmgmt password for %s' % host)
+        priv_level = hwmgmt.get('priv_level')
+        if priv_level and priv_level not in valid_ipmi_priv:
+            # priv_level is optional, but should be in the valid range.
+            raise validation.ValidationError('Invalid IPMI privilege level %s for %s' %
+                                             (priv_level, host))
         validationutils = validation.ValidationUtils()
         validationutils.validate_ip_address(hwmgmt.get('address'))
 
@@ -553,6 +574,9 @@ class HostsValidation(cmvalidator.CMValidator):
                 return True
         return False
 
+    def is_host_caas_node(self, host):
+        return bool(set(self.caas_service_profiles).intersection(host['service_profiles']))
+
     def _get_type_of_nodes(self, nodetype, config):
         nodes = [k for k, v in config.iteritems() if nodetype in v['service_profiles']]
         return nodes