Exemplo n.º 1
0
 def get_virtual_node_name_from_mac(self, mac):
     vNode_names, _ = execute('virsh list|awk \'{print $2}\'', shell=True)
     for node in vNode_names.split('\n'):
         if 'baremetal' in node:
             admin_net_mac, _ = execute(
                 'virsh domiflist %s |grep admin |awk \'{print $5}\'' %
                 node,
                 shell=True)
             if admin_net_mac.replace('\n', '') == mac:
                 return node
     raise Exception(
         'Could not find corresponding virtual node for MAC: %s' % mac)
Exemplo n.º 2
0
 def cleanup(self):
     for i in range(MAX_NODES):
         rv, (_, rc) = execute('virsh destroy %(name)s%(i)s-%(env)s'
                               % {'i': i, 'env': self.env,
                                  'name': self.NODE_NAME},
                               check_exit_code=[0, 1])
         if rc == 0:
             LOG.info(rv)
         rv, (_, rc) = execute('virsh undefine %(name)s%(i)s-%(env)s'
                               % {'i': i, 'env': self.env,
                                  'name': self.NODE_NAME},
                               check_exit_code=[0, 1])
         if rc == 0:
             LOG.info(rv)
     execute('rm -rf ' + self.BUILD_DIR)
Exemplo n.º 3
0
    def gen_node_info(self):
        overcloud_ip_list = TripleoHelper.find_overcloud_ips()

        for node_ip in overcloud_ip_list:
            LOG.info('Introspecting node %s' % node_ip)
            node = Node('intro-%s' % node_ip,
                        address=node_ip,
                        user=self.overcloud_user)
            node_mac = None
            virsh_domain = None
            server_name, _ = node.execute('hostname')
            server_name = server_name.rstrip()
            if 'overcloud-controller' in server_name:
                node_type = 'controller'
            elif 'overcloud-novacompute' in server_name:
                node_type = 'compute'
            else:
                raise TripleOInspectorException('Unknown type '
                                                '(controller/compute) %s ' %
                                                server_name)
            try:
                processutils.execute('ping -c 1 %s' % node_ip)
                res, _ = processutils.execute('/usr/sbin/arp -a '
                                              '%s' % node_ip)
                node_mac = \
                    re.search('([0-9a-z]+:){5}[0-9a-z]+', res).group(0)
                virsh_domain = \
                    TripleoHelper.get_virtual_node_name_from_mac(node_mac)
            except AttributeError:
                LOG.warning("Unable to find MAC address for node {"
                            "}".format(node_ip))

            # find ovs controller and manager
            ovs_controller = self.get_ovs_controller(node)
            out, _ = node.execute('ovs-vsctl get-manager', as_root=True)
            ovs_managers = out.rstrip().split("\n")
            if all(ovs_manager == '' for ovs_manager in ovs_managers):
                LOG.warning(
                    "OVS managers for node {} is empty!".format(node_ip))
            self.node_info['servers'][server_name] = {
                'address': node_ip,
                'user': self.overcloud_user,
                'type': node_type,
                'orig-ctl-mac': node_mac,
                'vNode-name': virsh_domain,
                'ovs-controller': ovs_controller,
                'ovs-managers': ovs_managers
            }
Exemplo n.º 4
0
    def run(self, sys_args, config):
        self.env = str(sys_args.env_number).replace('"', '')
        self.BUILD_DIR = '../build/apex-%s' % self.env
        self.cleanup()
        if sys_args.cleanup:
            return
        if not sys_args.cloner_info or not sys_args.snapshot_disks\
                or not sys_args.vjump_hosts:
            LOG.error('--cloner-info, --snapshot-disks and --vjump-hosts '
                      ' have to be given if not  only --cleanup.')
            exit(1)
        node_info = utils_yaml.read_dict_from_yaml(sys_args.cloner_info +
                                                   '/node.yaml')
        nodes = node_info['servers']
        number_of_nodes = len(nodes)
        disk_home = self.BUILD_DIR + '/disks/'
        shutil.mkdir_if_not_exsist(disk_home)
        # Create Snapshots
        for i in range(number_of_nodes):
            disk_name = '%s%s.qcow2' % (self.NODE_NAME, i)
            self.create_snapshot(
                '%s/%s' % (sys_args.snapshot_disks, disk_name),
                '%s/%s' % (disk_home, disk_name))

        # Create Bridges if not existing
        for net in self.BRIGES:
            bridge_name = '%s-%s' % (net, self.env)
            if not self.check_if_br_exists(bridge_name):
                LOG.info('Creating bridge %s' % bridge_name)
                execute('ovs-vsctl add-br %s' % bridge_name, as_root=True)

        # Create virtual Nodes
        dom_template = self.TEMPLATES + '/nodes/baremetalX.xml'
        dom_config = self.BUILD_DIR + '/nodes/baremetalX.xml'
        shutil.mkdir_if_not_exsist(self.BUILD_DIR + '/nodes/')
        LOG.info('Creating virtual Nodes')
        for name, node in nodes.iteritems():
            orig_node_name = node['vNode-name']
            node_name = orig_node_name + '-' + self.env
            LOG.info('Create node %s' % node_name)
            type = node['type']
            if type == 'compute':
                cpu = 4
                mem = 4
            elif type == 'controller':
                cpu = 8
                mem = 10
            else:
                raise Exception('Unknown node type! %s' % type)
            shutil.copy('to', dom_template, dom_config)
            shutil.replace_string_in_file(dom_config, 'NaMe', node_name)
            disk_full_path = os.path.abspath('%s/%s.qcow2' %
                                             (disk_home, orig_node_name))
            shutil.replace_string_in_file(dom_config, 'DiSk', disk_full_path)
            shutil.replace_string_in_file(dom_config, 'vCpU', str(cpu))
            shutil.replace_string_in_file(dom_config, 'MeMoRy', str(mem))
            shutil.replace_string_in_file(dom_config, 'InDeX', self.env)

            execute('virsh define ' + dom_config)
            execute('virsh start ' + node_name)

            cores_per_environment = 8
            cores = '%s-%s' % (int(self.env) * 8,
                               int(self.env) * 8 + cores_per_environment - 1)
            LOG.info('Pining vCPU of node %s to cores %s' % (node_name, cores))
            for i in range(cpu):
                execute('virsh vcpupin %(node)s %(nodes_cpu)s %(host_cpu)s' % {
                    'node': node_name,
                    'nodes_cpu': i,
                    'host_cpu': cores
                })

        # Upload cloner_info to jenkins slave
        node_name = 'jenkins%s' % self.env
        jenkins_node_config = utils_yaml.read_dict_from_yaml(
            sys_args.vjump_hosts)['servers']
        if node_name not in jenkins_node_config:
            raise Exception('Jenkins host %s not provided in %s' %
                            (node_name, sys_args.vjump_hosts))
        jenkins_slave = NodeManager(jenkins_node_config).get_node(node_name)
        if 'CLONER_INFO' in os.environ:
            cloner_info_path = os.environ['CLONER_INFO']
        else:
            cloner_info_path = '/home/jenkins/cloner-info/'
        jenkins_slave.copy('to', sys_args.cloner_info, cloner_info_path)
Exemplo n.º 5
0
 def create_snapshot(self, orig, path):
     LOG.info('Creating snapshot of %s in %s' % (orig, path))
     execute('qemu-img create -f qcow2 -b %s %s' % (orig, path),
             as_root=True)
Exemplo n.º 6
0
 def check_if_br_exists(self, bridge):
     _, (_, rc) = execute('ovs-vsctl br-exists %s' % bridge,
                          check_exit_code=[0, 2],
                          as_root=True)
     return True if rc == 0 else False
Exemplo n.º 7
0
 def get_all_files_in_path(path):
     if os.path.exists(path):
         file_list = putils.execute(['l', path])
Exemplo n.º 8
0
 def mv(src, dst):
     putils.execute(["mv", src, dst])
Exemplo n.º 9
0
 def rm(path):
     putils.execute(["rm -rf", path])
Exemplo n.º 10
0
 def copy(src, dst):
     if os.path.isfile(src):
         python_shutil.copy(src, dst)
     else:
         putils.execute(['cp', '-R', src, dst])
Exemplo n.º 11
0
 def mkdir_if_not_exsist(path):
     putils.execute(["mkdir", "-p", path])