Example #1
0
def delete_cinder_volume(kwargs):

    handle = kwargs['handle']
    prompt = kwargs['prompt']
    test_obj = kwargs['test_obj']
    vol_name = kwargs['volume_name']

    cmd = "cinder list --display-name=%s" % vol_name
    output = gen_lib.send_cmd(test_obj, handle, cmd, prompt, 30)
    ret = re.findall("^\|\s*(\S+)\s*\|", output, re.M)
    for v in ret:
        cmd = "cinder delete %s" % v
        output = gen_lib.send_cmd(test_obj, handle, cmd, prompt, 30)
Example #2
0
def delete_glance_image(kwargs):

    handle = kwargs['handle']
    prompt = kwargs['prompt']
    test_obj = kwargs['test_obj']

    cmd = "glance image-list --name=%s" % kwargs['image_name']
    output = gen_lib.send_cmd(test_obj, handle, cmd, prompt, 300)

    ret = re.findall('\|\s*(\S+)\s*\| %s' % kwargs['image_name'], output)

    for im in ret:
        cmd = "glance image-delete %s" % im
        output = gen_lib.send_cmd(test_obj, handle, cmd, prompt, 300)
Example #3
0
def delete_all_vms(test_obj, handle, prompt, all=False):

    init_credentials(test_obj, handle, prompt)

    cmd = "nova list"
    output = gen_lib.send_cmd(test_obj, handle, cmd, prompt, 60)
    ret = re.findall("^\s*\|\s*(\S+)\s*\|\s*(\S+)", output, re.M)
    for i in xrange(1, len(ret)):
        vm_id, vm_name = ret[i]
        if vm_name == "livemnfs" and not all:
            continue
        cmd = "nova delete %s" % vm_id
        output = gen_lib.send_cmd(test_obj, handle, cmd, prompt, 60)
        time.sleep(5)
Example #4
0
def setup_storage(test_obj, handle, prompt):

    test_conf = test_obj.argument['test_conf']['test_conf']
    testbed_config = test_obj.argument['testbed_config']['testbed_config']

    cmd = "cd /opt/contrail/utils"
    output = gen_lib.send_cmd(test_obj, handle, cmd, prompt, 10)

    cmd = "fab setup_storage"
    output = gen_lib.send_cmd(test_obj, handle, cmd, prompt, 1200)

    if re.search('Abort', output):
        gen_lib.Print("ERROR: %s Aborted" % cmd)
        test_obj.argument['err_msg'] += "ERROR: fab setup_storage failed.\n"
        sys.exit()
Example #5
0
def get_vm_id(test_obj, handle, prompt, vm_name):

    cmd = "nova list"
    output = gen_lib.send_cmd(test_obj, handle, cmd, prompt, 60)

    vm_id = re.search('\|\s*(\S+)\s*\|\s*%s\s*' % vm_name, output).group(1)
    return vm_id
Example #6
0
def get_vm_hostinfo(test_obj, handle, prompt, vm_name):

    cmd = 'nova show %s | grep hypervisor_hostname' % vm_name
    output = gen_lib.send_cmd(test_obj, handle, cmd, prompt, 60)
    current_hostname = re.search('\|\s*(\S+)\s*\|\s*(\S+)', output).group(2)
    print "###", current_hostname
    return current_hostname.strip()
Example #7
0
    def provision_servers(self):

        smgr_handle = self.arg['handle']
        smgr_prompt = self.arg['prompt']
        test_obj = self.arg['test_obj']
        test_conf = test_obj.argument['test_conf']['test_conf']
        testbed_config = test_obj.argument['testbed_config']['testbed_config']

        cluster_id = get_cluster_id(testbed_config['cluster_json_file'])
        cmd = test_conf[
            'smgr_client_cmd'] + " provision --cluster_id %s contrail_test_pkg" % cluster_id
        print "CMD: ", cmd
        smgr_handle.sendline(cmd)
        i = smgr_handle.expect(['y/N', pexpect.EOF, pexpect.TIMEOUT],
                               timeout=120)
        cmd = 'y'
        output = gen_lib.send_cmd(test_obj, smgr_handle, cmd, smgr_prompt, 120)
        if not re.search('provision issued', output):
            err_msg = "ERROR: servers not provisioned..\n"
            gen_lib.Print(err_msg)
            test_obj.argument['err_msg'] += err_msg
            sys.exit()

        self.wait_until_provision_complete(smgr_handle, smgr_prompt)

        time.sleep(180)

        return
Example #8
0
def get_cinder_type_list(test_obj, handle, prompt):

    init_credentials(test_obj, handle, prompt)

    cmd = "cinder type-list"
    output = gen_lib.send_cmd(test_obj, handle, cmd, prompt, 60)
    return re.findall('ocs\S+', output)
Example #9
0
    def re_image_all(self):

        handle = self.arg['handle']
        prompt = self.arg['prompt']
        test_obj = self.arg['test_obj']
        test_conf = test_obj.argument['test_conf']['test_conf']
        testbed_config = test_obj.argument['testbed_config']['testbed_config']

        cluster_id = get_cluster_id(testbed_config['cluster_json_file'])

        cmd = test_conf[
            'smgr_client_cmd'] + " reimage --cluster_id %s ubuntu-server1" % cluster_id
        print "CMD: ", cmd
        handle.sendline(cmd)
        i = handle.expect(['y/N', pexpect.EOF, pexpect.TIMEOUT], timeout=120)
        cmd = 'y'
        output = gen_lib.send_cmd(test_obj, handle, cmd, prompt, 60)
        if re.search('No Image', output):
            err_msg = "ERROR: image-not found error seen\n"
            gen_lib.Print(err_msg)
            test_obj.argument['err_msg'] += err_msg
            sys.exit()
        ret = re.search('server\(s\) reimage queued|issued', output)
        if not ret:
            err_msg = "ERROR: server re-image command failed.\n"
            print err_msg
            test_obj.argument['err_msg'] += err_msg
            sys.exit()

        self.wait_until_reimage_complete()
        time.sleep(180)  # to allow servers to reboot.
Example #10
0
def identify_vm_ip(test_obj, handle, prompt):

    cmd = "route -n"
    output = gen_lib.send_cmd(test_obj, handle, cmd, prompt, 60)

    ret = re.findall('(169.254\.\d+\.\d+) ', output)
    return ret
Example #11
0
def remove_volume_group(test_obj,handle,prompt,vg_name):

  cmd = "pvscan"
  output = gen_lib.send_cmd(test_obj,handle,cmd,prompt,60,True,False) 
  pv_ret = re.findall('PV\s+(\S+)\s+VG\s+%s\s+'%vg_name,output)
  
  if len(pv_ret) == 0 :
    return
   
  cmd = "lvs"
  output = gen_lib.send_cmd(test_obj,handle,cmd,prompt,30,True,False) 
  lv_ret = re.findall('(\S+)\s+%s'%vg_name,output)

  if len(lv_ret):
   cmd = "service tgt stop"
   output = gen_lib.send_cmd(test_obj,handle,cmd,prompt,30,True,False) 
   cmd = "service iscsitarget stop"
   output = gen_lib.send_cmd(test_obj,handle,cmd,prompt,30,True,False) 

  for lv in lv_ret :
    cmd = "lvremove /dev/%s/%s -ff"%(vg_name,lv)
    output = gen_lib.send_cmd(test_obj,handle,cmd,prompt,30,True,False) 
   
  cmd = "vgremove %s"%vg_name
  output = gen_lib.send_cmd(test_obj,handle,cmd,prompt,30,True,False) 

  for pv in pv_ret:
    cmd = "pvremove %s"%pv
    output = gen_lib.send_cmd(test_obj,handle,cmd,prompt,30,True,False) 
Example #12
0
def execute_smgr_cli(test_obj, handle, prompt, cmd, timeout):

    output = gen_lib.send_cmd(test_obj, handle, cmd, prompt, timeout)
    ret = re.search('error', output, re.I)
    if ret:
        msg = "ERROR : error seen for cmd : %s" % cmd
        print msg
        test_obj.argument['err_msg'] += msg
    return output
Example #13
0
def get_network_id(test_obj, handle, prompt, network_name):

    cmd = "neutron net-list --name=%s" % network_name
    output = gen_lib.send_cmd(test_obj, handle, cmd, prompt, 60)

    ret = re.search('\|\s*(\S+)\s*\| %s' % network_name, output)
    if ret:
        return ret.group(1)
    else:
        return -1
Example #14
0
def set_cinder_quota(kwargs):
    handle = kwargs['handle']
    prompt = kwargs['prompt']
    test_obj = kwargs['test_obj']
    tenant_name = kwargs['tenant_name']
    quota = kwargs['quota']
    id = kwargs['tenant_id']

    cmd = "cinder quota --gigabytes=%d %s" % (int(quota), id)
    output = gen_lib.send_cmd(test_obj, handle, cmd, prompt, 30)
Example #15
0
def check_disk_list(test_obj, handle, prompt):

    cmd = "show media-cache disk list"

    output = gen_lib.send_cmd(test_obj, handle, cmd, prompt, 20)

    ret = re.findall('dc_\d+\s*SAS', output)
    if len(ret) != 2:
        err_msg = "ERROR: disk did not attach correctly to MFC\n"
        gen_lib.Print(err_msg)
        test_obj.argument['err_msg'] += err_msg
Example #16
0
def telnet_to_mfc(handle, mfc_ip):

    handle.expect('.*', timeout=2)

    for i in xrange(5):

        cmd = "telnet %s" % mfc_ip
        handle.sendline(cmd)
        i = handle.expect([
            'login', 'Connection timed out',
            'Unable to connect to remote host', pexpect.EOF, pexpect.TIMEOUT
        ],
                          timeout=300)
        output = handle.before
        print output

        if i == 0:
            break
        else:
            time.sleep(10)
            continue

    cmd = "admin"
    handle.sendline(cmd)
    i = handle.expect([pexpect.EOF, pexpect.TIMEOUT, '>', 'Password'],
                      timeout=100)
    output = handle.before
    print output

    if i == 3:
        cmd = "n1keenA"
        handle.sendline(cmd)
        i = handle.expect([pexpect.EOF, pexpect.TIMEOUT, '>'], timeout=100)
        output = handle.before
        print output

    cmd = "en"
    output = gen_lib.send_cmd(test_obj, handle, cmd, '#', 60)
    cmd = "config term"
    output = gen_lib.send_cmd(test_obj, handle, cmd, '\(config\)', 60)
Example #17
0
    def add_images(self):

        handle = self.arg['handle']
        prompt = self.arg['prompt']
        test_obj = self.arg['test_obj']
        test_conf = test_obj.argument['test_conf']['test_conf']
        testbed_config = test_obj.argument['testbed_config']['testbed_config']

        tmp_image_json_file = "/cloud/auto/tmp/smgr_image_%s.json" % strftime(
            "%Y-%m-%d-%H:%M:%S", gmtime())
        print tmp_image_json_file

        file_list = []
        file_list.append(test_conf['contrail-install-packages'])
        file_list.append(test_conf['contrail-storage-packages'])
        ubuntu_version = test_conf['ubuntu_version']
        file_list.append(test_conf['%s,ubuntu-image' % ubuntu_version])
        file_list.append(tmp_image_json_file)

        self.updateImageJsonFile(tmp_image_json_file)

        src_ip = testbed_config['regression,ip']
        src_login = testbed_config['regression,login']
        src_passwd = testbed_config['regression,password']

        cmd = "mkdir /tmp/smgr_files/"
        output = gen_lib.send_cmd(test_obj, handle, cmd, prompt, 10)

        for file in file_list:
            dest_path = "/tmp/smgr_files/"
            if re.search('http://', file):
                d, f = os.path.split(file)
                t = dest_path + f
                status = gen_lib.wget_file(test_obj, handle, prompt, file, t,
                                           300)
            else:
                status = test_obj.remote_scp_from(handle, prompt, file, src_ip,
                                                  src_login, src_passwd,
                                                  dest_path)

            if status:
                msg = "FILE %s copied successfully" % file
                print msg
            else:
                msg = "test_obj.remote_scp/wget for %s failed" % file
                print msg
                test_obj.argument['err_msg'] += msg

        d, f = os.path.split(tmp_image_json_file)
        cmd = test_conf[
            'smgr_client_cmd'] + " add image -f /tmp/smgr_files/%s" % f
        output = execute_smgr_cli(test_obj, handle, prompt, cmd, 180)
Example #18
0
def run_fab_commands1(test_obj,
                      handle,
                      prompt,
                      setup_data_interface=False,
                      host_list=None):

    test_conf = test_obj.argument['test_conf']['test_conf']
    testbed_config = test_obj.argument['testbed_config']['testbed_config']
    profile_name = test_conf['profile_name']
    fab_node_host = testbed_config['%s,fab_node' % profile_name]
    fab_node = testbed_config['%s,node_name' % fab_node_host]

    node_rebooted = upgrade_kernel(test_obj, handle, prompt,
                                   setup_data_interface, host_list)

    if node_rebooted:
        handle = test_obj.argument['%s_handle' % fab_node]

    cmd = "cd /opt/contrail/utils"
    output = gen_lib.send_cmd(test_obj, handle, cmd, prompt, 10)

    cmd = "fab install_contrail"
    output = gen_lib.send_cmd(test_obj, handle, cmd, prompt, 3600)

    if re.search('Abort', output):
        gen_lib.Print("ERROR: %s Aborted" % cmd)
        test_obj.argument['err_msg'] += "ERROR: fab install_contrail failed.\n"
        sys.exit()

    cmd = "cd /opt/contrail/utils"
    output = gen_lib.send_cmd(test_obj, handle, cmd, prompt, 10)

    cmd = "fab setup_all"
    output = gen_lib.send_cmd(test_obj, handle, cmd, prompt, 1800)

    if re.search('Abort', output):
        gen_lib.Print("ERROR: %s Aborted" % cmd)
        test_obj.argument['err_msg'] += "ERROR: fab setup_all falied.\n"
        sys.exit()
Example #19
0
def configure_namespace(test_obj, handle, origin_ip):

    cmd = "namespace abcd origin-server http %s" % origin_ip
    gen_lib.send_cmd(test_obj, handle, cmd, '\(config\)', 10)
    cmd = "namespace abcd match uri /"
    gen_lib.send_cmd(test_obj, handle, cmd, '\(config\)', 10)
    cmd = "namespace abcd status active"
    gen_lib.send_cmd(test_obj, handle, cmd, '\(config\)', 10)
Example #20
0
def create_cinder_volume(kwargs):

    handle = kwargs['handle']
    prompt = kwargs['prompt']
    test_obj = kwargs['test_obj']
    vol_name = kwargs['volume_name']
    vol_type = kwargs['volume_type']
    vol_size = kwargs['volume_size']

    cmd = "cinder create --display-name %s --volume-type %s %d" % (
        vol_name, vol_type, int(vol_size))
    output = gen_lib.send_cmd(test_obj, handle, cmd, prompt, 30)
    ret = re.findall("\s+id\s*\|\s*(\S+)", output)
    return ret[0]
Example #21
0
def snapshot(test_obj, fab_node_handle, fab_node_prompt, vm, snapshot_name):

    cmd = "time nova image-create %s %s --poll" % (vm, snapshot_name)
    output = gen_lib.send_cmd(test_obj, fab_node_handle, cmd, fab_node_prompt,
                              900)

    if not re.search('100%\s*complete', output):
        return -1
    ret = re.search('real\s+(\d+)m(\d+)', output)
    if ret:
        snapshot_time = int(ret.group(1)) * 60 + int(ret.group(2))
    else:
        snapshot_time = -1
    return snapshot_time
Example #22
0
    def wait_until_reimage_complete(self):

        handle = self.arg['handle']
        prompt = self.arg['prompt']
        test_obj = self.arg['test_obj']
        test_conf = test_obj.argument['test_conf']['test_conf']
        testbed_config = test_obj.argument['testbed_config']['testbed_config']

        profile_name = test_conf['profile_name']

        ceph_build_version = ceph.get_ceph_build_version(test_obj)
        node_ubuntu_version = test_conf['ubuntu_version']

        if float(ceph_build_version) >= float("2.10"):
            src_file = testbed_config['%s,%s,server_json_file_post_2.10' %
                                      (profile_name, node_ubuntu_version)]
        else:
            src_file = testbed_config['%s,%s,server_json_file_pre_2.10' %
                                      (profile_name, node_ubuntu_version)]

        node_ubuntu_version = test_conf['ubuntu_version']
        json_data = open(src_file)
        data = simplejson.load(json_data)
        json_data.close()
        server_list = data['server']

        server_list_t = []
        for server in server_list:
            server_list_t.append(server['id'])

        s_list = map(lambda x: x.strip(), server_list_t)
        servers = ",".join(s_list)

        src_file = "/var/nkn/qa/smoke/utils/check_reimage_complete.py"
        src_ip = testbed_config['regression,ip']
        src_login = testbed_config['regression,login']
        src_passwd = testbed_config['regression,password']
        dest_path = "/tmp/smgr_files/"
        status = test_obj.remote_scp_from(handle, prompt, src_file, src_ip,
                                          src_login, src_passwd, dest_path)

        if not status:
            msg = "ERROR : test_obj.remote_scp for %s failed" % src_file
            print msg
            test_obj.argument['err_msg'] += msg
            sys.exit()

        cmd = "python /tmp/smgr_files/check_reimage_complete.py %s" % servers
        output = gen_lib.send_cmd(test_obj, handle, cmd, prompt, 1800)
Example #23
0
def init_sources_list(test_obj,handle,prompt,run_setup=False):

    cmd = "echo > /etc/apt/sources.list"
    output = gen_lib.send_cmd(test_obj,handle,cmd,prompt,60)

    cmd = "apt-get update"
    output = gen_lib.send_cmd(test_obj,handle,cmd,prompt,60)

    if not run_setup:
       return
    cmd = "cd /opt/contrail/contrail_packages/"
    output = gen_lib.send_cmd(test_obj,handle,cmd,'contrail_packages#',10)

    cmd = "./setup.sh"
    output = gen_lib.send_cmd(test_obj,handle,cmd,'contrail_packages#',300)
    if re.search('Abort',output):
       test_obj.argument['err_msg'] += "ERROR: ./setup.sh aborted.\n"
       sys.exit()

    cmd = "./setup_storage.sh"
    output = gen_lib.send_cmd(test_obj,handle,cmd,'contrail_packages#',300)
    if re.search('Abort',output):
       test_obj.argument['err_msg'] += "ERROR: ./setup.sh aborted.\n"
       sys.exit()
Example #24
0
def get_tenant_id(kwargs):

    handle = kwargs['handle']
    prompt = kwargs['prompt']
    test_obj = kwargs['test_obj']
    tenant_name = kwargs['tenant_name']

    cmd = "keystone tenant-list | grep %s" % tenant_name
    output = gen_lib.send_cmd(test_obj, handle, cmd, prompt, 30)

    ret = re.search('\|\s*(\S+)\s*\|\s*%s\s*\|' % tenant_name, output)
    if ret:
        return ret.group(1)
    else:
        return -1
Example #25
0
def check_cinder_volume_state(kwargs):

    handle = kwargs['handle']
    prompt = kwargs['prompt']
    test_obj = kwargs['test_obj']
    vol_name = kwargs['volume_name']
    vol_state = kwargs['volume_state']

    cmd = "cinder list --display-name %s" % kwargs['volume_name']
    output = gen_lib.send_cmd(test_obj, handle, cmd, prompt, 30)

    ret = re.search('(\S+)\s+\|\s+%s\s+' % kwargs['volume_name'], output)

    if ret and ret.group(1) == vol_state:
        return True
    else:
        return False
Example #26
0
def boot_nova_image(kwargs):

    handle = kwargs['handle']
    prompt = kwargs['prompt']
    test_obj = kwargs['test_obj']

    cmd = "nova boot"
    cmd += " --image %s" % kwargs['image_name']
    cmd += " --flavor %s" % kwargs['flavor']
    cmd += " %s" % kwargs['vm_name']
    cmd += " --nic net-id=%s" % kwargs['net_id']

    if kwargs.has_key('zone'):
        cmd += " --availability-zone nova:%s" % kwargs['zone']

    if kwargs.has_key('security-groups'):
        cmd += " --security-groups %s" % kwargs['security-groups']

    output = gen_lib.send_cmd(test_obj, handle, cmd, prompt, 120)
Example #27
0
def get_data_interface_name(test_obj,handle,prompt,node_name):

  testbed_config = test_obj.argument['testbed_config']['testbed_config'] 

  cmd = "/sbin/ifconfig -a | grep '%s'" %testbed_config['%s,data_link,mac'%node_name]
  output = gen_lib.send_cmd(test_obj,handle,cmd,prompt,10)
  gen_lib.Print("####")
  gen_lib.Print(output)
  gen_lib.Print("####")
  ret = re.search('eth\d',output)
  iface = ret.group(0)

  #ip = testbed_config['%s,data_link,ip'%node_name]
  #netmask = testbed_config['%s,data_link,netmask'%node_name]
  #cmd = "/sbin/ifconfig %s %s netmask %s up"%(iface,ip,netmask)
  #output = gen_lib.send_cmd(test_obj,handle,cmd,prompt,10)
  #gen_lib.Print(output)

  return iface
Example #28
0
def check_mfc_version(test_obj, handle, qcow_file):

    cmd = "show version"
    op = gen_lib.send_cmd(test_obj, handle, cmd, '\(config\)', 30)

    d, f = os.path.split(qcow_file)
    build_id = f.split("-")[-1].strip(".qcow2")
    version = f.split("-" + build_id)[0]

    version_match = True
    find = re.search(".*Product release: \s*([a-z0-9_.-]+)", op, re.M)
    if find.group(1) != version:
        version_match = False

    find = re.search(".*Build ID: *([0-9_]*)", op, re.M)
    if find.group(1) != build_id:
        version_match = False

    return version_match
Example #29
0
def add_glance_image(kwargs):

    handle = kwargs['handle']
    prompt = kwargs['prompt']
    test_obj = kwargs['test_obj']

    cmd = "glance image-create"

    cmd += " --name \"%s\"" % kwargs['image_name']
    cmd += " --is-public true"
    cmd += " --container-format %s" % kwargs['container_format']
    cmd += " --disk-format %s" % kwargs['disk_format']
    cmd += " < %s" % kwargs['image']

    output = gen_lib.send_cmd(test_obj, handle, cmd, prompt, 900)
    image_id = re.search('Added new image with ID:\s*(\S+)', output)
    if not image_id:
        return -1
    else:
        return image_id.group(1)
Example #30
0
def get_storage_host_list(test_obj, handle, prompt):

    testbed_config = test_obj.argument['testbed_config']['testbed_config']

    cmd = "ceph osd dump"
    output = gen_lib.send_cmd(test_obj, handle, cmd, prompt, 60)

    ip_list = list(set(re.findall('osd.* (\d+\.\d+\.\d+\.\d+):', output)))
    print ip_list
    host_list = []
    for ip in ip_list:
        for k, v in testbed_config.items():
            if v == ip:
                print v, k
            if v == ip and (re.match('node\d+,ip', k)
                            or re.search('node\d+,data_link,ip', k)):
                node_name = k.split(",")[0]
                host_list.append(testbed_config['%s,host_name' % node_name])
                break
    return host_list