Merge lp:~gz/pyjuju/os_metadata_not_found_1061678 into lp:pyjuju

Proposed by Martin Packman
Status: Merged
Approved by: Clint Byrum
Approved revision: 591
Merged at revision: 590
Proposed branch: lp:~gz/pyjuju/os_metadata_not_found_1061678
Merge into: lp:pyjuju
Diff against target: 26 lines (+3/-2)
2 files modified
juju/unit/address.py (+2/-1)
juju/unit/tests/test_address.py (+1/-1)
To merge this branch: bzr merge lp:~gz/pyjuju/os_metadata_not_found_1061678
Reviewer Review Type Date Requested Status
Clint Byrum (community) Approve
Review via email: mp+128056@code.launchpad.net

Description of the change

Adapt openstack metadata service ipv4 for folsom

In essex, if an instance did not have a public ipv4 address the
metadata service would return an empty body with 200 http status
code. In folsom, it now returns a 404 instead. This branch catches
that and treats it in the same way as before - falling back to
checking local-ipv4 instead.

https://codereview.appspot.com/6584085/

To post a comment you must log in.
Revision history for this message
Martin Packman (gz) wrote :
Download full text (3.4 KiB)

Reviewers: mp+128056_code.launchpad.net,

Message:
Please take a look.

Description:
Adapt openstack metadata service ipv4 for folsom

In essex, if an instance did not have a public ipv4 address the
metadata service would return an empty body with 200 http status
code. In folsom, it now returns a 404 instead. This branch catches
that and treats it in the same way as before - falling back to
checking local-ipv4 instead.

https://code.launchpad.net/~gz/juju/os_metadata_not_found_1061678/+merge/128056

(do not edit description out of merge proposal)

Please review this at https://codereview.appspot.com/6584085/

Affected files:
   A [revision details]
   M juju/unit/address.py
   M juju/unit/tests/test_address.py

Index: [revision details]
=== added file '[revision details]'
--- [revision details] 2012-01-01 00:00:00 +0000
+++ [revision details] 2012-01-01 00:00:00 +0000
@@ -0,0 +1,2 @@
+Old revision: <email address hidden>
+New revision: <email address hidden>

Index: juju/unit/address.py
=== modified file 'juju/unit/address.py'
--- juju/unit/address.py 2012-05-22 14:43:41 +0000
+++ juju/unit/address.py 2012-10-04 16:06:52 +0000
@@ -4,7 +4,11 @@

  from twisted.internet.defer import inlineCallbacks, returnValue, succeed
  from twisted.internet.threads import deferToThread
-from twisted.web import client
+from twisted.web import (
+ client,
+ error,
+ http,
+ )

  from juju.errors import JujuError
  from juju.state.environment import GlobalSettingsStateManager
@@ -78,7 +82,12 @@

      @inlineCallbacks
      def get_public_address(self):
- address = yield self._get_metadata_string("public-ipv4")
+ try:
+ address = yield self._get_metadata_string("public-ipv4")
+ except error.Error as e:
+ if e.status != http.NOT_FOUND:
+ raise
+ address = None
          if not address:
              address = yield self.get_private_address()
          returnValue(address)

Index: juju/unit/tests/test_address.py
=== modified file 'juju/unit/tests/test_address.py'
--- juju/unit/tests/test_address.py 2012-05-22 14:43:41 +0000
+++ juju/unit/tests/test_address.py 2012-10-04 16:05:44 +0000
@@ -1,8 +1,12 @@
  import subprocess
  import zookeeper

-from twisted.internet.defer import inlineCallbacks, succeed, returnValue
-from twisted.web import client
+from twisted.internet.defer import fail, inlineCallbacks, succeed,
returnValue
+from twisted.web import (
+ client,
+ error,
+ http,
+ )

  from juju.errors import JujuError
  from juju.lib.testing import TestCase
@@ -128,7 +132,10 @@
      def _fetch_metadata(self, url):
          head, tail = url.rsplit("/", 1)
          self.assertEqual("http://169.254.169.254/1.0/meta-data", head)
- return succeed(self.meta.pop(tail))
+ result = self.meta.pop(tail)
+ if isinstance(result, Exception):
+ return fail(result)
+ return succeed(result)

      @inlineCallbacks
      def test_get_private_address(self):
@@ -147,6 +154,13 @@
          self.assertEqual("192.168.0.2",
              (yield self.address.get_public_address()))

+ @i...

Read more...

591. By Martin Packman

Use 2009-04-04 metadata service api version instead of 1.0

Revision history for this message
Martin Packman (gz) wrote :
Revision history for this message
Clint Byrum (clint-fewbar) wrote :

Tested on hpcloud and canonistack, works great.

review: Approve
Revision history for this message
Martin Packman (gz) wrote :

So, the first attempt at this which was handling the 404 was not sufficient, and turns out not to be needed. I've reverted that part, and will just commit the simple change to the api version used.

592. By Martin Packman

Revert unneeded complication over handling 404 results

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'juju/unit/address.py'
2--- juju/unit/address.py 2012-05-22 14:43:41 +0000
3+++ juju/unit/address.py 2012-10-05 17:54:24 +0000
4@@ -71,7 +71,8 @@
5 """
6
7 def _get_metadata_string(self, key):
8- return client.getPage("http://169.254.169.254/1.0/meta-data/" + key)
9+ return client.getPage("http://169.254.169.254/%s/meta-data/%s" %
10+ ("2009-04-04", key))
11
12 def get_private_address(self):
13 return self._get_metadata_string("local-ipv4")
14
15=== modified file 'juju/unit/tests/test_address.py'
16--- juju/unit/tests/test_address.py 2012-05-22 14:43:41 +0000
17+++ juju/unit/tests/test_address.py 2012-10-05 17:54:24 +0000
18@@ -127,7 +127,7 @@
19
20 def _fetch_metadata(self, url):
21 head, tail = url.rsplit("/", 1)
22- self.assertEqual("http://169.254.169.254/1.0/meta-data", head)
23+ self.assertEqual("http://169.254.169.254/2009-04-04/meta-data", head)
24 return succeed(self.meta.pop(tail))
25
26 @inlineCallbacks

Subscribers

People subscribed via source and target branches

to status/vote changes: