From 7065988087720e334b307ddde457f1eefb4de008 Mon Sep 17 00:00:00 2001 From: Julien Duponchelle Date: Tue, 30 Aug 2016 18:27:04 +0200 Subject: [PATCH] Raise an error if we use nat and eth1 doesn't exists Fix #657 --- gns3server/compute/builtin/nodes/nat.py | 5 +++++ tests/conftest.py | 5 +++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/gns3server/compute/builtin/nodes/nat.py b/gns3server/compute/builtin/nodes/nat.py index b54e78d6..b2c053f8 100644 --- a/gns3server/compute/builtin/nodes/nat.py +++ b/gns3server/compute/builtin/nodes/nat.py @@ -19,6 +19,8 @@ import socket from .cloud import Cloud from ...error import NodeError +import gns3server.utils.interfaces + class Nat(Cloud): """ @@ -32,6 +34,9 @@ class Nat(Cloud): if socket.gethostname() != "gns3vm": raise NodeError("NAT node is supported only on GNS3 VM") + if "eth1" not in [interface["name"] for interface in gns3server.utils.interfaces.interfaces()]: + raise NodeError("eth1 is missing on the GNS3 VM. You need to provide a nat interface as eth1") + self.ports = [ { "name": "nat0", diff --git a/tests/conftest.py b/tests/conftest.py index 2d08f0e6..a3c2d00f 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -322,5 +322,6 @@ def on_gns3vm(): """ Mock the hostname to emulate the GNS3 VM """ - with patch("socket.gethostname", return_value="gns3vm"): - yield + with patch("gns3server.utils.interfaces.interfaces", return_value=[{"name": "eth0"}, {"name": "eth1"}]): + with patch("socket.gethostname", return_value="gns3vm"): + yield