فهرست منبع

Added aws implementation of remove floating ip and added tests

Nuwan Goonasekera 9 سال پیش
والد
کامیت
def356f28c
2فایلهای تغییر یافته به همراه30 افزوده شده و 3 حذف شده
  1. 8 3
      cloudbridge/cloud/providers/aws/resources.py
  2. 22 0
      test/test_compute_service.py

+ 8 - 3
cloudbridge/cloud/providers/aws/resources.py

@@ -356,7 +356,7 @@ class AWSInstance(BaseInstance):
         """
         if self._ec2_instance.vpc_id:
             aid = self._provider._vpc_conn.get_all_addresses([ip_address])[0]
-            return self._provider._ec2_conn.associate_address(
+            return self._provider.ec2_conn.associate_address(
                 self._ec2_instance.id, allocation_id=aid.allocation_id)
         else:
             return self._ec2_instance.use_ip(ip_address)
@@ -365,8 +365,13 @@ class AWSInstance(BaseInstance):
         """
         Remove a elastic IP address from this instance.
         """
-        raise NotImplementedError(
-            'remove_floating_ip not implemented by this provider.')
+        ip_addr = self._provider._vpc_conn.get_all_addresses([ip_address])[0]
+        if self._ec2_instance.vpc_id:
+            return self._provider.ec2_conn.disassociate_address(
+                association_id=ip_addr.association_id)
+        else:
+            return self._provider.ec2_conn.disassociate_address(
+                public_ip=ip_addr.public_ip)
 
     def add_security_group(self, sg):
         """

+ 22 - 0
test/test_compute_service.py

@@ -8,6 +8,7 @@ from cloudbridge.cloud.interfaces import InstanceState
 from cloudbridge.cloud.interfaces.resources import InstanceType
 from cloudbridge.cloud.interfaces.resources import SnapshotState
 from cloudbridge.cloud.interfaces.exceptions import WaitStateException
+from cloudbridge.cloud.interfaces import TestMockHelperMixin
 
 from test.helpers import ProviderTestBase
 import test.helpers as helpers
@@ -362,3 +363,24 @@ class CloudComputeServiceTestCase(ProviderTestBase):
                 sg not in test_inst.security_groups, "Expected security group"
                 " '%s' to be removed from instance security_groups: [%s]" %
                 (sg, test_inst.security_groups))
+
+            # check floating ips
+            router = self.provider.network.create_router(name=name)
+
+            with helpers.cleanup_action(lambda: router.delete()):
+                router.attach_network(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)