Beispiel #1
0
def FILE_MANAGER_TYPE_ERR_CASE():
    NOT_EXIST_TYPE = "NOT_EXIST_TYPE"
    MANAGER_GET_EXCEPTION = Exception("exc")

    return ComponentTestCase(
        name="push_local_files manager type err case",
        inputs={
            "biz_cc_id": "biz_cc_id",
            "job_local_files": "job_local_files",
            "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":
                "can not get file manager for type: {}\n err: {}".format(
                    NOT_EXIST_TYPE, MANAGER_GET_EXCEPTION)
            },
        ),
        schedule_assertion=None,
        patchers=[
            Patcher(target=ENVIRONMENT_VAR_GET, return_value=NOT_EXIST_TYPE),
            Patcher(target=FACTORY_GET_MANAGER,
                    side_effect=MANAGER_GET_EXCEPTION),
        ],
    )
Beispiel #2
0
def FILE_MANAGER_TYPE_ERR_CASE():
    NOT_EXIST_TYPE = 'NOT_EXIST_TYPE'
    MANAGER_GET_EXCEPTION = Exception('exc')

    return ComponentTestCase(
        name='push_local_files manager type err case',
        inputs={
            'biz_cc_id': 'biz_cc_id',
            'job_local_files': 'job_local_files',
            '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':
                'can not get file manager for type: {}\n err: {}'.format(
                    NOT_EXIST_TYPE, MANAGER_GET_EXCEPTION)
            }),
        schedule_assertion=None,
        patchers=[
            Patcher(target=ENVIRONMENT_VAR_GET, return_value=NOT_EXIST_TYPE),
            Patcher(target=FACTORY_GET_MANAGER,
                    side_effect=MANAGER_GET_EXCEPTION)
        ])
Beispiel #3
0
def FILE_MANAGER_NOT_CONFIG_CASE():
    return ComponentTestCase(
        name='push_local_files file manager not config case',
        inputs={
            'biz_cc_id': 'biz_cc_id',
            'job_local_files': 'job_local_files',
            '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':
                'File Manager configuration error, contact administrator please.'
            }),
        schedule_assertion=None,
        patchers=[Patcher(target=ENVIRONMENT_VAR_GET, return_value=None)])
Beispiel #4
0
def FILE_MANAGER_NOT_CONFIG_CASE():
    return ComponentTestCase(
        name="push_local_files file manager not config case",
        inputs={
            "biz_cc_id": "biz_cc_id",
            "job_local_files": "job_local_files",
            "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":
                "File Manager configuration error, contact administrator please."
            }),
        schedule_assertion=None,
        patchers=[Patcher(target=ENVIRONMENT_VAR_GET, return_value=None)],
    )
Beispiel #5
0
    schedule_call_assertion=[
        CallAssertion(
            func=EXECUTE_JOB_PLAN_SUCCESS_CASE_CLIENT.jobv3.
            get_job_instance_global_var_value,
            calls=[
                Call({
                    "bk_scope_type": "biz_set",
                    "bk_scope_id": "2",
                    "bk_biz_id": 2,
                    "job_instance_id": 10000
                })
            ],
        )
    ],
    patchers=[
        Patcher(target=GET_CLIENT_BY_USER,
                return_value=EXECUTE_JOB_PLAN_SUCCESS_CASE_CLIENT),
        Patcher(target=GET_NODE_CALLBACK_URL, return_value="callback_url"),
        Patcher(target=GET_JOB_INSTANCE_URL,
                return_value="instance_url_token"),
    ],
)

# execute_job_plan fail
# 不合法的IP
INVALID_IP_FAIL_CASE = ComponentTestCase(
    name="all biz execute job plan invalid ip fail test case",
    inputs={
        "all_biz_job_config": {
            "all_biz_cc_id":
            2,
            "job_plan_id":
Beispiel #6
0
            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,
                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={
                    "result": True,
                    "data": [2, 3]
                }),
    ],
)

TRANSFER_FAIL_CASE = ComponentTestCase(
    name="transfer fail case",
    inputs={"cc_host_ip": "1.1.1.1;2.2.2.2"},
    parent_data={
        "executor": "executor_token",
        "biz_cc_id": 2,
Beispiel #7
0
                    "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,
                return_value=CC_FORMAT_PROP_DATA_RETURN),
    ],
)

SELECT_BY_TOPO_SUCCESS_CLIENT = MockClient(
    get_mainline_object_topo_return=COMMON_MAINLINE,
    search_biz_inst_topo_return=COMMON_TOPO,
    create_module_return={
        "result": True,
        "code": 0,
        "message": "",
        "data": {}
Beispiel #8
0
        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={
                                           "data": {
                                               "result": {
                                                   "id": "1"
    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={
                    'result': True,
                    'data': [2, 3]
                })
    ])

TRANSFER_FAIL_CASE = ComponentTestCase(
    name='transfer fail 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
Beispiel #10
0
                      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,
                return_value=SELECT_BY_TEXT_SUCCESS_CLIENT),
        Patcher(target=CC_GET_CLIENT_BY_USER,
                return_value=SELECT_BY_TEXT_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={
                    "result": True,
                    "data": ["2", "3"]
                }),
    ],
)

SELECT_BY_TOPO_SUCCESS_CLIENT = MockClient(
    get_mainline_object_topo_return=COMMON_MAINLINE,
    search_biz_inst_topo_return=COMMON_TOPO,
    transfer_host_module_return={
Beispiel #11
0
# test  cases

WEBHOOK_NOT_CONFIG_CASE = ComponentTestCase(
    name="webhook not config test case",
    inputs={
        "wechat_work_chat_id": "@all",
        "message_content": "haha",
        "wechat_work_mentioned_members": "",
        "msgtype": "text",
    },
    parent_data={},
    execute_assertion=ExecuteAssertion(
        success=False, outputs={"ex_data": "WechatWork send message URL is not config, contact admin please"}
    ),
    schedule_assertion=None,
    patchers=[Patcher(target=ENVIRONMENT_VAIRABLES_GET, return_value=None)],
)

EMPTY_CHAT_ID_CASE = ComponentTestCase(
    name="empty chat id case",
    inputs={
        "wechat_work_chat_id": "",
        "message_content": "haha",
        "wechat_work_mentioned_members": "",
        "msgtype": "text",
    },
    parent_data={},
    execute_assertion=ExecuteAssertion(success=False, outputs={"ex_data": "会话 ID 不能为空"}),
    schedule_assertion=None,
    patchers=[Patcher(target=ENVIRONMENT_VAIRABLES_GET, return_value="test_url")],
)
Beispiel #12
0
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')
        ])
Beispiel #13
0
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')
        ])
Beispiel #14
0
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')
        ])
Beispiel #15
0
                                {"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=[
        Patcher(target=GET_CLIENT_BY_USER, return_value=CREATE_SHIELD_FAIL_CLIENT),
        Patcher(target=GET_SET_LIST, side_effect=get_set_list),
        Patcher(target=GET_LIST_BY_SELECTED_NAMES, side_effect=get_list_by_selected_names),
        Patcher(target=GET_SERVICE_TEMPLATE_LIST, side_effect=get_service_template_list),
        Patcher(target=GET_SERVICE_TEMPLATE_LIST_BY_NAMES, side_effect=get_service_template_list_by_names),
        Patcher(target=GET_MODULE_ID_LIST_BY_NAME, side_effect=get_module_id_list_by_name),
    ],
)

ALTER_BILL_SUCCESS_CASE = ComponentTestCase(
    name="create shield success case",
    inputs=INPUT_DATA,
    parent_data={"executor": "executor", "biz_cc_id": 2},
    execute_assertion=ExecuteAssertion(success=True, outputs={"shield_id": "1", "message": "success"}),
    schedule_assertion=None,
    execute_call_assertion=[
Beispiel #16
0
}

# test case
# 没有输入规则 修改主机名不成功的案例
NO_INPUT_RULE_CHANGE_HOST_PROPERTY_FAIL_CASE = ComponentTestCase(
    name="no input rule change host property fail case",
    inputs=INPUT_DATA_NO_RULE,
    parent_data={
        "executor": "executor",
        "biz_cc_id": 1
    },
    execute_assertion=ExecuteAssertion(success=False,
                                       outputs={"ex_data": "请选择至少一种规则"}),
    schedule_assertion=None,
    patchers=[
        Patcher(target=CC_GET_IPS_INFO_BY_STR,
                return_value=CC_GET_IPS_INFO_BY_STR_VALUE)
    ],
)

# 查询集群的属性值失败的案例
FIND_SET_BATCH_FAIL_CHANGE_HOST_PROPERTY_FAIL_CASE = ComponentTestCase(
    name="find set batch fail change host property fail case",
    inputs=INPUT_DATA,
    parent_data={
        "executor": "executor",
        "biz_cc_id": 1
    },
    execute_assertion=ExecuteAssertion(
        success=False,
        outputs={
            'ex_data':
Beispiel #17
0
    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": []}),
    ],
)

# 上传文件成功异步执行成功样例
LOCAL_CONTENT_UPLOAD_SUCCESS_SCHEDULE_SUCCESS_CASE = ComponentTestCase(
    name="local content upload success and schedule success test case",
    inputs=INPUTS,
    parent_data=PARENT_DATA,
    execute_assertion=ExecuteAssertion(success=True, outputs=SUCCESS_OUTPUTS),
Beispiel #18
0
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/"),
        ],
    )
Beispiel #19
0
            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,
                    }
                )
            ],
        ),
    ],
    patchers=[
        Patcher(target=GET_CLIENT_BY_USER, return_value=TRANSFER_MODULE_SUCCESS_CLIENT),
        Patcher(target=CC_GET_CLIENT_BY_USER, return_value=TRANSFER_MODULE_SUCCESS_CLIENT),
        Patcher(target=CC_GET_HOST_ID_BY_INNERIP, return_value={"result": True, "data": ["2"]}),
        Patcher(target=CC_LIST_SELECT_NODE_INST_ID, return_value={"result": True, "data": ["7"]}),
    ],
)

TRANSFER_MODULE_AUTO_COMPLETE_BIZ_SUCCESS_INPUTS = {
    "cc_module_select_method": "manual",
    "cc_host_transfer_detail": [{"cc_transfer_host_ip": "2.5.5.6", "cc_transfer_host_target_module": "Tun>set"}],
    "cc_transfer_host_template_break_line": "",
    "is_append": True,
    "_loop": 1,
}

TRANSFER_MODULE_AUTO_COMPLETE_BIZ_SUCCESS_OUTPUTS = {
Beispiel #20
0
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,
    execute_assertion=ExecuteAssertion(success=True,
                                       outputs={"sn": "NO2019090519542603"}),
    execute_call_assertion=[
        CallAssertion(
            func=CREAT_TICKET_SUCCESS_CLIENT.create_ticket,
            calls=[Call(**CREAT_TICKET_CALL)],
Beispiel #21
0
        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_job_id": 1,
        "job_cron_name": "job_cron_name",
        "job_cron_expression": "0 0/5 * * * ?",
        "job_cron_status": 2,
    },
    parent_data={
        "executor": "executor",
        "biz_cc_id": 1
    },
    execute_assertion=ExecuteAssertion(success=True,
Beispiel #22
0
        "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
                }],
                "invalid_ip": []
            },
        ),
    ],
)
Beispiel #23
0
            {
                "attr_id": "bk_set_desc",
                "attr_value": "bk_set_desc"
            },
        ]
    },
}

SELECT_BY_TEXT_SUCCESS_CASE = ComponentTestCase(
    name="success case: select parent set by text(include newline/space)",
    inputs=SELECT_BY_TEXT_SUCCESS_INPUTS,
    parent_data=PARENT_DATA,
    execute_assertion=ExecuteAssertion(success=True, outputs={}),
    schedule_assertion=[],
    patchers=[
        Patcher(target=GET_CLIENT_BY_USER, return_value=COMMON_CLIENT),
        Patcher(target=CC_GET_CLIENT_BY_USER, return_value=COMMON_CLIENT),
    ],
)

SELECT_BY_TEXT_ERROR_LEVEL_FAIL_INPUTS = {
    "biz_cc_id": 2,
    "cc_select_set_parent_method": "text",
    "cc_set_parent_select_topo": [],
    "cc_set_parent_select_text": u"蓝鲸>blue>Tun\n\n   ",
    "cc_set_name": "1,2",
    "cc_set_template": 1,
    "cc_set_attr_combine": {
        "set_attr": [
            {
                "attr_id": "4",
Beispiel #24
0
        outputs={
            "module_update_success": [{
                "cc_module_select_text": "set>module",
                "bk_module_name": "test",
                "bk_module_type": "",
                "operator": "",
                "bk_bak_operator": "",
            }],
            "module_update_failed": [],
        },
    ),
    schedule_assertion=ScheduleAssertion(success=True,
                                         schedule_finished=True,
                                         outputs={}),
    patchers=[
        Patcher(target=GET_CLIENT_BY_USER,
                return_value=UPDATE_MODULE_SUCCESS_CLIENT),
        Patcher(target=CC_GET_CLIENT_BY_USER,
                return_value=UPDATE_MODULE_SUCCESS_CLIENT),
    ],
)

UPDATE_MODULE_FAILED_BY_CUSTOM = ComponentTestCase(
    name="update module failed by custom",
    inputs={
        "cc_tag_method":
        "custom",
        "cc_module_update_data": [{
            "cc_module_select_text": "set>module",
            "bk_module_name": "test",
            "bk_module_type": "",
            "operator": "",
Beispiel #25
0
                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}),
    ],
)

OPERATE_FAIL_CASE = ComponentTestCase(
    name="nodeman v1.0 operate plugin failed case",
    inputs={
        "biz_cc_id": "1",
        "nodeman_plugin_operate": {
            "nodeman_op_type": "MAIN_INSTALL_PLUGIN",
            "nodeman_plugin": "plugin",
            "nodeman_plugin_version": "plugin_version",
            "install_config": ["keep_config"],
        },
Beispiel #26
0
                                "ip": "1.1.1.1",
                                "bk_cloud_id": 1
                            }, {
                                "ip": "2.2.2.2",
                                "bk_cloud_id": 1
                            }],
                        },
                    ],
                    "bk_callback_url":
                    "url_token",
                })
            ],
        ),
    ],
    patchers=[
        Patcher(target=GET_CLIENT_BY_USER,
                return_value=EXECUTE_JOB_CALL_FAIL_CLIENT),
        Patcher(
            target=CC_GET_IPS_INFO_BY_STR,
            return_value={
                "ip_result": [{
                    "InnerIP": "1.1.1.1",
                    "Source": 1
                }, {
                    "InnerIP": "2.2.2.2",
                    "Source": 1
                }]
            },
        ),
        Patcher(target=GET_NODE_CALLBACK_URL, return_value="url_token"),
    ],
)
Beispiel #27
0
}

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": {}},
)

SELECT_BY_TOPO_SUCCESS_INPUTS = {
    "biz_cc_id": 2,
    "cc_set_select_method": "topo",
    "cc_set_select_topo": ["set_5"],
Beispiel #28
0
                                "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,
                    })
            ],
        )
    ],
    patchers=[
        Patcher(target=MONITOR_CLIENT, return_value=CREATE_SHIELD_FAIL_CLIENT),
        Patcher(target=CMDB_GET_BIZ_HOST,
                return_value=CREATE_SHIELD_FAIL_GET_BIZ_HOST_RETURN),
        Patcher(target=BIZ_MODEL_SUPPLIER_ACCOUNT_FOR_BIZ,
                return_value=CREATE_SHIELD_FAIL_SUPPLIER_RETURN),
    ],
)

CREATE_SHIELD_SUCCESS_CASE = ComponentTestCase(
    name="create shield success case",
    inputs={
        "bk_alarm_shield_strategy": "123",
        "bk_alarm_shield_IP": "10.0.1.11",
        "bk_alarm_shield_strategy_begin_time": "2019-11-04 00:00:00",
        "bk_alarm_shield_strategy_end_time": "2019-11-05 00:00:00",
        "bk_alarm_time_type": "0",
Beispiel #29
0

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"},
    ),
    execute_call_assertion=[
        CallAssertion(func=FETCH_TASK_LOG_CLIENT.jobv3.get_job_instance_ip_log, calls=[Call(MANUAL_KWARGS)]),
    ],
Beispiel #30
0
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
                        }]
                    }),
        ],
    )