def get_config_and_net_part_bodies(self): from lab import with_config cfg_tmpl = with_config.read_config_from_file(config_path='xrnc_vm_config.txt', directory='vts', is_as_string=True) net_part_tmpl = with_config.read_config_from_file(config_path='xrnc-net-part-of-libvirt-domain.template', directory='vts', is_as_string=True) dns_ip, ntp_ip = self.lab().get_dns()[0], self.lab().get_ntp()[0] lab_name = str(self.lab()) _, username, password = self.get_ssh() nic_ssh_net = filter(lambda x: x.is_ssh(), self.get_nics().values())[0] # Vtc sits on out-of-tor network marked is_ssh dl_ssh_ip, ssh_netmask = nic_ssh_net.get_ip_and_mask() ssh_gw = nic_ssh_net.get_net()[1] ssh_prefixlen = nic_ssh_net.get_net().prefixlen nic_vts_net = filter(lambda x: x.is_vts(), self.get_nics().values())[0] # also sits on local network marked is_vts dl_loc_ip, loc_netmask = nic_vts_net.get_ip_and_mask() vlan = nic_vts_net.get_net().get_vlan() loc_prefixlen = nic_ssh_net.get_net().prefixlen # TODO: parametrize xrvr_ip and vtc_vip xrvr_loc_ip = nic_vts_net.get_net()[170 + int(self.get_id()[-1])] xrvr_ssh_ip = nic_vts_net.get_net()[42 + int(self.get_id()[-1])] vtc_vip = '10.23.221.150' # XRVR is a VM sitting in a VM which runs on vts-host. outer VM called DL inner VM called XRVR , so 2 IPs on ssh and vts networks needed cfg_body = cfg_tmpl.format(ssh_ip_dl=dl_ssh_ip, ssh_ip_xrvr=xrvr_ssh_ip, ssh_netmask=ssh_netmask, ssh_prefixlen=ssh_prefixlen, ssh_gw=ssh_gw, loc_ip_dl=dl_loc_ip, loc_ip_xrvr=xrvr_loc_ip, loc_netmask=loc_netmask, loc_prefixlen=loc_prefixlen, dns_ip=dns_ip, ntp_ip=ntp_ip, vtc_ssh_ip=vtc_vip, username=username, password=password, lab_name=lab_name) net_part = net_part_tmpl.format(ssh_nic_name=nic_ssh_net.get_name(), vts_nic_name=nic_vts_net.get_name(), vlan=vlan) return cfg_body, net_part
def get_cluster_conf_body(self): from lab import with_config vip_a, vip_mx = self.ssh_ip a_ip = [] mx_ip = [] mx_gw = None for node_id in ['bld', 'vtc1', 'vtc2']: a_ip.append( self.pod.get_node_by_id( node_id=node_id).get_nic('a').get_ip_and_mask()[0]) mx_nic = self.pod.get_node_by_id(node_id=node_id).get_nic('mx') mx_gw = mx_nic.get_gw() mx_ip.append(mx_nic.get_ip_and_mask()[0]) cfg_tmpl = with_config.read_config_from_file( cfg_path='cluster.conf.template', folder='vts', is_as_string=True) cfg_body = cfg_tmpl.format(lab_name=self.pod, vip_a=vip_a, vip_mx=vip_mx, vtc1_a_ip=a_ip[1], vtc2_a_ip=a_ip[2], vtc1_mx_ip=mx_ip[1], vtc2_mx_ip=mx_ip[2], special_ip=a_ip[0], mx_gw=mx_gw) with with_config.WithConfig.open_artifact('cluster.conf', 'w') as f: f.write(cfg_body) return cfg_body
def __create_overcloud_config_and_template(self, servers): import json import os from lab.with_config import read_config_from_file, CONFIG_DIR config = {'nodes': []} mac_profiles = [] ucsm_ip = servers[0].ucsm['ip'] ucsm_username = servers[0].ucsm['username'] ucsm_password = servers[0].ucsm['password'] for server in servers: ucsm_profile = server.ucsm['service-profile'] mac_profiles.append('{0}:{1}'.format(server.ucsm['iface_mac']['eth0'], ucsm_profile)) pxe_mac = server.ucsm['iface_mac']['pxe-int'] config['nodes'].append({'mac': [pxe_mac], 'cpu': 2, 'memory': 128000, 'disk': 500, 'arch': 'x86_64', 'pm_type': "pxe_ipmitool", 'pm_user': server.ipmi['username'], 'pm_password': server.ipmi['password'], 'pm_addr': server.ipmi['ip']}) self.director_server.put_string_as_file_in_dir(string_to_put=json.dumps(config), file_name='overcloud.json') self.director_server.get(remote_path='overcloud.json', local_path='overcloud.json') yaml_name = 'networking-cisco-environment.yaml' config_tmpl = read_config_from_file(yaml_path=yaml_name, directory='osp7', is_as_string=True) config = config_tmpl.format(network_ucsm_ip=ucsm_ip, network_ucsm_username=ucsm_username, network_ucsm_password=ucsm_password, network_ucsm_host_list=','.join(mac_profiles)) self.director_server.put_string_as_file_in_dir(string_to_put=config, file_name=yaml_name, in_directory='templates')
def __init__(self, yaml_name): import importlib import os from lab.with_config import read_config_from_file self.providers = [] self.deployers = [] self.runners = [] self._servers_and_clouds = {'servers': [], 'clouds': []} self._results = [] config = read_config_from_file(config_path=yaml_name, directory='run') for section_name, class_path_vs_config in sorted(config.items()): module_class_path, class_config = class_path_vs_config.items()[0] module_path, class_name = module_class_path.rsplit('.', 1) try: modul = importlib.import_module(module_path) klass = getattr(modul, class_name) except ImportError: section_name_no_digits = section_name.strip('0123456789') section_dir = 'lab/' + section_name_no_digits + 's' classes = map(lambda name: section_dir.replace('/', '.') + '.' + name.replace('.py', ''), filter(lambda name: name.startswith(section_name_no_digits) and name.endswith('.py'), os.listdir(section_dir))) raise ValueError('yaml {y} section {l}: Module "{mp}" is not defined! Use one of:\n {c}'.format(y=yaml_name, l=section_name, mp=module_path, c=classes)) except AttributeError: raise ValueError('in yaml {y}: class {k} is not in {p}'.format(y=yaml_name, k=class_name, p=module_path)) class_instance = klass(config=class_config) if type(class_instance).__name__.startswith('Provider'): self.providers.append(class_instance) elif type(class_instance).__name__.startswith('Deployer'): self.deployers.append(class_instance) elif type(class_instance).__name__.startswith('Runner'): self.runners.append(class_instance)
def __init__(self, config): from lab.with_config import read_config_from_file super(RunnerRally, self).__init__(config=config) self._cloud_name = config['cloud'] self._task_body = read_config_from_file(yaml_path=config['task-yaml'], directory='artifacts', is_as_string=True) self._rally_repo = config['rally-repo'] self._rally_patch = config['rally-patch']
def get_config_and_net_part_bodies(self): from lab import with_config config_tmpl = with_config.read_config_from_file(config_path='vtf_vm_config.txt', directory='vts', is_as_string=True) net_part_tmpl = with_config.read_config_from_file(config_path='vtf-net-part-of-libvirt-domain.template', directory='vts', is_as_string=True) compute = self.get_all_wires()[0].get_peer_node(self) compute_hostname = compute.hostname() nic_vts_net = filter(lambda x: x.is_vts(), self.get_nics().values())[0] loc_ip, loc_netmask = nic_vts_net.get_ip_and_mask() loc_gw = nic_vts_net.get_net()[1] vlan = nic_vts_net.get_net().get_vlan() dns_ip = self.lab().get_dns()[0] ntp_ip = self.lab().get_ntp()[0] _, ssh_username, ssh_password = self.get_ssh() config_body = config_tmpl.format(loc_ip=loc_ip, loc_netmask=loc_netmask, loc_gw=loc_gw, dns_ip=dns_ip, ntp_ip=ntp_ip, vtc_loc_ip=' TODO: ', # TODO username=ssh_username, password=ssh_password, compute_hostname=compute_hostname) net_part = net_part_tmpl.format(vlan=vlan) return config_body, net_part
def get_cluster_conf_body(self): from lab import with_config vip_ssh, vip_vts = self.get_vip() ip_ssh = [] for node_id in ['bld', 'vtc1', 'vtc2']: ip = self.lab().get_node_by_id(node_id=node_id).get_nics()['api'].get_ip_and_mask()[0] ip_ssh.append(ip) cfg_tmpl = with_config.read_config_from_file(config_path='cluster.conf.template', directory='vts', is_as_string=True) cfg_body = cfg_tmpl.format(lab_name=self.lab(), vip_ssh=vip_ssh, vtc1_ip_ssh=ip_ssh[1], vtc2_ip_ssh=ip_ssh[2], bld_ip_ssh=ip_ssh[0], vip_vts=vip_vts) return cfg_body
def get_config_and_net_part_bodies(self): from lab import with_config cfg_tmpl = with_config.read_config_from_file( cfg_path='vtc-vm-config.txt', folder='vts', is_as_string=True) net_part_tmpl = with_config.read_config_from_file( cfg_path='vtc-net-part-of-libvirt-domain.template', folder='vts', is_as_string=True) dns_ip, ntp_ip = self.pod.get_dns()[0], self.pod.get_ntp()[0] hostname = '{id}-{lab}'.format(lab=self.pod, id=self.id) a_nic = self.get_nic( 'a') # Vtc sits on out-of-tor network marked is_ssh a_ip, a_net_mask = a_nic.get_ip_and_mask() a_gw = a_nic.get_net().get_gw() mx_nic = self.get_nic('mx') # also sits on mx network mx_ip, mx_net_mask = mx_nic.get_ip_and_mask() mx_vlan = mx_nic.get_net().get_vlan_id() cfg_body = cfg_tmpl.format(vtc_a_ip=a_ip, a_net_mask=a_net_mask, a_gw=a_gw, vtc_mx_ip=mx_ip, mx_net_mask=mx_net_mask, dns_ip=dns_ip, ntp_ip=ntp_ip, username=self.ssh_username, password=self.ssh_password, hostname=hostname) net_part = net_part_tmpl.format(a_nic_name='a', mx_nic_name='mx', mx_vlan=mx_vlan) with with_config.WithConfig.open_artifact(hostname, 'w') as f: f.write(cfg_body) return cfg_body, net_part
def get_config_and_net_part_bodies(self): from lab import with_config cfg_tmpl = with_config.read_config_from_file(cfg_path='vtc-vm-config.txt', folder='vts', is_as_string=True) net_part_tmpl = with_config.read_config_from_file(cfg_path='vtc-net-part-of-libvirt-domain.template', folder='vts', is_as_string=True) dns_ip, ntp_ip = self.pod.get_dns()[0], self.pod.get_ntp()[0] hostname = '{id}-{lab}'.format(lab=self.pod, id=self.id) a_nic = self.nics_dic('a') # Vtc sits on out-of-tor network marked is_ssh a_ip, a_net_mask = a_nic.get_ip_and_mask() a_gw = a_nic.get_net().get_gw() mx_nic = self.nics_dic('mx') # also sits on mx network mx_ip, mx_net_mask = mx_nic.get_ip_and_mask() mx_vlan = mx_nic.get_net().get_vlan_id() cfg_body = cfg_tmpl.format(vtc_a_ip=a_ip, a_net_mask=a_net_mask, a_gw=a_gw, vtc_mx_ip=mx_ip, mx_net_mask=mx_net_mask, dns_ip=dns_ip, ntp_ip=ntp_ip, username=self.username, password=self.password, hostname=hostname) net_part = net_part_tmpl.format(a_nic_name='a', mx_nic_name='mx', mx_vlan=mx_vlan) with with_config.WithConfig.open_artifact(hostname, 'w') as f: f.write(cfg_body) return cfg_body, net_part
def __init__(self, config_path): from lab import with_config from lab.network import Network self._cfg = with_config.read_config_from_file(config_path=config_path) self._id = self._cfg['lab-id'] self._lab_name = self._cfg['lab-name'] self._lab_type = self._cfg['lab-type'] if self._lab_type not in self.SUPPORTED_LAB_TYPES: raise ValueError('"{}" is not one of supported types: {}'.format(self._lab_type, self.SUPPORTED_LAB_TYPES)) self._unique_dict = dict() # to make sure that all needed objects are unique self._nodes = list() self._director = None self._is_sriov = self._cfg.get('use-sr-iov', False) self._role_vs_count = dict() self._dns, self._ntp = self._cfg['dns'], self._cfg['ntp'] self._neutron_username, self._neutron_password = self._cfg['special-creds']['neutron_username'], self._cfg['special-creds']['neutron_password'] self._nets = {} self._upstream_vlans = [] # list of vlans which should go out of the lab net_markers_used = [] for net_name, net_desc in self._cfg['nets'].items(): try: net = Network(name=net_name, cidr=net_desc['cidr'], mac_pattern=net_desc['mac-pattern'], vlan=net_desc['vlan']) self._nets[net_name] = net if net_desc.get('is-via-tor', False): self._upstream_vlans.append(net_desc['vlan']) for is_xxx in ['pxe', 'ssh', 'vts']: if net_desc.get('is-' + is_xxx, False): if is_xxx not in net_markers_used: getattr(net, 'set_is_' + is_xxx)() # will set marker to True net_markers_used.append(is_xxx) else: raise ValueError('Check net section- more then one network is marked as is-' + is_xxx) except KeyError as ex: raise ValueError('Network "{}" has no {}'.format(net_name, ex.message)) for node_description in self._cfg['nodes']: self._process_single_node(node_description) if not self._director: self._director = self.get_controllers()[0] # assign first controller as director if no director node specified in yaml config for peer_link in self._cfg['peer-links']: # list of {'own-id': 'n97', 'own-port': '1/46', 'port-channel': 'pc100', 'peer-id': 'n98', 'peer-port': '1/46'} own_node = self.get_node_by_id(peer_link['own-id']) self._process_single_wire(own_node=own_node, wire_info=(peer_link['own-port'], {'peer-id': peer_link['peer-id'], 'peer-port': peer_link['peer-port'], 'port-channel': peer_link['port-channel']}))
def get_config_and_net_part_bodies(self): from lab import with_config cfg_tmpl = with_config.read_config_from_file(config_path='vtc_vm_config.txt', directory='vts', is_as_string=True) net_part_tmpl = with_config.read_config_from_file(config_path='vtc-net-part-of-libvirt-domain.template', directory='vts', is_as_string=True) dns_ip, ntp_ip = self.lab().get_dns()[0], self.lab().get_ntp()[0] lab_name = str(self.lab()) _, ssh_username, ssh_password = self.get_ssh() nic_ssh_net = filter(lambda x: x.is_ssh(), self.get_nics().values())[0] # Vtc sits on out-of-tor network marked is_ssh ssh_ip, ssh_netmask = nic_ssh_net.get_ip_and_mask() ssh_gw = nic_ssh_net.get_net()[1] nic_vts_net = filter(lambda x: x.is_vts(), self.get_nics().values())[0] # also sits on local network marked is_vts loc_ip, loc_netmask = nic_vts_net.get_ip_and_mask() vlan = nic_vts_net.get_net().get_vlan() cfg_body = cfg_tmpl.format(ssh_ip=ssh_ip, ssh_netmask=ssh_netmask, ssh_gw=ssh_gw, loc_ip=loc_ip, loc_netmask=loc_netmask, dns_ip=dns_ip, ntp_ip=ntp_ip, username=ssh_username, password=ssh_password, lab_name=lab_name) net_part = net_part_tmpl.format(ssh_nic_name=nic_ssh_net.get_name(), vts_nic_name=nic_vts_net.get_name(), vlan=vlan) return cfg_body, net_part
def get_cluster_conf_body(self): from lab import with_config vip_a, vip_mx = self.ip a_ip = [] mx_ip = [] mx_gw = None for node_id in ['bld', 'vtc1', 'vtc2']: a_ip.append(self.pod.get_node_by_id(node_id=node_id).get_nic('a').get_ip_and_mask()[0]) mx_nic = self.pod.get_node_by_id(node_id=node_id).get_nic('mx') mx_gw = mx_nic.get_gw() mx_ip.append(mx_nic.get_ip_and_mask()[0]) cfg_tmpl = with_config.read_config_from_file(cfg_path='cluster.conf.template', folder='vts', is_as_string=True) cfg_body = cfg_tmpl.format(lab_name=self.pod, vip_a=vip_a, vip_mx=vip_mx, vtc1_a_ip=a_ip[1], vtc2_a_ip=a_ip[2], vtc1_mx_ip=mx_ip[1], vtc2_mx_ip=mx_ip[2], special_ip=a_ip[0], mx_gw=mx_gw) with with_config.WithConfig.open_artifact('cluster.conf', 'w') as f: f.write(cfg_body) return cfg_body
def ha(lab, test_regex, do_not_clean=False, is_tims=False): """fab ha:g10,tc-vts,no_clean\t\tRun all VTS tests on lab g10 :param lab: which lab to use :param test_regex: regex to match some tc in $REPO/configs/ha :param do_not_clean: if True then the lab will not be cleaned before running test :param is_tims: if True then publish results to TIMS """ import os from fabric.api import local from lab import with_config lab_path = with_config.actual_path_to_config(path=lab) lab_name = lab_path.rsplit('/', 1)[-1].replace('.yaml', '') available_tc = with_config.ls_configs(directory='ha') tests = sorted(filter(lambda x: test_regex in x, available_tc)) run_config_yaml = '{lab}-ha-{regex}.yaml'.format(lab=lab_name, regex=test_regex) with with_config.open_artifact(run_config_yaml, 'w') as f: f.write('deployer: {lab.deployers.deployer_existing.DeployerExisting: {cloud: %s, hardware-lab-config: %s}}\n' % (lab_name, lab)) for i, test in enumerate(tests, start=1): if not do_not_clean: f.write('runner%s: {lab.runners.runner_ha.RunnerHA: {cloud: %s, hardware-lab-config: %s, task-yaml: clean.yaml}}\n' % (10*i, lab_name, lab_name)) f.write('runner%s: {lab.runners.runner_ha.RunnerHA: {cloud: %s, hardware-lab-config: %s, task-yaml: "%s"}}\n' % (10*i + 1, lab_name, lab_name, test)) run(config_path=run_config_yaml) results = {x: {'status': False, 'n_exceptions': 2} for x in tests} if 'pyats' in os.getenv('PATH'): pyast_template = with_config.read_config_from_file('pyats.template', 'pyats', is_as_string=True) pyats_body = pyast_template.format(results) with with_config.open_artifact('pyats_job.py', 'w') as f: f.write(pyats_body) # noinspection PyBroadException try: local('easypy artifacts/pyats_job.py -no_archive ' + ('-tims_post -tims_dns "tims/Tcbr2p"' if is_tims else '')) except: pass
def update_conf(original_tempest_conf, output_tempest_conf, lab_config, stackrc="/home/stack/stackrc"): frame = inspect.currentframe() args, _, _, values = inspect.getargvalues(frame) if not all(args): print """ Ex: fab ucsm_tempest_conf.update_conf:/etc/redhat-certification-openstack/tempest.conf,etc/tempest.conf,10.23.228.253,admin,cisco """ ucsm_section = 'ucsm' tempest_conf = ConfigParser.RawConfigParser() tempest_conf.read(original_tempest_conf) config = read_config_from_file(yaml_path=lab_config) ucsm_ip = config['ucsm']['host'] ucsm_user = config['ucsm']['username'] ucsm_password = config['ucsm']['password'] ucsm_servers = list() nodes = list() # Find list of service profiles, servers and macs with settings(host_string="{0}@{1}".format(ucsm_user, ucsm_ip), password=ucsm_password): profiles = run("show service-profile assoc | egrep Associated | cut -f 1 -d ' '", shell=False).split() for profile in profiles: server_num = run("scope org ; scope service-profile {0} ; show assoc detail | egrep '^Server:' | cut -f 2 -d ' '".format(profile), shell=False) macs = run("scope server {0} ; scope adapter 1 ; show host-eth-if detail | no-more | egrep 'Dynamic MAC Address' | cut -f 8 -d ' '".format(server_num), shell=False).split() macs = {mac.lower() for mac in macs} ucsm_servers.append({'profile': profile, 'server': server_num, 'macs': macs}) print "UCSM Servers: ", ucsm_servers # Find list of nodes, IP, hostname and MACs of them node_names = local("source {0} && nova list | grep ACTIVE | awk '{{print $4}}'".format(stackrc), capture=True).split() for node_name in node_names: ip = local("nova list | grep {0} | grep -o -P '(?<=ctlplane\=).*? '".format(node_name), capture=True) with settings(host_string="{0}@{1}".format('heat-admin', ip), disable_known_hosts=True): macs = set(run("ip -o link | grep -o -P '(?<=link\/ether )(.*?) '").split()) for ucsm_server in ucsm_servers: if ucsm_server['macs'] & macs: profile = ucsm_server['profile'] break nodes.append({'ip': ip, 'hostname': '{0}.localdomain'.format(node_name), 'macs': macs, 'profile': profile}) print "Nodes: ", nodes ucsm_host_dict = list() network_node_list = list() for node in nodes: ucsm_host_dict.append('{0}:{1}'.format(node['hostname'], node['profile'])) if 'controll' in node['hostname']: network_node_list.append(node['hostname']) if not tempest_conf.has_section(ucsm_section): tempest_conf.add_section(ucsm_section) tempest_conf.set(ucsm_section, 'ucsm_ip', ucsm_ip) tempest_conf.set(ucsm_section, 'ucsm_username', ucsm_user) tempest_conf.set(ucsm_section, 'ucsm_password', ucsm_password) tempest_conf.set(ucsm_section, 'ucsm_host_dict', ','.join(ucsm_host_dict)) tempest_conf.set(ucsm_section, 'network_node_list', ','.join(network_node_list)) tempest_conf.set(ucsm_section, 'eth_names', 'eth0,eth1') tempest_conf.set(ucsm_section, 'virtual_functions_amount', '4') with open(output_tempest_conf, 'w') as f: tempest_conf.write(f)
def create_config_file_for_osp7_install(self, topology=TOPOLOGY_VLAN): import os from lab.logger import lab_logger from lab.with_config import read_config_from_file from lab.cimc import CimcServer from lab.fi import FI from lab.n9k import Nexus lab_logger.info('Creating config for osp7_bootstrap') osp7_install_template = read_config_from_file(config_path='./configs/osp7/osp7-install.yaml', is_as_string=True) # Calculate IPs for user net, VIPs and director IP ssh_net = filter(lambda net: net.is_ssh(), self._nets.values())[0] overcloud_network_cidr, overcloud_external_gateway, overcloud_external_ip_start, overcloud_external_ip_end = ssh_net.cidr, ssh_net[1], ssh_net[4+1], ssh_net[-3] eth0_mac_versus_service_profile = {} overcloud_section = [] for server in self.get_controllers() + self.get_computes(): service_profile_name = '""' if isinstance(server, CimcServer) else server.get_ucsm_info()[1] try: eth0_nic = server.get_nic(nic='eth0')[0] except IndexError: raise ValueError('{0} has no eth0'.format(server.name())) eth0_mac = eth0_nic.get_mac() eth0_mac_versus_service_profile[eth0_mac] = service_profile_name try: pxe_int_nic = server.get_nic(nic='pxe-int')[0] except IndexError: raise ValueError('{0} has no pxe-int'.format(server.name())) pxe_mac = pxe_int_nic.get_mac() ipmi_ip, ipmi_username, ipmi_password = server.get_ipmi() role = server.name().split('-')[0] descriptor = {'"arch"': '"x86_64"', '"cpu"': '"2"', '"memory"': '"8256"', '"disk"': '"1112"', '"name"': '"{0}"'.format(server.name()), '"capabilities"': '"profile:{0},boot_option:local"'.format(role), '"mac"': '["{0}"]'.format(pxe_mac), '"pm_type"': '"pxe_ipmitool"', '"pm_addr"': '"{0}"'.format(ipmi_ip), '"pm_user"': '"{0}"'.format(ipmi_username), '"pm_password"': '"{0}"'.format(ipmi_password)} overcloud_section.append(',\n\t '.join(['{0}:{1}'.format(x, y) for x, y in sorted(descriptor.iteritems())])) network_ucsm_host_list = ','.join(['{0}:{1}'.format(name, mac) for name, mac in eth0_mac_versus_service_profile.iteritems()]) overcloud_nodes = '{{"nodes":[\n\t{{\n\t {0}\n\t}}\n ]\n }}'.format('\n\t},\n\t{\n\t '.join(overcloud_section)) nexus_section = [] switch_tempest_section = [] for n9 in self.get_nodes_by_class(Nexus): common_pcs_part = ': {"ports": "port-channel:' + str(n9.get_peer_link_id()) # all pcs n9k-n9k and n9k-fi fi_pc_part = ',port-channel:' + ',port-channel:'.join(n9.get_pcs_to_fi()) mac_port_lines = [] for server in self.get_controllers() + self.get_computes(): mac = server.get_nic('pxe-int')[0].get_mac() if isinstance(server, CimcServer): individual_ports_part = ','.join([x.get_peer_node(server) for x in server.get_all_wires() if x.get_peer_node(server) == n9]) # add if wired to this n9k only if individual_ports_part: individual_ports_part = ',' + individual_ports_part else: individual_ports_part = fi_pc_part mac_port_lines.append('"' + mac + '"' + common_pcs_part + individual_ports_part + '" }') nexus_servers_section = ',\n\t\t\t\t\t\t'.join(mac_port_lines) ssh_ip, ssh_username, ssh_password, hostname = n9.get_ssh() switch_tempest_section.append({'hostname': hostname, 'username': ssh_username, 'password': ssh_password, 'sw': str(ssh_ip)}) n9k_description = ['"' + hostname + '": {', '"ip_address": "' + str(ssh_ip) + '",', '"username": "******",', '"password": "******",', '"nve_src_intf": 2,', '"ssh_port": 22,', '"physnet": "datacentre",', '"servers": {' + nexus_servers_section + '}}', ] nexus_section.append('\n\t\t\t'.join(n9k_description)) network_nexus_config = '{\n\t\t' + ',\n\t\t'.join(nexus_section) + '}' n_controls, n_computes, n_ceph = self.count_role(role_name='control'), self.count_role(role_name='compute'), self.count_role(role_name='ceph') director_node_ssh_ip, _, _, director_hostname = self.get_director().get_ssh() pxe_int_vlans = self._cfg['nets']['pxe-int']['vlan'] eth1_vlans = self._cfg['nets']['eth1']['vlan'] ext_vlan, test_vlan, stor_vlan, stor_mgmt_vlan, tenant_vlan, fip_vlan = eth1_vlans[1], pxe_int_vlans[1], pxe_int_vlans[2], pxe_int_vlans[3], pxe_int_vlans[4], eth1_vlans[0] ucsm_vip = self.get_nodes_by_class(FI)[0].get_vip() cfg = osp7_install_template.format(director_node_hostname=director_hostname, director_node_ssh_ip=director_node_ssh_ip, ext_vlan=ext_vlan, test_vlan=test_vlan, stor_vlan=stor_vlan, stor_mgmt_vlan=stor_mgmt_vlan, tenant_vlan=tenant_vlan, fip_vlan=fip_vlan, vlan_range=self.vlan_range(), overcloud_network_cidr=overcloud_network_cidr, overcloud_external_ip_start=overcloud_external_ip_start, overcloud_external_gateway=overcloud_external_gateway, overcloud_external_ip_end=overcloud_external_ip_end, overcloud_nodes=overcloud_nodes, overcloud_control_scale=n_controls, overcloud_ceph_storage_scale=n_ceph, overcloud_compute_scale=n_computes, network_ucsm_ip=ucsm_vip, network_ucsm_username=self._neutron_username, network_ucsm_password=self._neutron_password, network_ucsm_host_list=network_ucsm_host_list, undercloud_lab_pxe_interface='pxe-ext', undercloud_local_interface='pxe-int', undercloud_fake_gateway_interface='eth1', provisioning_nic='nic4', tenant_nic='nic1', external_nic='nic2', cobbler_system='G{0}-DIRECTOR'.format(self._id), network_nexus_config=network_nexus_config, switch_tempest_section=switch_tempest_section, do_sriov=self._is_sriov ) if topology == self.TOPOLOGY_VXLAN: pass folder = 'artifacts' file_path = os.path.join(folder, 'g{0}-osp7-install-config.conf'.format(self._id)) if not os.path.exists(folder): os.makedirs(folder) with open(file_path, 'w') as f: f.write(cfg) lab_logger.info('finished. Execute osp7_bootstrap --config {0}'.format(file_path))
def create_config_file_for_osp7_install(self, topology=TOPOLOGY_VLAN): import os from lab.logger import lab_logger from lab.with_config import read_config_from_file from lab.nodes.cimc_server import CimcServer from lab.nodes.fi import FI from lab.nodes.n9 import N9 lab_logger.info('Creating config for osp7_bootstrap') osp7_install_template = read_config_from_file(config_path='./configs/osp7/osp7-install.yaml', is_as_string=True) # Calculate IPs for user net, VIPs and director IP ssh_net = filter(lambda net: net.is_ssh(), self._nets.values())[0] overcloud_network_cidr, overcloud_external_gateway, overcloud_external_ip_start, overcloud_external_ip_end = ssh_net.cidr, ssh_net[1], ssh_net[4 + 1], ssh_net[-3] eth0_mac_versus_service_profile = {} overcloud_section = [] for server in self.get_controllers() + self.get_computes(): service_profile_name = '""' if isinstance(server, CimcServer) else server.get_ucsm_info()[1] try: eth0_nic = server.get_nic(nic='eth0')[0] except IndexError: raise ValueError('{0} has no eth0'.format(server.name())) eth0_mac = eth0_nic.get_mac() eth0_mac_versus_service_profile[eth0_mac] = service_profile_name try: pxe_int_nic = server.get_nic(nic='pxe-int')[0] except IndexError: raise ValueError('{0} has no pxe-int'.format(server.name())) pxe_mac = pxe_int_nic.get_mac() ipmi_ip, ipmi_username, ipmi_password = server.get_ipmi() role = server.name().split('-')[0] descriptor = {'"arch"': '"x86_64"', '"cpu"': '"2"', '"memory"': '"8256"', '"disk"': '"1112"', '"name"': '"{0}"'.format(server.name()), '"capabilities"': '"profile:{0},boot_option:local"'.format(role), '"mac"': '["{0}"]'.format(pxe_mac), '"pm_type"': '"pxe_ipmitool"', '"pm_addr"': '"{0}"'.format(ipmi_ip), '"pm_user"': '"{0}"'.format(ipmi_username), '"pm_password"': '"{0}"'.format(ipmi_password)} overcloud_section.append(',\n\t '.join(['{0}:{1}'.format(x, y) for x, y in sorted(descriptor.items())])) network_ucsm_host_list = ','.join(['{0}:{1}'.format(name, mac) for name, mac in eth0_mac_versus_service_profile.items()]) overcloud_nodes = '{{"nodes":[\n\t{{\n\t {0}\n\t}}\n ]\n }}'.format('\n\t},\n\t{\n\t '.join(overcloud_section)) nexus_section = [] switch_tempest_section = [] for n9 in self.get_nodes_by_class(N9): common_pcs_part = ': {"ports": "port-channel:' + str(n9.get_peer_link_id()) # all pcs n9k-n9k and n9k-fi fi_pc_part = ',port-channel:' + ',port-channel:'.join(n9.get_pcs_to_fi()) mac_port_lines = [] for server in self.get_controllers() + self.get_computes(): mac = server.get_nic('pxe-int')[0].get_mac() if isinstance(server, CimcServer): individual_ports_part = ','.join([x.get_peer_node(server) for x in server.get_all_wires() if x.get_peer_node(server) == n9]) # add if wired to this n9k only if individual_ports_part: individual_ports_part = ',' + individual_ports_part else: individual_ports_part = fi_pc_part mac_port_lines.append('"' + mac + '"' + common_pcs_part + individual_ports_part + '" }') nexus_servers_section = ',\n\t\t\t\t\t\t'.join(mac_port_lines) ssh_ip, ssh_username, ssh_password, hostname = n9.get_ssh() switch_tempest_section.append({'hostname': hostname, 'username': ssh_username, 'password': ssh_password, 'sw': str(ssh_ip)}) n9k_description = ['"' + hostname + '": {', '"ip_address": "' + str(ssh_ip) + '",', '"username": "******",', '"password": "******",', '"nve_src_intf": 2,', '"ssh_port": 22,', '"physnet": "datacentre",', '"servers": {' + nexus_servers_section + '}}', ] nexus_section.append('\n\t\t\t'.join(n9k_description)) network_nexus_config = '{\n\t\t' + ',\n\t\t'.join(nexus_section) + '}' n_controls, n_computes, n_ceph = self.count_role(role_name='control'), self.count_role(role_name='compute'), self.count_role(role_name='ceph') director_node_ssh_ip, _, _, director_hostname = self.get_director().get_ssh() pxe_int_vlans = self._cfg['nets']['pxe-int']['vlan'] eth1_vlans = self._cfg['nets']['eth1']['vlan'] ext_vlan, test_vlan, stor_vlan, stor_mgmt_vlan, tenant_vlan, fip_vlan = eth1_vlans[1], pxe_int_vlans[1], pxe_int_vlans[2], pxe_int_vlans[3], pxe_int_vlans[4], eth1_vlans[0] ucsm_vip = self.get_nodes_by_class(FI)[0].get_ucsm_vip() cfg = osp7_install_template.format(director_node_hostname=director_hostname, director_node_ssh_ip=director_node_ssh_ip, ext_vlan=ext_vlan, test_vlan=test_vlan, stor_vlan=stor_vlan, stor_mgmt_vlan=stor_mgmt_vlan, tenant_vlan=tenant_vlan, fip_vlan=fip_vlan, vlan_range=self.vlan_range(), overcloud_network_cidr=overcloud_network_cidr, overcloud_external_ip_start=overcloud_external_ip_start, overcloud_external_gateway=overcloud_external_gateway, overcloud_external_ip_end=overcloud_external_ip_end, overcloud_nodes=overcloud_nodes, overcloud_control_scale=n_controls, overcloud_ceph_storage_scale=n_ceph, overcloud_compute_scale=n_computes, network_ucsm_ip=ucsm_vip, network_ucsm_username=self._neutron_username, network_ucsm_password=self._neutron_password, network_ucsm_host_list=network_ucsm_host_list, undercloud_lab_pxe_interface='pxe-ext', undercloud_local_interface='pxe-int', undercloud_fake_gateway_interface='eth1', provisioning_nic='nic4', tenant_nic='nic1', external_nic='nic2', cobbler_system='G{0}-DIRECTOR'.format(self._id), network_nexus_config=network_nexus_config, switch_tempest_section=switch_tempest_section, do_sriov=self._is_sriov ) if topology == self.TOPOLOGY_VXLAN: pass folder = 'artifacts' file_path = os.path.join(folder, 'g{0}-osp7-install-config.conf'.format(self._id)) if not os.path.exists(folder): os.makedirs(folder) with open(file_path, 'w') as f: f.write(cfg) lab_logger.info('finished. Execute osp7_bootstrap --config {0}'.format(file_path))