From 15a625ba16a8179a6b3d509cbd80c98b3ed41033 Mon Sep 17 00:00:00 2001 From: Salvatore Orlando Date: Tue, 7 Jun 2011 18:25:16 +0100 Subject: [PATCH 01/10] Fixing pep8 errors removing excess debug lines --- quantum/api/__init__.py | 6 +- quantum/api/faults.py | 2 +- quantum/api/networks.py | 2 +- quantum/api/ports.py | 64 +++++----- quantum/api/views/__init__.py | 1 - quantum/api/views/networks.py | 5 +- quantum/api/views/ports.py | 5 +- quantum/cli.py | 9 +- quantum/common/config.py | 4 +- quantum/common/exceptions.py | 11 +- quantum/common/flags.py | 3 +- quantum/common/utils.py | 2 + quantum/common/wsgi.py | 15 +-- quantum/manager.py | 7 +- quantum/plugins/SamplePlugin.py | 204 ++++++++++++++------------------ quantum/plugins/__init__.py | 2 +- quantum/service.py | 4 +- 17 files changed, 153 insertions(+), 193 deletions(-) diff --git a/quantum/api/__init__.py b/quantum/api/__init__.py index 25b66f5573..e437d27d84 100644 --- a/quantum/api/__init__.py +++ b/quantum/api/__init__.py @@ -51,11 +51,11 @@ class APIRouterV01(wsgi.Router): mapper.resource('network', 'networks', controller=networks.Controller(), path_prefix=uri_prefix) - mapper.resource('port', 'ports', + mapper.resource('port', 'ports', controller=ports.Controller(), parent_resource=dict(member_name='network', - collection_name=\ - uri_prefix + 'networks')) + collection_name=uri_prefix +\ + 'networks')) mapper.connect("get_resource", uri_prefix + 'networks/{network_id}/' \ diff --git a/quantum/api/faults.py b/quantum/api/faults.py index a10364df19..6f68f561e9 100644 --- a/quantum/api/faults.py +++ b/quantum/api/faults.py @@ -52,7 +52,7 @@ class Fault(webob.exc.HTTPException): fault_data = { fault_name: { 'code': code, - 'message': self.wrapped_exc.explanation, + 'message': self.wrapped_exc.explanation, 'detail': self.wrapped_exc.detail}} # 'code' is an attribute on the fault tag itself metadata = {'application/xml': {'attributes': {fault_name: 'code'}}} diff --git a/quantum/api/networks.py b/quantum/api/networks.py index 98dd5e305d..0985dbc856 100644 --- a/quantum/api/networks.py +++ b/quantum/api/networks.py @@ -78,7 +78,7 @@ class Controller(common.QuantumController): except exc.HTTPError as e: return faults.Fault(e) network = self.network_manager.\ - create_network(tenant_id,req_params['network-name']) + create_network(tenant_id, req_params['network-name']) builder = networks_view.get_view_builder(req) result = builder.build(network) return dict(networks=result) diff --git a/quantum/api/ports.py b/quantum/api/ports.py index 2b93cdec72..bbe6d3f520 100644 --- a/quantum/api/ports.py +++ b/quantum/api/ports.py @@ -24,24 +24,25 @@ from quantum.common import exceptions as exception LOG = logging.getLogger('quantum.api.ports') + class Controller(common.QuantumController): """ Port API controller for Quantum API """ _port_ops_param_list = [{ 'param-name': 'port-state', - 'default-value': 'DOWN', - 'required': False},] - + 'default-value': 'DOWN', + 'required': False}, + ] _attachment_ops_param_list = [{ 'param-name': 'attachment-id', - 'required': True},] + 'required': True}, + ] - _serialization_metadata = { "application/xml": { "attributes": { - "port": ["id","state"], + "port": ["id", "state"], }, }, } @@ -49,14 +50,14 @@ class Controller(common.QuantumController): def __init__(self, plugin_conf_file=None): self._resource_name = 'port' super(Controller, self).__init__() - + def index(self, req, tenant_id, network_id): """ Returns a list of port ids for a given network """ return self._items(req, tenant_id, network_id, is_detail=False) def _items(self, req, tenant_id, network_id, is_detail): """ Returns a list of networks. """ - try : + try: ports = self.network_manager.get_all_ports(tenant_id, network_id) builder = ports_view.get_view_builder(req) result = [builder.build(port, is_detail)['port'] @@ -64,7 +65,7 @@ class Controller(common.QuantumController): return dict(ports=result) except exception.NetworkNotFound as e: return faults.Fault(faults.NetworkNotFound(e)) - + def show(self, req, tenant_id, network_id, id): """ Returns port details for given port and network """ try: @@ -77,7 +78,7 @@ class Controller(common.QuantumController): except exception.NetworkNotFound as e: return faults.Fault(faults.NetworkNotFound(e)) except exception.PortNotFound as e: - return faults.Fault(faults.PortNotFound(e)) + return faults.Fault(faults.PortNotFound(e)) def create(self, req, tenant_id, network_id): """ Creates a new port for a given network """ @@ -87,17 +88,17 @@ class Controller(common.QuantumController): self._parse_request_params(req, self._port_ops_param_list) except exc.HTTPError as e: return faults.Fault(e) - try: + try: port = self.network_manager.create_port(tenant_id, - network_id, + network_id, req_params['port-state']) builder = ports_view.get_view_builder(req) result = builder.build(port) return dict(ports=result) except exception.NetworkNotFound as e: return faults.Fault(faults.NetworkNotFound(e)) - except exception.StateInvalid as e: - return faults.Fault(faults.RequestedStateInvalid(e)) + except exception.StateInvalid as e: + return faults.Fault(faults.RequestedStateInvalid(e)) def update(self, req, tenant_id, network_id, id): """ Updates the state of a port for a given network """ @@ -106,9 +107,9 @@ class Controller(common.QuantumController): req_params = \ self._parse_request_params(req, self._port_ops_param_list) except exc.HTTPError as e: - return faults.Fault(e) - try: - port = self.network_manager.update_port(tenant_id,network_id, id, + return faults.Fault(e) + try: + port = self.network_manager.update_port(tenant_id, network_id, id, req_params['port-state']) builder = ports_view.get_view_builder(req) result = builder.build(port, True) @@ -117,26 +118,24 @@ class Controller(common.QuantumController): return faults.Fault(faults.NetworkNotFound(e)) except exception.PortNotFound as e: return faults.Fault(faults.PortNotFound(e)) - except exception.StateInvalid as e: + except exception.StateInvalid as e: return faults.Fault(faults.RequestedStateInvalid(e)) - def delete(self, req, tenant_id, network_id, id): """ Destroys the port with the given id """ #look for port state in request try: self.network_manager.delete_port(tenant_id, network_id, id) return exc.HTTPAccepted() - #TODO(salvatore-orlando): Handle portInUse error + # TODO(salvatore-orlando): Handle portInUse error except exception.NetworkNotFound as e: return faults.Fault(faults.NetworkNotFound(e)) except exception.PortNotFound as e: - return faults.Fault(faults.PortNotFound(e)) + return faults.Fault(faults.PortNotFound(e)) except exception.PortInUse as e: return faults.Fault(faults.PortInUse(e)) - - def get_resource(self,req,tenant_id, network_id, id): + def get_resource(self, req, tenant_id, network_id, id): try: result = self.network_manager.get_interface_details( tenant_id, network_id, id) @@ -144,12 +143,9 @@ class Controller(common.QuantumController): except exception.NetworkNotFound as e: return faults.Fault(faults.NetworkNotFound(e)) except exception.PortNotFound as e: - return faults.Fault(faults.PortNotFound(e)) + return faults.Fault(faults.PortNotFound(e)) - #TODO - Complete implementation of these APIs - def attach_resource(self,req,tenant_id, network_id, id): - content_type = req.best_match_content_type() - print "Content type:%s" %content_type + def attach_resource(self, req, tenant_id, network_id, id): try: req_params = \ self._parse_request_params(req, @@ -158,26 +154,24 @@ class Controller(common.QuantumController): return faults.Fault(e) try: self.network_manager.plug_interface(tenant_id, - network_id,id, + network_id, id, req_params['attachment-id']) return exc.HTTPAccepted() except exception.NetworkNotFound as e: return faults.Fault(faults.NetworkNotFound(e)) except exception.PortNotFound as e: - return faults.Fault(faults.PortNotFound(e)) + return faults.Fault(faults.PortNotFound(e)) except exception.PortInUse as e: return faults.Fault(faults.PortInUse(e)) except exception.AlreadyAttached as e: return faults.Fault(faults.AlreadyAttached(e)) - - #TODO - Complete implementation of these APIs - def detach_resource(self,req,tenant_id, network_id, id): + def detach_resource(self, req, tenant_id, network_id, id): try: self.network_manager.unplug_interface(tenant_id, - network_id,id) + network_id, id) return exc.HTTPAccepted() except exception.NetworkNotFound as e: return faults.Fault(faults.NetworkNotFound(e)) except exception.PortNotFound as e: - return faults.Fault(faults.PortNotFound(e)) + return faults.Fault(faults.PortNotFound(e)) diff --git a/quantum/api/views/__init__.py b/quantum/api/views/__init__.py index ea91034003..3e54802128 100644 --- a/quantum/api/views/__init__.py +++ b/quantum/api/views/__init__.py @@ -13,4 +13,3 @@ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. -# @author: Somik Behera, Nicira Networks, Inc. \ No newline at end of file diff --git a/quantum/api/views/networks.py b/quantum/api/views/networks.py index 2a64d87f09..98c69730e5 100644 --- a/quantum/api/views/networks.py +++ b/quantum/api/views/networks.py @@ -33,17 +33,16 @@ class ViewBuilder(object): def build(self, network_data, is_detail=False): """Generic method used to generate a network entity.""" - print "NETWORK-DATA:%s" %network_data if is_detail: network = self._build_detail(network_data) else: network = self._build_simple(network_data) return network - + def _build_simple(self, network_data): """Return a simple model of a server.""" return dict(network=dict(id=network_data['net-id'])) - + def _build_detail(self, network_data): """Return a simple model of a server.""" return dict(network=dict(id=network_data['net-id'], diff --git a/quantum/api/views/ports.py b/quantum/api/views/ports.py index 2d93a35f60..f72e24dbdc 100644 --- a/quantum/api/views/ports.py +++ b/quantum/api/views/ports.py @@ -31,17 +31,16 @@ class ViewBuilder(object): def build(self, port_data, is_detail=False): """Generic method used to generate a port entity.""" - print "PORT-DATA:%s" %port_data if is_detail: port = self._build_detail(port_data) else: port = self._build_simple(port_data) return port - + def _build_simple(self, port_data): """Return a simple model of a server.""" return dict(port=dict(id=port_data['port-id'])) - + def _build_detail(self, port_data): """Return a simple model of a server.""" return dict(port=dict(id=port_data['port-id'], diff --git a/quantum/cli.py b/quantum/cli.py index 78f1a6b481..dc6cf8240a 100644 --- a/quantum/cli.py +++ b/quantum/cli.py @@ -36,7 +36,7 @@ def usage(): print "detail_iface " print "list_iface \n" -if len(sys.argv) < 2 or len(sys.argv) > 6: +if len(sys.argv) < 2 or len(sys.argv) > 6: usage() exit(1) @@ -89,13 +89,13 @@ elif sys.argv[1] == "plug_iface" and len(sys.argv) == 6: elif sys.argv[1] == "unplug_iface" and len(sys.argv) == 5: manager.unplug_interface(sys.argv[2], sys.argv[3], sys.argv[4]) print "UnPlugged remote interface " \ - "from Virtual Port:%s Virtual Network:%s" % (sys.argv[4], + "from Virtual Port:%s Virtual Network:%s" % (sys.argv[4], sys.argv[3]) elif sys.argv[1] == "detail_iface" and len(sys.argv) == 5: - remote_iface = manager.get_interface_details(sys.argv[2], + remote_iface = manager.get_interface_details(sys.argv[2], sys.argv[3], sys.argv[4]) print "Remote interface on Virtual Port:%s " \ - "Virtual Network:%s is %s" % (sys.argv[4], + "Virtual Network:%s is %s" % (sys.argv[4], sys.argv[3], remote_iface) elif sys.argv[1] == "list_iface" and len(sys.argv) == 4: iface_list = manager.get_all_attached_interfaces(sys.argv[2], sys.argv[3]) @@ -107,4 +107,3 @@ elif sys.argv[1] == "all" and len(sys.argv) == 2: else: print "invalid arguments: %s" % str(sys.argv) usage() - diff --git a/quantum/common/config.py b/quantum/common/config.py index cda7650781..a497f0dd44 100644 --- a/quantum/common/config.py +++ b/quantum/common/config.py @@ -209,7 +209,7 @@ def find_config_file(options, args): fix_path(os.path.join('~', '.quantum')), fix_path('~'), os.path.join(FLAGS.state_path, 'etc'), - os.path.join(FLAGS.state_path, 'etc','quantum'), + os.path.join(FLAGS.state_path, 'etc', 'quantum'), '/etc/quantum/', '/etc'] for cfg_dir in config_file_dirs: @@ -244,12 +244,10 @@ def load_paste_config(app_name, options, args): problem loading the configuration file. """ conf_file = find_config_file(options, args) - print "Conf_file:%s" %conf_file if not conf_file: raise RuntimeError("Unable to locate any configuration file. " "Cannot load application %s" % app_name) try: - print "App_name:%s" %app_name conf = deploy.appconfig("config:%s" % conf_file, name=app_name) return conf_file, conf except Exception, e: diff --git a/quantum/common/exceptions.py b/quantum/common/exceptions.py index 7b9784b921..4daf31762b 100644 --- a/quantum/common/exceptions.py +++ b/quantum/common/exceptions.py @@ -25,7 +25,7 @@ import logging class QuantumException(Exception): """Base Quantum Exception - + Taken from nova.exception.NovaException To correctly use this class, inherit from it and define a 'message' property. That message will get printf'd @@ -45,6 +45,7 @@ class QuantumException(Exception): def __str__(self): return self._error_string + class ProcessExecutionError(IOError): def __init__(self, stdout=None, stderr=None, exit_code=None, cmd=None, description=None): @@ -84,11 +85,11 @@ class NetworkNotFound(NotFound): class PortNotFound(NotFound): message = _("Port %(port_id)s could not be found " \ "on network %(net_id)s") - + class StateInvalid(QuantumException): message = _("Unsupported port state: %(port_state)s") - + class NetworkInUse(QuantumException): message = _("Unable to complete operation on network %(net_id)s. " \ @@ -100,11 +101,13 @@ class PortInUse(QuantumException): "for network %(net_id)s. The attachment '%(att_id)s" \ "is plugged into the logical port.") + class AlreadyAttached(QuantumException): message = _("Unable to plug the attachment %(att_id)s into port " \ "%(port_id)s for network %(net_id)s. The attachment is " \ "already plugged into port %(att_port_id)s") - + + class Duplicate(Error): pass diff --git a/quantum/common/flags.py b/quantum/common/flags.py index 947999d0f2..5adf4c3854 100644 --- a/quantum/common/flags.py +++ b/quantum/common/flags.py @@ -23,7 +23,7 @@ Global flags should be defined here, the rest are defined where they're used. """ import getopt -import os +import os import string import sys @@ -249,4 +249,3 @@ def DECLARE(name, module_string, flag_values=FLAGS): DEFINE_string('state_path', os.path.join(os.path.dirname(__file__), '../../'), "Top-level directory for maintaining quantum's state") - diff --git a/quantum/common/utils.py b/quantum/common/utils.py index c80ac9cccd..d3730ba61a 100644 --- a/quantum/common/utils.py +++ b/quantum/common/utils.py @@ -37,6 +37,7 @@ from exceptions import ProcessExecutionError TIME_FORMAT = "%Y-%m-%dT%H:%M:%SZ" FLAGS = flags.FLAGS + def int_from_bool_as_string(subject): """ Interpret a string as a boolean and return either 1 or 0. @@ -188,6 +189,7 @@ def isotime(at=None): def parse_isotime(timestr): return datetime.datetime.strptime(timestr, TIME_FORMAT) + def getPluginFromConfig(file="config.ini"): Config = ConfigParser.ConfigParser() Config.read(os.path.join(FLAGS.state_path, file)) diff --git a/quantum/common/wsgi.py b/quantum/common/wsgi.py index 4caeab9abc..f3873e351c 100644 --- a/quantum/common/wsgi.py +++ b/quantum/common/wsgi.py @@ -40,6 +40,7 @@ from quantum.common import exceptions as exception LOG = logging.getLogger('quantum.common.wsgi') + class WritableLogger(object): """A thin wrapper that responds to `write` and logs.""" @@ -126,7 +127,7 @@ class Request(webob.Request): """ parts = self.path.rsplit('.', 1) - LOG.debug("Request parts:%s",parts) + LOG.debug("Request parts:%s", parts) if len(parts) > 1: format = parts[1] if format in ['json', 'xml']: @@ -134,7 +135,6 @@ class Request(webob.Request): ctypes = ['application/json', 'application/xml'] bm = self.accept.best_match(ctypes) - LOG.debug("BM:%s",bm) return bm or 'application/json' def get_content_type(self): @@ -336,10 +336,6 @@ class Controller(object): arg_dict = req.environ['wsgiorg.routing_args'][1] action = arg_dict['action'] method = getattr(self, action) - LOG.debug("ARG_DICT:%s",arg_dict) - LOG.debug("Action:%s",action) - LOG.debug("Method:%s",method) - LOG.debug("%s %s" % (req.method, req.url)) del arg_dict['controller'] del arg_dict['action'] if 'format' in arg_dict: @@ -349,8 +345,6 @@ class Controller(object): if type(result) is dict: content_type = req.best_match_content_type() - LOG.debug("Content type:%s",content_type) - LOG.debug("Result:%s",result) default_xmlns = self.get_default_xmlns(req) body = self._serialize(result, content_type, default_xmlns) @@ -497,9 +491,7 @@ class Serializer(object): xmlns = metadata.get('xmlns', None) if xmlns: result.setAttribute('xmlns', xmlns) - LOG.debug("DATA:%s",data) if type(data) is list: - LOG.debug("TYPE IS LIST") collections = metadata.get('list_collections', {}) if nodename in collections: metadata = collections[nodename] @@ -518,7 +510,6 @@ class Serializer(object): node = self._to_xml_node(doc, metadata, singular, item) result.appendChild(node) elif type(data) is dict: - LOG.debug("TYPE IS DICT") collections = metadata.get('dict_collections', {}) if nodename in collections: metadata = collections[nodename] @@ -538,8 +529,6 @@ class Serializer(object): result.appendChild(node) else: # Type is atom - LOG.debug("TYPE IS ATOM:%s",data) node = doc.createTextNode(str(data)) result.appendChild(node) return result - diff --git a/quantum/manager.py b/quantum/manager.py index dc3f39d754..f4b829303d 100644 --- a/quantum/manager.py +++ b/quantum/manager.py @@ -18,8 +18,9 @@ """ -Quantum's Manager class is responsible for parsing a config file and instantiating the correct -plugin that concretely implement quantum_plugin_base class +Quantum's Manager class is responsible for parsing a config file +and instantiating the correct plugin that concretely implement +quantum_plugin_base class The caller should make sure that QuantumManager is a singleton. """ @@ -34,7 +35,7 @@ CONFIG_FILE = "quantum/plugins.ini" class QuantumManager(object): - def __init__(self,config=CONFIG_FILE): + def __init__(self, config=CONFIG_FILE): self.configuration_file = CONFIG_FILE plugin_location = utils.getPluginFromConfig(CONFIG_FILE) print "PLUGIN LOCATION:%s" % plugin_location diff --git a/quantum/plugins/SamplePlugin.py b/quantum/plugins/SamplePlugin.py index 7b43b4c6d4..15b6ab0899 100644 --- a/quantum/plugins/SamplePlugin.py +++ b/quantum/plugins/SamplePlugin.py @@ -17,33 +17,32 @@ from quantum.common import exceptions as exc + class QuantumEchoPlugin(object): """ QuantumEchoPlugin is a demo plugin that doesn't do anything but demonstrated the concept of a concrete Quantum Plugin. Any call to this plugin - will result in just a "print" to std. out with + will result in just a "print" to std. out with the name of the method that was called. """ - + def get_all_networks(self, tenant_id): """ Returns a dictionary containing all for - the specified tenant. + the specified tenant. """ print("get_all_networks() called\n") - - + def create_network(self, tenant_id, net_name): """ Creates a new Virtual Network, and assigns it a symbolic name. """ print("create_network() called\n") - - + def delete_network(self, tenant_id, net_id): """ Deletes the network with the specified network identifier @@ -51,38 +50,33 @@ class QuantumEchoPlugin(object): """ print("delete_network() called\n") - def get_network_details(self, tenant_id, net_id): """ Deletes the Virtual Network belonging to a the spec """ print("get_network_details() called\n") - - + def rename_network(self, tenant_id, net_id, new_name): """ Updates the symbolic name belonging to a particular Virtual Network. """ print("rename_network() called\n") - - + def get_all_ports(self, tenant_id, net_id): """ Retrieves all port identifiers belonging to the specified Virtual Network. """ print("get_all_ports() called\n") - - + def create_port(self, tenant_id, net_id): """ Creates a port on the specified Virtual Network. """ print("create_port() called\n") - - + def delete_port(self, tenant_id, net_id, port_id): """ Deletes a port on a specified Virtual Network, @@ -91,40 +85,35 @@ class QuantumEchoPlugin(object): is deleted. """ print("delete_port() called\n") - - + def get_port_details(self, tenant_id, net_id, port_id): """ This method allows the user to retrieve a remote interface that is attached to this particular port. """ print("get_port_details() called\n") - - + def plug_interface(self, tenant_id, net_id, port_id, remote_interface_id): """ Attaches a remote interface to the specified port on the specified Virtual Network. """ print("plug_interface() called\n") - - + def unplug_interface(self, tenant_id, net_id, port_id): """ Detaches a remote interface from the specified port on the specified Virtual Network. """ print("unplug_interface() called\n") - - + def get_interface_details(self, tenant_id, net_id, port_id): """ Retrieves the remote interface that is attached at this particular port. """ print("get_interface_details() called\n") - - + def get_all_attached_interfaces(self, tenant_id, net_id): """ Retrieves all remote interfaces that are attached to @@ -132,6 +121,7 @@ class QuantumEchoPlugin(object): """ print("get_all_attached_interfaces() called\n") + class DummyDataPlugin(object): """ @@ -139,18 +129,17 @@ class DummyDataPlugin(object): hard-coded data structures to aid in quantum client/cli development """ - + def get_all_networks(self, tenant_id): """ Returns a dictionary containing all for - the specified tenant. + the specified tenant. """ - nets = {"001": "lNet1", "002": "lNet2" , "003": "lNet3"} + nets = {"001": "lNet1", "002": "lNet2", "003": "lNet3"} print("get_all_networks() called\n") return nets - - + def create_network(self, tenant_id, net_name): """ Creates a new Virtual Network, and assigns it @@ -159,8 +148,7 @@ class DummyDataPlugin(object): print("create_network() called\n") # return network_id of the created network return 101 - - + def delete_network(self, tenant_id, net_id): """ Deletes the network with the specified network identifier @@ -168,25 +156,23 @@ class DummyDataPlugin(object): """ print("delete_network() called\n") - def get_network_details(self, tenant_id, net_id): """ retrieved a list of all the remote vifs that are attached to the network """ print("get_network_details() called\n") - vifs_on_net = ["/tenant1/networks/net_id/portid/vif2.0", "/tenant1/networks/10/121/vif1.1"] + vifs_on_net = ["/tenant1/networks/net_id/portid/vif2.0", + "/tenant1/networks/10/121/vif1.1"] return vifs_on_net - - + def rename_network(self, tenant_id, net_id, new_name): """ Updates the symbolic name belonging to a particular Virtual Network. """ print("rename_network() called\n") - - + def get_all_ports(self, tenant_id, net_id): """ Retrieves all port identifiers belonging to the @@ -195,8 +181,7 @@ class DummyDataPlugin(object): print("get_all_ports() called\n") port_ids_on_net = ["2", "3", "4"] return port_ids_on_net - - + def create_port(self, tenant_id, net_id): """ Creates a port on the specified Virtual Network. @@ -204,8 +189,7 @@ class DummyDataPlugin(object): print("create_port() called\n") #return the port id return 201 - - + def delete_port(self, tenant_id, net_id, port_id): """ Deletes a port on a specified Virtual Network, @@ -214,8 +198,7 @@ class DummyDataPlugin(object): is deleted. """ print("delete_port() called\n") - - + def get_port_details(self, tenant_id, net_id, port_id): """ This method allows the user to retrieve a remote interface @@ -224,24 +207,21 @@ class DummyDataPlugin(object): print("get_port_details() called\n") #returns the remote interface UUID return "/tenant1/networks/net_id/portid/vif2.1" - - + def plug_interface(self, tenant_id, net_id, port_id, remote_interface_id): """ Attaches a remote interface to the specified port on the specified Virtual Network. """ print("plug_interface() called\n") - - + def unplug_interface(self, tenant_id, net_id, port_id): """ Detaches a remote interface from the specified port on the specified Virtual Network. """ print("unplug_interface() called\n") - - + def get_interface_details(self, tenant_id, net_id, port_id): """ Retrieves the remote interface that is attached at this @@ -250,8 +230,7 @@ class DummyDataPlugin(object): print("get_interface_details() called\n") #returns the remote interface UUID return "/tenant1/networks/net_id/portid/vif2.0" - - + def get_all_attached_interfaces(self, tenant_id, net_id): """ Retrieves all remote interfaces that are attached to @@ -259,10 +238,11 @@ class DummyDataPlugin(object): """ print("get_all_attached_interfaces() called\n") # returns a list of all attached remote interfaces - vifs_on_net = ["/tenant1/networks/net_id/portid/vif2.0", "/tenant1/networks/10/121/vif1.1"] + vifs_on_net = ["/tenant1/networks/net_id/portid/vif2.0", + "/tenant1/networks/10/121/vif1.1"] return vifs_on_net - - + + class FakePlugin(object): """ FakePlugin is a demo plugin that provides @@ -272,72 +252,70 @@ class FakePlugin(object): #static data for networks and ports _port_dict_1 = { - 1 : {'port-id': 1, - 'port-state': 'DOWN', - 'attachment': None}, - 2 : {'port-id': 2, - 'port-state':'UP', - 'attachment': None} + 1: {'port-id': 1, + 'port-state': 'DOWN', + 'attachment': None}, + 2: {'port-id': 2, + 'port-state': 'UP', + 'attachment': None} } _port_dict_2 = { - 1 : {'port-id': 1, - 'port-state': 'UP', - 'attachment': 'SomeFormOfVIFID'}, - 2 : {'port-id': 2, - 'port-state':'DOWN', - 'attachment': None} - } - _networks={'001': + 1: {'port-id': 1, + 'port-state': 'UP', + 'attachment': 'SomeFormOfVIFID'}, + 2: {'port-id': 2, + 'port-state': 'DOWN', + 'attachment': None} + } + _networks = {'001': { - 'net-id':'001', - 'net-name':'pippotest', + 'net-id': '001', + 'net-name': 'pippotest', 'net-ports': _port_dict_1 }, '002': { - 'net-id':'002', - 'net-name':'cicciotest', - 'net-ports': _port_dict_2 + 'net-id': '002', + 'net-name': 'cicciotest', + 'net-ports': _port_dict_2 }} - - + def __init__(self): - FakePlugin._net_counter=len(FakePlugin._networks) - + FakePlugin._net_counter = len(FakePlugin._networks) + def _get_network(self, tenant_id, network_id): network = FakePlugin._networks.get(network_id) if not network: raise exc.NetworkNotFound(net_id=network_id) return network - def _get_port(self, tenant_id, network_id, port_id): net = self._get_network(tenant_id, network_id) port = net['net-ports'].get(int(port_id)) if not port: raise exc.PortNotFound(net_id=network_id, port_id=port_id) return port - + def _validate_port_state(self, port_state): - if port_state.upper() not in ('UP','DOWN'): + if port_state.upper() not in ('UP', 'DOWN'): raise exc.StateInvalid(port_state=port_state) return True - + def _validate_attachment(self, tenant_id, network_id, port_id, remote_interface_id): network = self._get_network(tenant_id, network_id) for port in network['net-ports'].values(): if port['attachment'] == remote_interface_id: - raise exc.AlreadyAttached(net_id = network_id, - port_id = port_id, - att_id = port['attachment'], - att_port_id = port['port-id']) - + raise exc.AlreadyAttached(net_id=network_id, + port_id=port_id, + att_id=port['attachment'], + att_port_id=port['port-id']) + def get_all_networks(self, tenant_id): """ Returns a dictionary containing all for - the specified tenant. + the specified tenant. """ print("get_all_networks() called\n") return FakePlugin._networks.values() @@ -357,16 +335,16 @@ class FakePlugin(object): """ print("create_network() called\n") FakePlugin._net_counter += 1 - new_net_id=("0" * (3 - len(str(FakePlugin._net_counter)))) + \ + new_net_id = ("0" * (3 - len(str(FakePlugin._net_counter)))) + \ str(FakePlugin._net_counter) print new_net_id - new_net_dict={'net-id':new_net_id, - 'net-name':net_name, - 'net-ports': {}} - FakePlugin._networks[new_net_id]=new_net_dict + new_net_dict = {'net-id': new_net_id, + 'net-name': net_name, + 'net-ports': {}} + FakePlugin._networks[new_net_id] = new_net_dict # return network_id of the created network return new_net_dict - + def delete_network(self, tenant_id, net_id): """ Deletes the network with the specified network identifier @@ -384,7 +362,7 @@ class FakePlugin(object): return net # Network not found raise exc.NetworkNotFound(net_id=net_id) - + def rename_network(self, tenant_id, net_id, new_name): """ Updates the symbolic name belonging to a particular @@ -392,7 +370,7 @@ class FakePlugin(object): """ print("rename_network() called\n") net = self._get_network(tenant_id, net_id) - net['net-name']=new_name + net['net-name'] = new_name return net def get_all_ports(self, tenant_id, net_id): @@ -412,7 +390,7 @@ class FakePlugin(object): """ print("get_port_details() called\n") return self._get_port(tenant_id, net_id, port_id) - + def create_port(self, tenant_id, net_id, port_state=None): """ Creates a port on the specified Virtual Network. @@ -420,15 +398,15 @@ class FakePlugin(object): print("create_port() called\n") net = self._get_network(tenant_id, net_id) # check port state - # TODO(salvatore-orlando): Validate port state in API? + # TODO(salvatore-orlando): Validate port state in API? self._validate_port_state(port_state) ports = net['net-ports'] - new_port_id = max(ports.keys())+1 - new_port_dict = {'port-id':new_port_id, + new_port_id = max(ports.keys()) + 1 + new_port_dict = {'port-id': new_port_id, 'port-state': port_state, 'attachment': None} ports[new_port_id] = new_port_dict - return new_port_dict + return new_port_dict def update_port(self, tenant_id, net_id, port_id, port_state): """ @@ -438,8 +416,8 @@ class FakePlugin(object): port = self._get_port(tenant_id, net_id, port_id) self._validate_port_state(port_state) port['port-state'] = port_state - return port - + return port + def delete_port(self, tenant_id, net_id, port_id): """ Deletes a port on a specified Virtual Network, @@ -451,11 +429,11 @@ class FakePlugin(object): net = self._get_network(tenant_id, net_id) port = self._get_port(tenant_id, net_id, port_id) if port['attachment']: - raise exc.PortInUse(net_id=net_id,port_id=port_id, + raise exc.PortInUse(net_id=net_id, port_id=port_id, att_id=port['attachment']) try: net['net-ports'].pop(int(port_id)) - except KeyError: + except KeyError: raise exc.PortNotFound(net_id=net_id, port_id=port_id) def get_interface_details(self, tenant_id, net_id, port_id): @@ -466,7 +444,7 @@ class FakePlugin(object): print("get_interface_details() called\n") port = self._get_port(tenant_id, net_id, port_id) return port['attachment'] - + def plug_interface(self, tenant_id, net_id, port_id, remote_interface_id): """ Attaches a remote interface to the specified port on the @@ -478,10 +456,10 @@ class FakePlugin(object): remote_interface_id) port = self._get_port(tenant_id, net_id, port_id) if port['attachment']: - raise exc.PortInUse(net_id=net_id,port_id=port_id, + raise exc.PortInUse(net_id=net_id, port_id=port_id, att_id=port['attachment']) port['attachment'] = remote_interface_id - + def unplug_interface(self, tenant_id, net_id, port_id): """ Detaches a remote interface from the specified port on the @@ -492,8 +470,8 @@ class FakePlugin(object): # TODO(salvatore-orlando): # Should unplug on port without attachment raise an Error? port['attachment'] = None - - #TODO - neeed to update methods from this point onwards + + # TODO - neeed to update methods from this point onwards def get_all_attached_interfaces(self, tenant_id, net_id): """ Retrieves all remote interfaces that are attached to @@ -501,6 +479,6 @@ class FakePlugin(object): """ print("get_all_attached_interfaces() called\n") # returns a list of all attached remote interfaces - vifs_on_net = ["/tenant1/networks/net_id/portid/vif2.0", "/tenant1/networks/10/121/vif1.1"] + vifs_on_net = ["/tenant1/networks/net_id/portid/vif2.0", + "/tenant1/networks/10/121/vif1.1"] return vifs_on_net - \ No newline at end of file diff --git a/quantum/plugins/__init__.py b/quantum/plugins/__init__.py index df928bbf1c..7e695ff08d 100644 --- a/quantum/plugins/__init__.py +++ b/quantum/plugins/__init__.py @@ -13,4 +13,4 @@ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. -# @author: Somik Behera, Nicira Networks, Inc. \ No newline at end of file +# @author: Somik Behera, Nicira Networks, Inc. diff --git a/quantum/service.py b/quantum/service.py index 193725ef3e..1406462b18 100644 --- a/quantum/service.py +++ b/quantum/service.py @@ -88,7 +88,7 @@ class QuantumApiService(WsgiService): return service -def serve_wsgi(cls, conf=None, options = None, args=None): +def serve_wsgi(cls, conf=None, options=None, args=None): try: service = cls.create(conf, options, args) except Exception: @@ -99,7 +99,7 @@ def serve_wsgi(cls, conf=None, options = None, args=None): return service - + def _run_wsgi(app_name, paste_conf, paste_config_file): LOG.info(_('Using paste.deploy config at: %s'), paste_config_file) app = config.load_paste_app(paste_config_file, app_name) From cc07877e10b241b398db9fcd6e1c9781236b2a12 Mon Sep 17 00:00:00 2001 From: Salvatore Orlando Date: Fri, 10 Jun 2011 15:53:11 +0100 Subject: [PATCH 02/10] Adding support for 'detail' action on networks objects GET /tenants/{tenant-id}/networks/detail returns details about all networks (id,name,number of logical ports) GET /tenants/{tenant-id}/networks/{network-id}/detail return complete details about a specific network, including ports and attachments --- quantum/api/__init__.py | 4 ++++ quantum/api/networks.py | 37 ++++++++++++++++++++++++++--------- quantum/api/views/networks.py | 25 +++++++++++++++++------ quantum/api/views/ports.py | 3 ++- 4 files changed, 53 insertions(+), 16 deletions(-) diff --git a/quantum/api/__init__.py b/quantum/api/__init__.py index e437d27d84..41bc6f5a3d 100644 --- a/quantum/api/__init__.py +++ b/quantum/api/__init__.py @@ -50,6 +50,8 @@ class APIRouterV01(wsgi.Router): uri_prefix = '/tenants/{tenant_id}/' mapper.resource('network', 'networks', controller=networks.Controller(), + collection={'detail': 'GET'}, + member={'detail': 'GET'}, path_prefix=uri_prefix) mapper.resource('port', 'ports', controller=ports.Controller(), @@ -75,3 +77,5 @@ class APIRouterV01(wsgi.Router): controller=ports.Controller(), action="detach_resource", conditions=dict(method=['DELETE'])) + print "MAPPED ROUTES" + print mapper diff --git a/quantum/api/networks.py b/quantum/api/networks.py index 0985dbc856..b959b527bd 100644 --- a/quantum/api/networks.py +++ b/quantum/api/networks.py @@ -36,6 +36,7 @@ class Controller(common.QuantumController): "application/xml": { "attributes": { "network": ["id", "name"], + "port": ["id", "state"], }, }, } @@ -47,25 +48,43 @@ class Controller(common.QuantumController): def index(self, req, tenant_id): """ Returns a list of network ids """ #TODO: this should be for a given tenant!!! - return self._items(req, tenant_id, is_detail=False) + return self._items(req, tenant_id, net_detail=False) - def _items(self, req, tenant_id, is_detail): + def _item(self, req, tenant_id, network_id, + net_details, port_details): + network = self.network_manager.get_network_details( + tenant_id, network_id) + builder = networks_view.get_view_builder(req) + result = builder.build(network, net_details, port_details) + return dict(networks=result) + + def _items(self, req, tenant_id, net_details, port_details): """ Returns a list of networks. """ networks = self.network_manager.get_all_networks(tenant_id) builder = networks_view.get_view_builder(req) - result = [builder.build(network, is_detail)['network'] + result = [builder.build(network, net_details, port_details)['network'] for network in networks] return dict(networks=result) def show(self, req, tenant_id, id): """ Returns network details for the given network id """ try: - network = self.network_manager.get_network_details( - tenant_id, id) - builder = networks_view.get_view_builder(req) - #build response with details - result = builder.build(network, True) - return dict(networks=result) + return self._item(req, tenant_id, id, + net_details=True, port_details=False) + except exception.NetworkNotFound as e: + return faults.Fault(faults.NetworkNotFound(e)) + + def detail(self, req, **kwargs): + tenant_id = kwargs.get('tenant_id') + network_id = kwargs.get('id') + try: + if network_id: + return self._item(req, tenant_id, network_id, + net_details=True, port_details=True) + else: + #do like show but with detaik + return self._items(req, tenant_id, + net_details=True, port_details=False) except exception.NetworkNotFound as e: return faults.Fault(faults.NetworkNotFound(e)) diff --git a/quantum/api/views/networks.py b/quantum/api/views/networks.py index 98c69730e5..8b7657297d 100644 --- a/quantum/api/views/networks.py +++ b/quantum/api/views/networks.py @@ -15,7 +15,7 @@ # License for the specific language governing permissions and limitations # under the License. -import os +from quantum.api.views import ports as ports_view def get_view_builder(req): @@ -31,19 +31,32 @@ class ViewBuilder(object): """ self.base_url = base_url - def build(self, network_data, is_detail=False): + def build(self, network_data, net_detail=False, port_detail=False): """Generic method used to generate a network entity.""" - if is_detail: + if net_detail: network = self._build_detail(network_data) else: network = self._build_simple(network_data) + if port_detail: + builder = ports_view.ViewBuilder(self.base_url) + ports = [builder.build(port_data, port_detail)['port'] + for port_data in network_data['net-ports'].values()] + network['ports'] = ports return network def _build_simple(self, network_data): - """Return a simple model of a server.""" + """Return a simple model of a network.""" return dict(network=dict(id=network_data['net-id'])) def _build_detail(self, network_data): - """Return a simple model of a server.""" + """Return a detailed model of a network.""" return dict(network=dict(id=network_data['net-id'], - name=network_data['net-name'])) + name=network_data['net-name'], + PortCount=len(network_data['net-ports']. + keys()))) + + def _build_port(self, port_data): + """Return details about a specific logical port.""" + return dict(port=dict(id=port_data['port-id'], + state=port_data['port-state'], + attachment=port_data['attachment'])) diff --git a/quantum/api/views/ports.py b/quantum/api/views/ports.py index f72e24dbdc..fba250aa11 100644 --- a/quantum/api/views/ports.py +++ b/quantum/api/views/ports.py @@ -44,4 +44,5 @@ class ViewBuilder(object): def _build_detail(self, port_data): """Return a simple model of a server.""" return dict(port=dict(id=port_data['port-id'], - state=port_data['port-state'])) + state=port_data['port-state'], + attachment=port_data['attachment'])) From fdfa94c8ae23ff4c47dc9b0fd70c033f0f08b960 Mon Sep 17 00:00:00 2001 From: Salvatore Orlando Date: Fri, 24 Jun 2011 14:05:35 +0100 Subject: [PATCH 03/10] no-commit --- quantum/api/__init__.py | 1 + quantum/plugins/openvswitch/README | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/quantum/api/__init__.py b/quantum/api/__init__.py index 3bf7f113ad..00ad619125 100644 --- a/quantum/api/__init__.py +++ b/quantum/api/__init__.py @@ -20,6 +20,7 @@ Quantum API controllers. """ import logging +import pprint import routes import webob.dec import webob.exc diff --git a/quantum/plugins/openvswitch/README b/quantum/plugins/openvswitch/README index 090e53b73d..ef0660c081 100644 --- a/quantum/plugins/openvswitch/README +++ b/quantum/plugins/openvswitch/README @@ -79,7 +79,7 @@ $ /etc/xapi.d/plugins/ovs_quantum_agent.py /etc/xapi.d/plugins/ovs_quantum_plugi # -- Getting quantum up and running - Start quantum [on the quantum service host]: -~/src/quantum-framework$ PYTHONPATH=.:$PYTHONPATH python bin/quantum etc/quantum.conf +~/src/quantum- $ PYTHONPATH=.:$PYTHONPATH python bin/quantum etc/quantum.conf - Run ovs_quantum_plugin.py via the quantum plugin framework cli [on the quantum service host] ~/src/quantum-framework$ PYTHONPATH=.:$PYTHONPATH python quantum/cli.py From 9c6ab1bc280ef0947528c948db7f113cbfa8a1ab Mon Sep 17 00:00:00 2001 From: Salvatore Orlando Date: Fri, 24 Jun 2011 15:21:56 +0100 Subject: [PATCH 04/10] Fixing bug #798261 --- quantum/api/faults.py | 2 +- quantum/api/ports.py | 2 -- quantum/plugins/SamplePlugin.py | 1 + 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/quantum/api/faults.py b/quantum/api/faults.py index 35f6c1073d..ef4d50bc6b 100644 --- a/quantum/api/faults.py +++ b/quantum/api/faults.py @@ -52,7 +52,7 @@ class Fault(webob.exc.HTTPException): fault_name: { 'code': code, 'message': self.wrapped_exc.explanation, - 'detail': self.wrapped_exc.detail}} + 'detail': str(self.wrapped_exc.detail)}} # 'code' is an attribute on the fault tag itself metadata = {'application/xml': {'attributes': {fault_name: 'code'}}} default_xmlns = common.XML_NS_V10 diff --git a/quantum/api/ports.py b/quantum/api/ports.py index 2a066255de..729a7182d0 100644 --- a/quantum/api/ports.py +++ b/quantum/api/ports.py @@ -42,7 +42,6 @@ class Controller(common.QuantumController): "attributes": { "port": ["id", "state"], }, }, } - def __init__(self, plugin_conf_file=None): self._resource_name = 'port' super(Controller, self).__init__() @@ -142,7 +141,6 @@ class Controller(common.QuantumController): except exception.PortNotFound as e: return faults.Fault(faults.PortNotFound(e)) - def attach_resource(self, request, tenant_id, network_id, id): content_type = request.best_match_content_type() print "Content type:%s" % content_type diff --git a/quantum/plugins/SamplePlugin.py b/quantum/plugins/SamplePlugin.py index 32dc823f99..5964beffb9 100644 --- a/quantum/plugins/SamplePlugin.py +++ b/quantum/plugins/SamplePlugin.py @@ -226,6 +226,7 @@ class DummyDataPlugin(object): """ print("unplug_interface() called\n") + class FakePlugin(object): """ FakePlugin is a demo plugin that provides From 1cb59504db2735f6f56892d76b50d64cd45de8b3 Mon Sep 17 00:00:00 2001 From: Salvatore Orlando Date: Mon, 27 Jun 2011 14:09:52 +0100 Subject: [PATCH 05/10] Fixing bug #798262 --- .project | 17 +++++++++ .pydevproject | 10 ++++++ .pydevproject.moved | 10 ++++++ bin/quantum.py | 61 ++++++++++++++++++++++++++++++++ pep8.errors | 49 +++++++++++++++++++++++++ quantum/api/api_common.py | 3 +- quantum/api/networks.py | 6 ++-- quantum/common/wsgi.py | 8 ++--- tests/functional/test_service.py | 6 ++-- 9 files changed, 158 insertions(+), 12 deletions(-) create mode 100644 .project create mode 100644 .pydevproject create mode 100644 .pydevproject.moved create mode 100755 bin/quantum.py create mode 100644 pep8.errors diff --git a/.project b/.project new file mode 100644 index 0000000000..3a156e5bd1 --- /dev/null +++ b/.project @@ -0,0 +1,17 @@ + + + quantum-api + + + + + + org.python.pydev.PyDevBuilder + + + + + + org.python.pydev.pythonNature + + diff --git a/.pydevproject b/.pydevproject new file mode 100644 index 0000000000..024d0515ec --- /dev/null +++ b/.pydevproject @@ -0,0 +1,10 @@ + + + + +python +python 2.7 + +/quantum-api + + diff --git a/.pydevproject.moved b/.pydevproject.moved new file mode 100644 index 0000000000..024d0515ec --- /dev/null +++ b/.pydevproject.moved @@ -0,0 +1,10 @@ + + + + +python +python 2.7 + +/quantum-api + + diff --git a/bin/quantum.py b/bin/quantum.py new file mode 100755 index 0000000000..48abd18ae9 --- /dev/null +++ b/bin/quantum.py @@ -0,0 +1,61 @@ +#!/usr/bin/env python +# vim: tabstop=4 shiftwidth=4 softtabstop=4 + +# Copyright 2011 Nicira Neworks, Inc. +# All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, 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. + +# If ../quantum/__init__.py exists, add ../ to Python search path, so that +# it will override what happens to be installed in /usr/(local/)lib/python... + +import gettext +import optparse +import os +import sys + + +possible_topdir = os.path.normpath(os.path.join(os.path.abspath(sys.argv[0]), + os.pardir, + os.pardir)) +if os.path.exists(os.path.join(possible_topdir, 'quantum', '__init__.py')): + sys.path.insert(0, possible_topdir) + +gettext.install('quantum', unicode=1) + +from quantum import service +from quantum.common import config + + +def create_options(parser): + """ + Sets up the CLI and config-file options that may be + parsed and program commands. + :param parser: The option parser + """ + config.add_common_options(parser) + config.add_log_options(parser) + + +if __name__ == '__main__': + oparser = optparse.OptionParser(version='%%prog VERSION') + create_options(oparser) + (options, args) = config.parse_options(oparser) + + try: + service = service.serve_wsgi(service.QuantumApiService, + options=options, + args=args) + service.wait() + except RuntimeError, e: + sys.exit("ERROR: %s" % e) diff --git a/pep8.errors b/pep8.errors new file mode 100644 index 0000000000..5744ad98e5 --- /dev/null +++ b/pep8.errors @@ -0,0 +1,49 @@ +quantum/cli.py:39:43: W291 trailing whitespace +quantum/cli.py:92:68: W291 trailing whitespace +quantum/cli.py:95:62: W291 trailing whitespace +quantum/cli.py:98:53: W291 trailing whitespace +quantum/cli.py:110:1: W391 blank line at end of file +quantum/manager.py:21:80: E501 line too long (94 characters) +quantum/manager.py:37:22: E231 missing whitespace after ',' +quantum/service.py:91:39: E251 no spaces around keyword / parameter equals +quantum/service.py:102:1: W293 blank line contains whitespace +quantum/api/__init__.py:54:41: W291 trailing whitespace +quantum/api/__init__.py:57:60: E251 no spaces around keyword / parameter equals +quantum/api/faults.py:55:57: W291 trailing whitespace +quantum/api/networks.py:81:48: E231 missing whitespace after ',' +quantum/common/exceptions.py:98:1: E302 expected 2 blank lines, found 1 +quantum/common/exceptions.py:103:1: E302 expected 2 blank lines, found 1 +quantum/plugins/SamplePlugin.py:137:30: W291 trailing whitespace +quantum/plugins/SamplePlugin.py:139:47: E203 whitespace before ',' +quantum/plugins/SamplePlugin.py:184:1: W293 blank line contains whitespace +quantum/plugins/SamplePlugin.py:255:38: W291 trailing whitespace +quantum/plugins/SamplePlugin.py:258:38: W291 trailing whitespace +quantum/plugins/SamplePlugin.py:255:21: E203 whitespace before ':' +quantum/plugins/SamplePlugin.py:259:37: E231 missing whitespace after ':' +quantum/plugins/SamplePlugin.py:263:38: W291 trailing whitespace +quantum/plugins/SamplePlugin.py:266:38: W291 trailing whitespace +quantum/plugins/SamplePlugin.py:269:21: W291 trailing whitespace +quantum/plugins/SamplePlugin.py:263:21: E203 whitespace before ':' +quantum/plugins/SamplePlugin.py:267:37: E231 missing whitespace after ':' +quantum/plugins/SamplePlugin.py:280:46: W291 trailing whitespace +quantum/plugins/SamplePlugin.py:272:29: E231 missing whitespace after ':' +quantum/plugins/SamplePlugin.py:270:14: E225 missing whitespace around operator +quantum/plugins/SamplePlugin.py:284:32: E225 missing whitespace around operator +quantum/plugins/SamplePlugin.py:300:43: E231 missing whitespace after ',' +quantum/plugins/SamplePlugin.py:309:49: E251 no spaces around keyword / parameter equals +quantum/plugins/SamplePlugin.py:318:30: W291 trailing whitespace +quantum/plugins/SamplePlugin.py:338:19: E225 missing whitespace around operator +quantum/plugins/SamplePlugin.py:341:31: E231 missing whitespace after ':' +quantum/plugins/SamplePlugin.py:341:21: E225 missing whitespace around operator +quantum/plugins/SamplePlugin.py:344:41: E225 missing whitespace around operator +quantum/plugins/SamplePlugin.py:373:33: W291 trailing whitespace +quantum/plugins/SamplePlugin.py:373:24: E225 missing whitespace around operator +quantum/plugins/SamplePlugin.py:401:63: W291 trailing whitespace +quantum/plugins/SamplePlugin.py:404:40: E225 missing whitespace around operator +quantum/plugins/SamplePlugin.py:405:35: E231 missing whitespace after ':' +quantum/plugins/SamplePlugin.py:409:29: W291 trailing whitespace +quantum/plugins/SamplePlugin.py:419:20: W291 trailing whitespace +quantum/plugins/SamplePlugin.py:432:46: E231 missing whitespace after ',' +quantum/plugins/SamplePlugin.py:436:25: W291 trailing whitespace +quantum/plugins/SamplePlugin.py:459:46: E231 missing whitespace after ',' +quantum/plugins/SamplePlugin.py:482:80: E501 line too long (99 characters) diff --git a/quantum/api/api_common.py b/quantum/api/api_common.py index df8608df3b..4e01e55bf7 100644 --- a/quantum/api/api_common.py +++ b/quantum/api/api_common.py @@ -58,8 +58,7 @@ class QuantumController(wsgi.Controller): pass if not param_value and param['required']: msg = ("Failed to parse request. " + - "Parameter: %(param_name)s " + - "not specified" % locals()) + "Parameter: " + param_name + " not specified") for line in msg.split('\n'): LOG.error(line) raise exc.HTTPBadRequest(msg) diff --git a/quantum/api/networks.py b/quantum/api/networks.py index bcaef0f9ff..f9f5df4ed8 100644 --- a/quantum/api/networks.py +++ b/quantum/api/networks.py @@ -48,17 +48,17 @@ class Controller(common.QuantumController): def index(self, request, tenant_id): """ Returns a list of network ids """ #TODO: this should be for a given tenant!!! - return self._items(request, tenant_id, net_detail=False) + return self._items(request, tenant_id) def _item(self, req, tenant_id, network_id, - net_details, port_details): + net_details=True, port_details=False): network = self.network_manager.get_network_details( tenant_id, network_id) builder = networks_view.get_view_builder(req) result = builder.build(network, net_details, port_details) return dict(networks=result) - def _items(self, req, tenant_id, net_details, port_details): + def _items(self, req, tenant_id, net_details=False, port_details=False): """ Returns a list of networks. """ networks = self.network_manager.get_all_networks(tenant_id) builder = networks_view.get_view_builder(req) diff --git a/quantum/common/wsgi.py b/quantum/common/wsgi.py index b1d72c4699..dc4ee1c8f2 100644 --- a/quantum/common/wsgi.py +++ b/quantum/common/wsgi.py @@ -20,17 +20,13 @@ Utility methods for working with WSGI servers """ -import json import logging import sys -import datetime from xml.dom import minidom -import eventlet import eventlet.wsgi eventlet.patcher.monkey_patch(all=False, socket=True) -import routes import routes.middleware import webob.dec import webob.exc @@ -423,6 +419,7 @@ class Serializer(object): The string must be in the format of a supported MIME type. """ + LOG.debug("Deserialize invoked:%s", datastring) return self.get_deserialize_handler(content_type)(datastring) def get_deserialize_handler(self, content_type): @@ -455,7 +452,8 @@ class Serializer(object): if len(node.childNodes) == 1 and node.childNodes[0].nodeType == 3: return node.childNodes[0].nodeValue elif node.nodeName in listnames: - return [self._from_xml_node(n, listnames) for n in node.childNodes] + return [self._from_xml_node(n, listnames) + for n in node.childNodes if n.nodeType != node.TEXT_NODE] else: result = dict() for attr in node.attributes.keys(): diff --git a/tests/functional/test_service.py b/tests/functional/test_service.py index 6ed728394a..29d23cf3fd 100644 --- a/tests/functional/test_service.py +++ b/tests/functional/test_service.py @@ -49,7 +49,8 @@ def print_response(res): class QuantumTest(unittest.TestCase): def setUp(self): self.client = MiniClient(HOST, PORT, USE_SSL) - + + def create_network(self, data): content_type = "application/" + FORMAT body = Serializer().serialize(data, content_type) @@ -128,7 +129,8 @@ class QuantumTest(unittest.TestCase): self.assertEqual(res.status, 202) def tearDown(self): - self.delete_networks() + pass + #self.delete_networks() # Standard boilerplate to call the main() function. if __name__ == '__main__': From 81f9170ad5e93b331d90b1273fdc801e4bb3dff5 Mon Sep 17 00:00:00 2001 From: Salvatore Orlando Date: Tue, 28 Jun 2011 10:29:08 +0100 Subject: [PATCH 06/10] Addressing comments from Somik --- .pydevproject | 10 ------ .pydevproject.moved | 10 ------ pep8.errors | 49 ------------------------------ quantum/api/ports.py | 4 +-- quantum/common/wsgi.py | 3 -- quantum/plugins/SamplePlugin.py | 38 ++--------------------- quantum/plugins/openvswitch/README | 4 +-- tests/functional/test_service.py | 3 +- 8 files changed, 7 insertions(+), 114 deletions(-) delete mode 100644 .pydevproject delete mode 100644 .pydevproject.moved delete mode 100644 pep8.errors diff --git a/.pydevproject b/.pydevproject deleted file mode 100644 index 024d0515ec..0000000000 --- a/.pydevproject +++ /dev/null @@ -1,10 +0,0 @@ - - - - -python -python 2.7 - -/quantum-api - - diff --git a/.pydevproject.moved b/.pydevproject.moved deleted file mode 100644 index 024d0515ec..0000000000 --- a/.pydevproject.moved +++ /dev/null @@ -1,10 +0,0 @@ - - - - -python -python 2.7 - -/quantum-api - - diff --git a/pep8.errors b/pep8.errors deleted file mode 100644 index 5744ad98e5..0000000000 --- a/pep8.errors +++ /dev/null @@ -1,49 +0,0 @@ -quantum/cli.py:39:43: W291 trailing whitespace -quantum/cli.py:92:68: W291 trailing whitespace -quantum/cli.py:95:62: W291 trailing whitespace -quantum/cli.py:98:53: W291 trailing whitespace -quantum/cli.py:110:1: W391 blank line at end of file -quantum/manager.py:21:80: E501 line too long (94 characters) -quantum/manager.py:37:22: E231 missing whitespace after ',' -quantum/service.py:91:39: E251 no spaces around keyword / parameter equals -quantum/service.py:102:1: W293 blank line contains whitespace -quantum/api/__init__.py:54:41: W291 trailing whitespace -quantum/api/__init__.py:57:60: E251 no spaces around keyword / parameter equals -quantum/api/faults.py:55:57: W291 trailing whitespace -quantum/api/networks.py:81:48: E231 missing whitespace after ',' -quantum/common/exceptions.py:98:1: E302 expected 2 blank lines, found 1 -quantum/common/exceptions.py:103:1: E302 expected 2 blank lines, found 1 -quantum/plugins/SamplePlugin.py:137:30: W291 trailing whitespace -quantum/plugins/SamplePlugin.py:139:47: E203 whitespace before ',' -quantum/plugins/SamplePlugin.py:184:1: W293 blank line contains whitespace -quantum/plugins/SamplePlugin.py:255:38: W291 trailing whitespace -quantum/plugins/SamplePlugin.py:258:38: W291 trailing whitespace -quantum/plugins/SamplePlugin.py:255:21: E203 whitespace before ':' -quantum/plugins/SamplePlugin.py:259:37: E231 missing whitespace after ':' -quantum/plugins/SamplePlugin.py:263:38: W291 trailing whitespace -quantum/plugins/SamplePlugin.py:266:38: W291 trailing whitespace -quantum/plugins/SamplePlugin.py:269:21: W291 trailing whitespace -quantum/plugins/SamplePlugin.py:263:21: E203 whitespace before ':' -quantum/plugins/SamplePlugin.py:267:37: E231 missing whitespace after ':' -quantum/plugins/SamplePlugin.py:280:46: W291 trailing whitespace -quantum/plugins/SamplePlugin.py:272:29: E231 missing whitespace after ':' -quantum/plugins/SamplePlugin.py:270:14: E225 missing whitespace around operator -quantum/plugins/SamplePlugin.py:284:32: E225 missing whitespace around operator -quantum/plugins/SamplePlugin.py:300:43: E231 missing whitespace after ',' -quantum/plugins/SamplePlugin.py:309:49: E251 no spaces around keyword / parameter equals -quantum/plugins/SamplePlugin.py:318:30: W291 trailing whitespace -quantum/plugins/SamplePlugin.py:338:19: E225 missing whitespace around operator -quantum/plugins/SamplePlugin.py:341:31: E231 missing whitespace after ':' -quantum/plugins/SamplePlugin.py:341:21: E225 missing whitespace around operator -quantum/plugins/SamplePlugin.py:344:41: E225 missing whitespace around operator -quantum/plugins/SamplePlugin.py:373:33: W291 trailing whitespace -quantum/plugins/SamplePlugin.py:373:24: E225 missing whitespace around operator -quantum/plugins/SamplePlugin.py:401:63: W291 trailing whitespace -quantum/plugins/SamplePlugin.py:404:40: E225 missing whitespace around operator -quantum/plugins/SamplePlugin.py:405:35: E231 missing whitespace after ':' -quantum/plugins/SamplePlugin.py:409:29: W291 trailing whitespace -quantum/plugins/SamplePlugin.py:419:20: W291 trailing whitespace -quantum/plugins/SamplePlugin.py:432:46: E231 missing whitespace after ',' -quantum/plugins/SamplePlugin.py:436:25: W291 trailing whitespace -quantum/plugins/SamplePlugin.py:459:46: E231 missing whitespace after ',' -quantum/plugins/SamplePlugin.py:482:80: E501 line too long (99 characters) diff --git a/quantum/api/ports.py b/quantum/api/ports.py index 729a7182d0..b92f33e9ef 100644 --- a/quantum/api/ports.py +++ b/quantum/api/ports.py @@ -133,8 +133,8 @@ class Controller(common.QuantumController): def get_resource(self, request, tenant_id, network_id, id): try: - result = self.network_manager.get_interface_details( - tenant_id, network_id, id) + result = self.network_manager.get_port_details( + tenant_id, network_id, id).get('attachment', None) return dict(attachment=result) except exception.NetworkNotFound as e: return faults.Fault(faults.NetworkNotFound(e)) diff --git a/quantum/common/wsgi.py b/quantum/common/wsgi.py index dc4ee1c8f2..6edaf731ec 100644 --- a/quantum/common/wsgi.py +++ b/quantum/common/wsgi.py @@ -294,7 +294,6 @@ class Router(object): Route the incoming request to a controller based on self.map. If no match, return a 404. """ - LOG.debug("HERE - wsgi.Router.__call__") return self._router @staticmethod @@ -328,7 +327,6 @@ class Controller(object): """ Call the method specified in req.environ by RoutesMiddleware. """ - LOG.debug("HERE - wsgi.Controller.__call__") arg_dict = req.environ['wsgiorg.routing_args'][1] action = arg_dict['action'] method = getattr(self, action) @@ -419,7 +417,6 @@ class Serializer(object): The string must be in the format of a supported MIME type. """ - LOG.debug("Deserialize invoked:%s", datastring) return self.get_deserialize_handler(content_type)(datastring) def get_deserialize_handler(self, content_type): diff --git a/quantum/plugins/SamplePlugin.py b/quantum/plugins/SamplePlugin.py index 5964beffb9..1f7c9f8dd4 100644 --- a/quantum/plugins/SamplePlugin.py +++ b/quantum/plugins/SamplePlugin.py @@ -113,20 +113,6 @@ class QuantumEchoPlugin(object): """ print("unplug_interface() called\n") - def get_interface_details(self, tenant_id, net_id, port_id): - """ - Retrieves the remote interface that is attached at this - particular port. - """ - print("get_interface_details() called\n") - - def get_all_attached_interfaces(self, tenant_id, net_id): - """ - Retrieves all remote interfaces that are attached to - a particular Virtual Network. - """ - print("get_all_attached_interfaces() called\n") - class DummyDataPlugin(object): @@ -240,11 +226,11 @@ class FakePlugin(object): 'port-state': 'DOWN', 'attachment': None}, 2: {'port-id': 2, - 'port-state': 'UP', + 'port-state': 'ACTIVE', 'attachment': None}} _port_dict_2 = { 1: {'port-id': 1, - 'port-state': 'UP', + 'port-state': 'ACTIVE', 'attachment': 'SomeFormOfVIFID'}, 2: {'port-id': 2, 'port-state': 'DOWN', @@ -418,15 +404,6 @@ class FakePlugin(object): except KeyError: raise exc.PortNotFound(net_id=net_id, port_id=port_id) - def get_interface_details(self, tenant_id, net_id, port_id): - """ - Retrieves the remote interface that is attached at this - particular port. - """ - print("get_interface_details() called\n") - port = self._get_port(tenant_id, net_id, port_id) - return port['attachment'] - def plug_interface(self, tenant_id, net_id, port_id, remote_interface_id): """ Attaches a remote interface to the specified port on the @@ -452,14 +429,3 @@ class FakePlugin(object): # TODO(salvatore-orlando): # Should unplug on port without attachment raise an Error? port['attachment'] = None - - def get_all_attached_interfaces(self, tenant_id, net_id): - """ - Retrieves all remote interfaces that are attached to - a particular Virtual Network. - """ - print("get_all_attached_interfaces() called\n") - # returns a list of all attached remote interfaces - vifs_on_net = ["/tenant1/networks/net_id/portid/vif2.0", - "/tenant1/networks/10/121/vif1.1"] - return vifs_on_net diff --git a/quantum/plugins/openvswitch/README b/quantum/plugins/openvswitch/README index ef0660c081..b44a596724 100644 --- a/quantum/plugins/openvswitch/README +++ b/quantum/plugins/openvswitch/README @@ -79,10 +79,10 @@ $ /etc/xapi.d/plugins/ovs_quantum_agent.py /etc/xapi.d/plugins/ovs_quantum_plugi # -- Getting quantum up and running - Start quantum [on the quantum service host]: -~/src/quantum- $ PYTHONPATH=.:$PYTHONPATH python bin/quantum etc/quantum.conf +~/src/quantum $ PYTHONPATH=.:$PYTHONPATH python bin/quantum etc/quantum.conf - Run ovs_quantum_plugin.py via the quantum plugin framework cli [on the quantum service host] -~/src/quantum-framework$ PYTHONPATH=.:$PYTHONPATH python quantum/cli.py +~/src/quantum$ PYTHONPATH=.:$PYTHONPATH python quantum/cli.py This will show help all of the available commands. diff --git a/tests/functional/test_service.py b/tests/functional/test_service.py index 29d23cf3fd..ba4f61416b 100644 --- a/tests/functional/test_service.py +++ b/tests/functional/test_service.py @@ -49,8 +49,7 @@ def print_response(res): class QuantumTest(unittest.TestCase): def setUp(self): self.client = MiniClient(HOST, PORT, USE_SSL) - - + def create_network(self, data): content_type = "application/" + FORMAT body = Serializer().serialize(data, content_type) From be45ced09cda21a1e2164f47e1d2b1d99385000d Mon Sep 17 00:00:00 2001 From: Salvatore Orlando Date: Thu, 21 Jul 2011 16:54:23 +0100 Subject: [PATCH 07/10] doh --- .project | 17 ----------------- 1 file changed, 17 deletions(-) delete mode 100644 .project diff --git a/.project b/.project deleted file mode 100644 index 3a156e5bd1..0000000000 --- a/.project +++ /dev/null @@ -1,17 +0,0 @@ - - - quantum-api - - - - - - org.python.pydev.PyDevBuilder - - - - - - org.python.pydev.pythonNature - - From 49344b17c44e62a20deca4b2015d12183adf3fd8 Mon Sep 17 00:00:00 2001 From: Salvatore Orlando Date: Fri, 22 Jul 2011 10:51:22 +0100 Subject: [PATCH 08/10] Re-fixing issues with XML deserialization (changes got lost in merges with trunk) Adapting assertions in unit tests merged from trunk to reflect changes in the API due to RFE requested by Erik Carlin --- quantum/api/__init__.py | 2 -- quantum/api/networks.py | 12 ++++--- quantum/api/ports.py | 9 +++-- quantum/api/views/networks.py | 6 ++-- quantum/api/views/ports.py | 7 ++-- quantum/plugins/SamplePlugin.py | 5 ++- tests/unit/test_api.py | 59 +++++++++++++++++++-------------- 7 files changed, 59 insertions(+), 41 deletions(-) diff --git a/quantum/api/__init__.py b/quantum/api/__init__.py index c5cac4bf74..9933bfdbee 100644 --- a/quantum/api/__init__.py +++ b/quantum/api/__init__.py @@ -79,5 +79,3 @@ class APIRouterV01(wsgi.Router): controller=ports.Controller(plugin), action="detach_resource", conditions=dict(method=['DELETE'])) - print "MAPPED ROUTES" - print mapper diff --git a/quantum/api/networks.py b/quantum/api/networks.py index 2a56d6bc64..9afc09c24e 100644 --- a/quantum/api/networks.py +++ b/quantum/api/networks.py @@ -38,6 +38,7 @@ class Controller(common.QuantumController): "network": ["id", "name"], "port": ["id", "state"], }, + "plurals": {"networks": "network"} }, } @@ -52,11 +53,13 @@ class Controller(common.QuantumController): def _item(self, req, tenant_id, network_id, net_details=True, port_details=False): - network = self.network_manager.get_network_details( + # We expect get_network_details to return information + # concerning logical ports as well. + network = self._plugin.get_network_details( tenant_id, network_id) builder = networks_view.get_view_builder(req) - result = builder.build(network, net_details, port_details) - return dict(networks=result) + result = builder.build(network, net_details, port_details)['network'] + return dict(network=result) def _items(self, req, tenant_id, net_details=False, port_details=False): """ Returns a list of networks. """ @@ -79,10 +82,11 @@ class Controller(common.QuantumController): network_id = kwargs.get('id') try: if network_id: + # show details for a given network return self._item(request, tenant_id, network_id, net_details=True, port_details=True) else: - #do like show but with detaik + # show details for all networks return self._items(request, tenant_id, net_details=True, port_details=False) network = self._plugin.get_network_details( diff --git a/quantum/api/ports.py b/quantum/api/ports.py index ebe9ab843f..042ea673c3 100644 --- a/quantum/api/ports.py +++ b/quantum/api/ports.py @@ -40,7 +40,10 @@ class Controller(common.QuantumController): _serialization_metadata = { "application/xml": { "attributes": { - "port": ["id", "state"], }, }, } + "port": ["id", "state"], }, + "plurals": {"ports": "port"} + }, + } def __init__(self, plugin): self._resource_name = 'port' @@ -68,8 +71,8 @@ class Controller(common.QuantumController): tenant_id, network_id, id) builder = ports_view.get_view_builder(request) #build response with details - result = builder.build(port, True) - return dict(ports=result) + result = builder.build(port, True)['port'] + return dict(port=result) except exception.NetworkNotFound as e: return faults.Fault(faults.NetworkNotFound(e)) except exception.PortNotFound as e: diff --git a/quantum/api/views/networks.py b/quantum/api/views/networks.py index 8b7657297d..2242e00f79 100644 --- a/quantum/api/views/networks.py +++ b/quantum/api/views/networks.py @@ -50,10 +50,12 @@ class ViewBuilder(object): def _build_detail(self, network_data): """Return a detailed model of a network.""" + # net-ports might not be present in response from plugin + ports = network_data.get('net-ports', None) + portcount = ports and len(ports) or 0 return dict(network=dict(id=network_data['net-id'], name=network_data['net-name'], - PortCount=len(network_data['net-ports']. - keys()))) + PortCount=portcount)) def _build_port(self, port_data): """Return details about a specific logical port.""" diff --git a/quantum/api/views/ports.py b/quantum/api/views/ports.py index fba250aa11..b743888ce3 100644 --- a/quantum/api/views/ports.py +++ b/quantum/api/views/ports.py @@ -38,11 +38,10 @@ class ViewBuilder(object): return port def _build_simple(self, port_data): - """Return a simple model of a server.""" + """Return a simple model of a port.""" return dict(port=dict(id=port_data['port-id'])) def _build_detail(self, port_data): - """Return a simple model of a server.""" + """Return a simple model of a port (with its state).""" return dict(port=dict(id=port_data['port-id'], - state=port_data['port-state'], - attachment=port_data['attachment'])) + state=port_data['port-state'])) diff --git a/quantum/plugins/SamplePlugin.py b/quantum/plugins/SamplePlugin.py index 46576389ca..34573d2fe5 100644 --- a/quantum/plugins/SamplePlugin.py +++ b/quantum/plugins/SamplePlugin.py @@ -283,8 +283,11 @@ class FakePlugin(object): """ LOG.debug("FakePlugin.get_network_details() called") net = self._get_network(tenant_id, net_id) + # Retrieves ports for network + ports = self.get_all_ports(tenant_id, net_id) return {'net-id': str(net.uuid), - 'net-name': net.name} + 'net-name': net.name, + 'net-ports': ports} def create_network(self, tenant_id, net_name): """ diff --git a/tests/unit/test_api.py b/tests/unit/test_api.py index c09af76990..74b2227eea 100644 --- a/tests/unit/test_api.py +++ b/tests/unit/test_api.py @@ -75,7 +75,7 @@ class APITest(unittest.TestCase): network_data = Serializer().deserialize(show_network_res.body, content_type) self.assertEqual(network_id, - network_data['networks']['network']['id']) + network_data['network']['id']) LOG.debug("_test_create_network - format:%s - END", format) def _test_create_network_badrequest(self, format): @@ -96,8 +96,8 @@ class APITest(unittest.TestCase): format) list_network_res = list_network_req.get_response(self.api) self.assertEqual(list_network_res.status_int, 200) - network_data = Serializer().deserialize(list_network_res.body, - content_type) + network_data = self._net_serializer.deserialize( + list_network_res.body, content_type) # Check network count: should return 2 self.assertEqual(len(network_data['networks']), 2) LOG.debug("_test_list_networks - format:%s - END", format) @@ -111,10 +111,12 @@ class APITest(unittest.TestCase): format) show_network_res = show_network_req.get_response(self.api) self.assertEqual(show_network_res.status_int, 200) - network_data = Serializer().deserialize(show_network_res.body, - content_type) - self.assertEqual({'id': network_id, 'name': self.network_name}, - network_data['networks']['network']) + network_data = self._net_serializer.deserialize( + show_network_res.body, content_type) + self.assertEqual({'id': network_id, + 'name': self.network_name, + 'PortCount': 0}, + network_data['network']) LOG.debug("_test_show_network - format:%s - END", format) def _test_show_network_not_found(self, format): @@ -142,10 +144,12 @@ class APITest(unittest.TestCase): format) show_network_res = show_network_req.get_response(self.api) self.assertEqual(show_network_res.status_int, 200) - network_data = Serializer().deserialize(show_network_res.body, - content_type) - self.assertEqual({'id': network_id, 'name': new_name}, - network_data['networks']['network']) + network_data = self._net_serializer.deserialize( + show_network_res.body, content_type) + self.assertEqual({'id': network_id, + 'name': new_name, + 'PortCount': 0}, + network_data['network']) LOG.debug("_test_rename_network - format:%s - END", format) def _test_rename_network_badrequest(self, format): @@ -189,8 +193,8 @@ class APITest(unittest.TestCase): list_network_req = testlib.network_list_request(self.tenant_id, format) list_network_res = list_network_req.get_response(self.api) - network_list_data = Serializer().deserialize(list_network_res.body, - content_type) + network_list_data = self._net_serializer.deserialize( + list_network_res.body, content_type) network_count = len(network_list_data['networks']) self.assertEqual(network_count, 0) LOG.debug("_test_delete_network - format:%s - END", format) @@ -233,8 +237,8 @@ class APITest(unittest.TestCase): network_id, format) list_port_res = list_port_req.get_response(self.api) self.assertEqual(list_port_res.status_int, 200) - port_data = Serializer().deserialize(list_port_res.body, - content_type) + port_data = self._port_serializer.deserialize( + list_port_res.body, content_type) # Check port count: should return 2 self.assertEqual(len(port_data['ports']), 2) LOG.debug("_test_list_ports - format:%s - END", format) @@ -250,10 +254,10 @@ class APITest(unittest.TestCase): format) show_port_res = show_port_req.get_response(self.api) self.assertEqual(show_port_res.status_int, 200) - port_data = Serializer().deserialize(show_port_res.body, - content_type) + port_data = self._port_serializer.deserialize( + show_port_res.body, content_type) self.assertEqual({'id': port_id, 'state': port_state}, - port_data['ports']['port']) + port_data['port']) LOG.debug("_test_show_port - format:%s - END", format) def _test_show_port_networknotfound(self, format): @@ -291,8 +295,9 @@ class APITest(unittest.TestCase): network_id, port_id, format) show_port_res = show_port_req.get_response(self.api) self.assertEqual(show_port_res.status_int, 200) - port_data = Serializer().deserialize(show_port_res.body, content_type) - self.assertEqual(port_id, port_data['ports']['port']['id']) + port_data = self._port_serializer.deserialize( + show_port_res.body, content_type) + self.assertEqual(port_id, port_data['port']['id']) LOG.debug("_test_create_port - format:%s - END", format) def _test_create_port_networknotfound(self, format): @@ -329,8 +334,8 @@ class APITest(unittest.TestCase): list_port_req = testlib.port_list_request(self.tenant_id, network_id, format) list_port_res = list_port_req.get_response(self.api) - port_list_data = Serializer().deserialize(list_port_res.body, - content_type) + port_list_data = self._port_serializer.deserialize( + list_port_res.body, content_type) port_count = len(port_list_data['ports']) self.assertEqual(port_count, 0) LOG.debug("_test_delete_port - format:%s - END", format) @@ -405,10 +410,10 @@ class APITest(unittest.TestCase): format) show_port_res = show_port_req.get_response(self.api) self.assertEqual(show_port_res.status_int, 200) - network_data = Serializer().deserialize(show_port_res.body, - content_type) + port_data = self._port_serializer.deserialize( + show_port_res.body, content_type) self.assertEqual({'id': port_id, 'state': new_port_state}, - network_data['ports']['port']) + port_data['port']) LOG.debug("_test_set_port_state - format:%s - END", format) def _test_set_port_state_networknotfound(self, format): @@ -620,6 +625,10 @@ class APITest(unittest.TestCase): self.api = server.APIRouterV01(options) self.tenant_id = "test_tenant" self.network_name = "test_network" + self._net_serializer = \ + Serializer(server.networks.Controller._serialization_metadata) + self._port_serializer = \ + Serializer(server.ports.Controller._serialization_metadata) def tearDown(self): """Clear the test environment""" From afa6cf95164121edb9be65fab83536f21deccdb8 Mon Sep 17 00:00:00 2001 From: Salvatore Orlando Date: Fri, 29 Jul 2011 22:22:59 +0100 Subject: [PATCH 09/10] Removing extra quantum.py file from source control removing unused import from quantum/api/__init__.py --- quantum/api/__init__.py | 1 - 1 file changed, 1 deletion(-) diff --git a/quantum/api/__init__.py b/quantum/api/__init__.py index 9933bfdbee..619de63a97 100644 --- a/quantum/api/__init__.py +++ b/quantum/api/__init__.py @@ -20,7 +20,6 @@ Quantum API controllers. """ import logging -import pprint import routes import webob.dec import webob.exc From 94cd9b03735abccf0080cfd6a57e1685c8dbe319 Mon Sep 17 00:00:00 2001 From: Dan Wendlandt Date: Fri, 29 Jul 2011 22:20:52 -0700 Subject: [PATCH 10/10] fix bug 817826 and similar error in batch_config.py --- quantum/cli.py | 4 ++-- tools/batch_config.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/quantum/cli.py b/quantum/cli.py index 02bafbd09d..0f6a0c27e0 100644 --- a/quantum/cli.py +++ b/quantum/cli.py @@ -114,7 +114,7 @@ def create_net(manager, *args): def api_create_net(client, *args): tid, name = args - data = {'network': {'network-name': '%s' % name}} + data = {'network': {'net-name': '%s' % name}} body = Serializer().serialize(data, CONTENT_TYPE) res = client.do_request(tid, 'POST', "/networks." + FORMAT, body=body) rd = json.loads(res.read()) @@ -185,7 +185,7 @@ def rename_net(manager, *args): def api_rename_net(client, *args): tid, nid, name = args - data = {'network': {'network-name': '%s' % name}} + data = {'network': {'net-name': '%s' % name}} body = Serializer().serialize(data, CONTENT_TYPE) res = client.do_request(tid, 'PUT', "/networks/%s.%s" % (nid, FORMAT), body=body) diff --git a/tools/batch_config.py b/tools/batch_config.py index 63f4a5223d..8415513d01 100644 --- a/tools/batch_config.py +++ b/tools/batch_config.py @@ -84,7 +84,7 @@ def delete_all_nets(client, tenant_id): def create_net_with_attachments(net_name, iface_ids): - data = {'network': {'network-name': '%s' % net_name}} + data = {'network': {'net-name': '%s' % net_name}} body = Serializer().serialize(data, CONTENT_TYPE) res = client.do_request(tenant_id, 'POST', "/networks." + FORMAT, body=body)