diff options
author | George Kraft <george.kraft@calxeda.com> | 2012-07-17 14:29:36 -0500 |
---|---|---|
committer | George Kraft <george.kraft@calxeda.com> | 2012-07-17 14:29:36 -0500 |
commit | f0b32dfcd2cf183f4f4dff5c153a7ecf01f0b02d (patch) | |
tree | 730e9652fead3030177715d88fa487e4f51a0ac3 | |
parent | 42772ca86d43ad25cd30dca02b1c6df20006cb1e (diff) | |
download | cxmanage-f0b32dfcd2cf183f4f4dff5c153a7ecf01f0b02d.tar.gz |
controller: Add threading back in for ipmitool command
Output no longer overlaps, however.
-rw-r--r-- | cxmanage/controller.py | 46 | ||||
-rw-r--r-- | cxmanage/target.py | 2 | ||||
-rw-r--r-- | cxmanage_test/controller_test.py | 1 |
3 files changed, 40 insertions, 9 deletions
diff --git a/cxmanage/controller.py b/cxmanage/controller.py index bfd599a..292c978 100644 --- a/cxmanage/controller.py +++ b/cxmanage/controller.py @@ -491,17 +491,47 @@ class Controller: def ipmitool_command(self, ipmitool_args): """ Run an arbitrary ipmitool command on all targets """ - errors = {} + threads = set() + error_encountered = False + for target in self.targets: - try: - target.ipmitool_command(ipmitool_args) - except Exception as e: - errors[target.address] = e + # Wait while we have too many running threads + while len(threads) >= self.max_threads: + time.sleep(0.001) + for thread in threads: + if not thread.is_alive(): + threads.remove(thread) + print "[ %s ]" % thread.target.address + if thread.error == None: + print thread.result.rstrip().lstrip() + else: + print thread.error + error_encountered = True + print + break - # Print errors - self._print_errors(errors) + # Start the new thread + thread = ControllerCommandThread(target, + "ipmitool_command", (ipmitool_args,)) + thread.start() + threads.add(thread) - return len(errors) > 0 + # Join with any remaining threads + while len(threads) > 0: + time.sleep(0.001) + for thread in threads: + if not thread.is_alive(): + threads.remove(thread) + print "[ %s ]" % thread.target.address + if thread.error == None: + print thread.result.rstrip().lstrip() + else: + print thread.error + error_encountered = True + print + break + + return error_encountered def _run_command(self, name, *args): """ Run a target command with multiple threads diff --git a/cxmanage/target.py b/cxmanage/target.py index ae08aba..9b46fae 100644 --- a/cxmanage/target.py +++ b/cxmanage/target.py @@ -314,7 +314,7 @@ class Target: if self.verbosity >= 2: print "Running %s" % " ".join(command) - subprocess.call(command) + return subprocess.check_output(command, stderr=subprocess.STDOUT) def _get_slot(self, fwinfo, image_type, slot_arg): """ Get a slot for this image type based on the slot argument """ diff --git a/cxmanage_test/controller_test.py b/cxmanage_test/controller_test.py index 6ede75f..5c131ce 100644 --- a/cxmanage_test/controller_test.py +++ b/cxmanage_test/controller_test.py @@ -337,6 +337,7 @@ class DummyTarget: def ipmitool_command(self, ipmitool_args): self.executed.append(("ipmitool_command", ipmitool_args)) + return "Dummy output" class DummyImage: |