Check for uBridge version and catch uBridge errors.

This commit is contained in:
Jeremy 2015-07-21 17:58:53 -06:00
parent f0649b4ac3
commit fc0409286b
4 changed files with 30 additions and 7 deletions

View File

@ -28,6 +28,7 @@ import tempfile
from pkg_resources import parse_version from pkg_resources import parse_version
from gns3server.ubridge.hypervisor import Hypervisor from gns3server.ubridge.hypervisor import Hypervisor
from gns3server.ubridge.ubridge_error import UbridgeError
from gns3server.utils.telnet_server import TelnetServer from gns3server.utils.telnet_server import TelnetServer
from gns3server.utils.interfaces import get_windows_interfaces from gns3server.utils.interfaces import get_windows_interfaces
from collections import OrderedDict from collections import OrderedDict
@ -357,6 +358,8 @@ class VMwareVM(BaseVM):
if not ubridge_path or not os.path.isfile(ubridge_path): if not ubridge_path or not os.path.isfile(ubridge_path):
raise VMwareError("ubridge is necessary to start a VMware VM") raise VMwareError("ubridge is necessary to start a VMware VM")
yield from self._start_ubridge()
try: try:
self._vmx_pairs = self.manager.parse_vmware_file(self._vmx_path) self._vmx_pairs = self.manager.parse_vmware_file(self._vmx_path)
except OSError as e: except OSError as e:
@ -375,7 +378,6 @@ class VMwareVM(BaseVM):
else: else:
yield from self._control_vm("start") yield from self._control_vm("start")
yield from self._start_ubridge()
for adapter_number in range(0, self._adapters): for adapter_number in range(0, self._adapters):
nio = self._ethernet_adapters[adapter_number].get_nio(0) nio = self._ethernet_adapters[adapter_number].get_nio(0)
if nio: if nio:

View File

@ -27,16 +27,16 @@ import signal
import re import re
import asyncio import asyncio
import shutil import shutil
import gns3server.utils.asyncio
from gns3server.utils.asyncio import wait_for_process_termination
from gns3server.utils.asyncio import monitor_process
from gns3server.utils.asyncio import subprocess_check_output
from pkg_resources import parse_version from pkg_resources import parse_version
from .vpcs_error import VPCSError from .vpcs_error import VPCSError
from ..adapters.ethernet_adapter import EthernetAdapter from ..adapters.ethernet_adapter import EthernetAdapter
from ..nios.nio_udp import NIOUDP from ..nios.nio_udp import NIOUDP
from ..nios.nio_tap import NIOTAP from ..nios.nio_tap import NIOTAP
from ..base_vm import BaseVM from ..base_vm import BaseVM
from ...utils.asyncio import subprocess_check_output, monitor_process
import logging import logging
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
@ -268,7 +268,7 @@ class VPCSVM(BaseVM):
self._terminate_process() self._terminate_process()
if self._process.returncode is None: if self._process.returncode is None:
try: try:
yield from gns3server.utils.asyncio.wait_for_process_termination(self._process, timeout=3) yield from wait_for_process_termination(self._process, timeout=3)
except asyncio.TimeoutError: except asyncio.TimeoutError:
if self._process.returncode is None: if self._process.returncode is None:
log.warn("VPCS process {} is still running... killing it".format(self._process.pid)) log.warn("VPCS process {} is still running... killing it".format(self._process.pid))

View File

@ -23,9 +23,12 @@ import os
import subprocess import subprocess
import asyncio import asyncio
import socket import socket
import re
from pkg_resources import parse_version
from gns3server.utils.asyncio import wait_for_process_termination from gns3server.utils.asyncio import wait_for_process_termination
from gns3server.utils.asyncio import monitor_process from gns3server.utils.asyncio import monitor_process
from gns3server.utils.asyncio import subprocess_check_output
from .ubridge_hypervisor import UBridgeHypervisor from .ubridge_hypervisor import UBridgeHypervisor
from .ubridge_error import UbridgeError from .ubridge_error import UbridgeError
@ -114,14 +117,31 @@ class Hypervisor(UBridgeHypervisor):
self._path = path self._path = path
@asyncio.coroutine
def _check_ubridge_version(self):
"""
Checks if the ubridge executable version is >= 0.9.1
"""
try:
output = yield from subprocess_check_output(self._path, "-v", cwd=self._working_dir)
match = re.search("ubridge version ([0-9a-z\.]+)", output)
if match:
version = match.group(1)
if parse_version(version) < parse_version("0.9.1"):
raise UbridgeError("uBridge executable version must be >= 0.9.1")
else:
raise UbridgeError("Could not determine uBridge version for {}".format(self._path))
except (OSError, subprocess.SubprocessError) as e:
raise UbridgeError("Error while looking for uBridge version: {}".format(e))
@asyncio.coroutine @asyncio.coroutine
def start(self): def start(self):
""" """
Starts the uBridge hypervisor process. Starts the uBridge hypervisor process.
""" """
yield from self._check_ubridge_version()
try: try:
# self._update_ubridge_config()
command = self._build_command() command = self._build_command()
log.info("starting ubridge: {}".format(command)) log.info("starting ubridge: {}".format(command))
self._stdout_file = os.path.join(self._working_dir, "ubridge.log") self._stdout_file = os.path.join(self._working_dir, "ubridge.log")

View File

@ -26,6 +26,7 @@ import traceback
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
from ..modules.vm_error import VMError from ..modules.vm_error import VMError
from ..ubridge.ubridge_error import UbridgeError
from .response import Response from .response import Response
from ..crash_report import CrashReport from ..crash_report import CrashReport
from ..config import Config from ..config import Config
@ -179,7 +180,7 @@ class Route(object):
response = Response(request=request, route=route) response = Response(request=request, route=route)
response.set_status(e.status) response.set_status(e.status)
response.json({"message": e.text, "status": e.status}) response.json({"message": e.text, "status": e.status})
except VMError as e: except (VMError, UbridgeError) as e:
log.error("VM error detected: {type}".format(type=type(e)), exc_info=1) log.error("VM error detected: {type}".format(type=type(e)), exc_info=1)
response = Response(request=request, route=route) response = Response(request=request, route=route)
response.set_status(409) response.set_status(409)