Kaynağa Gözat

Fixed routing in test and improved cleanup

Nuwan Goonasekera 9 yıl önce
ebeveyn
işleme
736f31c2b4
1 değiştirilmiş dosya ile 22 ekleme ve 15 silme
  1. 22 15
      test/test_compute_service.py

+ 22 - 15
test/test_compute_service.py

@@ -384,18 +384,25 @@ class CloudComputeServiceTestCase(ProviderTestBase):
                 else:
                     external_net = net
                 router.attach_network(external_net.id)
-                # check whether adding an elastic ip works
-                fip = self.provider.network.create_floating_ip()
-                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)
-
-                    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)
+                router.add_route(subnet.id)
+
+                def cleanup_router():
+                    router.remove_route(subnet.id)
+                    router.detach_network()
+
+                with helpers.cleanup_action(lambda: cleanup_router()):
+                    # check whether adding an elastic ip works
+                    fip = self.provider.network.create_floating_ip()
+                    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)
+
+                        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)