#!/usr/bin/env python # # Workload Automation v2 for LAVA # # Copyright (C) 2014, Linaro Limited. # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # # Author: Milosz Wasilewski # import re import sys from string import Template from optparse import OptionParser TEMPLATE_PATH = "templates/" CONFIG_NAME = "config.py" CONFIG_PATH = TEMPLATE_PATH + CONFIG_NAME LAVA_CACHE_PATH = "/tmp/lava_multi_node_cache.txt" IPADDR_FILE = "IPADDR" IPADDR = "-ipaddr" if __name__ == '__main__': usage = "usage: %prog [OPTIONS]" parser = OptionParser(usage=usage) parser.add_option("-p", "--prefix", dest="prefix", help="Signal prefix used in the multinode job to retrieve IP address") (options, args) = parser.parse_args() if not options.prefix: parser.error("Prefix missing") lava_cache_file = open(LAVA_CACHE_PATH, 'r') lava_cache_regexp = re.compile("^(?P[a-zA-Z0-9_\-]+):(?P[a-zA-Z0-9_\-]+)=(?P.*)$") ipaddr = None for line in lava_cache_file.readlines(): print line lava_cache_match = lava_cache_regexp.search(line) if lava_cache_match: if lava_cache_match.group("key") == options.prefix + IPADDR: ipaddr = lava_cache_match.group("value") ipaddr_file = open(IPADDR_FILE, "w") ipaddr_file.write(ipaddr) ipaddr_file.close() lava_cache_file.close() if not ipaddr: sys.exit(1) config = open(CONFIG_PATH, "r") config_template = Template(config.read()) config.close() dest_config = open(CONFIG_NAME, "w") dest_config.write(config_template.safe_substitute(ipaddr=ipaddr + ":5555")) dest_config.close()