diff --git a/systemvm/patches/debian/config/opt/cloud/bin/cs/CsConfig.py b/systemvm/patches/debian/config/opt/cloud/bin/cs/CsConfig.py index e3b900912fd..e242a8fc32e 100755 --- a/systemvm/patches/debian/config/opt/cloud/bin/cs/CsConfig.py +++ b/systemvm/patches/debian/config/opt/cloud/bin/cs/CsConfig.py @@ -26,7 +26,7 @@ class CsConfig(object): A class to cache all the stuff that the other classes need """ __LOG_FILE = "/var/log/cloud.log" - __LOG_LEVEL = "DEBUG" + __LOG_LEVEL = "INFO" __LOG_FORMAT = "%(asctime)s %(levelname)-8s %(message)s" cl = None diff --git a/systemvm/patches/debian/config/opt/cloud/bin/merge.py b/systemvm/patches/debian/config/opt/cloud/bin/merge.py index e6ca8586eea..0c85461f94e 100755 --- a/systemvm/patches/debian/config/opt/cloud/bin/merge.py +++ b/systemvm/patches/debian/config/opt/cloud/bin/merge.py @@ -47,28 +47,29 @@ class DataBag: data = self.bdata if not os.path.exists(self.DPATH): os.makedirs(self.DPATH) - self.fpath = self.DPATH + '/' + self.key + '.json' + self.fpath = os.path.join(self.DPATH, self.key + '.json') + try: - handle = open(self.fpath) + with open(self.fpath, 'r') as _fh: + logging.debug("Loading data bag type %s", self.key) + data = json.load(_fh) except IOError: logging.debug("Creating data bag type %s", self.key) data.update({"id": self.key}) - else: - logging.debug("Loading data bag type %s", self.key) - data = json.load(handle) - handle.close() - self.dbag = data + finally: + self.dbag = data def save(self, dbag): try: - handle = open(self.fpath, 'w') + with open(self.fpath, 'w') as _fh: + logging.debug("Writing data bag type %s", self.key) + json.dump( + dbag, _fh, + sort_keys=True, + indent=2 + ) except IOError: logging.error("Could not write data bag %s", self.key) - else: - logging.debug("Writing data bag type %s", self.key) - logging.debug(dbag) - jsono = json.dumps(dbag, indent=4, sort_keys=True) - handle.write(jsono) def getDataBag(self): return self.dbag diff --git a/systemvm/patches/debian/config/opt/cloud/bin/update_config.py b/systemvm/patches/debian/config/opt/cloud/bin/update_config.py index 9ec3f872785..620d042ef1a 100755 --- a/systemvm/patches/debian/config/opt/cloud/bin/update_config.py +++ b/systemvm/patches/debian/config/opt/cloud/bin/update_config.py @@ -27,7 +27,7 @@ import configure import json from cs.CsVmPassword import * -logging.basicConfig(filename='/var/log/cloud.log', level=logging.DEBUG, format='%(asctime)s %(filename)s %(funcName)s:%(lineno)d %(message)s') +logging.basicConfig(filename='/var/log/cloud.log', level=logging.INFO, format='%(asctime)s %(filename)s %(funcName)s:%(lineno)d %(message)s') # first commandline argument should be the file to process if (len(sys.argv) != 2):