def initialize_sandesh_logger(): # parse the logger args args = parse_logger_args() args.random_collectors = args.collectors if args.collectors: args.random_collectors = random.sample(args.collectors, len(args.collectors)) # initialize logger logger = JobLogger(args) logger.info("Job Manager process is starting. Sandesh is initialized.") return logger
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 initialize_sandesh_logger(self, config_args): # parse the logger args args = self.parse_logger_args(config_args) args.random_collectors = args.collectors if args.collectors: args.random_collectors = random.sample(args.collectors, len(args.collectors)) self.args = args # initialize logger logger = JobLogger(args=args, sandesh_instance_id=self.sandesh_instance_id) try: sandesh_util = SandeshUtils() sandesh_util.wait_for_connection_establish(logger) except JobException: raise JobException("Sandesh initialization timeout after 15s") logger.info("Sandesh is initialized. Config logger instance created.") return logger
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) resp = jm.start_job()
def initialize_sandesh_logger(self, config_args): # parse the logger args args = self.parse_logger_args(config_args) args.random_collectors = args.collectors if args.collectors: args.random_collectors = random.sample(args.collectors, len(args.collectors)) self.args = args # initialize logger logger = JobLogger(args=args, sandesh_instance_id=self.sandesh_instance_id) try: sandesh_util = SandeshUtils(logger) sandesh_util.wait_for_connection_establish() except JobException: msg = MsgBundle.getMessage( MsgBundle.SANDESH_INITIALIZATION_TIMEOUT_ERROR) raise JobException(msg) logger.info("Sandesh is initialized. Config logger instance created.") return logger
if __name__ == "__main__": # TODO the logs before the sandesh is initalized should go to some log file # parse the params passed to the job manager process job_input_json = None try: job_params = parse_args() job_input_json = json.loads(job_params.job_input[0]) if job_input_json is None: sys.exit("Job input data is not passed to job mgr. " "Aborting job ...") # TODO integrate with Sandesh logger logger = JobLogger() except Exception as e: print >> sys.stderr, "Failed to initialize logger due "\ "to Exception: %s" % traceback.print_stack() sys.exit( "Exiting due to logger initialization error: %s" % repr(e)) # initialize _vnc_api instance vnc_api = None try: auth_token = job_input_json['auth_token'] vnc_api = VncApi(auth_token=auth_token) logger.info("VNC api is initialized using the auth token passed.") except Exception as e: logger.error("Caught exception when initialing vnc api: " "%s" % traceback.print_stack())