def test_success_REST(self): config = readPilotJSONConfigFile(self.pilotJSON_REST) url = "https://testMachineREST.cern.ch:666/msg" key_file = "/path/to/certs/hostkey.pem" cert_file = "/path/to/certs/hostcert.pem" ca_certs = "/path/to/certs/ca-bundle.crt" config = readPilotJSONConfigFile(self.pilotJSON_REST) self.assertEqual(config["LoggingType"], "REST_API") self.assertEqual(config["LocalOutputFile"], "myLocalQueueOfMessages") self.assertEqual(config["Url"], url) self.assertEqual(config["HostKey"], key_file) self.assertEqual(config["HostCertificate"], cert_file) self.assertEqual(config["CACertificate"], ca_certs) self.assertEqual(config["FileWithID"], "PilotUUID") self.assertFalse(config["QueuePath"])
def test_success_REST(self): config = readPilotJSONConfigFile(self.pilotJSON_REST) url = 'https://testMachineREST.cern.ch:666/msg' key_file = '/path/to/certs/hostkey.pem' cert_file = '/path/to/certs/hostcert.pem' ca_certs = '/path/to/certs/ca-bundle.crt' config = readPilotJSONConfigFile(self.pilotJSON_REST) self.assertEqual(config['LoggingType'], 'REST_API') self.assertEqual(config['LocalOutputFile'], 'myLocalQueueOfMessages') self.assertEqual(config['Url'], url) self.assertEqual(config['HostKey'], key_file) self.assertEqual(config['HostCertificate'], cert_file) self.assertEqual(config['CACertificate'], ca_certs) self.assertEqual(config['FileWithID'], 'PilotUUID') self.assertFalse(config['QueuePath'])
def test_success_MQ(self): config = readPilotJSONConfigFile(self.pilotJSON_MQ) host = "testMachineMQ.cern.ch" port = 61614 queuePath = "/queue/test" key_file = "/path/to/certs/hostkey.pem" cert_file = "/path/to/certs/hostcert.pem" ca_certs = "/path/to/certs/ca-bundle.crt" config = readPilotJSONConfigFile(self.pilotJSON_MQ) self.assertEqual(config["LoggingType"], "MQ") self.assertEqual(config["LocalOutputFile"], "myLocalQueueOfMessages") self.assertEqual(int(config["Port"]), port) self.assertEqual(config["Host"], host) self.assertEqual(config["QueuePath"], queuePath) self.assertEqual(config["HostKey"], key_file) self.assertEqual(config["HostCertificate"], cert_file) self.assertEqual(config["CACertificate"], ca_certs) self.assertEqual(config["FileWithID"], "PilotUUID")
def test_success_MQ(self): config = readPilotJSONConfigFile(self.pilotJSON_MQ) host = 'testMachineMQ.cern.ch' port = 61614 queuePath = '/queue/test' key_file = '/path/to/certs/hostkey.pem' cert_file = '/path/to/certs/hostcert.pem' ca_certs = '/path/to/certs/ca-bundle.crt' config = readPilotJSONConfigFile(self.pilotJSON_MQ) self.assertEqual(config['LoggingType'], 'MQ') self.assertEqual(config['LocalOutputFile'], 'myLocalQueueOfMessages') self.assertEqual(int(config['Port']), port) self.assertEqual(config['Host'], host) self.assertEqual(config['QueuePath'], queuePath) self.assertEqual(config['HostKey'], key_file) self.assertEqual(config['HostCertificate'], cert_file) self.assertEqual(config['CACertificate'], ca_certs) self.assertEqual(config['FileWithID'], 'PilotUUID')
def test_success_LOCAL(self): config = readPilotJSONConfigFile(self.pilotJSON_LOCAL) self.assertEqual(config["LoggingType"], "LOCAL_FILE") self.assertEqual(config["LocalOutputFile"], "myLocalQueueOfMessages") self.assertEqual(config["FileWithID"], "PilotUUID") self.assertFalse(config["QueuePath"]) self.assertFalse(config["Port"]) self.assertFalse(config["Host"]) self.assertFalse(config["HostKey"]) self.assertFalse(config["HostCertificate"]) self.assertFalse(config["CACertificate"])
def test_success_LOCAL(self): config = readPilotJSONConfigFile(self.pilotJSON_LOCAL) self.assertEqual(config['LoggingType'], 'LOCAL_FILE') self.assertEqual(config['LocalOutputFile'], 'myLocalQueueOfMessages') self.assertEqual(config['FileWithID'], 'PilotUUID') self.assertFalse(config['QueuePath']) self.assertFalse(config['Port']) self.assertFalse(config['Host']) self.assertFalse(config['HostKey']) self.assertFalse(config['HostCertificate']) self.assertFalse(config['CACertificate'])
def __init__( self, configFile="pilot.json", messageSenderType="LOCAL_FILE", localOutputFile="myLocalQueueOfMessages", fileWithUUID="PilotUUID", setup="DIRAC-Certification", ): """ctr loads the configuration parameters from the json file or if the file does not exists, loads the default set of values. Next, if self.fileWithUUID is not set (this variable corresponds to the name of the file with Pilot Agent ID) the default value is used, and if the file does not exist, the Pilot ID is created and saved in this file. Args: configFile(str): Name of the file with the configuration parameters. messageSenderType(str): Type of the message sender to use e.g. to a REST interface, to a message queue or to a local file. localOutputFile(str): Name of the file that can be used to store the log messages locally. fileWithUUID(str): Name of the file used to store the Pilot identifier. """ logging.debug("In init of PilotLogger") self.STATUSES = PilotLogger.STATUSES self.params = addMissingConfiguration( config=readPilotJSONConfigFile(configFile, setup), defaultConfig={ "LoggingType": messageSenderType, "LocalOutputFile": localOutputFile, "FileWithID": fileWithUUID, }, ) fileWithID = self.params["FileWithID"] if os.path.isfile(fileWithID): logging.warning( "The file: " + fileWithID + " already exists. The content will be used to get UUID.") else: result = getUniqueIDAndSaveToFile(filename=fileWithID) if not result: logging.error("Error while generating pilot logger id.") self.messageSender = messageSenderFactory( senderType=self.params["LoggingType"], params=self.params) if not self.messageSender: logging.error("Something went wrong - no messageSender created.")
def __init__(self, configFile='pilot.json', messageSenderType='LOCAL_FILE', localOutputFile='myLocalQueueOfMessages', fileWithUUID='PilotUUID', setup='DIRAC-Certification'): """ ctr loads the configuration parameters from the json file or if the file does not exists, loads the default set of values. Next, if self.fileWithUUID is not set (this variable corresponds to the name of the file with Pilot Agent ID) the default value is used, and if the file does not exist, the Pilot ID is created and saved in this file. Args: configFile(str): Name of the file with the configuration parameters. messageSenderType(str): Type of the message sender to use e.g. to a REST interface, to a message queue or to a local file. localOutputFile(str): Name of the file that can be used to store the log messages locally. fileWithUUID(str): Name of the file used to store the Pilot identifier. """ self.STATUSES = PilotLogger.STATUSES self.params = addMissingConfiguration( config=readPilotJSONConfigFile(configFile, setup), defaultConfig={ 'LoggingType': messageSenderType, 'LocalOutputFile': localOutputFile, 'FileWithID': fileWithUUID }) fileWithID = self.params['FileWithID'] if os.path.isfile(fileWithID): logging.warning( 'The file: ' + fileWithID + ' already exists. The content will be used to get UUID.') else: result = getUniqueIDAndSaveToFile(filename=fileWithID) if not result: logging.error('Error while generating pilot logger id.') self.messageSender = messageSenderFactory( senderType=self.params['LoggingType'], params=self.params) if not self.messageSender: logging.error('Something went wrong - no messageSender created.')