Fixing pep8 errors

This commit is contained in:
Tyler Smith 2011-08-01 15:05:53 -07:00
parent 60abf6ee8f
commit 9865adbd24
3 changed files with 84 additions and 104 deletions

View File

@ -378,7 +378,8 @@ if __name__ == "__main__":
sys.exit(1)
LOG.debug("Executing command \"%s\" with args: %s" % (cmd, args))
if not options.load_plugin:
client = Client(options.host, options.port, options.ssl, args[0],FORMAT)
client = Client(options.host, options.port, options.ssl,
args[0], FORMAT)
if "api_func" not in commands[cmd]:
LOG.error("API version of \"%s\" is not yet implemented" % cmd)
sys.exit(1)

View File

@ -21,6 +21,7 @@ import socket
import urllib
from quantum.common.wsgi import Serializer
class api_call(object):
"""A Decorator to add support for format and tenant overriding"""
def __init__(self, f):
@ -28,7 +29,7 @@ class api_call(object):
def __get__(self, instance, owner):
def with_params(*args, **kwargs):
# Backup the format and tenant, then temporarily change them if needed
# Temporarily set format and tenant for this request
(format, tenant) = (instance.format, instance.tenant)
if 'format' in kwargs:
@ -41,6 +42,7 @@ class api_call(object):
return ret
return with_params
class Client(object):
"""A base client class - derived from Glance.BaseClient"""
@ -54,8 +56,8 @@ class Client(object):
port_path = "/networks/%s/ports/%s"
attachment_path = "/networks/%s/ports/%s/attachment"
def __init__(self, host = "127.0.0.1", port = 9696, use_ssl = False,
tenant=None, format="xml", testingStub=None, key_file=None, cert_file=None):
def __init__(self, host="127.0.0.1", port=9696, use_ssl=False, tenant=None,
format="xml", testingStub=None, key_file=None, cert_file=None):
"""
Creates a new client to some service.
@ -64,7 +66,7 @@ class Client(object):
:param use_ssl: True to use SSL, False to use HTTP
:param tenant: The tenant ID to make requests with
:param format: The format to query the server with
:param testingStub: A class that stubs basic server attributes for tests
:param testingStub: A class that stubs basic server methods for tests
:param key_file: The SSL key file to use if use_ssl is true
:param cert_file: The SSL cert file to use if use_ssl is true
"""
@ -180,7 +182,7 @@ class Client(object):
"""
Queries the server for the details of a certain network
"""
return self.do_request("GET", (self.network_path%network))
return self.do_request("GET", self.network_path % (network))
@api_call
def create_network(self, body=None):
@ -263,4 +265,5 @@ class Client(object):
"""
Deletes a port from a network on the server
"""
return self.do_request("DELETE", self.attachment_path % (network,port))
return self.do_request("DELETE",
self.attachment_path % (network, port))

View File

@ -29,6 +29,7 @@ LOG = logging.getLogger('quantum.tests.test_api')
TENANT_1 = 'totore'
TENANT_2 = 'totore2'
class ServerStub():
"""This class stubs a basic server for the API client to talk to"""
@ -70,20 +71,23 @@ class ServerStub():
# Extract important information from the action string to assure sanity
match = re.search('tenants/(.+?)/(.+)\.(json|xml)$', self.action)
(tenant,path,format) = (match.group(1),match.group(2),match.group(3))
tenant = match.group(1)
path = match.group(2)
format = match.group(3)
data = {'data': {'method': self.method, 'action': self.action,
'body': self.body, 'tenant': tenant, 'path': path,
'format': format, 'key_file': self.key_file,
'cert_file': self.cert_file}}
# Serialize it to the proper format so the API client can deserialize it
# Serialize it to the proper format so the API client can handle it
if data['data']['format'] == 'json':
res.content = Serializer().serialize(data, "application/json")
else:
res.content = Serializer().serialize(data, "application/xml")
return res
class APITest(unittest.TestCase):
def setUp(self):
@ -113,7 +117,6 @@ class APITest(unittest.TestCase):
return data
def _test_list_networks(self, tenant=TENANT_1, format='json', status=200):
LOG.debug("_test_list_networks - tenant:%s "\
"- format:%s - START", format, tenant)
@ -123,7 +126,7 @@ class APITest(unittest.TestCase):
"GET",
"networks",
data=[],
params = {'tenant':tenant, 'format':format},)
params={'tenant': tenant, 'format': format})
LOG.debug("_test_list_networks - tenant:%s "\
"- format:%s - END", format, tenant)
@ -165,10 +168,8 @@ class APITest(unittest.TestCase):
status,
"PUT",
"networks/001",
data = [
"001",
{'network': {'net-name': 'newName'}}
],
data=["001",
{'network': {'net-name': 'newName'}}],
params={'tenant': tenant, 'format': format})
LOG.debug("_test_update_network - tenant:%s "\
@ -228,7 +229,6 @@ class APITest(unittest.TestCase):
data=["001"],
params={'tenant': tenant, 'format': format})
LOG.debug("_test_create_port - tenant:%s "\
"- format:%s - END", format, tenant)
@ -246,7 +246,6 @@ class APITest(unittest.TestCase):
LOG.debug("_test_delete_port - tenant:%s "\
"- format:%s - END", format, tenant)
def _test_set_port_state(self, tenant=TENANT_1, format='json', status=200):
LOG.debug("_test_set_port_state - tenant:%s "\
"- format:%s - START", format, tenant)
@ -255,7 +254,8 @@ class APITest(unittest.TestCase):
status,
"PUT",
"networks/001/ports/001",
data = ["001","001",{'port':{'state':'ACTIVE'}}],
data=["001", "001",
{'port': {'state': 'ACTIVE'}}],
params={'tenant': tenant, 'format': format})
LOG.debug("_test_set_port_state - tenant:%s "\
@ -276,7 +276,8 @@ class APITest(unittest.TestCase):
LOG.debug("_test_list_port_attachments - tenant:%s "\
"- format:%s - END", format, tenant)
def _test_attach_resource(self, tenant=TENANT_1, format='json', status=200):
def _test_attach_resource(self, tenant=TENANT_1,
format='json', status=200):
LOG.debug("_test_attach_resource - tenant:%s "\
"- format:%s - START", format, tenant)
@ -284,13 +285,15 @@ class APITest(unittest.TestCase):
status,
"PUT",
"networks/001/ports/001/attachment",
data = ["001","001",{'resource':{'id':'1234'}}],
data=["001", "001",
{'resource': {'id': '1234'}}],
params={'tenant': tenant, 'format': format})
LOG.debug("_test_attach_resource - tenant:%s "\
"- format:%s - END", format, tenant)
def _test_detach_resource(self, tenant=TENANT_1, format='json', status=200):
def _test_detach_resource(self, tenant=TENANT_1,
format='json', status=200):
LOG.debug("_test_detach_resource - tenant:%s "\
"- format:%s - START", format, tenant)
@ -304,7 +307,8 @@ class APITest(unittest.TestCase):
LOG.debug("_test_detach_resource - tenant:%s "\
"- format:%s - END", format, tenant)
def _test_ssl_certificates(self, tenant=TENANT_1, format='json', status=200):
def _test_ssl_certificates(self, tenant=TENANT_1,
format='json', status=200):
LOG.debug("_test_ssl_certificates - tenant:%s "\
"- format:%s - START", format, tenant)
@ -326,7 +330,6 @@ class APITest(unittest.TestCase):
LOG.debug("_test_ssl_certificates - tenant:%s "\
"- format:%s - END", format, tenant)
def test_list_networks_json(self):
self._test_list_networks(format='json')
@ -342,8 +345,6 @@ class APITest(unittest.TestCase):
def test_list_networks_error_401(self):
self._test_list_networks(status=401)
def test_list_network_details_json(self):
self._test_list_network_details(format='json')
@ -362,8 +363,6 @@ class APITest(unittest.TestCase):
def test_list_network_details_error_420(self):
self._test_list_network_details(status=420)
def test_create_network_json(self):
self._test_create_network(format='json')
@ -385,9 +384,6 @@ class APITest(unittest.TestCase):
def test_create_network_error_422(self):
self._test_create_network(status=422)
def test_update_network_json(self):
self._test_update_network(format='json')
@ -412,8 +408,6 @@ class APITest(unittest.TestCase):
def test_update_network_error_422(self):
self._test_update_network(status=422)
def test_delete_network_json(self):
self._test_delete_network(format='json')
@ -435,8 +429,6 @@ class APITest(unittest.TestCase):
def test_delete_network_error_421(self):
self._test_delete_network(status=421)
def test_list_ports_json(self):
self._test_list_ports(format='json')
@ -455,8 +447,6 @@ class APITest(unittest.TestCase):
def test_list_ports_error_420(self):
self._test_list_ports(status=420)
def test_list_port_details_json(self):
self._test_list_ports(format='json')
@ -478,8 +468,6 @@ class APITest(unittest.TestCase):
def test_list_port_details_error_430(self):
self._test_list_ports(status=430)
def test_create_port_json(self):
self._test_create_port(format='json')
@ -507,8 +495,6 @@ class APITest(unittest.TestCase):
def test_create_port_error_431(self):
self._test_create_port(status=431)
def test_delete_port_json(self):
self._test_delete_port(format='json')
@ -533,8 +519,6 @@ class APITest(unittest.TestCase):
def test_delete_port_error_432(self):
self._test_delete_port(status=432)
def test_set_port_state_json(self):
self._test_set_port_state(format='json')
@ -562,8 +546,6 @@ class APITest(unittest.TestCase):
def test_set_port_state_error_431(self):
self._test_set_port_state(status=431)
def test_list_port_attachments_json(self):
self._test_list_port_attachments(format='json')
@ -588,8 +570,6 @@ class APITest(unittest.TestCase):
def test_list_port_attachments_error_430(self):
self._test_list_port_attachments(status=430)
def test_attach_resource_json(self):
self._test_attach_resource(format='json')
@ -620,8 +600,6 @@ class APITest(unittest.TestCase):
def test_attach_resource_error_440(self):
self._test_attach_resource(status=440)
def test_detach_resource_json(self):
self._test_detach_resource(format='json')
@ -643,7 +621,5 @@ class APITest(unittest.TestCase):
def test_detach_resource_error_430(self):
self._test_detach_resource(status=430)
def test_ssl_certificates(self):
self._test_ssl_certificates()