Created
March 15, 2011 18:58
-
-
Save Kami/871236 to your computer and use it in GitHub Desktop.
tavis fixes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| diff --git .gitignore .gitignore | |
| index 8d491af..1c8d957 100644 | |
| --- .gitignore | |
| +++ .gitignore | |
| @@ -6,3 +6,6 @@ demos/secrets.py | |
| _trial_temp | |
| build | |
| MANIFEST | |
| +/.ropeproject/config.py | |
| +/.coverage | |
| +coverage_html_report/ | |
| diff --git libcloud/__init__.py libcloud/__init__.py | |
| index 7cb4a86..a6a5eac 100644 | |
| --- libcloud/__init__.py | |
| +++ libcloud/__init__.py | |
| @@ -30,7 +30,9 @@ def enable_debug(fo): | |
| @param fo: Where to append debugging information | |
| @type fo: File like object, only write operations are used. | |
| """ | |
| - from libcloud.base import ConnectionKey, LoggingHTTPConnection, LoggingHTTPSConnection | |
| + from libcloud.base import (ConnectionKey, | |
| + LoggingHTTPConnection, | |
| + LoggingHTTPSConnection) | |
| LoggingHTTPSConnection.log = fo | |
| LoggingHTTPConnection.log = fo | |
| ConnectionKey.conn_classes = (LoggingHTTPConnection, LoggingHTTPSConnection) | |
| diff --git libcloud/base.py libcloud/base.py | |
| index 736bb65..ef340cb 100644 | |
| --- libcloud/base.py | |
| +++ libcloud/base.py | |
| @@ -20,6 +20,22 @@ from libcloud.compute.base import Node, NodeSize, NodeImage | |
| from libcloud.compute.base import NodeLocation, NodeAuthSSHKey, NodeAuthPassword | |
| from libcloud.compute.base import NodeDriver, is_private_subnet | |
| +__all__ = ['RawResponse', | |
| + 'Response', | |
| + 'LoggingConnection', | |
| + 'LoggingHTTPSConnection', | |
| + 'LoggingHTTPConnection', | |
| + 'ConnectionKey', | |
| + 'ConnectionUserAndKey', | |
| + 'Node', | |
| + 'NodeSize', | |
| + 'NodeImage', | |
| + 'NodeLocation', | |
| + 'NodeAuthSSHKey', | |
| + 'NodeAuthPassword', | |
| + 'NodeDriver', | |
| + 'is_private_subnet'] | |
| + | |
| from libcloud.utils import deprecated_warning | |
| deprecated_warning(__name__) | |
| diff --git libcloud/common/rackspace.py libcloud/common/rackspace.py | |
| index 8f41375..3b54c64 100644 | |
| --- libcloud/common/rackspace.py | |
| +++ libcloud/common/rackspace.py | |
| @@ -25,6 +25,11 @@ AUTH_HOST_US='auth.api.rackspacecloud.com' | |
| AUTH_HOST_UK='lon.auth.api.rackspacecloud.com' | |
| AUTH_API_VERSION = 'v1.0' | |
| +__all__ = [ | |
| + "RackspaceBaseConnection", | |
| + "AUTH_HOST_US", | |
| + "AUTH_HOST_UK" | |
| + ] | |
| class RackspaceBaseConnection(ConnectionUserAndKey): | |
| def __init__(self, user_id, key, secure): | |
| self.cdn_management_url = None | |
| @@ -32,7 +37,8 @@ class RackspaceBaseConnection(ConnectionUserAndKey): | |
| self.auth_token = None | |
| self.request_path = None | |
| self.__host = None | |
| - super(RackspaceBaseConnection, self).__init__(user_id, key, secure=secure) | |
| + super(RackspaceBaseConnection, self).__init__( | |
| + user_id, key, secure=secure) | |
| def add_default_headers(self, headers): | |
| headers['X-Auth-Token'] = self.auth_token | |
| @@ -48,7 +54,8 @@ class RackspaceBaseConnection(ConnectionUserAndKey): | |
| """ | |
| if not self.__host: | |
| # Initial connection used for authentication | |
| - conn = self.conn_classes[self.secure](self.auth_host, self.port[self.secure]) | |
| + conn = self.conn_classes[self.secure]( | |
| + self.auth_host, self.port[self.secure]) | |
| conn.request( | |
| method='GET', | |
| url='/%s' % (AUTH_API_VERSION), | |
| @@ -74,8 +81,7 @@ class RackspaceBaseConnection(ConnectionUserAndKey): | |
| raise InvalidCredsError() | |
| scheme, server, self.request_path, param, query, fragment = ( | |
| - urlparse.urlparse(getattr(self, self._url_key)) | |
| - ) | |
| + urlparse.urlparse(getattr(self, self._url_key))) | |
| if scheme is "https" and self.secure is not True: | |
| raise InvalidCredsError() | |
| diff --git libcloud/common/types.py libcloud/common/types.py | |
| index 36a0d7f..f2f1b5d 100644 | |
| --- libcloud/common/types.py | |
| +++ libcloud/common/types.py | |
| @@ -13,33 +13,53 @@ | |
| # See the License for the specific language governing permissions and | |
| # limitations under the License. | |
| +__all__ = [ | |
| + "LibcloudError", | |
| + "MalformedResponseError", | |
| + "InvalidCredsError", | |
| + "InvalidCredsException" | |
| + ] | |
| + | |
| class LibcloudError(Exception): | |
| """The base class for other libcloud exceptions""" | |
| + | |
| def __init__(self, value, driver=None): | |
| self.value = value | |
| self.driver = driver | |
| def __str__(self): | |
| - return "<LibcloudError in "+ repr(self.driver) +" "+ repr(self.value) + ">" | |
| + return ("<LibcloudError in " | |
| + + repr(self.driver) | |
| + +" " | |
| + + repr(self.value) + ">") | |
| class MalformedResponseError(LibcloudError): | |
| """Exception for the cases when a provider returns a malformed | |
| - response, e.g. you request JSON and provider returns | |
| + response, e.g. you request JSON and provider returns | |
| '<h3>something</h3>' due to some error on their side.""" | |
| + | |
| def __init__(self, value, body=None, driver=None): | |
| - self.value = value | |
| - self.driver = driver | |
| - self.body = body | |
| + self.value = value | |
| + self.driver = driver | |
| + self.body = body | |
| + | |
| def __str__(self): | |
| - return "<MalformedResponseException in "+ repr(self.driver) +" "+ repr(self.value) +">: "+ repr(self.body) | |
| + return ("<MalformedResponseException in " | |
| + + repr(self.driver) | |
| + + " " | |
| + + repr(self.value) | |
| + + ">: " | |
| + + repr(self.body)) | |
| class InvalidCredsError(LibcloudError): | |
| """Exception used when invalid credentials are used on a provider.""" | |
| - def __init__(self, value='Invalid credentials with the provider', driver=None): | |
| + | |
| + def __init__(self, value='Invalid credentials with the provider', | |
| + driver=None): | |
| self.value = value | |
| self.driver = driver | |
| def __str__(self): | |
| return repr(self.value) | |
| -"""Deprecated alias of L{InvalidCredsError}""" | |
| +# Deprecated alias of L{InvalidCredsError} | |
| InvalidCredsException = InvalidCredsError | |
| diff --git libcloud/compute/base.py libcloud/compute/base.py | |
| index 5c44f5e..06d97f8 100644 | |
| --- libcloud/compute/base.py | |
| +++ libcloud/compute/base.py | |
| @@ -22,14 +22,32 @@ import os | |
| import socket | |
| import struct | |
| -from httplib import HTTPConnection as LibcloudHTTPConnection | |
| - | |
| from libcloud.pricing import get_size_price | |
| - | |
| -from libcloud.common.base import ConnectionKey, ConnectionUserAndKey | |
| from libcloud.compute.types import NodeState, DeploymentError | |
| from libcloud.compute.ssh import SSHClient | |
| + | |
| +# @@TR: are the imports below part of the public api for this | |
| +# module? They aren't used in here ... | |
| +from libcloud.common.base import ConnectionKey, ConnectionUserAndKey | |
| from libcloud.httplib_ssl import LibcloudHTTPSConnection | |
| +from libcloud.common.base import LibcloudHTTPConnection | |
| + | |
| +__all__ = [ | |
| + "Node", | |
| + "NodeState", | |
| + "NodeSize", | |
| + "NodeImage", | |
| + "NodeLocation", | |
| + "NodeAuthSSHKey", | |
| + "NodeAuthPassword", | |
| + "NodeDriver", | |
| + | |
| + # @@TR: do the following need exporting? | |
| + "ConnectionKey", | |
| + "ConnectionUserAndKey", | |
| + "LibcloudHTTPSConnection", | |
| + "LibcloudHTTPConnection" | |
| + ] | |
| class Node(object): | |
| """ | |
| @@ -196,6 +214,7 @@ class NodeSize(object): | |
| self.bandwidth = bandwidth | |
| self.price = price | |
| self.driver = driver | |
| + | |
| def __repr__(self): | |
| return (('<NodeSize: id=%s, name=%s, ram=%s disk=%s bandwidth=%s ' | |
| 'price=%s driver=%s ...>') | |
| @@ -473,6 +492,7 @@ class NodeDriver(object): | |
| existing implementation should be able to handle most such. | |
| """ | |
| # TODO: support ssh keys | |
| + # FIX: this method is too long and complicated | |
| WAIT_PERIOD=3 | |
| password = None | |
| @@ -487,60 +507,68 @@ class NodeDriver(object): | |
| password = kwargs['auth'].password | |
| node = self.create_node(**kwargs) | |
| try: | |
| - if 'generates_password' in self.features["create_node"]: | |
| - password = node.extra.get('password') | |
| - start = time.time() | |
| - end = start + (60 * 15) | |
| - while time.time() < end: | |
| - # need to wait until we get a public IP address. | |
| - # TODO: there must be a better way of doing this | |
| - time.sleep(WAIT_PERIOD) | |
| - nodes = self.list_nodes() | |
| - nodes = filter(lambda n: n.uuid == node.uuid, nodes) | |
| - if len(nodes) == 0: | |
| - raise DeploymentError(node, "Booted node[%s] is missing form list_nodes." % node) | |
| - if len(nodes) > 1: | |
| - raise DeploymentError(node, "Booted single node[%s], but multiple nodes have same UUID"% node) | |
| - | |
| - node = nodes[0] | |
| - | |
| - if node.public_ip is not None and node.public_ip != "" and node.state == NodeState.RUNNING: | |
| - break | |
| - | |
| - ssh_username = kwargs.get('ssh_username', 'root') | |
| - ssh_port = kwargs.get('ssh_port', 22) | |
| - | |
| - client = SSHClient(hostname=node.public_ip[0], | |
| - port=ssh_port, username=ssh_username, | |
| - password=password) | |
| - laste = None | |
| - while time.time() < end: | |
| - laste = None | |
| - try: | |
| - client.connect() | |
| - break | |
| - except (IOError, socket.gaierror, socket.error), e: | |
| - laste = e | |
| - time.sleep(WAIT_PERIOD) | |
| - if laste is not None: | |
| - raise e | |
| - | |
| - tries = 3 | |
| - while tries >= 0: | |
| - try: | |
| - n = kwargs["deploy"].run(node, client) | |
| - client.close() | |
| - break | |
| - except Exception, e: | |
| - tries -= 1 | |
| - if tries == 0: | |
| - raise | |
| - client.connect() | |
| - | |
| - except DeploymentError, e: | |
| - raise | |
| + if 'generates_password' in self.features["create_node"]: | |
| + password = node.extra.get('password') | |
| + start = time.time() | |
| + end = start + (60 * 15)# FIX: this should be soft-coded | |
| + while time.time() < end: | |
| + # need to wait until we get a public IP address. | |
| + # TODO: there must be a better way of doing this | |
| + time.sleep(WAIT_PERIOD) | |
| + nodes = self.list_nodes() | |
| + nodes = filter(lambda n: n.uuid == node.uuid, nodes) | |
| + if len(nodes) == 0: | |
| + raise DeploymentError( | |
| + node, | |
| + ("Booted node[%s] " % node | |
| + + "is missing from list_nodes.")) | |
| + if len(nodes) > 1: | |
| + raise DeploymentError( | |
| + node, | |
| + ("Booted single node[%s], " % node | |
| + + "but multiple nodes have same UUID")) | |
| + | |
| + node = nodes[0] | |
| + | |
| + if (node.public_ip is not None | |
| + and node.public_ip != "" | |
| + and node.state == NodeState.RUNNING): | |
| + break | |
| + | |
| + ssh_username = kwargs.get('ssh_username', 'root') | |
| + ssh_port = kwargs.get('ssh_port', 22) | |
| + | |
| + client = SSHClient(hostname=node.public_ip[0], | |
| + port=ssh_port, username=ssh_username, | |
| + password=password) | |
| + laste = None | |
| + while time.time() < end: | |
| + laste = None | |
| + try: | |
| + client.connect() | |
| + break | |
| + except (IOError, socket.gaierror, socket.error), e: | |
| + laste = e | |
| + time.sleep(WAIT_PERIOD) | |
| + if laste is not None: | |
| + raise e | |
| + | |
| + tries = 3 | |
| + while tries >= 0: | |
| + try: | |
| + n = kwargs["deploy"].run(node, client) | |
| + client.close() | |
| + break | |
| + except Exception, e: | |
| + tries -= 1 | |
| + if tries == 0: | |
| + raise | |
| + client.connect() | |
| + | |
| + except DeploymentError: | |
| + raise | |
| except Exception, e: | |
| - raise DeploymentError(node, e) | |
| + raise DeploymentError(node, e) | |
| return n | |
| def _get_size_price(self, size_id): | |
| diff --git libcloud/compute/drivers/dreamhost.py libcloud/compute/drivers/dreamhost.py | |
| index e80ca37..59d03f8 100644 | |
| --- libcloud/compute/drivers/dreamhost.py | |
| +++ libcloud/compute/drivers/dreamhost.py | |
| @@ -26,15 +26,14 @@ import copy | |
| from libcloud.pricing import get_pricing | |
| from libcloud.common.base import ConnectionKey, Response | |
| from libcloud.common.types import InvalidCredsError | |
| -from libcloud.compute.base import Node, NodeDriver, NodeLocation, NodeSize | |
| +from libcloud.compute.base import Node, NodeDriver, NodeSize | |
| from libcloud.compute.base import NodeImage | |
| from libcloud.compute.types import Provider, NodeState | |
| -""" | |
| -DreamHost Private Servers can be resized on the fly, but Libcloud doesn't | |
| -currently support extensions to its interface, so we'll put some basic sizes | |
| -in for node creation. | |
| -""" | |
| +# DreamHost Private Servers can be resized on the fly, but Libcloud doesn't | |
| +# currently support extensions to its interface, so we'll put some basic sizes | |
| +# in for node creation. | |
| + | |
| DH_PS_SIZES = { | |
| 'minimum': { | |
| 'id' : 'minimum', | |
| @@ -100,7 +99,8 @@ class DreamhostResponse(Response): | |
| def _api_parse_error(self, response): | |
| if 'data' in response: | |
| if response['data'] == 'invalid_api_key': | |
| - raise InvalidCredsError("Oops! You've entered an invalid API key") | |
| + raise InvalidCredsError( | |
| + "Oops! You've entered an invalid API key") | |
| else: | |
| raise DreamhostAPIException(response['data']) | |
| else: | |
| @@ -186,11 +186,13 @@ class DreamhostNodeDriver(NodeDriver): | |
| return False | |
| def list_nodes(self, **kwargs): | |
| - data = self.connection.request('/', {'cmd': 'dreamhost_ps-list_ps'}).object | |
| + data = self.connection.request( | |
| + '/', {'cmd': 'dreamhost_ps-list_ps'}).object | |
| return [self._to_node(n) for n in data] | |
| def list_images(self, **kwargs): | |
| - data = self.connection.request('/', {'cmd': 'dreamhost_ps-list_images'}).object | |
| + data = self.connection.request( | |
| + '/', {'cmd': 'dreamhost_ps-list_images'}).object | |
| images = [] | |
| for img in data: | |
| images.append(NodeImage( | |
| @@ -210,7 +212,9 @@ class DreamhostNodeDriver(NodeDriver): | |
| return sizes | |
| def list_locations(self, **kwargs): | |
| - raise NotImplementedError('You cannot select a location for DreamHost Private Servers at this time.') | |
| + raise NotImplementedError( | |
| + 'You cannot select a location for ' | |
| + 'DreamHost Private Servers at this time.') | |
| ############################################ | |
| # Private Methods (helpers and extensions) # | |
| @@ -243,6 +247,4 @@ class DreamhostNodeDriver(NodeDriver): | |
| extra = { | |
| 'current_size' : data['memory_mb'], | |
| 'account_id' : data['account_id'], | |
| - 'type' : data['type'] | |
| - } | |
| - ) | |
| + 'type' : data['type']}) | |
| diff --git libcloud/compute/drivers/rackspace.py libcloud/compute/drivers/rackspace.py | |
| index 356bb65..34a9061 100644 | |
| --- libcloud/compute/drivers/rackspace.py | |
| +++ libcloud/compute/drivers/rackspace.py | |
| @@ -18,20 +18,19 @@ Rackspace driver | |
| import os | |
| import base64 | |
| -import urlparse | |
| from xml.etree import ElementTree as ET | |
| from xml.parsers.expat import ExpatError | |
| from libcloud.pricing import get_pricing | |
| - | |
| -from libcloud.common.base import ConnectionUserAndKey, Response | |
| -from libcloud.common.types import InvalidCredsError, MalformedResponseError | |
| +from libcloud.common.base import Response | |
| +from libcloud.common.types import MalformedResponseError | |
| from libcloud.compute.types import NodeState, Provider | |
| from libcloud.compute.base import NodeDriver, Node | |
| from libcloud.compute.base import NodeSize, NodeImage, NodeLocation | |
| -from libcloud.common.rackspace import AUTH_HOST_US, AUTH_HOST_UK, RackspaceBaseConnection | |
| +from libcloud.common.rackspace import ( | |
| + AUTH_HOST_US, AUTH_HOST_UK, RackspaceBaseConnection) | |
| NAMESPACE='http://docs.rackspacecloud.com/servers/api/v1.0' | |
| @@ -48,14 +47,19 @@ class RackspaceResponse(Response): | |
| try: | |
| body = ET.XML(self.body) | |
| except: | |
| - raise MalformedResponseError("Failed to parse XML", body=self.body, driver=RackspaceNodeDriver) | |
| + raise MalformedResponseError( | |
| + "Failed to parse XML", | |
| + body=self.body, | |
| + driver=RackspaceNodeDriver) | |
| return body | |
| def parse_error(self): | |
| # TODO: fixup, Rackspace only uses response codes really! | |
| try: | |
| body = ET.XML(self.body) | |
| except: | |
| - raise MalformedResponseError("Failed to parse XML", body=self.body, driver=RackspaceNodeDriver) | |
| + raise MalformedResponseError( | |
| + "Failed to parse XML", | |
| + body=self.body, driver=RackspaceNodeDriver) | |
| try: | |
| text = "; ".join([ err.text or '' | |
| for err in | |
| @@ -188,7 +192,8 @@ class RackspaceNodeDriver(NodeDriver): | |
| server_elm = ET.Element('server', body) | |
| - resp = self.connection.request(uri, method='PUT', data=ET.tostring(server_elm)) | |
| + resp = self.connection.request( | |
| + uri, method='PUT', data=ET.tostring(server_elm)) | |
| if resp.status == 204 and password != None: | |
| node.extra['password'] = password | |
| @@ -243,7 +248,8 @@ class RackspaceNodeDriver(NodeDriver): | |
| if files_elm: | |
| server_elm.append(files_elm) | |
| - shared_ip_elm = self._shared_ip_group_to_xml(kwargs.get("ex_shared_ip_group", None)) | |
| + shared_ip_elm = self._shared_ip_group_to_xml( | |
| + kwargs.get("ex_shared_ip_group", None)) | |
| if shared_ip_elm: | |
| server_elm.append(shared_ip_elm) | |
| @@ -414,7 +420,8 @@ class RackspaceNodeDriver(NodeDriver): | |
| n = Node(id=el.get('id'), | |
| name=el.get('name'), | |
| - state=self.NODE_STATE_MAP.get(el.get('status'), NodeState.UNKNOWN), | |
| + state=self.NODE_STATE_MAP.get( | |
| + el.get('status'), NodeState.UNKNOWN), | |
| public_ip=public_ip, | |
| private_ip=private_ip, | |
| driver=self.connection.driver, | |
| @@ -423,7 +430,9 @@ class RackspaceNodeDriver(NodeDriver): | |
| 'hostId': el.get('hostId'), | |
| 'imageId': el.get('imageId'), | |
| 'flavorId': el.get('flavorId'), | |
| - 'uri': "https://%s%s/servers/%s" % (self.connection.host, self.connection.request_path, el.get('id')), | |
| + 'uri': "https://%s%s/servers/%s" % ( | |
| + self.connection.host, | |
| + self.connection.request_path, el.get('id')), | |
| 'metadata': metadata, | |
| }) | |
| return n | |
| @@ -461,7 +470,7 @@ class RackspaceNodeDriver(NodeDriver): | |
| rates (for example amount of POST requests per day) | |
| and absolute limits like total amount of available | |
| RAM to be used by servers. | |
| - | |
| + | |
| @return: C{dict} with keys 'rate' and 'absolute' | |
| """ | |
| @@ -506,7 +515,8 @@ class RackspaceNodeDriver(NodeDriver): | |
| def _to_shared_ip_group(self, el): | |
| servers_el = self._findall(el, 'servers') | |
| if servers_el: | |
| - servers = [s.get('id') for s in self._findall(servers_el[0], 'server')] | |
| + servers = [s.get('id') | |
| + for s in self._findall(servers_el[0], 'server')] | |
| else: | |
| servers = None | |
| return RackspaceSharedIpGroup(id=el.get('id'), | |
| @@ -515,8 +525,10 @@ class RackspaceNodeDriver(NodeDriver): | |
| def _to_ip_addresses(self, el): | |
| return RackspaceNodeIpAddresses( | |
| - [ip.get('addr') for ip in self._findall(self._findall(el, 'public')[0], 'ip')], | |
| - [ip.get('addr') for ip in self._findall(self._findall(el, 'private')[0], 'ip')] | |
| + [ip.get('addr') for ip in | |
| + self._findall(self._findall(el, 'public')[0], 'ip')], | |
| + [ip.get('addr') for ip in | |
| + self._findall(self._findall(el, 'private')[0], 'ip')] | |
| ) | |
| def _shared_ip_group_to_xml(self, shared_ip_group): | |
| diff --git libcloud/compute/drivers/slicehost.py libcloud/compute/drivers/slicehost.py | |
| index d2eff0b..1cf866e 100644 | |
| --- libcloud/compute/drivers/slicehost.py | |
| +++ libcloud/compute/drivers/slicehost.py | |
| @@ -21,22 +21,27 @@ import socket | |
| from xml.etree import ElementTree as ET | |
| from xml.parsers.expat import ExpatError | |
| -from libcloud.common.base import ConnectionUserAndKey, ConnectionKey, Response | |
| -from libcloud.compute.types import NodeState, Provider, InvalidCredsError, MalformedResponseError | |
| +from libcloud.common.base import ConnectionKey, Response | |
| +from libcloud.compute.types import ( | |
| + NodeState, Provider, InvalidCredsError, MalformedResponseError) | |
| from libcloud.compute.base import NodeSize, NodeDriver, NodeImage, NodeLocation | |
| from libcloud.compute.base import Node, is_private_subnet | |
| class SlicehostResponse(Response): | |
| def parse_body(self): | |
| - # length of 1 can't be valid XML, but on destroy node, slicehost returns | |
| - # a 1 byte response with a "Content-Type: application/xml" header. booya. | |
| + # length of 1 can't be valid XML, but on destroy node, | |
| + # slicehost returns a 1 byte response with a "Content-Type: | |
| + # application/xml" header. booya. | |
| if not self.body or len(self.body) <= 1: | |
| return None | |
| try: | |
| body = ET.XML(self.body) | |
| except: | |
| - raise MalformedResponseError("Failed to parse XML", body=self.body, driver=SlicehostNodeDriver) | |
| + raise MalformedResponseError( | |
| + "Failed to parse XML", | |
| + body=self.body, | |
| + driver=SlicehostNodeDriver) | |
| return body | |
| def parse_error(self): | |
| @@ -46,7 +51,10 @@ class SlicehostResponse(Response): | |
| try: | |
| body = ET.XML(self.body) | |
| except: | |
| - raise MalformedResponseError("Failed to parse XML", body=self.body, driver=SlicehostNodeDriver) | |
| + raise MalformedResponseError( | |
| + "Failed to parse XML", | |
| + body=self.body, | |
| + driver=SlicehostNodeDriver) | |
| try: | |
| return "; ".join([ err.text | |
| for err in | |
| diff --git libcloud/compute/providers.py libcloud/compute/providers.py | |
| index 89c6efd..e24e398 100644 | |
| --- libcloud/compute/providers.py | |
| +++ libcloud/compute/providers.py | |
| @@ -16,9 +16,12 @@ | |
| Provider related utilities | |
| """ | |
| -from libcloud.utils import get_driver as get_provider_driver | |
| +from libcloud.utils import get_driver as _get_provider_driver | |
| from libcloud.compute.types import Provider | |
| - | |
| +__all__ = [ | |
| + "Provider", | |
| + "DRIVERS", | |
| + "get_driver"] | |
| DRIVERS = { | |
| Provider.DUMMY: | |
| ('libcloud.compute.drivers.dummy', 'DummyNodeDriver'), | |
| @@ -73,4 +76,4 @@ DRIVERS = { | |
| } | |
| def get_driver(provider): | |
| - return get_provider_driver(DRIVERS, provider) | |
| + return _get_provider_driver(DRIVERS, provider) | |
| diff --git libcloud/compute/types.py libcloud/compute/types.py | |
| index eff9290..d9f62be 100644 | |
| --- libcloud/compute/types.py | |
| +++ libcloud/compute/types.py | |
| @@ -18,7 +18,18 @@ Base types used by other parts of libcloud | |
| from libcloud.common.types import LibcloudError, MalformedResponseError | |
| from libcloud.common.types import InvalidCredsError, InvalidCredsException | |
| +__all__ = [ | |
| + "Provider", | |
| + "NodeState", | |
| + "DeploymentError", | |
| + "DeploymentException", | |
| + # @@TR: should the unused imports below be exported? | |
| + "LibcloudError", | |
| + "MalformedResponseError", | |
| + "InvalidCredsError", | |
| + "InvalidCredsException" | |
| + ] | |
| class Provider(object): | |
| """ | |
| Defines for each of the supported providers | |
| diff --git libcloud/deployment.py libcloud/deployment.py | |
| index 38e2dc5..cbf51c8 100644 | |
| --- libcloud/deployment.py | |
| +++ libcloud/deployment.py | |
| @@ -14,6 +14,18 @@ | |
| # limitations under the License. | |
| from libcloud.utils import deprecated_warning | |
| -from libcloud.compute.deployment import * | |
| +from libcloud.compute.deployment import ( # pylint: disable-msg=W0611 | |
| + Deployment, | |
| + SSHKeyDeployment, | |
| + ScriptDeployment, | |
| + MultiStepDeployment | |
| + ) | |
| + | |
| +__all__ = [ | |
| + "Deployment", | |
| + "SSHKeyDeployment", | |
| + "ScriptDeployment", | |
| + "MultiStepDeployment" | |
| + ] | |
| deprecated_warning(__name__) | |
| diff --git libcloud/pricing.py libcloud/pricing.py | |
| index 44421fa..6283bdb 100644 | |
| --- libcloud/pricing.py | |
| +++ libcloud/pricing.py | |
| @@ -12,6 +12,7 @@ | |
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| # See the License for the specific language governing permissions and | |
| # limitations under the License. | |
| +from __future__ import with_statement | |
| """ | |
| A class which handles loading the pricing files. | |
| """ | |
| diff --git libcloud/providers.py libcloud/providers.py | |
| index d26cb41..337b52f 100644 | |
| --- libcloud/providers.py | |
| +++ libcloud/providers.py | |
| @@ -14,6 +14,18 @@ | |
| # limitations under the License. | |
| from libcloud.utils import deprecated_warning | |
| -from libcloud.compute.providers import * | |
| - | |
| +from libcloud.compute.providers import ( | |
| + DRIVERS, | |
| + Provider, | |
| + providers, | |
| + get_driver, | |
| + get_provider_driver # @@TR: can this be removed from here? | |
| + ) | |
| +__all__ = [ | |
| + "DRIVERS", | |
| + "Provider", | |
| + "providers", | |
| + "get_driver", | |
| + "get_provider_driver" | |
| + ] | |
| deprecated_warning(__name__) | |
| diff --git libcloud/security.py libcloud/security.py | |
| index d761a97..9ac72f5 100644 | |
| --- libcloud/security.py | |
| +++ libcloud/security.py | |
| @@ -42,8 +42,8 @@ CA_CERTS_PATH = [ | |
| ] | |
| CA_CERTS_UNAVAILABLE_MSG = ( | |
| - 'Warning: No CA Certificates were found in CA_CERTS_PATH. ' | |
| - 'Toggling VERIFY_SSL_CERT to False.' | |
| + 'Warning: No CA Certificates were found in CA_CERTS_PATH. ' | |
| + 'Toggling VERIFY_SSL_CERT to False.' | |
| ) | |
| VERIFY_SSL_DISABLED_MSG = ( | |
| diff --git libcloud/ssh.py libcloud/ssh.py | |
| index 9c0b7a6..8901d7c 100644 | |
| --- libcloud/ssh.py | |
| +++ libcloud/ssh.py | |
| @@ -14,6 +14,17 @@ | |
| # limitations under the License. | |
| from libcloud.utils import deprecated_warning | |
| -from libcloud.compute.ssh import * | |
| +from libcloud.compute.ssh import ( | |
| + BaseSSHClient, | |
| + ParamikoSSHClient, | |
| + ShellOutSSHClient, | |
| + SSHClient, | |
| + have_paramiko) | |
| +__all__ = [ | |
| + "BaseSSHClient", | |
| + "ParamikoSSHClient", | |
| + "ShellOutSSHClient", | |
| + "SSHClient", | |
| + "have_paramiko"] | |
| deprecated_warning(__name__) | |
| diff --git libcloud/storage/base.py libcloud/storage/base.py | |
| index 3b68e4b..241dcf5 100644 | |
| --- libcloud/storage/base.py | |
| +++ libcloud/storage/base.py | |
| @@ -17,7 +17,7 @@ | |
| from __future__ import with_statement | |
| import os | |
| -import os.path | |
| +import os.path # pylint: disable-msg=W0404 | |
| import hashlib | |
| from os.path import join as pjoin | |
| @@ -78,8 +78,8 @@ class Object(object): | |
| return self.driver.delete_object(self) | |
| def __repr__(self): | |
| - return '<Object: name=%s, size=%s, hash=%s, provider=%s ...>' % \ | |
| - (self.name, self.size, self.hash, self.driver.name) | |
| + return ('<Object: name=%s, size=%s, hash=%s, provider=%s ...>' % | |
| + (self.name, self.size, self.hash, self.driver.name)) | |
| class Container(object): | |
| """ | |
| @@ -110,10 +110,12 @@ class Container(object): | |
| object_name=object_name) | |
| def upload_object(self, file_path, object_name, extra=None, file_hash=None): | |
| - return self.driver.upload_object(file_path, self, object_name, extra, file_hash) | |
| + return self.driver.upload_object( | |
| + file_path, self, object_name, extra, file_hash) | |
| def upload_object_via_stream(self, iterator, object_name, extra=None): | |
| - return self.driver.upload_object_via_stream(iterator, self, object_name, extra) | |
| + return self.driver.upload_object_via_stream( | |
| + iterator, self, object_name, extra) | |
| def download_object(self, obj, destination_path, overwrite_existing=False, | |
| delete_on_failure=True): | |
| @@ -129,7 +131,8 @@ class Container(object): | |
| return self.driver.delete_container(self) | |
| def __repr__(self): | |
| - return '<Container: name=%s, provider=%s>' % (self.name, self.driver.name) | |
| + return ('<Container: name=%s, provider=%s>' | |
| + % (self.name, self.driver.name)) | |
| class StorageDriver(object): | |
| """ | |
| @@ -169,12 +172,12 @@ class StorageDriver(object): | |
| @return A C{dict} with account meta data. | |
| """ | |
| - raise NotImplementedError, \ | |
| - 'get_account_meta_data not implemented for this driver' | |
| + raise NotImplementedError( | |
| + 'get_account_meta_data not implemented for this driver') | |
| def list_containters(self): | |
| - raise NotImplementedError, \ | |
| - 'list_containers not implemented for this driver' | |
| + raise NotImplementedError( | |
| + 'list_containers not implemented for this driver') | |
| def list_container_objects(self, container): | |
| """ | |
| @@ -185,8 +188,8 @@ class StorageDriver(object): | |
| @return A list of Object instances. | |
| """ | |
| - raise NotImplementedError, \ | |
| - 'list_objects not implemented for this driver' | |
| + raise NotImplementedError( | |
| + 'list_objects not implemented for this driver') | |
| def get_container(self, container_name): | |
| """ | |
| @@ -197,8 +200,8 @@ class StorageDriver(object): | |
| @return: C{Container} instance. | |
| """ | |
| - raise NotImplementedError, \ | |
| - 'get_object not implemented for this driver' | |
| + raise NotImplementedError( | |
| + 'get_object not implemented for this driver') | |
| def get_object(self, container_name, object_name): | |
| """ | |
| @@ -212,8 +215,8 @@ class StorageDriver(object): | |
| @return: C{Object} instance. | |
| """ | |
| - raise NotImplementedError, \ | |
| - 'get_object not implemented for this driver' | |
| + raise NotImplementedError( | |
| + 'get_object not implemented for this driver') | |
| def download_object(self, obj, destination_path, delete_on_failure=True): | |
| """ | |
| @@ -236,8 +239,8 @@ class StorageDriver(object): | |
| @return C{bool} True if an object has been successfully downloaded, False | |
| otherwise. | |
| """ | |
| - raise NotImplementedError, \ | |
| - 'download_object not implemented for this driver' | |
| + raise NotImplementedError( | |
| + 'download_object not implemented for this driver') | |
| def download_object_as_stream(self, obj, chunk_size=None): | |
| """ | |
| @@ -249,8 +252,8 @@ class StorageDriver(object): | |
| @type chunk_size: C{int} | |
| @param chunk_size: Optional chunk size (in bytes). | |
| """ | |
| - raise NotImplementedError, \ | |
| - 'download_object_as_stream not implemented for this driver' | |
| + raise NotImplementedError( | |
| + 'download_object_as_stream not implemented for this driver') | |
| def upload_object(self, file_path, container, object_name, extra=None, | |
| file_hash=None): | |
| @@ -274,10 +277,12 @@ class StorageDriver(object): | |
| on upload and if it doesn't match the one provided an | |
| exception is thrown. | |
| """ | |
| - raise NotImplementedError, \ | |
| - 'upload_object not implemented for this driver' | |
| + raise NotImplementedError( | |
| + 'upload_object not implemented for this driver') | |
| - def upload_object_via_stream(self, iterator, container, object_name, extra=None): | |
| + def upload_object_via_stream(self, iterator, container, | |
| + object_name, | |
| + extra=None): | |
| """ | |
| @type iterator: C{object} | |
| @param iterator: An object which implements the iterator interface. | |
| @@ -291,8 +296,8 @@ class StorageDriver(object): | |
| @type extra: C{dict} | |
| @param extra: (optional) Extra attributes (driver specific). | |
| """ | |
| - raise NotImplementedError, \ | |
| - 'upload_object_via_stream not implemented for this driver' | |
| + raise NotImplementedError( | |
| + 'upload_object_via_stream not implemented for this driver') | |
| def delete_object(self, obj): | |
| """ | |
| @@ -303,8 +308,8 @@ class StorageDriver(object): | |
| @return: C{bool} True on success. | |
| """ | |
| - raise NotImplementedError, \ | |
| - 'delete_object not implemented for this driver' | |
| + raise NotImplementedError( | |
| + 'delete_object not implemented for this driver') | |
| def create_container(self, container_name): | |
| """ | |
| @@ -315,8 +320,8 @@ class StorageDriver(object): | |
| @return C{Container} instance on success. | |
| """ | |
| - raise NotImplementedError, \ | |
| - 'create_container not implemented for this driver' | |
| + raise NotImplementedError( | |
| + 'create_container not implemented for this driver') | |
| def delete_container(self, container): | |
| """ | |
| @@ -327,8 +332,8 @@ class StorageDriver(object): | |
| @return C{bool} True on success, False otherwise. | |
| """ | |
| - raise NotImplementedError, \ | |
| - 'delete_container not implemented for this driver' | |
| + raise NotImplementedError( | |
| + 'delete_container not implemented for this driver') | |
| def _save_object(self, response, obj, destination_path, | |
| overwrite_existing=False, delete_on_failure=True, | |
| @@ -363,8 +368,9 @@ class StorageDriver(object): | |
| base_name = os.path.basename(destination_path) | |
| if not base_name and not os.path.exists(destination_path): | |
| - raise LibcloudError(value='Path %s does not exist' % (destination_path), | |
| - driver=self) | |
| + raise LibcloudError( | |
| + value='Path %s does not exist' % (destination_path), | |
| + driver=self) | |
| if not base_name: | |
| file_path = pjoin(destination_path, obj.name) | |
| @@ -372,9 +378,10 @@ class StorageDriver(object): | |
| file_path = destination_path | |
| if os.path.exists(file_path) and not overwrite_existing: | |
| - raise LibcloudError(value='File %s already exists, but ' % (file_path) + | |
| - 'overwrite_existing=False', | |
| - driver=self) | |
| + raise LibcloudError( | |
| + value='File %s already exists, but ' % (file_path) + | |
| + 'overwrite_existing=False', | |
| + driver=self) | |
| stream = utils.read_in_chunks(response, chunk_size) | |
| @@ -452,7 +459,11 @@ class StorageDriver(object): | |
| response.connection.connection.send('\r\n') | |
| else: | |
| response.connection.connection.send(chunk) | |
| - except Exception, e: | |
| + except Exception: | |
| + # @@TR: this wildcard try/except block looks like it | |
| + # could mask unexpected errors. It should be narrowed | |
| + # down to expected exceptions. | |
| + | |
| # Timeout, etc. | |
| return False, None, bytes_transferred | |
| @@ -493,10 +504,11 @@ class StorageDriver(object): | |
| is the number of transferred bytes. | |
| """ | |
| with open (file_path, 'rb') as file_handle: | |
| - success, data_hash, bytes_transferred = \ | |
| - self._stream_data(response=response, | |
| - iterator=iter(file_handle), | |
| - chunked=chunked, | |
| - calculate_hash=calculate_hash) | |
| + success, data_hash, bytes_transferred = ( | |
| + self._stream_data( | |
| + response=response, | |
| + iterator=iter(file_handle), | |
| + chunked=chunked, | |
| + calculate_hash=calculate_hash)) | |
| return success, data_hash, bytes_transferred | |
| diff --git libcloud/storage/drivers/cloudfiles.py libcloud/storage/drivers/cloudfiles.py | |
| index 16327a6..119867a 100644 | |
| --- libcloud/storage/drivers/cloudfiles.py | |
| +++ libcloud/storage/drivers/cloudfiles.py | |
| @@ -14,7 +14,6 @@ | |
| # limitations under the License. | |
| import httplib | |
| -import urlparse | |
| import os.path | |
| import urllib | |
| @@ -25,8 +24,7 @@ except: | |
| from libcloud import utils | |
| from libcloud.common.types import MalformedResponseError, LibcloudError | |
| -from libcloud.common.types import InvalidCredsError | |
| -from libcloud.common.base import ConnectionUserAndKey, Response | |
| +from libcloud.common.base import Response | |
| from libcloud.storage.providers import Provider | |
| from libcloud.storage.base import Object, Container, StorageDriver | |
| @@ -37,7 +35,8 @@ from libcloud.storage.types import ObjectDoesNotExistError | |
| from libcloud.storage.types import ObjectHashMismatchError | |
| from libcloud.storage.types import InvalidContainerNameError | |
| -from libcloud.common.rackspace import AUTH_HOST_US, AUTH_HOST_UK, RackspaceBaseConnection | |
| +from libcloud.common.rackspace import ( | |
| + AUTH_HOST_US, AUTH_HOST_UK, RackspaceBaseConnection) | |
| API_VERSION = 'v1.0' | |
| @@ -145,9 +144,12 @@ class CloudFilesStorageDriver(StorageDriver): | |
| response = self.connection.request('', method='HEAD') | |
| if response.status == httplib.NO_CONTENT: | |
| - container_count = response.headers.get('x-account-container-count', 'unknown') | |
| - object_count = response.headers.get('x-account-object-count', 'unknown') | |
| - bytes_used = response.headers.get('x-account-bytes-used', 'unknown') | |
| + container_count = response.headers.get( | |
| + 'x-account-container-count', 'unknown') | |
| + object_count = response.headers.get( | |
| + 'x-account-object-count', 'unknown') | |
| + bytes_used = response.headers.get( | |
| + 'x-account-bytes-used', 'unknown') | |
| return { 'container_count': int(container_count), | |
| 'object_count': int(object_count), | |
| @@ -181,7 +183,8 @@ class CloudFilesStorageDriver(StorageDriver): | |
| method='HEAD') | |
| if response.status == httplib.NO_CONTENT: | |
| - container = self._headers_to_container(container_name, response.headers) | |
| + container = self._headers_to_container( | |
| + container_name, response.headers) | |
| return container | |
| elif response.status == httplib.NOT_FOUND: | |
| raise ContainerDoesNotExistError(None, self, container_name) | |
| @@ -195,7 +198,8 @@ class CloudFilesStorageDriver(StorageDriver): | |
| method='HEAD') | |
| if response.status in [ httplib.OK, httplib.NO_CONTENT ]: | |
| - obj = self._headers_to_object(object_name, container, response.headers) | |
| + obj = self._headers_to_object( | |
| + object_name, container, response.headers) | |
| return obj | |
| elif response.status == httplib.NOT_FOUND: | |
| raise ObjectDoesNotExistError(None, self, object_name) | |
| @@ -204,7 +208,8 @@ class CloudFilesStorageDriver(StorageDriver): | |
| def create_container(self, container_name): | |
| container_name = self._clean_container_name(container_name) | |
| - response = self.connection.request('/%s' % (container_name), method='PUT') | |
| + response = self.connection.request( | |
| + '/%s' % (container_name), method='PUT') | |
| if response.status == httplib.CREATED: | |
| # Accepted mean that container is not yet created but it will be | |
| @@ -262,7 +267,8 @@ class CloudFilesStorageDriver(StorageDriver): | |
| upload_func=upload_func, | |
| upload_func_args=upload_func_args) | |
| - def upload_object_via_stream(self, iterator, container, object_name, extra=None): | |
| + def upload_object_via_stream(self, iterator, | |
| + container, object_name, extra=None): | |
| if isinstance(iterator, file): | |
| iterator = iter(iterator) | |
| @@ -278,8 +284,8 @@ class CloudFilesStorageDriver(StorageDriver): | |
| container_name = self._clean_container_name(obj.container.name) | |
| object_name = self._clean_object_name(obj.name) | |
| - response = self.connection.request('/%s/%s' % (container_name, | |
| - object_name), method='DELETE') | |
| + response = self.connection.request( | |
| + '/%s/%s' % (container_name, object_name), method='DELETE') | |
| if response.status == httplib.NO_CONTENT: | |
| return True | |
| @@ -302,7 +308,10 @@ class CloudFilesStorageDriver(StorageDriver): | |
| if response.status == httplib.OK: | |
| return callback(**callback_args) | |
| elif response.status == httplib.NOT_FOUND: | |
| - raise ObjectDoesNotExistError(name=object_name) | |
| + raise ObjectDoesNotExistError( | |
| + object_name=object_name, | |
| + driver=self, | |
| + value='') | |
| raise LibcloudError('Unexpected status code: %s' % (response.status)) | |
| @@ -323,8 +332,9 @@ class CloudFilesStorageDriver(StorageDriver): | |
| content_type, _ = utils.guess_file_mime_type(name) | |
| if not content_type: | |
| - raise AttributeError('File content-type could not be guessed and' + | |
| - ' no content_type value provided') | |
| + raise AttributeError( | |
| + 'File content-type could not be guessed and' + | |
| + ' no content_type value provided') | |
| headers = {} | |
| if iterator: | |
| @@ -361,12 +371,14 @@ class CloudFilesStorageDriver(StorageDriver): | |
| if response.status == httplib.EXPECTATION_FAILED: | |
| raise LibcloudError('Missing content-type header') | |
| elif response.status == httplib.UNPROCESSABLE_ENTITY: | |
| - raise ObjectHashMismatchError(value='MD5 hash checksum does not match', | |
| - object_name=object_name, driver=self) | |
| + raise ObjectHashMismatchError( | |
| + value='MD5 hash checksum does not match', | |
| + object_name=object_name, driver=self) | |
| elif response.status == httplib.CREATED: | |
| - obj = Object(name=object_name, size=bytes_transferred, hash=file_hash, | |
| - extra=None, meta_data=meta_data, container=container, | |
| - driver=self) | |
| + obj = Object( | |
| + name=object_name, size=bytes_transferred, hash=file_hash, | |
| + extra=None, meta_data=meta_data, container=container, | |
| + driver=self) | |
| return obj | |
| @@ -416,8 +428,9 @@ class CloudFilesStorageDriver(StorageDriver): | |
| hash = obj['hash'] | |
| extra = { 'content_type': obj['content_type'], | |
| 'last_modified': obj['last_modified'] } | |
| - objects.append(Object(name=name, size=size, hash=hash, extra=extra, | |
| - meta_data=None, container=container, driver=self)) | |
| + objects.append(Object( | |
| + name=name, size=size, hash=hash, extra=extra, | |
| + meta_data=None, container=container, driver=self)) | |
| return objects | |
| diff --git libcloud/storage/drivers/dummy.py libcloud/storage/drivers/dummy.py | |
| index 295a436..ef0f76c 100644 | |
| --- libcloud/storage/drivers/dummy.py | |
| +++ libcloud/storage/drivers/dummy.py | |
| @@ -47,18 +47,19 @@ class DummyFileObject(file): | |
| return self._yield_count * self._chunk_len | |
| class DummyIterator(object): | |
| - def __init__(self, data=None): | |
| - self._data = data or [] | |
| - self._current_item = 0 | |
| + def __init__(self, data=None): | |
| + self._data = data or [] | |
| + self._current_item = 0 | |
| - def next(self): | |
| - if self._current_item == len(self._data): | |
| - raise StopIteration | |
| + def next(self): | |
| + if self._current_item == len(self._data): | |
| + raise StopIteration | |
| - value = self._data[self._current_item] | |
| - self._current_item += 1 | |
| - return value | |
| + value = self._data[self._current_item] | |
| + self._current_item += 1 | |
| + return value | |
| +# @@FIX: the doctests below are not run by the main test suite | |
| class DummyStorageDriver(StorageDriver): | |
| """ | |
| Dummy Storage driver. | |
| @@ -86,7 +87,8 @@ class DummyStorageDriver(StorageDriver): | |
| {'object_count': 0, 'container_count': 0, 'bytes_used': 0} | |
| >>> container = driver.create_container(container_name='test container 1') | |
| >>> container = driver.create_container(container_name='test container 2') | |
| - >>> obj = container.upload_object_via_stream(object_name='test object', iterator=DummyFileObject(5, 10), extra={}) | |
| + >>> obj = container.upload_object_via_stream( | |
| + ... object_name='test object', iterator=DummyFileObject(5, 10), extra={}) | |
| >>> driver.get_meta_data() | |
| {'object_count': 1, 'container_count': 2, 'bytes_used': 50} | |
| """ | |
| @@ -118,7 +120,8 @@ class DummyStorageDriver(StorageDriver): | |
| >>> container = driver.create_container(container_name='test container 2') | |
| >>> container | |
| <Container: name=test container 2, provider=Dummy Storage Provider> | |
| - >>> container = driver.create_container(container_name='test container 2') #doctest: +IGNORE_EXCEPTION_DETAIL | |
| + >>> container = driver.create_container( | |
| + ... container_name='test container 2') #doctest: +IGNORE_EXCEPTION_DETAIL | |
| Traceback (most recent call last): | |
| ContainerAlreadyExistsError: | |
| >>> container_list=driver.list_containers() | |
| @@ -150,29 +153,31 @@ class DummyStorageDriver(StorageDriver): | |
| """ | |
| if container_name not in self._containers: | |
| - raise ContainerDoesNotExistError(driver=self, value=None, | |
| - container_name=container_name) | |
| + raise ContainerDoesNotExistError(driver=self, value=None, | |
| + container_name=container_name) | |
| return self._containers[container_name]['container'] | |
| def get_object(self, container_name, object_name): | |
| """ | |
| - >>> driver = DummyStorageDriver('key', 'secret') | |
| - >>> driver.get_object('unknown', 'unknown') #doctest: +IGNORE_EXCEPTION_DETAIL | |
| - Traceback (most recent call last): | |
| - ContainerDoesNotExistError: | |
| - >>> container = driver.create_container(container_name='test container 1') | |
| - >>> container | |
| - <Container: name=test container 1, provider=Dummy Storage Provider> | |
| - >>> driver.get_object('test container 1', 'unknown') #doctest: +IGNORE_EXCEPTION_DETAIL | |
| - Traceback (most recent call last): | |
| - ObjectDoesNotExistError: | |
| - >>> obj = container.upload_object_via_stream(object_name='test object', iterator=DummyFileObject(5, 10), extra={}) | |
| - >>> obj | |
| - <Object: name=test object, size=50, hash=None, provider=Dummy Storage Provider ...> | |
| + >>> driver = DummyStorageDriver('key', 'secret') | |
| + >>> driver.get_object('unknown', 'unknown') #doctest: +IGNORE_EXCEPTION_DETAIL | |
| + Traceback (most recent call last): | |
| + ContainerDoesNotExistError: | |
| + >>> container = driver.create_container(container_name='test container 1') | |
| + >>> container | |
| + <Container: name=test container 1, provider=Dummy Storage Provider> | |
| + >>> driver.get_object( | |
| + ... 'test container 1', 'unknown') #doctest: +IGNORE_EXCEPTION_DETAIL | |
| + Traceback (most recent call last): | |
| + ObjectDoesNotExistError: | |
| + >>> obj = container.upload_object_via_stream(object_name='test object', | |
| + ... iterator=DummyFileObject(5, 10), extra={}) | |
| + >>> obj | |
| + <Object: name=test object, size=50, hash=None, provider=Dummy Storage Provider ...> | |
| """ | |
| - container = self.get_container(container_name) | |
| + self.get_container(container_name) | |
| container_objects = self._containers[container_name]['objects'] | |
| if object_name not in container_objects: | |
| @@ -187,7 +192,8 @@ class DummyStorageDriver(StorageDriver): | |
| >>> container = driver.create_container(container_name='test container 1') | |
| >>> container | |
| <Container: name=test container 1, provider=Dummy Storage Provider> | |
| - >>> container = driver.create_container(container_name='test container 1') #doctest: +IGNORE_EXCEPTION_DETAIL | |
| + >>> container = driver.create_container( | |
| + ... container_name='test container 1') #doctest: +IGNORE_EXCEPTION_DETAIL | |
| Traceback (most recent call last): | |
| ContainerAlreadyExistsError: | |
| """ | |
| @@ -207,52 +213,58 @@ class DummyStorageDriver(StorageDriver): | |
| def delete_container(self, container): | |
| """ | |
| >>> driver = DummyStorageDriver('key', 'secret') | |
| - >>> container = Container(name = 'test container', extra={'object_count': 0}, driver=driver) | |
| - >>> driver.delete_container(container=container) #doctest: +IGNORE_EXCEPTION_DETAIL | |
| + >>> container = Container(name = 'test container', | |
| + ... extra={'object_count': 0}, driver=driver) | |
| + >>> driver.delete_container(container=container)#doctest: +IGNORE_EXCEPTION_DETAIL | |
| Traceback (most recent call last): | |
| ContainerDoesNotExistError: | |
| - >>> container = driver.create_container(container_name='test container 1') #doctest: +IGNORE_EXCEPTION_DETAIL | |
| + >>> container = driver.create_container( | |
| + ... container_name='test container 1') #doctest: +IGNORE_EXCEPTION_DETAIL | |
| >>> len(driver._containers) | |
| 1 | |
| >>> driver.delete_container(container=container) | |
| True | |
| >>> len(driver._containers) | |
| 0 | |
| - >>> container = driver.create_container(container_name='test container 1') #doctest: +IGNORE_EXCEPTION_DETAIL | |
| - >>> obj = container.upload_object_via_stream(object_name='test object', iterator=DummyFileObject(5, 10), extra={}) | |
| - >>> driver.delete_container(container=container) #doctest: +IGNORE_EXCEPTION_DETAIL | |
| + >>> container = driver.create_container( | |
| + ... container_name='test container 1') #doctest: +IGNORE_EXCEPTION_DETAIL | |
| + >>> obj = container.upload_object_via_stream( | |
| + ... object_name='test object', iterator=DummyFileObject(5, 10), extra={}) | |
| + >>> driver.delete_container(container=container)#doctest: +IGNORE_EXCEPTION_DETAIL | |
| Traceback (most recent call last): | |
| ContainerIsNotEmptyError: | |
| """ | |
| container_name = container.name | |
| if container_name not in self._containers: | |
| - raise ContainerDoesNotExistError(container_name=container_name, | |
| - value=None, driver=self) | |
| + raise ContainerDoesNotExistError(container_name=container_name, | |
| + value=None, driver=self) | |
| container = self._containers[container_name] | |
| if len(container['objects']) > 0: | |
| - raise ContainerIsNotEmptyError(container_name=container_name, | |
| - value=None, driver=self) | |
| + raise ContainerIsNotEmptyError(container_name=container_name, | |
| + value=None, driver=self) | |
| del self._containers[container_name] | |
| return True | |
| def download_object(self, obj, destination_path, overwrite_existing=False, | |
| delete_on_failure=True): | |
| - kwargs_dict = {'obj': obj, | |
| - 'response': DummyFileObject(), | |
| - 'destination_path': destination_path, | |
| - 'overwrite_existing': overwrite_existing, | |
| - 'delete_on_failure': delete_on_failure} | |
| + kwargs_dict = {'obj': obj, | |
| + 'response': DummyFileObject(), | |
| + 'destination_path': destination_path, | |
| + 'overwrite_existing': overwrite_existing, | |
| + 'delete_on_failure': delete_on_failure} | |
| - return self._save_object(**kwargs_dict) | |
| + return self._save_object(**kwargs_dict) | |
| def download_object_as_stream(self, obj, chunk_size=None): | |
| """ | |
| >>> driver = DummyStorageDriver('key', 'secret') | |
| - >>> container = driver.create_container(container_name='test container 1') #doctest: +IGNORE_EXCEPTION_DETAIL | |
| - >>> obj = container.upload_object_via_stream(object_name='test object', iterator=DummyFileObject(5, 10), extra={}) | |
| + >>> container = driver.create_container( | |
| + ... container_name='test container 1') #doctest: +IGNORE_EXCEPTION_DETAIL | |
| + >>> obj = container.upload_object_via_stream(object_name='test object', | |
| + ... iterator=DummyFileObject(5, 10), extra={}) | |
| >>> stream = container.download_object_as_stream(obj) | |
| >>> stream #doctest: +ELLIPSIS | |
| <closed file '<uninitialized file>', mode '<uninitialized file>' at 0x...> | |
| @@ -265,7 +277,8 @@ class DummyStorageDriver(StorageDriver): | |
| """ | |
| >>> driver = DummyStorageDriver('key', 'secret') | |
| >>> container = driver.create_container(container_name='test container 1') | |
| - >>> container.upload_object(file_path='/tmp/inexistent.file', object_name='test') #doctest: +IGNORE_EXCEPTION_DETAIL | |
| + >>> container.upload_object(file_path='/tmp/inexistent.file', | |
| + ... object_name='test') #doctest: +IGNORE_EXCEPTION_DETAIL | |
| Traceback (most recent call last): | |
| LibcloudError: | |
| >>> file_path = path = os.path.abspath(__file__) | |
| @@ -285,11 +298,14 @@ class DummyStorageDriver(StorageDriver): | |
| return self._add_object(container=container, object_name=object_name, | |
| size=size, extra=extra) | |
| - def upload_object_via_stream(self, iterator, container, object_name, extra=None): | |
| + def upload_object_via_stream(self, iterator, container, | |
| + object_name, extra=None): | |
| """ | |
| >>> driver = DummyStorageDriver('key', 'secret') | |
| - >>> container = driver.create_container(container_name='test container 1') #doctest: +IGNORE_EXCEPTION_DETAIL | |
| - >>> obj = container.upload_object_via_stream(object_name='test object', iterator=DummyFileObject(5, 10), extra={}) | |
| + >>> container = driver.create_container( | |
| + ... container_name='test container 1') #doctest: +IGNORE_EXCEPTION_DETAIL | |
| + >>> obj = container.upload_object_via_stream( | |
| + ... object_name='test object', iterator=DummyFileObject(5, 10), extra={}) | |
| >>> obj #doctest: +ELLIPSIS | |
| <Object: name=test object, size=50, ...> | |
| """ | |
| @@ -301,13 +317,17 @@ class DummyStorageDriver(StorageDriver): | |
| def delete_object(self, obj): | |
| """ | |
| >>> driver = DummyStorageDriver('key', 'secret') | |
| - >>> container = driver.create_container(container_name='test container 1') #doctest: +IGNORE_EXCEPTION_DETAIL | |
| - >>> obj = container.upload_object_via_stream(object_name='test object', iterator=DummyFileObject(5, 10), extra={}) | |
| + >>> container = driver.create_container( | |
| + ... container_name='test container 1') #doctest: +IGNORE_EXCEPTION_DETAIL | |
| + >>> obj = container.upload_object_via_stream(object_name='test object', | |
| + ... iterator=DummyFileObject(5, 10), extra={}) | |
| >>> obj #doctest: +ELLIPSIS | |
| <Object: name=test object, size=50, ...> | |
| >>> container.delete_object(obj=obj) | |
| True | |
| - >>> obj = Object(name='test object 2', size=1000, hash=None, extra=None, meta_data=None, container=container,driver=None) | |
| + >>> obj = Object(name='test object 2', | |
| + ... size=1000, hash=None, extra=None, | |
| + ... meta_data=None, container=container,driver=None) | |
| >>> container.delete_object(obj=obj) #doctest: +IGNORE_EXCEPTION_DETAIL | |
| Traceback (most recent call last): | |
| ObjectDoesNotExistError: | |
| diff --git libcloud/storage/types.py libcloud/storage/types.py | |
| index ebf8d58..781500c 100644 | |
| --- libcloud/storage/types.py | |
| +++ libcloud/storage/types.py | |
| @@ -15,6 +15,16 @@ | |
| from libcloud.common.types import LibcloudError | |
| +__all__ = ['Provider', | |
| + 'ContainerError', | |
| + 'ObjectError', | |
| + 'ContainerAlreadyExistsError', | |
| + 'ContainerDoesNotExistError', | |
| + 'ContainerIsNotEmptyError', | |
| + 'ObjectDoesNotExistError', | |
| + 'ObjectHashMismatchError', | |
| + 'InvalidContainerNameError'] | |
| + | |
| class Provider(object): | |
| """ | |
| Defines for each of the supported providers | |
| @@ -35,8 +45,9 @@ class ContainerError(LibcloudError): | |
| super(ContainerError, self).__init__(value=value, driver=driver) | |
| def __str__(self): | |
| - return '<%s in %s, container = %s>' % (self.error_type, repr(self.driver), | |
| - self.container_name) | |
| + return ('<%s in %s, container = %s>' % | |
| + (self.error_type, repr(self.driver), | |
| + self.container_name)) | |
| class ObjectError(LibcloudError): | |
| error_type = 'ContainerError' | |
| diff --git libcloud/types.py libcloud/types.py | |
| index e95356f..18aebe4 100644 | |
| --- libcloud/types.py | |
| +++ libcloud/types.py | |
| @@ -20,4 +20,9 @@ from libcloud.compute.types import DeploymentException | |
| from libcloud.utils import deprecated_warning | |
| +__all__ = ["LibcloudError", "MalformedResponseError", | |
| + "InvalidCredsError", "InvalidCredsException", | |
| + "Provider", "NodeState", "DeploymentError", | |
| + "DeploymentException" | |
| + ] | |
| deprecated_warning(__name__) | |
| diff --git libcloud/utils.py libcloud/utils.py | |
| index 3631a3d..08782d5 100644 | |
| --- libcloud/utils.py | |
| +++ libcloud/utils.py | |
| @@ -56,10 +56,10 @@ def guess_file_mime_type(file_path): | |
| def deprecated_warning(module): | |
| if SHOW_DEPRECATION_WARNING: | |
| warnings.warn('This path has been deprecated and the module' | |
| - ' is now available at "libcloud.compute.%s".' | |
| - ' This path will be fully removed in libcloud %s.' % \ | |
| - (module, OLD_API_REMOVE_VERSION), | |
| - category=DeprecationWarning) | |
| + ' is now available at "libcloud.compute.%s".' | |
| + ' This path will be fully removed in libcloud %s.' % | |
| + (module, OLD_API_REMOVE_VERSION), | |
| + category=DeprecationWarning) | |
| def str2dicts(data): | |
| """ | |
| diff --git setup.py setup.py | |
| index 9acae7b..4b07c4c 100644 | |
| --- setup.py | |
| +++ setup.py | |
| @@ -34,7 +34,7 @@ class TestCommand(Command): | |
| THIS_DIR = os.path.abspath(os.path.split(__file__)[0]) | |
| sys.path.insert(0, THIS_DIR) | |
| for test_path in TEST_PATHS: | |
| - sys.path.insert(0, pjoin(THIS_DIR, test_path)) | |
| + sys.path.insert(0, pjoin(THIS_DIR, test_path)) | |
| self._dir = os.getcwd() | |
| def finalize_options(self): | |
| @@ -59,11 +59,13 @@ class TestCommand(Command): | |
| # test for dependencies | |
| try: | |
| import simplejson | |
| + simplejson # silence pyflakes | |
| except ImportError: | |
| missing.append("simplejson") | |
| try: | |
| import ssl | |
| + ssl # silence pyflakes | |
| except ImportError: | |
| missing.append("ssl") | |
| @@ -73,10 +75,9 @@ class TestCommand(Command): | |
| testfiles = [] | |
| for test_path in TEST_PATHS: | |
| - for t in glob(pjoin(self._dir, test_path, 'test_*.py')): | |
| - testfiles.append('.'.join( | |
| - [test_path.replace('/', '.'), splitext(basename(t))[0]]) | |
| - ) | |
| + for t in glob(pjoin(self._dir, test_path, 'test_*.py')): | |
| + testfiles.append('.'.join( | |
| + [test_path.replace('/', '.'), splitext(basename(t))[0]])) | |
| tests = TestLoader().loadTestsFromNames(testfiles) | |
| t = TextTestRunner(verbosity = 2) | |
| diff --git test/__init__.py test/__init__.py | |
| index 97a9816..0763c02 100644 | |
| --- test/__init__.py | |
| +++ test/__init__.py | |
| @@ -18,8 +18,6 @@ from cStringIO import StringIO | |
| from urllib2 import urlparse | |
| from cgi import parse_qs | |
| -from libcloud.common.base import RawResponse | |
| - | |
| class multipleresponse(object): | |
| """ | |
| A decorator that allows MockHttp objects to return multi responses | |
| diff --git test/compute/__init__.py test/compute/__init__.py | |
| index 9c0675e..b7f04ad 100644 | |
| --- test/compute/__init__.py | |
| +++ test/compute/__init__.py | |
| @@ -13,11 +13,6 @@ | |
| # See the License for the specific language governing permissions and | |
| # limitations under the License. | |
| -import httplib | |
| -from cStringIO import StringIO | |
| -from urllib2 import urlparse | |
| -from cgi import parse_qs | |
| - | |
| from libcloud.compute.base import Node, NodeImage, NodeLocation | |
| class TestCaseMixin(object): | |
| diff --git test/compute/test_base.py test/compute/test_base.py | |
| index f8c9bd3..b56e9bb 100644 | |
| --- test/compute/test_base.py | |
| +++ test/compute/test_base.py | |
| @@ -19,7 +19,7 @@ from libcloud.common.base import Response | |
| from libcloud.common.base import ConnectionKey, ConnectionUserAndKey | |
| from libcloud.compute.base import Node, NodeSize, NodeImage, NodeDriver | |
| -from test import MockResponse | |
| +from test import MockResponse # pylint: disable-msg=E0611 | |
| class FakeDriver(object): | |
| type = 0 | |
| @@ -27,57 +27,27 @@ class FakeDriver(object): | |
| class BaseTests(unittest.TestCase): | |
| def test_base_node(self): | |
| - node = Node(id=0, name=0, state=0, public_ip=0, private_ip=0, | |
| - driver=FakeDriver()) | |
| + Node(id=0, name=0, state=0, public_ip=0, private_ip=0, | |
| + driver=FakeDriver()) | |
| def test_base_node_size(self): | |
| - node_size = NodeSize(id=0, name=0, ram=0, disk=0, bandwidth=0, price=0, | |
| - driver=FakeDriver()) | |
| + NodeSize(id=0, name=0, ram=0, disk=0, bandwidth=0, price=0, | |
| + driver=FakeDriver()) | |
| def test_base_node_image(self): | |
| - node_image = NodeImage(id=0, name=0, driver=FakeDriver()) | |
| + NodeImage(id=0, name=0, driver=FakeDriver()) | |
| def test_base_response(self): | |
| - resp = Response(MockResponse(status=200, body='foo')) | |
| + Response(MockResponse(status=200, body='foo')) | |
| def test_base_node_driver(self): | |
| - node_driver = NodeDriver('foo') | |
| + NodeDriver('foo') | |
| def test_base_connection_key(self): | |
| - conn = ConnectionKey('foo') | |
| + ConnectionKey('foo') | |
| def test_base_connection_userkey(self): | |
| - conn = ConnectionUserAndKey('foo', 'bar') | |
| - | |
| -# def test_drivers_interface(self): | |
| -# failures = [] | |
| -# for driver in DRIVERS: | |
| -# creds = ProviderCreds(driver, 'foo', 'bar') | |
| -# try: | |
| -# verifyObject(INodeDriver, get_driver(driver)(creds)) | |
| -# except BrokenImplementation: | |
| -# failures.append(DRIVERS[driver][1]) | |
| -# | |
| -# if failures: | |
| -# self.fail('the following drivers do not support the \ | |
| -# INodeDriver interface: %s' % (', '.join(failures))) | |
| - | |
| -# def test_invalid_creds(self): | |
| -# failures = [] | |
| -# for driver in DRIVERS: | |
| -# if driver == Provider.DUMMY: | |
| -# continue | |
| -# conn = connect(driver, 'bad', 'keys') | |
| -# try: | |
| -# conn.list_nodes() | |
| -# except InvalidCredsException: | |
| -# pass | |
| -# else: | |
| -# failures.append(DRIVERS[driver][1]) | |
| -# | |
| -# if failures: | |
| -# self.fail('the following drivers did not throw an \ | |
| -# InvalidCredsException: %s' % (', '.join(failures))) | |
| + ConnectionUserAndKey('foo', 'bar') | |
| if __name__ == '__main__': | |
| sys.exit(unittest.main()) | |
| diff --git test/compute/test_cloudsigma.py test/compute/test_cloudsigma.py | |
| index e9e4dda..f825d10 100644 | |
| --- test/compute/test_cloudsigma.py | |
| +++ test/compute/test_cloudsigma.py | |
| @@ -21,9 +21,9 @@ from libcloud.compute.base import Node | |
| from libcloud.compute.drivers.cloudsigma import CloudSigmaZrhNodeDriver | |
| from libcloud.utils import str2dicts, str2list, dict2str | |
| -from test import MockHttp | |
| -from test.compute import TestCaseMixin | |
| -from test.file_fixtures import ComputeFileFixtures | |
| +from test import MockHttp # pylint: disable-msg=E0611 | |
| +from test.compute import TestCaseMixin # pylint: disable-msg=E0611 | |
| +from test.file_fixtures import ComputeFileFixtures # pylint: disable-msg=E0611 | |
| class CloudSigmaTestCase(unittest.TestCase, TestCaseMixin): | |
| @@ -72,12 +72,13 @@ class CloudSigmaTestCase(unittest.TestCase, TestCaseMixin): | |
| def test_destroy_node(self): | |
| node = self.driver.list_nodes()[0] | |
| self.assertTrue(self.driver.destroy_node(node)) | |
| - nodes = self.driver.list_nodes() | |
| + self.driver.list_nodes() | |
| def test_create_node(self): | |
| size = self.driver.list_sizes()[0] | |
| image = self.driver.list_images()[0] | |
| - node = self.driver.create_node(name = "cloudsigma node", image = image, size = size) | |
| + node = self.driver.create_node( | |
| + name="cloudsigma node", image=image, size = size) | |
| self.assertTrue(isinstance(node, Node)) | |
| def test_ex_static_ip_list(self): | |
| @@ -99,7 +100,9 @@ class CloudSigmaTestCase(unittest.TestCase, TestCaseMixin): | |
| self.assertEqual(len(result), 2) | |
| def test_ex_drive_destroy(self): | |
| - result = self.driver.ex_drive_destroy('d18119ce_7afa_474a_9242_e0384b160220') | |
| + result = self.driver.ex_drive_destroy( | |
| + # @@TR: this should be soft-coded: | |
| + 'd18119ce_7afa_474a_9242_e0384b160220') | |
| self.assertTrue(result) | |
| def test_ex_set_node_configuration(self): | |
| @@ -135,20 +138,31 @@ class CloudSigmaHttp(MockHttp): | |
| body = self.fixtures.load('drives_standard_info.txt') | |
| return (httplib.OK, body, {}, httplib.responses[httplib.OK]) | |
| - def _servers_62fe7cde_4fb9_4c63_bd8c_e757930066a0_start(self, method, url, body, headers): | |
| + def _servers_62fe7cde_4fb9_4c63_bd8c_e757930066a0_start( | |
| + self, method, url, body, headers): | |
| + | |
| return (httplib.OK, body, {}, httplib.responses[httplib.OK]) | |
| - def _servers_62fe7cde_4fb9_4c63_bd8c_e757930066a0_stop(self, method, url, body, headers): | |
| + def _servers_62fe7cde_4fb9_4c63_bd8c_e757930066a0_stop( | |
| + self, method, url, body, headers): | |
| + | |
| return (httplib.NO_CONTENT, body, {}, httplib.responses[httplib.OK]) | |
| - def _servers_62fe7cde_4fb9_4c63_bd8c_e757930066a0_destroy(self, method, url, body, headers): | |
| - return (httplib.NO_CONTENT, body, {}, httplib.responses[httplib.NO_CONTENT]) | |
| + def _servers_62fe7cde_4fb9_4c63_bd8c_e757930066a0_destroy( | |
| + self, method, url, body, headers): | |
| + | |
| + return (httplib.NO_CONTENT, | |
| + body, {}, httplib.responses[httplib.NO_CONTENT]) | |
| + | |
| + def _drives_d18119ce_7afa_474a_9242_e0384b160220_clone( | |
| + self, method, url, body, headers): | |
| - def _drives_d18119ce_7afa_474a_9242_e0384b160220_clone(self, method, url, body, headers): | |
| body = self.fixtures.load('drives_clone.txt') | |
| return (httplib.OK, body, {}, httplib.responses[httplib.OK]) | |
| - def _drives_a814def5_1789_49a0_bf88_7abe7bb1682a_info(self, method, url, body, headers): | |
| + def _drives_a814def5_1789_49a0_bf88_7abe7bb1682a_info( | |
| + self, method, url, body, headers): | |
| + | |
| body = self.fixtures.load('drives_single_info.txt') | |
| return (httplib.OK, body, {}, httplib.responses[httplib.OK]) | |
| @@ -175,10 +189,14 @@ class CloudSigmaHttp(MockHttp): | |
| def _resources_ip_1_2_3_4_destroy(self, method, url, body, headers): | |
| return (httplib.NO_CONTENT, body, {}, httplib.responses[httplib.OK]) | |
| - def _drives_d18119ce_7afa_474a_9242_e0384b160220_destroy(self, method, url, body, headers): | |
| + def _drives_d18119ce_7afa_474a_9242_e0384b160220_destroy( | |
| + self, method, url, body, headers): | |
| + | |
| return (httplib.NO_CONTENT, body, {}, httplib.responses[httplib.OK]) | |
| - def _servers_62fe7cde_4fb9_4c63_bd8c_e757930066a0_set(self, method, url, body, headers): | |
| + def _servers_62fe7cde_4fb9_4c63_bd8c_e757930066a0_set( | |
| + self, method, url, body, headers): | |
| + | |
| body = self.fixtures.load('servers_set.txt') | |
| return (httplib.OK, body, {}, httplib.responses[httplib.OK]) | |
| diff --git test/compute/test_gogrid.py test/compute/test_gogrid.py | |
| index d84cf03..31e1464 100644 | |
| --- test/compute/test_gogrid.py | |
| +++ test/compute/test_gogrid.py | |
| @@ -17,18 +17,13 @@ import sys | |
| import unittest | |
| import urlparse | |
| -try: | |
| - import json | |
| -except ImportError: | |
| - import simplejson as json | |
| - | |
| from libcloud.common.types import LibcloudError, InvalidCredsError | |
| from libcloud.compute.drivers.gogrid import GoGridNodeDriver, GoGridIpAddress | |
| from libcloud.compute.base import Node, NodeImage, NodeSize, NodeLocation | |
| -from test import MockHttp | |
| -from test.compute import TestCaseMixin | |
| -from test.file_fixtures import ComputeFileFixtures | |
| +from test import MockHttp # pylint: disable-msg=E0611 | |
| +from test.compute import TestCaseMixin # pylint: disable-msg=E0611 | |
| +from test.file_fixtures import ComputeFileFixtures # pylint: disable-msg=E0611 | |
| class GoGridTests(unittest.TestCase, TestCaseMixin): | |
| @@ -37,11 +32,21 @@ class GoGridTests(unittest.TestCase, TestCaseMixin): | |
| GoGridMockHttp.type = None | |
| self.driver = GoGridNodeDriver("foo", "bar") | |
| + def _get_test_512Mb_node_size(self): | |
| + return NodeSize(id='512Mb', | |
| + name=None, | |
| + ram=None, | |
| + disk=None, | |
| + bandwidth=None, | |
| + price=None, | |
| + driver=self.driver) | |
| + | |
| def test_create_node(self): | |
| image = NodeImage(1531, None, self.driver) | |
| - size = NodeSize('512Mb', None, None, None, None, None, driver=self.driver) | |
| - | |
| - node = self.driver.create_node(name='test1', image=image, size=size) | |
| + node = self.driver.create_node( | |
| + name='test1', | |
| + image=image, | |
| + size=self._get_test_512Mb_node_size()) | |
| self.assertEqual(node.name, 'test1') | |
| self.assertTrue(node.id is not None) | |
| self.assertEqual(node.extra['password'], 'bebebe') | |
| @@ -73,7 +78,7 @@ class GoGridTests(unittest.TestCase, TestCaseMixin): | |
| def test_malformed_reply(self): | |
| GoGridMockHttp.type = 'FAIL' | |
| try: | |
| - images = self.driver.list_images() | |
| + self.driver.list_images() | |
| except LibcloudError, e: | |
| self.assertTrue(isinstance(e, LibcloudError)) | |
| else: | |
| @@ -82,7 +87,7 @@ class GoGridTests(unittest.TestCase, TestCaseMixin): | |
| def test_invalid_creds(self): | |
| GoGridMockHttp.type = 'FAIL' | |
| try: | |
| - nodes = self.driver.list_nodes() | |
| + self.driver.list_nodes() | |
| except InvalidCredsError, e: | |
| self.assertTrue(e.driver is not None) | |
| self.assertEqual(e.driver.name, self.driver.name) | |
| @@ -93,9 +98,10 @@ class GoGridTests(unittest.TestCase, TestCaseMixin): | |
| GoGridMockHttp.type = 'NOPUBIPS' | |
| try: | |
| image = NodeImage(1531, None, self.driver) | |
| - size = NodeSize('512Mb', None, None, None, None, None, driver=self.driver) | |
| - | |
| - node = self.driver.create_node(name='test1', image=image, size=size) | |
| + self.driver.create_node( | |
| + name='test1', | |
| + image=image, | |
| + size=self._get_test_512Mb_node_size()) | |
| except LibcloudError, e: | |
| self.assertTrue(isinstance(e, LibcloudError)) | |
| self.assertTrue(e.driver is not None) | |
| @@ -126,9 +132,10 @@ class GoGridTests(unittest.TestCase, TestCaseMixin): | |
| self.assertTrue(isinstance(ret, NodeImage)) | |
| def test_ex_edit_node(self): | |
| - node = Node(90967, None, None, None, None, self.driver) | |
| - size = NodeSize('512Mb', None, None, None, None, None, driver=self.driver) | |
| - ret = self.driver.ex_edit_node(node=node, size=size) | |
| + node = Node(id=90967, name=None, state=None, | |
| + public_ip=None, private_ip=None, driver=self.driver) | |
| + ret = self.driver.ex_edit_node(node=node, | |
| + size=self._get_test_512Mb_node_size()) | |
| self.assertTrue(isinstance(ret, Node)) | |
| @@ -177,7 +184,8 @@ class GoGridMockHttp(MockHttp): | |
| _api_grid_server_list_NOPUBIPS = _api_grid_server_list | |
| def _api_grid_server_list_FAIL(self, method, url, body, headers): | |
| - return (httplib.FORBIDDEN, "123", {}, httplib.responses[httplib.FORBIDDEN]) | |
| + return (httplib.FORBIDDEN, | |
| + "123", {}, httplib.responses[httplib.FORBIDDEN]) | |
| def _api_grid_ip_list(self, method, url, body, headers): | |
| body = self.fixtures.load('ip_list.json') | |
| diff --git test/compute/test_softlayer.py test/compute/test_softlayer.py | |
| index c8e453e..3f2190a 100644 | |
| --- test/compute/test_softlayer.py | |
| +++ test/compute/test_softlayer.py | |
| @@ -23,11 +23,10 @@ import xmlrpclib | |
| from libcloud.compute.drivers.softlayer import SoftLayerNodeDriver as SoftLayer | |
| from libcloud.compute.types import NodeState | |
| -from test import MockHttp | |
| -from test.compute import TestCaseMixin | |
| -from test.file_fixtures import ComputeFileFixtures | |
| - | |
| -from test.secrets import SOFTLAYER_USER, SOFTLAYER_APIKEY | |
| +from test import MockHttp # pylint: disable-msg=E0611 | |
| +from test.file_fixtures import ComputeFileFixtures # pylint: disable-msg=E0611 | |
| +from test.secrets import ( # pylint: disable-msg=E0611 | |
| + SOFTLAYER_USER, SOFTLAYER_APIKEY) | |
| class MockSoftLayerTransport(xmlrpclib.Transport): | |
| @@ -43,7 +42,8 @@ class MockSoftLayerTransport(xmlrpclib.Transport): | |
| class SoftLayerTests(unittest.TestCase): | |
| def setUp(self): | |
| - SoftLayer.connectionCls.proxyCls.transportCls = [MockSoftLayerTransport, MockSoftLayerTransport] | |
| + SoftLayer.connectionCls.proxyCls.transportCls = [ | |
| + MockSoftLayerTransport, MockSoftLayerTransport] | |
| self.driver = SoftLayer(SOFTLAYER_USER, SOFTLAYER_APIKEY) | |
| def test_list_nodes(self): | |
| @@ -71,12 +71,17 @@ class SoftLayerTests(unittest.TestCase): | |
| class SoftLayerMockHttp(MockHttp): | |
| fixtures = ComputeFileFixtures('softlayer') | |
| - def _xmlrpc_v3_SoftLayer_Account_getVirtualGuests(self, method, url, body, headers): | |
| + def _xmlrpc_v3_SoftLayer_Account_getVirtualGuests( | |
| + self, method, url, body, headers): | |
| + | |
| body = self.fixtures.load('v3_SoftLayer_Account_getVirtualGuests.xml') | |
| return (httplib.OK, body, {}, httplib.responses[httplib.OK]) | |
| - def _xmlrpc_v3_SoftLayer_Location_Datacenter_getDatacenters(self, method, url, body, headers): | |
| - body = self.fixtures.load('v3_SoftLayer_Location_Datacenter_getDatacenters.xml') | |
| + def _xmlrpc_v3_SoftLayer_Location_Datacenter_getDatacenters( | |
| + self, method, url, body, headers): | |
| + | |
| + body = self.fixtures.load( | |
| + 'v3_SoftLayer_Location_Datacenter_getDatacenters.xml') | |
| return (httplib.OK, body, {}, httplib.responses[httplib.OK]) | |
| if __name__ == '__main__': | |
| diff --git test/storage/test_cloudfiles.py test/storage/test_cloudfiles.py | |
| index e7debeb..427dcff 100644 | |
| --- test/storage/test_cloudfiles.py | |
| +++ test/storage/test_cloudfiles.py | |
| @@ -13,7 +13,7 @@ | |
| # See the License for the specific language governing permissions and | |
| # limitations under the License. | |
| import os | |
| -import os.path | |
| +import os.path # pylint: disable-msg=W0404 | |
| import random | |
| import sys | |
| import copy | |
| @@ -30,17 +30,18 @@ from libcloud.storage.types import ContainerIsNotEmptyError | |
| from libcloud.storage.types import ObjectDoesNotExistError | |
| from libcloud.storage.types import ObjectHashMismatchError | |
| from libcloud.storage.drivers.cloudfiles import CloudFilesStorageDriver | |
| -from libcloud.storage.drivers.dummy import DummyFileObject, DummyIterator | |
| +from libcloud.storage.drivers.dummy import DummyIterator | |
| -from test import MockHttp, MockRawResponse | |
| -from test.file_fixtures import StorageFileFixtures | |
| +from test import MockHttp, MockRawResponse # pylint: disable-msg=E0611 | |
| +from test.file_fixtures import StorageFileFixtures # pylint: disable-msg=E0611 | |
| class CloudFilesTests(unittest.TestCase): | |
| def setUp(self): | |
| - CloudFilesStorageDriver.connectionCls.conn_classes = (None, | |
| - CloudFilesMockHttp) | |
| - CloudFilesStorageDriver.connectionCls.rawResponseCls = CloudFilesMockRawResponse | |
| + CloudFilesStorageDriver.connectionCls.conn_classes = ( | |
| + None, CloudFilesMockHttp) | |
| + CloudFilesStorageDriver.connectionCls.rawResponseCls = \ | |
| + CloudFilesMockRawResponse | |
| CloudFilesMockHttp.type = None | |
| CloudFilesMockRawResponse.type = None | |
| self.driver = CloudFilesStorageDriver('dummy', 'dummy') | |
| @@ -50,7 +51,7 @@ class CloudFilesTests(unittest.TestCase): | |
| self._remove_test_file() | |
| def test_get_meta_data(self): | |
| - meta_data = self.driver.get_meta_data() | |
| + self.driver.get_meta_data() | |
| def test_list_containers(self): | |
| CloudFilesMockHttp.type = 'EMPTY' | |
| @@ -67,7 +68,8 @@ class CloudFilesTests(unittest.TestCase): | |
| def test_list_container_objects(self): | |
| CloudFilesMockHttp.type = 'EMPTY' | |
| - container = Container(name='test_container', extra={}, driver=self.driver) | |
| + container = Container( | |
| + name='test_container', extra={}, driver=self.driver) | |
| objects = self.driver.list_container_objects(container=container) | |
| self.assertEqual(len(objects), 0) | |
| @@ -93,12 +95,14 @@ class CloudFilesTests(unittest.TestCase): | |
| self.assertEqual(obj.size, 555) | |
| self.assertEqual(obj.extra['content_type'], 'application/zip') | |
| self.assertEqual(obj.extra['etag'], '6b21c4a111ac178feacf9ec9d0c71f17') | |
| - self.assertEqual(obj.extra['last_modified'], 'Tue, 25 Jan 2011 22:01:49 GMT') | |
| + self.assertEqual( | |
| + obj.extra['last_modified'], 'Tue, 25 Jan 2011 22:01:49 GMT') | |
| self.assertEqual(obj.meta_data['foo-bar'], 'test 1') | |
| self.assertEqual(obj.meta_data['bar-foo'], 'test 2') | |
| def test_create_container_success(self): | |
| - container = self.driver.create_container(container_name='test_create_container') | |
| + container = self.driver.create_container( | |
| + container_name='test_create_container') | |
| self.assertTrue(isinstance(container, Container)) | |
| self.assertEqual(container.name, 'test_create_container') | |
| self.assertEqual(container.extra['object_count'], 0) | |
| @@ -107,28 +111,34 @@ class CloudFilesTests(unittest.TestCase): | |
| CloudFilesMockHttp.type = 'ALREADY_EXISTS' | |
| try: | |
| - container = self.driver.create_container(container_name='test_create_container') | |
| + self.driver.create_container( | |
| + container_name='test_create_container') | |
| except ContainerAlreadyExistsError: | |
| pass | |
| else: | |
| - self.fail('Container already exists but an exception was not thrown') | |
| + self.fail( | |
| + 'Container already exists but an exception was not thrown') | |
| def test_create_container_invalid_name(self): | |
| try: | |
| - container = self.driver.create_container(container_name='invalid//name/') | |
| + self.driver.create_container(container_name='invalid//name/') | |
| except: | |
| pass | |
| else: | |
| - self.fail('Invalid name was provided (name contains slashes), but exception was not thrown') | |
| + self.fail( | |
| + 'Invalid name was provided (name contains slashes)' | |
| + ', but exception was not thrown') | |
| def test_create_container_invalid_name(self): | |
| name = ''.join([ 'x' for x in range(0, 257)]) | |
| try: | |
| - container = self.driver.create_container(container_name=name) | |
| + self.driver.create_container(container_name=name) | |
| except: | |
| pass | |
| else: | |
| - self.fail('Invalid name was provided (name is too long), but exception was not thrown') | |
| + self.fail( | |
| + 'Invalid name was provided (name is too long)' | |
| + ', but exception was not thrown') | |
| def test_delete_container_success(self): | |
| container = Container(name='foo_bar_container', extra={}, driver=self) | |
| @@ -139,17 +149,18 @@ class CloudFilesTests(unittest.TestCase): | |
| CloudFilesMockHttp.type = 'NOT_FOUND' | |
| container = Container(name='foo_bar_container', extra={}, driver=self) | |
| try: | |
| - result = self.driver.delete_container(container=container) | |
| + self.driver.delete_container(container=container) | |
| except ContainerDoesNotExistError: | |
| pass | |
| else: | |
| - self.fail('Container does not exist but an exception was not thrown') | |
| + self.fail( | |
| + 'Container does not exist but an exception was not thrown') | |
| def test_delete_container_not_empty(self): | |
| CloudFilesMockHttp.type = 'NOT_EMPTY' | |
| container = Container(name='foo_bar_container', extra={}, driver=self) | |
| try: | |
| - result = self.driver.delete_container(container=container) | |
| + self.driver.delete_container(container=container) | |
| except ContainerIsNotEmptyError: | |
| pass | |
| else: | |
| @@ -180,17 +191,22 @@ class CloudFilesTests(unittest.TestCase): | |
| delete_on_failure=True) | |
| self.assertFalse(result) | |
| - def download_object_success_not_found(self): | |
| - CloudFilesMockHttp.type = 'NOT_FOUND' | |
| + def test_download_object_success_not_found(self): | |
| + #CloudFilesMockHttp.type = 'NOT_FOUND' | |
| + CloudFilesMockRawResponse.type = 'NOT_FOUND' | |
| + container = Container(name='foo_bar_container', extra={}, driver=self) | |
| + | |
| obj = Object(name='foo_bar_object', size=1000, hash=None, extra={}, | |
| - container=container, meta_data=None, | |
| + container=container, | |
| + meta_data=None, | |
| driver=CloudFilesStorageDriver) | |
| - destination_path = os.path.abspath(__file__) | |
| + destination_path = os.path.abspath(__file__) + '.temp' | |
| try: | |
| - result = self.driver.download_object(obj=obj, | |
| - destination_path=destination_path, | |
| - overwrite_existing=False, | |
| - delete_on_failure=True) | |
| + self.driver.download_object( | |
| + obj=obj, | |
| + destination_path=destination_path, | |
| + overwrite_existing=False, | |
| + delete_on_failure=True) | |
| except ObjectDoesNotExistError: | |
| pass | |
| else: | |
| @@ -209,7 +225,8 @@ class CloudFilesTests(unittest.TestCase): | |
| file_path = os.path.abspath(__file__) | |
| container = Container(name='foo_bar_container', extra={}, driver=self) | |
| object_name = 'foo_test_upload' | |
| - obj = self.driver.upload_object(file_path=file_path, container=container, | |
| + obj = self.driver.upload_object( | |
| + file_path=file_path, container=container, | |
| object_name=object_name) | |
| self.assertEqual(obj.name, 'foo_test_upload') | |
| self.assertEqual(obj.size, 1000) | |
| @@ -228,13 +245,14 @@ class CloudFilesTests(unittest.TestCase): | |
| container = Container(name='foo_bar_container', extra={}, driver=self) | |
| object_name = 'foo_test_upload' | |
| try: | |
| - obj = self.driver.upload_object(file_path=file_path, container=container, | |
| - object_name=object_name, | |
| - file_hash='footest123') | |
| + self.driver.upload_object(file_path=file_path, container=container, | |
| + object_name=object_name, | |
| + file_hash='footest123') | |
| except ObjectHashMismatchError: | |
| pass | |
| else: | |
| - self.fail('Invalid hash was returned but an exception was not thrown') | |
| + self.fail( | |
| + 'Invalid hash was returned but an exception was not thrown') | |
| finally: | |
| CloudFilesStorageDriver._upload_file = old_func | |
| @@ -248,12 +266,14 @@ class CloudFilesTests(unittest.TestCase): | |
| container = Container(name='foo_bar_container', extra={}, driver=self) | |
| object_name = 'foo_test_upload' | |
| try: | |
| - obj = self.driver.upload_object(file_path=file_path, container=container, | |
| - object_name=object_name) | |
| + self.driver.upload_object(file_path=file_path, container=container, | |
| + object_name=object_name) | |
| except AttributeError: | |
| pass | |
| else: | |
| - self.fail('File content type not provided but an exception was not thrown') | |
| + self.fail( | |
| + 'File content type not provided' | |
| + ' but an exception was not thrown') | |
| finally: | |
| libcloud.utils.guess_file_mime_type = old_func | |
| @@ -273,8 +293,10 @@ class CloudFilesTests(unittest.TestCase): | |
| container = Container(name='foo_bar_container', extra={}, driver=self) | |
| object_name = 'foo_test_upload' | |
| try: | |
| - obj = self.driver.upload_object(file_path=file_path, container=container, | |
| - object_name=object_name) | |
| + self.driver.upload_object( | |
| + file_path=file_path, | |
| + container=container, | |
| + object_name=object_name) | |
| except LibcloudError: | |
| pass | |
| else: | |
| @@ -294,8 +316,10 @@ class CloudFilesTests(unittest.TestCase): | |
| container = Container(name='foo_bar_container', extra={}, driver=self) | |
| object_name = 'foo_test_upload' | |
| try: | |
| - obj = self.driver.upload_object(file_path=file_path, container=container, | |
| - object_name=object_name) | |
| + self.driver.upload_object( | |
| + file_path=file_path, | |
| + container=container, | |
| + object_name=object_name) | |
| except OSError: | |
| pass | |
| else: | |
| @@ -314,7 +338,7 @@ class CloudFilesTests(unittest.TestCase): | |
| object_name = 'foo_test_stream_data' | |
| iterator = DummyIterator(data=['2', '3', '5']) | |
| try: | |
| - obj = self.driver.upload_object_via_stream(container=container, | |
| + self.driver.upload_object_via_stream(container=container, | |
| object_name=object_name, | |
| iterator=iterator) | |
| finally: | |
| @@ -335,7 +359,7 @@ class CloudFilesTests(unittest.TestCase): | |
| container=container, meta_data=None, | |
| driver=CloudFilesStorageDriver) | |
| try: | |
| - result = self.driver.delete_object(obj=obj) | |
| + self.driver.delete_object(obj=obj) | |
| except ObjectDoesNotExistError: | |
| pass | |
| else: | |
| @@ -364,21 +388,30 @@ class CloudFilesMockHttp(MockHttp): | |
| pass | |
| def send(self, data): | |
| - pass | |
| + pass | |
| # fake auth token response | |
| def _v1_0(self, method, url, body, headers): | |
| headers = copy.deepcopy(self.base_headers) | |
| - headers.update({ 'x-server-management-url': 'https://servers.api.rackspacecloud.com/v1.0/slug', | |
| + headers.update({ 'x-server-management-url': | |
| + 'https://servers.api.rackspacecloud.com/v1.0/slug', | |
| 'x-auth-token': 'FE011C19', | |
| - 'x-cdn-management-url': 'https://cdn.clouddrive.com/v1/MossoCloudFS', | |
| + 'x-cdn-management-url': | |
| + 'https://cdn.clouddrive.com/v1/MossoCloudFS', | |
| 'x-storage-token': 'FE011C19', | |
| - 'x-storage-url': 'https://storage4.clouddrive.com/v1/MossoCloudFS'}) | |
| - return (httplib.NO_CONTENT, "", headers, httplib.responses[httplib.NO_CONTENT]) | |
| + 'x-storage-url': | |
| + 'https://storage4.clouddrive.com/v1/MossoCloudFS'}) | |
| + return (httplib.NO_CONTENT, | |
| + "", | |
| + headers, | |
| + httplib.responses[httplib.NO_CONTENT]) | |
| def _v1_MossoCloudFS_EMPTY(self, method, url, body, headers): | |
| body = self.fixtures.load('list_containers_empty.json') | |
| - return (httplib.OK, body, self.base_headers, httplib.responses[httplib.OK]) | |
| + return (httplib.OK, | |
| + body, | |
| + self.base_headers, | |
| + httplib.responses[httplib.OK]) | |
| def _v1_MossoCloudFS(self, method, url, body, headers): | |
| if method == 'GET': | |
| @@ -399,7 +432,10 @@ class CloudFilesMockHttp(MockHttp): | |
| def _v1_MossoCloudFS_test_container_EMPTY(self, method, url, body, headers): | |
| body = self.fixtures.load('list_container_objects_empty.json') | |
| - return (httplib.OK, body, self.base_headers, httplib.responses[httplib.OK]) | |
| + return (httplib.OK, | |
| + body, | |
| + self.base_headers, | |
| + httplib.responses[httplib.OK]) | |
| def _v1_MossoCloudFS_test_container(self, method, url, body, headers): | |
| if method == 'GET': | |
| @@ -417,8 +453,9 @@ class CloudFilesMockHttp(MockHttp): | |
| }) | |
| return (status_code, body, headers, httplib.responses[httplib.OK]) | |
| - def _v1_MossoCloudFS_test_container_test_object(self, method, url, body, | |
| - headers): | |
| + def _v1_MossoCloudFS_test_container_test_object( | |
| + self, method, url, body, headers): | |
| + | |
| if method == 'HEAD': | |
| # get_object | |
| body = self.fixtures.load('list_container_objects_empty.json') | |
| @@ -432,7 +469,9 @@ class CloudFilesMockHttp(MockHttp): | |
| 'content-type': 'application/zip'}) | |
| return (status_code, body, headers, httplib.responses[httplib.OK]) | |
| - def _v1_MossoCloudFS_test_create_container(self, method, url, body, headers): | |
| + def _v1_MossoCloudFS_test_create_container( | |
| + self, method, url, body, headers): | |
| + | |
| # test_create_container_success | |
| body = self.fixtures.load('list_container_objects_empty.json') | |
| headers = self.base_headers | |
| @@ -442,7 +481,9 @@ class CloudFilesMockHttp(MockHttp): | |
| status_code = httplib.CREATED | |
| return (status_code, body, headers, httplib.responses[httplib.OK]) | |
| - def _v1_MossoCloudFS_test_create_container_ALREADY_EXISTS(self, method, url, body, headers): | |
| + def _v1_MossoCloudFS_test_create_container_ALREADY_EXISTS( | |
| + self, method, url, body, headers): | |
| + | |
| # test_create_container_already_exists | |
| body = self.fixtures.load('list_container_objects_empty.json') | |
| headers = self.base_headers | |
| @@ -458,7 +499,9 @@ class CloudFilesMockHttp(MockHttp): | |
| status_code = httplib.NO_CONTENT | |
| return (status_code, body, headers, httplib.responses[httplib.OK]) | |
| - def _v1_MossoCloudFS_foo_bar_container_NOT_FOUND(self, method, url, body, headers): | |
| + def _v1_MossoCloudFS_foo_bar_container_NOT_FOUND( | |
| + self, method, url, body, headers): | |
| + | |
| if method == 'DELETE': | |
| # test_delete_container_not_found | |
| body = self.fixtures.load('list_container_objects_empty.json') | |
| @@ -466,7 +509,9 @@ class CloudFilesMockHttp(MockHttp): | |
| status_code = httplib.NOT_FOUND | |
| return (status_code, body, headers, httplib.responses[httplib.OK]) | |
| - def _v1_MossoCloudFS_foo_bar_container_NOT_EMPTY(self, method, url, body, headers): | |
| + def _v1_MossoCloudFS_foo_bar_container_NOT_EMPTY( | |
| + self, method, url, body, headers): | |
| + | |
| if method == 'DELETE': | |
| # test_delete_container_not_empty | |
| body = self.fixtures.load('list_container_objects_empty.json') | |
| @@ -474,7 +519,9 @@ class CloudFilesMockHttp(MockHttp): | |
| status_code = httplib.CONFLICT | |
| return (status_code, body, headers, httplib.responses[httplib.OK]) | |
| - def _v1_MossoCloudFS_foo_bar_container_foo_bar_object(self, method, url, body, headers): | |
| + def _v1_MossoCloudFS_foo_bar_container_foo_bar_object( | |
| + self, method, url, body, headers): | |
| + | |
| if method == 'DELETE': | |
| # test_delete_object_success | |
| body = self.fixtures.load('list_container_objects_empty.json') | |
| @@ -482,12 +529,15 @@ class CloudFilesMockHttp(MockHttp): | |
| status_code = httplib.NO_CONTENT | |
| return (status_code, body, headers, httplib.responses[httplib.OK]) | |
| - def _v1_MossoCloudFS_foo_bar_container_foo_bar_object_NOT_FOUND(self, method, url, body, headers): | |
| + def _v1_MossoCloudFS_foo_bar_container_foo_bar_object_NOT_FOUND( | |
| + self, method, url, body, headers): | |
| + | |
| if method == 'DELETE': | |
| # test_delete_object_success | |
| body = self.fixtures.load('list_container_objects_empty.json') | |
| headers = self.base_headers | |
| status_code = httplib.NOT_FOUND | |
| + | |
| return (status_code, body, headers, httplib.responses[httplib.OK]) | |
| class CloudFilesMockRawResponse(MockRawResponse): | |
| @@ -496,58 +546,85 @@ class CloudFilesMockRawResponse(MockRawResponse): | |
| base_headers = { 'content-type': 'application/json; charset=UTF-8'} | |
| def __init__(self, *args, **kwargs): | |
| - super(CloudFilesMockRawResponse, self).__init__(*args, **kwargs) | |
| - self._data = [] | |
| - self._current_item = 0 | |
| + super(CloudFilesMockRawResponse, self).__init__(*args, **kwargs) | |
| + self._data = [] | |
| + self._current_item = 0 | |
| def next(self): | |
| if self._current_item == len(self._data): | |
| - raise StopIteration | |
| + raise StopIteration | |
| value = self._data[self._current_item] | |
| self._current_item += 1 | |
| return value | |
| def _generate_random_data(self, size): | |
| - data = [] | |
| - current_size = 0 | |
| - while current_size < size: | |
| - value = str(random.randint(0, 9)) | |
| - value_size = len(value) | |
| - data.append(value) | |
| - current_size += value_size | |
| - | |
| - return data | |
| - | |
| - def _v1_MossoCloudFS_foo_bar_container_foo_test_upload(self, method, url, body, headers): | |
| + data = [] | |
| + current_size = 0 | |
| + while current_size < size: | |
| + value = str(random.randint(0, 9)) | |
| + value_size = len(value) | |
| + data.append(value) | |
| + current_size += value_size | |
| + | |
| + return data | |
| + | |
| + def _v1_MossoCloudFS_foo_bar_container_foo_test_upload( | |
| + self, method, url, body, headers): | |
| # test_object_upload_success | |
| + | |
| body = '' | |
| - header = copy.deepcopy(self.base_headers) | |
| + headers = copy.deepcopy(self.base_headers) | |
| + headers.update(headers) | |
| return (httplib.CREATED, body, headers, httplib.responses[httplib.OK]) | |
| - def _v1_MossoCloudFS_foo_bar_container_foo_test_upload_INVALID_HASH(self, method, url, body, headers): | |
| + def _v1_MossoCloudFS_foo_bar_container_foo_test_upload_INVALID_HASH( | |
| + self, method, url, body, headers): | |
| + | |
| # test_object_upload_invalid_hash | |
| body = '' | |
| headers = self.base_headers | |
| return (httplib.UNPROCESSABLE_ENTITY, body, headers, | |
| httplib.responses[httplib.OK]) | |
| - def _v1_MossoCloudFS_foo_bar_container_foo_bar_object(self, method, url, body, headers): | |
| + def _v1_MossoCloudFS_foo_bar_container_foo_bar_object( | |
| + self, method, url, body, headers): | |
| + | |
| # test_download_object_success | |
| body = 'test' | |
| self._data = self._generate_random_data(1000) | |
| - return (httplib.OK, body, self.base_headers, httplib.responses[httplib.OK]) | |
| + return (httplib.OK, | |
| + body, | |
| + self.base_headers, | |
| + httplib.responses[httplib.OK]) | |
| + | |
| + def _v1_MossoCloudFS_foo_bar_container_foo_bar_object_INVALID_SIZE( | |
| + self, method, url, body, headers): | |
| - def _v1_MossoCloudFS_foo_bar_container_foo_bar_object_INVALID_SIZE(self, method, url, body, headers): | |
| # test_download_object_invalid_file_size | |
| body = 'test' | |
| self._data = self._generate_random_data(100) | |
| - return (httplib.OK, body, self.base_headers, httplib.responses[httplib.OK]) | |
| + return (httplib.OK, body, | |
| + self.base_headers, | |
| + httplib.responses[httplib.OK]) | |
| + | |
| + def _v1_MossoCloudFS_foo_bar_container_foo_bar_object_NOT_FOUND( | |
| + self, method, url, body, headers): | |
| + | |
| + body = '' | |
| + return (httplib.NOT_FOUND, body, | |
| + self.base_headers, | |
| + httplib.responses[httplib.OK]) | |
| + | |
| + def _v1_MossoCloudFS_foo_bar_container_foo_test_stream_data( | |
| + self, method, url, body, headers): | |
| - def _v1_MossoCloudFS_foo_bar_container_foo_test_stream_data(self, method, url, body, headers): | |
| # test_upload_object_via_stream_success | |
| body = 'test' | |
| - return (httplib.OK, body, self.base_headers, httplib.responses[httplib.OK]) | |
| + return (httplib.OK, | |
| + body, | |
| + self.base_headers, | |
| + httplib.responses[httplib.OK]) | |
| if __name__ == '__main__': | |
| sys.exit(unittest.main()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment