diff options
author | Tim Smith <tsmith@chef.io> | 2019-06-25 14:45:03 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-06-25 14:45:03 -0700 |
commit | 553abb17f39e378ef1572ee7f7044afe5c439943 (patch) | |
tree | de19e004fc415bfb729c48f2fed639710ff3487a | |
parent | aad97f389c0b7a164e67bef5ab7e928a0f914885 (diff) | |
parent | 0d71053a8ee7678c42ac04661dd31ef9c693b6ff (diff) | |
download | chef-553abb17f39e378ef1572ee7f7044afe5c439943.tar.gz |
Merge pull request #8692 from chef/lcg/yum-exception-handling
yum_package: Better handle yum exceptions in our helper so we always close the rpmdb
-rw-r--r-- | lib/chef/provider/package/yum/yum_helper.py | 53 |
1 files changed, 29 insertions, 24 deletions
diff --git a/lib/chef/provider/package/yum/yum_helper.py b/lib/chef/provider/package/yum/yum_helper.py index 7e99951555..47cbe2efe6 100644 --- a/lib/chef/provider/package/yum/yum_helper.py +++ b/lib/chef/provider/package/yum/yum_helper.py @@ -169,7 +169,8 @@ def query(command): # to keep process tables clean. additional error handling should probably be added to the retry loop # on the ruby side. def exit_handler(signal, frame): - base.closeRpmDB() + if base is not None: + base.closeRpmDB() sys.exit(0) def setup_exit_handler(): @@ -185,27 +186,31 @@ else: inpipe = os.fdopen(int(sys.argv[1]), "r") outpipe = os.fdopen(int(sys.argv[2]), "w") -while 1: - # kill self if we get orphaned (tragic) - ppid = os.getppid() - if ppid == 1: - sys.exit(0) - setup_exit_handler() - line = inpipe.readline() - - try: - command = json.loads(line) - except ValueError, e: +try: + while 1: + # kill self if we get orphaned (tragic) + ppid = os.getppid() + if ppid == 1: + raise RuntimeError("orphaned") + + setup_exit_handler() + line = inpipe.readline() + + try: + command = json.loads(line) + except ValueError, e: + raise RuntimeError("bad json parse") + + if command['action'] == "whatinstalled": + query(command) + elif command['action'] == "whatavailable": + query(command) + elif command['action'] == "versioncompare": + versioncompare(command['versions']) + elif command['action'] == "installonlypkgs": + install_only_packages(command['package']) + else: + raise RuntimeError("bad command") +finally: + if base is not None: base.closeRpmDB() - sys.exit(0) - - if command['action'] == "whatinstalled": - query(command) - elif command['action'] == "whatavailable": - query(command) - elif command['action'] == "versioncompare": - versioncompare(command['versions']) - elif command['action'] == "installonlypkgs": - install_only_packages(command['package']) - else: - raise RuntimeError("bad command") |