Description:
Tolerate older twisted versions in openstack provider
The juju ppa includes newer versions of txaws and txzookeeper, but uses
the system twisted version. This means it ftbfs on natty and oneiric,
which doesn't matter much as most devs should be using something newer
anyway, but is not hard to fix. This branch uses some existing compat
code and adds a conditional import, which is enough to make happiness.
Affected files:
A [revision details]
M juju/providers/openstack/client.py
M juju/providers/openstack/provider.py
M juju/providers/openstack/tests/test_client.py
from juju import errors
+from juju.lib.twistutils import gather_results
from juju.lib.cache import CachedValue
from juju.providers.common.base import MachineProviderBase
@@ -181,7 +182,7 @@
:rtype: :class:`twisted.internet.defer.Deferred`
"""
machines = yield self.get_machines()
- deleted_machines = yield gatherResults(
+ deleted_machines = yield gather_results( [self._delete_machine(m, True) for m in machines])
yield self.save_state({}) returnValue(deleted_machines)
@@ -200,8 +201,8 @@
"""
# XXX: need to actually handle errors as non-terminated machines
# and not include them in the resulting list
- return gatherResults(
- [self.shutdown_machine(m) for m in machines],
consumeErrors=True)
+ return gather_results(
+ [self.shutdown_machine(m) for m in machines],
consume_errors=True)
def open_port(self, machine, machine_id, port, protocol="tcp"): """Authorizes `port` using `protocol` on EC2 for `machine`."""
Reviewers: mp+122849_ code.launchpad. net,
Message:
Please take a look.
Description:
Tolerate older twisted versions in openstack provider
The juju ppa includes newer versions of txaws and txzookeeper, but uses
the system twisted version. This means it ftbfs on natty and oneiric,
which doesn't matter much as most devs should be using something newer
anyway, but is not hard to fix. This branch uses some existing compat
code and adds a conditional import, which is enough to make happiness.
https:/ /code.launchpad .net/~gz/ juju/old_ twisted_ 1029070/ +merge/ 122849
(do not edit description out of merge proposal)
Please review this at https:/ /codereview. appspot. com/6496084/
Affected files: openstack/ client. py openstack/ provider. py openstack/ tests/test_ client. py
A [revision details]
M juju/providers/
M juju/providers/
M juju/providers/
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/providers/ openstack/ client. py /openstack/ client. py' openstack/ client. py 2012-09-03 11:08:13 +0000 openstack/ client. py 2012-09-05 11:10:08 +0000 internet. interfaces import IProducer
=== modified file 'juju/providers
--- juju/providers/
+++ juju/providers/
@@ -30,10 +30,13 @@
from twisted.
from twisted.internet import reactor
-from twisted.web import ( web._newclient import ResponseFailed web.http_ headers import Headers
- client,
- http_headers,
- )
+from twisted.web.client import Agent
+# Older twisted versions don't expose _newclient exceptions via client
module
+try:
+ from twisted.web.client import ResponseFailed
+except ImportError:
+ from twisted.
+from twisted.
from zope.interface import implements
from juju import errors response_ failed( failure) : ResponseFailed) :
@@ -100,7 +103,7 @@
def _translate_
"""Turn internal twisted client failures into juju exceptions"""
txerr = failure.value
- if isinstance(txerr, client.
+ if isinstance(txerr, ResponseFailed):
for reason in txerr.reasons:
err = reason.value
if isinstance(err, SSLError):
@@ -110,7 +113,7 @@
@inlineCallbacks Headers( {
"User- Agent": [_USER_AGENT],
kwargs[ 'contextFactory '] = WebVerifyingCon textFactory( ) Agent(reactor, **kwargs) method, url, headers, body).addErrback(
_translate_ response_ failed)
def request(method, url, extra_headers=(), body=None, check_certs=False):
- headers = http_headers.
+ headers = Headers({
# GZ 2012-07-03: Previously passed Accept: application/json header
# here, but not always the right thing. Bad for
swift?
@@ -128,7 +131,7 @@
kwargs = {}
if check_certs:
- agent = client.
+ agent = Agent(reactor, **kwargs)
response = yield agent.request(
if response.length == 0:
Index: juju/providers/ openstack/ provider. py /openstack/ provider. py' openstack/ provider. py 2012-09-01 14:46:03 +0000 openstack/ provider. py 2012-09-05 11:07:35 +0000
=== modified file 'juju/providers
--- juju/providers/
+++ juju/providers/
@@ -12,9 +12,10 @@
import logging
-from twisted. internet. defer import inlineCallbacks, returnValue, internet. defer import inlineCallbacks, returnValue
gatherResults
+from twisted.
from juju import errors common. base import MachineProviderBase
+from juju.lib.twistutils import gather_results
from juju.lib.cache import CachedValue
from juju.providers.
@@ -181,7 +182,7 @@ `twisted. internet. defer.Deferred`
[self._ delete_ machine( m, True) for m in machines])
returnValue( deleted_ machines) machine( m) for m in machines], machine( m) for m in machines], errors= True)
:rtype: :class:
"""
machines = yield self.get_machines()
- deleted_machines = yield gatherResults(
+ deleted_machines = yield gather_results(
yield self.save_state({})
@@ -200,8 +201,8 @@
"""
# XXX: need to actually handle errors as non-terminated machines
# and not include them in the resulting list
- return gatherResults(
- [self.shutdown_
consumeErrors=True)
+ return gather_results(
+ [self.shutdown_
consume_
def open_port(self, machine, machine_id, port, protocol="tcp"):
"""Authorize s `port` using `protocol` on EC2 for `machine`."""
Index: juju/providers/ openstack/ tests/test_ client. py /openstack/ tests/test_ client. py' openstack/ tests/test_ client. py 2012-08-28 12:25:41 +0000 openstack/ tests/test_ client. py 2012-09-05 11:10:08 +0000 python. failure import Failure
=== modified file 'juju/providers
--- juju/providers/
+++ juju/providers/
@@ -7,7 +7,6 @@
from twisted.
from twisted.web import (
http_headers,
- client as txclient,
)
from juju import errors
"X-Server- Management- Url": ["http:// testing. invalid/ compute"],
"X-Auth- Token": ["tok"], result( defer.fail( txclient. ResponseFailed( [ result( defer.fail( client. ResponseFailed( [
Failure( self.SSLError( )),
self. mocker. replay( )
@@ -142,7 +141,7 @@
}))
- self.mocker.
+ self.mocker.
])))