예제 #1
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
예제 #2
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
예제 #3
0
    def db_initiation(cls):
        LOG.info("--- Initiating SONA DB ---")
        init_sql = [
            'CREATE TABLE ' + cls.NODE_INFO_TBL +
            '(nodename text primary key, ip_addr, username)',
            'CREATE TABLE ' + cls.STATUS_TBL +
            '(nodename text primary key, ping, app, cpu, memory, disk, time)',
            'CREATE TABLE ' + cls.RESOURCE_TBL +
            '(nodename text primary key, cpu real, memory real, disk real)',
            'CREATE TABLE ' + cls.REGI_SYS_TBL +
            '(url text primary key, auth)', 'CREATE TABLE ' + cls.EVENT_TBL +
            '(nodename, item, grade, desc, time, PRIMARY KEY (nodename, item))'
        ]

        for sql in init_sql:
            sql_rt = cls.sql_execute(sql)

            if "already exist" in sql_rt:
                table_name = sql_rt.split()[1]
                LOG.info(
                    "\'%s\' table already exist. Delete all tuple of this table...",
                    table_name)
                sql = 'DELETE FROM ' + table_name
                sql_rt = cls.sql_execute(sql)
                if sql_rt != 'SUCCESS':
                    LOG.info("DB %s table initiation fail\n%s", table_name,
                             sql_rt)
                    sys.exit(1)
            elif sql_rt != 'SUCCESS':
                LOG.info("DB initiation fail\n%s", sql_rt)
                sys.exit(1)

        LOG.info('Insert nodes information ...')
        for node in CONF.watchdog()['check_system']:
            if str(node).lower() == 'onos':
                cls.sql_insert_nodes(CONF.onos()['list'],
                                     str(CONF.onos()['account']).split(':')[0])
            elif str(node).lower() == 'xos':
                cls.sql_insert_nodes(CONF.xos()['list'],
                                     str(CONF.xos()['account']).split(':')[0])
            elif str(node).lower() == 'swarm':
                cls.sql_insert_nodes(
                    CONF.swarm()['list'],
                    str(CONF.swarm()['account']).split(':')[0])
            elif str(node).lower() == 'openstack':
                cls.sql_insert_nodes(
                    CONF.openstack()['list'],
                    str(CONF.openstack()['account']).split(':')[0])
예제 #4
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
예제 #5
0
def delete_test_instance(server_vm, client_vm, client_floatingip):
    try:
        nova_credentials = client.Client(CONF.openstack()['version'],
                                         CONF.openstack()['username'],
                                         CONF.openstack()['api_key'],
                                         CONF.openstack()['project_id'],
                                         CONF.openstack()['auth_url'])

        nova_credentials.floating_ips.delete(client_floatingip)
        LOG.info('[Tperf Test] Client floatingip Deleted --- ')

        for vm in [server_vm, client_vm]:
            if vm:
                nova_credentials.servers.delete(vm)
        LOG.info('[Tperf Test] Server and Client instance Deleted] --- ')

    except:
        LOG.exception()
예제 #6
0
 def get_gateway_ip(self):
     return str(list(CONF.openstack()['gateway_list']).pop()).split(':')[-1]
예제 #7
0
def run_test(sona_topology, test_json, timeout_arr, index, total_timeout):
    try:
        node = test_json['node']
        ins_id = test_json['instance_id']
        user = test_json['vm_user_id']
        pw = test_json['vm_user_password']
        command = test_json['traffic_test_command']

        ip = sona_topology.get_openstack_info(node, 'ip')

        if ip == '':
            str_output = node + ' node does not exist'
        else:
            node_id = CONF.openstack()['account'].split(':')[0]

            ssh_options = '-o StrictHostKeyChecking=no ' \
                          '-o ConnectTimeout=' + str(CONF.ssh_conn()['ssh_req_timeout'])
            cmd = 'ssh %s %s@%s' % (ssh_options, node_id, ip)

            try:
                LOG.info('ssh_pexpect cmd = ' + cmd)
                ssh_conn = pexpect.spawn(cmd)
                rt1 = ssh_conn.expect(
                    PROMPT, timeout=CONF.ssh_conn()['ssh_req_timeout'])

                if rt1 == 0:
                    cmd = 'virsh console ' + ins_id

                    LOG.info('ssh_pexpect cmd = ' + cmd)
                    ssh_conn.sendline(cmd)
                    rt2 = ssh_conn.expect(
                        [
                            pexpect.TIMEOUT, 'Escape character is', 'error:',
                            pexpect.EOF
                        ],
                        timeout=CONF.ssh_conn()['ssh_req_timeout'])

                    if rt2 == 0:
                        str_output = cmd + ' timeout'
                    elif rt2 == 1:
                        ssh_conn.sendline('\n')
                        try:
                            rt3 = ssh_conn.expect(
                                ['login: '******'ssh_req_timeout'])

                            LOG.info('rt3 = ' + str(rt3))

                            if rt3 == 2:
                                str_output = 'Permission denied'
                            else:
                                ssh_conn.sendline(user)
                                rt_pw = ssh_conn.expect(
                                    [
                                        pexpect.TIMEOUT, '[P|p]assword:',
                                        pexpect.EOF
                                    ],
                                    timeout=CONF.ssh_conn()['ssh_req_timeout'])

                                if rt_pw == 1:
                                    ssh_conn.sendline(pw)
                                    rt4 = ssh_conn.expect(
                                        [
                                            pexpect.TIMEOUT, 'Login incorrect',
                                            '~# ', 'onos> ', '\$ ', '\# ',
                                            ':~$ '
                                        ],
                                        timeout=CONF.ssh_conn()
                                        ['ssh_req_timeout'])

                                    LOG.info('rt4 = ' + str(rt4))
                                    if rt4 == 0 or rt4 == 1:
                                        str_output = 'auth fail'
                                    else:
                                        ssh_conn.sendline(command)
                                        rt5 = ssh_conn.expect(
                                            [
                                                pexpect.TIMEOUT, '~# ',
                                                'onos> ', '\$ ', '\# ', ':~$ '
                                            ],
                                            timeout=total_timeout)
                                        if rt5 == 0:
                                            str_output = 'timeout'
                                            ssh_conn.sendline('exit')
                                            ssh_conn.close()
                                        else:
                                            str_output = ssh_conn.before
                                            ssh_conn.sendline('exit')
                                            ssh_conn.close()
                                else:
                                    str_output = 'auth fail'
                        except:
                            str_output = 'exception'
                            ssh_conn.sendline('exit')
                            ssh_conn.close()
                    elif rt2 == 2:
                        result = {'command_result': 'virsh console error'}
                        timeout_arr[index] = result
                        return

                    else:
                        str_output = 'connection fail'

            except:
                LOG.exception()
                str_output = 'exception 1'
    except:
        LOG.exception()
        str_output = 'exception 2'

    result = {
        'command_result': str_output.replace('\r\n', '\n'),
        'node': node,
        'instance_id': ins_id
    }
    timeout_arr[index] = result
예제 #8
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