Frank Wierzbicki has proposed merging 
lp:~fwierzbicki/txaws/empty-instances-workaround into lp:txaws.

Requested reviews:
  txAWS Developers (txaws-dev)

For more details, see:
https://code.launchpad.net/~fwierzbicki/txaws/empty-instances-workaround/+merge/85562

This branch allows for TerminateInstancesResponse XML to lack a list of 
instances. The workaround returns an empty list instead. This is a partial 
workaround for a bug in OpenStack's implementation -- see 
https://bugs.launchpad.net/nova/+bug/862680
-- 
https://code.launchpad.net/~fwierzbicki/txaws/empty-instances-workaround/+merge/85562
Your team txAWS Developers is requested to review the proposed merge of 
lp:~fwierzbicki/txaws/empty-instances-workaround into lp:txaws.
=== modified file 'txaws/ec2/client.py'
--- txaws/ec2/client.py	2011-08-19 16:09:39 +0000
+++ txaws/ec2/client.py	2011-12-13 22:16:57 +0000
@@ -629,14 +629,20 @@
         """
         root = XML(xml_bytes)
         result = []
-        # May be a more elegant way to do this:
-        for instance in root.find("instancesSet"):
-            instanceId = instance.findtext("instanceId")
-            previousState = instance.find("previousState").findtext(
-                "name")
-            shutdownState = instance.find("shutdownState").findtext(
-                "name")
-            result.append((instanceId, previousState, shutdownState))
+        
+        # instancesSet is sometimes not present for OpenStack, but this is a
+        # bug https://bugs.launchpad.net/nova/+bug/862680 when fixed, we will
+        # no longer need to None check instancesSet.
+        instances = root.find("instancesSet")
+        if instances is not None:
+            # May be a more elegant way to do this:
+            for instance in instances:
+                instanceId = instance.findtext("instanceId")
+                previousState = instance.find("previousState").findtext(
+                    "name")
+                shutdownState = instance.find("shutdownState").findtext(
+                    "name")
+                result.append((instanceId, previousState, shutdownState))
         return result
 
     def describe_security_groups(self, xml_bytes):

=== modified file 'txaws/ec2/tests/test_client.py'
--- txaws/ec2/tests/test_client.py	2011-08-29 19:51:50 +0000
+++ txaws/ec2/tests/test_client.py	2011-12-13 22:16:57 +0000
@@ -315,6 +315,36 @@
         d.addCallback(check_transition)
         return d
 
+    # This shoudn't really happen, but does with current OpenStack.
+    # When https://bugs.launchpad.net/nova/+bug/862680 is fixed, remove this.
+    def test_empty_terminate_instances(self):
+
+        class StubQuery(object):
+
+            def __init__(stub, action="", creds=None, endpoint=None,
+                         other_params={}):
+                self.assertEqual(action, "TerminateInstances")
+                self.assertEqual(creds.access_key, "foo")
+                self.assertEqual(creds.secret_key, "bar")
+                self.assertEqual(
+                    other_params,
+                    {"InstanceId.1": "i-1234", "InstanceId.2": "i-5678"})
+
+            def submit(self):
+                return succeed(payload.empty_terminate_instances_result)
+
+        def check_transition(changes):
+            self.assertEqual([], sorted(changes))
+
+        creds = AWSCredentials("foo", "bar")
+        endpoint = AWSServiceEndpoint(uri=EC2_ENDPOINT_US)
+        ec2 = client.EC2Client(creds=creds, endpoint=endpoint,
+                               query_factory=StubQuery)
+        d = ec2.terminate_instances("i-1234", "i-5678")
+        d.addCallback(check_transition)
+        return d
+
+
     def check_parsed_run_instances(self, results):
         instance = results[0]
         # check reservations

=== modified file 'txaws/testing/payload.py'
--- txaws/testing/payload.py	2011-08-29 19:51:50 +0000
+++ txaws/testing/payload.py	2011-12-13 22:16:57 +0000
@@ -177,6 +177,13 @@
 </TerminateInstancesResponse>
 """ % (version.ec2_api,)
 
+# This shoudn't really happen, but does with current OpenStack.
+# When https://bugs.launchpad.net/nova/+bug/862680 is fixed, remove this.
+empty_terminate_instances_result = """\
+<?xml version="1.0"?>
+<TerminateInstancesResponse xmlns="http://ec2.amazonaws.com/doc/%s/";>
+</TerminateInstancesResponse>
+""" % (version.ec2_api,)
 
 sample_describe_security_groups_with_openstack = """\
 <?xml version="1.0"?>

_______________________________________________
Mailing list: https://launchpad.net/~txaws-dev
Post to     : txaws-dev@lists.launchpad.net
Unsubscribe : https://launchpad.net/~txaws-dev
More help   : https://help.launchpad.net/ListHelp

Reply via email to