Exemple #1
0
def get_pci_interface_stats_for_providernet(
        providernet_id,
        fields=('pci_pfs_configured', 'pci_pfs_used', 'pci_vfs_configured',
                'pci_vfs_used'),
        auth_info=Tenant.get('admin'),
        con_ssh=None):
    """
    get pci interface usage
    Args:
        providernet_id (str): id of a providernet
        fields: fields such as ('pci_vfs_configured', 'pci_pfs_used')
        auth_info (dict):
        con_ssh (SSHClient):

    Returns (tuple): tuple of integers

    """
    if not providernet_id:
        raise ValueError("Providernet id is not provided.")

    table_ = table_parser.table(
        cli.nova('providernet-show',
                 providernet_id,
                 ssh_client=con_ssh,
                 auth_info=auth_info)[1])
    rtn_vals = []
    for field in fields:
        pci_stat = int(
            table_parser.get_value_two_col_table(table_, field, strict=True))
        rtn_vals.append(pci_stat)
    return tuple(rtn_vals)
Exemple #2
0
def get_provider_net_info(providernet_id,
                          field='pci_pfs_configured',
                          strict=True,
                          auth_info=Tenant.get('admin'),
                          con_ssh=None,
                          rtn_int=True):
    """
    Get provider net info from "nova providernet-show"

    Args:
        providernet_id (str): id of a providernet
        field (str): Field name such as pci_vfs_configured, pci_pfs_used, etc
        strict (bool): whether to perform a strict search on field name
        auth_info (dict):
        con_ssh (SSHClient):
        rtn_int (bool): whether to return integer or string

    Returns (int|str): value of specified field. Convert to integer by default unless rnt_int=False.

    """
    if not providernet_id:
        raise ValueError("Providernet id is not provided.")

    table_ = table_parser.table(
        cli.nova('providernet-show',
                 providernet_id,
                 ssh_client=con_ssh,
                 auth_info=auth_info)[1])
    info_str = table_parser.get_value_two_col_table(table_,
                                                    field,
                                                    strict=strict)
    return int(info_str) if rtn_int else info_str
Exemple #3
0
def create_server_group(name=None,
                        policy='affinity',
                        rule=None,
                        fail_ok=False,
                        auth_info=None,
                        con_ssh=None,
                        rtn_exist=False,
                        field='id'):
    """
    Create a server group with given criteria

    Args:
        name (str): name of the server group
        policy (str): affinity or anti_infinity
        rule (str|None): max_server_per_host can be specified when
        policy=anti-affinity
        fail_ok (bool):
        auth_info (dict):
        con_ssh (SSHClient):
        rtn_exist (bool): Whether to return existing server group that
        matches the given name
        field (str): id or name

    Returns (tuple): (rtn_code (int), err_msg_or_srv_grp_id (str))
        - (0, <server_group_id>)    # server group created successfully
        - (1, <stderr>)     # create server group cli rejected

    """
    # process server group metadata
    if name and rtn_exist:
        existing_grp = get_server_groups(name=name,
                                         strict=False,
                                         con_ssh=con_ssh,
                                         auth_info=auth_info,
                                         field=field)
        if existing_grp:
            LOG.debug("Returning existing server group {}".format(
                existing_grp[0]))
            return -1, existing_grp[0]

    # process server group name and policy
    if not name:
        name = 'grp_{}'.format(policy.replace('-', '_'))
    name = common.get_unique_name(name_str=name)
    args = '{}{} {}'.format('--rule {} '.format(rule) if rule else '', name,
                            policy.replace('_', '-'))

    LOG.info("Creating server group with args: {}...".format(args))
    exit_code, output = cli.nova('server-group-create',
                                 args,
                                 ssh_client=con_ssh,
                                 fail_ok=fail_ok,
                                 auth_info=auth_info)
    if exit_code > 0:
        return 1, output

    table_ = table_parser.table(output)
    srv_grp_id = table_parser.get_values(table_, field)[0]
    LOG.info("Server group {} created successfully.".format(name))
    return 0, srv_grp_id
Exemple #4
0
def get_migration_list_table(con_ssh=None, auth_info=Tenant.get('admin')):
    """
    nova migration-list to collect migration history of each vm
    Args:
        con_ssh (SSHClient):
        auth_info (dict):

    """
    LOG.info("Listing migration history...")
    return table_parser.table(
        cli.nova('migration-list', ssh_client=con_ssh, auth_info=auth_info)[1])
Exemple #5
0
def update_dovetail_mgmt_interface():
    """
    Update dovetail vm mgmt interface on cumulus system.
    Since cumulus system is on different version. This helper function requires use cli matches the cumulus tis.

    Returns:

    """
    expt_mgmt_net = get_expt_mgmt_net()
    if not expt_mgmt_net:
        skip('{} mgmt net is not found in Cumulus tis-lab project'.format(
            ProjVar.get_var('LAB')['name']))

    with ssh_to_cumulus_server() as cumulus_con:
        cumulus_auth = CumulusCreds.TENANT_TIS_LAB
        vm_id = vm_helper.get_vm_id_from_name(vm_name='dovetail',
                                              con_ssh=cumulus_con,
                                              auth_info=cumulus_auth)

        dovetail_networks = vm_helper.get_vms(vms=vm_id,
                                              field='Networks',
                                              con_ssh=cumulus_con,
                                              auth_info=cumulus_auth)[0]

        actual_nets = dovetail_networks.split(sep=';')
        prev_mgmt_nets = []
        for net in actual_nets:
            net_name, net_ip = net.split('=')
            if '-MGMT-net' in net_name:
                prev_mgmt_nets.append(net_name)

        attach = True
        if expt_mgmt_net in prev_mgmt_nets:
            attach = False
            prev_mgmt_nets.remove(expt_mgmt_net)
            LOG.info("{} interface already attached to Dovetail vm".format(
                expt_mgmt_net))

        if prev_mgmt_nets:
            LOG.info("Detach interface(s) {} from dovetail vm".format(
                prev_mgmt_nets))
            vm_ports_table = table_parser.table(
                cli.nova('interface-list',
                         vm_id,
                         ssh_client=cumulus_con,
                         auth_info=cumulus_auth)[1])
            for prev_mgmt_net in prev_mgmt_nets:
                prev_net_id = network_helper.get_net_id_from_name(
                    net_name=prev_mgmt_net,
                    con_ssh=cumulus_con,
                    auth_info=cumulus_auth)

                prev_port = table_parser.get_values(vm_ports_table, 'Port ID',
                                                    **{'Net ID':
                                                       prev_net_id})[0]
                detach_arg = '{} {}'.format(vm_id, prev_port)
                cli.nova('interface-detach',
                         detach_arg,
                         ssh_client=cumulus_con,
                         auth_info=cumulus_auth)

        mgmt_net_id = network_helper.get_net_id_from_name(
            net_name=expt_mgmt_net,
            con_ssh=cumulus_con,
            auth_info=cumulus_auth)
        if attach:
            LOG.info("Attach {} to dovetail vm".format(expt_mgmt_net))
            args = '--net-id {} {}'.format(mgmt_net_id, vm_id)
            cli.nova('interface-attach',
                     args,
                     ssh_client=cumulus_con,
                     auth_info=cumulus_auth)

        vm_ports_table = table_parser.table(
            cli.nova('interface-list',
                     vm_id,
                     ssh_client=cumulus_con,
                     auth_info=cumulus_auth)[1])
        mgmt_mac = table_parser.get_values(vm_ports_table, 'MAC Addr',
                                           **{'Net ID': mgmt_net_id})[0]

    ComplianceCreds.set_host(Dovetail.TEST_NODE)
    ComplianceCreds.set_user(Dovetail.USERNAME)
    ComplianceCreds.set_password(Dovetail.PASSWORD)
    with ssh_to_compliance_server() as dovetail_ssh:
        if not attach and network_helper.ping_server('192.168.204.3',
                                                     ssh_client=dovetail_ssh,
                                                     fail_ok=True)[0] == 0:
            return
        LOG.info("Bring up dovetail mgmt interface and assign ip")
        eth_name = network_helper.get_eth_for_mac(dovetail_ssh,
                                                  mac_addr=mgmt_mac)
        dovetail_ssh.exec_sudo_cmd('ip link set dev {} up'.format(eth_name))
        dovetail_ssh.exec_sudo_cmd('dhclient {}'.format(eth_name),
                                   expect_timeout=180)
        dovetail_ssh.exec_cmd('ip addr')
        network_helper.ping_server(server='192.168.204.3',
                                   ssh_client=dovetail_ssh,
                                   fail_ok=False)