"biz_cc_id": 2, "cc_set_select_method": "text", "cc_set_select_topo": [], "cc_set_select_text": u" 蓝鲸>Tun>set\n\n", "_loop": 1, } SELECT_BY_TEXT_SUCCESS_CASE = ComponentTestCase( name="success case: select set by text(include newline/space)", inputs=SELECT_BY_TEXT_SUCCESS_INPUTS, parent_data=COMMON_PARENT, execute_assertion=ExecuteAssertion(success=True, outputs={}), schedule_assertion=None, execute_call_assertion=[ CallAssertion( func=SELECT_BY_TEXT_SUCCESS_CLIENT.cc.batch_delete_set, calls=[Call({"bk_biz_id": 2, "bk_supplier_account": 0, "delete": {"inst_ids": [5]}})], ) ], patchers=[ Patcher(target=GET_CLIENT_BY_USER, return_value=SELECT_BY_TEXT_SUCCESS_CLIENT), Patcher(target=CC_GET_CLIENT_BY_USER, return_value=SELECT_BY_TEXT_SUCCESS_CLIENT), ], ) SELECT_BY_TOPO_SUCCESS_CLIENT = MockClient( get_mainline_object_topo_return=COMMON_MAINLINE, search_biz_inst_topo_return=COMMON_TOPO, batch_delete_set_return={"result": True, "code": 0, "message": "", "data": {}}, )
"data": {} }) TRANSFER_SUCCESS_CASE = ComponentTestCase( name='transfer success case', inputs={'cc_host_ip': '1.1.1.1;2.2.2.2'}, parent_data={ 'executor': 'executor_token', 'biz_cc_id': 2, 'biz_supplier_account': 0 }, execute_assertion=ExecuteAssertion(success=True, outputs={}), schedule_assertion=None, execute_call_assertion=[ CallAssertion( func=CC_GET_HOST_ID_BY_INNERIP, calls=[Call('executor_token', 2, ['1.1.1.1', '2.2.2.2'], 0)]), CallAssertion( func=TRANSFER_SUCCESS_CLIENT.cc.transfer_host_to_resourcemodule, calls=[Call({ 'bk_biz_id': 2, 'bk_host_id': [2, 3] })]) ], # add patch patchers=[ Patcher(target=GET_CLIENT_BY_USER, return_value=TRANSFER_SUCCESS_CLIENT), Patcher(target=GET_IP_BY_REGEX, return_value=['1.1.1.1', '2.2.2.2']), Patcher(target=CC_GET_HOST_ID_BY_INNERIP, return_value={
SELECT_BY_TEXT_SUCCESS_CASE = ComponentTestCase( name="success case: select set by text(include newline/space)", inputs=SELECT_BY_TEXT_SUCCESS_INPUTS, parent_data=COMMON_PARENT, execute_assertion=ExecuteAssertion(success=True, outputs={}), schedule_assertion=None, execute_call_assertion=[ CallAssertion( func=SELECT_BY_TEXT_SUCCESS_CLIENT.cc.create_module, calls=[ Call({ "bk_biz_id": 2, "bk_set_id": 5, "data": { "bk_parent_id": 5, "bk_module_name": "1", "bk_module_type": "1", "operator": "1", "bk_bak_operator": "1", "service_category_id": 2, }, }) ], ) ], patchers=[ Patcher(target=GET_CLIENT_BY_USER, return_value=SELECT_BY_TEXT_SUCCESS_CLIENT), Patcher(target=CC_GET_CLIENT_BY_USER, return_value=SELECT_BY_TEXT_SUCCESS_CLIENT), Patcher(target=CC_FORMAT_PROP_DATA,
def PUSH_FILE_TO_IPS_FAIL_CASE(): return ComponentTestCase( name="all buz fast_push_files v1.0 call fail case", inputs=INPUT, parent_data={ "executor": "executor", "project_id": "project_id" }, execute_assertion=ExecuteAssertion( success=True, outputs={ "requests_error": "Request Error:\nfailed\n", "task_count": 4, "job_instance_id_list": [10000, 10001, 10002], "job_id_of_batch_execute": [10000, 10001, 10002], "job_inst_url": [ "job.com/api_execute/", "job.com/api_execute/", "job.com/api_execute/" ], "request_success_count": 3, "success_count": 0, "final_res": False, }, ), execute_call_assertion=[ CallAssertion( func=FAST_PUSH_FILE_REQUEST_FAILURE_CLIENT.job.fast_push_file, calls=[ Call(**CLL_INFO()), Call(**CLL_INFO()), Call(**CLL_INFO()), Call(**CLL_INFO()) ], ), ], schedule_assertion=ScheduleAssertion( success=False, outputs={ "requests_error": "Request Error:\nfailed\n", "task_count": 4, "job_instance_id_list": [10000, 10001, 10002], "job_id_of_batch_execute": [], "job_inst_url": [ "job.com/api_execute/", "job.com/api_execute/", "job.com/api_execute/" ], "request_success_count": 3, "success_count": 3, "final_res": False, "ex_data": "Request Error:\nfailed\n\n Get Result Error:\n", }, schedule_finished=True, ), patchers=[ Patcher(target=GET_CLIENT_BY_USER, return_value=FAST_PUSH_FILE_REQUEST_FAILURE_CLIENT), Patcher(target=BASE_GET_CLIENT_BY_USER, return_value=FAST_PUSH_FILE_REQUEST_FAILURE_CLIENT), Patcher(target=JOB_HANDLE_API_ERROR, return_value="failed"), Patcher(target=GET_JOB_INSTANCE_URL, return_value="job.com/api_execute/"), ], )
"biz_cc_id": 2 }, execute_assertion=ExecuteAssertion( success=False, outputs={ "data": { "result": "调用监控平台(Monitor)接口monitor.disable_shield返回失败, " 'params={"id":"1"}, error=disable shield fail' }, "status_code": 500, }, ), schedule_assertion=None, execute_call_assertion=[ CallAssertion(func=DISABLE_SHIELD_FAIL_CLIENT.disable_shield, calls=[Call(**{"id": "1"})]) ], patchers=[ Patcher(target=MONITOR_CLIENT, return_value=DISABLE_SHIELD_FAIL_CLIENT) ], ) DISABLE_SHIELD_SUCCESS_CASE = ComponentTestCase( name="disable shield success case", inputs={"bk_alarm_shield_id_input": "1"}, parent_data={ "executor": "executor", "biz_cc_id": 2 }, execute_assertion=ExecuteAssertion(success=True, outputs={
SCHEDULE_SUCCESS_OUTPUTS = {"name": "value"} # 上传文件成功异步执行失败样例 LOCAL_CONTENT_UPLOAD_SUCCESS_SCHEDULE_CALLBACK_DATA_ERROR_CASE = ComponentTestCase( name="local content upload success schedule callback data error test case", inputs=INPUTS, parent_data=PARENT_DATA, execute_assertion=ExecuteAssertion(success=True, outputs=SUCCESS_OUTPUTS), schedule_assertion=ScheduleAssertion( success=True, schedule_finished=True, outputs=dict(list(SUCCESS_OUTPUTS.items())), ), execute_call_assertion=[ CallAssertion( func=LOCAL_CONTENT_UPLOAD_SUCCESS_CLIENT.job.push_config_file, calls=[Call(KWARGS)]), ], patchers=[ Patcher( target=CC_GET_IPS_INFO_BY_STR, return_value={"ip_result": []}, ), Patcher(target=GET_CLIENT_BY_USER, return_value=LOCAL_CONTENT_UPLOAD_SUCCESS_CLIENT), Patcher(target=GET_JOB_INSTANCE_URL, return_value="instance_url_token"), Patcher(target=CC_GET_IPS_INFO_BY_STR, return_value={"ip_result": []}), ], )
"cc_module_select_method": "text", "cc_module_select_topo": [], "cc_module_select_text": " 蓝鲸>Tun>set>module\n\n", "cc_host_ip": "1.1.1.1;2.2.2.2", "cc_is_increment": "false", "_loop": 1, } SELECT_BY_TEXT_SUCCESS_CASE = ComponentTestCase( name="success case: select module by text(include newline/space)", inputs=SELECT_BY_TEXT_SUCCESS_INPUTS, parent_data=COMMON_PARENT, execute_assertion=ExecuteAssertion(success=True, outputs={}), schedule_assertion=None, execute_call_assertion=[ CallAssertion(func=CC_GET_HOST_ID_BY_INNERIP, calls=[Call("admin", 2, ["1.1.1.1", "2.2.2.2"], 0)]), CallAssertion( func=SELECT_BY_TEXT_SUCCESS_CLIENT.cc.transfer_host_module, calls=[ Call({ "bk_biz_id": 2, "bk_supplier_account": 0, "bk_host_id": [2, 3], "bk_module_id": [7], "is_increment": False, }) ], ), ], patchers=[ Patcher(target=GET_CLIENT_BY_USER,
}, execute_assertion=ExecuteAssertion( success=False, outputs={ 'ex_data': '调用蓝鲸配置平台(CC)接口cc.find_set_batch返回失败,' ' params={"bk_biz_id":1,"bk_ids":[222,111],"fields":["bk_set_name","bk_set_id"]},' ' error=find set batch fail' }, ), execute_call_assertion=[ CallAssertion( func=CC_GET_IPS_INFO_BY_STR, calls=[ Call(username="******", biz_cc_id=1, ip_str="1.1.1.1,2.2.2.2", use_cache=False) ], ), CallAssertion( func=FIND_SET_BATCH_FAIL_CLIENT.cc.find_set_batch, calls=[ Call({ "bk_biz_id": 1, "bk_ids": [222, 111], "fields": ["bk_set_name", "bk_set_id"] }) ], ), ],
schedule_assertion=None, execute_call_assertion=[ CallAssertion( func=CREATE_SHIELD_FAIL_CLIENT.add_shield, calls=[ Call( **{ "begin_time": "2020-09-28 11:18:58", "bk_biz_id": 2, "category": "scope", "cycle_config": {"begin_time": "", "end_time": "", "day_list": [], "week_list": [], "type": 1}, "description": "shield by bk_sops", "dimension_config": { "scope_type": "node", "target": [ {"bk_obj_id": "module", "bk_inst_id": 1}, {"bk_obj_id": "module", "bk_inst_id": 2}, {"bk_obj_id": "module", "bk_inst_id": 3}, {"bk_obj_id": "module", "bk_inst_id": 4}, {"bk_obj_id": "module", "bk_inst_id": 5}, ], "metric_id": ["bk_monitor.system.load.load5", "bk_monitor.system.cpu_summary.usage"], }, "end_time": "2020-09-28 11:18:58", "notice_config": {}, "shield_notice": False, } ) ], ) ], patchers=[
INPUTS = { "bk_verifier": "tester, tester1", "bk_approve_title": "this is a test", "bk_notify_title": "title", "bk_approve_content": "test content", } CREATE_APPROVE_TICKET_FAIL_CASE = ComponentTestCase( name="create approve ticket fail case", inputs=INPUTS, parent_data=COMMON_PARENT, execute_assertion=ExecuteAssertion( success=False, outputs={"ex_data": "create ticket fail"}), execute_call_assertion=[ CallAssertion( func=CREAT_TICKET_FAIL_RETURN_CLIENT.create_ticket, calls=[Call(**CREAT_TICKET_CALL)], ) ], schedule_assertion=None, patchers=[ Patcher(target=GET_CLIENT_BY_USER, return_value=CREAT_TICKET_FAIL_RETURN_CLIENT), Patcher(target=BK_HANDLE_API_ERROR, return_value="create ticket fail"), Patcher(target=GET_NODE_CALLBACK_URL, return_value="callback_url"), ], ) CREATE_APPROVE_TICKET_SUCCESS_CASE = ComponentTestCase( name="create approve ticket success case", inputs=INPUTS, parent_data=COMMON_PARENT,
inputs={ "wechat_work_chat_id": "11111111111111111111111111111111\n22222222222222222222222222222222", # noqa "message_content": "haha", "wechat_work_mentioned_members": "m1,m2", "msgtype": "text", }, parent_data={}, execute_assertion=ExecuteAssertion(success=True, outputs={}), schedule_assertion=None, execute_call_assertion=[ CallAssertion( func=SUCCESS_REQUEST_POST, calls=[ Call( url="test_url", json={ "chatid": "11111111111111111111111111111111|22222222222222222222222222222222", # noqa "msgtype": "text", "text": {"content": "haha", "mentioned_list": ["m1", "m2"]}, }, timeout=5, ) ], ) ], patchers=[ Patcher(target=ENVIRONMENT_VAIRABLES_GET, return_value="test_url"), Patcher(target=REQUESTS_POST, side_effect=SUCCESS_REQUEST_POST), ], )
def SUCCESS_CASE(): SUCCESS_RESULT = {"result": True, "data": {"job_id": 12345}} SUCCESS_ESB_CLIENT = MagicMock() SUCCESS_MANAGER = MagicMock() SUCCESS_MANAGER.push_files_to_ips = MagicMock(return_value=SUCCESS_RESULT) return ComponentTestCase( name="push_local_files success case", inputs={ "biz_cc_id": "biz_cc_id", "job_local_files": [ { "response": { "result": True, "tag": "tag_1" } }, { "response": { "result": True, "tag": "tag_2" } }, ], "job_target_ip_list": "1.1.1.1", "job_target_account": "job_target_account", "job_target_path": "job_target_path", }, parent_data={ "executor": "executor", "project_id": "project_id" }, execute_assertion=ExecuteAssertion( success=True, outputs={ "job_inst_id": SUCCESS_RESULT["data"]["job_id"], "job_inst_url": "url_token" }), schedule_assertion=ScheduleAssertion( success=True, outputs={ "job_inst_id": SUCCESS_RESULT["data"]["job_id"], "job_inst_url": "url_token" }, callback_data={ "status": 3, "job_instance_id": 12345 }, schedule_finished=True, ), execute_call_assertion=[ CallAssertion(func=GET_CLIENT_BY_USER, calls=[Call("executor")]), CallAssertion( func=CC_GET_IPS_INFO_BY_STR, calls=[ Call(username="******", biz_cc_id="biz_cc_id", ip_str="1.1.1.1", use_cache=False) ], ), CallAssertion( func=SUCCESS_MANAGER.push_files_to_ips, calls=[ Call( esb_client=SUCCESS_ESB_CLIENT, bk_biz_id="biz_cc_id", file_tags=["tag_1", "tag_2"], target_path="job_target_path", ips=[{ "ip": "1.1.1.1", "bk_cloud_id": 0 }], account="job_target_account", callback_url="callback_url", ) ], ), ], patchers=[ Patcher(target=ENVIRONMENT_VAR_GET, return_value="a_type"), Patcher(target=FACTORY_GET_MANAGER, return_value=SUCCESS_MANAGER), Patcher(target=GET_CLIENT_BY_USER, return_value=SUCCESS_ESB_CLIENT), Patcher(target=GET_NODE_CALLBACK_URL, return_value="callback_url"), Patcher(target=GET_JOB_INSTANCE_URL, return_value="url_token"), Patcher(target=CC_GET_IPS_INFO_BY_STR, return_value={ "ip_result": [{ "InnerIP": "1.1.1.1", "Source": 0 }] }), ], )
def PUSH_FILE_TO_IPS_FAIL_CASE(): PUSH_FAIL_RESULT = { "result": False, "message": "msg token", "job_api": "api token", "response": { "result": False, "message": "msg token" }, "kwargs": "kwargs token", } PUSH_FAIL_ESB_CLIENT = MagicMock() PUSH_FAIL_MANAGER = MagicMock() PUSH_FAIL_MANAGER.push_files_to_ips = MagicMock( return_value=PUSH_FAIL_RESULT) return ComponentTestCase( name="push_local_files manager call fail case", inputs={ "biz_cc_id": "biz_cc_id", "job_local_files": [ { "response": { "result": True, "tag": "tag_1" } }, { "response": { "result": True, "tag": "tag_2" } }, ], "job_target_ip_list": "1.1.1.1", "job_target_account": "job_target_account", "job_target_path": "job_target_path", }, parent_data={ "executor": "executor", "project_id": "project_id" }, execute_assertion=ExecuteAssertion( success=False, outputs={ "ex_data": '调用作业平台(JOB)接口api token返回失败, params="kwargs token", error=msg token' }), schedule_assertion=None, execute_call_assertion=[ CallAssertion(func=GET_CLIENT_BY_USER, calls=[Call("executor")]), CallAssertion( func=CC_GET_IPS_INFO_BY_STR, calls=[ Call(username="******", biz_cc_id="biz_cc_id", ip_str="1.1.1.1", use_cache=False) ], ), CallAssertion( func=PUSH_FAIL_MANAGER.push_files_to_ips, calls=[ Call( esb_client=PUSH_FAIL_ESB_CLIENT, bk_biz_id="biz_cc_id", file_tags=["tag_1", "tag_2"], target_path="job_target_path", ips=[{ "ip": "1.1.1.1", "bk_cloud_id": 0 }], account="job_target_account", callback_url="callback_url", ) ], ), ], patchers=[ Patcher(target=ENVIRONMENT_VAR_GET, return_value="a_type"), Patcher(target=FACTORY_GET_MANAGER, return_value=PUSH_FAIL_MANAGER), Patcher(target=GET_CLIENT_BY_USER, return_value=PUSH_FAIL_ESB_CLIENT), Patcher(target=CC_GET_IPS_INFO_BY_STR, return_value={ "ip_result": [{ "InnerIP": "1.1.1.1", "Source": 0 }] }), Patcher(target=GET_NODE_CALLBACK_URL, return_value="callback_url"), ], )
success=False, outputs={ 'ex_data': u'\u8c03\u7528\u4f5c\u4e1a\u5e73\u53f0(JOB)' u'\u63a5\u53e3job.execute_job\u8fd4\u56de\u5931\u8d25, ' u'params={"bk_biz_id": 1, "global_vars": [{"name": "key_1", "value": "value_1"}, ' u'{"name": "key_2", "value": "value_2"}, {"name": "key_3", "ip_list": ' u'[{"ip": "1.1.1.1", "bk_cloud_id": 1}, {"ip": "2.2.2.2", "bk_cloud_id": 1}]}], ' u'"bk_job_id": 12345, "bk_callback_url": "url_token"}, error=message token' }), schedule_assertion=None, execute_call_assertion=[ CallAssertion(func=CC_GET_IPS_INFO_BY_STR, calls=[ Call(username='******', biz_cc_id=1, ip_str='1.1.1.1,2.2.2.2', use_cache=False) ]), CallAssertion(func=EXECUTE_JOB_CALL_FAIL_CLIENT.job.execute_job, calls=[ Call({ 'bk_biz_id': 1, 'bk_job_id': 12345, 'global_vars': [{ 'name': 'key_1', 'value': 'value_1' }, { 'name': 'key_2',
"data": {} }) TRANSFER_SUCCESS_CASE = ComponentTestCase( name="transfer success case", inputs={"cc_host_ip": "1.1.1.1;2.2.2.2"}, parent_data={ "executor": "executor_token", "biz_cc_id": 2, "biz_supplier_account": 0 }, execute_assertion=ExecuteAssertion(success=True, outputs={}), schedule_assertion=None, execute_call_assertion=[ CallAssertion( func=CC_GET_HOST_ID_BY_INNERIP, calls=[Call("executor_token", 2, ["1.1.1.1", "2.2.2.2"], 0)]), CallAssertion( func=TRANSFER_SUCCESS_CLIENT.cc.transfer_host_to_resourcemodule, calls=[ Call({ "bk_supplier_account": 0, "bk_biz_id": 2, "bk_host_id": [2, 3] }) ], ), ], # add patch patchers=[ Patcher(target=GET_CLIENT_BY_USER,
def PUSH_FILE_TO_IPS_FAIL_CASE(): PUSH_FAIL_RESULT = {'result': False, 'message': 'msg token'} PUSH_FAIL_ESB_CLIENT = MagicMock() PUSH_FAIL_MANAGER = MagicMock() PUSH_FAIL_MANAGER.push_files_to_ips = MagicMock( return_value=PUSH_FAIL_RESULT) return ComponentTestCase( name='push_local_files manager call fail case', inputs={ 'biz_cc_id': 'biz_cc_id', 'job_local_files': [{ 'tag': 'tag_1' }, { 'tag': 'tag_2' }], 'job_target_ip_list': 'job_target_ip_list', 'job_target_account': 'job_target_account', 'job_target_path': 'job_target_path' }, parent_data={ 'executor': 'executor', 'project_id': 'project_id' }, execute_assertion=ExecuteAssertion( success=False, outputs={'ex_data': PUSH_FAIL_RESULT['message']}), schedule_assertion=None, execute_call_assertion=[ CallAssertion(func=GET_CLIENT_BY_USER, calls=[Call('executor')]), CallAssertion( func=CC_GET_IPS_INFO_BY_STR, calls=[Call('executor', 'biz_cc_id', 'job_target_ip_list')]), CallAssertion(func=PUSH_FAIL_MANAGER.push_files_to_ips, calls=[ Call(esb_client=PUSH_FAIL_ESB_CLIENT, bk_biz_id='biz_cc_id', file_tags=['tag_1', 'tag_2'], target_path='job_target_path', ips=[{ 'ip': '1.1.1.1', 'bk_cloud_id': 0 }], account='job_target_account', callback_url='callback_url') ]) ], patchers=[ Patcher(target=ENVIRONMENT_VAR_GET, return_value='a_type'), Patcher(target=FACTORY_GET_MANAGER, return_value=PUSH_FAIL_MANAGER), Patcher(target=GET_CLIENT_BY_USER, return_value=PUSH_FAIL_ESB_CLIENT), Patcher(target=CC_GET_IPS_INFO_BY_STR, return_value={ 'ip_result': [{ 'InnerIP': '1.1.1.1', 'Source': 0 }] }), Patcher(target=GET_NODE_CALLBACK_URL, return_value='callback_url') ])
CallAssertion( func=EXECUTE_JOB_PLAN_SUCCESS_CASE_CLIENT.jobv3.execute_job_plan, calls=[ Call({ "bk_scope_type": "biz_set", "bk_scope_id": "2", "bk_biz_id": 2, "job_plan_id": 1000010, "global_var_list": [ { "id": 1000030, "value": "test" }, { "id": 1000031, "server": { "ip_list": [{ "ip": "192.168.20.218", "bk_cloud_id": "0" }] } }, ], "callback_url": "callback_url", }) ], ),
def CALLBACK_FAIL_CASE(): CALLBACK_FAIL_RESULT = {'result': True, 'data': {'job_id': 12345}} CALLBACK_FAIL_ESB_CLIENT = MagicMock() CALLBACK_FAIL_MANAGER = MagicMock() CALLBACK_FAIL_MANAGER.push_files_to_ips = MagicMock( return_value=CALLBACK_FAIL_RESULT) return ComponentTestCase( name='push_local_files callback fail case', inputs={ 'biz_cc_id': 'biz_cc_id', 'job_local_files': [{ 'tag': 'tag_1' }, { 'tag': 'tag_2' }], 'job_target_ip_list': 'job_target_ip_list', 'job_target_account': 'job_target_account', 'job_target_path': 'job_target_path' }, parent_data={ 'executor': 'executor', 'project_id': 'project_id' }, execute_assertion=ExecuteAssertion( success=True, outputs={ 'job_inst_id': CALLBACK_FAIL_RESULT['data']['job_id'], 'job_inst_url': 'url_token' }), schedule_assertion=ScheduleAssertion( success=False, outputs={ 'job_inst_id': CALLBACK_FAIL_RESULT['data']['job_id'], 'job_inst_url': 'url_token', 'ex_data': { 'exception_msg': u"任务执行失败,<a href='{}' target='_blank'>" u"前往作业平台(JOB)查看详情</a>".format('url_token'), 'show_ip_log': True, 'task_inst_id': 12345 } }, callback_data={ 'status': 4, 'job_instance_id': 12345 }, schedule_finished=False), execute_call_assertion=[ CallAssertion(func=GET_CLIENT_BY_USER, calls=[Call('executor')]), CallAssertion( func=CC_GET_IPS_INFO_BY_STR, calls=[Call('executor', 'biz_cc_id', 'job_target_ip_list')]), CallAssertion(func=CALLBACK_FAIL_MANAGER.push_files_to_ips, calls=[ Call(esb_client=CALLBACK_FAIL_ESB_CLIENT, bk_biz_id='biz_cc_id', file_tags=['tag_1', 'tag_2'], target_path='job_target_path', ips=[{ 'ip': '1.1.1.1', 'bk_cloud_id': 0 }], account='job_target_account', callback_url='callback_url') ]) ], patchers=[ Patcher(target=ENVIRONMENT_VAR_GET, return_value='a_type'), Patcher(target=FACTORY_GET_MANAGER, return_value=CALLBACK_FAIL_MANAGER), Patcher(target=GET_CLIENT_BY_USER, return_value=CALLBACK_FAIL_ESB_CLIENT), Patcher(target=CC_GET_IPS_INFO_BY_STR, return_value={ 'ip_result': [{ 'InnerIP': '1.1.1.1', 'Source': 0 }] }), Patcher(target=GET_NODE_CALLBACK_URL, return_value='callback_url'), Patcher(target=GET_JOB_INSTANCE_URL, return_value='url_token') ])
TRANSFER_MODULE_SUCCESS_OUTPUTS = { "transfer_host_module_success": [ {"cc_transfer_host_ip": "2.5.5.6", "cc_transfer_host_target_module": "蓝鲸>Tun>set"} ], "transfer_host_module_failed": [], } TRANSFER_HOST_MODULE_SUCCESS_CASE = ComponentTestCase( name="transfer success case", inputs=TRANSFER_MODULE_SUCCESS_INPUTS, parent_data=COMMON_PARENT, execute_assertion=ExecuteAssertion(success=True, outputs=TRANSFER_MODULE_SUCCESS_OUTPUTS), schedule_assertion=None, execute_call_assertion=[ CallAssertion(func=CC_GET_HOST_ID_BY_INNERIP, calls=[Call("admin", 2, ["2.5.5.6"], 0)]), CallAssertion( func=TRANSFER_MODULE_SUCCESS_CLIENT.cc.transfer_host_module, calls=[ Call( { "bk_biz_id": 2, "bk_supplier_account": 0, "bk_host_id": [2], "bk_module_id": [7], "is_increment": True, } ) ], ), ],
def SUCCESS_CASE(): SUCCESS_RESULT = {'result': True, 'data': {'job_id': 12345}} SUCCESS_ESB_CLIENT = MagicMock() SUCCESS_MANAGER = MagicMock() SUCCESS_MANAGER.push_files_to_ips = MagicMock(return_value=SUCCESS_RESULT) return ComponentTestCase( name='push_local_files success case', inputs={ 'biz_cc_id': 'biz_cc_id', 'job_local_files': [{ 'tag': 'tag_1' }, { 'tag': 'tag_2' }], 'job_target_ip_list': 'job_target_ip_list', 'job_target_account': 'job_target_account', 'job_target_path': 'job_target_path' }, parent_data={ 'executor': 'executor', 'project_id': 'project_id' }, execute_assertion=ExecuteAssertion( success=True, outputs={ 'job_inst_id': SUCCESS_RESULT['data']['job_id'], 'job_inst_url': 'url_token' }), schedule_assertion=ScheduleAssertion( success=True, outputs={ 'job_inst_id': SUCCESS_RESULT['data']['job_id'], 'job_inst_url': 'url_token' }, callback_data={ 'status': 3, 'job_instance_id': 12345 }, schedule_finished=True), execute_call_assertion=[ CallAssertion(func=GET_CLIENT_BY_USER, calls=[Call('executor')]), CallAssertion( func=CC_GET_IPS_INFO_BY_STR, calls=[Call('executor', 'biz_cc_id', 'job_target_ip_list')]), CallAssertion(func=SUCCESS_MANAGER.push_files_to_ips, calls=[ Call(esb_client=SUCCESS_ESB_CLIENT, bk_biz_id='biz_cc_id', file_tags=['tag_1', 'tag_2'], target_path='job_target_path', ips=[{ 'ip': '1.1.1.1', 'bk_cloud_id': 0 }], account='job_target_account', callback_url='callback_url') ]) ], patchers=[ Patcher(target=ENVIRONMENT_VAR_GET, return_value='a_type'), Patcher(target=FACTORY_GET_MANAGER, return_value=SUCCESS_MANAGER), Patcher(target=GET_CLIENT_BY_USER, return_value=SUCCESS_ESB_CLIENT), Patcher(target=CC_GET_IPS_INFO_BY_STR, return_value={ 'ip_result': [{ 'InnerIP': '1.1.1.1', 'Source': 0 }] }), Patcher(target=GET_NODE_CALLBACK_URL, return_value='callback_url'), Patcher(target=GET_JOB_INSTANCE_URL, return_value='url_token') ])
"bk_biz_id": 1, "bk_job_id": 1, "cron_name": "job_cron_name", "cron_expression": "0 0/5 * * * ?", })) }, ), schedule_assertion=None, execute_call_assertion=[ CallAssertion( func=SAVE_CRON_CALL_FAIL_CLIENT.job.save_cron, calls=[ Call({ "bk_scope_type": "biz", "bk_scope_id": "1", "bk_biz_id": 1, "bk_job_id": 1, "cron_name": "job_cron_name", "cron_expression": "0 0/5 * * * ?", }) ], ), ], patchers=[ Patcher(target=GET_CLIENT_BY_USER, return_value=SAVE_CRON_CALL_FAIL_CLIENT) ], ) SAVE_CRON_SUCCESS_CASE = ComponentTestCase( name="save cron call success case", inputs={
'job_cron_expression': '0 0/5 * * * ?', 'job_cron_status': 1, }, parent_data={ 'executor': 'executor', 'biz_cc_id': 1 }, execute_assertion=ExecuteAssertion(success=False, outputs={'ex_data': 'save_cron fail'}), schedule_assertion=None, execute_call_assertion=[ CallAssertion(func=SAVE_CRON_CALL_FAIL_CLIENT.job.save_cron, calls=[ Call({ 'bk_biz_id': 1, 'bk_job_id': 1, 'cron_name': 'job_cron_name', 'cron_expression': '0 0/5 * * * ?' }) ]), ], patchers=[ Patcher(target=GET_CLIENT_BY_USER, return_value=SAVE_CRON_CALL_FAIL_CLIENT), ]) SAVE_CRON_SUCCESS_CASE = ComponentTestCase( name='save cron call success case', inputs={ 'job_cron_job_id': 1, 'job_cron_name': 'job_cron_name', 'job_cron_expression': '0 0/5 * * * ?',
} SELECT_BY_TEXT_SUCCESS_CASE = ComponentTestCase( name="success case: select set by text(include newline/space)", inputs=SELECT_BY_TEXT_SUCCESS_INPUTS, parent_data=COMMON_PARENT, execute_assertion=ExecuteAssertion(success=True, outputs={}), schedule_assertion=None, execute_call_assertion=[ CallAssertion( func=SELECT_BY_TEXT_SUCCESS_CLIENT.cc.update_set, calls=[ Call({ "bk_biz_id": 2, "bk_supplier_account": 0, "bk_set_id": 5, "data": { "bk_service_status": "1" } }) ], ) ], patchers=[ Patcher(target=GET_CLIENT_BY_USER, return_value=SELECT_BY_TEXT_SUCCESS_CLIENT), Patcher(target=CC_GET_CLIENT_BY_USER, return_value=SELECT_BY_TEXT_SUCCESS_CLIENT), ], )
"data": {} }) ADD_HOST_LOCK_SUCCESS_CASE = ComponentTestCase( name="add host lock success case", inputs={"cc_host_ip": "1.1.1.1;2.2.2.2"}, parent_data={ "executor": "executor_token", "biz_cc_id": 2, "biz_supplier_account": 0, "language": "中文" }, execute_assertion=ExecuteAssertion(success=True, outputs={}), schedule_assertion=None, execute_call_assertion=[ CallAssertion(func=CC_GET_IPS_INFO_BY_STR, calls=[Call("executor_token", 2, "1.1.1.1;2.2.2.2")]), CallAssertion(func=ADD_HOST_LOCK_SUCCESS_CLIENT.cc.add_host_lock, calls=[Call({"id_list": [1, 2]})]), ], # add patch patchers=[ Patcher(target=GET_CLIENT_BY_USER, return_value=ADD_HOST_LOCK_SUCCESS_CLIENT), Patcher( target=CC_GET_IPS_INFO_BY_STR, return_value={ "result": True, "ip_result": [{ "HostID": 1 }, { "HostID": 2
schedule_finished=True, outputs={ "job_url": ["{}/#/task-history/1/log/host|instance|host|1".format(settings.BK_NODEMAN_HOST)], "job_id": "1", "success_num": 1, "fail_num": 0, }, ), execute_call_assertion=[ CallAssertion( func=INSTALL_OR_OPERATE_SUCCESS_CLIENT.plugin_operate, calls=[ Call( { "job_type": "MAIN_INSTALL_PLUGIN", "bk_biz_id": ["1"], "bk_host_id": [1], "plugin_params": {"name": "plugin", "version": "plugin_version", "keep_config": 1}, } ) ], ), ], schedule_call_assertion=[ CallAssertion(func=INSTALL_OR_OPERATE_SUCCESS_CLIENT.job_details, calls=[Call(**{"job_id": "1"})]), ], patchers=[ Patcher(target=GET_CLIENT_BY_USER, return_value=INSTALL_OR_OPERATE_SUCCESS_CLIENT), Patcher(target=GET_CLIENT_BY_USER_BASE, return_value=INSTALL_OR_OPERATE_SUCCESS_CLIENT), Patcher(target=GET_HOST_ID_BY_INNER_IP, return_value={"1.1.1.1": 1}), ],
"bk_cloud_id": 1 }], }, ], "bk_callback_url": "url_token", })) }, ), schedule_assertion=None, execute_call_assertion=[ CallAssertion( func=CC_GET_IPS_INFO_BY_STR, calls=[ Call(username="******", biz_cc_id=1, ip_str="1.1.1.1,2.2.2.2", use_cache=False) ], ), CallAssertion( func=EXECUTE_JOB_CALL_FAIL_CLIENT.job.execute_job, calls=[ Call({ "bk_scope_type": "biz", "bk_scope_id": "1", "bk_biz_id": 1, "bk_job_id":
"biz_cc_id": 2, "cc_set_select_method": "text", "cc_set_select_topo": [], "cc_set_select_text": " 蓝鲸>Tun>set\n\n", "_loop": 1, } SELECT_BY_TEXT_SUCCESS_CASE = ComponentTestCase( name="success case: select set by text(include newline/space)", inputs=SELECT_BY_TEXT_SUCCESS_INPUTS, parent_data=COMMON_PARENT, execute_assertion=ExecuteAssertion(success=True, outputs={}), schedule_assertion=None, execute_call_assertion=[ CallAssertion( func=SELECT_BY_TEXT_SUCCESS_CLIENT.cc.transfer_sethost_to_idle_module, calls=[Call({"bk_biz_id": 2, "bk_supplier_account": 0, "bk_set_id": 5})], ) ], patchers=[ Patcher(target=GET_CLIENT_BY_USER, return_value=SELECT_BY_TEXT_SUCCESS_CLIENT), Patcher(target=CC_GET_CLIENT_BY_USER, return_value=SELECT_BY_TEXT_SUCCESS_CLIENT), ], ) SELECT_BY_TOPO_SUCCESS_CLIENT = MockClient( get_mainline_object_topo_return=COMMON_MAINLINE, search_biz_inst_topo_return=COMMON_TOPO, transfer_sethost_to_idle_module_return={"result": True, "code": 0, "message": "", "data": {}}, )
CallAssertion( func=CREATE_SHIELD_FAIL_CLIENT.add_shield, calls=[ Call( **{ "begin_time": "2019-11-04 00:00:00", "bk_biz_id": 2, "category": "strategy", "cycle_config": { "begin_time": "", "end_time": "", "day_list": [], "week_list": [], "type": 1 }, "description": "shield by bk_sops", "dimension_config": { "id": "123", "scope_type": "ip", "target": [{ "ip": "127.0.0.1", "bk_cloud_id": 0 }, { "ip": "127.0.0.2", "bk_cloud_id": 1 }], }, "end_time": "2019-11-05 00:00:00", "notice_config": {}, "shield_notice": False, }) ], )
FETCH_TASK_LOG_CLIENT = MockClient( get_job_instance_status=EXECUTE_SUCCESS_GET_STATUS_RETURN, get_job_instance_ip_log_return=EXECUTE_SUCCESS_GET_IP_LOG_RETURN, ) FETCH_TASK_LOG_SUCCESS_CASE = ComponentTestCase( name="fetch task log success case", inputs={"biz_cc_id": 1, "job_task_id": "12345"}, parent_data={"executor": "executor", "project_id": "project_id", "biz_cc_id": 1}, execute_assertion=ExecuteAssertion( success=True, outputs={"job_task_log": "log text\n"}, ), execute_call_assertion=[ CallAssertion(func=FETCH_TASK_LOG_CLIENT.jobv3.get_job_instance_ip_log, calls=[Call(MANUAL_KWARGS)]), ], schedule_assertion=None, patchers=[ Patcher(target=GET_CLIENT_BY_USER, return_value=FETCH_TASK_LOG_CLIENT), Patcher(target=BASE_GET_CLIENT_BY_USER, return_value=FETCH_TASK_LOG_CLIENT), ], ) FETCH_TASK_LOG_WITH_TARGET_IP_SUCCESS_CASE = ComponentTestCase( name="fetch task log with target ip success case", inputs={"biz_cc_id": 1, "job_task_id": "12345", "job_target_ip": "1.1.1.1"}, parent_data={"executor": "executor", "project_id": "project_id", "biz_cc_id": 1}, execute_assertion=ExecuteAssertion( success=True, outputs={"job_task_log": "log text\n"},
} SELECT_BY_TEXT_SUCCESS_CASE = ComponentTestCase( name="success case: select module by text(include newline/space)", inputs=SELECT_BY_TEXT_SUCCESS_INPUTS, parent_data=COMMON_PARENT, execute_assertion=ExecuteAssertion(success=True, outputs={}), schedule_assertion=None, execute_call_assertion=[ CallAssertion( func=SELECT_BY_TEXT_SUCCESS_CLIENT.cc.update_module, calls=[ Call({ "bk_biz_id": 2, "bk_supplier_account": 0, "bk_set_id": 5, "bk_module_id": 7, "data": { "bk_module_name": "name" }, }) ], ) ], patchers=[ Patcher(target=GET_CLIENT_BY_USER, return_value=SELECT_BY_TEXT_SUCCESS_CLIENT), Patcher(target=CC_GET_CLIENT_BY_USER, return_value=SELECT_BY_TEXT_SUCCESS_CLIENT), ], )