Rewrite test_hook_docker_cmd to avoid paunch internals

This test breaks frequently as it is asserting the docker calls which
paunch is making internally. These calls are changing often, as paunch
is in active development.

This change rewrites the test to be a unit test of hook-docker-cmd.py
specifically, with calls to paunch.apply mocked out.

Change-Id: Ieeef3e5916e46d006a358f132bbd64f3960e1fcd
Task: 36342
This commit is contained in:
Steve Baker 2019-08-26 11:40:21 +12:00
parent a6b1984711
commit 9a399e7c35
3 changed files with 98 additions and 954 deletions

View File

@ -35,23 +35,23 @@ def build_response(deploy_stdout, deploy_stderr, deploy_status_code):
}
def main(argv=sys.argv):
def main(argv=sys.argv, stdin=sys.stdin, stdout=sys.stdout, stderr=sys.stderr):
global log
log = logging.getLogger('heat-config')
handler = logging.StreamHandler(sys.stderr)
handler = logging.StreamHandler(stderr)
handler.setFormatter(
logging.Formatter(
'[%(asctime)s] (%(name)s) [%(levelname)s] %(message)s'))
log.addHandler(handler)
log.setLevel('DEBUG')
c = json.load(sys.stdin)
c = json.load(stdin)
input_values = dict((i['name'], i['value']) for i in c.get('inputs', {}))
if input_values.get('deploy_action') == 'DELETE':
json.dump(build_response(
'', '', 0), sys.stdout)
'', '', 0), stdout)
return
config = c.get('config', '')
@ -59,11 +59,9 @@ def main(argv=sys.argv):
if not config:
log.debug("No 'config' input found, nothing to do.")
json.dump(build_response(
'', '', 0), sys.stdout)
'', '', 0), stdout)
return
stdout = []
stderr = []
deploy_status_code = 0
# convert config to dict
@ -73,7 +71,7 @@ def main(argv=sys.argv):
labels = collections.OrderedDict()
labels['deploy_stack_id'] = input_values.get('deploy_stack_id')
labels['deploy_resource_name'] = input_values.get('deploy_resource_name')
stdout, stderr, deploy_status_code = paunch.apply(
apply_stdout, apply_stderr, deploy_status_code = paunch.apply(
cid,
config,
'docker-cmd',
@ -82,7 +80,9 @@ def main(argv=sys.argv):
)
json.dump(build_response(
'\n'.join(stdout), '\n'.join(stderr), deploy_status_code), sys.stdout)
'\n'.join(apply_stdout),
'\n'.join(apply_stderr),
deploy_status_code), stdout)
if __name__ == '__main__':
sys.exit(main(sys.argv))

1
tests/hook_docker_cmd.py Symbolic link
View File

@ -0,0 +1 @@
../heat-config-docker-cmd/install.d/hook-docker-cmd.py

File diff suppressed because it is too large Load Diff