def test():

    global bs_username, bs_hostname, bs_password, bs_name, bs_username, bs_url, bs_sshport
    global new_image    

    file_path = test_stub.gen_license('woodpecker', '*****@*****.**', '1', 'Prepaid', '1', '')
    test_stub.load_license(file_path)
    issued_date = test_stub.get_license_info().issuedDate
    expired_date = test_stub.license_date_cal(issued_date, 86400 * 1)
    test_stub.check_license("*****@*****.**", 1, None, False, 'Paid', issued_date=issued_date, expired_date=expired_date)

    test_util.test_logger('create zone and add the bs of the imagestore')
    node_uuid = res_ops.query_resource(res_ops.MANAGEMENT_NODE)[0].uuid
    test_stub.create_zone()
    zone_uuid = res_ops.query_resource(res_ops.ZONE)[0].uuid

    bs_name = 'BS1'
    bs_hostname = os.environ.get('node1Ip')
    bs_username = os.environ.get('nodeUserName')
    bs_password = os.environ.get('nodePassword')
    bs_url = '/zstack_bs'
    bs_sshport = '22'
    test_stub.create_image_store_backup_storage(bs_name, bs_hostname, bs_username, bs_password, bs_url, bs_sshport)
    bs_uuid = res_ops.query_resource(res_ops.BACKUP_STORAGE)[0].uuid

    test_stub.reload_default_license()
    test_util.test_logger('Check default community license')
    #test_stub.check_license(None, None, 2147483647, False, 'Community')

    try:
        bs_ops.reconnect_backup_storage(bs_uuid)
    except Exception, e:
        if "commercial" in str(e):
            test_util.test_pass('test reconnect bs failed, An operation failed, details: commercial license is required to use ImageStore.')
def error_cleanup():
    global email_endpoint_uuid,email_platform_uuid,my_sns_topic_uuid,host_sns_topic_uuid,ps_uuid,hostname,host_management_ip,host_status,bs_type,bs_status,event_list
    if host_status == 'Disconnected':
        host_ops.update_host(host_uuid, 'managementIp', host_management_ip)
        host_ops.reconnect_host(host_uuid)
    if bs_status == 'Disconnected':
        if bs_type == res_ops.IMAGE_STORE_BACKUP_STORAGE:
            bs_ops.update_image_store_backup_storage_info(bs_uuid, 'hostname', hostname)
            bs_ops.reconnect_backup_storage(bs_uuid)
        elif bs_type == res_ops.SFTP_BACKUP_STORAGE:
            bs_ops.update_sftp_backup_storage_info(bs_uuid, 'hostname', hostname)
            bs_ops.reconnect_backup_storage(bs_uuid)
    if ps_uuid:
        ps_ops.delete_primary_storage(ps_uuid)
    if host_sns_topic_uuid:
        zwt_ops.delete_sns_topic(host_sns_topic_uuid)
    if my_sns_topic_uuid:
        zwt_ops.delete_sns_topic(my_sns_topic_uuid)
    if event_list:
        for event_uuid in event_list:
            zwt_ops.unsubscribe_event(event_uuid)
    if email_endpoint_uuid:
        zwt_ops.delete_sns_application_endpoint(email_endpoint_uuid)
    if email_platform_uuid:
        zwt_ops.delete_sns_application_platform(email_platform_uuid)
def error_cleanup():
    global email_endpoint_uuid, email_platform_uuid, my_sns_topic_uuid, host_sns_topic_uuid, ps_uuid, hostname, host_management_ip, host_status, bs_type, bs_status, event_list
    if host_status == 'Disconnected':
        host_ops.update_host(host_uuid, 'managementIp', host_management_ip)
        host_ops.reconnect_host(host_uuid)
    if bs_status == 'Disconnected':
        if bs_type == res_ops.IMAGE_STORE_BACKUP_STORAGE:
            bs_ops.update_image_store_backup_storage_info(
                bs_uuid, 'hostname', hostname)
            bs_ops.reconnect_backup_storage(bs_uuid)
        elif bs_type == res_ops.SFTP_BACKUP_STORAGE:
            bs_ops.update_sftp_backup_storage_info(bs_uuid, 'hostname',
                                                   hostname)
            bs_ops.reconnect_backup_storage(bs_uuid)
    if ps_uuid:
        ps_ops.delete_primary_storage(ps_uuid)
    if host_sns_topic_uuid:
        zwt_ops.delete_sns_topic(host_sns_topic_uuid)
    if my_sns_topic_uuid:
        zwt_ops.delete_sns_topic(my_sns_topic_uuid)
    if event_list:
        for event_uuid in event_list:
            zwt_ops.unsubscribe_event(event_uuid)
    if email_endpoint_uuid:
        zwt_ops.delete_sns_application_endpoint(email_endpoint_uuid)
    if email_platform_uuid:
        zwt_ops.delete_sns_application_platform(email_platform_uuid)
def error_cleanup():
	global vm,bss,host,ENABLE,infoType
	if vm:
		vm.clean()
	bs_ops.change_backup_storage_state(bss[0].uuid, ENABLE)
	bs_ops.update_image_store_backup_storage_info(bss[0].uuid, infoType, host)
	bs_ops.reconnect_backup_storage(bss[0].uuid)
Пример #5
0
def error_cleanup():
    global vm, bss, host, ENABLE, infoType
    if vm:
        vm.clean()
    bs_ops.change_backup_storage_state(bss[0].uuid, ENABLE)
    bs_ops.update_image_store_backup_storage_info(bss[0].uuid, infoType, host)
    bs_ops.reconnect_backup_storage(bss[0].uuid)
def test():
    global vm_inv,host_name, host_uuid, host_management_ip, vm_ip, bs_name, bs_uuid
    test_util.test_dsc('Create test vm to test zstack upgrade by -u.')

    image_name = os.environ.get('imageTestAlarm_230_mn')
    iso_path = os.environ.get('iso_path')
    zstack_latest_version = os.environ.get('zstackLatestVersion')
    zstack_latest_path = os.environ.get('zstackLatestInstaller')
    vm_name = os.environ.get('vmName') + image_name
    upgrade_script_path = os.environ.get('upgradeScript')

    vm_inv = test_stub.create_vm_scenario(image_name, vm_name)
    vm_ip = vm_inv.vmNics[0].ip
    test_lib.lib_wait_target_up(vm_ip, 22)
    #vm_ip = '172.20.197.159'
    os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = vm_ip
    test_stub.make_ssh_no_password(vm_ip, tmp_file)

    test_util.test_logger('Update MN IP')
    test_stub.update_mn_hostname(vm_ip, tmp_file)
    test_stub.update_mn_ip(vm_ip, tmp_file)
    test_stub.start_mn(vm_ip, tmp_file)


    test_util.test_logger('Update host management IP and reconnect host')
    host_name = 'Host-1'
    cond1 = res_ops.gen_query_conditions('name', '=', host_name)
    test2 = res_ops.query_resource(res_ops.HOST, cond1)
    test_util.test_logger('aaaaa %s' % test2)
    #host_uuid = res_ops.query_resource(res_ops.HOST, conditions)[0].inventories[0]
    management_ip = vm_ip
    host_uuid = scen_ops.query_resource(management_ip, res_ops.HOST, cond1).inventories[0].uuid
    print 'test = ' 
    print  host_uuid
    host_management_ip = vm_ip
    host_ops.update_host(host_uuid, 'managementIp', host_management_ip)
    host_ops.reconnect_host(host_uuid)

    test_util.test_logger('Update bs IP and reconnect bs')
    bs_name = 'BS-1'
    cond2 = res_ops.gen_query_conditions('name', '=', bs_name)
    #bs_uuid = res_ops.query_resource(res_ops.BACKUP_STORAGE, conditions)[0].inventories[0].uuid    
    bs_uuid = scen_ops.query_resource(management_ip, res_ops.BACKUP_STORAGE, cond2).inventories[0].uuid
    bs_ip = vm_ip
    bs_ops.update_image_store_backup_storage_info(bs_uuid, 'hostname', bs_ip)
    bs_ops.reconnect_backup_storage(bs_uuid)

    #test_stub.check_installation(vm_ip, tmp_file)

    test_util.test_logger('Upgrade zstack to latest') 
    test_stub.update_iso(vm_ip, tmp_file, iso_path, upgrade_script_path)
    test_stub.upgrade_zstack(vm_ip, zstack_latest_path, tmp_file) 
    test_stub.check_zstack_version(vm_ip, tmp_file, zstack_latest_version)
    test_stub.start_mn(vm_ip, tmp_file)
    test_stub.check_installation(vm_ip, tmp_file)

    os.system('rm -f %s' % tmp_file)
    test_stub.destroy_vm_scenario(vm_inv.uuid)
    test_util.test_pass('ZStack upgrade Test Success')
Пример #7
0
def check_resource():

    hosts = res_ops.query_resource(res_ops.HOST, [], None)
    for host in hosts:
        if host.status != "Connected":
            host_ops.reconnect_host(host.uuid)
            return False

    pss = res_ops.query_resource(res_ops.PRIMARY_STORAGE, [], None)
    for ps in pss:
        if ps.status != "Connected":
            ps_ops.reconnect_primary_storage(ps.uuid)
            return False

    bss = res_ops.query_resource(res_ops.BACKUP_STORAGE, [], None)
    for bs in bss:
        if bs.status != "Connected":
            bs_ops.reconnect_backup_storage(bs.uuid)
            return False

    if os.environ.get('WOODPECKER_PARALLEL') != None and os.environ.get(
            'WOODPECKER_PARALLEL') == '0':
        vms = res_ops.query_resource(res_ops.VM_INSTANCE, [], None)
        for vm in vms:
            if vm.type == 'UserVm':
                try:
                    vm_ops.destroy_vm(vm.uuid)
                except:
                    test_util.test_logger('ignore exception try to destroy vm')
                try:
                    vm_ops.expunge_vm(vm.uuid)
                except:
                    test_util.test_logger('ignore exception try to expunge vm')

    vrs = res_ops.query_resource(res_ops.APPLIANCE_VM, [], None)
    for vr in vrs:
        if vr.status != "Connected" or vr.state != "Running":
            if vr.applianceVmType != "vrouter":
                try:
                    vm_ops.stop_vm(vr.uuid, force='cold')
                    vm_ops.start_vm(vr.uuid)
                except:
                    test_util.test_logger('Exception when reboot vr vm')
            else:
                try:
                    vm_ops.stop_vm(vr.uuid, force='cold')
                except:
                    test_util.test_logger('Exception when reboot vr vm')
            return False

    return True
Пример #8
0
def check_resource():

    hosts = res_ops.query_resource(res_ops.HOST, [], None)
    for host in hosts:
        if host.status != "Connected":
            host_ops.reconnect_host(host.uuid) 
            return False

    pss = res_ops.query_resource(res_ops.PRIMARY_STORAGE, [], None)
    for ps in pss:
        if ps.status != "Connected":
            ps_ops.reconnect_primary_storage(ps.uuid)
            return False

    bss = res_ops.query_resource(res_ops.BACKUP_STORAGE, [], None)
    for bs in bss:
        if bs.status != "Connected":
            bs_ops.reconnect_backup_storage(bs.uuid)
            return False

    if os.environ.get('WOODPECKER_PARALLEL') != None and os.environ.get('WOODPECKER_PARALLEL') == '0':
        vms = res_ops.query_resource(res_ops.VM_INSTANCE, [], None)
        for vm in vms:
            if vm.type == 'UserVm':
                try:
                    vm_ops.destroy_vm(vm.uuid)
                except:
                    test_util.test_logger('ignore exception try to destroy vm')
                try:
                    vm_ops.expunge_vm(vm.uuid)
                except:
                    test_util.test_logger('ignore exception try to expunge vm')

    vrs = res_ops.query_resource(res_ops.APPLIANCE_VM, [], None)
    for vr in vrs:
        if vr.status != "Connected" or vr.state != "Running":
            if vr.applianceVmType != "vrouter":
		try:
                    vm_ops.stop_vm(vr.uuid, force='cold')
                    vm_ops.start_vm(vr.uuid)
                except:
                    test_util.test_logger('Exception when reboot vr vm')
            else:
                try:
                    vm_ops.stop_vm(vr.uuid, force='cold')
                except:
                    test_util.test_logger('Exception when reboot vr vm')
            return False

    return True
Пример #9
0
def ensure_bss_connected():
    for i in range(300):
        #time.sleep(1)
        bs_list = res_ops.query_resource(res_ops.BACKUP_STORAGE)
        for bs in bs_list:
            bs_ops.reconnect_backup_storage(bs.uuid)
            cond = res_ops.gen_query_conditions('uuid', '=', bs.uuid)
            bss = res_ops.query_resource_fields(res_ops.BACKUP_STORAGE, cond, None)
            if not "connected" in bss[0].status.lower():
                test_util.test_logger("times: %s found not connected ps status: %s" %(str(i), bss[0].status))
                break
        else:
            return
    else:
        test_util.test_fail("bs status didn't change to Connected within 300s, therefore, failed")
Пример #10
0
def ensure_bss_connected():
    for i in range(300):
        #time.sleep(1)
        bs_list = res_ops.query_resource(res_ops.BACKUP_STORAGE)
        for bs in bs_list:
            bs_ops.reconnect_backup_storage(bs.uuid)
            cond = res_ops.gen_query_conditions('uuid', '=', bs.uuid)
            bss = res_ops.query_resource_fields(res_ops.BACKUP_STORAGE, cond, None)
            if not "connected" in bss[0].status.lower():
                test_util.test_logger("times: %s found not connected ps status: %s" %(str(i), bss[0].status))
                break
        else:
            return
    else:
        test_util.test_fail("bs status didn't change to Connected within 300s, therefore, failed")
def test():
    global email_endpoint_uuid, email_platform_uuid, my_sns_topic_uuid, host_sns_topic_uuid, ps_uuid, hostname, host_management_ip, host_uuid, host_status, bs_uuid, bs_type, bs_status
    bs_cond = res_ops.gen_query_conditions('status', '=', 'Connected')
    bs_list = res_ops.query_resource(res_ops.BACKUP_STORAGE, bs_cond)
    for bss in bs_list:
        if bss.type == res_ops.SFTP_BACKUP_STORAGE:
            bs_uuid = bss.uuid
            bs_type = bss.type
            hostname = bss.hostname
            break
        elif bss.type == res_ops.IMAGE_STORE_BACKUP_STORAGE:
            bs_uuid = bss.uuid
            bs_type = bss.type
            hostname = bss.hostname
            break
        else:
            test_util.test_skip('No match backupStorage,test skip')

    smtp_server = os.environ.get('smtpServer')
    pop_server = os.environ.get('popServer')
    smtp_port = os.environ.get('smtpPort')
    username = os.environ.get('mailUsername')
    password = os.environ.get('mailPassword')
    email_platform_name = 'Alarm_email'
    email_platform = zwt_ops.create_sns_email_platform(smtp_server, smtp_port,
                                                       email_platform_name,
                                                       username, password)
    email_platform_uuid = email_platform.uuid
    try:
        zwt_ops.validate_sns_email_platform(email_platform_uuid)
    except:
        test_util.test_fail(
            'Validate SNS Email Platform Failed, Email Plarform: %s' %
            email_platform_uuid)
    email_endpoint_uuid = zwt_ops.create_sns_email_endpoint(
        username, 'test_qa', email_platform_uuid).uuid

    my_sns_topic = zwt_ops.create_sns_topic('my_sns_topic')
    my_sns_topic_uuid = my_sns_topic.uuid
    zwt_ops.subscribe_sns_topic(my_sns_topic_uuid, email_endpoint_uuid)

    host_sns_topic = zwt_ops.create_sns_topic('host_topic')
    host_sns_topic_uuid = host_sns_topic.uuid
    zwt_ops.subscribe_sns_topic(host_sns_topic_uuid, email_endpoint_uuid)

    ps_actions = [{"actionUuid": my_sns_topic_uuid, "actionType": "sns"}]
    ps_namespace = 'ZStack/PrimaryStorage'
    ps_disconnected = 'PrimaryStorageDisconnected'
    ps_event_sub_uuid = zwt_ops.subscribe_event(ps_namespace, ps_disconnected,
                                                ps_actions).uuid
    event_list.append(ps_event_sub_uuid)

    bs_actions = [{"actionUuid": my_sns_topic_uuid, "actionType": "sns"}]
    bs_namespace = 'ZStack/BackupStorage'
    bs_disconnected = 'BackupStorageDisconnected'
    bs_event_sub_uuid = zwt_ops.subscribe_event(bs_namespace, bs_disconnected,
                                                bs_actions).uuid
    event_list.append(bs_event_sub_uuid)

    host_actions = [{"actionUuid": host_sns_topic_uuid, "actionType": "sns"}]
    host_namespace = 'ZStack/Host'
    host_status_changed = 'HostStatusChanged'
    host_status_labels = [{
        "key": "NewStatus",
        "op": "Equal",
        "value": "Disconnected"
    }]
    host_status_event_sub_uuid = zwt_ops.subscribe_event(
        host_namespace, host_status_changed, host_actions,
        host_status_labels).uuid
    event_list.append(host_status_event_sub_uuid)

    host_disconnected = 'HostDisconnected'
    host_disconnected_event_sub_uuid = zwt_ops.subscribe_event(
        host_namespace, host_disconnected, host_actions).uuid
    event_list.append(host_disconnected_event_sub_uuid)

    if zwt_ops.check_sns_email(pop_server, username, password, ps_disconnected,
                               ps_event_sub_uuid):
        test_util.test_fail('email already exsist before test')
    if zwt_ops.check_sns_email(pop_server, username, password, bs_disconnected,
                               bs_event_sub_uuid):
        test_util.test_fail('email already exsist before test')
    if zwt_ops.check_sns_email(pop_server, username, password,
                               host_status_changed,
                               host_status_event_sub_uuid):
        test_util.test_fail('email already exsist before test')
    if zwt_ops.check_sns_email(pop_server, username, password,
                               host_disconnected,
                               host_disconnected_event_sub_uuid):
        test_util.test_fail('email already exsist before test')

    # Disconnected ps ,bs and host
    zone_uuid = res_ops.query_resource(res_ops.ZONE)[0].uuid
    primary_storage_option = test_util.PrimaryStorageOption()
    primary_storage_option.set_type('nfs')
    primary_storage_option.set_zone_uuid(zone_uuid)
    primary_storage_option.set_name('test_nfs_ps')
    primary_storage_option.set_url('222.222.222.222/nfs/')
    try:
        ps_uuid = ps_ops.create_nfs_primary_storage(
            primary_storage_option).uuid
        ps_ops.reconnect_primary_storage(ps_uuid)
    except:
        pass

    if bs_type == res_ops.IMAGE_STORE_BACKUP_STORAGE:
        bs_ops.update_image_store_backup_storage_info(bs_uuid, 'hostname',
                                                      '222.222.222.222')
        try:
            bs_ops.reconnect_backup_storage(bs_uuid)
        except:
            cond = res_ops.gen_query_conditions('uuid', '=', bs_uuid)
            bs_status = res_ops.query_resource(
                res_ops.IMAGE_STORE_BACKUP_STORAGE, cond)[0].status
    elif bs_type == res_ops.SFTP_BACKUP_STORAGE:
        bs_ops.update_sftp_backup_storage_info(bs_uuid, 'hostname',
                                               '222.222.222.222')
        try:
            bs_ops.reconnect_backup_storage(bs_uuid)
        except:
            cond = res_ops.gen_query_conditions('uuid', '=', bs_uuid)
            bs_status = res_ops.query_resource(res_ops.SFTP_BACKUP_STORAGE,
                                               cond)[0].status

    host_cond = res_ops.gen_query_conditions('status', '=', 'Connected')
    host = res_ops.query_resource_with_num(res_ops.HOST,
                                           host_cond,
                                           start=0,
                                           limit=1)[0]
    host_uuid = host.uuid
    host_management_ip = host.managementIp
    host_ops.update_host(host_uuid, 'managementIp', '222.222.222.222')
    try:
        host_ops.reconnect_host(host_uuid)
    except:
        cond = res_ops.gen_query_conditions('uuid', '=', host_uuid)
        bs_status = res_ops.query_resource(res_ops.HOST, cond)[0].status

    # wait for send email
    time.sleep(60)

    ps_ops.delete_primary_storage(ps_uuid)
    if hostname:
        if bs_type == res_ops.IMAGE_STORE_BACKUP_STORAGE:
            bs_ops.update_image_store_backup_storage_info(
                bs_uuid, 'hostname', hostname)
            bs_ops.reconnect_backup_storage(bs_uuid)
        elif bs_type == res_ops.SFTP_BACKUP_STORAGE:
            bs_ops.update_sftp_backup_storage_info(bs_uuid, 'hostname',
                                                   hostname)
            bs_ops.reconnect_backup_storage(bs_uuid)
    host_ops.update_host(host_uuid, 'managementIp', host_management_ip)
    host_ops.reconnect_host(host_uuid)
    zwt_ops.delete_sns_topic(host_sns_topic_uuid)
    zwt_ops.delete_sns_topic(my_sns_topic_uuid)
    for event_uuid in event_list:
        zwt_ops.unsubscribe_event(event_uuid)
    zwt_ops.delete_sns_application_endpoint(email_endpoint_uuid)
    zwt_ops.delete_sns_application_platform(email_platform_uuid)

    check_1 = zwt_ops.check_sns_email(pop_server, username, password,
                                      ps_disconnected, ps_event_sub_uuid)
    check_2 = zwt_ops.check_sns_email(pop_server, username, password,
                                      bs_disconnected, bs_event_sub_uuid)
    check_3 = zwt_ops.check_sns_email(pop_server, username, password,
                                      host_status_changed,
                                      host_status_event_sub_uuid)
    check_4 = zwt_ops.check_sns_email(pop_server, username, password,
                                      host_disconnected,
                                      host_disconnected_event_sub_uuid)

    if check_1 and check_2 and check_3 and check_4:
        test_util.test_pass(
            'test host ,bs, ps disconnected event with email success!')
    else:
        test_util.test_fail('cannt receive all event mail')
def test():
    global bs
    flavor = case_flavor[os.environ.get('CASE_FLAVOR')]

    cond = res_ops.gen_query_conditions('state', '=', 'Enabled')
    cond = res_ops.gen_query_conditions('status', '=', 'Connected', cond)
    if flavor['sftp']:
        cond = res_ops.gen_query_conditions('type', '=', 'SftpBackupStorage',
                                            cond)
    elif flavor['imagestore']:
        cond = res_ops.gen_query_conditions('type', '=',
                                            'ImageStoreBackupStorage', cond)
    elif flavor['ceph']:
        cond = res_ops.gen_query_conditions('type', '=', 'Ceph', cond)

    bs = res_ops.query_resource_with_num(res_ops.BACKUP_STORAGE, cond, limit=1)
    if not bs:
        test_util.test_skip('No Enabled/Connected bs was found, skip test.')

    bs_ops.reconnect_backup_storage(bs[0].uuid)
    saved_bs = res_ops.query_resource_with_num(res_ops.BACKUP_STORAGE,
                                               cond,
                                               limit=1)
    if flavor['ceph']:
        bs[0].managementIp = bs[0].mons[0].hostname
    else:
        bs[0].managementIp = bs[0].hostname
    if flavor['ceph']:
        test_stub.setup_fake_ceph(bs[0], 631242663936, 428968118272)
        fake_total = 631242663936
        fake_available = 428968118272
    else:
        test_stub.setup_fake_fs(bs[0], '2G', saved_bs[0].url)
        fake_total = 2 * 1024 * 1024 * 1024
        fake_available = 2 * 1024 * 1024 * 1024

    bs_ops.reconnect_backup_storage(bs[0].uuid)

    bs = res_ops.query_resource_with_num(res_ops.BACKUP_STORAGE, cond, limit=1)
    if flavor['ceph']:
        bs[0].managementIp = bs[0].mons[0].hostname
    else:
        bs[0].managementIp = bs[0].hostname

    if bs[0].totalCapacity != fake_total:
        test_util.test_fail('totalCapacity %s not updated after reconnect bs' %
                            (bs[0].totalCapacity))
    if bs[0].availableCapacity != fake_available:
        test_util.test_fail(
            'availableCapacity %s not updated after reconnect bs' %
            (bs[0].availableCapacity))

    if flavor['ceph']:
        test_stub.remove_fake_ceph(bs[0])
    else:
        test_stub.remove_fake_fs(bs[0], saved_bs[0].url)
    bs_ops.reconnect_backup_storage(bs[0].uuid)

    bs = res_ops.query_resource_with_num(res_ops.BACKUP_STORAGE, cond, limit=1)
    if flavor['ceph']:
        bs[0].managementIp = bs[0].mons[0].hostname
    else:
        bs[0].managementIp = bs[0].hostname

    if bs[0].totalCapacity != saved_bs[0].totalCapacity:
        test_util.test_fail('totalCapacity %s not updated after reconnect bs' %
                            (bs[0].totalCapacity))
    if bs[0].availableCapacity == 0:
        test_util.test_fail(
            'availableCapacity %s not updated after reconnect bs' %
            (bs[0].availableCapacity))

    test_util.test_pass(
        'Test backup storage capacity after reconnect bs pass.')
def test():
    global vcenter_uuid1
    global vcenter_uuid2
    global mevoco1_ip
    global mevoco2_ip
    global img_uuid
    global delete_policy1
    global delete_policy2

    print os.environ
    vcenter1_name = os.environ['vcenter2_name']
    vcenter1_domain_name = os.environ['vcenter2_ip']
    vcenter1_username = os.environ['vcenter2_domain_name']
    vcenter1_password = os.environ['vcenter2_password']
    sync_image_url = os.environ['vcenter2_sync_image_url']
    image_name = os.environ['vcenter2_sync_image_name']

    mevoco1_ip = os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP']
    mevoco2_ip = os.environ['serverIp2']


    os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco1_ip
    delete_policy1 = test_lib.lib_set_delete_policy('image', 'Delay')
    zone_uuid = res_ops.get_resource(res_ops.ZONE)[0].uuid
    inv = vct_ops.add_vcenter(vcenter1_name, vcenter1_domain_name, vcenter1_username, vcenter1_password, True, zone_uuid)
    vcenter_uuid1 = inv.uuid
    if vcenter_uuid1 == None:
        test_util.test_fail("vcenter_uuid is None")


    os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco2_ip
    delete_policy2 = test_lib.lib_set_delete_policy('image', 'Delay')
    zone_uuid = res_ops.get_resource(res_ops.ZONE)[0].uuid
    inv = vct_ops.add_vcenter(vcenter1_name, vcenter1_domain_name, vcenter1_username, vcenter1_password, True, zone_uuid)
    vcenter_uuid2 = inv.uuid
    if vcenter_uuid2 == None:
        test_util.test_fail("vcenter_uuid is None")

    #bs_cond = res_ops.gen_query_conditions("name", '=', "vCenter[vm-center]")
    bs_cond = res_ops.gen_query_conditions("type", '=', "VCenter")
    bss = res_ops.query_resource_fields(res_ops.BACKUP_STORAGE, bs_cond, \
            None, fields=['uuid'])
    if not bss:
        test_util.test_skip("not find available backup storage. Skip test")

    #add sync image in mevoco2
    image_option = test_util.ImageOption()
    image_option.set_name(image_name)
    #image_option.set_mediaType('RootVolumeTemplate')
    image_option.set_format('vmtx')
    image_option.set_system_tags('vcenter::datacenter::datacenter1')
    #image_option.set_url(os.environ.get(sync_image_url))
    image_option.set_url(sync_image_url)
    image_option.set_backup_storage_uuid_list([bss[0].uuid])


    new_image = zstack_image_header.ZstackTestImage()
    new_image.set_creation_option(image_option)

    #if a error happens here, check whether the image with the same name is already
    #exist in vcenter, which is also raise exception about can't download on all backup storage
    test_util.test_logger("add image from url:%s" %(sync_image_url))
    new_image.add_root_volume_template()


    #reconnect vcenter and check newly add image in mevoco1
    test_util.test_logger("check image sync from mevoco1")
    os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco1_ip
    bs_cond = res_ops.gen_query_conditions("type", '=', "VCenter")
    bss = res_ops.query_resource_fields(res_ops.BACKUP_STORAGE, bs_cond, None, fields=['uuid'])
    bs_ops.reconnect_backup_storage(bss[0].uuid)
    image_cond = res_ops.gen_query_conditions("name", '=', image_name)
    img_inv = res_ops.query_resource_fields(res_ops.IMAGE, image_cond, None, fields=['uuid'])[0]
    img_uuid = img_inv.uuid
    if not img_uuid:
        test_util.test_fail("local woodpecker image uuid is null")


    #delete image in mevoco2
    test_util.test_logger("delete image from mevoco2")
    os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco2_ip
    image_cond = res_ops.gen_query_conditions("name", '=', image_name)
    img_inv = res_ops.query_resource_fields(res_ops.IMAGE, image_cond, None, fields=['uuid'])[0]
    img_uuid = img_inv.uuid
    img_ops.delete_image(img_uuid)
    img_ops.expunge_image(img_uuid)

    #check image in mevoco1
    test_util.test_logger("check image delete sync from mevoco1")
    os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco1_ip
    bs_cond = res_ops.gen_query_conditions("type", '=', "VCenter")
    bss = res_ops.query_resource_fields(res_ops.BACKUP_STORAGE, bs_cond, None, fields=['uuid'])
    bs_ops.reconnect_backup_storage(bss[0].uuid)
    image_cond = res_ops.gen_query_conditions("name", '=', image_name)
    #img_inv = res_ops.query_resource_fields(res_ops.IMAGE, image_cond, None, fields=['uuid'])[0]
    #img_uuid = img_inv.uuid
    img_inv = res_ops.query_resource_fields(res_ops.IMAGE, image_cond, None, fields=['uuid'])
    if img_inv:
        test_util.test_fail("local woodpecker image is not deleted as expected")


    os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco2_ip
    test_lib.lib_set_delete_policy('image', delete_policy2)
    if vcenter_uuid2:
        vct_ops.delete_vcenter(vcenter_uuid2)

    os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco1_ip
    test_lib.lib_set_delete_policy('image', delete_policy1)
    if vcenter_uuid1:
        vct_ops.delete_vcenter(vcenter_uuid1)

    test_util.test_pass("vcenter sync image test passed.")
Пример #14
0
def test():
    global vm_inv, host_name, host_uuid, host_management_ip, vm_ip, bs_name, bs_uuid, management_ip
    test_util.test_dsc('Create test vm to test zstack upgrade by -u.')

    image_name = os.environ.get('imageTestAlarm_230_mn')
    iso_path = os.environ.get('iso_path')
    #iso_21_path = os.environ.get('iso_21_path')
    zstack_latest_version = os.environ.get('zstackLatestVersion')
    zstack_latest_path = os.environ.get('zstackLatestInstaller')
    vm_name = os.environ.get('vmName')
    upgrade_script_path = os.environ.get('upgradeScript')

    vm_inv = test_stub.create_vm_scenario(image_name, vm_name)
    vm_ip = vm_inv.vmNics[0].ip
    test_lib.lib_wait_target_up(vm_ip, 22)

    test_util.test_dsc('vm_ip change to environ management_node_ip')
    os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = vm_ip

    test_stub.make_ssh_no_password(vm_ip, tmp_file)

    test_util.test_logger('Update MN IP')
    test_stub.update_mn_hostname(vm_ip, tmp_file)
    test_stub.update_mn_ip(vm_ip, tmp_file)
    test_stub.start_mn(vm_ip, tmp_file)

    time.sleep(400)
    test_util.test_logger('Update host management IP and reconnect host')
    host_name = 'Host-1'
    management_ip = vm_ip
    cond1 = res_ops.gen_query_conditions('name', '=', host_name)
    #host_uuid = res_ops.query_resource(res_ops.HOST, conditions)[0].inventories[0].uuid
    host_uuid = scen_ops.query_resource(management_ip, res_ops.HOST,
                                        cond1).inventories[0].uuid
    host_management_ip = vm_ip
    host_ops.update_host(host_uuid, 'managementIp', host_management_ip)
    host_ops.reconnect_host(host_uuid)

    test_util.test_logger('Update bs IP and reconnect bs')
    bs_name = 'BS-1'
    cond2 = res_ops.gen_query_conditions('name', '=', bs_name)
    #bs_uuid = res_ops.query_resource(res_ops.BACKUP_STORAGE, conditions)[0].inventories[0].uuid
    bs_uuid = scen_ops.query_resource(management_ip, res_ops.BACKUP_STORAGE,
                                      cond2).inventories[0].uuid
    bs_ip = vm_ip
    bs_ops.update_image_store_backup_storage_info(bs_uuid, 'hostname', bs_ip)
    bs_ops.reconnect_backup_storage(bs_uuid)

    #test_stub.check_installation(vm_ip, tmp_file)

    test_util.test_logger('Upgrade zstack to latest')
    test_stub.update_iso(vm_ip, tmp_file, iso_path, upgrade_script_path)
    #test_stub.updatei_21_iso(vm_ip, tmp_file, iso_21_path, upgrade_script_path)
    test_stub.upgrade_zstack(vm_ip, zstack_latest_path, tmp_file)
    test_stub.check_zstack_version(vm_ip, tmp_file, zstack_latest_version)
    test_stub.start_mn(vm_ip, tmp_file)
    test_stub.check_mn_running(vm_ip, tmp_file)
    #test_stub.check_installation(vm_ip, tmp_file)

    #check alarm update:
    test_util.test_dsc('check if alarm is update')
    all_alarm_list = scen_ops.query_resource(vm_ip, res_ops.ALARM)
    if len(all_alarm_list.inventories) <= 1:
        test_util.test_fail('update alarm failed.')
    all_endpoint_list = scen_ops.query_resource(vm_ip,
                                                res_ops.SNS_EMAIL_ENDPOINT)
    if len(all_endpoint_list.inventories) <= 1:
        test_util.test_fail('update endpoints failed')

    #check alarm email send
    test_util.test_dsc('check if alarm email is send')
    flag = False
    times = 5
    while times > 0:
        cond3 = res_ops.gen_query_conditions('status', '=', 'Alarm')
        alarm_list = scen_ops.query_resource(vm_ip, res_ops.ALARM,
                                             cond3).inventories
        #server = 'pop3.zstack.io'
        #email = '*****@*****.**'
        #password = '******'
        server = os.environ.get('receive_pop3server')
        email = os.environ.get('receive_email')
        password = os.environ.get('receive_password')
        for alarm in alarm_list:
            if True == flag:
                break
            flag = zwt_ops.check_sns_email(server, email, password,
                                           alarm.metricName, alarm.uuid)
        if True == flag:
            break
        time.sleep(60)
        times = times - 1

    os.system('rm -f %s' % tmp_file)
    test_stub.destroy_vm_scenario(vm_inv.uuid)
    if True == flag:
        test_util.test_pass('ZStack upgrade Test Success')
    else:
        test_util.test_fail('did\'n find alarm email.')
def test():
    global email_endpoint_uuid,email_platform_uuid,my_sns_topic_uuid,host_sns_topic_uuid,ps_uuid,hostname,host_management_ip,host_uuid,host_status,bs_uuid,bs_type,bs_status
    bs_cond = res_ops.gen_query_conditions('status', '=', 'Connected')
    bs_list = res_ops.query_resource(res_ops.BACKUP_STORAGE, bs_cond)
    for bss in bs_list:
        if bss.type ==res_ops.SFTP_BACKUP_STORAGE:
            bs_uuid =bss.uuid
            bs_type =bss.type
            hostname = bss.hostname
            break
        elif bss.type == res_ops.IMAGE_STORE_BACKUP_STORAGE:
            bs_uuid=bss.uuid
            bs_type=bss.type
            hostname = bss.hostname
            break
        else:
            test_util.test_skip('No match backupStorage,test skip')

    smtp_server = os.environ.get('smtpServer')
    pop_server = os.environ.get('popServer')
    smtp_port = os.environ.get('smtpPort')
    username = os.environ.get('mailUsername')
    password = os.environ.get('mailPassword')
    email_platform_name='Alarm_email'
    email_platform = zwt_ops.create_sns_email_platform(smtp_server, smtp_port,email_platform_name , username, password)
    email_platform_uuid = email_platform.uuid
    try:
        zwt_ops.validate_sns_email_platform(email_platform_uuid)
    except:
        test_util.test_fail('Validate SNS Email Platform Failed, Email Plarform: %s' % email_platform_uuid)
    email_endpoint_uuid = zwt_ops.create_sns_email_endpoint(username, 'test_qa', email_platform_uuid).uuid

    my_sns_topic = zwt_ops.create_sns_topic('my_sns_topic')
    my_sns_topic_uuid = my_sns_topic.uuid
    zwt_ops.subscribe_sns_topic(my_sns_topic_uuid, email_endpoint_uuid)

    host_sns_topic = zwt_ops.create_sns_topic('host_topic')
    host_sns_topic_uuid = host_sns_topic.uuid
    zwt_ops.subscribe_sns_topic(host_sns_topic_uuid, email_endpoint_uuid)

    ps_actions = [{"actionUuid": my_sns_topic_uuid, "actionType": "sns"}]
    ps_namespace = 'ZStack/PrimaryStorage'
    ps_disconnected = 'PrimaryStorageDisconnected'
    ps_event_sub_uuid = zwt_ops.subscribe_event(ps_namespace, ps_disconnected, ps_actions).uuid
    event_list.append(ps_event_sub_uuid)

    bs_actions = [{"actionUuid": my_sns_topic_uuid, "actionType": "sns"}]
    bs_namespace = 'ZStack/BackupStorage'
    bs_disconnected = 'BackupStorageDisconnected'
    bs_event_sub_uuid = zwt_ops.subscribe_event(bs_namespace, bs_disconnected, bs_actions).uuid
    event_list.append(bs_event_sub_uuid)

    host_actions = [{"actionUuid": host_sns_topic_uuid, "actionType": "sns"}]
    host_namespace = 'ZStack/Host'
    host_status_changed = 'HostStatusChanged'
    host_status_labels = [{"key": "NewStatus", "op": "Equal", "value": "Disconnected"}]
    host_status_event_sub_uuid = zwt_ops.subscribe_event(host_namespace, host_status_changed, host_actions, host_status_labels).uuid
    event_list.append(host_status_event_sub_uuid)

    host_disconnected = 'HostDisconnected'
    host_disconnected_event_sub_uuid = zwt_ops.subscribe_event(host_namespace, host_disconnected, host_actions).uuid
    event_list.append(host_disconnected_event_sub_uuid)

    if zwt_ops.check_sns_email(pop_server, username, password, ps_disconnected, ps_event_sub_uuid):
        test_util.test_fail('email already exsist before test')
    if zwt_ops.check_sns_email(pop_server, username, password, bs_disconnected, bs_event_sub_uuid):
        test_util.test_fail('email already exsist before test')
    if zwt_ops.check_sns_email(pop_server, username, password, host_status_changed, host_status_event_sub_uuid):
        test_util.test_fail('email already exsist before test')
    if zwt_ops.check_sns_email(pop_server, username, password, host_disconnected, host_disconnected_event_sub_uuid):
        test_util.test_fail('email already exsist before test')

    # Disconnected ps ,bs and host
    zone_uuid = res_ops.query_resource(res_ops.ZONE)[0].uuid
    primary_storage_option = test_util.PrimaryStorageOption()
    primary_storage_option.set_type('nfs')
    primary_storage_option.set_zone_uuid(zone_uuid)
    primary_storage_option.set_name('test_nfs_ps')
    primary_storage_option.set_url('222.222.222.222/nfs/')
    try:
        ps_uuid = ps_ops.create_nfs_primary_storage(primary_storage_option).uuid
        ps_ops.reconnect_primary_storage(ps_uuid)
    except:
        pass

    if bs_type == res_ops.IMAGE_STORE_BACKUP_STORAGE:
        bs_ops.update_image_store_backup_storage_info(bs_uuid, 'hostname', '222.222.222.222')
        try:
            bs_ops.reconnect_backup_storage(bs_uuid)
        except:
            cond = res_ops.gen_query_conditions('uuid', '=', bs_uuid)
            bs_status = res_ops.query_resource(res_ops.IMAGE_STORE_BACKUP_STORAGE, cond)[0].status
    elif bs_type == res_ops.SFTP_BACKUP_STORAGE:
        bs_ops.update_sftp_backup_storage_info(bs_uuid,'hostname','222.222.222.222')
        try:
            bs_ops.reconnect_backup_storage(bs_uuid)
        except:
            cond=res_ops.gen_query_conditions('uuid','=',bs_uuid)
            bs_status=res_ops.query_resource(res_ops.SFTP_BACKUP_STORAGE,cond)[0].status

    host_cond = res_ops.gen_query_conditions('status', '=', 'Connected')
    host = res_ops.query_resource_with_num(res_ops.HOST, host_cond, start=0, limit=1)[0]
    host_uuid = host.uuid
    host_management_ip = host.managementIp
    host_ops.update_host(host_uuid, 'managementIp', '222.222.222.222')
    try:
        host_ops.reconnect_host(host_uuid)
    except:
        cond = res_ops.gen_query_conditions('uuid', '=', host_uuid)
        bs_status = res_ops.query_resource(res_ops.HOST, cond)[0].status

    # wait for send email
    time.sleep(120)

    ps_ops.delete_primary_storage(ps_uuid)
    if hostname:
        if bs_type == res_ops.IMAGE_STORE_BACKUP_STORAGE:
            bs_ops.update_image_store_backup_storage_info(bs_uuid, 'hostname', hostname)
            bs_ops.reconnect_backup_storage(bs_uuid)
        elif bs_type == res_ops.SFTP_BACKUP_STORAGE:
            bs_ops.update_sftp_backup_storage_info(bs_uuid, 'hostname', hostname)
            bs_ops.reconnect_backup_storage(bs_uuid)
    host_ops.update_host(host_uuid, 'managementIp', host_management_ip)
    host_ops.reconnect_host(host_uuid)
    zwt_ops.delete_sns_topic(host_sns_topic_uuid)
    zwt_ops.delete_sns_topic(my_sns_topic_uuid)
    for event_uuid in event_list:
        zwt_ops.unsubscribe_event(event_uuid)
    zwt_ops.delete_sns_application_endpoint(email_endpoint_uuid)
    zwt_ops.delete_sns_application_platform(email_platform_uuid)

    check_1 = zwt_ops.check_sns_email(pop_server, username, password, ps_disconnected, ps_event_sub_uuid)
    check_2 = zwt_ops.check_sns_email(pop_server, username, password, bs_disconnected, bs_event_sub_uuid)
    check_3 = zwt_ops.check_sns_email(pop_server, username, password, host_status_changed, host_status_event_sub_uuid)
    check_4 = zwt_ops.check_sns_email(pop_server, username, password, host_disconnected, host_disconnected_event_sub_uuid)

    if check_1 and check_2 and check_3 and check_4:
        test_util.test_pass('test host ,bs, ps disconnected event with email success!')
    else:
        test_util.test_fail('cannt receive all event mail')
def test():
	"""
	"""
	image_uuid = None
	flag1 = False
	flag2 = False
	global bss,vm,host
	test_util.test_dsc('test for creating root volume template with bss disconnected and disable')
	
	#create a new vm
	image_uuid = test_lib.lib_get_image_by_name("centos").uuid
	vm = test_stub.create_vm(image_uuid=image_uuid)

	# firstly,test for bss state disable
	# change backup storage state

	cond = res_ops.gen_query_conditions('state', '=', 'Enabled')
	bss = res_ops.query_resource_with_num(res_ops.BACKUP_STORAGE, cond, limit=1)
	bs_ops.change_backup_storage_state(bss[0].uuid,DISABLE)

	#prepare to create root volume template after buckup_storage change state to disable

	root_volume_uuid = test_lib.lib_get_root_volume_uuid(vm.get_vm())

	image_option1 = test_util.ImageOption()
	image_option1.set_root_volume_uuid(root_volume_uuid)
	image_option1.set_name('image_for_bss_disconnected_test')
	image_option1.set_format('qcow2')
	image_option1.set_backup_storage_uuid_list([bss[0].uuid])
	# image_option1.set_platform('Linux')
	# bs_type = bss[0].type

	vm.stop()

	# this API can only be invoke when vm is stopped
	try:
		img_ops.create_root_volume_template(image_option1)
	except:
		bs_ops.change_backup_storage_state(bss[0].uuid, ENABLE)
		flag1=True

	# secondly,test for bss disconnected
	# change bss.host(IP address) to let bss disconnected.
	
	host = bss[0].hostname
	bs_ops.update_image_store_backup_storage_info(bss[0].uuid, infoType, infoValue)
	try:
		bs_ops.reconnect_backup_storage(bss[0].uuid)
	except:
		#can't reconnect the bs,so the bs'status is disconnected
		pass
	
	#create root volume template after buckup_storage change state to disable
	try:
		img_ops.create_root_volume_template(image_option1)
	except:
		bs_ops.update_image_store_backup_storage_info(bss[0].uuid, infoType, host)
		bs_ops.reconnect_backup_storage(bss[0].uuid)
		flag2=True
	
	if flag1 and flag2:
		vm.clean()
		test_util.test_pass(
			"can't create root volume template,The test that create root volume template from root volume with ImageStoreBackupStorage server disconnected or disable is "
			"success! ")
	else:
		vm.clean()
		test_util.test_fail(
			"success create root image,The test that create root volume template from root volume with ImageStoreBackupStorage server disconnected or dieable is "
			"fail! ")
def test():
    global vcenter_uuid1
    global vcenter_uuid2
    global mevoco1_ip
    global mevoco2_ip
    global img_uuid
    global delete_policy1
    global delete_policy2

    print os.environ
    vcenter1_name = os.environ['vcenter2_name']
    vcenter1_domain_name = os.environ['vcenter2_ip']
    vcenter1_username = os.environ['vcenter2_domain_name']
    vcenter1_password = os.environ['vcenter2_password']
    sync_image_url = os.environ['vcenter2_sync_image_url']
    image_name = os.environ['vcenter2_sync_image_name']

    mevoco1_ip = os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP']
    mevoco2_ip = os.environ['serverIp2']

    os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco1_ip
    delete_policy1 = test_lib.lib_set_delete_policy('image', 'Delay')
    zone_uuid = res_ops.get_resource(res_ops.ZONE)[0].uuid
    inv = vct_ops.add_vcenter(vcenter1_name, vcenter1_domain_name,
                              vcenter1_username, vcenter1_password, True,
                              zone_uuid)
    vcenter_uuid1 = inv.uuid
    if vcenter_uuid1 == None:
        test_util.test_fail("vcenter_uuid is None")

    os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco2_ip
    delete_policy2 = test_lib.lib_set_delete_policy('image', 'Delay')
    zone_uuid = res_ops.get_resource(res_ops.ZONE)[0].uuid
    inv = vct_ops.add_vcenter(vcenter1_name, vcenter1_domain_name,
                              vcenter1_username, vcenter1_password, True,
                              zone_uuid)
    vcenter_uuid2 = inv.uuid
    if vcenter_uuid2 == None:
        test_util.test_fail("vcenter_uuid is None")

    #bs_cond = res_ops.gen_query_conditions("name", '=', "vCenter[vm-center]")
    bs_cond = res_ops.gen_query_conditions("type", '=', "VCenter")
    bss = res_ops.query_resource_fields(res_ops.BACKUP_STORAGE, bs_cond, \
            None, fields=['uuid'])
    if not bss:
        test_util.test_skip("not find available backup storage. Skip test")

    #add sync image in mevoco2
    image_option = test_util.ImageOption()
    image_option.set_name(image_name)
    #image_option.set_mediaType('RootVolumeTemplate')
    image_option.set_format('vmtx')
    image_option.set_system_tags('vcenter::datacenter::datacenter1')
    #image_option.set_url(os.environ.get(sync_image_url))
    image_option.set_url(sync_image_url)
    image_option.set_backup_storage_uuid_list([bss[0].uuid])

    new_image = zstack_image_header.ZstackTestImage()
    new_image.set_creation_option(image_option)

    #if a error happens here, check whether the image with the same name is already
    #exist in vcenter, which is also raise exception about can't download on all backup storage
    test_util.test_logger("add image from url:%s" % (sync_image_url))
    new_image.add_root_volume_template()

    #reconnect vcenter and check newly add image in mevoco1
    test_util.test_logger("check image sync from mevoco1")
    os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco1_ip
    bs_cond = res_ops.gen_query_conditions("type", '=', "VCenter")
    bss = res_ops.query_resource_fields(res_ops.BACKUP_STORAGE,
                                        bs_cond,
                                        None,
                                        fields=['uuid'])
    bs_ops.reconnect_backup_storage(bss[0].uuid)
    image_cond = res_ops.gen_query_conditions("name", '=', image_name)
    img_inv = res_ops.query_resource_fields(res_ops.IMAGE,
                                            image_cond,
                                            None,
                                            fields=['uuid'])[0]
    img_uuid = img_inv.uuid
    if not img_uuid:
        test_util.test_fail("local woodpecker image uuid is null")

    #delete image in mevoco2
    test_util.test_logger("delete image from mevoco2")
    os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco2_ip
    image_cond = res_ops.gen_query_conditions("name", '=', image_name)
    img_inv = res_ops.query_resource_fields(res_ops.IMAGE,
                                            image_cond,
                                            None,
                                            fields=['uuid'])[0]
    img_uuid = img_inv.uuid
    img_ops.delete_image(img_uuid)
    img_ops.expunge_image(img_uuid)

    #check image in mevoco1
    test_util.test_logger("check image delete sync from mevoco1")
    os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco1_ip
    bs_cond = res_ops.gen_query_conditions("type", '=', "VCenter")
    bss = res_ops.query_resource_fields(res_ops.BACKUP_STORAGE,
                                        bs_cond,
                                        None,
                                        fields=['uuid'])
    bs_ops.reconnect_backup_storage(bss[0].uuid)
    image_cond = res_ops.gen_query_conditions("name", '=', image_name)
    #img_inv = res_ops.query_resource_fields(res_ops.IMAGE, image_cond, None, fields=['uuid'])[0]
    #img_uuid = img_inv.uuid
    img_inv = res_ops.query_resource_fields(res_ops.IMAGE,
                                            image_cond,
                                            None,
                                            fields=['uuid'])
    if img_inv:
        test_util.test_fail(
            "local woodpecker image is not deleted as expected")

    os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco2_ip
    test_lib.lib_set_delete_policy('image', delete_policy2)
    if vcenter_uuid2:
        vct_ops.delete_vcenter(vcenter_uuid2)

    os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco1_ip
    test_lib.lib_set_delete_policy('image', delete_policy1)
    if vcenter_uuid1:
        vct_ops.delete_vcenter(vcenter_uuid1)

    test_util.test_pass("vcenter sync image test passed.")
Пример #18
0
def test():
    """
	"""
    image_uuid = None
    flag1 = False
    flag2 = False
    global bss, vm, host
    test_util.test_dsc(
        'test for creating root volume template with bss disconnected and disable'
    )

    #create a new vm
    image_uuid = test_lib.lib_get_image_by_name("centos").uuid
    vm = test_stub.create_vm(image_uuid=image_uuid)

    # firstly,test for bss state disable
    # change backup storage state

    cond = res_ops.gen_query_conditions('state', '=', 'Enabled')
    bss = res_ops.query_resource_with_num(res_ops.BACKUP_STORAGE,
                                          cond,
                                          limit=1)
    bs_ops.change_backup_storage_state(bss[0].uuid, DISABLE)

    #prepare to create root volume template after buckup_storage change state to disable

    root_volume_uuid = test_lib.lib_get_root_volume_uuid(vm.get_vm())

    image_option1 = test_util.ImageOption()
    image_option1.set_root_volume_uuid(root_volume_uuid)
    image_option1.set_name('image_for_bss_disconnected_test')
    image_option1.set_format('qcow2')
    image_option1.set_backup_storage_uuid_list([bss[0].uuid])
    # image_option1.set_platform('Linux')
    # bs_type = bss[0].type

    vm.stop()

    # this API can only be invoke when vm is stopped
    try:
        img_ops.create_root_volume_template(image_option1)
    except:
        bs_ops.change_backup_storage_state(bss[0].uuid, ENABLE)
        flag1 = True

    # secondly,test for bss disconnected
    # change bss.host(IP address) to let bss disconnected.

    host = bss[0].hostname
    bs_ops.update_image_store_backup_storage_info(bss[0].uuid, infoType,
                                                  infoValue)
    try:
        bs_ops.reconnect_backup_storage(bss[0].uuid)
    except:
        #can't reconnect the bs,so the bs'status is disconnected
        pass

    #create root volume template after buckup_storage change state to disable
    try:
        img_ops.create_root_volume_template(image_option1)
    except:
        bs_ops.update_image_store_backup_storage_info(bss[0].uuid, infoType,
                                                      host)
        bs_ops.reconnect_backup_storage(bss[0].uuid)
        flag2 = True

    if flag1 and flag2:
        vm.clean()
        test_util.test_pass(
            "can't create root volume template,The test that create root volume template from root volume with ImageStoreBackupStorage server disconnected or disable is "
            "success! ")
    else:
        vm.clean()
        test_util.test_fail(
            "success create root image,The test that create root volume template from root volume with ImageStoreBackupStorage server disconnected or dieable is "
            "fail! ")
def test():
    global bs
    flavor = case_flavor[os.environ.get('CASE_FLAVOR')]

    cond = res_ops.gen_query_conditions('state', '=', 'Enabled')
    cond = res_ops.gen_query_conditions('status', '=', 'Connected', cond)
    if flavor['sftp']:
        cond = res_ops.gen_query_conditions('type', '=', 'SftpBackupStorage', cond)
    elif flavor['imagestore']:
        cond = res_ops.gen_query_conditions('type', '=', 'ImageStoreBackupStorage', cond)
    elif flavor['ceph']:
        cond = res_ops.gen_query_conditions('type', '=', 'Ceph', cond)

    bs = res_ops.query_resource_with_num(res_ops.BACKUP_STORAGE, cond, limit = 1)
    if not bs:
        test_util.test_skip('No Enabled/Connected bs was found, skip test.' )

    bs_ops.reconnect_backup_storage(bs[0].uuid)
    saved_bs = res_ops.query_resource_with_num(res_ops.BACKUP_STORAGE, cond, limit = 1)
    if flavor['ceph']:
        bs[0].managementIp = bs[0].mons[0].hostname
    else:
        bs[0].managementIp = bs[0].hostname
    if flavor['ceph']:
        test_stub.setup_fake_ceph(bs[0], 631242663936, 428968118272)
        fake_total = 631242663936
        fake_available = 428968118272
    else:
        test_stub.setup_fake_fs(bs[0], '2G', saved_bs[0].url)
        fake_total = 2*1024*1024*1024
        fake_available = 2*1024*1024*1024

    bs_ops.reconnect_backup_storage(bs[0].uuid)

    bs = res_ops.query_resource_with_num(res_ops.BACKUP_STORAGE, cond, limit = 1)
    if flavor['ceph']:
        bs[0].managementIp = bs[0].mons[0].hostname
    else:
        bs[0].managementIp = bs[0].hostname

    if bs[0].totalCapacity != fake_total:
        test_util.test_fail('totalCapacity %s not updated after reconnect bs' % (bs[0].totalCapacity))
    if bs[0].availableCapacity != fake_available:
        test_util.test_fail('availableCapacity %s not updated after reconnect bs' % (bs[0].availableCapacity))

    if flavor['ceph']:
        test_stub.remove_fake_ceph(bs[0])
    else:
        test_stub.remove_fake_fs(bs[0], saved_bs[0].url)
    bs_ops.reconnect_backup_storage(bs[0].uuid)
    
    bs = res_ops.query_resource_with_num(res_ops.BACKUP_STORAGE, cond, limit = 1)
    if flavor['ceph']:
        bs[0].managementIp = bs[0].mons[0].hostname
    else:
        bs[0].managementIp = bs[0].hostname

    if bs[0].totalCapacity != saved_bs[0].totalCapacity:
        test_util.test_fail('totalCapacity %s not updated after reconnect bs' % (bs[0].totalCapacity))
    if bs[0].availableCapacity == 0:
        test_util.test_fail('availableCapacity %s not updated after reconnect bs' % (bs[0].availableCapacity))

    test_util.test_pass('Test backup storage capacity after reconnect bs pass.')