def test():
    global vm_inv
    global zone_inv
    global cluster_inv
    global host_inv
    global ps_inv
    global bs_inv
    global image_inv
    global vmoffering_inv
    global l2_inv
    global l3_inv
    global l3_uuid
    global image_uuid
    global vmoffering_uuid
    global image_uuid
    global vm_ip

    test_util.test_dsc('Create test vm to test zstack install MN on centos7.1 and add the HOST')
    
    conditions = res_ops.gen_query_conditions('name', '=', os.environ.get('imageNameBase_c72'))
    image = res_ops.query_resource(res_ops.IMAGE, conditions)[0]
    vm_inv = create_vm(image)
    time.sleep(100)
    iso_path = os.environ.get('iso_path')
    upgrade_script_path = os.environ.get('upgradeScript')

    test_util.test_dsc('Install zstack with -o')
    vm_ip = vm_inv.vmNics[0].ip
    test_stub.make_ssh_no_password(vm_ip, tmp_file)
    test_util.test_dsc('Upgrade master iso')

    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_stub.update_iso(vm_ip, tmp_file, iso_path, upgrade_script_path)

    test_util.test_dsc('Install zstack with default path')
    ssh_cmd = 'ssh  -oStrictHostKeyChecking=no -oCheckHostIP=no -oUserKnownHostsFile=/dev/null %s' % vm_ip
    cmd= '%s "[ -e /usr/local/zstack ] && echo yes || echo no"' % ssh_cmd
    (process_result, cmd_stdout) = test_stub.execute_shell_in_process_stdout(cmd, tmp_file)
    if process_result != 0:
        test_util.test_fail('check /usr/local/zstack fail, cmd_stdout:%s' % cmd_stdout)
    cmd_stdout = cmd_stdout[:-1]
    if cmd_stdout == "yes":
        cmd = '%s "rm -rf /usr/local/zstack"' % ssh_cmd
        (process_result, cmd_stdout) = test_stub.execute_shell_in_process_stdout(cmd, tmp_file)
        if process_result != 0:
            test_util.test_fail('delete /usr/local/zstack fail')

    target_file = '/root/zstack-all-in-one.tgz'
    test_stub.prepare_test_env(vm_inv, target_file)
    ssh_cmd = 'ssh -oStrictHostKeyChecking=no -oCheckHostIP=no -oUserKnownHostsFile=/dev/null %s' % vm_ip
    args = "-D"

    test_util.test_dsc('start install the latest zstack-MN')
    test_stub.execute_install_with_args(ssh_cmd, args, target_file, tmp_file)

    test_util.test_dsc('create zone names is zone1')
    zone_inv = test_stub.create_zone1(vm_ip, tmp_file)
    zone_uuid = zone_inv.uuid

    test_util.test_dsc('create cluster names is clsuter1')
    cluster_name = 'Cluster1'
    cluster_inv = test_stub.create_cluster1(vm_ip, cluster_name, zone_uuid, tmp_file)
    cluster_uuid = cluster_inv.uuid

    test_util.test_dsc('add HOST names is HOST1')
    host_inv = test_stub.add_kvm_host1(vm_ip, cluster_uuid, tmp_file)
    host_uuid = host_inv.uuid

    test_util.test_dsc('add ps names is PS1')
    ps_inv = test_stub.create_local_ps(vm_ip, zone_uuid, tmp_file)
    ps_uuid = ps_inv.uuid

    test_stub.attach_ps(vm_ip, ps_uuid, cluster_uuid, tmp_file)

    test_util.test_dsc('add BS names is bs1')
    bs_inv = test_stub.create_sftp_backup_storage(vm_ip, tmp_file)
    bs_uuid = bs_inv.uuid

    test_stub.attach_bs(vm_ip, bs_uuid, zone_uuid, tmp_file)

    test_util.test_dsc('add image names is image1.4')
    image_inv = test_stub.add_image_local(vm_ip, bs_uuid, tmp_file)
    image_uuid = image_inv.uuid

    test_util.test_dsc('add vm instance offering names is 1-1G')
    vmoffering_inv = test_stub.create_vm_offering(vm_ip, tmp_file)
    vmoffering_uuid = vmoffering_inv.uuid

    test_util.test_dsc('create L2_vlan network  names is L2_vlan')
    l2_inv = sce_ops.create_l2_vlan(vm_ip, 'L2_vlan', 'eth0', '2200', zone_uuid)
    l2_uuid = l2_inv.inventory.uuid

    test_util.test_dsc('attach L2 netowrk to cluster')
    sce_ops.attach_l2(vm_ip, l2_uuid, cluster_uuid)

    test_util.test_dsc('create L3_flat_network names is L3_flat_network')
    l3_inv = sce_ops.create_l3(vm_ip, 'l3_flat_network', 'L3BasicNetwork', l2_uuid, 'local.com')
    l3_uuid = l3_inv.inventory.uuid    

    l3_dns = '223.5.5.5'
    start_ip = '192.168.109.5'
    end_ip = '192.168.109.200'
    gateway = '192.168.109.1'
    netmask = '255.255.255.0'

    test_util.test_dsc('add DNS and IP_Range for L3_flat_network')
    sce_ops.add_dns_to_l3(vm_ip, l3_uuid, l3_dns)
    sce_ops.add_ip_range(vm_ip,'IP_range', l3_uuid, start_ip, end_ip, gateway, netmask)
    
    test_util.test_dsc('query flat provider and attach network service to  L3_flat_network')
    provider_name = 'Flat Network Service Provider'
    conditions = res_ops.gen_query_conditions('name', '=', provider_name)
    net_provider_list = sce_ops.query_resource(vm_ip, res_ops.NETWORK_SERVICE_PROVIDER, conditions).inventories[0]
    pro_uuid = net_provider_list.uuid
    sce_ops.attach_flat_network_service_to_l3network(vm_ip, l3_uuid, pro_uuid)

    test_util.test_dsc('create a vm with L3_flat_network')
    new_vm_inv = create_new_vm(image_inv)

    os.system('rm -f %s' % tmp_file)
    sce_ops.destroy_vm(zstack_management_ip, vm_inv.uuid)
    test_util.test_pass('Install ZStack with -o on centos7.2 and create a vmSuccess')
def test():
    global linked_account_uuid,project_uuid,project_operator_uuid,account_lists,l2_uuid,account1_uuid,account2_uuid

    zone_uuid = res_ops.get_resource(res_ops.ZONE)[0].uuid
    cluster_uuid = res_ops.get_resource(res_ops.CLUSTER)[0].uuid
    # 1 create project
    project_name = 'test_shared_project1'
    project = iam2_ops.create_iam2_project(project_name)
    project_uuid = project.uuid
    linked_account_uuid = project.linkedAccountUuid

    # 2 create project operator
    project_operator_name = 'username_share1'
    project_operator_password = '******'
    attributes = [{"name": "__ProjectOperator__", "value": project_uuid}]
    project_operator_uuid = iam2_ops.create_iam2_virtual_id(project_operator_name,project_operator_password,attributes=attributes).uuid
    # 3 login in project by project operator
    iam2_ops.add_iam2_virtual_ids_to_project([project_operator_uuid],project_uuid)
    project_operator_session_uuid = iam2_ops.login_iam2_virtual_id(project_operator_name,project_operator_password)
    project_login_uuid = iam2_ops.login_iam2_project(project_name,session_uuid=project_operator_session_uuid).uuid

    l2_inv = net_ops.create_l2_vlan('L2_vlan_2221', 'eth0', zone_uuid, '2221')   
    l2_uuid = l2_inv.inventory.uuid

    test_util.test_dsc('share admin resoure to normal account')
    cond = res_ops.gen_query_conditions('name', '=', 'L2_vlan_2221')
    flat_l2_uuid = res_ops.query_resource(res_ops.L2_NETWORK, cond)[0].uuid
    acc_ops.share_resources([linked_account_uuid], [flat_l2_uuid])

    # ut_util.test_dsc('create L3_flat_network names is L3_flat_network by normal account')
    l3_inv = sce_ops.create_l3(zstack_management_ip, 'l3_flat_network', 'L3BasicNetwork', flat_l2_uuid, 'local.com', session_uuid = project_login_uuid)
    l3_uuid = l3_inv.inventory.uuid

    l3_dns = '223.5.5.5'
    start_ip = '192.168.123.2'
    end_ip = '192.168.123.10'
    gateway = '192.168.123.1'
    netmask = '255.255.255.0'

    test_util.test_dsc('add DNS and IP_Range for L3_flat_network')
    sce_ops.add_dns_to_l3(zstack_management_ip, l3_uuid, l3_dns, session_uuid = project_login_uuid)
    sce_ops.add_ip_range(zstack_management_ip,'IP_range', l3_uuid, start_ip, end_ip, gateway, netmask, session_uuid = project_login_uuid)

    test_util.test_dsc('query flat provider and attach network service to  L3_flat_network')
    provider_name = 'Flat Network Service Provider'
    conditions = res_ops.gen_query_conditions('name', '=', provider_name)
    net_provider_list = sce_ops.query_resource(zstack_management_ip, res_ops.NETWORK_SERVICE_PROVIDER, conditions, session_uuid = project_login_uuid).inventories[0]
    pro_uuid = net_provider_list.uuid
    sce_ops.attach_flat_network_service_to_l3network(zstack_management_ip, l3_uuid,pro_uuid, session_uuid = project_login_uuid)

    test_stub.share_admin_resource_1([linked_account_uuid])

    vm = test_stub.create_vm(session_uuid=project_login_uuid)
    test_obj_dict.add_vm(vm)

    #create normal account
    test_util.test_dsc('create normal account')
    account_name = 'test_abc'
    #account_pass = hashlib.sha512(account_name).hexdigest()
    account_pass = '******'
    test_account = acc_ops.create_normal_account(account_name, account_pass)
    test_account_uuid = test_account.uuid
    test_account_session = acc_ops.login_by_account(account_name, account_pass)

    test_util.test_dsc('share admin resoure to normal account test_abc')
    test_stub.share_admin_resource_1([test_account_uuid])

    l2_inv1 = sce_ops.create_l2_vlan(zstack_management_ip, 'L2_vlan_2215', 'eth0', '2215', zone_uuid)
    l2_uuid1 = l2_inv1.inventory.uuid

    test_util.test_dsc('attach L2 netowrk to cluster')
    sce_ops.attach_l2(zstack_management_ip, l2_uuid1, cluster_uuid)

    #share admin resoure to normal account
    test_util.test_dsc('share L2 L2_vlan_2215 to normal account test_a')
    cond = res_ops.gen_query_conditions('name', '=', 'L2_vlan_2215')
    flat_l2_uuid1 = res_ops.query_resource(res_ops.L2_NETWORK, cond)[0].uuid
    acc_ops.share_resources([test_account_uuid], [flat_l2_uuid1])

    test_account_session = acc_ops.login_by_account(account_name, account_pass)
    l3_inv1 = sce_ops.create_l3(zstack_management_ip, 'l3_flat_network1', 'L3BasicNetwork', flat_l2_uuid1, 'local.com', session_uuid = test_account_session)
    l3_uuid1 = l3_inv1.inventory.uuid

    l3_dns = '223.5.5.5'
    start_ip = '192.168.126.2'
    end_ip = '192.168.126.10'
    gateway = '192.168.126.1'
    netmask = '255.255.255.0'

    test_util.test_dsc('add DNS and IP_Range for L3_flat_network1')
    sce_ops.add_dns_to_l3(zstack_management_ip, l3_uuid1, l3_dns, session_uuid = test_account_session)
    sce_ops.add_ip_range(zstack_management_ip,'IP_range', l3_uuid1, start_ip, end_ip, gateway, netmask, session_uuid = test_account_session)

    test_util.test_dsc('query flat provider and attach network service to  L3_flat_network')
    provider_name = 'Flat Network Service Provider'
    conditions = res_ops.gen_query_conditions('name', '=', provider_name)
    net_provider_list = sce_ops.query_resource(zstack_management_ip, res_ops.NETWORK_SERVICE_PROVIDER, conditions, session_uuid = test_account_session).inventories[0]
    pro_uuid = net_provider_list.uuid
    sce_ops.attach_flat_network_service_to_l3network(zstack_management_ip, l3_uuid1,pro_uuid, session_uuid = test_account_session)

    vm2 = test_stub.create_vm(session_uuid = test_account_session)

    test_util.test_dsc('test success normal acount create L3 by admin share L2 ')
    test_obj_dict.add_vm(vm2)

    # 9 delete
    acc_ops.logout(project_login_uuid)
    iam2_ops.delete_iam2_virtual_id(project_operator_uuid)
    iam2_ops.delete_iam2_project(project_uuid)
    iam2_ops.expunge_iam2_project(project_uuid)
    test_lib.lib_error_cleanup(test_obj_dict)

    net_ops.delete_l2(l2_uuid)
    net_ops.delete_l2(l2_uuid1)

    acc_ops.delete_account(test_account_uuid)
Exemplo n.º 3
0
def test():
    global vm_inv
    global zone_inv
    global cluster_inv
    global host_inv
    global ps_inv
    global bs_inv
    global image_inv
    global vmoffering_inv
    global l2_inv
    global l3_inv
    global l3_uuid
    global image_uuid
    global vmoffering_uuid
    global image_uuid
    global vm_ip

    test_util.test_dsc(
        'Create test vm to test zstack install MN on centos7.1 and add the HOST'
    )

    conditions = res_ops.gen_query_conditions(
        'name', '=', os.environ.get('imageNameBase_c72'))
    image = res_ops.query_resource(res_ops.IMAGE, conditions)[0]
    vm_inv = create_vm(image)
    time.sleep(100)
    iso_path = os.environ.get('iso_path')
    upgrade_script_path = os.environ.get('upgradeScript')

    test_util.test_dsc('Install zstack with -o')
    vm_ip = vm_inv.vmNics[0].ip
    test_stub.make_ssh_no_password(vm_ip, tmp_file)
    test_util.test_dsc('Upgrade master iso')

    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_stub.update_iso(vm_ip, tmp_file, iso_path, upgrade_script_path)

    test_util.test_dsc('Install zstack with default path')
    ssh_cmd = 'ssh  -oStrictHostKeyChecking=no -oCheckHostIP=no -oUserKnownHostsFile=/dev/null %s' % vm_ip
    cmd = '%s "[ -e /usr/local/zstack ] && echo yes || echo no"' % ssh_cmd
    (process_result,
     cmd_stdout) = test_stub.execute_shell_in_process_stdout(cmd, tmp_file)
    if process_result != 0:
        test_util.test_fail('check /usr/local/zstack fail, cmd_stdout:%s' %
                            cmd_stdout)
    cmd_stdout = cmd_stdout[:-1]
    if cmd_stdout == "yes":
        cmd = '%s "rm -rf /usr/local/zstack"' % ssh_cmd
        (process_result,
         cmd_stdout) = test_stub.execute_shell_in_process_stdout(
             cmd, tmp_file)
        if process_result != 0:
            test_util.test_fail('delete /usr/local/zstack fail')

    target_file = '/root/zstack-all-in-one.tgz'
    test_stub.prepare_test_env(vm_inv, target_file)
    ssh_cmd = 'ssh -oStrictHostKeyChecking=no -oCheckHostIP=no -oUserKnownHostsFile=/dev/null %s' % vm_ip
    args = "-D"

    test_util.test_dsc('start install the latest zstack-MN')
    test_stub.execute_install_with_args(ssh_cmd, args, target_file, tmp_file)

    test_util.test_dsc('create zone names is zone1')
    zone_inv = test_stub.create_zone1(vm_ip, tmp_file)
    zone_uuid = zone_inv.uuid

    test_util.test_dsc('create cluster names is clsuter1')
    cluster_inv = test_stub.create_cluster1(vm_ip, zone_uuid, tmp_file)
    cluster_uuid = cluster_inv.uuid

    test_util.test_dsc('add HOST names is HOST1')
    host_inv = test_stub.add_kvm_host1(vm_ip, cluster_uuid, tmp_file)
    host_uuid = host_inv.uuid

    test_util.test_dsc('add ps names is PS1')
    ps_inv = test_stub.create_local_ps(vm_ip, zone_uuid, tmp_file)
    ps_uuid = ps_inv.uuid

    test_stub.attach_ps(vm_ip, ps_uuid, cluster_uuid, tmp_file)

    test_util.test_dsc('add BS names is bs1')
    bs_inv = test_stub.create_sftp_backup_storage(vm_ip, tmp_file)
    bs_uuid = bs_inv.uuid

    test_stub.attach_bs(vm_ip, bs_uuid, zone_uuid, tmp_file)

    test_util.test_dsc('add image names is image1.4')
    image_inv = test_stub.add_image_local(vm_ip, bs_uuid, tmp_file)
    image_uuid = image_inv.uuid

    test_util.test_dsc('add vm instance offering names is 1-1G')
    vmoffering_inv = test_stub.create_vm_offering(vm_ip, tmp_file)
    vmoffering_uuid = vmoffering_inv.uuid

    test_util.test_dsc('create L2_vlan network  names is L2_vlan')
    l2_inv = sce_ops.create_l2_vlan(vm_ip, 'L2_vlan', 'eth0', '2200',
                                    zone_uuid)
    l2_uuid = l2_inv.inventory.uuid

    test_util.test_dsc('attach L2 netowrk to cluster')
    sce_ops.attach_l2(vm_ip, l2_uuid, cluster_uuid)

    test_util.test_dsc('create L3_flat_network names is L3_flat_network')
    l3_inv = sce_ops.create_l3(vm_ip, 'l3_flat_network', 'L3BasicNetwork',
                               l2_uuid, 'local.com')
    l3_uuid = l3_inv.inventory.uuid

    l3_dns = '223.5.5.5'
    start_ip = '192.168.109.5'
    end_ip = '192.168.109.200'
    gateway = '192.168.109.1'
    netmask = '255.255.255.0'

    test_util.test_dsc('add DNS and IP_Range for L3_flat_network')
    sce_ops.add_dns_to_l3(vm_ip, l3_uuid, l3_dns)
    sce_ops.add_ip_range(vm_ip, 'IP_range', l3_uuid, start_ip, end_ip, gateway,
                         netmask)

    test_util.test_dsc(
        'query flat provider and attach network service to  L3_flat_network')
    provider_name = 'Flat Network Service Provider'
    conditions = res_ops.gen_query_conditions('name', '=', provider_name)
    net_provider_list = sce_ops.query_resource(
        vm_ip, res_ops.NETWORK_SERVICE_PROVIDER, conditions).inventories[0]
    pro_uuid = net_provider_list.uuid
    sce_ops.attach_flat_network_service_to_l3network(vm_ip, l3_uuid, pro_uuid)

    test_util.test_dsc('create a vm with L3_flat_network')
    new_vm_inv = create_new_vm(image_inv)

    os.system('rm -f %s' % tmp_file)
    sce_ops.destroy_vm(zstack_management_ip, vm_inv.uuid)
    test_util.test_pass(
        'Install ZStack with -o on centos7.2 and create a vmSuccess')
def test():
    global vm_inv
    global zone_inv
    global cluster_inv
    global host_inv
    global bs_inv
    global image_inv
    global vmoffering_inv
    global l2_inv
    global l3_inv
    global l3_uuid
    global image_uuid
    global vmoffering_uuid
    global image_uuid
    global vm_ip

    test_util.test_dsc('Create test vm to test zstack upgrade on centos72 mini iso with zstack 2.2.2 by -u.')

    image_name = os.environ.get('imageNameBase_c72_222_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)

    test_stub.make_ssh_no_password(vm_ip, tmp_file)

    os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = vm_ip

    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_stub.check_installation(vm_ip, tmp_file)

    test_util.test_dsc('create zone names is zone1')
    zone_inv = test_stub.create_zone1(vm_ip, tmp_file)
    zone_uuid = zone_inv.uuid

    test_util.test_dsc('create cluster names is clsuter1')
    cluster_name = 'Cluster1'
    cluster_inv = test_stub.create_cluster1(vm_ip, cluster_name, zone_uuid, tmp_file)
    cluster_uuid = cluster_inv.uuid

    test_util.test_dsc('add HOST names is HOST1')
    host_name = 'host1'
    host_ip = vm_ip
    host_inv = test_stub.add_kvm_host1(vm_ip, host_ip, host_name,  cluster_uuid, tmp_file)
    host_uuid = host_inv.uuid

    test_util.test_dsc('add ps names is PS1')
    ps_inv = test_stub.create_local_ps(vm_ip, zone_uuid, tmp_file)
    ps_uuid = ps_inv.uuid

    test_stub.attach_ps(vm_ip, ps_uuid, cluster_uuid, tmp_file)

    test_util.test_dsc('add BS names is bs1')
    bs_inv = test_stub.create_sftp_backup_storage(vm_ip, tmp_file)
    bs_uuid = bs_inv.uuid

    test_stub.attach_bs(vm_ip, bs_uuid, zone_uuid, tmp_file)

    test_util.test_dsc('add image names is image1.4')
    image_inv = test_stub.add_image_local(vm_ip, bs_uuid, tmp_file)
    image_uuid = image_inv.uuid

    test_util.test_dsc('add vm instance offering names is 1-1G')
    vmoffering_inv = test_stub.create_vm_offering(vm_ip, tmp_file)
    vmoffering_uuid = vmoffering_inv.uuid

    test_util.test_dsc('create L2_vlan network  names is L2_vlan')
    l2_inv = sce_ops.create_l2_vlan(vm_ip, 'L2_vlan', 'eth0', '2200', zone_uuid)
    l2_uuid = l2_inv.inventory.uuid

    test_util.test_dsc('attach L2 netowrk to cluster')
    sce_ops.attach_l2(vm_ip, l2_uuid, cluster_uuid)

    test_util.test_dsc('create L3_flat_network names is L3_flat_network')
    l3_inv = sce_ops.create_l3(vm_ip, 'l3_flat_network', 'L3BasicNetwork', l2_uuid, 'local.com')
    l3_uuid = l3_inv.inventory.uuid

    l3_dns = '223.5.5.5'
    start_ip = '192.168.109.5'
    end_ip = '192.168.109.200'
    gateway = '192.168.109.1'
    netmask = '255.255.255.0'

    test_util.test_dsc('add DNS and IP_Range for L3_flat_network')
    sce_ops.add_dns_to_l3(vm_ip, l3_uuid, l3_dns)
    sce_ops.add_ip_range(vm_ip,'IP_range', l3_uuid, start_ip, end_ip, gateway, netmask)

    test_util.test_dsc('query flat provider and attach network service to  L3_flat_network')
    provider_name = 'Flat Network Service Provider'
    conditions = res_ops.gen_query_conditions('name', '=', provider_name)
    net_provider_list = sce_ops.query_resource(vm_ip, res_ops.NETWORK_SERVICE_PROVIDER, conditions).inventories[0]
    pro_uuid = net_provider_list.uuid
    sce_ops.attach_flat_network_service_to_l3network(vm_ip, l3_uuid, pro_uuid)

    test_util.test_dsc('create a vm with L3_flat_network')
    new_vm_inv = create_new_vm(image_inv)

    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_mn_running(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 from centos72 mini iso 2.2.2 to the latest master zstack Test Success')
def test():
    global vm_inv
    global zone_inv
    global cluster_inv
    global host_inv
    global bs_inv
    global image_inv
    global vmoffering_inv
    global l2_inv
    global l3_inv
    global l3_uuid
    global image_uuid
    global vmoffering_uuid
    global image_uuid
    global vm_ip

    test_util.test_dsc('Create test vm to test zstack upgrade on centos71 mini iso with zstack 2.2.3 by -u.')

    image_name = os.environ.get('imageNameBase_c71_223_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')
    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_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_stub.check_installation(vm_ip, tmp_file)

    test_util.test_dsc('create zone names is zone1')
    zone_inv = test_stub.create_zone1(vm_ip, tmp_file)
    zone_uuid = zone_inv.uuid

    test_util.test_dsc('create cluster names is clsuter1')
    cluster_inv = test_stub.create_cluster1(vm_ip, zone_uuid, tmp_file)
    cluster_uuid = cluster_inv.uuid

    test_util.test_dsc('add HOST names is HOST1')
    host_inv = test_stub.add_kvm_host1(vm_ip, cluster_uuid, tmp_file)
    host_uuid = host_inv.uuid

    test_util.test_dsc('add ps names is PS1')
    ps_inv = test_stub.create_local_ps(vm_ip, zone_uuid, tmp_file)
    ps_uuid = ps_inv.uuid

    test_stub.attach_ps(vm_ip, ps_uuid, cluster_uuid, tmp_file)

    test_util.test_dsc('add BS names is bs1')
    bs_inv = test_stub.create_sftp_backup_storage(vm_ip, tmp_file)
    bs_uuid = bs_inv.uuid

    test_stub.attach_bs(vm_ip, bs_uuid, zone_uuid, tmp_file)

    test_util.test_dsc('add image names is image1.4')
    image_inv = test_stub.add_image_local(vm_ip, bs_uuid, tmp_file)
    image_uuid = image_inv.uuid

    test_util.test_dsc('add vm instance offering names is 1-1G')
    vmoffering_inv = test_stub.create_vm_offering(vm_ip, tmp_file)
    vmoffering_uuid = vmoffering_inv.uuid

    test_util.test_dsc('create L2_vlan network  names is L2_vlan')
    l2_inv = sce_ops.create_l2_vlan(vm_ip, 'L2_vlan', 'eth0', '2200', zone_uuid)
    l2_uuid = l2_inv.inventory.uuid

    test_util.test_dsc('attach L2 netowrk to cluster')
    sce_ops.attach_l2(vm_ip, l2_uuid, cluster_uuid)

    test_util.test_dsc('create L3_flat_network names is L3_flat_network')
    l3_inv = sce_ops.create_l3(vm_ip, 'l3_flat_network', 'L3BasicNetwork', l2_uuid, 'local.com')
    l3_uuid = l3_inv.inventory.uuid

    l3_dns = '223.5.5.5'
    start_ip = '192.168.109.5'
    end_ip = '192.168.109.200'
    gateway = '192.168.109.1'
    netmask = '255.255.255.0'

    test_util.test_dsc('add DNS and IP_Range for L3_flat_network')
    sce_ops.add_dns_to_l3(vm_ip, l3_uuid, l3_dns)
    sce_ops.add_ip_range(vm_ip,'IP_range', l3_uuid, start_ip, end_ip, gateway, netmask)

    test_util.test_dsc('query flat provider and attach network service to  L3_flat_network')
    provider_name = 'Flat Network Service Provider'
    conditions = res_ops.gen_query_conditions('name', '=', provider_name)
    net_provider_list = sce_ops.query_resource(vm_ip, res_ops.NETWORK_SERVICE_PROVIDER, conditions).inventories[0]
    pro_uuid = net_provider_list.uuid
    sce_ops.attach_flat_network_service_to_l3network(vm_ip, l3_uuid, pro_uuid)

    test_util.test_dsc('create a vm with L3_flat_network')
    new_vm_inv = create_new_vm(image_inv)

    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 from centos71 mini iso 2.2.3 to the latest master zstack Test Success')
def test():
    global vm, session_uuid
    global test_account_uuid, test_account_session
    
    test_util.test_dsc('Test normal account change the qos network and volume ')

    #create normal account
    test_util.test_dsc('create normal account')
    account_name = 'test_a'
    account_pass = hashlib.sha512(account_name).hexdigest()
    test_account = acc_ops.create_normal_account(account_name, account_pass)
    test_account_uuid = test_account.uuid
    test_account_session = acc_ops.login_by_account(account_name, account_pass)

    #create L3 flat network
    test_util.test_dsc('create L2_vlan network  names is L2_vlan')
    zone_uuid = res_ops.query_resource(res_ops.ZONE)[0].uuid
    cluster_uuid = res_ops.query_resource(res_ops.CLUSTER)[0].uuid
    
    l2_inv = sce_ops.create_l2_vlan(zstack_management_ip, 'L2_vlan_2215', 'eth0', '2215', zone_uuid)
    l2_uuid = l2_inv.inventory.uuid

    test_util.test_dsc('attach L2 netowrk to cluster')
    sce_ops.attach_l2(zstack_management_ip, l2_uuid, cluster_uuid)

    #share admin resoure to normal account
    test_util.test_dsc('share admin resoure to normal account')
    cond = res_ops.gen_query_conditions('name', '=', 'L2_vlan_2215')
    flat_l2_uuid = res_ops.query_resource(res_ops.L2_NETWORK, cond)[0].uuid
    acc_ops.share_resources([test_account_uuid], [flat_l2_uuid])

    test_util.test_dsc('create L3_flat_network names is L3_flat_network by normal account')
    l3_inv = sce_ops.create_l3(zstack_management_ip, 'l3_flat_network', 'L3BasicNetwork', l2_uuid, 'local.com', session_uuid = test_account_session)
    l3_uuid = l3_inv.inventory.uuid

    l3_dns = '223.5.5.5'
    start_ip = '192.168.129.2'
    end_ip = '192.168.129.10'
    gateway = '192.168.129.1'
    netmask = '255.255.255.0'

    test_util.test_dsc('add DNS and IP_Range for L3_flat_network')
    sce_ops.add_dns_to_l3(zstack_management_ip, l3_uuid, l3_dns, session_uuid = test_account_session)
    sce_ops.add_ip_range(zstack_management_ip,'IP_range', l3_uuid, start_ip, end_ip, gateway, netmask, session_uuid = test_account_session)

    test_util.test_dsc('query flat provider and attach network service to  L3_flat_network')
    provider_name = 'Flat Network Service Provider'
    conditions = res_ops.gen_query_conditions('name', '=', provider_name)
    net_provider_list = sce_ops.query_resource(zstack_management_ip, res_ops.NETWORK_SERVICE_PROVIDER, conditions, session_uuid = test_account_session).inventories[0]
    pro_uuid = net_provider_list.uuid
    sce_ops.attach_flat_network_service_to_l3network(zstack_management_ip, l3_uuid, pro_uuid, session_uuid = test_account_session)

    instance_offerings = res_ops.get_resource(res_ops.INSTANCE_OFFERING)
    for instance_offering in instance_offerings:
        acc_ops.share_resources([test_account_uuid], [instance_offering.uuid])

    #acc_ops.share_resources([test_account_uuid], [instance_offering_uuid])
    cond = res_ops.gen_query_conditions('mediaType', '!=', 'ISO')
    images = res_ops.query_resource(res_ops.IMAGE, cond)
    for image in images:
        acc_ops.share_resources([test_account_uuid], [image.uuid])

    #create vm
    test_util.test_dsc('create vm by normal account test_a')
    vm = test_stub.create_vm(session_uuid = test_account_session)
    
    vm.check()
    vm.destroy(test_account_session)
    net_ops.delete_l2(l2_uuid)
    vm.check()
    acc_ops.delete_account(test_account_uuid)    
    test_util.test_pass('normal account create eip by admin shared vip Test Success')
def test():
    global vm_inv
    global zone_inv
    global cluster_inv
    global host_inv
    global ps_inv
    global bs_inv
    global image_inv
    global vmoffering_inv
    global l2_inv
    global l3_inv
    global l3_uuid
    global image_uuid
    global vmoffering_uuid
    global image_uuid
    global vm_ip

    test_util.test_dsc('Create test vm to test zstack install MN on centos7.4 and add the HOST')
    
    conditions = res_ops.gen_query_conditions('name', '=', os.environ.get('imageNameBase_c74_231_ex'))
    image = res_ops.query_resource(res_ops.IMAGE, conditions)[0]
    vm_inv = create_vm(image)
    time.sleep(100)
    #c74_iso_path = os.environ.get('iso_250_c74_path')
    #upgrade_script_path = os.environ.get('upgradeScript')

    test_util.test_dsc('Install zstack with -o')
    vm_ip = vm_inv.vmNics[0].ip
    test_stub.make_ssh_no_password(vm_ip, tmp_file)
    #test_util.test_dsc('Upgrade 2.5.0 c74  iso')

    #test_stub.update_c74_iso(vm_ip, tmp_file, c74_iso_path, upgrade_script_path)

    test_stub.update_repo(vm_ip, tmp_file)
    target_file = '/root/zstack-all-in-one.tgz'
    test_stub.prepare_test_env(vm_inv, target_file)
    ssh_cmd = 'ssh -oStrictHostKeyChecking=no -oCheckHostIP=no -oUserKnownHostsFile=/dev/null %s' % vm_ip
    args = "-o"

    test_util.test_dsc('start install the latest zstack-MN')
    test_stub.execute_install_with_args(ssh_cmd, args, target_file, tmp_file)

       
    os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = vm_ip

    test_util.test_dsc('create zone names is zone1')
    zone_inv = test_stub.create_zone1(vm_ip, tmp_file)
    zone_uuid = zone_inv.uuid

    test_util.test_dsc('create cluster names is clsuter1')
    cluster_name = 'cluster1'
    cluster_inv = test_stub.create_cluster1(vm_ip, cluster_name, zone_uuid, tmp_file)
    cluster_uuid = cluster_inv.uuid

    test_util.test_dsc('add HOST names is HOST1')
    host_ip = vm_ip
    host_name = 'host1'
    host_inv = test_stub.add_kvm_host1(vm_ip, host_ip, host_name, cluster_uuid, tmp_file)
    host_uuid = host_inv.uuid

    test_util.test_dsc('add ps names is PS1')
    ps_inv = test_stub.create_local_ps(vm_ip, zone_uuid, tmp_file)
    ps_uuid = ps_inv.uuid

    test_stub.attach_ps(vm_ip, ps_uuid, cluster_uuid, tmp_file)

    test_util.test_dsc('add BS names is bs1')
    bs_inv = test_stub.create_sftp_backup_storage(vm_ip, tmp_file)
    bs_uuid = bs_inv.uuid

    test_stub.attach_bs(vm_ip, bs_uuid, zone_uuid, tmp_file)

    test_util.test_dsc('add image names is image1.4')
    image_inv = test_stub.add_image_local(vm_ip, bs_uuid, tmp_file)
    image_uuid = image_inv.uuid

    test_util.test_dsc('add vm instance offering names is 1-1G')
    vmoffering_inv = test_stub.create_vm_offering(vm_ip, tmp_file)
    vmoffering_uuid = vmoffering_inv.uuid

    test_util.test_dsc('create L2_vlan network  names is L2_vlan')
    l2_inv = sce_ops.create_l2_vlan(vm_ip, 'L2_vlan', 'eth0', '2204', zone_uuid)
    l2_uuid = l2_inv.inventory.uuid

    test_util.test_dsc('attach L2 netowrk to cluster')
    sce_ops.attach_l2(vm_ip, l2_uuid, cluster_uuid)

    test_util.test_dsc('create L3_flat_network names is L3_flat_network')
    l3_inv = sce_ops.create_l3(vm_ip, 'l3_flat_network', 'L3BasicNetwork', l2_uuid, 'local.com')
    l3_uuid = l3_inv.inventory.uuid    

    l3_dns = '223.5.5.5'
    start_ip = '192.168.108.5'
    end_ip = '192.168.108.200'
    gateway = '192.168.108.1'
    netmask = '255.255.255.0'

    test_util.test_dsc('add DNS and IP_Range for L3_flat_network')
    sce_ops.add_dns_to_l3(vm_ip, l3_uuid, l3_dns)
    sce_ops.add_ip_range(vm_ip,'IP_range', l3_uuid, start_ip, end_ip, gateway, netmask)
    
    test_util.test_dsc('query flat provider and attach network service to  L3_flat_network')
    provider_name = 'Flat Network Service Provider'
    conditions = res_ops.gen_query_conditions('name', '=', provider_name)
    net_provider_list = sce_ops.query_resource(vm_ip, res_ops.NETWORK_SERVICE_PROVIDER, conditions).inventories[0]
    pro_uuid = net_provider_list.uuid
    sce_ops.attach_flat_network_service_to_l3network(vm_ip, l3_uuid, pro_uuid)

    test_util.test_dsc('create a vm with L3_flat_network')
    new_vm_inv = create_new_vm(image_inv)

    os.system('rm -f %s' % tmp_file)
    sce_ops.destroy_vm(zstack_management_ip, vm_inv.uuid)
    test_util.test_pass('Install ZStack with -o on centos7.4 and create a vmSuccess')