Explorar el Código

Fixed openstack test failures

Nuwan Goonasekera hace 8 años
padre
commit
66297892d6

+ 8 - 2
cloudbridge/cloud/providers/openstack/resources.py

@@ -326,6 +326,11 @@ class OpenStackInstance(BaseInstance):
         """
         Permanently terminate this instance.
         """
+        # delete the port we created when launching
+        # Assumption: it's the first interface in the list
+        iface_list = self._os_instance.interface_list()
+        if iface_list:
+            self._provider.neutron.delete_port(iface_list[0].port_id)
         self._os_instance.delete()
 
     @property
@@ -883,6 +888,7 @@ class OpenStackRouter(BaseRouter):
         if self.is_valid_resource_name(value):
             self._provider.neutron.update_router(
                 self.id, {'router': {'name': value}})
+            self.refresh()
         else:
             raise InvalidNameException(value)
 
@@ -922,11 +928,11 @@ class OpenStackRouter(BaseRouter):
         return False
 
     def attach_gateway(self, gateway):
-        self._router = self._provider.neutron.add_gateway_router(
+        self._provider.neutron.add_gateway_router(
             self.id, {'network_id': gateway.id})
 
     def detach_gateway(self, gateway):
-        self._router = self._provider.neutron.remove_gateway_router(
+        self._provider.neutron.remove_gateway_router(
             self.id).get('router', self._router)
 
 

+ 1 - 1
cloudbridge/cloud/providers/openstack/services.py

@@ -839,7 +839,7 @@ class OpenStackSubnetService(BaseSubnetService):
             sn = net.create_subnet(name=OpenStackSubnet.CB_DEFAULT_SUBNET_NAME,
                                    cidr_block='10.0.0.0/24')
             router = self.provider.networking.routers.create(
-                OpenStackRouter.CB_DEFAULT_ROUTER_NAME)
+                network=net, name=OpenStackRouter.CB_DEFAULT_ROUTER_NAME)
             router.attach_subnet(sn)
             gteway = (self.provider.networking.gateways
                       .get_or_create_inet_gateway(

+ 9 - 4
test/test_compute_service.py

@@ -318,13 +318,14 @@ class CloudComputeServiceTestCase(ProviderTestBase):
             router = self.provider.networking.routers.create(name, net)
             gateway = None
 
-            def cleanup_router():
+            def cleanup_router(router, gateway):
                 with helpers.cleanup_action(lambda: router.delete()):
                     with helpers.cleanup_action(lambda: gateway.delete()):
                         router.detach_subnet(subnet)
                         router.detach_gateway(gateway)
 
-            with helpers.cleanup_action(lambda: cleanup_router()):
+            with helpers.cleanup_action(lambda: cleanup_router(router,
+                                                               gateway)):
                 router.attach_subnet(subnet)
                 gateway = (self.provider.networking.gateways
                            .get_or_create_inet_gateway(name))
@@ -335,11 +336,15 @@ class CloudComputeServiceTestCase(ProviderTestBase):
                 with helpers.cleanup_action(lambda: fip.delete()):
                     test_inst.add_floating_ip(fip.public_ip)
                     test_inst.refresh()
-                    self.assertIn(fip.public_ip, test_inst.public_ips)
+                    # On Devstack, the floating IP is listed under private_ips.
+                    self.assertIn(fip.public_ip,
+                                  test_inst.public_ips + test_inst.private_ips)
                     if isinstance(self.provider, TestMockHelperMixin):
                         # TODO: Moto bug does not refresh removed public ip
                         return
                     # check whether removing an elastic ip works
                     test_inst.remove_floating_ip(fip.public_ip)
                     test_inst.refresh()
-                    self.assertNotIn(fip.public_ip, test_inst.public_ips)
+                    self.assertNotIn(
+                        fip.public_ip,
+                        test_inst.public_ips + test_inst.private_ips)