Fix: Instantiate the same NS without emulator restart 24/6024/1
authorpeusterm <manuel.peuster@uni-paderborn.de>
Tue, 24 Apr 2018 14:52:51 +0000 (16:52 +0200)
committerpeusterm <manuel.peuster@uni-paderborn.de>
Tue, 24 Apr 2018 14:52:51 +0000 (16:52 +0200)
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>
src/emuvim/api/openstack/compute.py
src/emuvim/api/openstack/openstack_dummies/neutron_dummy_api.py
src/emuvim/api/openstack/openstack_dummies/nova_dummy_api.py

index 42f0064..7ba52f1 100755 (executable)
@@ -585,12 +585,10 @@ class OpenstackCompute(object):
         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
index 3b1ceda..7386e63 100755 (executable)
@@ -527,6 +527,7 @@ class NeutronCreateSubnet(Resource):
 
             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 @@ class NeutronDeleteSubnet(Resource):
                     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(
index 3409436..9dcfa48 100755 (executable)
@@ -226,6 +226,7 @@ class NovaListServersApi(Resource):
             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()