def convert_to_hardware_thunder_conf(hardware_list): """Validate for all vthunder nouns for hardware devices configurations.""" hardware_dict = {} for hardware_device in hardware_list: hardware_device = validate_params(hardware_device) project_id = hardware_device['project_id'] if hardware_dict.get(project_id): raise cfg.ConfigFileValueError( 'Supplied duplicate project_id {} ' ' in [hardware_thunder] section'.format(project_id)) hardware_device['undercloud'] = True if hardware_device.get('interface_vlan_map'): hardware_device[ 'device_network_map'] = validate_interface_vlan_map( hardware_device) del hardware_device['interface_vlan_map'] hierarchical_mt = hardware_device.get('hierarchical_multitenancy') if hierarchical_mt == "enable": hardware_device["partition_name"] = project_id[0:14] if hierarchical_mt and hierarchical_mt not in ('enable', 'disable'): raise cfg.ConfigFileValueError( 'Option `hierarchical_multitenancy` specified ' 'under project id {} only accepts "enable" and ' '"disable"'.format(project_id)) vthunder_conf = data_models.HardwareThunder(**hardware_device) hardware_dict[project_id] = vthunder_conf duplicates = check_duplicate_entries(hardware_dict) if duplicates: raise cfg.ConfigFileValueError( 'Duplicates found for the following ' '\'ip_address:partition_name\' entries: {}'.format( list(duplicates))) return hardware_dict
def convert_to_hardware_thunder_conf(hardware_list): """Validate for all vthunder nouns for hardware devices configurations.""" hardware_dict = {} for hardware_device in hardware_list: hardware_device = validate_params(hardware_device) if hardware_dict.get(hardware_device['project_id']): raise cfg.ConfigFileValueError('Supplied duplicate project_id ' + hardware_device['project_id'] + ' in [hardware_thunder] section') hardware_device['undercloud'] = True if hardware_device.get('interface_vlan_map'): hardware_device[ 'device_network_map'] = validate_interface_vlan_map( hardware_device) del hardware_device['interface_vlan_map'] vthunder_conf = data_models.HardwareThunder(**hardware_device) hardware_dict[hardware_device['project_id']] = vthunder_conf duplicates_list = check_duplicate_entries(hardware_dict) if duplicates_list: raise cfg.ConfigFileValueError( 'Duplicates found for the following ' '\'ip_address:partition_name\' entries: {}'.format( list(duplicates_list))) return hardware_dict
def __init__(self, restproxy): self.cms_id = cfg.CONF.RESTPROXY.cms_id if not self.cms_id: raise cfg.ConfigFileValueError('Missing cms_id in configuration.') self.restproxy = restproxy self.output = {} self.is_fatal_warn = False
def _validate_config_for_nuage_driver(self, nuage_driver, min_required_service_plugins, min_required_extensions): mentioned_service_plugins = cfg.CONF.service_plugins mentioned_extensions = cfg.CONF.ml2.extension_drivers self._check_config(mentioned_service_plugins, min_required_service_plugins, 'service_plugin(s)', nuage_driver) self._check_config(mentioned_extensions, min_required_extensions, 'extension(s)', nuage_driver) # Additional check: extension driver nuage_network is required # only when NuageL2Bridge service plugin is enabled. nuagel2bridge = ('NuageL2Bridge', 'nuage_neutron.plugins.common.service_plugins.' 'nuage_l2bridge.NuageL2BridgePlugin') nuage_network = ('nuage_network', 'nuage_neutron.plugins.nuage_ml2.' 'nuage_network_ext_driver.' 'NuageNetworkExtensionDriver') if (nuagel2bridge[0] in mentioned_service_plugins or nuagel2bridge[1] in mentioned_service_plugins): if (nuage_network[0] not in mentioned_extensions and nuage_network[1] not in mentioned_extensions): msg = ("Missing required extension " "'nuage_network' for service plugin " "NuageL2Bridge") raise cfg.ConfigFileValueError(msg)
def test_fail_with_config_exception(self): with mock.patch('sys.stderr.write') as mock_stderr: with mock.patch('sys.exit') as mock_exit: exc_msg = 'A ConfigError by George!' exc = cfg.ConfigFileValueError(exc_msg) glance.cmd.api.fail(exc) mock_stderr.assert_called_once_with('ERROR: %s\n' % exc_msg) mock_exit.assert_called_once_with(5)
def __init__(self, restproxy, is_dry_run): self.cms_id = cfg.CONF.RESTPROXY.cms_id if not self.cms_id: raise cfg.ConfigFileValueError('Missing cms_id in configuration.') self.restproxy = restproxy self.headers_for_pg = self.extra_header_for_pg() self.is_dry_run = is_dry_run self.output = {} self.is_fatal_warn = False
def validate_partial_ipv4(address): """Validate the partial IPv4 suffix provided""" partial_ip = address.lstrip('.') octets = partial_ip.split('.') for idx in range(4 - len(octets)): octets.insert(0, '0') if not netaddr.valid_ipv4('.'.join(octets), netaddr.core.INET_PTON): raise cfg.ConfigFileValueError( 'Invalid partial IPAddress value given' ' in configuration: {0}'.format(address))
def _check_config(mentioned, min_required, resource, driver_name): missing = [] for key, value in min_required.iteritems(): for conf_val in mentioned: if (conf_val == key or conf_val == value and resource == 'service_plugin(s)'): break else: missing.append(key) if missing: msg = ("Missing required " + resource + ' ' + str(missing) + " for mechanism driver " + driver_name) raise cfg.ConfigFileValueError(msg)
def validate_params(hardware_info): """Check for all the required parameters for hardware configurations.""" if all(k in hardware_info for k in ('ip_address', 'username', 'password', 'device_name')): if all(hardware_info[x] is not None for x in ('ip_address', 'username', 'password', 'device_name')): validate_ipv4(hardware_info['ip_address']) validate_partition(hardware_info) return hardware_info raise cfg.ConfigFileValueError( 'Please check your configuration. The params `project_id`, ' '`ip_address`, `username`, `password` and `device_name` ' 'under [hardware_thunder] section cannot be None ')
def init_vsd_client(self): cms_id = cfg.CONF.RESTPROXY.cms_id if not cms_id: raise cfg.ConfigFileValueError( _('Missing cms_id in configuration.')) self.vsdclient = VsdClientFactory.new_vsd_client( cms_id, server=cfg.CONF.RESTPROXY.server, base_uri=cfg.CONF.RESTPROXY.base_uri, serverssl=cfg.CONF.RESTPROXY.serverssl, serverauth=cfg.CONF.RESTPROXY.serverauth, auth_resource=cfg.CONF.RESTPROXY.auth_resource, organization=cfg.CONF.RESTPROXY.organization, servertimeout=cfg.CONF.RESTPROXY.server_timeout, max_retries=cfg.CONF.RESTPROXY.server_max_retries)
def _nuageclient_init(self): server = cfg.CONF.RESTPROXY.server serverauth = cfg.CONF.RESTPROXY.serverauth serverssl = cfg.CONF.RESTPROXY.serverssl base_uri = cfg.CONF.RESTPROXY.base_uri auth_resource = cfg.CONF.RESTPROXY.auth_resource organization = cfg.CONF.RESTPROXY.organization cms_id = cfg.CONF.RESTPROXY.cms_id if not cms_id: raise cfg.ConfigFileValueError( _('Missing cms_id in configuration.')) nuageclient = importutils.import_module('nuagenetlib.nuageclient') self.nuageclient = nuageclient.NuageClient(cms_id=cms_id, server=server, base_uri=base_uri, serverssl=serverssl, serverauth=serverauth, auth_resource=auth_resource, organization=organization)
def validate_ipv4(address): """Validate for IP4 address format""" if not netaddr.valid_ipv4(address, netaddr.core.INET_PTON): raise cfg.ConfigFileValueError( 'Invalid IPAddress value given in configuration: {0}'.format( address))