From 1e166f3efd72459fabe83e2141461329c67c811a Mon Sep 17 00:00:00 2001 From: Sergey Skripnick Date: Mon, 29 Apr 2013 16:46:51 +0300 Subject: [PATCH] Docstrings formatted according to pep257 Bug #1020184 quantum/plugins/bigswitch/* quantum/plugins/brocade/* Change-Id: I9bf4381738319551a5993d4b279a5cec3425b7ef --- quantum/plugins/bigswitch/plugin.py | 36 ++++++++++++------- .../plugins/bigswitch/tests/test_server.py | 13 ++++--- quantum/plugins/brocade/QuantumPlugin.py | 30 ++++++++-------- quantum/plugins/brocade/db/models.py | 5 ++- quantum/plugins/brocade/nos/fake_nosdriver.py | 7 ++-- quantum/plugins/brocade/nos/nctemplates.py | 5 +-- quantum/plugins/brocade/nos/nosdriver.py | 9 ++--- quantum/plugins/brocade/tests/noscli.py | 5 ++- quantum/plugins/brocade/tests/nostest.py | 4 +-- quantum/plugins/brocade/vlanbm.py | 12 +++---- 10 files changed, 66 insertions(+), 60 deletions(-) diff --git a/quantum/plugins/bigswitch/plugin.py b/quantum/plugins/bigswitch/plugin.py index 16a66bf64b..7f608b9849 100644 --- a/quantum/plugins/bigswitch/plugin.py +++ b/quantum/plugins/bigswitch/plugin.py @@ -18,7 +18,7 @@ # @author: Sumit Naiksatam, sumitnaiksatam@gmail.com, Big Switch Networks, Inc. """ -Quantum REST Proxy Plug-in for Big Switch and FloodLight Controllers +Quantum REST Proxy Plug-in for Big Switch and FloodLight Controllers. QuantumRestProxy provides a generic quantum plugin that translates all plugin function calls to equivalent authenticated REST calls to a set of redundant @@ -119,6 +119,7 @@ METADATA_SERVER_IP = '169.254.169.254' class RemoteRestError(exceptions.QuantumException): + def __init__(self, message): if message is None: message = "None" @@ -208,6 +209,7 @@ class ServerProxy(object): class ServerPool(object): + def __init__(self, servers, ssl, auth, quantum_id, timeout=10, base_uri='/quantum/v1.0', name='QuantumRestProxy'): self.base_uri = base_uri @@ -226,6 +228,7 @@ class ServerPool(object): def server_failure(self, resp): """Define failure codes as required. + Note: We assume 301-303 is a failure, and try the next server in the server pool. """ @@ -233,6 +236,7 @@ class ServerPool(object): def action_success(self, resp): """Defining success codes as required. + Note: We assume any valid 2xx as being successful response. """ return resp[0] in SUCCESS_CODES @@ -335,8 +339,11 @@ class QuantumRestProxyV2(db_base_plugin_v2.QuantumDbPluginV2, LOG.debug(_("QuantumRestProxyV2: initialization done")) def create_network(self, context, network): - """Create a network, which represents an L2 network segment which - can have a set of subnets and ports associated with it. + """Create a network. + + Network represents an L2 network segment which can have a set of + subnets and ports associated with it. + :param context: quantum api request context :param network: dictionary describing the network @@ -355,7 +362,6 @@ class QuantumRestProxyV2(db_base_plugin_v2.QuantumDbPluginV2, :raises: RemoteRestError """ - LOG.debug(_("QuantumRestProxyV2: create_network() called")) self._warn_on_state_status(network['network']) @@ -393,6 +399,7 @@ class QuantumRestProxyV2(db_base_plugin_v2.QuantumDbPluginV2, def update_network(self, context, net_id, network): """Updates the properties of a particular Virtual Network. + :param context: quantum api request context :param net_id: uuid of the network to update :param network: dictionary describing the updates @@ -413,7 +420,6 @@ class QuantumRestProxyV2(db_base_plugin_v2.QuantumDbPluginV2, :raises: exceptions.NetworkNotFound :raises: RemoteRestError """ - LOG.debug(_("QuantumRestProxyV2.update_network() called")) self._warn_on_state_status(network['network']) @@ -571,6 +577,7 @@ class QuantumRestProxyV2(db_base_plugin_v2.QuantumDbPluginV2, def update_port(self, context, port_id, port): """Update values of a port. + :param context: quantum api request context :param id: UUID representing the port to update. :param port: dictionary with keys indicating fields to update. @@ -640,6 +647,7 @@ class QuantumRestProxyV2(db_base_plugin_v2.QuantumDbPluginV2, def delete_port(self, context, port_id, l3_port_check=True): """Delete a port. + :param context: quantum api request context :param id: UUID representing the port to delete. @@ -648,7 +656,6 @@ class QuantumRestProxyV2(db_base_plugin_v2.QuantumDbPluginV2, :raises: exceptions.NetworkNotFound :raises: RemoteRestError """ - LOG.debug(_("QuantumRestProxyV2: delete_port() called")) # if needed, check to see if this is a port owned by @@ -684,8 +691,10 @@ class QuantumRestProxyV2(db_base_plugin_v2.QuantumDbPluginV2, def _plug_interface(self, context, tenant_id, net_id, port_id, remote_interface_id): - """Attaches a remote interface to the specified port on the - specified Virtual Network. + """Plug remote interface to the network. + + Attaches a remote interface to the specified port on the specified + Virtual Network. :returns: None @@ -716,8 +725,10 @@ class QuantumRestProxyV2(db_base_plugin_v2.QuantumDbPluginV2, raise def _unplug_interface(self, context, tenant_id, net_id, port_id): - """Detaches a remote interface from the specified port on the - network controller + """Detach interface from the network controller. + + Detaches a remote interface from the specified port on the network + controller. :returns: None @@ -1042,8 +1053,9 @@ class QuantumRestProxyV2(db_base_plugin_v2.QuantumDbPluginV2, raise def _send_all_data(self): - """Pushes all data to network ctrl (networks/ports, ports/attachments) - to give the controller an option to re-sync it's persistent store + """Pushes all data to network ctrl (networks/ports, ports/attachments). + + This gives the controller an option to re-sync it's persistent store with quantum's current view of that data. """ admin_context = qcontext.get_admin_context() diff --git a/quantum/plugins/bigswitch/tests/test_server.py b/quantum/plugins/bigswitch/tests/test_server.py index 5b38dcb2a4..ee7cb8f9a0 100755 --- a/quantum/plugins/bigswitch/tests/test_server.py +++ b/quantum/plugins/bigswitch/tests/test_server.py @@ -18,8 +18,9 @@ # # @author: Mandeep Dhami, Big Switch Networks, Inc. -""" -Test server mocking a REST based network ctrl. Used for QuantumRestProxy tests +"""Test server mocking a REST based network ctrl. + +Used for QuantumRestProxy tests """ import json @@ -29,6 +30,7 @@ from wsgiref.simple_server import make_server class TestNetworkCtrl(object): + def __init__(self, host='', port=8000, default_status='404 Not Found', default_response='404 Not Found', @@ -44,9 +46,10 @@ class TestNetworkCtrl(object): def match(self, prior, method_regexp, uri_regexp, handler, data=None, multi=True): - """Adds to the list of exptected inputs. The incomming request is - matched in the order of priority. For same priority, match the - oldest match request first. + """Add to the list of exptected inputs. + + The incoming request is matched in the order of priority. For same + priority, match the oldest match request first. :param prior: intgere priority of this match (e.g. 100) :param method_regexp: regexp to match method (e.g. 'PUT|POST') diff --git a/quantum/plugins/brocade/QuantumPlugin.py b/quantum/plugins/brocade/QuantumPlugin.py index ee097f3a0b..f24aa622a0 100644 --- a/quantum/plugins/brocade/QuantumPlugin.py +++ b/quantum/plugins/brocade/QuantumPlugin.py @@ -23,9 +23,7 @@ # TODO(shiv) need support for security groups -""" -Implentation of Brocade Quantum Plugin. -""" +"""Implentation of Brocade Quantum Plugin.""" from oslo.config import cfg @@ -86,11 +84,11 @@ class BridgeRpcCallbacks(dhcp_rpc_base.DhcpRpcCallbackMixin, TAP_PREFIX_LEN = 3 def create_rpc_dispatcher(self): - '''Get the rpc dispatcher for this manager. + """Get the rpc dispatcher for this manager. If a manager would like to set an rpc API version, or support more than one class as the target of rpc messages, override this method. - ''' + """ return q_rpc.PluginRpcDispatcher([self, agents_db.AgentExtRpcCallback()]) @@ -161,12 +159,12 @@ class BridgeRpcCallbacks(dhcp_rpc_base.DhcpRpcCallbackMixin, class AgentNotifierApi(proxy.RpcProxy, sg_rpc.SecurityGroupAgentRpcApiMixin): - '''Agent side of the linux bridge rpc API. + """Agent side of the linux bridge rpc API. API version history: 1.0 - Initial version. - ''' + """ BASE_RPC_API_VERSION = '1.0' @@ -207,8 +205,9 @@ class BrocadePluginV2(db_base_plugin_v2.QuantumDbPluginV2, """ def __init__(self): - """Initialize Brocade Plugin, specify switch address - and db configuration. + """Initialize Brocade Plugin. + + Specify switch address and db configuration. """ self.supported_extension_aliases = ["binding", "security-group", @@ -255,8 +254,10 @@ class BrocadePluginV2(db_base_plugin_v2.QuantumDbPluginV2, self.l3_agent_notifier = l3_rpc_agent_api.L3AgentNotify def create_network(self, context, network): - """This call to create network translates to creation of - port-profile on the physical switch. + """Create network. + + This call to create network translates to creation of port-profile on + the physical switch. """ with context.session.begin(subtransactions=True): @@ -284,8 +285,10 @@ class BrocadePluginV2(db_base_plugin_v2.QuantumDbPluginV2, return net def delete_network(self, context, net_id): - """This call to delete the network translates to removing - the port-profile on the physical switch. + """Delete network. + + This call to delete the network translates to removing the + port-profile on the physical switch. """ with context.session.begin(subtransactions=True): @@ -460,7 +463,6 @@ class BrocadePluginV2(db_base_plugin_v2.QuantumDbPluginV2, :type interface_mac: string :returns: MAC address in the format xxxx.xxxx.xxxx :rtype: string - """ mac = interface_mac.replace(":", "") diff --git a/quantum/plugins/brocade/db/models.py b/quantum/plugins/brocade/db/models.py index ee2dd4b25d..dd511420a2 100644 --- a/quantum/plugins/brocade/db/models.py +++ b/quantum/plugins/brocade/db/models.py @@ -20,9 +20,7 @@ # Varma Bhupatiraju (vbhupati@#brocade.com) -""" -Brocade specific database schema/model. -""" +"""Brocade specific database schema/model.""" import sqlalchemy as sa @@ -32,6 +30,7 @@ from quantum.db import models_v2 class BrocadeNetwork(model_base.BASEV2, models_v2.HasId): """Schema for brocade network.""" + vlan = sa.Column(sa.String(10)) diff --git a/quantum/plugins/brocade/nos/fake_nosdriver.py b/quantum/plugins/brocade/nos/fake_nosdriver.py index 495d23a3c8..5a911721ae 100644 --- a/quantum/plugins/brocade/nos/fake_nosdriver.py +++ b/quantum/plugins/brocade/nos/fake_nosdriver.py @@ -20,10 +20,10 @@ # Shiv Haris (sharis@brocade.com) -""" -FAKE DRIVER, for unit tests purposes +"""FAKE DRIVER, for unit tests purposes. + Brocade NOS Driver implements NETCONF over SSHv2 for -Quantum network life-cycle management +Quantum network life-cycle management. """ @@ -33,7 +33,6 @@ class NOSdriver(): Fake: Handles life-cycle management of Quantum network, leverages AMPP on NOS (for use by unit tests, avoids touching any hardware) - """ def __init__(self): diff --git a/quantum/plugins/brocade/nos/nctemplates.py b/quantum/plugins/brocade/nos/nctemplates.py index 1bbfc2218b..01468d3622 100644 --- a/quantum/plugins/brocade/nos/nctemplates.py +++ b/quantum/plugins/brocade/nos/nctemplates.py @@ -20,10 +20,11 @@ # Shiv Haris (sharis@brocade.com) -""" -NOS NETCONF XML Configuration Command Templates +"""NOS NETCONF XML Configuration Command Templates. + Interface Configuration Commands """ + # Create VLAN (vlan_id) CREATE_VLAN_INTERFACE = """ diff --git a/quantum/plugins/brocade/nos/nosdriver.py b/quantum/plugins/brocade/nos/nosdriver.py index c8362a13b7..028d14dbbc 100644 --- a/quantum/plugins/brocade/nos/nosdriver.py +++ b/quantum/plugins/brocade/nos/nosdriver.py @@ -20,10 +20,10 @@ # Shiv Haris (sharis@brocade.com) +"""Brocade NOS Driver implements NETCONF over SSHv2 for +Quantum network life-cycle management. """ -Brocade NOS Driver implements NETCONF over SSHv2 for -Quantum network life-cycle management -""" + from ncclient import manager from quantum.openstack.common import log as logging @@ -40,9 +40,7 @@ def nos_unknown_host_cb(host, fingerprint): Returns `True` if it finds the key acceptable, and `False` if not. This default callback for NOS always returns 'True' (i.e. trusts all hosts for now). - """ - return True @@ -50,7 +48,6 @@ class NOSdriver(): """NOS NETCONF interface driver for Quantum network. Handles life-cycle management of Quantum network (leverages AMPP on NOS) - """ def __init__(self): diff --git a/quantum/plugins/brocade/tests/noscli.py b/quantum/plugins/brocade/tests/noscli.py index 85d02c7569..9df8512b32 100644 --- a/quantum/plugins/brocade/tests/noscli.py +++ b/quantum/plugins/brocade/tests/noscli.py @@ -20,9 +20,8 @@ # Shiv Haris (sharis@brocade.com) -""" -Brocade NOS Driver CLI -""" +"""Brocade NOS Driver CLI.""" + import argparse from quantum.openstack.common import log as logging diff --git a/quantum/plugins/brocade/tests/nostest.py b/quantum/plugins/brocade/tests/nostest.py index a181eff70e..c95bf3a16b 100644 --- a/quantum/plugins/brocade/tests/nostest.py +++ b/quantum/plugins/brocade/tests/nostest.py @@ -18,9 +18,7 @@ # Shiv Haris (sharis@brocade.com) -""" -Brocade NOS Driver Test -""" +"""Brocade NOS Driver Test.""" import sys from quantum.plugins.brocade.nos import nosdriver as nos diff --git a/quantum/plugins/brocade/vlanbm.py b/quantum/plugins/brocade/vlanbm.py index baf4cbea6e..8dbf41e86c 100644 --- a/quantum/plugins/brocade/vlanbm.py +++ b/quantum/plugins/brocade/vlanbm.py @@ -20,9 +20,7 @@ # Varma Bhupatiraju (vbhupati@#brocade.com) -""" -A Vlan Bitmap class to handle allocation/de-allocation of vlan ids. -""" +"""A Vlan Bitmap class to handle allocation/de-allocation of vlan ids.""" from quantum.plugins.brocade.db import models as brocade_db @@ -37,16 +35,14 @@ class VlanBitmap(object): # uses a bitmap to do this def __init__(self, ctxt): - """initialize the vlan as a set.""" + """Initialize the vlan as a set.""" self.vlans = set(int(net['vlan']) for net in brocade_db.get_networks(ctxt) if net['vlan'] ) def get_next_vlan(self, vlan_id=None): - """try to get a specific vlan if requested - or get the next vlan. - """ + """Try to get a specific vlan if requested or get the next vlan.""" min_vlan_search = vlan_id or MIN_VLAN max_vlan_search = (vlan_id and vlan_id + 1) or MAX_VLAN @@ -56,6 +52,6 @@ class VlanBitmap(object): return vlan def release_vlan(self, vlan_id): - """return the vlan to the pool.""" + """Return the vlan to the pool.""" if vlan_id in self.vlans: self.vlans.remove(vlan_id)