def test():

    image_name = os.environ.get('ipv6ImageName')
    ipv4_net_uuid = test_lib.lib_get_l3_by_name(os.environ.get('l3PublicNetworkName')).uuid
    ipv6_net_uuid = test_lib.lib_get_l3_by_name(os.environ.get('l3PublicNetworkName1')).uuid
    print "ipv4_net_uuid is : %s , ipv6_net_uuid is : %s" %(ipv4_net_uuid, ipv6_net_uuid)
    vm1 = test_stub.create_vm(l3_name = os.environ.get('l3PublicNetworkName'), vm_name = 'vm_1 IPv6 2 stack test', system_tags = ["dualStackNic::%s::%s" %(ipv4_net_uuid, ipv6_net_uuid)], image_name = image_name)
    vm2 = test_stub.create_vm(l3_name = os.environ.get('l3PublicNetworkName'), vm_name = 'vm_2 IPv6 2 stack test', system_tags = ["dualStackNic::%s::%s" %(ipv4_net_uuid, ipv6_net_uuid)], image_name = image_name)
    time.sleep(120) #waiting for vm bootup
    ipv4 = None
    ipv6 = None
    vms = res_ops.query_resource(res_ops.VM_INSTANCE)
    vm1_nic1 = vms[1].vmNics[0].usedIps[0].ip
    vm1_nic2 = vms[1].vmNics[0].usedIps[1].ip
    vm2_nic1 = vms[0].vmNics[0].usedIps[0].ip
    vm2_nic2 = vms[0].vmNics[0].usedIps[1].ip

    for ip in [vm1_nic1, vm1_nic2]:
        if "172.20" in ip:
            ipv4 = ip
    for ip in [vm2_nic1, vm2_nic2]:
        if "1000:2000" in ip:
            ipv6 = ip
    for ip in [vm2_nic1, vm2_nic2]:
        if "172" in ip:
            vm2_ipv4 = ip
    print "vm1_nic1 : %s, vm1_nic2: %s, vm2_nic1 :%s,vm2_nic2 :%s, ipv4 :%s, ipv6 :%s." %(vm1_nic1, vm1_nic2, vm2_nic1, vm2_nic2, ipv4, ipv6)
    cmd = "ping6 -c 4 %s" %(ipv6)
    (retcode, output, erroutput) = ssh.execute(cmd, ipv4, "root", "password", True, 22)
    cmd1 = "ping -c 4 %s" %(vm2_ipv4)
    (retcode1, output1, erroutput1) = ssh.execute(cmd1, ipv4, "root", "password", True, 22)
    print "retcode is: %s; output is : %s.; erroutput is: %s" %(retcode, output , erroutput)
    print "retcode1 is: %s; output1 is : %s.; erroutput1 is: %s" %(retcode1, output1 , erroutput1)
    if retcode != 0 and retcode1 != 0:
        test_util.test_fail('Test Create IPv6 VM Failed.')
 def _install_zstack_nodes_ha(self):
     for node in self.nodes:
         cmd = "/root/scripts/network-setting -b %s %s %s %s %s" % (node.ip_, node.netmask_, node.gateway_, node.nic_, node.bridge_)
         ssh.execute(cmd, node.ip_, node.username_, node.password_)
         ssh.scp_file(self.zstack_pkg, "/root/zstack-installer.bin", node.ip_, node.username_, node.password_)
         cmd = "bash %s -o -i -I %s" % ("/root/zstack-installer.bin", node.bridge_)
         ssh.execute(cmd, node.ip_, node.username_, node.password_)
Example #3
0
def setup_mn_host_vm(vm_inv, vm_config):
    vm_ip = test_lib.lib_get_vm_nic_by_l3(vm_inv, vm_inv.defaultL3NetworkUuid).ip
    vm_nic = os.environ.get('nodeNic')
    vm_netmask = os.environ.get('nodeNetMask')
    vm_gateway = os.environ.get('nodeGateway')
    cmd = '/usr/local/bin/zs-network-setting -b %s %s %s %s' % (vm_nic, vm_ip, vm_netmask, vm_gateway)
    ssh.execute(cmd, vm_ip, vm_config.imageUsername_, vm_config.imagePassword_, True, 22)
 def _install_zstack_nodes_ha(self):
     for node in self.nodes:
         cmd = "/usr/local/bin/zs-network-setting -b %s %s %s %s" % (node.ip_, node.netmask_, node.gateway_, node.nic_)
         ssh.execute(cmd, node.ip_, node.username_, node.password_)
         ssh.scp_file(self.zstack_pkg, "/root/zstack-installer.bin", node.ip_, node.username_, node.password_)
         cmd = "deactivate; which python; bash %s -o -i -I %s" % ("/root/zstack-installer.bin", node.bridge_)
         ssh.execute(cmd, node.ip_, node.username_, node.password_)
Example #5
0
def cleanup_sftp_backup_storage():
    backup_obj = test_lib.deploy_config.backupStorages
    sftp_backupstorages = backup_obj.get_child_node_as_list('sftpBackupStorage')
    for storage in sftp_backupstorages:
        cmd = 'rm -rf %s/rootVolumeTemplates/*' % storage.url_
        ssh.execute(cmd, storage.hostname_, storage.username_, storage.password_)
        cmd = 'rm -rf %s/dataVolumeTemplates/*' % storage.url_
        ssh.execute(cmd, storage.hostname_, storage.username_, storage.password_)
def cleanup_sftp_backup_storage():
    backup_obj = test_lib.deploy_config.backupStorages
    sftp_backupstorages = backup_obj.get_child_node_as_list("sftpBackupStorage")
    for storage in sftp_backupstorages:
        cmd = "rm -rf %s/rootVolumeTemplates/*" % storage.url_
        ssh.execute(cmd, storage.hostname_, storage.username_, storage.password_)
        cmd = "rm -rf %s/dataVolumeTemplates/*" % storage.url_
        ssh.execute(cmd, storage.hostname_, storage.username_, storage.password_)
 def _change_node_ip(self):
     for node in self.nodes:
         cmd = 'zstack-ctl change_ip --ip=%s' % (node.ip_)
         if not linux.is_ip_existing(node.ip_):
             ssh.execute(cmd, node.ip_, node.username_, node.password_)
         else:
             thread = threading.Thread(target=shell_cmd_thread, args=(cmd,))
             thread.start()
             self._wait_for_thread_completion('change management node ip', 60)
 def _change_node_ip(self):
     for node in self.nodes:
         cmd = 'zstack-ctl change_ip --ip=%s --mysql_root_password=%s' % (node.ip_, os.environ.get('DBAdminPassword'))
         if not linux.is_ip_existing(node.ip_):
             ssh.execute(cmd, node.ip_, node.username_, node.password_)
         else:
             thread = threading.Thread(target=shell_cmd_thread, args=(cmd,))
             thread.start()
             self._wait_for_thread_completion('change management node ip', 60)
def setup_vm_console(vm_inv, vm_config, deploy_config):
    vm_ip = test_lib.lib_get_vm_nic_by_l3(vm_inv,
                                          vm_inv.defaultL3NetworkUuid).ip
    cmd = "sed -i 's/quiet/quiet console=ttyS0/g' /etc/default/grub"
    ssh.execute(cmd, vm_ip, vm_config.imageUsername_, vm_config.imagePassword_,
                True, 22)
    cmd = "grub2-mkconfig -o /boot/grub2/grub.cfg"
    ssh.execute(cmd, vm_ip, vm_config.imageUsername_, vm_config.imagePassword_,
                True, 22)
    def _install_zstack_ha(self):
        node1 = self.nodes[0]
	host_info = ""
        host_id = 1
        for node in self.nodes:
            host_info += "--host%s-info %s:%s@%s " % (host_id, node.username_, node.password_, node.ip_)
	    host_id += 1
        cmd = "zstack-ctl install_ha %s --vip %s" % (host_info, self.zstack_ha_vip)
        ssh.execute(cmd, node1.ip_, node1.username_, node1.password_)
 def _install_zstack_nodes_ha(self):
     for node in self.nodes:
         cmd = "/usr/local/bin/zs-network-setting -b %s %s %s %s" % (node.nic_, node.ip_, node.netmask_, node.gateway_)
         print cmd
         ssh.execute(cmd, node.ip_, node.username_, node.password_)
         ssh.scp_file(self.zstack_pkg, "/root/zstack-installer.bin", node.ip_, node.username_, node.password_)
         cmd = "deactivate; which python; bash %s -o -i -I %s" % ("/root/zstack-installer.bin", node.bridge_)
         print cmd
         ssh.execute(cmd, node.ip_, node.username_, node.password_)
Example #12
0
def setup_vm_no_password(vm_inv, vm_config, deploy_config):
    vm_ip = test_lib.lib_get_vm_nic_by_l3(vm_inv, vm_inv.defaultL3NetworkUuid).ip
#    ssh.scp_file(os.environ.get('scenarioPriKey'), '/root/.ssh/id_rsa', vm_ip, vm_config.imageUsername_, vm_config.imagePassword_)
#    ssh.scp_file(os.environ.get('scenarioPubKey'), '/root/.ssh/authorized_keys', vm_ip, vm_config.imageUsername_, vm_config.imagePassword_)
    ssh.scp_file('/home/id_rsa', '/root/.ssh/id_rsa', vm_ip, vm_config.imageUsername_, vm_config.imagePassword_)
    ssh.scp_file('/home/id_rsa.pub', '/root/.ssh/authorized_keys', vm_ip, vm_config.imageUsername_, vm_config.imagePassword_)
    cmd = 'chmod go-rwx /root/.ssh/authorized_keys /root/.ssh/id_rsa'
    ssh.execute(cmd, vm_ip, vm_config.imageUsername_, vm_config.imagePassword_, True, 22)
    cmd = "sed -i 's/.*StrictHostKeyChecking.*$/StrictHostKeyChecking no/g' /etc/ssh/ssh_config"
    ssh.execute(cmd, vm_ip, vm_config.imageUsername_, vm_config.imagePassword_, True, 22)
    def _install_zstack_ha(self):
        node1 = self.nodes[0]
	host_info = ""
        host_id = 1
        for node in self.nodes:
            host_info += "--host%s-info %s:%s@%s " % (host_id, node.username_, node.password_, node.ip_)
	    host_id += 1
        cmd = "zstack-ctl install_ha %s --vip %s" % (host_info, self.zstack_ha_vip)
        print cmd
        ssh.execute(cmd, node1.ip_, node1.username_, node1.password_)
 def _set_extra_node_config(self):
     node1 = self.nodes[0]
     for node in self.nodes:
         cmd = 'zstack-ctl configure --duplicate-to-remote=%s; zstack-ctl configure --host=%s management.server.ip=%s' % \
                 (node.ip_, node.ip_, node.ip_)
         if not linux.is_ip_existing(node.ip_):
             ssh.execute(cmd, node1.ip_, node.username_, node.password_)
         else:
             thread = threading.Thread(target=shell_cmd_thread, args=(cmd,))
             thread.start()
             self._wait_for_thread_completion('set extra management node config', 60)
 def _install_zstack_nodes_ha(self):
     for node in self.nodes:
         cmd = "/root/scripts/network-setting -b %s %s %s %s %s" % (
             node.ip_, node.netmask_, node.gateway_, node.nic_,
             node.bridge_)
         ssh.execute(cmd, node.ip_, node.username_, node.password_)
         ssh.scp_file(self.zstack_pkg, "/root/zstack-installer.bin",
                      node.ip_, node.username_, node.password_)
         cmd = "bash %s -o -i -I %s" % ("/root/zstack-installer.bin",
                                        node.bridge_)
         ssh.execute(cmd, node.ip_, node.username_, node.password_)
 def _set_extra_node_config(self):
     node1 = self.nodes[0]
     for node in self.nodes:
         cmd = 'zstack-ctl configure --duplicate-to-remote=%s; zstack-ctl configure --host=%s management.server.ip=%s' % \
                 (node.ip_, node.ip_, node.ip_)
         if not linux.is_ip_existing(node.ip_):
             ssh.execute(cmd, node1.ip_, node.username_, node.password_)
         else:
             thread = threading.Thread(target=shell_cmd_thread, args=(cmd,))
             thread.start()
             self._wait_for_thread_completion('set extra management node config', 60)
def check_chrony_status(node_ip, port):
    test_util.test_dsc("Check all hosts chrony status.")
    node_ip = node_ip
    port = port
    cmd1 = "chronyc tracking"
    cmd2 = "chronyc sources"
    (retcode1, output, erroutput) = ssh.execute(cmd1, node_ip, 'root', 'password', True, port)
    (retcode2, output, erroutput) = ssh.execute(cmd2, node_ip, 'root', 'password', True, port)
    if retcode1 == 0 and retcode2 == 0:
        test_util.test_logger('@@@DEBUG-> check chrony "chronyc tracking", "chronyc sources" pass')
    else:
        test_util.test_fail('@@@DEBUG-> check chrony "chronyc tracking", "chronyc sources" failed.')
Example #18
0
def setup_ceph_storages(scenario_config, scenario_file, deploy_config):
    ceph_storages = dict()
    for host in xmlobject.safe_list(scenario_config.deployerConfig.hosts.host):
        for vm in xmlobject.safe_list(host.vms.vm):
            vm_name = vm.name_

            if hasattr(vm, 'backupStorageRef'):
                for backupStorageRef in xmlobject.safe_list(vm.backupStorageRef):
                    print backupStorageRef.text_
                    if backupStorageRef.type_ == 'ceph':
                        if ceph_storages.has_key(backupStorageRef.text_):
                            if vm_name in ceph_storages[backupStorageRef.text_]:
                                continue
                            else:
                                ceph_storages[backupStorageRef.text_].append(vm_name)
                        else:
                            ceph_storages[backupStorageRef.text_] = [ vm_name ]

            if hasattr(vm, 'primaryStorageRef'):
                for primaryStorageRef in xmlobject.safe_list(vm.primaryStorageRef):
                    print primaryStorageRef.text_
                    for zone in xmlobject.safe_list(deploy_config.zones.zone):
                        if primaryStorageRef.type_ == 'ceph':
                            if ceph_storages.has_key(backupStorageRef.text_):
                                if vm_name in ceph_storages[backupStorageRef.text_]:
                                    continue
                                else:
                                    ceph_storages[backupStorageRef.text_].append(vm_name)
                            else:
                                ceph_storages[backupStorageRef.text_] = [ vm_name ]

    for ceph_storage in ceph_storages:
        test_util.test_logger('setup ceph [%s] service.' % (ceph_storage))
        node1_name = ceph_storages[ceph_storage][0]
        node1_config = get_scenario_config_vm(node1_name, scenario_config)
        node1_ip = get_scenario_file_vm(node1_name, scenario_file).ip_
        node_host = get_deploy_host(node1_config.hostRef.text_, deploy_config)
        if not hasattr(node_host, 'port_') or node_host.port_ == '22':
            node_host.port_ = '22'

        vm_ips = ''
        for ceph_node in ceph_storages[ceph_storage]:
            vm_nic_id = get_ceph_storages_nic_id(ceph_storage, scenario_config)
            vm = get_scenario_file_vm(ceph_node, scenario_file)
            if vm_nic_id == None:
                vm_ips += vm.ip_ + ' '
            else:
                vm_ips += vm.ips.ip[vm_nic_id].ip_ + ' '
        ssh.scp_file("%s/%s" % (os.environ.get('woodpecker_root_path'), '/tools/setup_ceph_nodes.sh'), '/tmp/setup_ceph_nodes.sh', node1_ip, node1_config.imageUsername_, node1_config.imagePassword_, port=int(node_host.port_))
        cmd = "bash -ex /tmp/setup_ceph_nodes.sh %s" % (vm_ips)
        ssh.execute(cmd, node1_ip, node1_config.imageUsername_, node1_config.imagePassword_, True, int(node_host.port_))
Example #19
0
def setup_ocfs2smp_primary_storages(scenario_config, scenario_file, deploy_config, vm_inv_lst, vm_cfg_lst):
    ocfs2_storages = dict()
    smp_url = None
    for host in xmlobject.safe_list(scenario_config.deployerConfig.hosts.host):
        for vm in xmlobject.safe_list(host.vms.vm):
            vm_name = vm.name_
            if hasattr(vm, 'primaryStorageRef'):
                for primaryStorageRef in xmlobject.safe_list(vm.primaryStorageRef):
                    for zone in xmlobject.safe_list(deploy_config.zones.zone):
                        if primaryStorageRef.type_ == 'ocfs2smp':
                            if ocfs2_storages.has_key(primaryStorageRef.text_):
                                if vm_name in ocfs2_storages[primaryStorageRef.text_]:
                                    continue
                                else:
                                    ocfs2_storages[primaryStorageRef.text_].append(vm_name)
                            else:
                                ocfs2_storages[primaryStorageRef.text_] = [ vm_name ]
                                if hasattr(primaryStorageRef, 'url_'):
                                    smp_url = primaryStorageRef.url_

    for ocfs2_storage in ocfs2_storages:
        test_util.test_logger('setup ocfs2 [%s] service.' % (ocfs2_storage))
        node1_name = ocfs2_storages[ocfs2_storage][0]
        node1_config = get_scenario_config_vm(node1_name, scenario_config)
        #node1_ip = get_scenario_file_vm(node1_name, scenario_file).ip_
        node_host = get_deploy_host(node1_config.hostRef.text_, deploy_config)
        if not hasattr(node_host, 'port_') or node_host.port_ == '22':
            node_host.port_ = '22'

        vm_ips = ''
        for ocfs2_node in ocfs2_storages[ocfs2_storage]:
            vm_nic_id = get_ceph_storages_nic_id(ocfs2_storage, scenario_config)
            vm = get_scenario_file_vm(ocfs2_node, scenario_file)
            if vm_nic_id == None:
                vm_ips += vm.ip_ + ' '
            else:
                vm_ips += vm.ips.ip[vm_nic_id].ip_ + ' '
        #ssh.scp_file("%s/%s" % (os.environ.get('woodpecker_root_path'), '/tools/setup_ocfs2.sh'), '/tmp/setup_ocfs2.sh', node1_ip, node1_config.imageUsername_, node1_config.imagePassword_, port=int(node_host.port_))
        import commands
        status, woodpecker_ip = commands.getstatusoutput("ip addr show eth0 | sed -n '3p' | awk '{print $2}' | awk -F / '{print $1}'")
        if smp_url:
            cmd = "SMP_URL=%s bash %s/%s %s" % (smp_url, os.environ.get('woodpecker_root_path'), '/tools/setup_ocfs2.sh', vm_ips)
        else:
            cmd = "bash %s/%s %s" % (os.environ.get('woodpecker_root_path'), '/tools/setup_ocfs2.sh', vm_ips)
           
        ssh.execute(cmd, woodpecker_ip, node1_config.imageUsername_, node1_config.imagePassword_, True, int(node_host.port_))

    if ocfs2_storages:
        for vm_inv, vm_config in zip(vm_inv_lst, vm_cfg_lst):
            recover_after_host_vm_reboot(vm_inv, vm_config, deploy_config)
Example #20
0
def recover_after_host_vm_reboot(vm_inv, vm_config, deploy_config):
    vm_ip = test_lib.lib_get_vm_nic_by_l3(vm_inv, vm_inv.defaultL3NetworkUuid).ip
    for l3network in xmlobject.safe_list(vm_config.l3Networks.l3Network):
        if hasattr(l3network, 'l2NetworkRef'):
            for l2networkref in xmlobject.safe_list(l3network.l2NetworkRef):
                nic_name = get_ref_l2_nic_name(l2networkref.text_, deploy_config)
                if nic_name.find('.') >= 0:
                    vlan = nic_name.split('.')[1]
                    test_util.test_logger('[vm:] %s %s is created.' % (vm_ip, nic_name))
                    cmd = 'vconfig add %s %s' % (nic_name.split('.')[0], vlan)
                    try:
                        ssh.execute(cmd, vm_ip, vm_config.imageUsername_, vm_config.imagePassword_, True, 22)
                    except:
                        pass
Example #21
0
def setup_primarystorage_vm(vm_inv, vm_config, deploy_config):
    vm_ip = test_lib.lib_get_vm_nic_by_l3(vm_inv, vm_inv.defaultL3NetworkUuid).ip
    host = get_host(vm_config, deploy_config)
    if not hasattr(host, 'port_') or host.port_ == '22':
        host.port_ = '22'

    for primaryStorageRef in xmlobject.safe_list(vm_config.primaryStorageRef):
        print primaryStorageRef.text_
        for zone in xmlobject.safe_list(deploy_config.zones.zone):
            if primaryStorageRef.type_ == 'nfs':
                for nfsPrimaryStorage in xmlobject.safe_list(zone.primaryStorages.nfsPrimaryStorage):
                    if primaryStorageRef.text_ == nfsPrimaryStorage.name_:
                        test_util.test_logger('[vm:] %s setup nfs service.' % (vm_ip))
                        # TODO: multiple NFS PS may refer to same host's different DIR
                        nfsPath = nfsPrimaryStorage.url_.split(':')[1]
                        cmd = "echo '%s *(rw,sync,no_root_squash)' > /etc/exports" % (nfsPath)
                        ssh.execute(cmd, vm_ip, vm_config.imageUsername_, vm_config.imagePassword_, True, int(host.port_))
                        cmd = "mkdir -p %s && service rpcbind restart && service nfs restart" % (nfsPath)
                        ssh.execute(cmd, vm_ip, vm_config.imageUsername_, vm_config.imagePassword_, True, int(host.port_))
                        cmd = "iptables -w 20 -I INPUT -p tcp -m tcp --dport 2049 -j ACCEPT && iptables -w 20 -I INPUT -p udp -m udp --dport 2049 -j ACCEPT"
                        ssh.execute(cmd, vm_ip, vm_config.imageUsername_, vm_config.imagePassword_, True, int(host.port_))
                        return
            elif primaryStorageRef.type_ == 'ceph':
                for cephPrimaryStorage in xmlobject.safe_list(zone.primaryStorages.cephPrimaryStorage):
                    if primaryStorageRef.text_ == cephPrimaryStorage.name_:
                        test_util.test_logger('[vm:] %s setup ceph service.' % (vm_ip))
                        ssh.scp_file("%s/%s" % (os.environ.get('woodpecker_root_path'), '/tools/setup_ceph_nodes.sh'), '/tmp/setup_ceph_nodes.sh', vm_ip, vm_config.imageUsername_, vm_config.imagePassword_, port=host.port_)
                        cmd = "bash -ex /tmp/setup_ceph_nodes.sh"
                        ssh.execute(cmd, vm_ip, vm_config.imageUsername_, vm_config.imagePassword_, True, int(host.port_))

                        #nfsPath = nfsPrimaryStorage.url_.split(':')[1]
                        return
def test():
    vm = test_stub.create_vlan_vm()
    #test_obj_dict.add_vm(vm)

    backup_storage_list = test_lib.lib_get_backup_storage_list_by_vm(vm.vm)
    for bs in backup_storage_list:
        if bs.type == inventory.IMAGE_STORE_BACKUP_STORAGE_TYPE:
            break
        #if bs.type == inventory.SFTP_BACKUP_STORAGE_TYPE:
        #    break
        #if bs.type == inventory.CEPH_BACKUP_STORAGE_TYPE:
        #    break
    else:
        vm.destroy()
        vm.expunge()
        test_util.test_skip('Not find image store type backup storage.')

    new_vms = vm.clone(vm_names)
    for new_vm in new_vms:
        test_obj_dict.add_vm(new_vm)

    if len(new_vms) != len(vm_names):
        test_util.test_fail('only %s VMs have been cloned, which is less than required: %s' % (len(new_vms), vm_names))

    for new_vm in new_vms:
        new_vm = new_vm.get_vm()
        try:
            vm_names.remove(new_vm.name)
            test_util.test_logger('VM:%s name: %s is found' % (new_vm.uuid, new_vm.name))
        except:
            test_util.test_fail('%s vm name: %s is not in list: %s' % (new_vm.uuid, new_vm.name, vm_names))
    
    vm.destroy()
    check_imf2_cmd = "find /|grep imf|grep %s" % (test_lib.lib_get_root_volume_uuid(vm.get_vm()))
    host = test_lib.lib_find_host_by_vm(vm.get_vm()) 
    ret, output, stderr = ssh.execute(check_imf2_cmd, host.managementIp, "root", "password", False, 22)
    test_util.test_logger('expect imf2 exist: %s,%s' % (output, ret))
    if ret != 0:
        test_util.test_fail('imf2 is expected to exist')

    vm.expunge()
    ret, output, stderr = ssh.execute(check_imf2_cmd, host.managementIp, "root", "password", False, 22)
    test_util.test_logger('expect imf2 not exist: %s,%s' % (output, ret))
    if ret == 0:
        test_util.test_fail('imf2 is expected to be deleted')

    test_lib.lib_robot_cleanup(test_obj_dict)
    test_util.test_pass('Clone VM Test Success')
def test():

    img_option = test_util.ImageOption()
    ipv6_image_url = os.environ.get('ipv6ImageUrl')
    image_name = os.environ.get('ipv6ImageName')
    img_option.set_name(image_name)
    bs_uuid = res_ops.query_resource_fields(res_ops.BACKUP_STORAGE, [], None)[0].uuid
    img_option.set_backup_storage_uuid_list([bs_uuid])
    img_option.set_format('qcow2')
    img_option.set_url(ipv6_image_url)
    image_inv = img_ops.add_root_volume_template(img_option)
    image = test_image.ZstackTestImage()
    image.set_image(image_inv)
    image.set_creation_option(img_option)
    test_obj_dict.add_image(image)
    vm1 = test_stub.create_vm(l3_name = "%s,%s" %(os.environ.get('l3PublicNetworkName1'), os.environ.get('l3PublicNetworkName')), vm_name = 'IPv6 2 stack test ipv4 and ipv6', image_name = image_name)
    vm2 = test_stub.create_vm(l3_name = os.environ.get('l3PublicNetworkName1'), vm_name = 'IPv6 2 stack test ipv6', image_name = image_name)
    time.sleep(90) #waiting for vm bootup
    vm1_nic1 = vm1.get_vm().vmNics[0].ip
    vm1_nic2 = vm1.get_vm().vmNics[1].ip
    vm2_nic1 = vm2.get_vm().vmNics[0].ip
    for ip in (vm1_nic1, vm1_nic2):
        if "." in ip:
            ipv4 = ip
    print "vm1_nic1 : %s, vm1_nic2: %s, vm2_nic1 :%s, ipv4 :%s." %(vm1_nic1, vm1_nic2, vm2_nic1,ipv4)
    cmd = "ping6 -c 4 %s" %(vm2_nic1)
    (retcode, output, erroutput) = ssh.execute(cmd, ipv4, "root", "password", True, 22)
    print "retcode is: %s; output is : %s.; erroutput is: %s" %(retcode, output , erroutput)
    if retcode != 0:
        test_util.test_fail('Test Create IPv6 VM Failed.')
Example #24
0
def setup_backupstorage_vm(vm_inv, vm_config, deploy_config):
    vm_ip = test_lib.lib_get_vm_nic_by_l3(vm_inv, vm_inv.defaultL3NetworkUuid).ip
    host = get_host(vm_config, deploy_config)
    if not hasattr(host, 'port_') or host.port_ == '22':
        host.port_ = '22'

    for backupStorageRef in xmlobject.safe_list(vm_config.backupStorageRef):
        print backupStorageRef.text_
        if backupStorageRef.type_ == 'sftp':
            for sftpBackupStorage in xmlobject.safe_list(deploy_config.backupStorages.sftpBackupStorage):
                if backupStorageRef.text_ == sftpBackupStorage.name_:
                    # TODO: sftp may setup with non-root or non-default user/password port
                    test_util.test_logger('[vm:] %s setup sftp service.' % (vm_ip))
                    cmd = "mkdir -p %s" % (sftpBackupStorage.url_)
                    ssh.execute(cmd, vm_ip, vm_config.imageUsername_, vm_config.imagePassword_, True, int(host.port_))
                    return
def set_quick_ha_properties():
    host_username = os.environ.get('hostUsername')
    host_password = os.environ.get('hostPassword')
    mn_ip = res_ops.query_resource(res_ops.MANAGEMENT_NODE)[0].hostName
    cmd = 'zstack-ctl status|grep properties|cut -d: -f2'
    ret, properties_file, stderr = ssh.execute(cmd, mn_ip, host_username, host_password, False, 22)

    cmd = "zstack-ctl stop"
    if test_lib.lib_execute_ssh_cmd(mn_ip, host_username, host_password, cmd,  timeout = 120) == False:
        test_util.test_fail("CMD:%s execute failed on %s" %(cmd, mn_ip))

    cmd = "sed 's/RESTFacade.connectTimeout.*$//g' -i " + properties_file
    if test_lib.lib_execute_ssh_cmd(mn_ip, host_username, host_password, cmd,  timeout = 10) == False:
        test_util.test_fail("CMD:%s execute failed on %s" %(cmd, mn_ip))

    cmd = "sed 's/RESTFacade.readTimeout.*$//g' -i " + properties_file
    if test_lib.lib_execute_ssh_cmd(mn_ip, host_username, host_password, cmd,  timeout = 10) == False:
        test_util.test_fail("CMD:%s execute failed on %s" %(cmd, mn_ip))

    cmd = "echo \"RESTFacade.readTimeout = 10000\" >>" + properties_file
    if test_lib.lib_execute_ssh_cmd(mn_ip, host_username, host_password, cmd,  timeout = 10) == False:
        test_util.test_fail("CMD:%s execute failed on %s" %(cmd, mn_ip))

    cmd = "echo \"RESTFacade.connectTimeout = 5000\" >>" + properties_file
    if test_lib.lib_execute_ssh_cmd(mn_ip, host_username, host_password, cmd,  timeout = 10) == False:
        test_util.test_fail("CMD:%s execute failed on %s" %(cmd, mn_ip))

    cmd = "nohup zstack-ctl start &"
    if test_lib.lib_execute_ssh_cmd(mn_ip, host_username, host_password, cmd,  timeout = 180) == False:
        test_util.test_fail("CMD:%s execute failed on %s" %(cmd, mn_ip))

    time.sleep(60)
Example #26
0
def ensure_storage_online(vm):
    ret, output, stderr = ssh.execute("o2cb.init status", vm.get_vm().vmNics[0].ip, "root", "password", False, 22)
    if ret != 0:
        test_util.test_fail( cmd + " failed")

    if "online" not in output.lower():
        test_util.test_fail("not found storage online")
def test():

    image_name = os.environ.get('ipv6ImageName')
    vm1 = test_stub.create_vm(l3_name = "%s,%s" %(os.environ.get('l3PublicNetworkName1'), os.environ.get('l3PublicNetworkName')), vm_name = 'IPv6 2 stack test ipv4 and ipv6', image_name = image_name)
    vm2 = test_stub.create_vm(l3_name = os.environ.get('l3PrivateNetworkName'), vm_name = 'IPv6 private vm', image_name = image_name)
    time.sleep(90) #waiting for vm bootup
    vm1_nic1 = vm1.get_vm().vmNics[0].ip
    vm1_nic2 = vm1.get_vm().vmNics[1].ip
    vm2_nic1 = vm2.get_vm().vmNics[0].ip
    for ip in (vm1_nic1, vm1_nic2):
        if "." in ip:
            ipv4 = ip
    print "vm1_nic1 : %s, vm1_nic2: %s, vm2_nic1 :%s, ipv4 :%s." %(vm1_nic1, vm1_nic2, vm2_nic1,ipv4)
#######################################################################
    pub_l3_name = os.environ.get('l3PublicNetworkName1')
    pub_l3_uuid = test_lib.lib_get_l3_by_name(pub_l3_name).uuid

    vm2_nic_uuid = vm2.get_vm().vmNics[0].uuid
    vip = test_stub.create_vip('create_eip_test', pub_l3_uuid)
    test_obj_dict.add_vip(vip)
    eip = test_stub.create_eip('create eip test', vip_uuid=vip.get_vip().uuid, vnic_uuid=vm2_nic_uuid, vm_obj=vm2)

    vip.attach_eip(eip)
    eip_ip = res_ops.query_resource(res_ops.EIP)[0].vipIp

    print "eip_ip : %s, vm1_nic2: %s, vm2_nic1 :%s, ipv4 :%s." %(eip_ip, vm1_nic2, vm2_nic1,ipv4)
    cmd = "ping6 -c 4 %s" %(eip_ip)
    (retcode, output, erroutput) = ssh.execute(cmd, ipv4, "root", "password", True, 22)
    print "ping6 EIP retcode is: %s; output is : %s.; erroutput is: %s" %(retcode, output , erroutput)
    if retcode != 0:
        test_util.test_fail('Test Create IPv6 VM Failed.')
def ensure_storage_online(vm):
    ret, output, stderr = ssh.execute("o2cb.init status", vm.get_vm().vmNics[0].ip, "root", "password", False, 22)
    if ret != 0:
        test_util.test_fail( cmd + " failed")

    if "online" not in output.lower():
        test_util.test_fail("not found storage online")
def exec_cmd_in_vm(vm, cmd, fail_msg):
    ret, output, stderr = ssh.execute(cmd,
                                      vm.get_vm().vmNics[0].ip, "root",
                                      "password", False, 22)
    if ret != 0:
        test_util.test_fail(fail_msg)
    return output
def force_vm_auto_boot(vm):
    cmd = "sed -i \"s/  set timeout=-1/  set timeout=3/g\" /boot/grub/grub.cfg; sync"
    ret, output, stderr = ssh.execute(cmd,
                                      vm.get_vm().vmNics[0].ip, "root",
                                      "password", False, 22)
    if ret != 0:
        test_util.test_fail("Force vm auto boot setting failed.")
    def _change_node_ip(self):
        for node in self.nodes:
            cmd = 'zstack-ctl change_ip --ip=%s --mysql_root_password=%s' % (node.ip_, os.environ.get('DBAdminPassword'))
            if not linux.is_ip_existing(node.ip_):
                ssh.execute(cmd, node.ip_, node.username_, node.password_)
            else:
                thread = threading.Thread(target=shell_cmd_thread, args=(cmd,))
                thread.start()
                self._wait_for_thread_completion('change management node ip', 120)

            cmd = 'zstack-ctl configure InfluxDB.startupTimeout=1200'
            if not linux.is_ip_existing(node.ip_):
                ssh.execute(cmd, node.ip_, node.username_, node.password_)
            else:
                thread = threading.Thread(target=shell_cmd_thread, args=(cmd,))
                thread.start()
                self._wait_for_thread_completion('InfluxDB startup time setting to 10 mins', 120)
Example #32
0
def exec_cmd_in_vm(vm, cmd, fail_msg, ignore_fail=False):
    ret, output, stderr = ssh.execute(cmd,
                                      vm.get_vm().vmNics[0].ip, "root",
                                      "password", False, 22)
    if ret != 0 and ignore_fail == False:
        test_util.test_fail("%s:%s" % (fail_msg, stderr))
    elif ret != 0 and ignore_fail == True:
        test_util.test_logger("skip failure: %s" % (stderr))
Example #33
0
 def copy_data(self, vm=None):
     vm = vm if vm else self.vm
     vm_ip = vm.get_vm().vmNics[0].ip
     test_lib.lib_wait_target_up(vm_ip, '22', timeout=600)
     cmd = "find /home -iname 'zstack-all-in-one.*'"
     file_path = commands.getoutput(cmd).split('\n')[0]
     file_name = os.path.basename(file_path)
     dst_file = os.path.join('/mnt', file_name)
     src_file_md5 = commands.getoutput('md5sum %s' % file_path).split(' ')[0]
     ssh.scp_file(file_path, dst_file, vm_ip, 'root', 'password')
     (_, dst_md5, _)= ssh.execute('sync; sync; sleep 60; md5sum %s' % dst_file, vm_ip, 'root', 'password')
     dst_file_md5 = dst_md5.split(' ')[0]
     test_util.test_dsc('src_file_md5: [%s], dst_file_md5: [%s]' % (src_file_md5, dst_file_md5))
     assert dst_file_md5 == src_file_md5, 'dst_file_md5 [%s] and src_file_md5 [%s] is not match, stop test' % (dst_file_md5, src_file_md5)
     extract_cmd = 'tar xvf /mnt/zstack-all-in-one.* -C /mnt > /dev/null 2>&1'
     ssh.execute(extract_cmd, vm_ip, 'root', 'password')
     return self
Example #34
0
def create_user_in_vm(vm, username, password):
    """
    create non-root user with password setting
    """
    global original_root_password
    test_util.test_logger("create_user_in_vm: %s:%s" %(username, password))

    vm_ip = vm.vmNics[0].ip

    cmd = "adduser %s" % (username)
    ret, output, stderr = ssh.execute(cmd, vm_ip, "root", original_root_password, False, 22)
    if ret != 0:
        test_util.test_fail("User created failure, cmd[%s], output[%s], stderr[%s]" %(cmd, output, stderr))

    cmd = "echo -e \'%s\n%s\' | passwd %s" % (password, password, username)
    ret, output, stderr = ssh.execute(cmd, vm_ip, "root", original_root_password, False, 22)
    if ret != 0:
        test_util.test_fail("set non-root password failure, cmd[%s], output[%s], stderr[%s]" %(cmd, output, stderr))
def set_quick_ha_properties():
    host_username = os.environ.get('hostUsername')
    host_password = os.environ.get('hostPassword')
    mn_ip = res_ops.query_resource(res_ops.MANAGEMENT_NODE)[0].hostName
    cmd = 'zstack-ctl status|grep properties|cut -d: -f2'
    ret, properties_file, stderr = ssh.execute(cmd, mn_ip, host_username,
                                               host_password, False, 22)

    cmd = "zstack-ctl stop"
    if test_lib.lib_execute_ssh_cmd(mn_ip,
                                    host_username,
                                    host_password,
                                    cmd,
                                    timeout=120) == False:
        test_util.test_fail("CMD:%s execute failed on %s" % (cmd, mn_ip))

    cmd = "sed 's/RESTFacade.connectTimeout.*$//g' -i " + properties_file
    if test_lib.lib_execute_ssh_cmd(mn_ip,
                                    host_username,
                                    host_password,
                                    cmd,
                                    timeout=10) == False:
        test_util.test_fail("CMD:%s execute failed on %s" % (cmd, mn_ip))

    cmd = "sed 's/RESTFacade.readTimeout.*$//g' -i " + properties_file
    if test_lib.lib_execute_ssh_cmd(mn_ip,
                                    host_username,
                                    host_password,
                                    cmd,
                                    timeout=10) == False:
        test_util.test_fail("CMD:%s execute failed on %s" % (cmd, mn_ip))

    cmd = "echo \"RESTFacade.readTimeout = 5000\" >>" + properties_file
    if test_lib.lib_execute_ssh_cmd(mn_ip,
                                    host_username,
                                    host_password,
                                    cmd,
                                    timeout=10) == False:
        test_util.test_fail("CMD:%s execute failed on %s" % (cmd, mn_ip))

    cmd = "echo \"RESTFacade.connectTimeout = 5000\" >>" + properties_file
    if test_lib.lib_execute_ssh_cmd(mn_ip,
                                    host_username,
                                    host_password,
                                    cmd,
                                    timeout=10) == False:
        test_util.test_fail("CMD:%s execute failed on %s" % (cmd, mn_ip))

    cmd = "nohup zstack-ctl start &"
    if test_lib.lib_execute_ssh_cmd(mn_ip,
                                    host_username,
                                    host_password,
                                    cmd,
                                    timeout=180) == False:
        test_util.test_fail("CMD:%s execute failed on %s" % (cmd, mn_ip))

    time.sleep(60)
def check_qemu_ga_is_alive(vm):
    global ga_process_not_alive_num
    vm.check()
    cmd = "ps -aux|grep ga|grep qemu"
    ret, output, stderr = ssh.execute(cmd, vm.get_vm().vmNics[0].ip, "root", "password", False, 22)
    if ret != 0:
        test_util.test_logger("qemu-ga is not alived when exception triggered: ip:%s; cmd:%s; user:%s; password:%s; stdout:%s, stderr:%s" %(vm.get_vm().vmNics[0].ip, cmd, "root", "password", output, stderr))
        ga_process_not_alive_num = ga_process_not_alive_num + 1
    return ret
def test():
    test_util.test_dsc('Check host active profile')
    conditions = res_ops.gen_query_conditions('state', '=', host_header.ENABLED)
    conditions = res_ops.gen_query_conditions('status', '=', host_header.CONNECTED, conditions)
    all_hosts = res_ops.query_resource(res_ops.HOST, conditions)
    if len(all_hosts) < 1:
        test_util.test_skip('Not available host to check')

    command = '/usr/sbin/tuned-adm active'
    for host in all_hosts:
        eout = ''
        if host.sshPort != None:
            (ret, out, eout) = ssh.execute(command, host.managementIp, host.username, host.password, port=host.sshPort)
	else:
            (ret, out, eout) = ssh.execute(command, host.managementIp, host.username, host.password)
         
        if out.find('virtual-host') < 0:
            test_util.test_fail('host not tuned to virtual-host mode')
def check_vr_reboot_record_line(vr_ip):
    global vr_type
    cmd = 'last reboot|grep reboot|wc -l'
    test_util.test_logger("check vr type is %s, vr_ip:%s" % (vr_type, vr_ip))
    if vr_type == "VirtualRouter":
        ret, output, stderr = ssh.execute(cmd, vr_ip,
                                          os.environ.get('vrImageUsername'),
                                          os.environ.get('vrImagePassword'),
                                          False, 22)
    elif vr_type == "vrouter":
        ret, output, stderr = ssh.execute(cmd, vr_ip, "vyos", "vrouter12#",
                                          False, 22)
    else:
        test_util.test_fail("vr is not expected type")

    if ret != 0:
        test_util.test_fail("%s login failed" % (vr_type))

    return output
Example #39
0
def check_qemu_ga_is_alive(vm):
    global cur_usr, cur_passwd
    cmd = "ps -aux|grep ga|grep qemu"
    ret, output, stderr = ssh.execute(cmd,
                                      vm.get_vm().vmNics[0].ip, cur_usr,
                                      cur_passwd, False, 22)
    if ret != 0:
        test_util.test_logger(
            "qemu-ga is not alived when exception triggered: ip:%s; cmd:%s; user:%s; password:%s; stdout:%s, stderr:%s"
            % (vm.get_vm().vmNics[0].ip, cmd, cur_usr, cur_passwd, output,
               stderr))
Example #40
0
    def check_data(self, vm=None):
        vm = vm if vm else self.vm
        vm_ip = vm.get_vm().vmNics[0].ip
        test_lib.lib_wait_target_up(vm_ip, '22', timeout=600)
#         check_cmd = "if [ ! -d /mnt/zstackwoodpecker ];then tar xvf /mnt/zstack-all-in-one.tar -C /mnt > /dev/null 2>&1; fi; \
#                      grep scenario_config_path /mnt/zstackwoodpecker/zstackwoodpecker/test_lib.py > /dev/null 2>&1 && echo 0 || echo 1"
        check_cmd = "grep APIQueryCephPrimaryStorageMsg /mnt/woodpecker/apibinding/inventory.py > /dev/null 2>&1 && echo 0 || echo 1"
        (_, ret, _)= ssh.execute(check_cmd, vm_ip, 'root', 'password')
        ret = ret.split('\n')[0]
        assert ret == '0', "data check failed!, the return code is %s, 0 is expected" % ret
        return self
def test():
    test_util.test_dsc('Create test vm with EIP and check.')
    vm1 = test_stub.create_vlan_vm(os.environ.get('l3VlanNetworkName1'))
    test_obj_dict.add_vm(vm1)

    vm2 = test_stub.create_vlan_vm(os.environ.get('l3VlanNetworkName1'))
    test_obj_dict.add_vm(vm2)

    pri_l3_name = os.environ.get('l3VlanNetworkName1')
    pri_l3_uuid = test_lib.lib_get_l3_by_name(pri_l3_name).uuid

    pub_l3_name = os.environ.get('l3PublicNetworkName')
    pub_l3_uuid = test_lib.lib_get_l3_by_name(pub_l3_name).uuid

    vm1_nic = vm1.vm.vmNics[0]
    vm1_nic_uuid = vm1_nic.uuid

    vm2_nic = vm2.vm.vmNics[0]
    vm2_nic_uuid = vm2_nic.uuid

    [test_stub.run_command_in_vm(vm.get_vm(), 'iptables -F') for vm in (vm1, vm2)]

    vip = test_stub.create_vip('create_eip_test', pub_l3_uuid)
    vip_ip = vip.get_vip().ip
    test_obj_dict.add_vip(vip)
    eip = test_stub.create_eip('create eip test', vip_uuid=vip.get_vip().uuid, vnic_uuid=vm1_nic_uuid, vm_obj=vm1)

    vip.attach_eip(eip)

    vm1.check()

    pri_l3_gateway = os.environ.get('vlanIpRangeGateway1')

    cmd1 = "ping -c 5 %s" % (vip_ip)
    (retcode1, output1, erroutput1) = ssh.execute(cmd1, ext_host_ip, "root", ext_host_pwd, True, 22)
    print "retcode1 is: %s; output1 is : %s.; erroutput1 is: %s" % (retcode1, output1, erroutput1)

    cmd2 = "arp -n | grep -w %s" % (pri_l3_gateway)
    if test_lib.lib_execute_command_in_flat_vm(vm2.vm, cmd2, l3_uuid=pri_l3_uuid):
        vm1.destroy()
        vm2.destroy()
        vm1.expunge()
        vm2.expunge()
        eip.delete()
        vip.delete()
        test_util.test_fail('Gateway leak to other vm, test failed.')

    vm1.destroy()
    vm2.destroy()
    vm1.expunge()
    vm2.expunge()
    eip.delete()
    vip.delete()
def test():
    recnt_timeout = 30000
    test_util.test_dsc('Test Host Reconnect within %s ms' % recnt_timeout)
    vm = test_stub.create_vlan_vm(os.environ.get('l3VlanNetworkName1'))
    test_obj_dict.add_vm(vm)

    zone_uuid = vm.get_vm().zoneUuid
    host = test_lib.lib_get_vm_host(vm.get_vm())
    host_uuid = host.uuid
    host_management_ip = host.managementIp
    cmd = "mkdir /var/lib/ebtables/; touch /var/lib/ebtables/lock; touch /run/ebtables.lock"
    try:
        ssh.execute(cmd, host_management_ip, "root", "password", True, 22)
    except:
        ssh.execute(cmd, host_management_ip, "root", "password", True, 22)
    try:
        host_ops.reconnect_host(host_uuid, timeout=recnt_timeout)
    except:
        host_ops.reconnect_host(host_uuid, timeout=recnt_timeout)

    test_util.test_pass('Reconnect Host within %s ms' % recnt_timeout)
Example #43
0
def setup_primarystorage_vm(vm_inv, vm_config, deploy_config):
    vm_ip = test_lib.lib_get_vm_nic_by_l3(vm_inv, vm_inv.defaultL3NetworkUuid).ip
    if hasattr(vm_config, 'hostRef'):
        host = get_deploy_host(vm_config.hostRef.text_, deploy_config)
        if not hasattr(host, 'port_') or host.port_ == '22':
            host_port = '22'
        else:
            host_port = host.port_
    else:
        host_port = '22'

    for primaryStorageRef in xmlobject.safe_list(vm_config.primaryStorageRef):
        print primaryStorageRef.text_
        for zone in xmlobject.safe_list(deploy_config.zones.zone):
            if primaryStorageRef.type_ == 'nfs':
                for nfsPrimaryStorage in xmlobject.safe_list(zone.primaryStorages.nfsPrimaryStorage):
                    if primaryStorageRef.text_ == nfsPrimaryStorage.name_:
                        test_util.test_logger('[vm:] %s setup nfs service.' % (vm_ip))
                        # TODO: multiple NFS PS may refer to same host's different DIR
                        nfsPath = nfsPrimaryStorage.url_.split(':')[1]
                        cmd = "echo '%s *(rw,sync,no_root_squash)' > /etc/exports" % (nfsPath)
                        ssh.execute(cmd, vm_ip, vm_config.imageUsername_, vm_config.imagePassword_, True, int(host_port))
                        cmd = "mkdir -p %s && service rpcbind restart && service nfs restart" % (nfsPath)
                        ssh.execute(cmd, vm_ip, vm_config.imageUsername_, vm_config.imagePassword_, True, int(host_port))
                        cmd = "iptables -w 20 -I INPUT -p tcp -m tcp --dport 2049 -j ACCEPT && iptables -w 20 -I INPUT -p udp -m udp --dport 2049 -j ACCEPT"
                        ssh.execute(cmd, vm_ip, vm_config.imageUsername_, vm_config.imagePassword_, True, int(host_port))
                        return
Example #44
0
def deploy_ha_env(scenarioConfig, scenarioFile, deploy_config, config_json,
                  deploy_tool, mn_img):
    prepare_config_json(scenarioConfig, scenarioFile, deploy_config,
                        config_json)
    test_host = get_mn_host(scenarioConfig, scenarioFile)[0]
    test_host_ip = test_host.ip_
    test_host_config = sce_ops.get_scenario_config_vm(test_host.name_,
                                                      scenarioConfig)
    host_password = test_host_config.imagePassword_
    mn_image_path = "/home/%s/mn.qcow2" % test_host_ip
    installer_path = "/home/%s/zs-ha" % test_host_ip
    config_path = "/home/%s/config.json" % test_host_ip
    ssh.scp_file(config_json, config_path, test_host_ip,
                 test_host_config.imageUsername_,
                 test_host_config.imagePassword_)
    cmd1 = "ceph osd pool create zstack 128"
    cmd2 = "qemu-img convert -f qcow2 -O raw %s rbd:zstack/mnvm.img" % mn_image_path
    cmd3 = '%s -a -p %s -c %s' % (installer_path, host_password, config_path)
    test_util.test_logger("[%s] %s" % (test_host_ip, cmd1))
    ssh.execute(cmd1, test_host_ip, test_host_config.imageUsername_,
                test_host_config.imagePassword_, True, 22)
    test_util.test_logger("[%s] %s" % (test_host_ip, cmd2))
    ssh.execute(cmd2, test_host_ip, test_host_config.imageUsername_,
                test_host_config.imagePassword_, True, 22)
    test_util.test_logger("[%s] %s" % (test_host_ip, cmd3))
    ssh.execute(cmd3, test_host_ip, test_host_config.imageUsername_,
                test_host_config.imagePassword_, True, 22)
Example #45
0
def setup_host_vm(vm_inv, vm_config, deploy_config):
    vm_ip = test_lib.lib_get_vm_nic_by_l3(vm_inv, vm_inv.defaultL3NetworkUuid).ip
    udev_config = ''
    for l3network in xmlobject.safe_list(vm_config.l3Networks.l3Network):
        for vmnic in vm_inv.vmNics:
            if vmnic.l3NetworkUuid == l3network.uuid_:
                vmnic_mac = vmnic.mac
                break
        for l2networkref in xmlobject.safe_list(l3network.l2NetworkRef):
            nic_name = get_ref_l2_nic_name(l2networkref.text_, deploy_config)
            if nic_name.find('.') < 0:
                break

        udev_config = udev_config + '\\nACTION=="add", SUBSYSTEM=="net", DRIVERS=="?*", ATTR{type}=="1", ATTR{address}=="%s", NAME="%s"' % (vmnic_mac, nic_name)

    cmd = 'echo %s > /etc/udev/rules.d/70-persistent-net.rules' % (udev_config)
    ssh.execute(cmd, vm_ip, vm_config.imageUsername_, vm_config.imagePassword_, True, 22)

    for l2networkref in xmlobject.safe_list(vm_config.l3Networks.l3Network.l2NetworkRef):
        nic_name = get_ref_l2_nic_name(l2networkref.text_, deploy_config)
        if nic_name.find('.') >= 0:
            vlan = nic_name.split('.')[1]
            test_util.test_logger('[vm:] %s %s is created.' % (vm_ip, nic_name))
            cmd = 'vconfig add %s %s' % (nic_name.split('.')[0], vlan)
            ssh.execute(cmd, vm_ip, vm_config.imageUsername_, vm_config.imagePassword_, True, 22)

    host = get_host(vm_config, deploy_config)
    if hasattr(host, 'port_') and host.port_ != '22':
        cmd = "sed -i 's/#Port 22/Port %s/g' /etc/ssh/sshd_config && iptables -I INPUT -p tcp -m tcp --dport %s -j ACCEPT && service sshd restart" % (host.port_, host.port_)
        ssh.execute(cmd, vm_ip, vm_config.imageUsername_, vm_config.imagePassword_, True, 22)
    else:
        host.port_ = '22'

    if host.username_ != 'root':
        cmd = 'adduser %s && echo -e %s\\\\n%s | passwd %s' % (host.username_, host.password_, host.password_, host.username_)
        ssh.execute(cmd, vm_ip, vm_config.imageUsername_, vm_config.imagePassword_, True, int(host.port_))
        cmd = "echo '%s        ALL=(ALL)       NOPASSWD: ALL' >> /etc/sudoers" % (host.username_)
        ssh.execute(cmd, vm_ip, vm_config.imageUsername_, vm_config.imagePassword_, True, int(host.port_))
Example #46
0
def check_qemu_ga_is_alive(vm):
    global ga_process_not_alive_num
    vm.check()
    cmd = "ps -aux|grep ga|grep qemu"
    ret, output, stderr = ssh.execute(cmd,
                                      vm.get_vm().vmNics[0].ip, "root",
                                      "password", False, 22)
    if ret != 0:
        test_util.test_logger(
            "qemu-ga is not alived when exception triggered: ip:%s; cmd:%s; user:%s; password:%s; stdout:%s, stderr:%s"
            % (vm.get_vm().vmNics[0].ip, cmd, "root", "password", output,
               stderr))
        ga_process_not_alive_num = ga_process_not_alive_num + 1
    return ret
Example #47
0
def create_user_in_vm(vm, username, password):
    """
    create non-root user with password setting
    """
    global original_root_password
    test_util.test_logger("create_user_in_vm: %s:%s" % (username, password))

    vm_ip = vm.vmNics[0].ip

    cmd = "adduser %s" % (username)
    ret, output, stderr = ssh.execute(cmd, vm_ip, "root",
                                      original_root_password, False, 22)
    if ret != 0:
        test_util.test_fail(
            "User created failure, cmd[%s], output[%s], stderr[%s]" %
            (cmd, output, stderr))

    cmd = "echo -e \'%s\n%s\' | passwd %s" % (password, password, username)
    ret, output, stderr = ssh.execute(cmd, vm_ip, "root",
                                      original_root_password, False, 22)
    if ret != 0:
        test_util.test_fail(
            "set non-root password failure, cmd[%s], output[%s], stderr[%s]" %
            (cmd, output, stderr))
def test():
    test_util.test_dsc('create ceph pool')
    try:
        ps = res_ops.query_resource(res_ops.CEPH_PRIMARY_STORAGE)[0]
    except Exception as e:
        test_util.test_dsc(str(e))
        test_util.test_skip('Skip for not finding ceph ps')
    ps_uuid = ps.uuid
    try:
        ceph_node_ip = ps.mons[0].monAddr
    except Exception as e:
        test_util.test_dsc(str(e))
        test_util.test_fail('Fail to get mon ip')
    create_pool_cmd = 'ceph osd pool create for_test_pool_create 4'
    try:
        (ret, out, eout) = ssh.execute(create_pool_cmd, ceph_node_ip, 'root',
                                       'password')
    except Exception as e:
        test_util.test_dsc(str(e))
        test_util.test_fail('Fail to create pool by using ceph command')
    aliasName = 'test_aliasName_new'
    poolName = 'test_poolName'
    description = 'test_description'
    isCreate = 'true'
    test_util.test_dsc('add new pool by zstack')
    ps_ops.add_ceph_primary_storage_pool(ps_uuid, poolName, aliasName,
                                         isCreate)
    cond = res_ops.gen_query_conditions('aliasName', '=', aliasName)
    pool = res_ops.query_resource(res_ops.CEPH_PRIMARY_STORAGE_POOL, cond)[0]
    print pool
    test_util.test_dsc("poolName: " + str(pool.poolName))
    if pool.poolName != poolName:
        test_util.test_fail('Find wrong pool should find: ' + str(poolName) +
                            'But find: ' + str(pool.poolName))
    test_util.test_dsc('add exist pool by zstack')
    aliasName = 'test_aliasName_exist'
    ps_ops.add_ceph_primary_storage_pool(ps_uuid, 'for_test_pool_create',
                                         aliasName)
    cond = res_ops.gen_query_conditions('aliasName', '=', aliasName)
    pool = res_ops.query_resource(res_ops.CEPH_PRIMARY_STORAGE_POOL, cond)[0]
    test_util.test_dsc("poolName: " + str(pool.poolName))
    if pool.poolName != 'for_test_pool_create':
        test_util.test_fail(
            'Find wrong pool should find: for_test_pool_create But find: ' +
            str(pool.poolName))
Example #49
0
        def login_vm():
            try:
                ret, output, stderr = ssh.execute(cmd.command, cmd.ip, cmd.username, cmd.password, False)
                if ret != 0:
                    rsp.success = False
                    rsp.error = '%s\n%s' % (output, stderr)
                else:
                    rsp.result = output

                rsp_dict['completion'] = True
                return True

            except Exception as e:
                logger.debug('[SSH] unable to ssh in vm[ip:%s], assume its not ready. Exception: %s' % (cmd.ip, str(e)))
                rsp_dict['error'] = True
                rsp_dict['completion'] = True
                
            return False
def test():
    test_util.test_dsc('create ceph pool')
    try:
        ps = res_ops.query_resource(res_ops.CEPH_PRIMARY_STORAGE)[0]
    except Exception as e:
        test_util.test_dsc(str(e))
        test_util.test_skip('Skip for not finding ceph ps')
    ps_uuid = ps.uuid
    try:
        ceph_node_ip = ps.mons[0].monAddr
    except Exception as e:
        test_util.test_dsc(str(e))
        test_util.test_fail('Fail to get mon ip')
    create_pool_cmd = 'ceph osd pool create for_test_pool_create 4'
    try:
        (ret, out, eout) = ssh.execute(create_pool_cmd, ceph_node_ip, 'root', 'password')
    except Exception as e:
        test_util.test_dsc(str(e))
        test_util.test_fail('Fail to create pool by using ceph command')
    aliasName = 'test_aliasName_new'
    poolName = 'test_poolName'
    description = 'test_description'
    isCreate = 'true'
    test_util.test_dsc('add new pool by zstack')
    ps_ops.add_ceph_primary_storage_pool(ps_uuid, poolName, aliasName, isCreate, poolType="Data")
    cond = res_ops.gen_query_conditions('aliasName', '=', aliasName)
    pool = res_ops.query_resource(res_ops.CEPH_PRIMARY_STORAGE_POOL, cond)[0]
    print pool
    test_util.test_dsc("poolName: " + str(pool.poolName))
    if pool.poolName != poolName:
        test_util.test_fail('Find wrong pool should find: ' + str(poolName) + 'But find: ' + str(pool.poolName))
    test_util.test_dsc('add exist pool by zstack')
    aliasName = 'test_aliasName_exist'
    ps_ops.add_ceph_primary_storage_pool(ps_uuid, 'for_test_pool_create', aliasName, poolType="Data")
    cond = res_ops.gen_query_conditions('aliasName', '=', aliasName)
    pool = res_ops.query_resource(res_ops.CEPH_PRIMARY_STORAGE_POOL, cond)[0]
    test_util.test_dsc("poolName: " + str(pool.poolName))
    if pool.poolName != 'for_test_pool_create':
        test_util.test_fail('Find wrong pool should find: for_test_pool_create But find: ' + str(pool.poolName))
Example #51
0
def auto_set_mn_ip(scenario_file):
    host_ip_lst = sce_ops.dump_scenario_file_ips(scenario_file)
    host_ip = host_ip_lst[0]
    for i in range(60):
        time.sleep(10)
        #cmd = "zsha2 status |grep -B 2 'Owns virtual address: *yes'|grep 'Status report from'|awk -F' ' '{print $4}'"
        cmd = "zsha2 status|grep VIP|head -n 1|awk -F' ' '{print $2}'"
        test_util.test_logger("@@@DEBUG->cmd=<%s>;host_ip=<%s>" %(cmd, host_ip))
        ret, mn_vip, stderr = ssh.execute(cmd, host_ip, "root", "password", False, 22)
        if re.match(r"^(?:[0-9]{1,3}\.){3}[0-9]{1,3}$", mn_vip):
            test_util.test_logger("find mn_host_ip=%s" %(mn_vip))
            break
    else:
        test_util.test_fail("not find valid mn_host_ip within 300s")

    mn_ip = mn_vip.strip()
    os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mn_ip
    os.environ['zstackHaVip'] = mn_ip
    test_util.test_logger("@@@DEBUG->in auto_set_mn_ip@@@ os\.environ\[\'ZSTACK_BUILT_IN_HTTP_SERVER_IP\'\]=%s; os\.environ\[\'zstackHaVip\'\]=%s"      \
                          %(os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'], os.environ['zstackHaVip']) )
    cmd = 'sed -i "s/zstackHaVip = .*$/zstackHaVip = %s/g" /root/.zstackwoodpecker/integrationtest/vm/mn_ha/deploy.tmpt' %(mn_ip)
    test_util.test_logger("@@@DEBUG->replace zstackHaVip @@@: %s" %cmd)
    os.system(cmd)
def test():
    global test_obj_dict
    cond_l3 = res_ops.gen_query_conditions('name', '=', os.environ.get('l3PublicNetworkName'))
    l3_uuid = res_ops.query_resource(res_ops.L3_NETWORK, cond_l3)[0].uuid
    ip_range_uuid = res_ops.query_resource(res_ops.L3_NETWORK, cond_l3)[0].ipRanges[0].uuid
    vm = test_stub.create_vm()

    #Get dhcp ip
    dhcp_ip = net_ops.get_l3network_dhcp_ip(l3NetworkUuid=l3_uuid)
    sys_tag = ["staticIp::%s::%s" % (l3_uuid, dhcp_ip)]
    vm.destroy()
    vm.expunge()
    time.sleep(10)
    ip_range=test_lib.lib_get_ip_range_by_l3_uuid(l3NetworkUuid=l3_uuid)
    net_ops.delete_ip_range(ip_range_uuid)
    time.sleep(2)
    ip_range_option = test_util.IpRangeOption()
    ip_range_option.set_l3_uuid(l3_uuid=l3_uuid)
    ip_range_option.set_startIp(startIp=ip_range.startIp)
    ip_range_option.set_endIp(endIp=ip_range.endIp)
    ip_range_option.set_gateway(gateway=ip_range.gateway)
    ip_range_option.set_netmask(netmask=ip_range.netmask)
    ip_range_option.set_name(name=ip_range.name)
    net_ops.add_ip_range(ip_range_option=ip_range_option)
    time.sleep(2)
    vm = test_stub.create_vm(vm_name='vm-dhcp-ip', system_tags=sys_tag)
    test_obj_dict.add_vm(vm)
    time.sleep(60)
    vm_ip = vm.vm.vmNics[0].ip

    cmd = "ping -c 5 %s" % (vm_ip)
    (retcode, output, erroutput) = ssh.execute(cmd, ext_host_ip, "root", ext_host_pwd, True, 22)
    print "retcode is: %s; output is : %s.; erroutput is: %s" % (retcode, output, erroutput)
    vm.destroy()
    vm.expunge()
    if retcode != 0:
        test_util.test_fail('Cannot ping public IP, test Failed.')
Example #53
0
def restart_mn_node_with_long_timeout():

    mn_ip = os.environ['zstackHaVip']

    test_lib.lib_wait_target_up(mn_ip, '22', 120)

    cmd = "zstack-ctl status|grep 'MN status'|awk '{print $3}'"
    ret, stdout, stderr = ssh.execute(cmd, mn_ip, "root", "password", False, 22)

    if stdout.strip().strip('\n').lower() != "running":

        check_mn_tool_path = "%s/%s" %(os.environ.get('woodpecker_root_path'), '/tools/check_mn_start.sh')
        test_util.test_logger("check_mn_tool_path:[%s],mn_ip:[%s]" %(check_mn_tool_path, mn_ip))
        ssh.scp_file(check_mn_tool_path, "/home/check_mn_start.sh", mn_ip, "root", "password")

        cmd = "bash /home/check_mn_start.sh"
        ret1, stdout1, stderr1 = ssh.execute(cmd, mn_ip, "root", "password", False, 22)
        test_util.test_logger("check_mn_start.sh stdout1:[%s],stderr1:[%s]" %(stdout1,stderr1))

        if str(ret1) == "0" :
            cmd = "zstack-ctl stop"
            ret, stdout, stderr = ssh.execute(cmd, mn_ip, "root", "password", True, 22)
            cmd = "zstack-ctl configure ThreadFacade.maxThreadNum=200"
            ret, stdout, stderr = ssh.execute(cmd, mn_ip, "root", "password", True, 22)
            cmd = "zstack-ctl start_node --timeout 3000"
            ret, stdout, stderr = ssh.execute(cmd, mn_ip, "root", "password", True, 22)
            cmd = "zstack-ctl start_ui"
            ret, stdout, stderr = ssh.execute(cmd, mn_ip, "root", "password", True, 22)

            #modify zstack start script
            cmd = r'sed -i "s:zstack-ctl start:zstack-ctl start_node --timeout 3000:g" /etc/init.d/zstack-server'
            test_lib.lib_execute_ssh_cmd(mn_ip, "root", "password", cmd)
            time.sleep(1)
            cmd = r'sed -i "/zstack-ctl start_node --timeout 3000/ a\    ZSTACK_HOME=\$zstack_app zstack-ctl start_ui" /etc/init.d/zstack-server'
            test_lib.lib_execute_ssh_cmd(mn_ip, "root", "password", cmd)

        else:
            test_util.test_logger("find mn not self-started as expected, checked by /home/check_mn_start.sh")

    else:
        test_util.test_logger("find zstack MN is running.")
 def _rshell(self, cmd):
     ssh.execute(cmd, self.node_ip, self.node_username, self.NODE_PASSWORD)
 def _install_zstack_ha(self):
     node1 = self.nodes[0]
     node2 = self.nodes[1]
     cmd = "zstack-ctl install_ha --host1-info %s:%s@%s --host2-info %s:%s@%s --vip %s" % \
             (node1.username_, node1.password_, node1.ip_, node2.username_, node2.password_, node2.ip_, self.zstack_ha_vip)
     ssh.execute(cmd, node1.ip_, node1.username_, node1.password_)
def exec_cmd_in_vm(vm, cmd, fail_msg):
    ret, output, stderr = ssh.execute(cmd, vm.get_vm().vmNics[0].ip, "root", "password", False, 22)
    if ret != 0:
        test_util.test_fail(fail_msg)
def force_vm_auto_boot(vm):
    cmd = "sed -i \"s/  set timeout=-1/  set timeout=3/g\" /boot/grub/grub.cfg; sync"
    ret, output, stderr = ssh.execute(cmd, vm.get_vm().vmNics[0].ip, "root", "password", False, 22)
    if ret != 0:
        test_util.test_logger("Force vm auto boot setting failed.")
def test():
    if test_lib.scenario_config == None or test_lib.scenario_file ==None:
        test_util.test_fail('Suite Setup Fail without scenario')

    if test_lib.scenario_config != None and test_lib.scenario_file != None and not os.path.exists(test_lib.scenario_file):
        scenario_operations.deploy_scenario(test_lib.all_scenario_config, test_lib.scenario_file, test_lib.deploy_config)
        test_util.test_skip('Suite Setup Success')
    if test_lib.scenario_config != None and test_lib.scenario_destroy != None:
        scenario_operations.destroy_scenario(test_lib.all_scenario_config, test_lib.scenario_destroy)

    nic_name = "eth0"
    if test_lib.scenario_config != None and test_lib.scenario_file != None and os.path.exists(test_lib.scenario_file):
        nic_name = "zsn0"

    #This vlan creation is not a must, if testing is under nested virt env. But it is required on physical host without enough physcial network devices and your test execution machine is not the same one as Host machine. 
    #no matter if current host is a ZStest host, we need to create 2 vlan devs for future testing connection for novlan test cases.
    linux.create_vlan_eth(nic_name, 10)
    linux.create_vlan_eth(nic_name, 11)

    #If test execution machine is not the same one as Host machine, deploy work is needed to separated to 2 steps(deploy_test_agent, execute_plan_without_deploy_test_agent). And it can not directly call SetupAction.run()
    test_lib.setup_plan.deploy_test_agent()
    cmd = host_plugin.CreateVlanDeviceCmd()
    cmd.ethname = nic_name
    cmd.vlan = 10
    
    cmd2 = host_plugin.CreateVlanDeviceCmd()
    cmd2.ethname = nic_name
    cmd2.vlan = 11
    testHosts = test_lib.lib_get_all_hosts_from_plan()
    if type(testHosts) != type([]):
        testHosts = [testHosts]
    for host in testHosts:
        http.json_dump_post(testagent.build_http_path(host.managementIp_, host_plugin.CREATE_VLAN_DEVICE_PATH), cmd)
        http.json_dump_post(testagent.build_http_path(host.managementIp_, host_plugin.CREATE_VLAN_DEVICE_PATH), cmd2)


    test_stub.deploy_2ha(test_lib.all_scenario_config, test_lib.scenario_file, test_lib.deploy_config)
    mn_ip1 = test_stub.get_host_by_index_in_scenario_file(test_lib.all_scenario_config, test_lib.scenario_file, 0).ip_
    mn_ip2 = test_stub.get_host_by_index_in_scenario_file(test_lib.all_scenario_config, test_lib.scenario_file, 1).ip_

    if not xmlobject.has_element(test_lib.deploy_config, 'backupStorages.miniBackupStorage'):
        host_ip1 = test_stub.get_host_by_index_in_scenario_file(test_lib.all_scenario_config, test_lib.scenario_file, 2).ip_
        test_stub.recover_vlan_in_host(host_ip1, test_lib.all_scenario_config, test_lib.deploy_config)

    test_stub.wrapper_of_wait_for_management_server_start(600, EXTRA_SUITE_SETUP_SCRIPT)
    test_util.test_logger("@@@DEBUG->suite_setup@@@ os\.environ\[\'ZSTACK_BUILT_IN_HTTP_SERVER_IP\'\]=%s; os\.environ\[\'zstackHaVip\'\]=%s"	\
                          %(os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'], os.environ['zstackHaVip']) )
    ssh.scp_file("/home/license-10host-10days-hp.txt", "/home/license-10host-10days-hp.txt", mn_ip1, 'root', 'password')
    ssh.scp_file("/home/license-10host-10days-hp.txt", "/home/license-10host-10days-hp.txt", mn_ip2, 'root', 'password')
    if os.path.exists(EXTRA_SUITE_SETUP_SCRIPT):
        os.system("bash %s %s" % (EXTRA_SUITE_SETUP_SCRIPT, mn_ip1))
        os.system("bash %s %s" % (EXTRA_SUITE_SETUP_SCRIPT, mn_ip2))

    deploy_operations.deploy_initial_database(test_lib.deploy_config, test_lib.all_scenario_config, test_lib.scenario_file)
    for host in testHosts:
        os.system("bash %s %s" % (EXTRA_HOST_SETUP_SCRIPT, host.managementIp_))

    test_lib.lib_set_primary_storage_imagecache_gc_interval(1)
    #test_lib.lib_set_reserved_memory('1G')

    if test_lib.lib_cur_cfg_is_a_and_b(["test-config-vyos-local-ps.xml"], ["scenario-config-upgrade-3.1.1.xml"]):
        cmd = r"sed -i '$a\172.20.198.8 rsync.repo.zstack.io' /etc/hosts"
        ssh.execute(cmd, mn_ip1, "root", "password", False, 22)
        ssh.execute(cmd, mn_ip2, "root", "password", False, 22)

    test_util.test_pass('Suite Setup Success')
def check_qemu_ga_is_alive(vm):
    global cur_usr, cur_passwd
    cmd = "ps -aux|grep ga|grep qemu"
    ret, output, stderr = ssh.execute(cmd, vm.get_vm().vmNics[0].ip, cur_usr, cur_passwd, False, 22)
    if ret != 0:
        test_util.test_logger("qemu-ga is not alived when exception triggered: ip:%s; cmd:%s; user:%s; password:%s; stdout:%s, stderr:%s" %(vm.get_vm().vmNics[0].ip, cmd, cur_usr, cur_passwd, output, stderr))