Ejemplo n.º 1
0
def onsway_trace(sona_topology, trace_conditions):
    retry_flag = True
    up_down_result = []
    is_success = False

    while retry_flag:
        ssh_result = SshCommand.ssh_exec(
            CONF.openstack()['account'].split(':')[0],
            trace_conditions.cur_target_ip, make_command(trace_conditions))

        LOG.info('target_node = ' + trace_conditions.cur_target_ip)
        LOG.info('TRACE RESULT = ' + str(ssh_result))

        node_trace = dict()
        node_trace['trace_node_name'] = trace_conditions.cur_target_hostname

        process_result, retry_flag, is_success = process_trace(
            ssh_result, sona_topology, trace_conditions)

        node_trace['flow_rules'] = process_result

        trace_conditions.cond_dict['in_port'] = ''
        trace_conditions.cond_dict['dl_src'] = ''
        trace_conditions.cond_dict['dl_dst'] = ''
        trace_conditions.cond_dict['eth_dst'] = ''
        trace_conditions.cond_dict['eth_src'] = ''

        up_down_result.append(node_trace)

    return up_down_result, is_success
Ejemplo n.º 2
0
def tperf_cmd_exec(client_floatingip, tperf_command, transmit_time, tperf_output, thread_index):
    for i in range(10):
        tperf_output[thread_index] = SshCommand.ssh_tperf_exec(CONF.openstack()['key_file'],
                                                               CONF.openstack()['tperf_vm_username'],
                                                               client_floatingip,
                                                               tperf_command,
                                                               timeout=int(transmit_time) + 5)
        if tperf_output[thread_index] == 'fail':
            time.sleep(2)
        else:
            break
Ejemplo n.º 3
0
    def get_floatingips(self, onos_ip):
        onos_ssh_result = SshCommand.onos_ssh_exec(onos_ip,
                                                   self.ONOS_FLOATINGIP)
        floatingips = re.findall(
            r'[0-9]+(?:\.[0-9]+){3}(?: +)(?:[0-9]+(?:\.[0-9]+){3})',
            onos_ssh_result)

        floatingip_set = {}
        for l in floatingips:
            floatingip_set[l.split(' ')[0]] = l.split(' ')[-1]

        return floatingip_set
Ejemplo n.º 4
0
def server_vm_check(server_ip, client_floatingip):
    for i in range(20):
        check_result = SshCommand.ssh_tperf_exec(CONF.openstack()['key_file'],
                                                 CONF.openstack()['tperf_vm_username'],
                                                 client_floatingip,
                                                 'ping -c 1 ' + server_ip + ' | grep transmitted',
                                                 timeout=2)
        if ' 0% packet loss' in check_result.split(','):
            return True
        else:
            LOG.error('[Server Network Check Fail and Retry %d', i)
            time.sleep(1)
    return False
Ejemplo n.º 5
0
 def get_subnets(self, onos_ip):
     onos_ssh_result = SshCommand.onos_ssh_exec(onos_ip, self.ONOS_SUBNET)
     subnets = re.findall(r'[0-9]+(?:\.[0-9]+){3}(?:/\d\d)',
                          onos_ssh_result)
     return subnets
Ejemplo n.º 6
0
 def get_openstacknodes(self, onos_ip):
     onos_ssh_result = SshCommand.onos_ssh_exec(onos_ip,
                                                self.ONOS_OPENSTACKNODES)
     return onos_ssh_result
Ejemplo n.º 7
0
 def get_hosts(self, onos_ip, find_cond):
     LOG.info('onos command = ' + self.ONOS_HOST + '| grep ' + find_cond)
     onos_ssh_result = SshCommand.onos_ssh_exec(
         onos_ip, self.ONOS_HOST + '| grep ' + find_cond)
     return onos_ssh_result
Ejemplo n.º 8
0
 def get_routers(self, onos_ip):
     onos_ssh_result = SshCommand.onos_ssh_exec(onos_ip,
                                                self.ONOS_OPENSTACKROUTERS)
     routers = re.findall(r'[0-9]+(?:\.[0-9]+){3}', onos_ssh_result)
     return routers
Ejemplo n.º 9
0
def create_instance(server_options, client_options):
    server_instance = client_instance = None

    image_name = CONF.openstack()['image']
    flavor_name = CONF.openstack()['flavor']
    securitygroups = CONF.openstack()['security_groups']
    keypair = CONF.openstack()['keypair_name']

    # TODO add exception for connection
    nova_credentials = client.Client(CONF.openstack()['version'],
                                     CONF.openstack()['username'],
                                     CONF.openstack()['api_key'],
                                     CONF.openstack()['project_id'],
                                     CONF.openstack()['auth_url'])

    image = nova_credentials.images.find(name=image_name)
    flavor = nova_credentials.flavors.find(name=flavor_name)
    hypervisors = nova_credentials.hypervisors.list()

    onos_ip = CONF.onos()['list'].pop().split(':')[-1]
    dpid2ip = {c[2]: c[3] for c in [(" ".join(l.split()).split(" "))
               for l in SshCommand.onos_ssh_exec(onos_ip, 'openstack-nodes | grep COMPUTE').splitlines()]}

    def get_zone(dpid):
        if dpid:
            for h in hypervisors:
                if h.host_ip == dpid2ip[dpid]:
                    return 'nova:' + h.service['host']
        else:
            return "nova"

    # TODO: when no network_id, choice a network excepted external netwrok
    # network_id = server_options['network_id'] if server_options['network_id'] \
    #     else random.choice(nova.networks.list()).id
    # network_list = nova_credentials.networks.list()
    # target_network.append(str(network_list[-1]).split(':')[1][:-1].strip())

    # Create server VM info
    vm_name = 'tperf_server_vm_' + str(random.randrange(10000, 20000))
    LOG.info('[server] - vmname = %s', vm_name)
    LOG.info('         | image = %s', image)
    LOG.info('         | flavor = %s', flavor)
    LOG.info('         | availability_zone = %s', get_zone(server_options['vm_location']))
    LOG.info('         | nics = %s', server_options['network_id'])
    LOG.info('         | security_groups = %s', securitygroups)
    LOG.info('         | key_pair = %s', keypair)

    nova_credentials.servers.create(name=vm_name,
                                    image=image,
                                    flavor=flavor,
                                    availability_zone=get_zone(server_options['vm_location']),
                                    nics=[{'net-id': server_options['network_id']}],
                                    security_groups=securitygroups,
                                    key_name=keypair)
    for i in range(20):
        time.sleep(1)
        server_instance = nova_credentials.servers.list(search_opts={'name': vm_name})[0]
        # server_instance = nova_credentials.servers.list(search_opts={'name': 'tperf_server_vm_17693'})[0]
        if server_instance.__dict__['addresses']:
            LOG.info("[Server VM created and ACTIVE] - %s", server_instance)
            break

    # Create client VM info
    vm_name = 'tperf_client_vm_' + str(random.randrange(10000, 20000))
    LOG.info('[client] - vmname = %s', vm_name)
    LOG.info('         | image = %s', image)
    LOG.info('         | flavor = %s', flavor)
    LOG.info('         | availability_zone = %s', get_zone(client_options['vm_location']))
    LOG.info('         | nics = %s', client_options['network_id'])
    LOG.info('         | security_groups = %s', securitygroups)
    LOG.info('         | key_pair = %s', keypair)

    nova_credentials.servers.create(name=vm_name,
                                    image=image,
                                    flavor=flavor,
                                    availability_zone=get_zone(client_options['vm_location']),
                                    nics=[{'net-id': client_options['network_id']}],
                                    security_groups=securitygroups,
                                    key_name=keypair)

    client_floatingip = get_floatingip(nova_credentials)
    # client_floatingip = '172.27.0.179'

    for i in range(20):
        time.sleep(1)
        client_instance = nova_credentials.servers.list(search_opts={'name': vm_name})[0]
        # client_instance = nova_credentials.servers.list(search_opts={'name': 'tperf_client_vm_15442'})[0]
        if client_instance.__dict__['addresses']:
            LOG.info("[Client VM created and ACTIVE] - %s", client_instance)
            nova_credentials.servers.add_floating_ip(client_instance, client_floatingip.ip)
            LOG.info("[Floating_IP Assignment] to Client ---")
            break

    return server_instance, client_instance, client_floatingip