def test(): global test_obj_dict global origin_ip global test_config_des global deploy_tmpt_src global deploy_tmpt_des origin_ip = os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] test_util.test_dsc( 'Create test vm to test zstack all installation in CentOS7.') # image_name = os.environ.get('imageName_i_c7') # image_name = "zstack_iso_centos7_141" image_name = os.environ.get('imageName_i_offline') vm = test_stub.create_vlan_vm(image_name) test_obj_dict.add_vm(vm) if os.environ.get('zstackManagementIp') == None: vm.check() else: time.sleep(60) vm_inv = vm.get_vm() vm_ip = vm_inv.vmNics[0].ip 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 test_stub.execute_all_install(ssh_cmd, target_file, tmp_file) # test_stub.check_installation(ssh_cmd, tmp_file, vm_inv) test_util.test_dsc("Prepare Config Files") cmd = "cp %s %s" % (deploy_tmpt_src, deploy_tmpt_des) os.system(cmd) cmd = "sed -i \"s/templateIP/%s/g\" %s" % (vm_ip, deploy_tmpt_des) os.system(cmd) test_config_obj = test_util.TestConfig(test_config_des) test_config = test_config_obj.get_test_config() all_config = test_config_obj.get_deploy_config() deploy_config = all_config.deployerConfig cmd = "vconfig add eth0 213" rsp = test_lib.lib_execute_ssh_cmd(vm_ip, 'root', 'password', cmd, 180) cmd = "vconfig add eth0 212" rsp = test_lib.lib_execute_ssh_cmd(vm_ip, 'root', 'password', cmd, 180) os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = vm_ip deploy_operations.deploy_initial_database(deploy_config) test_util.test_dsc("Clean up") os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = origin_ip os.system('rm -f %s' % deploy_tmpt_des) os.system('rm -f %s' % tmp_file) vm.destroy() test_obj_dict.rm_vm(vm) test_util.test_pass('ZStack installation Test Success')
def restart_zstack_without_deploy_db(test_config_path): ''' This API could be called, when zstack.war is rebuilt. It will find all running nodes and deploy zstack.war to them. ''' import zstackwoodpecker.test_util as test_util test_config_obj = test_util.TestConfig(test_config_path) all_config = test_config_obj.get_deploy_config() plan = Plan(all_config) plan.restart_war_on_all_nodes()
def _lazyload_image(condition=None): def _load_image(action): increase_image_thread() try: #evt = action.run() evt = account_operations.execute_action_with_session(action, None) except: exc_info.append(sys.exc_info()) finally: decrease_image_thread() iaction = api_actions.QueryImageAction() iaction.conditions = condition ret = account_operations.execute_action_with_session(iaction, None) if len(ret) != 0: print "no need lazy" return test_config_path = os.environ.get('WOODPECKER_TEST_CONFIG_FILE') test_config_obj = test_util.TestConfig(test_config_path) #Special config in test-config.xml, such like test ping target. test_config = test_config_obj.get_test_config() #All configs in deploy.xml. all_config = test_config_obj.get_deploy_config() #Detailed zstack deployment information, including zones/cluster/hosts... deploy_config = all_config.deployerConfig for i in xmlobject.safe_list(deploy_config.images.image): image_action = api_actions.QueryImageAction() condition = gen_query_conditions('name', '=', i.name_) image_action.conditions = condition ret = account_operations.execute_action_with_session( image_action, None) if len(ret) != 0: print "image has beed added" continue session_uuid = None if i.hasattr('label_') and i.label_ == 'lazyload': for bsref in xmlobject.safe_list(i.backupStorageRef): bss = get_resource(BACKUP_STORAGE, None, name=bsref.text_) bs = deploy_operations.get_first_item_from_list( bss, 'backup storage', bsref.text_, 'image') action = api_actions.AddImageAction() action.sessionUuid = session_uuid #TODO: account uuid will be removed later. action.accountUuid = inventory.INITIAL_SYSTEM_ADMIN_UUID action.backupStorageUuids = [bs.uuid] action.bits = i.bits__ if not action.bits: action.bits = 64 action.description = i.description__ action.format = i.format_ action.mediaType = i.mediaType_ action.guestOsType = i.guestOsType__ if not action.guestOsType: action.guestOsType = 'unknown' action.platform = i.platform__ if not action.platform: action.platform = 'Linux' action.hypervisorType = i.hypervisorType__ action.name = i.name_ action.url = i.url_ action.timeout = 1800000 if i.hasattr('system_'): action.system = i.system_ if i.hasattr('systemTags_'): action.systemTags = i.systemTags_.split(',') thread = threading.Thread(target=_load_image, args=(action, )) wait_for_image_thread_queue() print 'before add image2: %s' % i.url_ thread.start() print 'add image: %s' % i.url_ print 'all images add command are executed' wait_for_thread_done(True) print 'all images have been added'