From: Taewan Kim Date: Thu, 8 Jun 2023 09:19:23 +0000 (+0900) Subject: Assign None if the configuration variables can't be found in environment variables. X-Git-Tag: 1.1.1~2^2 X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F91%2F11291%2F1;p=aiml-fw%2Fawmf%2Ftm.git Assign None if the configuration variables can't be found in environment variables. - A unit test which `is_config_loaded_properly` returns False added Issue-ID: AIMLFW-35 Change-Id: I8ac0f3c7f30d6570caa6ec5c76fe499cead459a4 Signed-off-by: Taewan Kim --- diff --git a/tests/test_trainingmgr_config.py b/tests/test_trainingmgr_config.py index 08385cf..a699588 100644 --- a/tests/test_trainingmgr_config.py +++ b/tests/test_trainingmgr_config.py @@ -104,8 +104,15 @@ class Test_trainingmgr_config: result = self.TRAININGMGR_CONFIG_OBJ.allow_control_access_origin assert result == expected_data - def test_is_config_loaded_properly(self): + def test_is_config_loaded_properly_return_true(self): expected_data = True result = TrainingMgrConfig.is_config_loaded_properly(self.TRAININGMGR_CONFIG_OBJ) assert result == expected_data + @patch('trainingmgr.common.trainingmgr_config.TMLogger', return_value = TMLogger("tests/common/conf_log.yaml")) + def test_is_config_loaded_properly_return_false(self,mock1): + os.environ.pop("KF_ADAPTER_IP") + self.TRAININGMGR_CONFIG_OBJ = TrainingMgrConfig() + expected_data = False + result = TrainingMgrConfig.is_config_loaded_properly(self.TRAININGMGR_CONFIG_OBJ) + assert result == expected_data \ No newline at end of file diff --git a/trainingmgr/common/trainingmgr_config.py b/trainingmgr/common/trainingmgr_config.py index 11c6b92..2bcb0d0 100644 --- a/trainingmgr/common/trainingmgr_config.py +++ b/trainingmgr/common/trainingmgr_config.py @@ -33,20 +33,20 @@ class TrainingMgrConfig: """ This constructor filling configuration varibles. """ - self.__kf_adapter_port = getenv('KF_ADAPTER_PORT').rstrip() - self.__kf_adapter_ip = getenv('KF_ADAPTER_IP').rstrip() + self.__kf_adapter_port = getenv('KF_ADAPTER_PORT').rstrip() if getenv('KF_ADAPTER_PORT') is not None else None + self.__kf_adapter_ip = getenv('KF_ADAPTER_IP').rstrip() if getenv('KF_ADAPTER_IP') is not None else None - self.__data_extraction_port = getenv('DATA_EXTRACTION_API_PORT').rstrip() - self.__data_extraction_ip = getenv('DATA_EXTRACTION_API_IP').rstrip() + self.__data_extraction_port = getenv('DATA_EXTRACTION_API_PORT').rstrip() if getenv('DATA_EXTRACTION_API_PORT') is not None else None + self.__data_extraction_ip = getenv('DATA_EXTRACTION_API_IP').rstrip() if getenv('DATA_EXTRACTION_API_IP') is not None else None - self.__my_port = getenv('TRAINING_MANAGER_PORT').rstrip() - self.__my_ip = getenv('TRAINING_MANAGER_IP').rstrip() + self.__my_port = getenv('TRAINING_MANAGER_PORT').rstrip() if getenv('TRAINING_MANAGER_PORT') is not None else None + self.__my_ip = getenv('TRAINING_MANAGER_IP').rstrip() if getenv('TRAINING_MANAGER_IP') is not None else None - self.__ps_user = getenv('PS_USER').rstrip() - self.__ps_password = getenv('PS_PASSWORD').rstrip() - self.__ps_ip = getenv('PS_IP').rstrip() - self.__ps_port = getenv('PS_PORT').rstrip() - self.__allow_control_access_origin = getenv('ACCESS_CONTROL_ALLOW_ORIGIN').rstrip() + self.__ps_user = getenv('PS_USER').rstrip() if getenv('PS_USER') is not None else None + self.__ps_password = getenv('PS_PASSWORD').rstrip() if getenv('PS_PASSWORD') is not None else None + self.__ps_ip = getenv('PS_IP').rstrip() if getenv('PS_IP') is not None else None + self.__ps_port = getenv('PS_PORT').rstrip() if getenv('PS_PORT') is not None else None + self.__allow_control_access_origin = getenv('ACCESS_CONTROL_ALLOW_ORIGIN').rstrip() if getenv('ACCESS_CONTROL_ALLOW_ORIGIN') is not None else None self.tmgr_logger = TMLogger("common/conf_log.yaml") self.__logger = self.tmgr_logger.logger