Clean up codebase in accordance with HACKING/PEP8.
* Adds HACKING.rst * Addresses 981208 Change-Id: I3d701ca9a748a0c4ceada7d76a31dc6bb2d5969b
This commit is contained in:
187
HACKING.rst
Normal file
187
HACKING.rst
Normal file
@@ -0,0 +1,187 @@
|
|||||||
|
QuantumClient Style Commandments
|
||||||
|
================================
|
||||||
|
|
||||||
|
- Step 1: Read http://www.python.org/dev/peps/pep-0008/
|
||||||
|
- Step 2: Read http://www.python.org/dev/peps/pep-0008/ again
|
||||||
|
- Step 3: Read on
|
||||||
|
|
||||||
|
|
||||||
|
General
|
||||||
|
-------
|
||||||
|
- Put two newlines between top-level code (funcs, classes, etc)
|
||||||
|
- Put one newline between methods in classes and anywhere else
|
||||||
|
- Do not write "except:", use "except Exception:" at the very least
|
||||||
|
- Include your name with TODOs as in "#TODO(termie)"
|
||||||
|
- Do not shadow a built-in or reserved word. Example::
|
||||||
|
|
||||||
|
def list():
|
||||||
|
return [1, 2, 3]
|
||||||
|
|
||||||
|
mylist = list() # BAD, shadows `list` built-in
|
||||||
|
|
||||||
|
class Foo(object):
|
||||||
|
def list(self):
|
||||||
|
return [1, 2, 3]
|
||||||
|
|
||||||
|
mylist = Foo().list() # OKAY, does not shadow built-in
|
||||||
|
|
||||||
|
|
||||||
|
Imports
|
||||||
|
-------
|
||||||
|
- Do not make relative imports
|
||||||
|
- Order your imports by the full module path
|
||||||
|
- Organize your imports according to the following template
|
||||||
|
|
||||||
|
Example::
|
||||||
|
|
||||||
|
# vim: tabstop=4 shiftwidth=4 softtabstop=4
|
||||||
|
{{stdlib imports in human alphabetical order}}
|
||||||
|
\n
|
||||||
|
{{third-party lib imports in human alphabetical order}}
|
||||||
|
\n
|
||||||
|
{{quantum imports in human alphabetical order}}
|
||||||
|
\n
|
||||||
|
\n
|
||||||
|
{{begin your code}}
|
||||||
|
|
||||||
|
|
||||||
|
Human Alphabetical Order Examples
|
||||||
|
---------------------------------
|
||||||
|
Example::
|
||||||
|
|
||||||
|
import httplib
|
||||||
|
import logging
|
||||||
|
import random
|
||||||
|
import StringIO
|
||||||
|
import time
|
||||||
|
import unittest
|
||||||
|
|
||||||
|
import eventlet
|
||||||
|
import webob.exc
|
||||||
|
|
||||||
|
import quantum.api.networks
|
||||||
|
from quantum.api import ports
|
||||||
|
from quantum.db import models
|
||||||
|
from quantum.extensions import multiport
|
||||||
|
import quantum.manager
|
||||||
|
from quantum import service
|
||||||
|
|
||||||
|
|
||||||
|
Docstrings
|
||||||
|
----------
|
||||||
|
Example::
|
||||||
|
|
||||||
|
"""A one line docstring looks like this and ends in a period."""
|
||||||
|
|
||||||
|
|
||||||
|
"""A multiline docstring has a one-line summary, less than 80 characters.
|
||||||
|
|
||||||
|
Then a new paragraph after a newline that explains in more detail any
|
||||||
|
general information about the function, class or method. Example usages
|
||||||
|
are also great to have here if it is a complex class for function.
|
||||||
|
|
||||||
|
When writing the docstring for a class, an extra line should be placed
|
||||||
|
after the closing quotations. For more in-depth explanations for these
|
||||||
|
decisions see http://www.python.org/dev/peps/pep-0257/
|
||||||
|
|
||||||
|
If you are going to describe parameters and return values, use Sphinx, the
|
||||||
|
appropriate syntax is as follows.
|
||||||
|
|
||||||
|
:param foo: the foo parameter
|
||||||
|
:param bar: the bar parameter
|
||||||
|
:returns: return_type -- description of the return value
|
||||||
|
:returns: description of the return value
|
||||||
|
:raises: AttributeError, KeyError
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
Dictionaries/Lists
|
||||||
|
------------------
|
||||||
|
If a dictionary (dict) or list object is longer than 80 characters, its items
|
||||||
|
should be split with newlines. Embedded iterables should have their items
|
||||||
|
indented. Additionally, the last item in the dictionary should have a trailing
|
||||||
|
comma. This increases readability and simplifies future diffs.
|
||||||
|
|
||||||
|
Example::
|
||||||
|
|
||||||
|
my_dictionary = {
|
||||||
|
"image": {
|
||||||
|
"name": "Just a Snapshot",
|
||||||
|
"size": 2749573,
|
||||||
|
"properties": {
|
||||||
|
"user_id": 12,
|
||||||
|
"arch": "x86_64",
|
||||||
|
},
|
||||||
|
"things": [
|
||||||
|
"thing_one",
|
||||||
|
"thing_two",
|
||||||
|
],
|
||||||
|
"status": "ACTIVE",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Calling Methods
|
||||||
|
---------------
|
||||||
|
Calls to methods 80 characters or longer should format each argument with
|
||||||
|
newlines. This is not a requirement, but a guideline::
|
||||||
|
|
||||||
|
unnecessarily_long_function_name('string one',
|
||||||
|
'string two',
|
||||||
|
kwarg1=constants.ACTIVE,
|
||||||
|
kwarg2=['a', 'b', 'c'])
|
||||||
|
|
||||||
|
|
||||||
|
Rather than constructing parameters inline, it is better to break things up::
|
||||||
|
|
||||||
|
list_of_strings = [
|
||||||
|
'what_a_long_string',
|
||||||
|
'not as long',
|
||||||
|
]
|
||||||
|
|
||||||
|
dict_of_numbers = {
|
||||||
|
'one': 1,
|
||||||
|
'two': 2,
|
||||||
|
'twenty four': 24,
|
||||||
|
}
|
||||||
|
|
||||||
|
object_one.call_a_method('string three',
|
||||||
|
'string four',
|
||||||
|
kwarg1=list_of_strings,
|
||||||
|
kwarg2=dict_of_numbers)
|
||||||
|
|
||||||
|
|
||||||
|
Internationalization (i18n) Strings
|
||||||
|
-----------------------------------
|
||||||
|
In order to support multiple languages, we have a mechanism to support
|
||||||
|
automatic translations of exception and log strings.
|
||||||
|
|
||||||
|
Example::
|
||||||
|
|
||||||
|
msg = _("An error occurred")
|
||||||
|
raise HTTPBadRequest(explanation=msg)
|
||||||
|
|
||||||
|
If you have a variable to place within the string, first internationalize the
|
||||||
|
template string then do the replacement.
|
||||||
|
|
||||||
|
Example::
|
||||||
|
|
||||||
|
msg = _("Missing parameter: %s") % ("flavor",)
|
||||||
|
LOG.error(msg)
|
||||||
|
|
||||||
|
If you have multiple variables to place in the string, use keyword parameters.
|
||||||
|
This helps our translators reorder parameters when needed.
|
||||||
|
|
||||||
|
Example::
|
||||||
|
|
||||||
|
msg = _("The server with id %(s_id)s has no key %(m_key)s")
|
||||||
|
LOG.error(msg % {"s_id": "1234", "m_key": "imageId"})
|
||||||
|
|
||||||
|
|
||||||
|
Creating Unit Tests
|
||||||
|
-------------------
|
||||||
|
For every new feature, unit tests should be created that both test and
|
||||||
|
(implicitly) document the usage of said feature. If submitting a patch for a
|
||||||
|
bug that had no unit test, a new passing unit test should be added. If a
|
||||||
|
submitted bug fix does have a unit test, be sure to add a new one that fails
|
||||||
|
without the patch and passes with the patch.
|
@@ -16,9 +16,9 @@
|
|||||||
# under the License.
|
# under the License.
|
||||||
# @author: Tyler Smith, Cisco Systems
|
# @author: Tyler Smith, Cisco Systems
|
||||||
|
|
||||||
import logging
|
|
||||||
import gettext
|
import gettext
|
||||||
import httplib
|
import httplib
|
||||||
|
import logging
|
||||||
import socket
|
import socket
|
||||||
import time
|
import time
|
||||||
import urllib
|
import urllib
|
||||||
@@ -33,6 +33,8 @@ from quantumclient.common.serializer import Serializer
|
|||||||
|
|
||||||
|
|
||||||
LOG = logging.getLogger('quantumclient')
|
LOG = logging.getLogger('quantumclient')
|
||||||
|
|
||||||
|
|
||||||
AUTH_TOKEN_HEADER = "X-Auth-Token"
|
AUTH_TOKEN_HEADER = "X-Auth-Token"
|
||||||
|
|
||||||
|
|
||||||
@@ -53,7 +55,7 @@ def exception_handler_v10(status_code, error_content):
|
|||||||
430: 'portNotFound',
|
430: 'portNotFound',
|
||||||
431: 'requestedStateInvalid',
|
431: 'requestedStateInvalid',
|
||||||
432: 'portInUse',
|
432: 'portInUse',
|
||||||
440: 'alreadyAttached'
|
440: 'alreadyAttached',
|
||||||
}
|
}
|
||||||
|
|
||||||
quantum_errors = {
|
quantum_errors = {
|
||||||
@@ -66,7 +68,7 @@ def exception_handler_v10(status_code, error_content):
|
|||||||
431: exceptions.StateInvalidClient,
|
431: exceptions.StateInvalidClient,
|
||||||
432: exceptions.PortInUseClient,
|
432: exceptions.PortInUseClient,
|
||||||
440: exceptions.AlreadyAttachedClient,
|
440: exceptions.AlreadyAttachedClient,
|
||||||
501: NotImplementedError
|
501: NotImplementedError,
|
||||||
}
|
}
|
||||||
|
|
||||||
# Find real error type
|
# Find real error type
|
||||||
@@ -75,8 +77,7 @@ def exception_handler_v10(status_code, error_content):
|
|||||||
error_type = quantum_error_types.get(status_code)
|
error_type = quantum_error_types.get(status_code)
|
||||||
if error_type:
|
if error_type:
|
||||||
error_dict = error_content[error_type]
|
error_dict = error_content[error_type]
|
||||||
error_message = error_dict['message'] + "\n" +\
|
error_message = error_dict['message'] + "\n" + error_dict['detail']
|
||||||
error_dict['detail']
|
|
||||||
else:
|
else:
|
||||||
error_message = error_content
|
error_message = error_content
|
||||||
# raise the appropriate error!
|
# raise the appropriate error!
|
||||||
@@ -128,7 +129,7 @@ def exception_handler_v11(status_code, error_content):
|
|||||||
|
|
||||||
EXCEPTION_HANDLERS = {
|
EXCEPTION_HANDLERS = {
|
||||||
'1.0': exception_handler_v10,
|
'1.0': exception_handler_v10,
|
||||||
'1.1': exception_handler_v11
|
'1.1': exception_handler_v11,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -166,9 +167,12 @@ class Client(object):
|
|||||||
"network": ["id", "name"],
|
"network": ["id", "name"],
|
||||||
"port": ["id", "state"],
|
"port": ["id", "state"],
|
||||||
"attachment": ["id"]},
|
"attachment": ["id"]},
|
||||||
"plurals": {"networks": "network",
|
"plurals": {
|
||||||
"ports": "port"}},
|
"networks": "network",
|
||||||
}
|
"ports": "port",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
# Action query strings
|
# Action query strings
|
||||||
networks_path = "/networks"
|
networks_path = "/networks"
|
||||||
@@ -249,8 +253,8 @@ class Client(object):
|
|||||||
# Salvatore: Isolating this piece of code in its own method to
|
# Salvatore: Isolating this piece of code in its own method to
|
||||||
# facilitate stubout for testing
|
# facilitate stubout for testing
|
||||||
if self.logger:
|
if self.logger:
|
||||||
self.logger.debug("Quantum Client Request:\n" \
|
self.logger.debug("Quantum Client Request:\n"
|
||||||
+ method + " " + action + "\n")
|
+ method + " " + action + "\n")
|
||||||
if body:
|
if body:
|
||||||
self.logger.debug(body)
|
self.logger.debug(body)
|
||||||
conn.request(method, action, body, headers)
|
conn.request(method, action, body, headers)
|
||||||
@@ -286,7 +290,7 @@ class Client(object):
|
|||||||
try:
|
try:
|
||||||
connection_type = self.get_connection_type()
|
connection_type = self.get_connection_type()
|
||||||
headers = headers or {"Content-Type":
|
headers = headers or {"Content-Type":
|
||||||
"application/%s" % self.format}
|
"application/%s" % self.format}
|
||||||
# if available, add authentication token
|
# if available, add authentication token
|
||||||
if self.auth_token:
|
if self.auth_token:
|
||||||
headers[AUTH_TOKEN_HEADER] = self.auth_token
|
headers[AUTH_TOKEN_HEADER] = self.auth_token
|
||||||
@@ -301,8 +305,8 @@ class Client(object):
|
|||||||
status_code = self.get_status_code(res)
|
status_code = self.get_status_code(res)
|
||||||
data = res.read()
|
data = res.read()
|
||||||
if self.logger:
|
if self.logger:
|
||||||
self.logger.debug("Quantum Client Reply (code = %s) :\n %s" \
|
self.logger.debug("Quantum Client Reply (code = %s) :\n %s" %
|
||||||
% (str(status_code), data))
|
(str(status_code), data))
|
||||||
if status_code in (httplib.OK,
|
if status_code in (httplib.OK,
|
||||||
httplib.CREATED,
|
httplib.CREATED,
|
||||||
httplib.ACCEPTED,
|
httplib.ACCEPTED,
|
||||||
@@ -335,8 +339,8 @@ class Client(object):
|
|||||||
elif type(data) is dict:
|
elif type(data) is dict:
|
||||||
return Serializer().serialize(data, self.content_type())
|
return Serializer().serialize(data, self.content_type())
|
||||||
else:
|
else:
|
||||||
raise Exception("unable to serialize object of type = '%s'" \
|
raise Exception("unable to serialize object of type = '%s'" %
|
||||||
% type(data))
|
type(data))
|
||||||
|
|
||||||
def deserialize(self, data, status_code):
|
def deserialize(self, data, status_code):
|
||||||
"""
|
"""
|
||||||
@@ -344,8 +348,8 @@ class Client(object):
|
|||||||
"""
|
"""
|
||||||
if status_code == 204:
|
if status_code == 204:
|
||||||
return data
|
return data
|
||||||
return Serializer(self._serialization_metadata).\
|
return Serializer(self._serialization_metadata).deserialize(
|
||||||
deserialize(data, self.content_type())
|
data, self.content_type())
|
||||||
|
|
||||||
def content_type(self, format=None):
|
def content_type(self, format=None):
|
||||||
"""
|
"""
|
||||||
|
@@ -34,90 +34,114 @@ from quantumclient.common import utils
|
|||||||
#Configure logger for client - cli logger is a child of it
|
#Configure logger for client - cli logger is a child of it
|
||||||
#NOTE(salvatore-orlando): logger name does not map to package
|
#NOTE(salvatore-orlando): logger name does not map to package
|
||||||
#this is deliberate. Simplifies logger configuration
|
#this is deliberate. Simplifies logger configuration
|
||||||
LOG = logging.getLogger('quantum')
|
LOG = logging.getLogger('quantumclient')
|
||||||
|
|
||||||
|
|
||||||
DEFAULT_QUANTUM_VERSION = '1.1'
|
DEFAULT_QUANTUM_VERSION = '1.1'
|
||||||
FORMAT = 'json'
|
FORMAT = 'json'
|
||||||
commands_v10 = {
|
commands_v10 = {
|
||||||
"list_nets": {
|
"list_nets": {
|
||||||
"func": cli_lib.list_nets,
|
"func": cli_lib.list_nets,
|
||||||
"args": ["tenant-id"]},
|
"args": ["tenant-id"],
|
||||||
"list_nets_detail": {
|
},
|
||||||
"func": cli_lib.list_nets_detail,
|
"list_nets_detail": {
|
||||||
"args": ["tenant-id"]},
|
"func": cli_lib.list_nets_detail,
|
||||||
"create_net": {
|
"args": ["tenant-id"],
|
||||||
"func": cli_lib.create_net,
|
},
|
||||||
"args": ["tenant-id", "net-name"]},
|
"create_net": {
|
||||||
"delete_net": {
|
"func": cli_lib.create_net,
|
||||||
"func": cli_lib.delete_net,
|
"args": ["tenant-id", "net-name"],
|
||||||
"args": ["tenant-id", "net-id"]},
|
},
|
||||||
"show_net": {
|
"delete_net": {
|
||||||
"func": cli_lib.show_net,
|
"func": cli_lib.delete_net,
|
||||||
"args": ["tenant-id", "net-id"]},
|
"args": ["tenant-id", "net-id"],
|
||||||
"show_net_detail": {
|
},
|
||||||
"func": cli_lib.show_net_detail,
|
"show_net": {
|
||||||
"args": ["tenant-id", "net-id"]},
|
"func": cli_lib.show_net,
|
||||||
"update_net": {
|
"args": ["tenant-id", "net-id"],
|
||||||
"func": cli_lib.update_net,
|
},
|
||||||
"args": ["tenant-id", "net-id", "new-name"]},
|
"show_net_detail": {
|
||||||
"list_ports": {
|
"func": cli_lib.show_net_detail,
|
||||||
"func": cli_lib.list_ports,
|
"args": ["tenant-id", "net-id"],
|
||||||
"args": ["tenant-id", "net-id"]},
|
},
|
||||||
"list_ports_detail": {
|
"update_net": {
|
||||||
"func": cli_lib.list_ports_detail,
|
"func": cli_lib.update_net,
|
||||||
"args": ["tenant-id", "net-id"]},
|
"args": ["tenant-id", "net-id", "new-name"],
|
||||||
"create_port": {
|
},
|
||||||
"func": cli_lib.create_port,
|
"list_ports": {
|
||||||
"args": ["tenant-id", "net-id"]},
|
"func": cli_lib.list_ports,
|
||||||
"delete_port": {
|
"args": ["tenant-id", "net-id"],
|
||||||
"func": cli_lib.delete_port,
|
},
|
||||||
"args": ["tenant-id", "net-id", "port-id"]},
|
"list_ports_detail": {
|
||||||
"update_port": {
|
"func": cli_lib.list_ports_detail,
|
||||||
"func": cli_lib.update_port,
|
"args": ["tenant-id", "net-id"],
|
||||||
"args": ["tenant-id", "net-id", "port-id", "params"]},
|
},
|
||||||
"show_port": {
|
"create_port": {
|
||||||
"func": cli_lib.show_port,
|
"func": cli_lib.create_port,
|
||||||
"args": ["tenant-id", "net-id", "port-id"]},
|
"args": ["tenant-id", "net-id"],
|
||||||
"show_port_detail": {
|
},
|
||||||
"func": cli_lib.show_port_detail,
|
"delete_port": {
|
||||||
"args": ["tenant-id", "net-id", "port-id"]},
|
"func": cli_lib.delete_port,
|
||||||
"plug_iface": {
|
"args": ["tenant-id", "net-id", "port-id"],
|
||||||
"func": cli_lib.plug_iface,
|
},
|
||||||
"args": ["tenant-id", "net-id", "port-id", "iface-id"]},
|
"update_port": {
|
||||||
"unplug_iface": {
|
"func": cli_lib.update_port,
|
||||||
"func": cli_lib.unplug_iface,
|
"args": ["tenant-id", "net-id", "port-id", "params"],
|
||||||
"args": ["tenant-id", "net-id", "port-id"]},
|
},
|
||||||
"show_iface": {
|
"show_port": {
|
||||||
"func": cli_lib.show_iface,
|
"func": cli_lib.show_port,
|
||||||
"args": ["tenant-id", "net-id", "port-id"]}, }
|
"args": ["tenant-id", "net-id", "port-id"],
|
||||||
|
},
|
||||||
|
"show_port_detail": {
|
||||||
|
"func": cli_lib.show_port_detail,
|
||||||
|
"args": ["tenant-id", "net-id", "port-id"],
|
||||||
|
},
|
||||||
|
"plug_iface": {
|
||||||
|
"func": cli_lib.plug_iface,
|
||||||
|
"args": ["tenant-id", "net-id", "port-id", "iface-id"],
|
||||||
|
},
|
||||||
|
"unplug_iface": {
|
||||||
|
"func": cli_lib.unplug_iface,
|
||||||
|
"args": ["tenant-id", "net-id", "port-id"],
|
||||||
|
},
|
||||||
|
"show_iface": {
|
||||||
|
"func": cli_lib.show_iface,
|
||||||
|
"args": ["tenant-id", "net-id", "port-id"],
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
commands_v11 = commands_v10.copy()
|
commands_v11 = commands_v10.copy()
|
||||||
commands_v11.update({
|
commands_v11.update({
|
||||||
"list_nets": {
|
"list_nets": {
|
||||||
"func": cli_lib.list_nets_v11,
|
"func": cli_lib.list_nets_v11,
|
||||||
"args": ["tenant-id"],
|
"args": ["tenant-id"],
|
||||||
"filters": ["name", "op-status", "port-op-status", "port-state",
|
"filters": ["name", "op-status", "port-op-status", "port-state",
|
||||||
"has-attachment", "attachment", "port"]},
|
"has-attachment", "attachment", "port"],
|
||||||
"list_nets_detail": {
|
},
|
||||||
"func": cli_lib.list_nets_detail_v11,
|
"list_nets_detail": {
|
||||||
"args": ["tenant-id"],
|
"func": cli_lib.list_nets_detail_v11,
|
||||||
"filters": ["name", "op-status", "port-op-status", "port-state",
|
"args": ["tenant-id"],
|
||||||
"has-attachment", "attachment", "port"]},
|
"filters": ["name", "op-status", "port-op-status", "port-state",
|
||||||
"list_ports": {
|
"has-attachment", "attachment", "port"],
|
||||||
"func": cli_lib.list_ports_v11,
|
},
|
||||||
"args": ["tenant-id", "net-id"],
|
"list_ports": {
|
||||||
"filters": ["name", "op-status", "has-attachment", "attachment"]},
|
"func": cli_lib.list_ports_v11,
|
||||||
"list_ports_detail": {
|
"args": ["tenant-id", "net-id"],
|
||||||
"func": cli_lib.list_ports_detail_v11,
|
"filters": ["name", "op-status", "has-attachment", "attachment"],
|
||||||
"args": ["tenant-id", "net-id"],
|
},
|
||||||
"filters": ["name", "op-status", "has-attachment", "attachment"]},
|
"list_ports_detail": {
|
||||||
})
|
"func": cli_lib.list_ports_detail_v11,
|
||||||
|
"args": ["tenant-id", "net-id"],
|
||||||
|
"filters": ["name", "op-status", "has-attachment", "attachment"],
|
||||||
|
},
|
||||||
|
})
|
||||||
commands = {
|
commands = {
|
||||||
'1.0': commands_v10,
|
'1.0': commands_v10,
|
||||||
'1.1': commands_v11
|
'1.1': commands_v11,
|
||||||
}
|
}
|
||||||
clients = {
|
clients = {
|
||||||
'1.0': Client,
|
'1.0': Client,
|
||||||
'1.1': ClientV11
|
'1.1': ClientV11,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -125,23 +149,24 @@ def help(version):
|
|||||||
print "\nCommands:"
|
print "\nCommands:"
|
||||||
cmds = commands[version]
|
cmds = commands[version]
|
||||||
for k in cmds.keys():
|
for k in cmds.keys():
|
||||||
print " %s %s %s" % (k,
|
print " %s %s %s" % (
|
||||||
" ".join(["<%s>" % y for y in cmds[k]["args"]]),
|
k,
|
||||||
'filters' in cmds[k] and "[filterspec ...]" or "")
|
" ".join(["<%s>" % y for y in cmds[k]["args"]]),
|
||||||
|
'filters' in cmds[k] and "[filterspec ...]" or "")
|
||||||
|
|
||||||
|
|
||||||
def print_usage(cmd, version):
|
def print_usage(cmd, version):
|
||||||
cmds = commands[version]
|
cmds = commands[version]
|
||||||
print "Usage:\n %s %s" % (cmd,
|
print "Usage:\n %s %s" % (
|
||||||
" ".join(["<%s>" % y for y in cmds[cmd]["args"]]))
|
cmd, " ".join(["<%s>" % y for y in cmds[cmd]["args"]]))
|
||||||
|
|
||||||
|
|
||||||
def build_args(cmd, cmdargs, arglist):
|
def build_args(cmd, cmdargs, arglist):
|
||||||
arglist_len = len(arglist)
|
arglist_len = len(arglist)
|
||||||
cmdargs_len = len(cmdargs)
|
cmdargs_len = len(cmdargs)
|
||||||
if arglist_len < cmdargs_len:
|
if arglist_len < cmdargs_len:
|
||||||
message = "Not enough arguments for \"%s\" (expected: %d, got: %d)"\
|
message = ("Not enough arguments for \"%s\" (expected: %d, got: %d)" %
|
||||||
% (cmd, len(cmdargs), arglist_len)
|
(cmd, len(cmdargs), arglist_len))
|
||||||
raise exceptions.QuantumCLIError(message=message)
|
raise exceptions.QuantumCLIError(message=message)
|
||||||
args = arglist[:cmdargs_len]
|
args = arglist[:cmdargs_len]
|
||||||
return args
|
return args
|
||||||
@@ -192,12 +217,13 @@ def build_cmd(cmd, cmd_args, cmd_filters, arglist, version):
|
|||||||
return None, None
|
return None, None
|
||||||
filter_len = (filters is not None) and len(filters) or 0
|
filter_len = (filters is not None) and len(filters) or 0
|
||||||
if len(arglist) - len(args) - filter_len > 0:
|
if len(arglist) - len(args) - filter_len > 0:
|
||||||
message = "Too many arguments for \"%s\" (expected: %d, got: %d)"\
|
message = ("Too many arguments for \"%s\" (expected: %d, got: %d)" %
|
||||||
% (cmd, len(cmd_args), arglist_len)
|
(cmd, len(cmd_args), arglist_len))
|
||||||
LOG.error(message)
|
LOG.error(message)
|
||||||
print "Error in command line: %s " % message
|
print "Error in command line: %s " % message
|
||||||
print "Usage:\n %s %s" % (cmd,
|
print "Usage:\n %s %s" % (
|
||||||
" ".join(["<%s>" % y for y in commands[version][cmd]["args"]]))
|
cmd,
|
||||||
|
" ".join(["<%s>" % y for y in commands[version][cmd]["args"]]))
|
||||||
return None, None
|
return None, None
|
||||||
# Append version to arguments for cli functions
|
# Append version to arguments for cli functions
|
||||||
args.append(version)
|
args.append(version)
|
||||||
@@ -219,18 +245,21 @@ def main():
|
|||||||
usagestr = "Usage: %prog [OPTIONS] <command> [args]"
|
usagestr = "Usage: %prog [OPTIONS] <command> [args]"
|
||||||
parser = OptionParser(usage=usagestr)
|
parser = OptionParser(usage=usagestr)
|
||||||
parser.add_option("-H", "--host", dest="host",
|
parser.add_option("-H", "--host", dest="host",
|
||||||
type="string", default="127.0.0.1", help="ip address of api host")
|
type="string", default="127.0.0.1",
|
||||||
|
help="ip address of api host")
|
||||||
parser.add_option("-p", "--port", dest="port",
|
parser.add_option("-p", "--port", dest="port",
|
||||||
type="int", default=9696, help="api poort")
|
type="int", default=9696, help="api poort")
|
||||||
parser.add_option("-s", "--ssl", dest="ssl",
|
parser.add_option("-s", "--ssl", dest="ssl",
|
||||||
action="store_true", default=False, help="use ssl")
|
action="store_true", default=False, help="use ssl")
|
||||||
parser.add_option("-v", "--verbose", dest="verbose",
|
parser.add_option("-v", "--verbose", dest="verbose",
|
||||||
action="store_true", default=False, help="turn on verbose logging")
|
action="store_true", default=False,
|
||||||
|
help="turn on verbose logging")
|
||||||
parser.add_option("-f", "--logfile", dest="logfile",
|
parser.add_option("-f", "--logfile", dest="logfile",
|
||||||
type="string", default="syslog", help="log file path")
|
type="string", default="syslog", help="log file path")
|
||||||
parser.add_option("-t", "--token", dest="token",
|
parser.add_option("-t", "--token", dest="token",
|
||||||
type="string", default=None, help="authentication token")
|
type="string", default=None, help="authentication token")
|
||||||
parser.add_option('--version',
|
parser.add_option(
|
||||||
|
'--version',
|
||||||
default=utils.env('QUANTUM_VERSION', default=DEFAULT_QUANTUM_VERSION),
|
default=utils.env('QUANTUM_VERSION', default=DEFAULT_QUANTUM_VERSION),
|
||||||
help='Accepts 1.1 and 1.0, defaults to env[QUANTUM_VERSION].')
|
help='Accepts 1.1 and 1.0, defaults to env[QUANTUM_VERSION].')
|
||||||
options, args = parser.parse_args()
|
options, args = parser.parse_args()
|
||||||
|
@@ -23,10 +23,13 @@
|
|||||||
import logging
|
import logging
|
||||||
import traceback
|
import traceback
|
||||||
|
|
||||||
FORMAT = "json"
|
|
||||||
LOG = logging.getLogger('quantumclient.cli_lib')
|
LOG = logging.getLogger('quantumclient.cli_lib')
|
||||||
|
|
||||||
|
|
||||||
|
FORMAT = "json"
|
||||||
|
|
||||||
|
|
||||||
class OutputTemplate(object):
|
class OutputTemplate(object):
|
||||||
""" A class for generating simple templated output.
|
""" A class for generating simple templated output.
|
||||||
Based on Python templating mechanism.
|
Based on Python templating mechanism.
|
||||||
@@ -95,90 +98,146 @@ class CmdOutputTemplate(OutputTemplate):
|
|||||||
Extends OutputTemplate loading a different template for each command.
|
Extends OutputTemplate loading a different template for each command.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
_templates_v10 = {
|
_templates_v10 = dict(
|
||||||
"list_nets": "Virtual Networks for Tenant %(tenant_id)s\n" +
|
list_nets="""
|
||||||
"%(networks|\tNetwork ID: %(id)s)s",
|
Virtual Networks for Tenant %(tenant_id)s
|
||||||
"list_nets_detail": "Virtual Networks for Tenant %(tenant_id)s\n" +
|
%(networks|\tNetwork ID: %(id)s)s
|
||||||
"%(networks|\tNetwork %(name)s with ID: %(id)s)s",
|
""".strip(),
|
||||||
"show_net": "Network ID: %(network.id)s\n" +
|
|
||||||
"Network Name: %(network.name)s",
|
list_nets_detail="""
|
||||||
"show_net_detail": "Network ID: %(network.id)s\n" +
|
Virtual Networks for Tenant %(tenant_id)s
|
||||||
"Network Name: %(network.name)s\n" +
|
%(networks|\tNetwork %(name)s with ID: %(id)s)s
|
||||||
"Ports: %(network.ports|\tID: %(id)s\n" +
|
""".strip(),
|
||||||
"\t\tadministrative state: %(state)s\n" +
|
|
||||||
"\t\tinterface: %(attachment.id)s)s",
|
show_net="""
|
||||||
"create_net": "Created a new Virtual Network with ID: " +
|
Network ID: %(network.id)s
|
||||||
"%(network_id)s\n" +
|
Network Name: %(network.name)s
|
||||||
"for Tenant: %(tenant_id)s",
|
""".strip(),
|
||||||
"update_net": "Updated Virtual Network with ID: " +
|
|
||||||
"%(network.id)s\n" +
|
show_net_detail="""
|
||||||
"for Tenant: %(tenant_id)s\n",
|
Network ID: %(network.id)s
|
||||||
"delete_net": "Deleted Virtual Network with ID: " +
|
Network Name: %(network.name)s
|
||||||
"%(network_id)s\n" +
|
Ports: %(network.ports|\tID: %(id)s
|
||||||
"for Tenant %(tenant_id)s",
|
\t\tadministrative state: %(state)s
|
||||||
"list_ports": "Ports on Virtual Network: %(network_id)s\n" +
|
\t\tinterface: %(attachment.id)s)s
|
||||||
"for Tenant: %(tenant_id)s\n" +
|
""".strip(),
|
||||||
"%(ports|\tLogical Port: %(id)s)s",
|
|
||||||
"list_ports_detail": "Ports on Virtual Network: %(network_id)s\n" +
|
create_net="""
|
||||||
"for Tenant: %(tenant_id)s\n" +
|
Created a new Virtual Network with ID: %(network_id)s
|
||||||
"%(ports|\tLogical Port: %(id)s\n" +
|
for Tenant: %(tenant_id)s
|
||||||
"\t\tadministrative State: %(state)s)s",
|
""".strip(),
|
||||||
"create_port": "Created new Logical Port with ID: " +
|
|
||||||
"%(port_id)s\n" +
|
update_net="""
|
||||||
"on Virtual Network: %(network_id)s\n" +
|
Updated Virtual Network with ID: %(network.id)s
|
||||||
"for Tenant: %(tenant_id)s",
|
for Tenant: %(tenant_id)s
|
||||||
"show_port": "Logical Port ID: %(port.id)s\n" +
|
""".strip(),
|
||||||
"administrative State: %(port.state)s\n" +
|
|
||||||
"on Virtual Network: %(network_id)s\n" +
|
delete_net="""
|
||||||
"for Tenant: %(tenant_id)s",
|
Deleted Virtual Network with ID: %(network_id)s
|
||||||
"show_port_detail": "Logical Port ID: %(port.id)s\n" +
|
for Tenant %(tenant_id)s
|
||||||
"administrative State: %(port.state)s\n" +
|
""".strip(),
|
||||||
"interface: %(port.attachment.id)s\n" +
|
|
||||||
"on Virtual Network: %(network_id)s\n" +
|
list_ports="""
|
||||||
"for Tenant: %(tenant_id)s",
|
Ports on Virtual Network: %(network_id)s
|
||||||
"update_port": "Updated Logical Port " +
|
for Tenant: %(tenant_id)s
|
||||||
"with ID: %(port.id)s\n" +
|
%(ports|\tLogical Port: %(id)s)s
|
||||||
"on Virtual Network: %(network_id)s\n" +
|
""".strip(),
|
||||||
"for tenant: %(tenant_id)s",
|
|
||||||
"delete_port": "Deleted Logical Port with ID: %(port_id)s\n" +
|
list_ports_detail="""
|
||||||
"on Virtual Network: %(network_id)s\n" +
|
Ports on Virtual Network: %(network_id)s
|
||||||
"for Tenant: %(tenant_id)s",
|
for Tenant: %(tenant_id)s
|
||||||
"plug_iface": "Plugged interface %(attachment)s\n" +
|
%(ports|\tLogical Port: %(id)s
|
||||||
"into Logical Port: %(port_id)s\n" +
|
\t\tadministrative State: %(state)s)s
|
||||||
"on Virtual Network: %(network_id)s\n" +
|
""".strip(),
|
||||||
"for Tenant: %(tenant_id)s",
|
|
||||||
"unplug_iface": "Unplugged interface from Logical Port:" +
|
create_port="""
|
||||||
"%(port_id)s\n" +
|
Created new Logical Port with ID: %(port_id)s
|
||||||
"on Virtual Network: %(network_id)s\n" +
|
on Virtual Network: %(network_id)s
|
||||||
"for Tenant: %(tenant_id)s",
|
for Tenant: %(tenant_id)s
|
||||||
"show_iface": "interface: %(iface.id)s\n" +
|
""".strip(),
|
||||||
"plugged in Logical Port ID: %(port_id)s\n" +
|
|
||||||
"on Virtual Network: %(network_id)s\n" +
|
show_port="""
|
||||||
"for Tenant: %(tenant_id)s"}
|
Logical Port ID: %(port.id)s
|
||||||
|
administrative State: %(port.state)s
|
||||||
|
on Virtual Network: %(network_id)s
|
||||||
|
for Tenant: %(tenant_id)s
|
||||||
|
""".strip(),
|
||||||
|
|
||||||
|
show_port_detail="""
|
||||||
|
Logical Port ID: %(port.id)s
|
||||||
|
administrative State: %(port.state)s
|
||||||
|
interface: %(port.attachment.id)s
|
||||||
|
on Virtual Network: %(network_id)s
|
||||||
|
for Tenant: %(tenant_id)s
|
||||||
|
""".strip(),
|
||||||
|
|
||||||
|
update_port="""
|
||||||
|
Updated Logical Port with ID: %(port.id)s
|
||||||
|
on Virtual Network: %(network_id)s
|
||||||
|
for tenant: %(tenant_id)s
|
||||||
|
""".strip(),
|
||||||
|
|
||||||
|
delete_port="""
|
||||||
|
Deleted Logical Port with ID: %(port_id)s
|
||||||
|
on Virtual Network: %(network_id)s
|
||||||
|
for Tenant: %(tenant_id)s
|
||||||
|
""".strip(),
|
||||||
|
|
||||||
|
plug_iface="""
|
||||||
|
Plugged interface %(attachment)s
|
||||||
|
into Logical Port: %(port_id)s
|
||||||
|
on Virtual Network: %(network_id)s
|
||||||
|
for Tenant: %(tenant_id)s
|
||||||
|
""".strip(),
|
||||||
|
|
||||||
|
unplug_iface="""
|
||||||
|
Unplugged interface from Logical Port: %(port_id)s
|
||||||
|
on Virtual Network: %(network_id)s
|
||||||
|
for Tenant: %(tenant_id)s
|
||||||
|
""".strip(),
|
||||||
|
|
||||||
|
show_iface="""
|
||||||
|
interface: %(iface.id)s
|
||||||
|
plugged in Logical Port ID: %(port_id)s
|
||||||
|
on Virtual Network: %(network_id)s
|
||||||
|
for Tenant: %(tenant_id)s
|
||||||
|
""".strip(),
|
||||||
|
)
|
||||||
|
|
||||||
_templates_v11 = _templates_v10.copy()
|
_templates_v11 = _templates_v10.copy()
|
||||||
_templates_v11.update({
|
_templates_v11.update(dict(
|
||||||
"show_net": "Network ID: %(network.id)s\n" +
|
show_net="""
|
||||||
"network Name: %(network.name)s\n" +
|
Network ID: %(network.id)s
|
||||||
"operational Status: %(network.op-status)s",
|
network Name: %(network.name)s
|
||||||
"show_net_detail": "Network ID: %(network.id)s\n" +
|
operational Status: %(network.op-status)s
|
||||||
"Network Name: %(network.name)s\n" +
|
""".strip(),
|
||||||
"operational Status: %(network.op-status)s\n" +
|
|
||||||
"Ports: %(network.ports|\tID: %(id)s\n" +
|
show_net_detail="""
|
||||||
"\t\tadministrative state: %(state)s\n" +
|
Network ID: %(network.id)s
|
||||||
"\t\tinterface: %(attachment.id)s)s",
|
Network Name: %(network.name)s
|
||||||
"show_port": "Logical Port ID: %(port.id)s\n" +
|
operational Status: %(network.op-status)s
|
||||||
"administrative state: %(port.state)s\n" +
|
Ports: %(network.ports|\tID: %(id)s
|
||||||
"operational status: %(port.op-status)s\n" +
|
\t\tadministrative state: %(state)s
|
||||||
"on Virtual Network: %(network_id)s\n" +
|
\t\tinterface: %(attachment.id)s)s
|
||||||
"for Tenant: %(tenant_id)s",
|
""".strip(),
|
||||||
"show_port_detail": "Logical Port ID: %(port.id)s\n" +
|
|
||||||
"administrative State: %(port.state)s\n" +
|
show_port="""
|
||||||
"operational status: %(port.op-status)s\n" +
|
Logical Port ID: %(port.id)s
|
||||||
"interface: %(port.attachment.id)s\n" +
|
administrative state: %(port.state)s
|
||||||
"on Virtual Network: %(network_id)s\n" +
|
operational status: %(port.op-status)s
|
||||||
"for Tenant: %(tenant_id)s",
|
on Virtual Network: %(network_id)s
|
||||||
})
|
for Tenant: %(tenant_id)s
|
||||||
|
""".strip(),
|
||||||
|
|
||||||
|
show_port_detail="""
|
||||||
|
Logical Port ID: %(port.id)s
|
||||||
|
administrative State: %(port.state)s
|
||||||
|
operational status: %(port.op-status)s
|
||||||
|
interface: %(port.attachment.id)s
|
||||||
|
on Virtual Network: %(network_id)s
|
||||||
|
for Tenant: %(tenant_id)s
|
||||||
|
""".strip(),
|
||||||
|
))
|
||||||
|
|
||||||
_templates = {
|
_templates = {
|
||||||
'1.0': _templates_v10,
|
'1.0': _templates_v10,
|
||||||
@@ -197,8 +256,8 @@ def _handle_exception(ex):
|
|||||||
if ex.args and isinstance(ex.args[-1][0], dict):
|
if ex.args and isinstance(ex.args[-1][0], dict):
|
||||||
status_code = ex.args[-1][0].get('status_code', None)
|
status_code = ex.args[-1][0].get('status_code', None)
|
||||||
message = ex.args[-1][0].get('message', None)
|
message = ex.args[-1][0].get('message', None)
|
||||||
msg_1 = "Command failed with error code: %s" \
|
msg_1 = ("Command failed with error code: %s" %
|
||||||
% (status_code or '<missing>')
|
(status_code or '<missing>'))
|
||||||
msg_2 = "Error message:%s" % (message or '<missing>')
|
msg_2 = "Error message:%s" % (message or '<missing>')
|
||||||
print msg_1
|
print msg_1
|
||||||
print msg_2
|
print msg_2
|
||||||
@@ -207,8 +266,8 @@ def _handle_exception(ex):
|
|||||||
|
|
||||||
|
|
||||||
def prepare_output(cmd, tenant_id, response, version):
|
def prepare_output(cmd, tenant_id, response, version):
|
||||||
LOG.debug("Preparing output for response:%s, version:%s"
|
LOG.debug("Preparing output for response:%s, version:%s" %
|
||||||
% (response, version))
|
(response, version))
|
||||||
response['tenant_id'] = tenant_id
|
response['tenant_id'] = tenant_id
|
||||||
output = str(CmdOutputTemplate(cmd, response, version))
|
output = str(CmdOutputTemplate(cmd, response, version))
|
||||||
LOG.debug("Finished preparing output for command:%s", cmd)
|
LOG.debug("Finished preparing output for command:%s", cmd)
|
||||||
|
@@ -43,7 +43,7 @@ class Serializer(object):
|
|||||||
return self.get_deserialize_handler(content_type)(datastring)
|
return self.get_deserialize_handler(content_type)(datastring)
|
||||||
except Exception:
|
except Exception:
|
||||||
raise exception.MalformedResponseBody(
|
raise exception.MalformedResponseBody(
|
||||||
reason="Unable to deserialize response body")
|
reason="Unable to deserialize response body")
|
||||||
|
|
||||||
def get_deserialize_handler(self, content_type):
|
def get_deserialize_handler(self, content_type):
|
||||||
handlers = {
|
handlers = {
|
||||||
|
@@ -21,7 +21,6 @@
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
import sys
|
import sys
|
||||||
import unittest
|
import unittest
|
||||||
@@ -43,8 +42,8 @@ class CLITest(unittest.TestCase):
|
|||||||
def setUp(self):
|
def setUp(self):
|
||||||
"""Prepare the test environment"""
|
"""Prepare the test environment"""
|
||||||
options = {}
|
options = {}
|
||||||
options['plugin_provider'] = \
|
options['plugin_provider'] = (
|
||||||
'quantum.plugins.sample.SamplePlugin.FakePlugin'
|
'quantum.plugins.sample.SamplePlugin.FakePlugin')
|
||||||
#TODO: make the version of the API router configurable
|
#TODO: make the version of the API router configurable
|
||||||
self.api = server.APIRouterV11(options)
|
self.api = server.APIRouterV11(options)
|
||||||
|
|
||||||
@@ -160,17 +159,25 @@ class CLITest(unittest.TestCase):
|
|||||||
'op-status': nw.op_status}
|
'op-status': nw.op_status}
|
||||||
port_list = db.port_list(nw.uuid)
|
port_list = db.port_list(nw.uuid)
|
||||||
if not port_list:
|
if not port_list:
|
||||||
network['ports'] = [{'id': '<none>',
|
network['ports'] = [
|
||||||
'state': '<none>',
|
{
|
||||||
'attachment': {'id': '<none>'}}]
|
'id': '<none>',
|
||||||
|
'state': '<none>',
|
||||||
|
'attachment': {
|
||||||
|
'id': '<none>',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
]
|
||||||
else:
|
else:
|
||||||
network['ports'] = []
|
network['ports'] = []
|
||||||
for port in port_list:
|
for port in port_list:
|
||||||
network['ports'].append({'id': port.uuid,
|
network['ports'].append({
|
||||||
'state': port.state,
|
'id': port.uuid,
|
||||||
'attachment': {'id':
|
'state': port.state,
|
||||||
port.interface_id
|
'attachment': {
|
||||||
or '<none>'}})
|
'id': port.interface_id or '<none>',
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
# Fill CLI template
|
# Fill CLI template
|
||||||
output = cli.prepare_output('show_net_detail',
|
output = cli.prepare_output('show_net_detail',
|
||||||
|
@@ -17,15 +17,17 @@
|
|||||||
# @author: Tyler Smith, Cisco Systems
|
# @author: Tyler Smith, Cisco Systems
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
import unittest
|
|
||||||
import re
|
import re
|
||||||
|
import unittest
|
||||||
|
|
||||||
from quantumclient.common import exceptions
|
from quantumclient.common import exceptions
|
||||||
from quantumclient.common.serializer import Serializer
|
from quantumclient.common.serializer import Serializer
|
||||||
from quantumclient import Client
|
from quantumclient import Client
|
||||||
|
|
||||||
|
|
||||||
LOG = logging.getLogger('quantumclient.tests.test_api')
|
LOG = logging.getLogger('quantumclient.tests.test_api')
|
||||||
|
|
||||||
|
|
||||||
# Set a couple tenants to use for testing
|
# Set a couple tenants to use for testing
|
||||||
TENANT_1 = 'totore'
|
TENANT_1 = 'totore'
|
||||||
TENANT_2 = 'totore2'
|
TENANT_2 = 'totore2'
|
||||||
@@ -119,7 +121,7 @@ class APITest(unittest.TestCase):
|
|||||||
return data
|
return data
|
||||||
|
|
||||||
def _test_list_networks(self, tenant=TENANT_1, format='json', status=200):
|
def _test_list_networks(self, tenant=TENANT_1, format='json', status=200):
|
||||||
LOG.debug("_test_list_networks - tenant:%s "\
|
LOG.debug("_test_list_networks - tenant:%s "
|
||||||
"- format:%s - START", format, tenant)
|
"- format:%s - START", format, tenant)
|
||||||
|
|
||||||
self._assert_sanity(self.client.list_networks,
|
self._assert_sanity(self.client.list_networks,
|
||||||
@@ -129,13 +131,13 @@ class APITest(unittest.TestCase):
|
|||||||
data=[],
|
data=[],
|
||||||
params={'tenant': tenant, 'format': format})
|
params={'tenant': tenant, 'format': format})
|
||||||
|
|
||||||
LOG.debug("_test_list_networks - tenant:%s "\
|
LOG.debug("_test_list_networks - tenant:%s - format:%s - END",
|
||||||
"- format:%s - END", format, tenant)
|
format, tenant)
|
||||||
|
|
||||||
def _test_list_networks_details(self,
|
def _test_list_networks_details(self,
|
||||||
tenant=TENANT_1, format='json',
|
tenant=TENANT_1, format='json',
|
||||||
status=200):
|
status=200):
|
||||||
LOG.debug("_test_list_networks_details - tenant:%s "\
|
LOG.debug("_test_list_networks_details - tenant:%s "
|
||||||
"- format:%s - START", format, tenant)
|
"- format:%s - START", format, tenant)
|
||||||
|
|
||||||
self._assert_sanity(self.client.list_networks_details,
|
self._assert_sanity(self.client.list_networks_details,
|
||||||
@@ -145,12 +147,12 @@ class APITest(unittest.TestCase):
|
|||||||
data=[],
|
data=[],
|
||||||
params={'tenant': tenant, 'format': format})
|
params={'tenant': tenant, 'format': format})
|
||||||
|
|
||||||
LOG.debug("_test_list_networks_details - tenant:%s "\
|
LOG.debug("_test_list_networks_details - tenant:%s "
|
||||||
"- format:%s - END", format, tenant)
|
"- format:%s - END", format, tenant)
|
||||||
|
|
||||||
def _test_show_network(self,
|
def _test_show_network(self,
|
||||||
tenant=TENANT_1, format='json', status=200):
|
tenant=TENANT_1, format='json', status=200):
|
||||||
LOG.debug("_test_show_network - tenant:%s "\
|
LOG.debug("_test_show_network - tenant:%s "
|
||||||
"- format:%s - START", format, tenant)
|
"- format:%s - START", format, tenant)
|
||||||
|
|
||||||
self._assert_sanity(self.client.show_network,
|
self._assert_sanity(self.client.show_network,
|
||||||
@@ -160,12 +162,12 @@ class APITest(unittest.TestCase):
|
|||||||
data=["001"],
|
data=["001"],
|
||||||
params={'tenant': tenant, 'format': format})
|
params={'tenant': tenant, 'format': format})
|
||||||
|
|
||||||
LOG.debug("_test_show_network - tenant:%s "\
|
LOG.debug("_test_show_network - tenant:%s "
|
||||||
"- format:%s - END", format, tenant)
|
"- format:%s - END", format, tenant)
|
||||||
|
|
||||||
def _test_show_network_details(self,
|
def _test_show_network_details(self,
|
||||||
tenant=TENANT_1, format='json', status=200):
|
tenant=TENANT_1, format='json', status=200):
|
||||||
LOG.debug("_test_show_network_details - tenant:%s "\
|
LOG.debug("_test_show_network_details - tenant:%s "
|
||||||
"- format:%s - START", format, tenant)
|
"- format:%s - START", format, tenant)
|
||||||
|
|
||||||
self._assert_sanity(self.client.show_network_details,
|
self._assert_sanity(self.client.show_network_details,
|
||||||
@@ -175,11 +177,11 @@ class APITest(unittest.TestCase):
|
|||||||
data=["001"],
|
data=["001"],
|
||||||
params={'tenant': tenant, 'format': format})
|
params={'tenant': tenant, 'format': format})
|
||||||
|
|
||||||
LOG.debug("_test_show_network_details - tenant:%s "\
|
LOG.debug("_test_show_network_details - tenant:%s "
|
||||||
"- format:%s - END", format, tenant)
|
"- format:%s - END", format, tenant)
|
||||||
|
|
||||||
def _test_create_network(self, tenant=TENANT_1, format='json', status=200):
|
def _test_create_network(self, tenant=TENANT_1, format='json', status=200):
|
||||||
LOG.debug("_test_create_network - tenant:%s "\
|
LOG.debug("_test_create_network - tenant:%s "
|
||||||
"- format:%s - START", format, tenant)
|
"- format:%s - START", format, tenant)
|
||||||
|
|
||||||
self._assert_sanity(self.client.create_network,
|
self._assert_sanity(self.client.create_network,
|
||||||
@@ -189,11 +191,11 @@ class APITest(unittest.TestCase):
|
|||||||
data=[{'network': {'net-name': 'testNetwork'}}],
|
data=[{'network': {'net-name': 'testNetwork'}}],
|
||||||
params={'tenant': tenant, 'format': format})
|
params={'tenant': tenant, 'format': format})
|
||||||
|
|
||||||
LOG.debug("_test_create_network - tenant:%s "\
|
LOG.debug("_test_create_network - tenant:%s "
|
||||||
"- format:%s - END", format, tenant)
|
"- format:%s - END", format, tenant)
|
||||||
|
|
||||||
def _test_update_network(self, tenant=TENANT_1, format='json', status=200):
|
def _test_update_network(self, tenant=TENANT_1, format='json', status=200):
|
||||||
LOG.debug("_test_update_network - tenant:%s "\
|
LOG.debug("_test_update_network - tenant:%s "
|
||||||
"- format:%s - START", format, tenant)
|
"- format:%s - START", format, tenant)
|
||||||
|
|
||||||
self._assert_sanity(self.client.update_network,
|
self._assert_sanity(self.client.update_network,
|
||||||
@@ -204,11 +206,11 @@ class APITest(unittest.TestCase):
|
|||||||
{'network': {'net-name': 'newName'}}],
|
{'network': {'net-name': 'newName'}}],
|
||||||
params={'tenant': tenant, 'format': format})
|
params={'tenant': tenant, 'format': format})
|
||||||
|
|
||||||
LOG.debug("_test_update_network - tenant:%s "\
|
LOG.debug("_test_update_network - tenant:%s "
|
||||||
"- format:%s - END", format, tenant)
|
"- format:%s - END", format, tenant)
|
||||||
|
|
||||||
def _test_delete_network(self, tenant=TENANT_1, format='json', status=200):
|
def _test_delete_network(self, tenant=TENANT_1, format='json', status=200):
|
||||||
LOG.debug("_test_delete_network - tenant:%s "\
|
LOG.debug("_test_delete_network - tenant:%s "
|
||||||
"- format:%s - START", format, tenant)
|
"- format:%s - START", format, tenant)
|
||||||
|
|
||||||
self._assert_sanity(self.client.delete_network,
|
self._assert_sanity(self.client.delete_network,
|
||||||
@@ -218,11 +220,11 @@ class APITest(unittest.TestCase):
|
|||||||
data=["001"],
|
data=["001"],
|
||||||
params={'tenant': tenant, 'format': format})
|
params={'tenant': tenant, 'format': format})
|
||||||
|
|
||||||
LOG.debug("_test_delete_network - tenant:%s "\
|
LOG.debug("_test_delete_network - tenant:%s "
|
||||||
"- format:%s - END", format, tenant)
|
"- format:%s - END", format, tenant)
|
||||||
|
|
||||||
def _test_list_ports(self, tenant=TENANT_1, format='json', status=200):
|
def _test_list_ports(self, tenant=TENANT_1, format='json', status=200):
|
||||||
LOG.debug("_test_list_ports - tenant:%s "\
|
LOG.debug("_test_list_ports - tenant:%s "
|
||||||
"- format:%s - START", format, tenant)
|
"- format:%s - START", format, tenant)
|
||||||
|
|
||||||
self._assert_sanity(self.client.list_ports,
|
self._assert_sanity(self.client.list_ports,
|
||||||
@@ -232,12 +234,12 @@ class APITest(unittest.TestCase):
|
|||||||
data=["001"],
|
data=["001"],
|
||||||
params={'tenant': tenant, 'format': format})
|
params={'tenant': tenant, 'format': format})
|
||||||
|
|
||||||
LOG.debug("_test_list_ports - tenant:%s "\
|
LOG.debug("_test_list_ports - tenant:%s "
|
||||||
"- format:%s - END", format, tenant)
|
"- format:%s - END", format, tenant)
|
||||||
|
|
||||||
def _test_list_ports_details(self,
|
def _test_list_ports_details(self,
|
||||||
tenant=TENANT_1, format='json', status=200):
|
tenant=TENANT_1, format='json', status=200):
|
||||||
LOG.debug("_test_list_ports_details - tenant:%s "\
|
LOG.debug("_test_list_ports_details - tenant:%s "
|
||||||
"- format:%s - START", format, tenant)
|
"- format:%s - START", format, tenant)
|
||||||
|
|
||||||
self._assert_sanity(self.client.list_ports_details,
|
self._assert_sanity(self.client.list_ports_details,
|
||||||
@@ -247,11 +249,11 @@ class APITest(unittest.TestCase):
|
|||||||
data=["001"],
|
data=["001"],
|
||||||
params={'tenant': tenant, 'format': format})
|
params={'tenant': tenant, 'format': format})
|
||||||
|
|
||||||
LOG.debug("_test_list_ports_details - tenant:%s "\
|
LOG.debug("_test_list_ports_details - tenant:%s "
|
||||||
"- format:%s - END", format, tenant)
|
"- format:%s - END", format, tenant)
|
||||||
|
|
||||||
def _test_show_port(self, tenant=TENANT_1, format='json', status=200):
|
def _test_show_port(self, tenant=TENANT_1, format='json', status=200):
|
||||||
LOG.debug("_test_show_port - tenant:%s "\
|
LOG.debug("_test_show_port - tenant:%s "
|
||||||
"- format:%s - START", format, tenant)
|
"- format:%s - START", format, tenant)
|
||||||
|
|
||||||
self._assert_sanity(self.client.show_port,
|
self._assert_sanity(self.client.show_port,
|
||||||
@@ -261,12 +263,12 @@ class APITest(unittest.TestCase):
|
|||||||
data=["001", "001"],
|
data=["001", "001"],
|
||||||
params={'tenant': tenant, 'format': format})
|
params={'tenant': tenant, 'format': format})
|
||||||
|
|
||||||
LOG.debug("_test_show_port - tenant:%s "\
|
LOG.debug("_test_show_port - tenant:%s "
|
||||||
"- format:%s - END", format, tenant)
|
"- format:%s - END", format, tenant)
|
||||||
|
|
||||||
def _test_show_port_details(self,
|
def _test_show_port_details(self,
|
||||||
tenant=TENANT_1, format='json', status=200):
|
tenant=TENANT_1, format='json', status=200):
|
||||||
LOG.debug("_test_show_port_details - tenant:%s "\
|
LOG.debug("_test_show_port_details - tenant:%s "
|
||||||
"- format:%s - START", format, tenant)
|
"- format:%s - START", format, tenant)
|
||||||
|
|
||||||
self._assert_sanity(self.client.show_port_details,
|
self._assert_sanity(self.client.show_port_details,
|
||||||
@@ -276,11 +278,11 @@ class APITest(unittest.TestCase):
|
|||||||
data=["001", "001"],
|
data=["001", "001"],
|
||||||
params={'tenant': tenant, 'format': format})
|
params={'tenant': tenant, 'format': format})
|
||||||
|
|
||||||
LOG.debug("_test_show_port_details - tenant:%s "\
|
LOG.debug("_test_show_port_details - tenant:%s "
|
||||||
"- format:%s - END", format, tenant)
|
"- format:%s - END", format, tenant)
|
||||||
|
|
||||||
def _test_create_port(self, tenant=TENANT_1, format='json', status=200):
|
def _test_create_port(self, tenant=TENANT_1, format='json', status=200):
|
||||||
LOG.debug("_test_create_port - tenant:%s "\
|
LOG.debug("_test_create_port - tenant:%s "
|
||||||
"- format:%s - START", format, tenant)
|
"- format:%s - START", format, tenant)
|
||||||
|
|
||||||
self._assert_sanity(self.client.create_port,
|
self._assert_sanity(self.client.create_port,
|
||||||
@@ -290,11 +292,11 @@ class APITest(unittest.TestCase):
|
|||||||
data=["001"],
|
data=["001"],
|
||||||
params={'tenant': tenant, 'format': format})
|
params={'tenant': tenant, 'format': format})
|
||||||
|
|
||||||
LOG.debug("_test_create_port - tenant:%s "\
|
LOG.debug("_test_create_port - tenant:%s "
|
||||||
"- format:%s - END", format, tenant)
|
"- format:%s - END", format, tenant)
|
||||||
|
|
||||||
def _test_delete_port(self, tenant=TENANT_1, format='json', status=200):
|
def _test_delete_port(self, tenant=TENANT_1, format='json', status=200):
|
||||||
LOG.debug("_test_delete_port - tenant:%s "\
|
LOG.debug("_test_delete_port - tenant:%s "
|
||||||
"- format:%s - START", format, tenant)
|
"- format:%s - START", format, tenant)
|
||||||
|
|
||||||
self._assert_sanity(self.client.delete_port,
|
self._assert_sanity(self.client.delete_port,
|
||||||
@@ -304,11 +306,11 @@ class APITest(unittest.TestCase):
|
|||||||
data=["001", "001"],
|
data=["001", "001"],
|
||||||
params={'tenant': tenant, 'format': format})
|
params={'tenant': tenant, 'format': format})
|
||||||
|
|
||||||
LOG.debug("_test_delete_port - tenant:%s "\
|
LOG.debug("_test_delete_port - tenant:%s "
|
||||||
"- format:%s - END", format, tenant)
|
"- format:%s - END", format, tenant)
|
||||||
|
|
||||||
def _test_update_port(self, tenant=TENANT_1, format='json', status=200):
|
def _test_update_port(self, tenant=TENANT_1, format='json', status=200):
|
||||||
LOG.debug("_test_update_port - tenant:%s "\
|
LOG.debug("_test_update_port - tenant:%s "
|
||||||
"- format:%s - START", format, tenant)
|
"- format:%s - START", format, tenant)
|
||||||
|
|
||||||
self._assert_sanity(self.client.update_port,
|
self._assert_sanity(self.client.update_port,
|
||||||
@@ -319,12 +321,12 @@ class APITest(unittest.TestCase):
|
|||||||
{'port': {'state': 'ACTIVE'}}],
|
{'port': {'state': 'ACTIVE'}}],
|
||||||
params={'tenant': tenant, 'format': format})
|
params={'tenant': tenant, 'format': format})
|
||||||
|
|
||||||
LOG.debug("_test_update_port - tenant:%s "\
|
LOG.debug("_test_update_port - tenant:%s "
|
||||||
"- format:%s - END", format, tenant)
|
"- format:%s - END", format, tenant)
|
||||||
|
|
||||||
def _test_show_port_attachment(self,
|
def _test_show_port_attachment(self,
|
||||||
tenant=TENANT_1, format='json', status=200):
|
tenant=TENANT_1, format='json', status=200):
|
||||||
LOG.debug("_test_show_port_attachment - tenant:%s "\
|
LOG.debug("_test_show_port_attachment - tenant:%s "
|
||||||
"- format:%s - START", format, tenant)
|
"- format:%s - START", format, tenant)
|
||||||
|
|
||||||
self._assert_sanity(self.client.show_port_attachment,
|
self._assert_sanity(self.client.show_port_attachment,
|
||||||
@@ -334,12 +336,12 @@ class APITest(unittest.TestCase):
|
|||||||
data=["001", "001"],
|
data=["001", "001"],
|
||||||
params={'tenant': tenant, 'format': format})
|
params={'tenant': tenant, 'format': format})
|
||||||
|
|
||||||
LOG.debug("_test_show_port_attachment - tenant:%s "\
|
LOG.debug("_test_show_port_attachment - tenant:%s "
|
||||||
"- format:%s - END", format, tenant)
|
"- format:%s - END", format, tenant)
|
||||||
|
|
||||||
def _test_attach_resource(self, tenant=TENANT_1,
|
def _test_attach_resource(self, tenant=TENANT_1,
|
||||||
format='json', status=200):
|
format='json', status=200):
|
||||||
LOG.debug("_test_attach_resource - tenant:%s "\
|
LOG.debug("_test_attach_resource - tenant:%s "
|
||||||
"- format:%s - START", format, tenant)
|
"- format:%s - START", format, tenant)
|
||||||
|
|
||||||
self._assert_sanity(self.client.attach_resource,
|
self._assert_sanity(self.client.attach_resource,
|
||||||
@@ -350,12 +352,12 @@ class APITest(unittest.TestCase):
|
|||||||
{'resource': {'id': '1234'}}],
|
{'resource': {'id': '1234'}}],
|
||||||
params={'tenant': tenant, 'format': format})
|
params={'tenant': tenant, 'format': format})
|
||||||
|
|
||||||
LOG.debug("_test_attach_resource - tenant:%s "\
|
LOG.debug("_test_attach_resource - tenant:%s "
|
||||||
"- format:%s - END", format, tenant)
|
"- format:%s - END", format, tenant)
|
||||||
|
|
||||||
def _test_detach_resource(self, tenant=TENANT_1,
|
def _test_detach_resource(self, tenant=TENANT_1,
|
||||||
format='json', status=200):
|
format='json', status=200):
|
||||||
LOG.debug("_test_detach_resource - tenant:%s "\
|
LOG.debug("_test_detach_resource - tenant:%s "
|
||||||
"- format:%s - START", format, tenant)
|
"- format:%s - START", format, tenant)
|
||||||
|
|
||||||
self._assert_sanity(self.client.detach_resource,
|
self._assert_sanity(self.client.detach_resource,
|
||||||
@@ -365,12 +367,12 @@ class APITest(unittest.TestCase):
|
|||||||
data=["001", "001"],
|
data=["001", "001"],
|
||||||
params={'tenant': tenant, 'format': format})
|
params={'tenant': tenant, 'format': format})
|
||||||
|
|
||||||
LOG.debug("_test_detach_resource - tenant:%s "\
|
LOG.debug("_test_detach_resource - tenant:%s "
|
||||||
"- format:%s - END", format, tenant)
|
"- format:%s - END", format, tenant)
|
||||||
|
|
||||||
def _test_ssl_certificates(self, tenant=TENANT_1,
|
def _test_ssl_certificates(self, tenant=TENANT_1,
|
||||||
format='json', status=200):
|
format='json', status=200):
|
||||||
LOG.debug("_test_ssl_certificates - tenant:%s "\
|
LOG.debug("_test_ssl_certificates - tenant:%s "
|
||||||
"- format:%s - START", format, tenant)
|
"- format:%s - START", format, tenant)
|
||||||
|
|
||||||
# Set SSL, and our cert file
|
# Set SSL, and our cert file
|
||||||
@@ -379,16 +381,16 @@ class APITest(unittest.TestCase):
|
|||||||
self.client.key_file = self.client.cert_file = cert_file
|
self.client.key_file = self.client.cert_file = cert_file
|
||||||
|
|
||||||
data = self._assert_sanity(self.client.list_networks,
|
data = self._assert_sanity(self.client.list_networks,
|
||||||
status,
|
status,
|
||||||
"GET",
|
"GET",
|
||||||
"networks",
|
"networks",
|
||||||
data=[],
|
data=[],
|
||||||
params={'tenant': tenant, 'format': format})
|
params={'tenant': tenant, 'format': format})
|
||||||
|
|
||||||
self.assertEquals(data["key_file"], cert_file)
|
self.assertEquals(data["key_file"], cert_file)
|
||||||
self.assertEquals(data["cert_file"], cert_file)
|
self.assertEquals(data["cert_file"], cert_file)
|
||||||
|
|
||||||
LOG.debug("_test_ssl_certificates - tenant:%s "\
|
LOG.debug("_test_ssl_certificates - tenant:%s "
|
||||||
"- format:%s - END", format, tenant)
|
"- format:%s - END", format, tenant)
|
||||||
|
|
||||||
def test_list_networks_json(self):
|
def test_list_networks_json(self):
|
||||||
|
Reference in New Issue
Block a user