docker-cmd hook handle empty config file

Early in a server boot the file /var/run/heat-config/heat-config may
exist but be empty. This causes a stack trace to be raised in this
script.

This change detects a json parse error and exits gracefully.

Change-Id: I29d731098659bfbf10a2caf80c2cfc49de5df4cc
Closes-Bug: #1648249
This commit is contained in:
Steve Baker 2016-12-08 12:25:06 +13:00
parent 8ab13c5489
commit d10069ac13
2 changed files with 6 additions and 5 deletions

View File

@ -45,7 +45,7 @@ def main(argv=sys.argv):
log.setLevel('DEBUG') log.setLevel('DEBUG')
if not os.path.exists(CONF_FILE): if not os.path.exists(CONF_FILE):
log.error('No config file %s' % CONF_FILE) log.warning('No config file %s' % CONF_FILE)
return 1 return 1
if not os.path.isdir(WORKING_DIR): if not os.path.isdir(WORKING_DIR):
@ -53,8 +53,9 @@ def main(argv=sys.argv):
try: try:
configs = json.load(open(CONF_FILE)) configs = json.load(open(CONF_FILE))
except ValueError: except ValueError as e:
pass log.warning('Could not load config json: %s' % e)
return 1
cmd_configs = list(build_configs(configs)) cmd_configs = list(build_configs(configs))
try: try:

View File

@ -22,7 +22,7 @@ from testtools import matchers
from tests.software_config import common from tests.software_config import common
class HookDockerComposeTest(common.RunScriptTest): class HookDockerCmdTest(common.RunScriptTest):
data = { data = {
"name": "abcdef001", "name": "abcdef001",
"group": "docker-cmd", "group": "docker-cmd",
@ -52,7 +52,7 @@ class HookDockerComposeTest(common.RunScriptTest):
} }
def setUp(self): def setUp(self):
super(HookDockerComposeTest, self).setUp() super(HookDockerCmdTest, self).setUp()
self.hook_path = self.relative_path( self.hook_path = self.relative_path(
__file__, __file__,
'../..', '../..',