Revision 6bb65e3a lib/backend.py
b/lib/backend.py | ||
---|---|---|
40 | 40 |
import stat |
41 | 41 |
import errno |
42 | 42 |
import re |
43 |
import subprocess |
|
44 | 43 |
import random |
45 | 44 |
import logging |
46 | 45 |
import tempfile |
... | ... | |
2666 | 2665 |
else: |
2667 | 2666 |
_Fail("Unknown hooks phase '%s'", phase) |
2668 | 2667 |
|
2669 |
rr = [] |
|
2670 | 2668 |
|
2671 | 2669 |
subdir = "%s-%s.d" % (hpath, suffix) |
2672 | 2670 |
dir_name = "%s/%s" % (self._BASE_DIR, subdir) |
2673 |
try: |
|
2674 |
dir_contents = utils.ListVisibleFiles(dir_name) |
|
2675 |
except OSError: |
|
2676 |
# FIXME: must log output in case of failures |
|
2677 |
return rr |
|
2678 |
|
|
2679 |
# we use the standard python sort order, |
|
2680 |
# so 00name is the recommended naming scheme |
|
2681 |
dir_contents.sort() |
|
2682 |
for relname in dir_contents: |
|
2683 |
fname = os.path.join(dir_name, relname) |
|
2684 |
if not (os.path.isfile(fname) and os.access(fname, os.X_OK) and |
|
2685 |
constants.EXT_PLUGIN_MASK.match(relname) is not None): |
|
2671 |
runparts_results = utils.RunParts(dir_name, env=env, reset_env=True) |
|
2672 |
|
|
2673 |
results = [] |
|
2674 |
for (relname, relstatus, runresult) in runparts_results: |
|
2675 |
if relstatus == constants.RUNPARTS_SKIP: |
|
2686 | 2676 |
rrval = constants.HKR_SKIP |
2687 | 2677 |
output = "" |
2688 |
else: |
|
2689 |
try: |
|
2690 |
result = utils.RunCmd([fname], env=env, reset_env=True) |
|
2691 |
except (OpExecError, EnvironmentError), err: |
|
2678 |
elif relstatus == constants.RUNPARTS_ERR: |
|
2679 |
rrval = constants.HKR_FAIL |
|
2680 |
output = "Hook script execution error: %s" % runresult |
|
2681 |
elif relstatus == constants.RUNPARTS_RUN: |
|
2682 |
if runresult.failed: |
|
2692 | 2683 |
rrval = constants.HKR_FAIL |
2693 |
output = "Hook script error: %s" % str(err) |
|
2694 | 2684 |
else: |
2695 |
if result.failed: |
|
2696 |
rrval = constants.HKR_FAIL |
|
2697 |
else: |
|
2698 |
rrval = constants.HKR_SUCCESS |
|
2699 |
output = utils.SafeEncode(result.output.strip()) |
|
2700 |
rr.append(("%s/%s" % (subdir, relname), rrval, output)) |
|
2701 |
|
|
2702 |
return rr |
|
2685 |
rrval = constants.HKR_SUCCESS |
|
2686 |
output = utils.SafeEncode(runresult.output.strip()) |
|
2687 |
results.append(("%s/%s" % (subdir, relname), rrval, output)) |
|
2688 |
|
|
2689 |
return results |
|
2703 | 2690 |
|
2704 | 2691 |
|
2705 | 2692 |
class IAllocatorRunner(object): |
Also available in: Unified diff