Browse Source

set validate=True when calling boto update() to make sure deleted
objects are detected and fixed instance crud test

nuwan_ag 10 years ago
parent
commit
8a032d624b

+ 6 - 6
cloudbridge/providers/aws/resources.py

@@ -276,8 +276,8 @@ class AWSInstance(BaseInstance):
         for its latest state.
         """
         try:
-            self._ec2_instance.update()
-        except EC2ResponseError:
+            self._ec2_instance.update(validate=True)
+        except (EC2ResponseError, ValueError):
             # The volume no longer exists and cannot be refreshed.
             # set the status to unknown
             self._ec2_instance.status = 'unknown'
@@ -367,8 +367,8 @@ class AWSVolume(BaseVolume):
         for its latest state.
         """
         try:
-            self._volume.update()
-        except EC2ResponseError:
+            self._volume.update(validate=True)
+        except (EC2ResponseError, ValueError):
             # The volume no longer exists and cannot be refreshed.
             # set the status to unknown
             self._volume.status = 'unknown'
@@ -422,8 +422,8 @@ class AWSSnapshot(BaseSnapshot):
         for its latest state.
         """
         try:
-            self._snapshot.update()
-        except EC2ResponseError:
+            self._snapshot.update(validate=True)
+        except (EC2ResponseError, ValueError):
             # The snapshot no longer exists and cannot be refreshed.
             # set the status to unknown
             self._snapshot.status = 'unknown'

+ 2 - 0
cloudbridge/providers/aws/services.py

@@ -419,6 +419,8 @@ class AWSComputeService(ComputeService):
             instance_ids=[instance_id])
         if reservation:
             return AWSInstance(self.provider, reservation[0].instances[0])
+        else:
+            return None
 
     def find_instance(self, name):
         """

+ 5 - 5
test/test_compute_service.py

@@ -1,6 +1,5 @@
 import uuid
 import ipaddress
-
 from cloudbridge.providers.interfaces import InstanceState
 from test.helpers import ProviderTestBase
 import test.helpers as helpers
@@ -29,11 +28,12 @@ class ProviderComputeServiceTestCase(ProviderTestBase):
             inst.wait_for(
                 [InstanceState.TERMINATED, InstanceState.UNKNOWN],
                 terminal_states=[InstanceState.ERROR])
-            all_instances = self.provider.compute.list_instances()
-            found_instances = [i for i in all_instances if i.name == name]
+            deleted_inst = self.provider.compute.get_instance(inst.instance_id)
             self.assertTrue(
-                len(found_instances) == 0,
-                "List instances does not return the expected instance %s" %
+                deleted_inst is None or deleted_inst.state in (
+                    InstanceState.TERMINATED,
+                    InstanceState.UNKNOWN),
+                "Instance %s should have been deleted but still exists." %
                 name)
 
     def _is_valid_ip(self, address):