From 1524493c33f019c6719165f6d89c594cca5ea492 Mon Sep 17 00:00:00 2001 From: grossmj Date: Thu, 12 Oct 2017 23:32:45 +0800 Subject: [PATCH] Fix IOU detection of layer 1 keepalive support. Fixes #1183. --- gns3server/compute/iou/iou_vm.py | 4 ++-- gns3server/utils/asyncio/__init__.py | 12 ++++++++---- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/gns3server/compute/iou/iou_vm.py b/gns3server/compute/iou/iou_vm.py index 890bbc63..542a850d 100644 --- a/gns3server/compute/iou/iou_vm.py +++ b/gns3server/compute/iou/iou_vm.py @@ -945,13 +945,13 @@ class IOUVM(BaseNode): if "IOURC" not in os.environ: env["IOURC"] = self.iourc_path try: - output = yield from gns3server.utils.asyncio.subprocess_check_output(self._path, "-h", cwd=self.working_dir, env=env) + output = yield from gns3server.utils.asyncio.subprocess_check_output(self._path, "-h", cwd=self.working_dir, env=env, stderr=True) if re.search("-l\s+Enable Layer 1 keepalive messages", output): command.extend(["-l"]) else: raise IOUError("layer 1 keepalive messages are not supported by {}".format(os.path.basename(self._path))) except (OSError, subprocess.SubprocessError) as e: - log.warn("could not determine if layer 1 keepalive messages are supported by {}: {}".format(os.path.basename(self._path), e)) + log.warning("could not determine if layer 1 keepalive messages are supported by {}: {}".format(os.path.basename(self._path), e)) @property def startup_config_content(self): diff --git a/gns3server/utils/asyncio/__init__.py b/gns3server/utils/asyncio/__init__.py index 2046f6a6..34e7571c 100644 --- a/gns3server/utils/asyncio/__init__.py +++ b/gns3server/utils/asyncio/__init__.py @@ -41,18 +41,23 @@ def wait_run_in_executor(func, *args, **kwargs): @asyncio.coroutine -def subprocess_check_output(*args, cwd=None, env=None): +def subprocess_check_output(*args, cwd=None, env=None, stderr=False): """ Run a command and capture output :param *args: List of command arguments :param cwd: Current working directory :param env: Command environment + :param stderr: Read on stderr :returns: Command output """ - proc = yield from asyncio.create_subprocess_exec(*args, stdout=asyncio.subprocess.PIPE, cwd=cwd, env=env) - output = yield from proc.stdout.read() + if stderr: + proc = yield from asyncio.create_subprocess_exec(*args, stderr=asyncio.subprocess.PIPE, cwd=cwd, env=env) + output = yield from proc.stderr.read() + else: + proc = yield from asyncio.create_subprocess_exec(*args, stdout=asyncio.subprocess.PIPE, cwd=cwd, env=env) + output = yield from proc.stdout.read() if output is None: return "" # If we received garbage we ignore invalid characters @@ -60,7 +65,6 @@ def subprocess_check_output(*args, cwd=None, env=None): # and the code of VPCS, dynamips... Will detect it's not the correct binary return output.decode("utf-8", errors="ignore") - @asyncio.coroutine def wait_for_process_termination(process, timeout=10): """