class Init: # 项目基本参数 BASE_INFO = choose_Yaml() V1_BASE_INFO = choose_v1yaml() # 环境变量参数 ENV = get_env() # 各模块参数文件 DOMAIN_INFO = readYaml('params/cdn/domain.yaml') CERT_INFO = readYaml('params/cdn/cert.yaml') V1_INFO = readYaml('params/cdn/v1.yaml') LOG_INFO = readYaml('params/cdn/log.yaml') CTYUN_INFO = readYaml('params/cdn/ctyun.yaml') # 证书相关参数 PUBLIC_KEY = read('/params/cdn/server365.crt') PRIVATE_KEY = read('/params/cdn/server_private365.key') PUBLIC_KEY_EXPIRE = read('/params/cdn/server_expire.crt') PRIVATE_KEY_EXPIRE = read('/params/cdn/server_private_expire.key') PUBLIC_ZHIHUA_KEY = read('/params/cdn/server_zhihua.crt') PRIVATE_KEY_ZHIHUA = read('/params/cdn/server_private_zhihua.key') # Session 部分 [客户控制台,业务控制台,工单系统 ] CONSOLE_SESSION = Session().get_session() # 业务平台跳转后的控制台cookie BS_SESSION = Session().get_bs_console_session() WO_SESSION = Session().get_iam_private_session() CTYUN_SESSION = Session().get_ctyun_session()
def write_scdn_XML(): r = readYaml('application.yaml') env = get_env() file_path = str( os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir))) # 创建根节点 a = ET.Element("environment") # h = HTMLParser. # 创建子节点,并添加属性 b = ET.SubElement(a, "parameter") b1 = ET.SubElement(a, "parameter") b2 = ET.SubElement(a, "parameter") # b.attrib = {"category":"COOKING"} # 创建子节点,并添加数据 key1 = ET.SubElement(b, "key") key1.text = "Test_Type" key1 = ET.SubElement(b, "value") key1.text = r.get('TEST_TYPE') key2 = ET.SubElement(b1, "key") key2.text = "Test_Range" key2 = ET.SubElement(b1, "value") key2.text = r.get('SCDN_ENV_RANGE') key3 = ET.SubElement(b2, "key") key3.text = "ENV" key3 = ET.SubElement(b2, "value") if env == 'PE' or env == 'pe': key3.text = "生产环境" elif env == 'ITE' or env == 'ite': key3.text = "集成测试环境" elif env == 'ATE' or env == 'ate': key3.text = "自动化测试环境" else: key3.text = "未知环境,请校验ENV参数" # 创建elementtree对象,写文件 tree = ET.ElementTree(a) xmlPath = file_path + '/report/scdn_console/xml/environment.xml' if os.path.exists(xmlPath): os.remove(xmlPath) tree.write(xmlPath, encoding='utf-8')
from bin.Yaml import get_env from locust import events, TaskSet, task, HttpLocust from gevent._semaphore import Semaphore all_locusts_spawned = Semaphore() all_locusts_spawned.acquire() def on_hatch_complete(**kwargs): all_locusts_spawned.release() events.hatch_complete += on_hatch_complete env = get_env() headers = { "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko)\ Chrome/67.0.3396.99 Safari/537.36", "Content-Type": "application/x-www-form-urlencoded", # "Connection": "close" } class TestTask(TaskSet): def on_start(self): """ on_start is called when a Locust start before any task is scheduled 所有压测的task执行之前等待登录完成 """ self.console_host = 'https://iam-test.ctcdn.cn' self.workspace_id = "10003885" self.login()