Beispiel #1
0
def reg_img(addr,account,img):   
    img_name = img.partition('.')[0]
    img_des = img_name + " system image!"
    
    encrypted_account_session, server, image_id = upload_img(addr,account,img)

    i = image(server,encrypted_account_session)
    if i.query_state_by_id(image_id) != 1:
        #id,name,type,arch,is_public,is_available,description
        if i.register(image_id,img_name,"machine","x86_64",False,True,img_des) != True:
            st_exit(-1,lines(),"failed to register new image!")

    return encrypted_account_session, server, image_id
Beispiel #2
0
def upload_img(addr,account,img):
    image_home = "/home/ci_server/images/"
    test_image = image_home + img
		    
    encrypted_account_session, server = login_user(addr,account)
    
    i = image(server,encrypted_account_session)
    image_id = i.get_id_by_filename(img)
    if image_id is None:
        upload_image_file(addr,account,account,test_image)
        image_id = i.get_id_by_filename(img)
        
    return encrypted_account_session, server, image_id
Beispiel #3
0
        
server_url = '%s%s%s%s%s%s%s%s%s' % ('http://',test_root_user,':',test_root_passwd,'@',server_addr,':',server_port,'/RPC2')
print "Connect to xmlrpc url %s ..." % server_url
try:
    server = xmlrpclibex.ServerProxy(server_url,allow_none=True)
except:
    ci_exit(-1,"failed to create xmlrpc ServerProxy!")
root_session = login(server,test_root_user,test_root_passwd)
if root_session is None:
    ci_exit(-1,"root_session is none") 
#w_addr["target_workflow"] = [{"target":"tecscluster.cc.workflow_engine_0","workflow_id":"w-3e16ad30-60aa-4aa3-ae14-5b69904b0209"},{"target":v_target,"workflow_id":v_workflow_id}]
#w_addr["target_workflow"] = [{"target":v_target,"workflow_id":v_workflow_id},{"target":v_target,"workflow_id":v_workflow_id}]

w = worflow(server,root_session)
p = project(server,root_session)
i =  image(server,root_session)
v = vmcfg(server,root_session)
w_addr = {}

def workflow_max_query(target,workflow_id):
    w_addr["workflows"] = [{"engine":target,"id":workflow_id},{"engine":target,"id":workflow_id},
                            {"engine":target,"id":workflow_id},{"engine":target,"id":workflow_id},
                            {"engine":target,"id":workflow_id},{"engine":target,"id":workflow_id},
                            {"engine":target,"id":workflow_id},{"engine":target,"id":workflow_id},
                            {"engine":target,"id":workflow_id},{"engine":target,"id":workflow_id},
                            {"engine":target,"id":workflow_id}]
    w_states = w.query(w_addr)
    
    w_addr["workflows"] = [{"engine":target,"id":workflow_id},{"engine":target,"id":workflow_id},
                            {"engine":target,"id":workflow_id},{"engine":target,"id":workflow_id},
                            {"engine":target,"id":workflow_id},{"engine":target,"id":workflow_id},
Beispiel #4
0
    def testImage(self):   
        # ------------------环境准备------------------
        # 登录tecs,获取管理员账户加密后的session
        root_session = login(server,test_root_user,test_root_passwd)
        self.assertNotEqual(root_session,None,"failed to get encrypted root session!")

        #系统运行状态查询 EC:611003077308 tecs提供rpc接口查询系统运行时信息
        #此处延时20s,否则hc的MU_VM_HANDLER和MU_HOST_HEARTBEAT不存在
        time.sleep(100)
        #必须是管理员账户
        sys_runtime_query = tecssystem(server,root_session)
        #查询TC状态
        self.assertEqual(int(sys_runtime_query.get_runtime_state(TYPE_CACULATE,DEFAULT_TC)),RUNTIME_STATE_NORMAL,"tc status is abnormal")
        #查询CC状态
        self.assertEqual(int(sys_runtime_query.get_runtime_state(TYPE_CACULATE,test_cluster)),RUNTIME_STATE_NORMAL,"cc status is abnormal")
        #查询HC状态
        test_cc_hc = test_cluster + "," + test_host
        hc_state = int(sys_runtime_query.get_runtime_state(TYPE_CACULATE,test_cc_hc))
        self.assertTrue(hc_state >= RUNTIME_STATE_NORMAL and hc_state <= RUNTIME_STATE_WARNNING,"hc status is abnormal")

        # 创建一个用户组使用参数为 test_group1,1 ,应该成功
        ug  = usergroup(server,root_session)
        self.assertTrue(ug.allocate("test_group1",GROUP_TYPE1))

        # 创建一个用户 参数为 user,test,test,3,test_group1  应该成功
        u  = user(server,root_session)
        self.assertTrue(u.allocate("user","test","test",ACCOUNTUSER,"test_group1"))

        # 登录租户  获取租户session 以备后面使用
        user_session = login(server,"user","test")
        self.assertNotEqual(user_session,None,"failed to get user session!")
        
        # 以管理员身份上传一个映像文件  应该成功        
        self.assertTrue(upload_image_file(server_addr,test_root_user,test_root_passwd,test_image),"failed to upload_image_file!")
        # 以租户身份上传一个映像文件  应该成功
        self.assertTrue(upload_image_file(server_addr,"user","test",test_image),"failed to upload_image_file!")
            
        # 注册集群
        root_cluster_manager_method = clustermanager(server,root_session) 
        #time.sleep(20)
        self.assertTrue(root_cluster_manager_method.query(START_INDEX,QUERY_COUNT,SYN_MODE))

        # 注册主机
        root_host_method = host(server,root_session)
        # 等待 20S 等待资源上报
        time.sleep(20)
        self.assertTrue(root_host_method.query(START_INDEX,QUERY_COUNT,test_cluster,test_host))

        # 创建工程
        user_project = project(server,user_session)
        self.assertTrue(user_project.allocate(test_project_name,"test project description"))
          
        root_project = project(server,root_session)
        self.assertTrue(root_project.allocate(test_project_name,"test project description"))
 
        # 设置tcu 8 
        cpu_id = root_host_method.get_cpu_id(test_cluster,test_host)
        self.assertNotEqual(cpu_id,None)        

        print "cpu id of host %s = %d" % (test_host,cpu_id)    

        root_tcu_method = tcu(server,root_session)
        self.assertTrue(root_tcu_method.set(test_cluster,cpu_id,TCU_NUM8,"test cpu description"))
        
        self.assertTrue(root_tcu_method.query(START_INDEX,QUERY_COUNT,test_cluster,NO_CPU_INFO,cpu_id))

        # ------------------管理员自身权限测试------------------
        # 测试注册
        # 查询管理员上传的image id, 参数为映像文件名,返回值为映像id
        i = image(server,root_session)
        file_id = i.get_id_by_filename(os.path.basename(test_image))
        self.assertNotEqual(file_id,None)   

        i_id = file_id;

        #查询镜像注册时间
        self.assertNotEqual(i.query_register_time(file_id),None)   

        # 修改image  参数为 file_id, "ttylinux2", "", "", ""  应当成功
        self.assertTrue(i.set(file_id, "ttylinux2", NO_IMAGE_TYPE, NO_IMAGE_ARCH, "ide",NO_IMAGE_DESCRIPTION,"SUSE"))
        
        # 查询image的名字 ,应该为"ttylinux2"
        self.assertEqual(i.query_name_by_id(i_id),"ttylinux2")

        # 查询image的type ,应该为"machine"
        self.assertEqual(i.query_type_by_id(i_id),"machine")

        # 修改image  参数为 file_id, "", "kernel", "", ""  应当成功
        self.assertTrue(i.set(file_id, NO_IMAGE_NAME, "kernel", NO_IMAGE_ARCH,"ide", NO_IMAGE_DESCRIPTION, "SUSE"))

        # 查询image的type ,应该为"kernel"
        self.assertEqual(i.query_type_by_id(i_id),"kernel")

        # 修改image  参数为 file_id, "", "ramdisk", "", ""  应当成功
        self.assertTrue(i.set(file_id, NO_IMAGE_NAME, "ramdisk", NO_IMAGE_ARCH,"ide", NO_IMAGE_DESCRIPTION, "SUSE"))

        # 查询image的type ,应该为"ramdisk"
        self.assertEqual(i.query_type_by_id(i_id),"ramdisk")

        # 修改image  参数为 file_id, "", "cdrom", "", ""  应当成功
        self.assertTrue(i.set(file_id, NO_IMAGE_NAME, "cdrom", NO_IMAGE_ARCH,"ide", NO_IMAGE_DESCRIPTION, "SUSE"))

        # 查询image的type ,应该为"cdrom"
        self.assertEqual(i.query_type_by_id(i_id),"cdrom")
        
        # 修改image  参数为 file_id, "", "datablock", "", ""  应当成功
        self.assertTrue(i.set(file_id, NO_IMAGE_NAME, "datablock", NO_IMAGE_ARCH,"ide", NO_IMAGE_DESCRIPTION, "SUSE"))

        # 查询image的type ,应该为"datablock"
        self.assertEqual(i.query_type_by_id(i_id),"datablock")

        # 修改image  参数为 file_id, "", "aaaaa", "", ""  应当失败
        self.assertFalse(i.set(file_id, NO_IMAGE_NAME, "aaaaa", NO_IMAGE_ARCH,"ide", NO_IMAGE_DESCRIPTION, "SUSE"))

        # 查询image的arch ,应该为"x86_64"
        self.assertEqual(i.query_arch_by_id(i_id),"x86_64")

        # 修改image  参数为 file_id, "", "", "i386", ""  应当成功
        self.assertTrue(i.set(file_id, NO_IMAGE_NAME, NO_IMAGE_TYPE, "i386", "ide",NO_IMAGE_DESCRIPTION, "SUSE"))

        # 查询image的arch ,应该为"i386"
        self.assertEqual(i.query_arch_by_id(i_id),"i386")

        ########################################################    
        # 修改image  参数为 file_id, "", "", "i386", "ide",""  应当成功
        self.assertTrue(i.set(file_id, NO_IMAGE_NAME, NO_IMAGE_TYPE, "i386", "ide",NO_IMAGE_DESCRIPTION, "SUSE"))
            
        # 查询image的arch ,应该为"i386"
        self.assertEqual(i.query_bus_by_id(i_id),"ide")
        
        # 修改image  参数为 file_id, "", "", "i386", "scsi",""  应当成功
        self.assertTrue(i.set(file_id, NO_IMAGE_NAME, NO_IMAGE_TYPE, "i386", "scsi",NO_IMAGE_DESCRIPTION, "SUSE"))

        # 查询image的arch ,应该为"i386"
        self.assertEqual(i.query_bus_by_id(i_id),"scsi")
        
        # 修改image  参数为 file_id, "", "", "i386", "aaa",""  应当失败
        self.assertFalse(i.set(file_id, NO_IMAGE_NAME, NO_IMAGE_TYPE, "i386", "aaa",NO_IMAGE_DESCRIPTION, "SUSE"))

        # 查询image的arch ,应该仍然为最后一次设置的"scsi"
        self.assertEqual(i.query_bus_by_id(i_id),"scsi")        
        ########################################################    

        # 修改image  参数为 file_id, "", "", "aaaa", ""  应当失败
        self.assertFalse(i.set(file_id, NO_IMAGE_NAME, NO_IMAGE_TYPE, "aaaa", "ide",NO_IMAGE_DESCRIPTION, "SUSE"))
        
        # 查询image的description 应该为 "this is test image"
        self.assertTrue(i.set(file_id, NO_IMAGE_NAME, NO_IMAGE_TYPE, NO_IMAGE_ARCH,"ide", "this is test image", "SUSE"))
        self.assertEqual(i.query_description_by_id(i_id),"this is test image")
        
        # 修改image  参数为 file_id, "", "", "", "test"  应当成功
        self.assertTrue(i.set(file_id, NO_IMAGE_NAME, NO_IMAGE_TYPE, NO_IMAGE_ARCH, "ide", "test", "SUSE"))
        # 查询image的description 应该为 "test"
        self.assertEqual(i.query_description_by_id(i_id), "test")

        # 测试使能
        # 查询image 的使能状态  应该为 1
        self.assertEqual(i.query_state_by_id(file_id), 1)
        
        # 禁能image  参数为 file_id, 0  应当成功
        self.assertTrue(i.enable(file_id,I_DISABLE))
        # 查询image 的使能状态  应该为 0
        self.assertEqual(i.query_state_by_id(file_id), 0)

        # 测试发布
        # 查询image 的发布状态  应该为 0(默认)
        self.assertEqual(i.query_pub_by_id(file_id), 0)
        # 取消image发布  参数为 file_id, 0  应当成功
        self.assertTrue(i.publish(file_id,NOT_PUBLIC))
        # 查询image 的发布状态  应该为 0
        self.assertEqual(i.query_pub_by_id(file_id), 0)
        self.assertTrue(i.publish(file_id, IS_PUBLIC))
        self.assertEqual(i.query_pub_by_id(file_id), 1)
        
        # 测试查询
        i_id = file_id;
        # 查询用户创建的image的数量   参数为 0,100, -4,"",0   返回的数量应该是1
        self.assertEqual(i.get_query_count(START_INDEX,QUERY_COUNT, QUERY_USER_CREAT_IMAGE, NO_USER_NAME, NO_IMAGE_ID), 1)
        # 查询用户可见的image的数量   参数为 0,100, -3,"",0   返回的数量应该是1
        self.assertEqual(i.get_query_count(START_INDEX,QUERY_COUNT, QUERY_USER_CREAT_VISBLE_IMAGE, NO_USER_NAME, NO_IMAGE_ID), 1)
        # 查询发布的的image的数量   参数为 0,100, -2,"",0   返回的数量应该是1
        self.assertEqual(i.get_query_count(START_INDEX,QUERY_COUNT, QUERY_USER_VISBLE_PUBLIC_IMAGE, NO_USER_NAME, NO_IMAGE_ID), 1)
        # 查询指定用户的image的数量   参数为 0,100, 0,"admin",0   返回的数量应该是1
        self.assertEqual(i.get_query_count(START_INDEX,QUERY_COUNT, QUERY_BY_USER,"admin",NO_IMAGE_ID), 1)
        # 查询指定id的image的数量   参数为 0,100, 1,"",file_id   返回的数量应该是1
        self.assertEqual(i.get_query_count(START_INDEX,QUERY_COUNT, QUERY_BY_IMAGE_ID, NO_USER_NAME, i_id), 1)
        # 查询系统中所有image的数量   参数为 0,100, 2,"",0   返回的数量应该是2,因为已经自动注册
        self.assertEqual(i.get_query_count(START_INDEX,QUERY_COUNT, QUERY_ALL_IMAGE, NO_USER_NAME, NO_IMAGE_ID), 2)

        # ------------------普通用户权限------------------
        # 测试注册
        # 查询租户上传的file_id, 参数 test_image    返回值为文件user_file_id
        user_i = image(server,user_session)
        user_file_id = user_i.get_id_by_filename(os.path.basename(test_image))
        self.assertNotEqual(user_file_id,None)

        user_i_id = user_file_id

        # 修改image  参数为 user_file_id, "ttylinux2", "", "", ""  应当成功
        self.assertTrue(user_i.set(user_file_id, "ttylinux2", NO_IMAGE_TYPE, NO_IMAGE_ARCH,"ide",NO_IMAGE_DESCRIPTION, "SUSE"))
        # 查询image的名字 ,应该为"ttylinux2"
        self.assertEqual(user_i.query_name_by_id(user_i_id),"ttylinux2")
        # 查询image的type ,应该为"machine"
        self.assertEqual(user_i.query_type_by_id(user_i_id),"machine")
        # 修改image  参数为 user_file_id, "", "kernel", "", ""  应当成功
        self.assertTrue(user_i.set(user_file_id, NO_IMAGE_NAME, "kernel", NO_IMAGE_ARCH,"ide", NO_IMAGE_DESCRIPTION, "SUSE"))
        # 查询image的type ,应该为"kernel"
        self.assertEqual(user_i.query_type_by_id(user_i_id), "kernel")
        # 修改image  参数为 user_file_id, "", "ramdisk", "", ""  应当成功
        self.assertTrue(user_i.set(user_file_id, NO_IMAGE_NAME, "ramdisk", NO_IMAGE_ARCH, "ide",NO_IMAGE_DESCRIPTION, "SUSE"))
        # 查询image的type ,应该为"ramdisk"
        self.assertEqual(user_i.query_type_by_id(user_i_id), "ramdisk")
        # 修改image  参数为 user_file_id, "", "cdrom", "", ""  应当成功
        self.assertTrue(user_i.set(user_file_id, NO_IMAGE_NAME, "cdrom", NO_IMAGE_ARCH,"ide", NO_IMAGE_DESCRIPTION, "SUSE"))
        # 查询image的type ,应该为"cdrom"
        self.assertEqual(user_i.query_type_by_id(user_i_id), "cdrom")
        # 修改image  参数为 user_file_id, "", "datablock", "", ""  应当成功
        self.assertTrue(user_i.set(user_file_id, NO_IMAGE_NAME, "datablock", NO_IMAGE_ARCH, "ide",NO_IMAGE_DESCRIPTION, "SUSE"))
        # 查询image的type ,应该为"datablock"
        self.assertEqual(user_i.query_type_by_id(user_i_id), "datablock")
        # 修改image  参数为 user_file_id, "", "aaaa", "", ""  应当失败
        self.assertFalse(user_i.set(user_file_id, NO_IMAGE_NAME, "aaaa", NO_IMAGE_ARCH,"ide", NO_IMAGE_DESCRIPTION, "SUSE"))
        # 查询image的arch ,应该为"x86_64"
        self.assertEqual(user_i.query_arch_by_id(user_i_id), "x86_64")
        # 修改image  参数为 user_file_id, "", "", "i386", ""  应当成功
        self.assertTrue(user_i.set(user_file_id, NO_IMAGE_NAME, NO_IMAGE_TYPE, "i386", "ide",NO_IMAGE_DESCRIPTION, "SUSE"))
        # 查询image的arch ,应该为"i386"
        self.assertEqual(user_i.query_arch_by_id(user_i_id), "i386")
        # 修改image  参数为 user_file_id, "", "", "aaaa", ""  应当失败
        self.assertFalse(user_i.set(user_file_id, NO_IMAGE_NAME, NO_IMAGE_TYPE, "aaaa","ide", NO_IMAGE_DESCRIPTION, "SUSE"))
        # 查询image的description 应该为 "this is test image"
        self.assertTrue(user_i.set(user_file_id, NO_IMAGE_NAME, NO_IMAGE_TYPE, NO_IMAGE_ARCH,"ide", "this is test image", "SUSE"))
        self.assertEqual(user_i.query_description_by_id(user_i_id), "this is test image")
        # 修改image  参数为 user_file_id, "", "", "", "test"  应当成功
        self.assertTrue(user_i.set(user_file_id, NO_IMAGE_NAME, NO_IMAGE_TYPE, NO_IMAGE_ARCH, "ide","test", "SUSE"))
        # 查询image的description 应该为 "test"
        self.assertEqual(user_i.query_description_by_id(user_i_id), "test")

        # 测试使能
        # 查询image 的使能状态  应该为 1
        self.assertEqual(user_i.query_state_by_id(user_file_id), 1)
        # 禁能image  参数为 user_file_id, 0  应当失败
        self.assertFalse(user_i.enable(user_file_id,I_DISABLE))
        # 查询image 的使能状态  应该为 1
        self.assertEqual(user_i.query_state_by_id(user_file_id), 1)

        # 测试发布
        # 查询image 的发布状态  应该为 0
        self.assertEqual(user_i.query_pub_by_id(user_file_id), 0)
        # 发布image  参数为 user_file_id, 1  应当失败
        self.assertFalse(user_i.publish(file_id,NOT_PUBLIC))
        # 查询image 的发布状态  应该为 0
        self.assertEqual(user_i.query_pub_by_id(user_file_id), 0)

        # 测试查询
        user_i_id = user_file_id 
        # 查询用户创建的image的数量   参数为 0,100, -4,"",0   返回的数量应该是1
        self.assertEqual(user_i.get_query_count(START_INDEX,QUERY_COUNT, QUERY_USER_CREAT_IMAGE, NO_USER_NAME, NO_IMAGE_ID), 1)
        # 查询用户可见的image的数量   参数为 0,100, -3,"",0   返回的数量应该是2
        self.assertEqual(user_i.get_query_count(START_INDEX,QUERY_COUNT, QUERY_USER_CREAT_VISBLE_IMAGE, NO_USER_NAME, NO_IMAGE_ID), 2)
        # 查询发布的的image的数量   参数为 0,100, -2,"",0   返回的数量应该是1
        self.assertEqual(user_i.get_query_count(START_INDEX,QUERY_COUNT, QUERY_USER_VISBLE_PUBLIC_IMAGE, NO_USER_NAME, NO_IMAGE_ID), 1)
        # 查询指定用户的image的数量   参数为 0,100, 0,"user",0   返回的数量应该是1
        self.assertEqual(user_i.get_query_count(START_INDEX,QUERY_COUNT, QUERY_BY_USER, NO_USER_NAME, NO_IMAGE_ID), 1)
        # 查询指定id的image的数量   参数为 0,100, 1,"",user_file_id   返回的数量应该是1
        self.assertEqual(user_i.get_query_count(START_INDEX,QUERY_COUNT, QUERY_BY_IMAGE_ID, NO_USER_NAME, user_file_id), 1)
        # 查询系统中所有image的数量   参数为 0,100, 2,"",0   应该返回-1
        self.assertEqual(user_i.get_query_count(START_INDEX,QUERY_COUNT, QUERY_ALL_IMAGE, NO_USER_NAME, NO_IMAGE_ID), None)

        # 测试修改别人的映像
        # 使用用户session 修改image 参数为 file_id, "ttylinux2", "", "", ""  应当失败
        self.assertFalse(user_i.set(file_id, "ttylinux2", NO_IMAGE_TYPE, NO_IMAGE_ARCH, "ide", NO_IMAGE_DESCRIPTION, "SUSE"))
        # 测试使能别人的映像
        # 使用用户session 禁能image 参数为 file_id, 0  应当失败
        self.assertFalse(user_i.enable(file_id, I_DISABLE))
        # 测试发布别人的映像
        # 使用用户session 发布image 参数为 file_id, 1  应当失败
        self.assertFalse(user_i.publish(file_id, IS_PUBLIC))


        # 测试查询别人的映像
        #下面几个测试使用用户serssion
        # 查询指定用户的image的数量   参数为 0,100, 0,"admin",0   应当返回-1
        self.assertEqual(user_i.get_query_count(START_INDEX,QUERY_COUNT, QUERY_BY_USER,"admin",NO_IMAGE_ID), None)
        # 查询指定id的image的数量   参数为 0,100, 1,"",file_id   
        #管理员不进行发布查询数量为0,返回的数量应该是-1
        self.assertTrue(i.publish(file_id,NOT_PUBLIC))
        self.assertEqual(user_i.get_query_count(START_INDEX,QUERY_COUNT, QUERY_BY_IMAGE_ID, NO_USER_NAME, file_id), None)
        #管理员发布后查询数量为1
        self.assertTrue(i.publish(file_id,IS_PUBLIC))
        self.assertEqual(user_i.get_query_count(START_INDEX,QUERY_COUNT, QUERY_BY_IMAGE_ID, NO_USER_NAME, file_id), 1)
        # 查询系统中所有image的数量   参数为 0,100, 2,"",0   应该返回-1
        self.assertEqual(user_i.get_query_count(START_INDEX,QUERY_COUNT, QUERY_ALL_IMAGE, NO_USER_NAME, NO_IMAGE_ID), None)

        # ------------------管理员其他权限测试------------------
        # 测试注销别人的映像

        # 测试修改别人的映像
        # 使用管理员session 修改image 参数为 user_file_id, "ttylinux2", "", "", ""  应当成功
        self.assertTrue(i.set(user_file_id, "ttylinux2", NO_IMAGE_TYPE, NO_IMAGE_ARCH, "ide", NO_IMAGE_DESCRIPTION, "SUSE"))

        # 测试使能别人的映像
        # 使用管理员session 禁能image 参数为 user_file_id, 0  应当成功
        self.assertTrue(i.enable(user_file_id, I_DISABLE))
        # 使用管理员session查询image 的使能状态   应该为0
        self.assertEqual(i.query_state_by_id(user_file_id), 0)

        # 使用管理员session 使能image 参数为 user_file_id, 1  应当成功
        self.assertTrue(i.enable(user_file_id, I_ENABLE))
        # 使用管理员session查询image 的使能状态   应该为1
        self.assertEqual(i.query_state_by_id(user_file_id), 1)

        # 测试发布别人的映像
        # 使用管理员session 发布image 参数为 user_file_id, 1  应当成功
        self.assertTrue(i.publish(user_file_id, IS_PUBLIC))
        # 使用管理员session查询image 的发布状态   应该为1
        self.assertEqual(i.query_pub_by_id(user_file_id), IS_PUBLIC)
        # 使用管理员session 取消发布image 参数为 user_file_id, 0  应当成功
        self.assertTrue(i.publish(user_file_id, NOT_PUBLIC))
        # 使用管理员session查询image 的发布状态   应该为0
        self.assertEqual(i.query_pub_by_id(user_file_id), NOT_PUBLIC)

        # 测试查询别人的映像
        #下面几个测试使用管理员serssion
        # 查询指定用户的image的数量   参数为 0,100, 0,"user",0   应当返回1
        self.assertEqual(i.get_query_count(START_INDEX,QUERY_COUNT, QUERY_BY_USER,"user", NO_IMAGE_ID), 1)
        # 查询指定id的image的数量   参数为 0,100, 1,"",user_file_id   返回的数量应该是1
        self.assertEqual(i.get_query_count(START_INDEX,QUERY_COUNT, QUERY_BY_IMAGE_ID, NO_USER_NAME,user_file_id), 1)
        # 查询系统中所有image的数量   参数为 0,100, 2,"",0   应该返回2
        self.assertEqual(i.get_query_count(START_INDEX,QUERY_COUNT, QUERY_ALL_IMAGE, NO_USER_NAME, NO_IMAGE_ID), 2)

        # ------------------image 被使用后的测试------------------
        # 该测试段都使用管理员身份来进行测试,创建虚拟机除外,创建虚拟机的接口需要使用租户的身份来创建
        # 创建虚拟下面是虚拟机创建的参数(使用租户身份进行创建)     应该成功
        cfg = {}
        cfg["vm_name"] = test_vm_name
        cfg["project_name"] = test_project_name   
        cfg["vm_num"] = 1   
        cfg["base_info"] = {}
        cfg["base_info"]["vcpu"] = 4
        cfg["base_info"]["memory"] = long(256 * 1024 * 1024)
        cfg["base_info"]["machine"] = {"id":file_id,"position":1,"size":0L,"bus":"ide","type":"machine","target":"hda"}
        cfg["base_info"]["virt_type"] = "hvm"    
     
        user_v = vmcfg(server,user_session)
        self.assertFalse(user_v.allocate(cfg))
        self.assertTrue(i.enable(file_id, I_ENABLE))
        self.assertTrue(i.set(file_id, NO_IMAGE_NAME, "machine", NO_IMAGE_ARCH,"ide", NO_IMAGE_DESCRIPTION, "SUSE"))
        self.assertTrue(i.set(file_id, NO_IMAGE_NAME, NO_IMAGE_TYPE, "x86_64", "ide", NO_IMAGE_DESCRIPTION, "SUSE"))
        self.assertTrue(user_v.allocate(cfg))
        self.assertNotEqual(user_v.get_vm_id(test_vm_name),None)
        # 修改虚拟机的各个字段
        # 修改image 参数为 file_id, "ttylinux2", "", "", ""  应当成功
        self.assertTrue(i.set(file_id, "ttylinux2", NO_IMAGE_TYPE, NO_IMAGE_ARCH, "ide",NO_IMAGE_DESCRIPTION, "SUSE"))
        # 修改image 参数为 file_id, "", "kernel", "", ""  应当失败
        self.assertFalse(i.set(file_id, NO_IMAGE_NAME, "kernel", NO_IMAGE_ARCH, "ide",NO_IMAGE_DESCRIPTION, "SUSE"))
        # 修改image 参数为 file_id, "", "", "i386", ""  应当失败
        self.assertFalse(i.set(file_id, NO_IMAGE_NAME, NO_IMAGE_TYPE, "i386", "ide",NO_IMAGE_DESCRIPTION, "SUSE"))
        # 修改image 参数为 file_id, "", "", "", "test"  应当成功
        self.assertTrue(i.set(file_id, NO_IMAGE_NAME, NO_IMAGE_TYPE, NO_IMAGE_ARCH, "ide","test", "SUSE"))

        #611003132165 web界面上显示的image引用计数需包含被模板引用的次数 
        #查询镜像被私有模板引用次数 此时未创建过模板,应该为0
        self.assertEqual(i.query_ref_count_by_private_vt(file_id),0)
        #查询镜像被公有模板引用次数 此时未创建过模板,应该为0
        self.assertEqual(i.query_ref_count_by_public_vt(file_id),0)
        # 测试使用快速创建接口来进行创建参数如下:   应该成功 
        cfg = {}
        cfg["vt_name"] = test_vt_name
        cfg["is_public"] = bool(0)
        cfg["base_info"] = {}
        cfg["base_info"]["vcpu"] = 2
        cfg["base_info"]["memory"] = long(128 * 1024 * 1024)
        cfg["base_info"]["machine"] = {"id":i_id,"position":1,"size":0L,"bus":"scsi","type":"machine","target":"hda"}
        cfg["base_info"]["virt_type"] = "hvm"
        cfg["base_info"]["root_device"] = ""
        cfg["base_info"]["kernel_command"] = ""
        cfg["base_info"]["rawdata"] = ""
        vt = vmtemplate(server,root_session)
        self.assertTrue(vt.allocate(cfg))
        #查询镜像被私有模板引用次数 ,应该为1
        self.assertEqual(i.query_ref_count_by_private_vt(file_id),1)
        #查询镜像被公有模板引用次数 ,应该为0
        self.assertEqual(i.query_ref_count_by_public_vt(file_id),0)
        #模板发布
        self.assertTrue(vt.publish_vmt(test_vt_name))
        #查询镜像被私有模板引用次数 ,应该为0
        self.assertEqual(i.query_ref_count_by_private_vt(file_id),0)
        #查询镜像被公有模板引用次数 ,应该为1
        self.assertEqual(i.query_ref_count_by_public_vt(file_id),1)
        #取消模板发布
        self.assertTrue(vt.unpublish_vmt(test_vt_name))
        #查询镜像被私有模板引用次数 ,应该为1
        self.assertEqual(i.query_ref_count_by_private_vt(file_id),1)
        #查询镜像被公有模板引用次数 ,应该为0
        self.assertEqual(i.query_ref_count_by_public_vt(file_id),0)
        #删除模板
        self.assertTrue(vt.del_vmt(test_vt_name))
        #查询镜像被私有模板引用次数 ,应该为0
        self.assertEqual(i.query_ref_count_by_private_vt(file_id),0)
        #查询镜像被公有模板引用次数 ,应该为0
        self.assertEqual(i.query_ref_count_by_public_vt(file_id),0)
        # 使能测试
        # 禁能image 参数为 file_id, 0  ,vms_running =1 ,应当失败
        self.assertFalse(i.enable(file_id, I_DISABLE))
        # 发布测试
        # 取消发布image 参数为 file_id, 0  应当失败
        self.assertFalse(i.publish(file_id, NOT_PUBLIC))

        # 注销测试
        # 查询image 的 running_vms  参数为 0,100, 1,"",file_id    应该为1
        self.assertEqual(i.query_running_vms_by_id(file_id), 1)
        #running_vms!=0时删除管理员上传的镜像,应该失败
        self.assertFalse(i.delete(file_id))
            
        # 删除虚拟机(使用租户的身份进行虚拟机删除)
        user_v_id = user_v.get_vm_id(test_vm_name)
        self.assertNotEqual(user_v_id,None)
        self.assertTrue(user_v.action(user_v_id,"delete"))

        # 查询image 的 running_vms 参数为 0,100, 1,"",file_id     应该为0
        self.assertEqual(i.query_running_vms_by_id(file_id), 0)

        #删除管理员上传的镜像
        self.assertTrue(i.delete(file_id))

        #删除租户上传的镜像
        self.assertTrue(i.delete(user_file_id))

        #删除租户上传的镜像后根据名字查询,应该为空
        user_file_id = user_i.get_id_by_filename(os.path.basename(test_image))
        self.assertEqual(user_file_id, None)

        svr_info = user_i.query_image_ftp_svr_info()
        self.assertNotEqual(svr_info,None)

        print "success to test test_007_image.py"
        
        def suite():
                suite = unittest.TestSuite()
                suite.addTest(ImageTestCase())
                return suite
Beispiel #5
0
# 普通租户上传一个映像文件,使用的文件名和管理员一样,  应该成功
upload_image_file(server_addr,test_tenant_user,test_tenant_passwd,test_image)

# 查询拥有文件的记录数       应该为1条
max_count3=f3.get_file_max_count(-4L)
if max_count3 is None:
    ci_exit_ex(-1,line())
elif max_count3 !=1:
    ci_exit_ex(-1,line())

# 注册为image   应该成功
time.sleep(1)
fileid3 = f3.get_file_id(os.path.basename(test_image))
if fileid3 is None:
    ci_exit_ex(-1,line())
i3 = image(server,user_session)
if i3.register(fileid3, "ttylinux", "machine", "x86_64", bool(0), bool(1), "reg image for  test file mod") == False:
    ci_exit_ex(-1,line())
    
# ------------------管理员权限测试------------------
# 查询拥有的映像文件数   应该只有一条
max_count=f.get_file_max_count(-4L)
if max_count is None:
    ci_exit_ex(-1,line())
elif max_count !=1:
    ci_exit_ex(-1,line())

# 注销 映像文件
if i.unregister(fileid) != True:
    ci_exit_ex(-1)
Beispiel #6
0
    def testHost(self):
        # ------------------环境准备------------------
        # 登录tecs,获取管理员账户加密后的session
        root_session = login(server,test_root_user,test_root_passwd)
        self.assertNotEqual(root_session,None,"failed to get encrypted root session!")

        #系统运行状态查询 EC:611003077308 tecs提供rpc接口查询系统运行时信息
        #此处延时20s,否则hc的MU_VM_HANDLER和MU_HOST_HEARTBEAT不存在
        time.sleep(100)
        #必须是管理员账户
        sys_runtime_query = tecssystem(server,root_session)
        #查询TC状态
        self.assertEqual(int(sys_runtime_query.get_runtime_state(TYPE_CACULATE,DEFAULT_TC)),RUNTIME_STATE_NORMAL,"tc status is abnormal")
        #查询CC状态
        self.assertEqual(int(sys_runtime_query.get_runtime_state(TYPE_CACULATE,test_cluster)),RUNTIME_STATE_NORMAL,"cc status is abnormal")
        #查询HC状态
        test_cc_hc = test_cluster + "," + test_host
        hc_state = int(sys_runtime_query.get_runtime_state(TYPE_CACULATE,test_cc_hc))
        self.assertTrue(hc_state >= RUNTIME_STATE_NORMAL and hc_state <= RUNTIME_STATE_WARNNING,"hc status is abnormal")

        # 创建一个用户组使用参数为 test_group1,1 ,应该成功
        ug  = usergroup(server,root_session)
        self.assertTrue(ug.allocate("test_group1",GROUP_TYPE1))

        # 创建一个用户 参数为 user,test,test,3,test_group1  应该成功
        u  = user(server,root_session)
        self.assertTrue(u.allocate("user","test","test",ACCOUNTUSER,"test_group1"))

        # 登录租户  获取租户session 以备后面使用
        user_session = login(server,"user","test")
        self.assertNotEqual(user_session, None, "failed to get user session!")
        
        # 以管理员身份上传一个映像文件  应该成功  
        self.assertTrue(upload_image_file(server_addr,test_root_user,test_root_passwd,test_image),"failed to upload_image_file!")
        # 以租户身份上传一个映像文件  应该成功
        self.assertTrue(upload_image_file(server_addr,"user","test",test_image),"failed to upload_image_file!")
        
        # 注册集群
        root_cluster_manager_method = clustermanager(server,root_session) 

        self.assertTrue(root_cluster_manager_method.query(START_INDEX,QUERY_COUNT,SYN_MODE))

        # 等待 20S 等待资源上报
        #time.sleep(20)  

        # 创建工程
        user_project = project(server,user_session)
        self.assertTrue(user_project.allocate(test_project_name,"test project description"))
            
        root_project = project(server,root_session)
        self.assertTrue(root_project.allocate(test_project_name,"test project description"))
            
        # 设置tcu 8 
        root_host_method = host(server,root_session)
        cpu_id = root_host_method.get_cpu_id(test_cluster,test_host)    
        self.assertNotEqual(cpu_id, None)
        print "cpu id of host %s = %d" % (test_host,cpu_id)    

        root_tcu_method = tcu(server,root_session)
        self.assertTrue(root_tcu_method.set(test_cluster,cpu_id,TCU_NUM8,"test cpu description"))

        self.assertTrue(root_tcu_method.query(START_INDEX,QUERY_COUNT,test_cluster,"",cpu_id))

        # 注册image
        # 根据文件名获取刚刚上传的映像文件在tecs中的id
        i = image(server,root_session)
        image_id = i.get_id_by_filename(os.path.basename(test_image))
        self.assertNotEqual(image_id, None,"failed to get image id!")
          
        # ------------------管理员自身权限测试------------------
        # 测试注册
        # 注册主机     参数为 test_cluster,test_host,False,"test"  应该成功
        h = host(server,root_session)
        # 等待20S
        #time.sleep(20)
        # 查询主机的运行状态  参数为 0,100,test_cluster,test_host   应该为 3
        #刘毅cc整改时更改ON_LINE为2
        self.assertEqual(h.query_run_state(test_cluster,test_host), ON_LINE)
  
        # 测试使能
        # 使能主机 参数为  test_cluster,test_host  应该成功
        self.assertTrue(h.enable(test_cluster,test_host))

        # 查询主机的使能状态 参数为 0,100,test_cluster,test_host  应该为 0
        self.assertEqual(h.query_enable_state(test_cluster,test_host), HOST_DISABLE)
        # 测试禁能
        # 禁能主机 参数为  test_cluster,test_host,1  应该成功
        self.assertTrue(h.disable(test_cluster,test_host,HOST_ENABLE))
        # 查询主机的使能状态 参数为 0,100,test_cluster,test_host  应该为 1
        self.assertEqual(h.query_enable_state(test_cluster,test_host), HOST_ENABLE)

        #添加EC611002999057 修改host属性改用set接口
        self.assertTrue(h.set(test_cluster,test_host,"test"))

        #重复注册  应该成功
        self.assertTrue(h.set(test_cluster,test_host,"test"))

        # 注册主机  参数为 test_cluster,"","test"  应该失败(主机名为空)
        self.assertFalse(h.set(test_cluster,"","test"))
        # 注册主机  参数为 test_cluster,"no_exist","test"  应该失败(主机不存在)
        self.assertFalse(h.set(test_cluster,"no_exist","test"))  

        # 遗忘主机 参数为 test_cluster,test_host   应该失败
        self.assertTrue(h.forget(test_cluster,test_host))
        # 下面两条测试暂时不实现,因为要考虑到第3方HC的加入,现阶段只测试3合一的情况
        # 测试重启
        # 测试关机

        # ------------------租户自身权限测试------------------    
        user_h = host(server,user_session)

        # 测试使能
        # 使能主机 参数为  test_cluster,test_host  应该失败
        self.assertFalse(user_h.enable(test_cluster,test_host))
        
        # 测试禁能
        # 禁能主机 参数为  test_cluster,test_host,1  应该失败
        self.assertFalse(user_h.disable(test_cluster,test_host,HOST_ENABLE)) 

        # 测试遗忘
        # 遗忘主机 参数为 test_cluster,test_host   应该失败
        self.assertFalse(user_h.forget(test_cluster,test_host))
        # ------------------管理员其他权限测试------------------
        # 无


        # ------------------和虚拟机相关测试------------------
        time.sleep(20)
        
        # 以租户身份部署一个虚拟机,具体参数参考image 模块
        cfg_base = {}
        cfg_base["vcpu"] = 1
        cfg_base["tcu"] = 1
        cfg_base["memory"] = long(128 * 1024 * 1024)
        cfg_base["cluster"] = ""
        cfg_base["host"] = ""
        cfg_base["vm_wdtime"] = 0
        cfg_base["machine"] = {"id":image_id,"position":1,"size":0L,"bus":"ide","type":"machine","target":"hda"}
        cfg_base["kernel"] = {"id":-1L,"size":0L}
        cfg_base["ramdisk"] = {"id":-1L,"size":0L,"bus":"scsi"}
        cfg_base["virt_type"] = "hvm"
        cfg_base["root_device"] = ""
        cfg_base["kernel_command"] = ""
        cfg_base["rawdata"] = ""
        cfg_base["context"] = {}
        cfg_base["qualifications"] = []
            
        cfg = {}
        cfg["base_info"] = cfg_base
        cfg["vm_name"] = test_vm_name
        cfg["project_name"] = test_project_name   
        cfg["vm_num"] = 1
        
        v = vmcfg(server,root_session)
        self.assertTrue(v.allocate(cfg))
        #部署虚拟机之前,打印集群资源,以便部署失败时查看信息
        cm = clustermanager(server,root_session) 
        self.assertTrue(cm.query(START_INDEX,QUERY_COUNT,SYN_MODE))
        #部署虚拟机
        self.assertTrue(v.action(v.get_vm_id(test_vm_name),"deploy"))

        # 等待2S,等待虚拟机部署完毕
        time.sleep(2)
        # 禁能主机 参数为  test_cluster,test_host  应该失败
        self.assertFalse(h.disable(test_cluster,test_host,HOST_DISABLE)) 

        # 查询主机运行的虚拟机数量  0,100,test_cluster,test_host  应该为 1
        self.assertEqual(h.query_running_vms(test_cluster,test_host), 1)
        #测试结束
        print "success to test test_009_host.py"
        
        def suite():
                suite = unittest.TestSuite()
                suite.addTest(HostTestCase())
                return suite
Beispiel #7
0
    def testProject(self):
        # ------------------环境准备------------------
        # 登录tecs,获取管理员账户加密后的session
        root_session = login(server,test_root_user,test_root_passwd)
        self.assertNotEqual(root_session,None,"failed to get encrypted root session!")

        #系统运行状态查询 EC:611003077308 tecs提供rpc接口查询系统运行时信息
        #此处延时20s,否则hc的MU_VM_HANDLER和MU_HOST_HEARTBEAT不存在
        time.sleep(100)
        #必须是管理员账户
        sys_runtime_query = tecssystem(server,root_session)
        #查询TC状态
        self.assertEqual(int(sys_runtime_query.get_runtime_state(TYPE_CACULATE,DEFAULT_TC)),RUNTIME_STATE_NORMAL,"tc status is abnormal")
        #查询CC状态
        self.assertEqual(int(sys_runtime_query.get_runtime_state(TYPE_CACULATE,test_cluster)),RUNTIME_STATE_NORMAL,"cc status is abnormal")
        #查询HC状态
        test_cc_hc = test_cluster + "," + test_host
        hc_state = int(sys_runtime_query.get_runtime_state(TYPE_CACULATE,test_cc_hc))
        self.assertTrue(hc_state >= RUNTIME_STATE_NORMAL and hc_state <= RUNTIME_STATE_WARNNING,"hc status is abnormal")

        #创建一个用户组使用参数为 test_group1,1 ,应该成功
        ug  = usergroup(server,root_session)
        self.assertTrue(ug.allocate("test_group1",GROUP_TYPE1))

        # 创建一个用户 参数为 user,test,test,3,test_group1  应该成功
        u  = user(server,root_session)
        self.assertTrue(u.allocate("user","test","test",ACCOUNTUSER,"test_group1"))

        # 登录租户  获取租户session 以备后面使用
        user_session = login(server,"user","test")
        self.assertNotEqual(user_session,None,"failed to get user session!")

        # 以管理员身份上传一个映像文件  应该成功  
        self.assertTrue(upload_image_file(server_addr,test_root_user,test_root_passwd,test_image),"failed to upload_image_file!")
        # 以租户身份上传一个映像文件  应该成功
        self.assertTrue(upload_image_file(server_addr,"user","test",test_image),"failed to upload_image_file!")
        
        # 注册集群
        root_cluster_manager_method = clustermanager(server,root_session) 

        self.assertTrue(root_cluster_manager_method.query(START_INDEX,QUERY_COUNT,SYN_MODE))

        # 注册主机
        root_host_method = host(server,root_session)
        # 等待 20S 等待资源上报
        #time.sleep(20)  

        self.assertTrue(root_host_method.query(START_INDEX,QUERY_COUNT,test_cluster,test_host))

        # 设置tcu 8 
        cpu_id = root_host_method.get_cpu_id(test_cluster,test_host)    
        self.assertNotEqual(cpu_id,None)
        print "cpu id of host %s = %d" % (test_host,cpu_id)    

        root_tcu_method = tcu(server,root_session)
        self.assertTrue(root_tcu_method.set(test_cluster,cpu_id,TCU_NUM8,"test cpu description"))

        self.assertTrue(root_tcu_method.query(START_INDEX,QUERY_COUNT,test_cluster,NO_CPU_INFO,cpu_id))

        # 注册image
        # 根据文件名获取刚刚上传的映像文件在tecs中的id
        i = image(server,root_session)
        image_id = i.get_id_by_filename(os.path.basename(test_image))
        self.assertNotEqual(image_id,None,"failed to get image id!")
           
        # ------------------管理员自身权限测试------------------
        # 使用 root_session 来进行操作  
        # 创建工程
        # 参数为 test_project_name, "testaaa"     应该成功
        p = project(server,root_session)
        self.assertTrue(p.allocate(test_project_name,"testaaa"))
        # 创建重名的工程 
        # 参数为 test_project_name, "testbbb"     应该失败
        self.assertFalse(p.allocate(test_project_name,"testbbb"))
        # 查看工程的描述
        # 参数为 0,100,0,test_project_name,""    应该为 "testaaa"
        self.assertEqual(p.query_des_by_name(test_project_name), "testaaa")
        # 修改工程描述
        # 参数为 test_project_name, "testbbb"     应该成功
        self.assertTrue(p.set(test_project_name,"testbbb"))
        # 查看修改的描述
        # 参数为 0,100,0,test_project_name,""    应该为 "testbbb"
        self.assertEqual(p.query_des_by_name(test_project_name), "testbbb")
        # 工程查询测试
        # 查询创建的工程数量
        # 参数为 0,100,-5,"",""     应该返回1
        self.assertEqual(p.query_count(START_INDEX,QUERY_COUNT,USER_CREAT_PROJECT,NO_PROJECT_NAME,NO_USER_NAME), 1)
        # 查询所有用户创建的工程数量
        # 参数为 0,100,-3,"",""     应该返回1
        self.assertEqual(p.query_count(START_INDEX,QUERY_COUNT,ALL_USER_PROJECT,NO_PROJECT_NAME,NO_USER_NAME), 1)
        # 查询工程中拥有虚拟机数量
        # 参数为 0,30,test_project_name,""  应该返回0
        self.assertEqual(p.query_vm_cout_by_project(VM_START_INDEX,VM_QUERY_COUNT,test_project_name,NO_USER_NAME), None)
        # 工程删除测试
        # 参数为 test_project_name,""  应该返回成功
        self.assertTrue(p.delete(test_project_name,NO_USER_NAME))

        # ------------------租户自身权限测试------------------    
        # 使用 user_session 来进行操作 
        # 创建工程
        # 参数为 test_project_name, "testaaa"     应该成功
        user_p = project(server,user_session)
        self.assertTrue(user_p.allocate(test_project_name,"testaaa"))
        # 创建重名的工程 
        # 参数为 test_project_name, "testbbb"     应该失败
        self.assertFalse(user_p.allocate(test_project_name,"testbbb"))
        # 查看工程的描述
        # 参数为 0,100,0,test_project_name,""    应该为 "testaaa"
        self.assertEqual(user_p.query_des_by_name(test_project_name), "testaaa")
        # 修改工程描述
        # 参数为 test_project_name, "testbbb"     应该成功
        self.assertTrue(user_p.set(test_project_name,"testbbb" ))
        # 查看修改的描述
        # 参数为 0,100,0,test_project_name,""    应该为 "testbbb"
        self.assertEqual(user_p.query_des_by_name(test_project_name), "testbbb")
        # 工程查询测试
        # 查询创建的工程数量
        # 参数为 0,100,-5,"",""     应该返回1
        self.assertEqual(user_p.query_count(START_INDEX,QUERY_COUNT,USER_CREAT_PROJECT,NO_PROJECT_NAME,NO_USER_NAME), 1)
        # 查询所有用户创建的工程数量
        # 参数为 0,100,-3,"",""     应该返回 -1
        self.assertEqual(user_p.query_count(START_INDEX,QUERY_COUNT,ALL_USER_PROJECT,NO_PROJECT_NAME,NO_USER_NAME), None)
        # 查询工程中拥有虚拟机数量
        # 参数为 0,30,test_project_name,""  应该返回0
        self.assertEqual(user_p.query_vm_cout_by_project(VM_START_INDEX,VM_QUERY_COUNT,test_project_name,NO_USER_NAME), None)
        # 工程删除测试
        # 参数为 test_project_name,""  应该返回成功
        self.assertTrue(user_p.delete(test_project_name,NO_USER_NAME))
        # 参数为 test_project_name,"admin"  应该返回失败
        self.assertFalse(user_p.delete(test_project_name,"admin"))


        # ------------------管理员其他权限测试------------------
        # 构建该测试段使用的环境
        # 使用user_session 创建一个工程
        # 参数为 test_project_name, "testaaa"     应该成功
        user_p = project(server,user_session)
        self.assertTrue(user_p.allocate(test_project_name,"testaaa"))

        # 查询租户创建的工程
        # 查询用户的工程数量
        # 参数为 0,100,-3,"",""   所有用户的  应该返回 1
        self.assertEqual(p.query_count(START_INDEX,QUERY_COUNT,ALL_USER_PROJECT,NO_PROJECT_NAME,NO_USER_NAME), 1)
        # 参数为 0,100,0, “” ,"user" ,指定用户的 应返回 None
        self.assertEqual(p.query_count(START_INDEX,QUERY_COUNT,APPOINTED_USER_PROJECT,NO_PROJECT_NAME,"user"), 1)
        # 参数为 0,100,-5,"",""   当前用户的  应该返回 0
        self.assertEqual(p.query_count(START_INDEX,QUERY_COUNT,USER_CREAT_PROJECT,test_project_name, NO_USER_NAME), 0)
		# 参数为 0,100,-5,"",""   当前用户空间指定project  应该返回 None
        self.assertEqual(p.query_count(START_INDEX,QUERY_COUNT,QUERY_BY_PROJECT_NAME,test_project_name, NO_USER_NAME), None)
        # 删除租户创建的工程
        # 参数为 test_project_name,"user"  应该返回成功
        self.assertTrue(p.delete(test_project_name,"user"))

        # ------------------和虚拟机相关测试------------------
        # 管理员身份进行测试
        # 创建一个虚拟机
        cfg = {}
        cfg_base = {}
        cfg_base["vcpu"] = 2
        cfg_base["tcu"] = 1
        cfg_base["memory"] = long(128 * 1024 * 1024)
        cfg_base["cluster"] = ""
        cfg_base["host"] = ""
        cfg_base["vm_wdtime"] = 0
        cfg_base["machine"] = {"id":image_id,"position":1,"size":0L,"bus":"ide","type":"machine","target":"hda"}
        cfg_base["kernel"] = {"id":-1L,"size":0L}
        cfg_base["ramdisk"] = {"id":-1L,"size":0L,"bus":"scsi"}
        cfg_base["virt_type"] = "hvm"
        cfg_base["root_device"] = ""
        cfg_base["kernel_command"] = ""
        cfg_base["rawdata"] = ""
        cfg_base["context"] = {}
        cfg["base_info"] = cfg_base
        cfg["vm_name"] = test_vm_name
        cfg["project_name"] = test_project_name
        cfg["vm_num"] = 1

        self.assertTrue( p.allocate(test_project_name,"testaaa"))

        v = vmcfg(server,root_session)
        self.assertTrue(v.allocate(cfg) )
        # 删除拥有虚拟机的工程
        # 参数为 test_project_name,""  应该返回失败
        self.assertFalse(p.delete(test_project_name,""))
        # 修改工程名称
        # 参数为 test_project_name, "testbbb"     应该成功
        self.assertTrue(p.set(test_project_name, "testbbb"))
        # 查询工程下面拥有的虚拟机信息
        # 调用工程中查询虚拟机的接口,查询虚拟机名
        # 参数为 0,30,test_project_name,""  应该返回 None
		# 暂时先注掉  chenww 2012/12/12
        self.assertEqual(p.query_vm_name_by_project(VM_START_INDEX,VM_QUERY_COUNT,test_project_name,NO_USER_NAME), None)
		
	
        # 部署虚拟机 应当成功
		#查询虚拟机ID
        vm_id = v.get_vm_id(test_vm_name)
        self.assertTrue(v.action(vm_id,"deploy"))

        # 查询状态    应该是2(可采用5S查询一次,一共查询10次,如果10次都查询失败,则退出)
        count = 0
        vm_state=U_STATE_UNKNOWN   
        while (v.get_vm_state(vm_id) != U_STATE_RUNNING and v.get_vm_state(vm_id)!= None):
            time.sleep(10)
            count = count + 1
            self.assertTrue(count<17)    


        # 再创建一个虚拟机
        cfg = {}
        cfg_base = {}
        cfg_base["vcpu"] = 2
        cfg_base["tcu"] = 1
        cfg_base["memory"] = long(128 * 1024 * 1024)
        cfg_base["cluster"] = ""
        cfg_base["host"] = ""
        cfg_base["vm_wdtime"] = 0
        cfg_base["machine"] = {"id":image_id,"position":1,"size":0L,"bus":"ide","type":"machine","target":"hda"}
        cfg_base["kernel"] = {"id":-1L,"size":0L}
        cfg_base["ramdisk"] = {"id":-1L,"size":0L,"bus":"scsi"}
        cfg_base["virt_type"] = "hvm"
        cfg_base["hypervisor"] = "xen"
        cfg_base["root_device"] = ""
        cfg_base["kernel_command"] = ""
        cfg_base["rawdata"] = ""
        cfg_base["context"] = {}
        cfg["base_info"] = cfg_base
        cfg["vm_name"] = test_vm_name1
        cfg["project_name"] = test_project_name
        cfg["vm_num"] = 1

        vm = vmcfg(server,root_session)
        self.assertTrue(vm.allocate(cfg) )	

        # 部署虚拟机 应当成功
		#查询虚拟机ID
        vm_id1 = vm.get_vm_id(test_vm_name1)
        self.assertTrue(vm.action(vm_id1,"deploy"))

        # 查询状态    应该是2(可采用5S查询一次,一共查询10次,如果10次都查询失败,则退出)
        count = 0
        vm_state=U_STATE_UNKNOWN   
        while (vm.get_vm_state(vm_id1) != U_STATE_RUNNING and vm.get_vm_state(vm_id1)!= None):
            time.sleep(10)
            count = count + 1
            self.assertTrue(count<17)    

            
        # 查询工程下的静态数据
        # 参数为 0,100,-3,"",""   所有用户的  应该返回 1
        self.assertEqual(p.statistics_static_data(START_INDEX,QUERY_COUNT,ALL_USER_PROJECT,NO_PROJECT_NAME,NO_USER_NAME), True)
        # 参数为 0,100,-4, “” ,"user" ,指定用户的 应返回 None
        self.assertEqual(p.statistics_static_data(START_INDEX,QUERY_COUNT,APPOINTED_USER_PROJECT,NO_PROJECT_NAME,"admin"), True)
        # 参数为 0,100,-5,"",""   当前用户的  应该返回 0
        self.assertEqual(p.statistics_static_data(START_INDEX,QUERY_COUNT,USER_CREAT_PROJECT,test_project_name, NO_USER_NAME), True)
		# 参数为 0,100,0,"",""   当前用户空间指定project  应该返回 None
        self.assertEqual(p.statistics_static_data(START_INDEX,QUERY_COUNT,QUERY_BY_PROJECT_NAME,test_project_name, NO_USER_NAME), True)

	
        # 删除虚拟机
        v_id = v.get_vm_id(test_vm_name)
        v.action(v_id,"cancel")
        while (v.get_vm_state(v_id)!=U_STATE_CONFIGURATION and v.get_vm_state(v_id)!= None):
                    time.sleep(10)
                    count = count + 1
                    self.assertTrue(count<17)
                    
        self.assertTrue(v.action(v_id,"delete") )
        
        vm.action(vm_id1,"cancel")
        while (vm.get_vm_state(vm_id1)!=U_STATE_CONFIGURATION and vm.get_vm_state(vm_id1)!= None):
                    time.sleep(10)
                    count = count + 1
                    self.assertTrue(count<17)        
        self.assertTrue(vm.action(vm_id1,"delete") )        
        # 删除工程
        # 参数为 test_project_name,""  应该返回成功
        self.assertTrue(p.delete(test_project_name,NO_USER_NAME))

        #测试结束
        print "success to test test_008_project.py"
        
        def suite():
                suite = unittest.TestSuite()
                suite.addTest(ProjectTestCase())
                return suite
Beispiel #8
0
    def testSmoking(self):  
        # ------------------环境准备------------------
        # 登录tecs,获取管理员账户加密后的session
        root_session = login(server,test_root_user,test_root_passwd)
        self.assertNotEqual(root_session,None,"failed to get encrypted root session!")

        #系统运行状态查询 EC:611003077308 tecs提供rpc接口查询系统运行时信息
        #此处延时20s,否则hc的MU_VM_HANDLER和MU_HOST_HEARTBEAT不存在
        time.sleep(100)
        #必须是管理员账户
        sys_runtime_query = tecssystem(server,root_session)
        #查询TC状态
        self.assertEqual(int(sys_runtime_query.get_runtime_state(TYPE_CACULATE,DEFAULT_TC)),RUNTIME_STATE_NORMAL,"tc status is abnormal")
        #查询CC状态
        self.assertEqual(int(sys_runtime_query.get_runtime_state(TYPE_CACULATE,test_cluster)),RUNTIME_STATE_NORMAL,"cc status is abnormal")
        #查询HC状态
        test_cc_hc = test_cluster + "," + test_host
        hc_state = int(sys_runtime_query.get_runtime_state(TYPE_CACULATE,test_cc_hc))
        self.assertTrue(hc_state >= RUNTIME_STATE_NORMAL and hc_state <= RUNTIME_STATE_WARNNING,"hc status is abnormal")

        # 注册cc到tc
        print "=============================================="
        cm = clustermanager(server,root_session) 

        #TODO 需要增加循环等待
        count=0
        while (cm.get_cluster_max_count() == 0):
            time.sleep(1)
            count = count + 1 
            self.assertTrue(count < 19)         
        print "get_cluster_max_count count= %d "% count  
        
        #查询集群列表
        self.assertTrue(cm.query(START_INDEX,QUERY_COUNT,ASYN_MODE))

        # 注册hc到cc
        print "=============================================="
        h = host(server,root_session)

        #TODO 需要增加循环等待    
        self.assertTrue(h.query(START_INDEX,QUERY_COUNT,test_cluster,test_host))

        # 设置tcu 
        print "=============================================="
        # 获取刚刚注册的主机的cpu id   
        cpu_id = h.get_cpu_id(test_cluster,test_host)    
        self.assertNotEqual(cpu_id,None)        
        print "cpu id of host %s = %d" % (test_host,cpu_id)    

        s = tcu(server,root_session)
        self.assertTrue(s.set(test_cluster,cpu_id,TCU_NUM2,"test cpu description"))
        self.assertTrue(s.query(START_INDEX,QUERY_COUNT,test_cluster,"",cpu_id))  

        # 创建一个类型为1的用户组,用于容纳普通租户的账号 
        print "=============================================="
        ug = usergroup(server,root_session)
        self.assertTrue(ug.allocate(test_tenant_usergroup,GROUP_TYPE1))
            
        # 创建一个普通账号用于后续模拟来自租户的操作 
        u = user(server,root_session)
        self.assertTrue(u.allocate(test_tenant_user,test_tenant_passwd,test_tenant_passwd,ACCOUNTUSER,test_tenant_usergroup))
            
        # 使用普通租户账户登录tecs,获取该账户加密后的session
        tenant_session = login(server,test_tenant_user,test_tenant_passwd)
        self.assertNotEqual(tenant_session,None,"failed to get encrypted tenant session!")    
        # 使用ftp客户端上传一个虚拟机machine映像
        ftp = FTP()
        try:
            ftp.connect(server_addr,21)
            ftp.login(test_tenant_user,test_tenant_passwd)
        except:
            ci_exit_ex(-1,line(),"ftp login failed!")

        print ftp.getwelcome()
        try:
            cmd='%s %s' % ("stor",os.path.basename(test_image))
            ftp.storbinary(cmd,open(test_image,'rb'),1024)
        except:
            ci_exit_ex(-1,line(),"ftp upload failed!")

        # 根据文件名获取刚刚上传的映像文件在tecs中的id
        time.sleep(1)
        i = image(server,tenant_session)
        image_id = i.get_id_by_filename(os.path.basename(test_image))
        self.assertNotEqual(image_id,None,"failed to get image id!")
        # 设置一个网络平面

        # 查询网络平面名称  不需要和设置的一样,有可能是下面上报的

        # 配置DHCP

        # 创建工程
        p = project(server,tenant_session)
        self.assertTrue(p.allocate(test_project_name,"test project description"))

        # 创建虚拟机
        cfg = {}
        cfg_base = {}
        cfg_base["vcpu"] = 2
        cfg_base["tcu"] = 1
        cfg_base["memory"] = long(128 * 1024 * 1024)
        cfg_base["cluster"] = ""
        cfg_base["host"] = ""
        cfg_base["vm_wdtime"] = 0
        cfg_base["machine"] = {"id":image_id,"position":1,"size":0L,"bus":"ide","type":"machine","target":"hda"}
        cfg_base["kernel"] = {"id":-1L,"size":0L}
        cfg_base["ramdisk"] = {"id":-1L,"size":0L,"bus":"scsi"}
        cfg_base["virt_type"] = "hvm"
        cfg_base["root_device"] = ""
        cfg_base["kernel_command"] = ""
        cfg_base["rawdata"] = ""
        cfg_base["context"] = {}
        cfg["base_info"] = cfg_base
        cfg["vm_name"] = test_vm_name
        cfg["project_name"] = test_project_name
        cfg["vm_num"] = 1
        v = vmcfg(server,tenant_session)
        self.assertTrue(v.allocate(cfg))

        # 根据名称获取刚刚创建的虚拟机的id    
        vm_id = v.get_vm_id(test_vm_name)
        self.assertNotEqual(vm_id,None,"failed to get vm id!")
        # 获取虚拟机状态
        vmstate = v.get_vm_state(vm_id)
        self.assertNotEqual(vmstate,None,"failed to get vm state!")            
        #增加一个磁盘
        disk1 = {"id":-1L,"size":long(512 * 1024 * 1024),"bus":"ide","type":"disk","target":"hdb","position":1,"fstype":"ext3"}
        disks = [disk1]
        self.assertTrue(v.set_disk(vm_id,disks))
                
        #增加一个网卡
        #nic1={"pci_order":0,"plane":"","vlan":0,"dhcp":bool(1),"ip":"10.43.180.250","netmask":"255.255.254.0","gateway":"10.43.180.1","mac":""}
        #nics = [nic1]
        #if v.set_nic(vm_id,nics) != True:
        #    ci_exit_ex(-1,line())
         
        #等待tc上集群资源信息到位 
        count = 0   
        while (cm.query(START_INDEX,QUERY_COUNT,SYN_MODE) != True):
            time.sleep(3)
            count = count + 1
            print "cluster query count = %d " %count

        print "waiting for hc power on ..."    
        time.sleep(180)   
         
        # 部署虚拟机
        self.assertTrue(v.action(vm_id,"deploy"))
            
        # 获取虚拟机状态   应该是部署成功态,状态6为位置状态
        count = 0
        vm_state = U_STATE_UNKNOWN   
        while (v.get_vm_state(vm_id) != U_STATE_RUNNING and v.get_vm_state(vm_id)!= None):
            time.sleep(10)
            count = count + 1
            self.assertTrue(count < 17)
  
        # 重启虚拟机
        self.assertTrue(v.action(vm_id,"reboot"))

        # 获取虚拟机状态,应该为2    
        count = 0
        vm_state = U_STATE_UNKNOWN  
        while (v.get_vm_state(vm_id) != U_STATE_RUNNING and v.get_vm_state(vm_id)!= None):
            time.sleep(10)
            count = count + 1
            self.assertTrue(count < 17)

        # 强制重启虚拟机
        self.assertTrue(v.action(vm_id,"reset"))
            
        # 获取虚拟机状态,应该为2    
        count = 0
        vm_state = U_STATE_UNKNOWN   
        while (v.get_vm_state(vm_id) != U_STATE_RUNNING and v.get_vm_state(vm_id)!= None):
            time.sleep(10)
            count = count + 1
            self.assertTrue(count < 17)      
                
        # 取消虚拟机
        self.assertTrue(v.action(vm_id,"cancel"))    
        #取消需要3分钟,这里延时200秒
        print "wait 200s" 
        time.sleep(200)
        # 获取虚拟机状态,应该为0 
        count = 0
        vm_state = U_STATE_UNKNOWN   
        while (v.get_vm_state(vm_id) != U_STATE_CONFIGURATION and v.get_vm_state(vm_id)!= None):
            time.sleep(10)
            count = count + 1
            self.assertTrue(count < 17) 
                
        #再次部署虚拟机
        self.assertTrue(v.action(vm_id,"deploy"))
        # 获取虚拟机状态,应该为2
        count = 0
        vm_state = U_STATE_UNKNOWN   
        while (v.get_vm_state(vm_id) != U_STATE_RUNNING and v.get_vm_state(vm_id)!= None):
            time.sleep(10)
            count = count + 1
            self.assertTrue(count < 17)       
            
        # 检测磁盘是否存在

        # 检测网络是否通

        # cancle虚拟机  应该成功

        #测试结束
        print "success to test test_001.py"
        
        def suite():
                suite = unittest.TestSuite()
                suite.addTest(SmokingTestCase())
                return suite
Beispiel #9
0
    def testVmt(self):
        # ------------------环境准备------------------
        # 登录tecs,获取管理员账户加密后的session
        root_session = login(server,test_root_user,test_root_passwd)
        self.assertNotEqual(root_session,None,"failed to get encrypted root session!")

        #系统运行状态查询 EC:611003077308 tecs提供rpc接口查询系统运行时信息
        #此处延时20s,否则hc的MU_VM_HANDLER和MU_HOST_HEARTBEAT不存在
        time.sleep(100)
        #必须是管理员账户
        sys_runtime_query = tecssystem(server,root_session)
        #查询TC状态
        self.assertEqual(int(sys_runtime_query.get_runtime_state(TYPE_CACULATE,DEFAULT_TC)),RUNTIME_STATE_NORMAL,"tc status is abnormal")
        #查询CC状态
        self.assertEqual(int(sys_runtime_query.get_runtime_state(TYPE_CACULATE,test_cluster)),RUNTIME_STATE_NORMAL,"cc status is abnormal")
        #查询HC状态
        test_cc_hc = test_cluster + "," + test_host
        hc_state = int(sys_runtime_query.get_runtime_state(TYPE_CACULATE,test_cc_hc))
        self.assertTrue(hc_state >= RUNTIME_STATE_NORMAL and hc_state <= RUNTIME_STATE_WARNNING,"hc status is abnormal")

        # 创建一个用户组使用参数为 test_group1,1 ,应该成功
        ug  = usergroup(server,root_session)
        self.assertTrue(ug.allocate("test_group1",GROUP_TYPE1))

        # 创建一个用户 参数为 user,test,test,3,test_group1  应该成功
        u  = user(server,root_session)
        self.assertTrue(u.allocate("user","test","test",ACCOUNTUSER,"test_group1"))

        # 登录租户  获取租户session 以备后面使用
        user_session = login(server,"user","test")
        self.assertNotEqual(user_session, None,"failed to get user session!")
        
        # 以管理员身份上传一个映像文件  应该成功        
        self.assertTrue(upload_image_file(server_addr,test_root_user,test_root_passwd,test_image),"failed to upload_image_file!")
        # 以租户身份上传一个映像文件  应该成功
        self.assertTrue(upload_image_file(server_addr,"user","test",test_image),"failed to upload_image_file!")
      
      
        # 注册集群
        root_cluster_manager_method = clustermanager(server,root_session) 

        self.assertTrue(root_cluster_manager_method.query(START_INDEX,QUERY_COUNT,SYN_MODE))

        # 注册主机
        root_host_method = host(server,root_session)
        # 等待 20S 等待资源上报
        #time.sleep(20) 

        self.assertTrue(root_host_method.query(START_INDEX,QUERY_COUNT,test_cluster,test_host))


        # 设置tcu 8 
        cpu_id = root_host_method.get_cpu_id(test_cluster,test_host)    
        self.assertNotEqual(cpu_id, None)
        print "cpu id of host %s = %d" % (test_host,cpu_id)    

        root_tcu_method = tcu(server,root_session)
        self.assertTrue(root_tcu_method.set(test_cluster,cpu_id,TCU_NUM8,"test cpu description"))
        self.assertTrue(root_tcu_method.query(START_INDEX,QUERY_COUNT,test_cluster,NO_CPU_INFO,cpu_id))

        # 注册image
        # 根据文件名获取刚刚上传的映像文件在tecs中的id
        i = image(server,root_session)
        image_id = i.get_id_by_filename(os.path.basename(test_image))
        self.assertNotEqual(image_id, None, "failed to get image id!")
        
        # 创建工程
        user_project = project(server,user_session)
        self.assertTrue(user_project.allocate(test_project_name,"test project description"))
            
        root_project = project(server,root_session)
        self.assertTrue(root_project.allocate(test_project_name,"test project description"))
        
        # ------------------管理员自身权限测试------------------
        # 创建模板测试
        # 测试使用快速创建接口来进行创建参数如下:   应该成功
        cfg = {}
        cfg["vt_name"] = test_vt_name
        cfg["is_public"] = bool(1)
        cfg["base_info"] = {}
        cfg["base_info"]["vcpu"] = 2
        cfg["base_info"]["memory"] = long(128 * 1024 * 1024)
        cfg["base_info"]["machine"] = {"id":image_id,"position":1,"size":0L,"bus":"ide","type":"machine","target":"hda"}
        cfg["base_info"]["virt_type"] = "hvm"
        cfg["base_info"]["root_device"] = ""
        cfg["base_info"]["kernel_command"] = ""
        cfg["base_info"]["rawdata"] = ""
        #cfg["base_info"]["disks"] = [{"id":-1L,"size":long(256 * 1024 * 1024),"bus":"scsi","type":"disk","target":"sdb","position":1,"fstype":"ext2"}]

        vt = vmtemplate(server,root_session)
        self.assertFalse(vt.allocate(cfg))
        # 发布image
        #Vmtemplate cannot public, for Image( -1 ) not public
        self.assertTrue(i.publish(image_id,IS_PUBLIC))
           
        # 创件模板:   应该成功 
        self.assertTrue(vt.allocate(cfg))
        #EC611002997307 创建模板时,如果名称冲突,报的是参数错误,不直观
        #创建相同名称的模板,返回错误参数
        self.assertFalse(vt.allocate(cfg))
        # 删除虚拟机模板 参数为 test_vt_name   应当成功
        self.assertTrue(vt.del_vmt(test_vt_name))
        # 测试使用快速创建接口来进行创建参数如下:   应该成功 
        cfg = {}
        cfg["vt_name"] = test_vt_name
        cfg["is_public"] = bool(1)
        cfg["base_info"] = {}
        cfg["base_info"]["vcpu"] = 2
        cfg["base_info"]["memory"] = long(128 * 1024 * 1024)
        cfg["base_info"]["machine"] = {"id":image_id,"position":1,"size":0L,"bus":"scsi","type":"machine","target":"hda"}
        cfg["base_info"]["virt_type"] = "hvm"
        cfg["base_info"]["root_device"] = ""
        cfg["base_info"]["kernel_command"] = ""
        cfg["base_info"]["rawdata"] = ""
        self.assertTrue(vt.allocate(cfg))
        # 删除虚拟机模板 参数为 test_vt_name   应当成功
        self.assertTrue(vt.del_vmt(test_vt_name))
        # 测试使用快速创建接口来进行创建参数如下:   应该成功 
        cfg = {}
        cfg["vt_name"] = test_vt_name
        cfg["is_public"] = bool(1)
        cfg["base_info"] = {}
        cfg["base_info"]["vcpu"] = 2
        cfg["base_info"]["memory"] = long(128 * 1024 * 1024)
        cfg["base_info"]["machine"] = {"id":image_id,"position":1,"size":0L,"bus":"scsi","type":"machine","target":"hda"}
        cfg["base_info"]["virt_type"] = "hvm"
        cfg["base_info"]["root_device"] = ""
        cfg["base_info"]["kernel_command"] = ""
        cfg["base_info"]["rawdata"] = ""
        self.assertTrue(vt.allocate(cfg))
        # 创建磁盘  参数如下    应当成功 
        user_i = image(server,user_session)
        user_image_id = user_i.get_id_by_filename(os.path.basename(test_image))
        self.assertNotEqual(user_image_id, None, "failed to get image id!")

        self.assertTrue(i.publish(user_image_id,IS_PUBLIC))
        
        cfg = {}
        cfg["vt_name"] = test_vt_name
        cfg["is_public"] = bool(1)
        cfg["base_info"] = {}
        cfg["base_info"]["vcpu"] = 4
        cfg["base_info"]["memory"] = long(256 * 1024 * 1024)
        cfg["base_info"]["machine"] = {"id":user_image_id,"position":1,"size":0L,"bus":"ide","type":"machine","target":"hda"}
        cfg["base_info"]["virt_type"] = "hvm"
        cfg["base_info"]["root_device"] = ""
        cfg["base_info"]["kernel_command"] = ""
        cfg["base_info"]["rawdata"] = ""
        cfg["base_info"]["context"] = {}
        cfg["base_info"]["qualifications"] = []
        #cfg["base_info"]["disks"] = [{"id":-1L,"size":long(256 * 1024 * 1024),"bus":"scsi","type":"disk","target":"xvdb","position":0,"fstype":"ext2"}]
        disk1 = {"id":-1L,"size":long(128 * 1024 * 1024),"bus":"ide","type":"disk","target":"hdb","position":1,"fstype":"ext3"}
        # test_vt_name 和 disks = [disk1]
        cfg["base_info"]["disks"] = [disk1]
        self.assertTrue(vt.set(cfg))
        # 创建磁盘  参数如下    应当成功
        disk2 = {"id":-1L,"size":long(128 * 1024 * 1024),"bus":"scsi","type":"disk","target":"sdb","position":1,"fstype":"ext4"}
        # test_vt_name 和 disks = [disk2]
        cfg["base_info"]["disks"] = [disk2]
        self.assertTrue(vt.set(cfg))
        # 创建磁盘  参数如下    应当成功
        disk3 = {"id":-1L,"size":long(128 * 1024 * 1024),"bus":"scsi","type":"disk","target":"sdd","position":2,"fstype":"ext4"}
        # test_vt_name 和 disks = [disk3]
        cfg["base_info"]["disks"] = [disk3]
        self.assertTrue(vt.set(cfg))
        # 创建image disk    应当成功,ramdisk暂时没有使用,不测试
        disk4 = {"id":image_id,"position":1,"size":long(128 * 1024 * 1024),"bus":"scsi","type":"datablock","target":"sde"}
        #if vt.set(cfg) != True:
        #    ci_exit_ex(-1,line())
        # 创建image disk    应当成功,ramdisk暂时没有使用,不测试
        disk5 = {"id":image_id,"position":1,"size":long(128 * 1024 * 1024),"bus":"scsi","type":"cdrom","target":"sdf"}
        #if vt.set(cfg) != True:
        #    ci_exit_ex(-1,line())
        # 创建image disk    应当失败,,ramdisk暂时没有使用,不测试
        disk6 = {"id":image_id,"position":1,"size":long(128 * 1024 * 1024),"bus":"scsi","type":"disk","target":"sdf"}
        #if vt.set(cfg) != False:
        #    ci_exit_ex(-1,line())
        # 创建磁盘  参数如下    应当失败,
        disk7 = {"id":-1L,"size":long(128 * 1024 * 1024),"bus":"scsi","type":"disk","target":"sdd","position":2,"fstype":"fat32"}
        # test_vt_name 和 disks = [disk7]
        cfg["base_info"]["disks"] = [disk7]
        self.assertFalse(vt.set(cfg))
        # 创建磁盘  参数如下    应当成功,
        disk8 = {"id":-1L,"size":long(128 * 1024 * 1024),"bus":"scsi","type":"cdrom","target":"sdd","position":2,"fstype":"ext4"}
        # test_vt_name 和 disks = [disk8]
        cfg["base_info"]["disks"] = [disk8]
        self.assertTrue(vt.set(cfg))
        # 创建磁盘  参数如下    应当成功
        disk9 = {"id":-1L,"size":long(128 * 1024 * 1024),"bus":"scsi","type":"disk","target":"sdg","position":2,"fstype":"ext2"}
        # test_vt_name 和 disks = [disk9]
        cfg["base_info"]["disks"] = [disk9]
        self.assertTrue(vt.set(cfg))
        # 创建磁盘  参数如下    应当成功
        # test_vt_name 和 disks = [disk1 disk2 disk3 disk4 disk9]
        cfg["base_info"]["disks"] = [disk1,disk2,disk3,disk9]
        self.assertTrue(vt.set(cfg))
        # 创建磁盘  参数如下    应当失败
        # test_vt_name 和 disks = [disk1 disk1]
        cfg["base_info"]["disks"] = [disk1,disk1]
        self.assertFalse(vt.set(cfg))
        # 删除虚拟机模板 参数为 test_vt_name   应当成功
        self.assertTrue(vt.del_vmt(test_vt_name))

        self.assertTrue(i.publish(user_image_id,NOT_PUBLIC))

        # 创建网口 参数如下    应当成功
        #EC611003123662 TC数据库整改 gaom 2012-07-30 增加nic_index字段用例
        cfg = {}
        cfg["vt_name"] = test_vt_name
        cfg["is_public"] = bool(1)
        cfg["base_info"] = {}
        cfg["base_info"]["vcpu"] = 4
        cfg["base_info"]["memory"] = long(256 * 1024 * 1024)
        cfg["base_info"]["machine"] = {"id":image_id,"position":1,"size":0L,"bus":"ide","type":"machine","target":"hda"}
        cfg["base_info"]["virt_type"] = "hvm"
        cfg["base_info"]["root_device"] = ""
        cfg["base_info"]["kernel_command"] = ""
        cfg["base_info"]["rawdata"] = ""
        cfg["base_info"]["context"] = {}
        cfg["base_info"]["qualifications"] = []
        nic1 = {"nic_index":0,"sriov":bool(0),"loop":bool(0),"logic_network_id":"logic_network_1"}  
        cfg["base_info"]["nics"] = [nic1]
        #创建模板,应该成功
        self.assertTrue(vt.allocate(cfg))
        nic_index = vt.query_nics_index(QUERY_BY_VT_NAME,test_vt_name,QUERY_FIRST_NIC)
        self.assertNotEqual(nic_index, 0)
        # 删除虚拟机模板 参数为 test_vt_name   应当成功
        self.assertTrue(vt.del_vmt(test_vt_name))
        #创建两个相同的nic_index网卡的模板,应该失败
        nic1 = {"nic_index":1,"sriov":bool(0),"loop":bool(0),"logic_network_id":"logic_network_1"}  
        nic2 = {"nic_index":1,"sriov":bool(0),"loop":bool(0),"logic_network_id":"logic_network_1"}  
        cfg["base_info"]["nics"] =[nic1,nic2]
        self.assertFalse(vt.allocate(cfg))
        #创建两个不同的nic_index网卡的模板,应该成功
        nic1 = {"nic_index":0,"sriov":bool(0),"loop":bool(0),"logic_network_id":"logic_network_1"}  
        nic2 = {"nic_index":2,"sriov":bool(0),"loop":bool(0),"logic_network_id":"logic_network_1"}  
        cfg["base_info"]["nics"] =[nic1,nic2]
        self.assertTrue(vt.allocate(cfg))
        #查询两个网卡的index,应该不同    
        #nic_index0 = vt.query_nics_index(QUERY_BY_VT_NAME,test_vt_name,QUERY_FIRST_NIC)
        #nic_index1 = vt.query_nics_index(QUERY_BY_VT_NAME,test_vt_name,QUERY_SECOND_NIC)
        #self.assertNotEqual(nic_index0, nic_index1)
        #删除模板 成功
        self.assertTrue(vt.del_vmt(test_vt_name))
         
        #添加EC611003050917:模板管理中创建或修改看门狗时长修改不成功,始终是0
        # 修改vm_wdtime为0    应该失败
        cfg = {}
        cfg["vt_name"] = test_vt_name
        cfg["is_public"] = bool(1)
        cfg["base_info"] = {}
        cfg["base_info"]["vcpu"] = 2
        cfg["base_info"]["memory"] = long(128 * 1024 * 1024)
        cfg["base_info"]["machine"] = {"id":image_id,"position":1,"size":0L,"bus":"ide","type":"machine","target":"hda"}
        cfg["base_info"]["virt_type"] = "hvm"
        cfg["base_info"]["root_device"] = ""
        cfg["base_info"]["kernel_command"] = ""
        cfg["base_info"]["rawdata"] = ""
        cfg["base_info"]["disks"] = [disk1]
        cfg["base_info"]["vm_wdtime"] = 0
        self.assertTrue(vt.allocate(cfg) )
        # 查询vm_wdtime:   应该为0
        self.assertEqual(vt.query_vm_wdtime(QUERY_BY_VT_NAME,test_vt_name),0)

        # 修改vm_wdtime为1    应该失败
        cfg["base_info"]["vm_wdtime"] = 1
        self.assertFalse(vt.set(cfg))

        # 修改vm_wdtime为599    应该失败
        cfg["base_info"]["vm_wdtime"] = 599
        self.assertFalse(vt.set(cfg))

        # 修改vm_wdtime为600    应该成功
        cfg["base_info"]["vm_wdtime"] = 600
        self.assertTrue(vt.set(cfg))
        # 查询vm_wdtime:   应该为600
        self.assertEqual(vt.query_vm_wdtime(QUERY_BY_VT_NAME,test_vt_name),600)

        # 修改vm_wdtime为999999    应该成功
        cfg["base_info"]["vm_wdtime"] = 999999
        self.assertTrue(vt.set(cfg))
        # 查询vm_wdtime:   应该为999999
        self.assertEqual(vt.query_vm_wdtime(QUERY_BY_VT_NAME,test_vt_name), 999999)

        # 删除虚拟机模板 参数为 test_vt_name   应当成功
        self.assertTrue(vt.del_vmt(test_vt_name))

        # 增加映像2,类型为Datablock,使能, 应当成功  
        #新建模板, 基于映像2创建Datablock类型的磁盘, 应当失败:611003248365	
        self.assertTrue(i.enable(user_image_id,I_ENABLE))
        self.assertTrue(i.publish(user_image_id,IS_PUBLIC))
        self.assertTrue(i.set(image_id, NO_IMAGE_NAME, "datablock", NO_IMAGE_ARCH, "ide", NO_IMAGE_DESCRIPTION,"Linux"))
        self.assertTrue(i.enable(image_id,I_ENABLE))
        cfg = {}
        cfg["vt_name"] = test_vt_name
        cfg["is_public"] = bool(1)
        cfg["base_info"] = {}
        cfg["base_info"]["vcpu"] = 2
        cfg["base_info"]["memory"] = long(128 * 1024 * 1024)
        cfg["base_info"]["machine"] = {"id":user_image_id,"position":1,"size":0L,"bus":"scsi","type":"machine","target":"hda"}
        cfg["base_info"]["virt_type"] = "hvm"
        cfg["base_info"]["root_device"] = ""
        cfg["base_info"]["kernel_command"] = ""
        cfg["base_info"]["rawdata"] = ""
        cfg["base_info"]["disks"] = [{"id":image_id,"position":1,"size":0L,"bus":"scsi","type":"datablock","target":"sdb"}]
Beispiel #10
0
    def testVm(self):
        # ------------------环境准备------------------
        # 登录tecs,获取管理员账户加密后的session
        root_session = login(server,test_root_user,test_root_passwd)
        self.assertNotEqual(root_session,None,"failed to get encrypted root session!")
        #系统运行状态查询 EC:611003077308 tecs提供rpc接口查询系统运行时信息
        #此处延时20s,否则hc的MU_VM_HANDLER和MU_HOST_HEARTBEAT不存在
        time.sleep(100)
        #必须是管理员账户
        sys_runtime_query = tecssystem(server,root_session)
        #查询TC状态
        self.assertEqual(int(sys_runtime_query.get_runtime_state(TYPE_CACULATE,DEFAULT_TC)),RUNTIME_STATE_NORMAL,"tc status is abnormal")
        #查询CC状态
        self.assertEqual(int(sys_runtime_query.get_runtime_state(TYPE_CACULATE,test_cluster)),RUNTIME_STATE_NORMAL,"cc status is abnormal")
        #查询HC状态
        test_cc_hc = test_cluster + "," + test_host
        hc_state = int(sys_runtime_query.get_runtime_state(TYPE_CACULATE,test_cc_hc))
        self.assertTrue(hc_state >= RUNTIME_STATE_NORMAL and hc_state <= RUNTIME_STATE_WARNNING,"hc status is abnormal")

        # 创建一个用户组使用参数为 test_group1,1 ,应该成功
        ug  = usergroup(server,root_session)
        self.assertTrue(ug.allocate("test_group1",GROUP_TYPE1))

        # 创建一个用户 参数为 user,test,test,3,test_group1  应该成功
        u  = user(server,root_session)
        self.assertTrue(u.allocate("user","test","test",ACCOUNTUSER,"test_group1"))

        # 登录租户  获取租户session 以备后面使用
        user_session = login(server,"user","test")
        self.assertNotEqual(user_session, None,"failed to get user session!")
        
        # 以管理员身份上传一个映像文件  应该成功        
        self.assertTrue(upload_image_file(server_addr,test_root_user,test_root_passwd,test_image),"failed to upload_image_file!")
        # 以租户身份上传一个映像文件  应该成功
        self.assertTrue(upload_image_file(server_addr,"user","test",test_image),"failed to upload_image_file!")
      
      
        # 注册集群
        root_cluster_manager_method = clustermanager(server,root_session) 

        self.assertTrue(root_cluster_manager_method.query(START_INDEX,QUERY_COUNT,SYN_MODE))

        # 注册主机
        root_host_method = host(server,root_session)
        # 等待 20S 等待资源上报
        #time.sleep(20) 

        self.assertTrue(root_host_method.query(START_INDEX,QUERY_COUNT,test_cluster,test_host))


        # 设置tcu 8 
        cpu_id = root_host_method.get_cpu_id(test_cluster,test_host)    
        self.assertNotEqual(cpu_id, None)
        print "cpu id of host %s = %d" % (test_host,cpu_id)    

        root_tcu_method = tcu(server,root_session)
        self.assertTrue(root_tcu_method.set(test_cluster,cpu_id,TCU_NUM8,"test cpu description"))
        self.assertTrue(root_tcu_method.query(START_INDEX,QUERY_COUNT,test_cluster,NO_CPU_INFO,cpu_id))

        # 注册image
        # 根据文件名获取刚刚上传的映像文件在tecs中的id
        i = image(server,root_session)
        image_id = i.get_id_by_filename(os.path.basename(test_image))
        self.assertNotEqual(image_id, None, "failed to get image id!")
        self.assertTrue(i.publish(image_id,IS_PUBLIC))
        # 创建工程
        user_project = project(server,user_session)
        self.assertTrue(user_project.allocate(test_project_name2,"test project description"))
            
        root_project = project(server,root_session)
        self.assertTrue(root_project.allocate(test_project_name,"test project description"))

        user_project = project(server,user_session)
        self.assertTrue(user_project.allocate(test_project_name,"test project description"))

   
        # ------------------管理员自身权限测试------------------
        # 使用虚拟机模板创建虚拟机,在虚拟机模板测试流程中已经测试过了
        # test_project_name下直接创建虚拟机vm_001
        # 使用参数如下:     应当成功
        cfg_base = {}
        cfg_base["vcpu"] = 1
        cfg_base["tcu"] = 1
        cfg_base["memory"] = long(128 * 1024 * 1024)
        cfg_base["cluster"] = ""
        cfg_base["host"] = ""
        cfg_base["vm_wdtime"] = 0
        cfg_base["machine"] = {"id":image_id,"position":1,"size":0L,"bus":"ide","type":"machine","target":"hda"}
        cfg_base["kernel"] = {"id":-1L,"size":0L}
        cfg_base["ramdisk"] = {"id":-1L,"size":0L,"bus":"scsi"}
        cfg_base["virt_type"] = "hvm"
        cfg_base["root_device"] = ""
        cfg_base["kernel_command"] = ""
        cfg_base["rawdata"] = ""
        cfg_base["context"] = {}
        cfg_base["qualifications"] = []
        cfg_base["disks"] = [{"id":-1L,"size":long(128 * 1024 * 1024),"bus":"ide","type":"disk","target":"hdb","position":1,"fstype":"ext3"}]