Fix: Instantiate the same NS without emulator restart

Fixes a bug that causes the emulator to not properly clean
its internal data structures when a NS is deleted. This could
cause errors when a NS should be instantiated again, without
restarting the emulator.

Change-Id: I8a0be1f28b889f2c01e7ef859acd6bdcc35b8b9d
Signed-off-by: peusterm <manuel.peuster@uni-paderborn.de>
diff --git a/src/emuvim/api/openstack/compute.py b/src/emuvim/api/openstack/compute.py
index 42f0064..7ba52f1 100755
--- a/src/emuvim/api/openstack/compute.py
+++ b/src/emuvim/api/openstack/compute.py
@@ -585,12 +585,10 @@
         if server is None:
             return False
         name_parts = server.name.split('_')
-        if len(name_parts) < 3:
-            return False
-
-        for stack in self.stacks.values():
-            if stack.stack_name == name_parts[1]:
-                stack.servers.pop(server.id, None)
+        if len(name_parts) > 1:
+            for stack in self.stacks.values():
+                if stack.stack_name == name_parts[1]:
+                    stack.servers.pop(server.id, None)
         if self.computeUnits.pop(server.id, None) is None:
             return False
         return True
diff --git a/src/emuvim/api/openstack/openstack_dummies/neutron_dummy_api.py b/src/emuvim/api/openstack/openstack_dummies/neutron_dummy_api.py
index 3b1ceda..7386e63 100755
--- a/src/emuvim/api/openstack/openstack_dummies/neutron_dummy_api.py
+++ b/src/emuvim/api/openstack/openstack_dummies/neutron_dummy_api.py
@@ -527,6 +527,7 @@
 
             net.subnet_name = subnet_dict["subnet"].get('name', str(net.name) + '-sub')
             if net.subnet_id is not None:
+                LOG.error("Only one subnet per network is supported: {}".format(net.subnet_id))
                 return Response('Only one subnet per network is supported\n', status=409, mimetype='application/json')
 
             if "id" in subnet_dict["subnet"]:
@@ -627,6 +628,9 @@
                     for server in self.api.compute.computeUnits.values():
                         for port_name in server.port_names:
                             port = self.api.compute.find_port_by_name_or_id(port_name)
+                            if port is None:
+                                LOG.warning("Port search for {} returned None.".format(port_name))
+                                continue
                             if port.net_name == net.name:
                                 port.ip_address = None
                                 self.api.compute.dc.net.removeLink(
diff --git a/src/emuvim/api/openstack/openstack_dummies/nova_dummy_api.py b/src/emuvim/api/openstack/openstack_dummies/nova_dummy_api.py
index 3409436..9dcfa48 100755
--- a/src/emuvim/api/openstack/openstack_dummies/nova_dummy_api.py
+++ b/src/emuvim/api/openstack/openstack_dummies/nova_dummy_api.py
@@ -226,6 +226,7 @@
             name = str(self.api.compute.dc.label) + "_" + server_dict["name"]
 
             if self.api.compute.find_server_by_name_or_id(name) is not None:
+                LOG.error("Server with name %s already exists. 409" % name)
                 return Response("Server with name %s already exists." % name, status=409)
             # TODO: not finished!
             resp = dict()