Energy could be safely disabled if one env var is missing.
No error message should be printed in console [1].
It could be enhanced in a second step to print the reasons (missing
or incorrect env vars) instead of the full stack.
[1] https://build.opnfv.org/ci/view/functest/job/functest-apex-baremetal-daily-master/766/console
Change-Id: I9c405edae16d186f02c632113de1317c89703991
Signed-off-by: Cédric Ollivier <cedric.ollivier@orange.com>
import json
import logging
import os
import json
import logging
import os
from functools import wraps
import requests
from functools import wraps
import requests
# Singleton pattern for energy_recorder_api static member
# Load only if not previouly done
if EnergyRecorder.energy_recorder_api is None:
# Singleton pattern for energy_recorder_api static member
# Load only if not previouly done
if EnergyRecorder.energy_recorder_api is None:
+ assert os.environ['NODE_NAME']
+ assert os.environ["ENERGY_RECORDER_API_URL"]
environment = os.environ['NODE_NAME']
environment = os.environ['NODE_NAME']
- assert environment
-
- # API URL
energy_recorder_uri = os.environ["ENERGY_RECORDER_API_URL"]
energy_recorder_uri = os.environ["ENERGY_RECORDER_API_URL"]
- assert energy_recorder_uri
# Creds
creds_usr = os.environ.get("ENERGY_RECORDER_API_USER", "")
# Creds
creds_usr = os.environ.get("ENERGY_RECORDER_API_USER", "")
except Exception: # pylint: disable=broad-except
# Default exception handler to ensure that method
# is safe for caller
except Exception: # pylint: disable=broad-except
# Default exception handler to ensure that method
# is safe for caller
- EnergyRecorder.logger.exception(
- "Error while submitting scenarion to energy recorder API"
+ EnergyRecorder.logger.info(
+ "Error while submitting scenarion to energy recorder API\n%s",
+ traceback.format_exc()
)
return_status = False
return return_status
)
return_status = False
return return_status
except Exception: # pylint: disable=broad-except
# Default exception handler to ensure that method
# is safe for caller
except Exception: # pylint: disable=broad-except
# Default exception handler to ensure that method
# is safe for caller
- EnergyRecorder.logger.exception(
- "Error while starting energy recorder API"
+ EnergyRecorder.logger.info(
+ "Error while starting energy recorder API\n%s",
+ traceback.format_exc()
)
return_status = False
return return_status
)
return_status = False
return return_status
except Exception: # pylint: disable=broad-except
# Default exception handler to ensure that method
# is safe for caller
except Exception: # pylint: disable=broad-except
# Default exception handler to ensure that method
# is safe for caller
- EnergyRecorder.logger.exception(
- "Error while stoping energy recorder API"
+ EnergyRecorder.logger.info(
+ "Error while stoping energy recorder API\n%s",
+ traceback.format_exc()
)
return_status = False
return return_status
)
return_status = False
return return_status
except Exception: # pylint: disable=broad-except
# Default exception handler to ensure that method
# is safe for caller
except Exception: # pylint: disable=broad-except
# Default exception handler to ensure that method
# is safe for caller
- EnergyRecorder.logger.exception(
- "Error while setting step on energy recorder API"
+ EnergyRecorder.logger.info(
+ "Error while setting step on energy recorder API\n%s",
+ traceback.format_exc()
)
return_status = False
return return_status
)
return_status = False
return return_status
except Exception: # pylint: disable=broad-except
# Default exception handler to ensure that method
# is safe for caller
except Exception: # pylint: disable=broad-except
# Default exception handler to ensure that method
# is safe for caller
- EnergyRecorder.logger.exception(
+ EnergyRecorder.logger.info(
"Error while getting current scenario from energy recorder API"
"Error while getting current scenario from energy recorder API"
+ "\n%s", traceback.format_exc()
)
return_value = None
return return_value
)
return_value = None
return return_value