← Back to team overview

txaws-dev team mailing list archive

[Merge] lp:~clint-fewbar/txaws/openstack-terminate-instances into lp:txaws

 

Clint Byrum has proposed merging lp:~clint-fewbar/txaws/openstack-terminate-instances into lp:txaws.

Requested reviews:
  txAWS Developers (txaws-dev)
Related bugs:
  Bug #862595 in txAWS: "terminate_instances raises NoneType not iterable on machine shutdown with Openstack"
  https://bugs.launchpad.net/txaws/+bug/862595

For more details, see:
https://code.launchpad.net/~clint-fewbar/txaws/openstack-terminate-instances/+merge/77593

Nova has a bug in its responses to TerminateInstances. At this point
there are Nova "diablo" implementations out there in the wild, so its
not enough to tell Nova to fix their responses, we should be able to
deal with the lack of instance list just fine.

The code also adds tests to make sure EC2 and the broken nova request
parse as expected.
-- 
https://code.launchpad.net/~clint-fewbar/txaws/openstack-terminate-instances/+merge/77593
Your team txAWS Developers is requested to review the proposed merge of lp:~clint-fewbar/txaws/openstack-terminate-instances into lp:txaws.
=== modified file 'txaws/ec2/client.py'
--- txaws/ec2/client.py	2011-05-12 14:48:26 +0000
+++ txaws/ec2/client.py	2011-09-29 19:40:52 +0000
@@ -630,13 +630,15 @@
         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))
+        instances = root.find("instancesSet")
+        if instances is not None:
+            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-05-12 14:38:37 +0000
+++ txaws/ec2/tests/test_client.py	2011-09-29 19:40:52 +0000
@@ -1962,3 +1962,40 @@
         d = ec2.disassociate_address("67.202.55.255")
         d.addCallback(self.assertTrue)
         return d
+
+class EC2ParserTestCase(TXAWSTestCase):
+
+    def setUp(self):
+        self.parser = client.Parser()
+
+    def test_ec2_terminate_instances(self):
+        """ Given a well formed response from EC2, will we parse the correct thing. """
+
+        ec2_xml = """<?xml version="1.0" encoding="UTF-8"?>
+<TerminateInstancesResponse xmlns="http://ec2.amazonaws.com/doc/2008-12-01/";>
+    <requestId>d0adc305-7f97-4652-b7c2-6993b2bb8260</requestId>
+    <instancesSet>
+        <item>
+            <instanceId>i-cab0c1aa</instanceId>
+            <shutdownState>
+                <code>32</code>
+                <name>shutting-down</name>
+            </shutdownState>
+            <previousState>
+                <code>16</code>
+                <name>running</name>
+            </previousState>
+        </item>
+    </instancesSet>
+</TerminateInstancesResponse>"""
+        ec2_response = self.parser.terminate_instances(ec2_xml)
+        self.assertEquals([('i-cab0c1aa','running','shutting-down')], ec2_response)
+
+    def test_nova_terminate_instances(self):
+        """ Ensure parser can handle the somewhat non-standard response from nova
+        Note that the bug has been reported in nova here: 
+        https://launchpad.net/bugs/862680 """
+
+        nova_xml = """<?xml version="1.0" ?><TerminateInstancesResponse xmlns="http://ec2.amazonaws.com/doc/2008-12-01/";><requestId>4fe6643d-2346-4add-adb7-a1f61f37c043</requestId><return>true</return></TerminateInstancesResponse>"""
+        nova_response = self.parser.terminate_instances(nova_xml)
+        self.assertEquals([], nova_response)