def setUp(self): self.test_conf_path = \ os.path.join(self.test_base_path, "etc", "agent.conf") self.conf_obj = config.AgentConfig([self.test_conf_path]) self.svc = service.DCMAgent(self.conf_obj) self._event = threading.Event() utils.verify_config_file(self.conf_obj) # script_dir must be forced to None so that we get the built in dir self.svc.pre_threads() self.conf_obj.start_job_runner() self.disp = dispatcher.Dispatcher(self.conf_obj) self.req_conn = test_conn.RequestConnection() self.reply_conn = test_conn.ReplyConnection() self.db = persistence.SQLiteAgentDB( os.path.join(self.test_base_path, "etc", "agentdb.sql")) self.request_listener = reply.RequestListener(self.conf_obj, self.reply_conn, self.disp, self.db) observers = self.request_listener.get_reply_observers() observers.append(self) self.req_conn.set_request_listener(self.request_listener) self.agent_id = "theAgentID" + str(uuid.uuid4()) self.customer_id = 50 handshake_doc = {} handshake_doc["version"] = "1" handshake_doc["agentID"] = self.agent_id handshake_doc["cloudId"] = "Amazon" handshake_doc["customerId"] = self.customer_id handshake_doc["regionId"] = None handshake_doc["zoneId"] = "rack2" handshake_doc["serverId"] = "thisServer" handshake_doc["serverName"] = "dcm.testagent.com" handshake_doc["ephemeralFileSystem"] = "/tmp" handshake_doc["encryptedEphemeralFsKey"] = "DEADBEAF" self.svc.conn = self.reply_conn self.svc.disp = self.disp self.svc.request_listener = self.request_listener self.svc.handshaker.incoming_document({ "handshake": handshake_doc, "return_code": 200 }) self.disp.start_workers(self.request_listener)
def setUp(self): self.test_conf_path = \ os.path.join(self.test_base_path, "etc", "agent.conf") self.conf_obj = config.AgentConfig([self.test_conf_path]) self.svc = service.DCMAgent(self.conf_obj) self._event = threading.Event() utils.verify_config_file(self.conf_obj) # script_dir must be forced to None so that we get the built in dir self.svc.pre_threads() self.conf_obj.start_job_runner() self.disp = dispatcher.Dispatcher(self.conf_obj) self.req_conn = test_conn.RequestConnection() self.reply_conn = test_conn.ReplyConnection() self.db = persistence.SQLiteAgentDB( os.path.join(self.test_base_path, "etc", "agentdb.sql")) self.request_listener = reply.RequestListener( self.conf_obj, self.reply_conn, self.disp, self.db) observers = self.request_listener.get_reply_observers() observers.append(self) self.req_conn.set_request_listener(self.request_listener) self.agent_id = "theAgentID" + str(uuid.uuid4()) self.customer_id = 50 handshake_doc = {} handshake_doc["version"] = "1" handshake_doc["agentID"] = self.agent_id handshake_doc["cloudId"] = "Amazon" handshake_doc["customerId"] = self.customer_id handshake_doc["regionId"] = None handshake_doc["zoneId"] = "rack2" handshake_doc["serverId"] = "thisServer" handshake_doc["serverName"] = "dcm.testagent.com" handshake_doc["ephemeralFileSystem"] = "/tmp" handshake_doc["encryptedEphemeralFsKey"] = "DEADBEAF" self.svc.conn = self.reply_conn self.svc.disp = self.disp self.svc.request_listener = self.request_listener self.svc.handshaker.incoming_document({"handshake": handshake_doc, "return_code": 200}) self.disp.start_workers(self.request_listener)
def start_main_service(cli_args): agent = None try: config_files = config.get_config_files(conffile=cli_args.conffile) conf = config.AgentConfig(config_files) agent = DCMAgent(conf) if cli_args.version: print("Version %s" % dcm.agent.g_version) return 0 agent.pre_threads() if cli_args.report: utils._g_logger.disabled = True cm._g_logger.disabled = True config._g_logger.disabled = True agent.g_logger.disabled = True _gather_info(conf) return 0 utils.verify_config_file(conf) conf.start_job_runner() agent.run_agent() except exceptions.AgentOptionException as aoex: console_log( cli_args, 0, "The agent is not configured properly. " "please check the config file.") console_log(cli_args, 0, str(aoex)) if agent: agent.shutdown_main_loop() if getattr(cli_args, "verbose", 0) > 2: raise except Exception: _g_logger = logging.getLogger(__name__) console_log(cli_args, 0, "Shutting down due to a top level exception") _g_logger.exception("An unknown exception bubbled to the top") if agent: agent.shutdown_main_loop() raise return 0
def start_main_service(cli_args): agent = None try: config_files = config.get_config_files(conffile=cli_args.conffile) conf = config.AgentConfig(config_files) agent = DCMAgent(conf) if cli_args.version: print("Version %s" % dcm.agent.g_version) return 0 agent.pre_threads() if cli_args.report: utils._g_logger.disabled = True cm._g_logger.disabled = True config._g_logger.disabled = True agent.g_logger.disabled = True _gather_info(conf) return 0 utils.verify_config_file(conf) conf.start_job_runner() agent.run_agent() except exceptions.AgentOptionException as aoex: console_log(cli_args, 0, "The agent is not configured properly. " "please check the config file.") console_log(cli_args, 0, str(aoex)) if agent: agent.shutdown_main_loop() if getattr(cli_args, "verbose", 0) > 2: raise except Exception: _g_logger = logging.getLogger(__name__) console_log(cli_args, 0, "Shutting down due to a top level exception") _g_logger.exception("An unknown exception bubbled to the top") if agent: agent.shutdown_main_loop() raise return 0