def _check_danger_flags(path, group): owner = path.split('/')[1] fmhostport = group[0]['thisResource']['sourceURL']['authority'] tmp = {} _set_owner_host_port_flags(tmp, owner, fmhostport) if tmp: raise err.ConfiguratorUserError('Configuration has DANGER flags.', details=tmp)
def get_easyconfig(path): """Raise ConfiguratorUserError if not found""" if path in easyconfigmap: return easyconfigmap[path] else: raise err.ConfiguratorUserError( 'Could not find easyconfig for given configuration path', details='given path: {},\neasyconfigs exist for:{}'.format( path, str(easyconfigmap.keys())))
def path2uri(path): owner = path.split('/')[1] if owner not in CONFIG.owners: raise err.ConfiguratorUserError('Unknown owner for path.', details=path) uri = ('http://' + CONFIG.owners[owner]['rcms_location'] + '/urn:rcms-fm:fullpath=' + path + ',group=BrilDAQFunctionManager,owner=' + owner) return uri
def submit_full(): data = flask.request.json try: comment = data['comment'] final = data['xml'] except ValueError: raise err.ConfiguratorUserError( '/submitfull request data must be {comment:..., xml:...}', details=data) r = utils.populate_RSDB_with_DUCK(final, comment) if r[0]: return flask.Response('Successfully submitted', status=200) else: return flask.Response(r[1], status=500)
def update_xml_fields(path, xml, fields): easy = get_easyconfig(path) _register_xml_nsprefixes(xml) root = ET.fromstring(xml) for field in fields: multi = field['multiple'] if 'multiple' in field else False log.debug(field) try: field['xpath'] = [ f['xpath'] for f in easy['fields'] if f['name'] == field['name'] ][0] except IndexError: raise err.ConfiguratorUserError( 'Could not find predefined field with this name', details=field) _modify_xml_value(root, field['xpath'], field['type'], field['value'], easy['namespaces'], multi) # log.debug(ET.tostring(root, encoding='UTF-8')) return ET.tostring(root, encoding='UTF-8')
def _check_hosts_and_ports(executive, xml): """Check if needed hosts and ports match between executive and xml. :param executive: dict executive fields (important: 'host', 'port') :param xml: str xdaq configuration xml :returns: True if (executive is None) or (executive.host=context.host=endpoint.host and executive.port=context.port and context.port!=endpoint.port) else raise ConfiguratorUserError :rtype: Boolean """ log.debug('In "_check_hosts_and_ports"') if executive is None: log.debug('executive is None - all good') return True root = ET.fromstring(xml) context = root.find('.//{' + CONFIG.xdaqxmlnamespace + '}Context') contexturl = context.attrib['url'].split(':') contexthost = contexturl[-2][2:] # drop two slashes after 'http:' contextport = int(contexturl[-1]) endpoint = context.find('.//{' + CONFIG.xdaqxmlnamespace + '}Endpoint') endpointhost = endpoint.attrib['hostname'] endpointport = int(endpoint.attrib['port']) log.debug( 'executive.host: {}, executive.port: {}, context.host: {}, ' 'context.port: {}, endpoint.host: {}, endpoint.port: {}'.format( executive['host'], executive['port'], contexthost, contextport, endpointhost, endpointport)) if executive['host'] == contexthost and executive['host'] == endpointhost: if executive['port'] == contextport and contextport != endpointport: return True raise err.ConfiguratorUserError( 'Failed hosts&ports check', details=( 'Some of the following violated:\n' '1) Executive.host ({}) = Context.host ({}) = Endpoint.host ({})\n' '2) Executive.port ({}) = Context.port ({})\n' '3) Context.port ({}) != Endpoint.port ({})').format( executive['host'], contexthost, endpointhost, executive['port'], contextport, contextport, endpointport))
def _get_parsed_groupblob(dbcon, path, version): select = ( 'select res.GROUPBLOB ' 'from CMS_LUMI_RS.CONFIGRESOURCES res, CMS_LUMI_RS.CONFIGURATIONS cfg ' 'where res.NAME=:resname ' 'and res.URN LIKE :path and ' 'res.CONFIGURATIONID=cfg.CONFIGURATIONID ') variables = { 'resname': 'BrilDAQFunctionManager', 'path': '%' + path + ',%'} if version is None: select += 'ORDER BY cfg.VERSION DESC' else: select += 'and cfg.VERSION=:cfgversion' variables['cfgversion'] = version r = dbcon.execute(select, variables).fetchone() if r is None: raise err.ConfiguratorUserError( 'Configuration groupblob not found by path and version in RS DB.', details={'path': path, 'version': version}) r = r[0] fobj = cStringIO.StringIO(r) gzf = gzip.GzipFile('dummy', 'rb', 9, fobj) return javabinary.parse(gzf)