def test_execute_job_multiple_device_families(self): play_info_mx = PlaybookInfoType(playbook_uri='job_manager_test.yaml', vendor='Juniper', device_family='MX') play_info_qfx = PlaybookInfoType(playbook_uri='job_manager_test.yaml', vendor='Juniper', device_family='QFX') playbooks_list = PlaybookInfoListType( playbook_info=[play_info_qfx, play_info_mx]) job_template = JobTemplate(job_template_type='device', job_template_job_runtime='ansible', job_template_multi_device_job=True, job_template_playbooks=playbooks_list, name='Test_template_multidevfamilies') job_template_uuid = self._vnc_lib.job_template_create(job_template) # mock the play book executor call self.mock_play_book_execution() TestJobManagerUtils.mock_sandesh_check() job_input_json, log_utils = self.get_details(job_template_uuid) jm = JobManager(log_utils.get_config_logger(), self._vnc_lib, job_input_json, log_utils) jm.start_job() self.assertEqual(jm.result_handler.job_result_status, JobStatus.SUCCESS)
def test_execute_job(self): # create job template play_info = PlaybookInfoType(playbook_uri='job_manager_test.yaml', vendor='Juniper', device_family='MX') playbooks_list = PlaybookInfoListType(playbook_info=[play_info]) job_template = JobTemplate(job_template_type='device', job_template_job_runtime='ansible', job_template_multi_device_job=False, job_template_playbooks=playbooks_list, name='Test_template') job_template_uuid = self._vnc_lib.job_template_create(job_template) # mock the play book executor call self.mock_play_book_executor() execution_id = uuid.uuid4() # Hardcoding a sample auth token since its a madatory value passed # by the api server while invoking the job manager. Here since we # are directly invoking the job manager, we are passing a dummy # auth token for testing. This value is not used internally since # the calls that use the auth token are mocked sample_auth_token = "6e7d7f87faa54fac96a2a28ec752336a" job_input_json = { "job_template_id": job_template_uuid, "input": { "playbook_data": "some playbook data" }, "job_execution_id": str(execution_id), "auth_token": sample_auth_token } logger = JobLogger() jm = JobManager(logger, self._vnc_lib, job_input_json) jm.start_job()
def test_execute_job(self): # create job template play_info = PlaybookInfoType(playbook_uri='job_manager_test.yaml', vendor='Juniper', device_family='MX') playbooks_list = PlaybookInfoListType(playbook_info=[play_info]) job_template = JobTemplate(job_template_type='device', job_template_job_runtime='ansible', job_template_multi_device_job=False, job_template_playbooks=playbooks_list, name='Test_template') job_template_uuid = self._vnc_lib.job_template_create(job_template) # mock the play book executor call self.mock_play_book_executor() execution_id = uuid.uuid4() job_input_json = { "job_template_id": job_template_uuid, "input": { "playbook_data": "some playbook data" }, "execution_id": str(execution_id) } sandesh_logger = initialize_sandesh_logger() jm = JobManager(sandesh_logger, self._vnc_lib, job_input_json) jm.start_job()
def test_execute_job_04(self): play_info_juniper_mx = PlaybookInfoType( playbook_uri='job_manager_test.yaml', vendor='Juniper', device_family='MX') play_info_juniper_qfx = PlaybookInfoType( playbook_uri='job_manager_test.yaml', vendor='Juniper', device_family='QFX') play_info_arista_df = PlaybookInfoType( playbook_uri='job_manager_test.yaml', vendor='Arista', device_family='df') playbooks_list = PlaybookInfoListType(playbook_info=[ play_info_arista_df, play_info_juniper_qfx, play_info_juniper_mx ]) job_template = JobTemplate(job_template_type='device', job_template_job_runtime='ansible', job_template_multi_device_job=True, job_template_playbooks=playbooks_list, name='Test_template_multivendors') job_template_uuid = self._vnc_lib.job_template_create(job_template) # mock the play book executor call self.mock_play_book_executor() execution_id = uuid.uuid4() # Hardcoding a sample auth token since its a madatory value passed # by the api server while invoking the job manager. Here since we # are directly invoking the job manager, we are passing a dummy # auth token for testing. This value is not used internally since # the calls that use the auth token are mocked sample_auth_token = "6e7d7f87faa54fac96a2a28ec752336a" job_input_json = { "job_template_id": job_template_uuid, "input": { "playbook_data": "some playbook data" }, "job_execution_id": str(execution_id), "auth_token": sample_auth_token, "params": { "device_list": ["aad74e24-a00b-4eb3-8412-f8b9412925c3"] }, "device_json": { "aad74e24-a00b-4eb3-8412-f8b9412925c3": { 'device_vendor': 'Juniper', 'device_family': 'MX' } } } logger = JobLogger() jm = JobManager(logger, self._vnc_lib, job_input_json) jm.start_job()
def test_execute_job_no_vendor(self): play_info_juniper_qfx = PlaybookInfoType( playbook_uri='job_manager_test.yaml', vendor='Juniper', device_family='QFX') play_info_vendor_agnostic = PlaybookInfoType( playbook_uri='job_manager_test.yaml') playbooks_list = PlaybookInfoListType( playbook_info=[play_info_juniper_qfx, play_info_vendor_agnostic]) job_template = JobTemplate(job_template_type='device', job_template_job_runtime='ansible', job_template_multi_device_job=True, job_template_playbooks=playbooks_list, name='Test_template_no_vendor') job_template_uuid = self._vnc_lib.job_template_create(job_template) # mock the play book executor call # check if the playbook is getting executed after job_manager # validation self.mock_play_book_execution() self.mock_sandesh_check() execution_id = uuid.uuid4() # Hardcoding a sample auth token since its a madatory value passed # by the api server while invoking the job manager. Here since we # are directly invoking the job manager, we are passing a dummy # auth token for testing. This value is not used internally since # the calls that use the auth token are mocked sample_auth_token = "6e7d7f87faa54fac96a2a28ec752336a" job_input_json = {"job_template_id": job_template_uuid, "input": {"playbook_data": "some playbook data"}, "job_execution_id": str(execution_id), "auth_token": sample_auth_token, "params": { "device_list": ["aad74e24-a00b-4eb3-8412-f8b9412925c3"]}, "device_json": { "aad74e24-a00b-4eb3-8412-f8b9412925c3": {'device_vendor': 'Juniper', 'device_family': 'MX' } }, "args": {"collectors": ['127.0.0.1:8086']}} args = {"collectors": ['127.0.0.1:8086']} log_utils = JobLogUtils(sandesh_instance_id=str(execution_id), config_args=json.dumps(args)) jm = JobManager(log_utils.get_config_logger(), self._vnc_lib, job_input_json, log_utils) jm.start_job() self.assertEqual(jm.result_handler.job_result_status, JobStatus.SUCCESS)
def test_execute_job_success(self): # create job template play_info = PlaybookInfoType(playbook_uri='job_manager_test.yaml', vendor='Juniper', device_family='MX') playbooks_list = PlaybookInfoListType(playbook_info=[play_info]) job_template = JobTemplate(job_template_type='device', job_template_job_runtime='ansible', job_template_multi_device_job=False, job_template_playbooks=playbooks_list, name='Test_template') job_template_uuid = self._vnc_lib.job_template_create(job_template) self.mock_play_book_execution() self.mock_sandesh_check() # Hardcoding a sample auth token since its a madatory value passed # by the api server while invoking the job manager. Here since we # are directly invoking the job manager, we are passing a dummy # auth token for testing. This value is not used internally since # the calls that use the auth token are mocked sample_auth_token = "6e7d7f87faa54fac96a2a28ec752336a" execution_id = uuid.uuid4() job_input_json = {"job_template_id": job_template_uuid, "input": {"playbook_data": "some playbook data"}, "job_execution_id": str(execution_id), "auth_token": sample_auth_token, "args": {"collectors": ['127.0.0.1:8086']}} args = {"collectors": ['127.0.0.1:8086']} log_utils = JobLogUtils(sandesh_instance_id=str(execution_id), config_args=json.dumps(args)) jm = JobManager(log_utils.get_config_logger(), self._vnc_lib, job_input_json, log_utils) jm.start_job() self.assertEqual(jm.result_handler.job_result_status, JobStatus.SUCCESS)