def neutron_check_segmentation_ids(self): """Check neutron segmentation ids check networks VLAN IDs not in Neutron L2 private VLAN ID range for VLAN segmentation only (neutron) """ tagged_nets = dict((n["name"], n["vlan_start"]) for n in filter( lambda n: (n["vlan_start"] is not None), self.networks)) if tagged_nets: if self.task.cluster.network_config.segmentation_type == \ consts.NEUTRON_SEGMENT_TYPES.vlan: # check networks tags not in Neutron L2 private VLAN ID range vrange = self.network_config['vlan_range'] net_intersect = [ name for name, vlan in six.iteritems(tagged_nets) if vrange[0] <= vlan <= vrange[1] ] if net_intersect: nets_with_errors = ", ". \ join(net_intersect) err_msg = u"VLAN tags of {0} network(s) intersect with " \ u"VLAN ID range defined for Neutron L2. " \ u"Networks VLAN tags must not intersect " \ u"with Neutron L2 VLAN ID range.". \ format(nets_with_errors) raise errors.NetworkCheckError(err_msg)
def check_vlan_ids_intersection(self): """Networks VLAN IDs should not intersect for any node's interface.""" if self.cluster.network_config.configuration_template is not None: # TODO(akasatkin) checking of network templates to be considered return tagged_nets = dict((n["id"], n["vlan_start"]) for n in filter( lambda n: (n["vlan_start"] is not None), self.networks)) # nothing to check if len(tagged_nets) < 2: return nodes_networks = \ objects.Cluster.get_networks_to_interfaces_mapping_on_all_nodes( self.cluster) # first, group by hostname for node_name, data in groupby(nodes_networks, lambda x: x[0]): # then group by interface name for particular node for if_name, nic_nets in groupby(data, lambda x: x[1]): net_ids = [ net_id for _, _, net_id in nic_nets if net_id in tagged_nets ] if len(net_ids) < 2: # no more than 1 tagged network is on the interface continue vlan_ids = [tagged_nets[n] for n in net_ids] if len(set(vlan_ids)) < len(vlan_ids): # some VLAN IDs are not unique for this interface seen_vlan_ids = set() duplicate_net_ids = set() for idx in range(len(vlan_ids)): if vlan_ids[idx] in seen_vlan_ids: duplicate_net_ids.add(net_ids[idx]) seen_vlan_ids.add(vlan_ids[idx]) net_names = [ net['name'] for net in self.networks if net['id'] in duplicate_net_ids ] err_msg = u"Node {0}, interface {1}: {2} networks use " \ u"the same VLAN tags. Different VLAN tags should be " \ u"assigned to the networks on the same interface.".\ format(node_name, if_name, ", ".join(net_names)) raise errors.NetworkCheckError(err_msg)
def expose_network_check_error_messages(task, result, err_messages): if err_messages: task.result = result db().add(task) db().commit() new_err_messages = [] for i, err_msg in enumerate(err_messages): if not err_msg: continue err_ids = '' ids = result[i].get('ids') if ids: err_ids = " (Network IDs: {0})".format(', '.join( str(x) for x in ids)) new_err_messages.append(err_msg + err_ids) full_err_msg = u"\n".join(new_err_messages) raise errors.NetworkCheckError(full_err_msg)