]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Swich over to update_{net,port} instead of rename_net and set_port_state
authorBrad Hall <brad@nicira.com>
Mon, 3 Oct 2011 05:39:26 +0000 (22:39 -0700)
committerBrad Hall <brad@nicira.com>
Sat, 5 Nov 2011 05:32:43 +0000 (22:32 -0700)
This commit changes the plugin interface so that we have update() functions
that can upate any attributes of the port or network.  In the future when we
add more things like operational state this will give us the flexibility to be
able to update those.  This also allows data extensions to be passed into the
update calls.

Thanks to Tyler and the others at cisco for making the changes to the cisco
plugins and tests (their patch is included in this commit).

Change-Id: If8a0111a7174d94d9f0aed9630e326d428ef994a

29 files changed:
client/lib/quantum/cli.py
client/lib/quantum/cli_lib.py
client/lib/quantum/client.py
client/lib/quantum/tests/unit/test_clientlib.py
plugins/cisco-plugin/lib/quantum/plugins/cisco/db/api.py
plugins/cisco-plugin/lib/quantum/plugins/cisco/l2device_inventory_base.py
plugins/cisco-plugin/lib/quantum/plugins/cisco/l2device_plugin_base.py
plugins/cisco-plugin/lib/quantum/plugins/cisco/l2network_model_base.py
plugins/cisco-plugin/lib/quantum/plugins/cisco/l2network_plugin.py
plugins/cisco-plugin/lib/quantum/plugins/cisco/models/l2network_multi_blade.py
plugins/cisco-plugin/lib/quantum/plugins/cisco/models/l2network_single_blade.py
plugins/cisco-plugin/lib/quantum/plugins/cisco/nexus/cisco_nexus_plugin.py
plugins/cisco-plugin/lib/quantum/plugins/cisco/ucs/cisco_ucs_inventory.py
plugins/cisco-plugin/lib/quantum/plugins/cisco/ucs/cisco_ucs_plugin.py
plugins/cisco-plugin/lib/quantum/tests/unit/test_database.py
plugins/cisco-plugin/lib/quantum/tests/unit/test_l2networkApi.py
plugins/cisco-plugin/lib/quantum/tests/unit/test_l2network_multi_blade.py
plugins/cisco-plugin/lib/quantum/tests/unit/test_nexus_plugin.py
plugins/cisco-plugin/lib/quantum/tests/unit/test_ucs_inventory.py
plugins/openvswitch-plugin/lib/quantum/plugins/openvswitch/ovs_quantum_plugin.py
plugins/sample-plugin/lib/quantum/plugins/SamplePlugin.py
server/lib/quantum/api/networks.py
server/lib/quantum/api/ports.py
server/lib/quantum/db/api.py
server/lib/quantum/quantum_plugin_base.py
server/lib/quantum/tests/unit/database_stubs.py
server/lib/quantum/tests/unit/test_api.py
server/lib/quantum/tests/unit/test_cli.py
server/lib/quantum/tests/unit/test_database.py

index 138d75d5e6eebb15fbfc5b1e78124b880983de6f..8509d1ae51fdb222ac930f922d62a05c6004eb2f 100755 (executable)
@@ -57,8 +57,8 @@ commands = {
   "show_net": {
     "func": cli_lib.show_net,
     "args": ["tenant-id", "net-id"]},
-  "rename_net": {
-    "func": cli_lib.rename_net,
+  "update_net": {
+    "func": cli_lib.update_net,
     "args": ["tenant-id", "net-id", "new-name"]},
   "list_ports": {
     "func": cli_lib.list_ports,
@@ -69,9 +69,9 @@ commands = {
   "delete_port": {
     "func": cli_lib.delete_port,
     "args": ["tenant-id", "net-id", "port-id"]},
-  "set_port_state": {
-    "func": cli_lib.set_port_state,
-    "args": ["tenant-id", "net-id", "port-id", "new_state"]},
+  "update_port": {
+    "func": cli_lib.update_port,
+    "args": ["tenant-id", "net-id", "port-id", "params"]},
   "show_port": {
     "func": cli_lib.show_port,
     "args": ["tenant-id", "net-id", "port-id"]},
index d9f4ea2a10df2fbe815d0e9e8ced539bb15f74e6..dcdf908814784e47788a9ea7a16e760e53c69676 100755 (executable)
@@ -100,9 +100,8 @@ class CmdOutputTemplate(OutputTemplate):
         "create_net":     "Created a new Virtual Network with ID: " +
                           "%(network_id)s\n" +
                           "for Tenant: %(tenant_id)s",
-        "rename_net":     "Renamed Virtual Network with ID: %(network.id)s\n" +
-                          "for Tenant: %(tenant_id)s\n" +
-                          "new name is: %(network.name)s",
+        "update_net":     "Updated Virtual Network with ID: %(network.id)s\n" +
+                          "for Tenant: %(tenant_id)s\n",
         "delete_net":     "Deleted Virtual Network with ID: %(network_id)s\n" +
                           "for Tenant %(tenant_id)s",
         "list_ports":     "Ports on Virtual Network: %(network_id)s\n" +
@@ -116,9 +115,8 @@ class CmdOutputTemplate(OutputTemplate):
                           "interface: %(port.attachment)s\n" +
                           "on Virtual Network: %(network_id)s\n" +
                           "for Tenant: %(tenant_id)s",
-        "set_port_state": "Updated state for Logical Port " +
+        "update_port":    "Updated Logical Port " +
                           "with ID: %(port.id)s\n" +
-                          "new state is: %(port.state)s\n" +
                           "on Virtual Network: %(network_id)s\n" +
                           "for tenant: %(tenant_id)s",
         "delete_port":    "Deleted Logical Port with ID: %(port_id)s\n" +
@@ -211,15 +209,18 @@ def show_net(client, *args):
         _handle_exception(ex)
 
 
-def rename_net(client, *args):
-    tenant_id, network_id, name = args
-    data = {'network': {'name': '%s' % name}}
+def update_net(client, *args):
+    tenant_id, network_id, param_data = args
+    data = {'network': {}}
+    for kv in param_data.split(","):
+        k, v = kv.split("=")
+        data['network'][k] = v
+    data['network']['id'] = network_id
     try:
         client.update_network(network_id, data)
         LOG.debug("Operation 'update_network' executed.")
         # Response has no body. Use data for populating output
-        data['network']['id'] = network_id
-        output = prepare_output("rename_net", tenant_id, data)
+        output = prepare_output("update_net", tenant_id, data)
         print output
     except Exception as ex:
         _handle_exception(ex)
@@ -288,16 +289,19 @@ def show_port(client, *args):
         _handle_exception(ex)
 
 
-def set_port_state(client, *args):
-    tenant_id, network_id, port_id, new_state = args
-    data = {'port': {'state': '%s' % new_state}}
+def update_port(client, *args):
+    tenant_id, network_id, port_id, param_data = args
+    data = {'port': {}}
+    for kv in param_data.split(","):
+        k, v = kv.split("=")
+        data['port'][k] = v
+    data['network_id'] = network_id
+    data['port']['id'] = port_id
     try:
-        client.set_port_state(network_id, port_id, data)
-        LOG.debug("Operation 'set_port_state' executed.")
+        client.update_port(network_id, port_id, data)
+        LOG.debug("Operation 'udpate_port' executed.")
         # Response has no body. Use data for populating output
-        data['network_id'] = network_id
-        data['port']['id'] = port_id
-        output = prepare_output("set_port_state", tenant_id, data)
+        output = prepare_output("update_port", tenant_id, data)
         print output
     except Exception as ex:
         _handle_exception(ex)
index afba7efb94b7d48eb8d049300cd2993d32726144..d4e032c135c8f24622d2415eae6e5efb9bd6eb49 100644 (file)
@@ -320,15 +320,14 @@ class Client(object):
                        exception_args={"net_id": network, "port_id": port})
 
     @ApiCall
-    def set_port_state(self, network, port, body=None):
+    def update_port(self, network, port, body=None):
         """
-        Sets the state of the specified port
+        Sets the attributes of the specified port
         """
         return self.do_request("PUT",
             self.port_path % (network, port), body=body,
                        exception_args={"net_id": network,
-                                       "port_id": port,
-                                       "port_state": str(body)})
+                                       "port_id": port})
 
     @ApiCall
     def show_port_attachment(self, network, port):
index 4e2c920c765f8a93cc601ac26765d17c5e11fee6..b87050f1723764bfbef8296b2f99c4ce61adab1d 100644 (file)
@@ -246,11 +246,11 @@ class APITest(unittest.TestCase):
         LOG.debug("_test_delete_port - tenant:%s "\
                   "- format:%s - END", format, tenant)
 
-    def _test_set_port_state(self, tenant=TENANT_1, format='json', status=200):
-        LOG.debug("_test_set_port_state - tenant:%s "\
+    def _test_update_port(self, tenant=TENANT_1, format='json', status=200):
+        LOG.debug("_test_update_port - tenant:%s "\
                   "- format:%s - START", format, tenant)
 
-        self._assert_sanity(self.client.set_port_state,
+        self._assert_sanity(self.client.update_port,
                             status,
                             "PUT",
                             "networks/001/ports/001",
@@ -258,7 +258,7 @@ class APITest(unittest.TestCase):
                                   {'port': {'state': 'ACTIVE'}}],
                             params={'tenant': tenant, 'format': format})
 
-        LOG.debug("_test_set_port_state - tenant:%s "\
+        LOG.debug("_test_update_port - tenant:%s "\
                   "- format:%s - END", format, tenant)
 
     def _test_show_port_attachment(self,
@@ -519,32 +519,32 @@ class APITest(unittest.TestCase):
     def test_delete_port_error_432(self):
         self._test_delete_port(status=432)
 
-    def test_set_port_state_json(self):
-        self._test_set_port_state(format='json')
+    def test_update_port_json(self):
+        self._test_update_port(format='json')
 
-    def test_set_port_state_xml(self):
-        self._test_set_port_state(format='xml')
+    def test_update_port_xml(self):
+        self._test_update_port(format='xml')
 
-    def test_set_port_state_alt_tenant(self):
-        self._test_set_port_state(tenant=TENANT_2)
+    def test_update_port_alt_tenant(self):
+        self._test_update_port(tenant=TENANT_2)
 
-    def test_set_port_state_error_470(self):
-        self._test_set_port_state(status=470)
+    def test_update_port_error_470(self):
+        self._test_update_port(status=470)
 
-    def test_set_port_state_error_401(self):
-        self._test_set_port_state(status=401)
+    def test_update_port_error_401(self):
+        self._test_update_port(status=401)
 
-    def test_set_port_state_error_400(self):
-        self._test_set_port_state(status=400)
+    def test_update_port_error_400(self):
+        self._test_update_port(status=400)
 
-    def test_set_port_state_error_420(self):
-        self._test_set_port_state(status=420)
+    def test_update_port_error_420(self):
+        self._test_update_port(status=420)
 
-    def test_set_port_state_error_430(self):
-        self._test_set_port_state(status=430)
+    def test_update_port_error_430(self):
+        self._test_update_port(status=430)
 
-    def test_set_port_state_error_431(self):
-        self._test_set_port_state(status=431)
+    def test_update_port_error_431(self):
+        self._test_update_port(status=431)
 
     def test_show_port_attachment_json(self):
         self._test_show_port_attachment(format='json')
index 55bce235fb534bb45866d070799f73ad74671af2..bfbaafa8ed9f130658f33c74b4ba7dea2204a872 100644 (file)
@@ -120,11 +120,13 @@ def network_get(net_id):
         raise q_exc.NetworkNotFound(net_id=net_id)
 
 
-def network_rename(tenant_id, net_id, new_name):
+def network_update(net_id, tenant_id, **kwargs):
     session = get_session()
     net = network_get(net_id)
-    _check_duplicate_net_name(tenant_id, new_name)
-    net.name = new_name
+    for key in kwargs.keys():
+        if key == "name":
+            _check_duplicate_net_name(tenant_id, kwargs[key])
+        net[key] = kwargs[key]
     session.merge(net)
     session.flush()
     return net
@@ -177,16 +179,17 @@ def port_get(net_id, port_id):
         raise q_exc.PortNotFound(net_id=net_id, port_id=port_id)
 
 
-def port_set_state(net_id, port_id, new_state):
-    if new_state not in ('ACTIVE', 'DOWN'):
-        raise q_exc.StateInvalid(port_state=new_state)
-
+def port_update(port_id, net_id, **kwargs):
     # confirm network exists
     network_get(net_id)
 
     port = port_get(net_id, port_id)
     session = get_session()
-    port.state = new_state
+    for key in kwargs.keys():
+        if key == "state":
+            if kwargs[key] not in ('ACTIVE', 'DOWN'):
+                raise q_exc.StateInvalid(port_state=kwargs[key])
+        port[key] = kwargs[key]
     session.merge(port)
     session.flush()
     return port
index 9ecbed3feb8287505db6b1b110cb8cc0815d161e..f2a3c9d9239ba40f9f1fa3ec664554cbeb44e501 100644 (file)
@@ -131,7 +131,7 @@ class L2NetworkDeviceInventoryBase(object):
         pass
 
     @abstractmethod
-    def rename_network(self, args):
+    def update_network(self, args):
         """
         Returns a dictionary containing the first element as a device
         IP address list. The model then invokes the device-specific plugin
index 43a8c83e837f44ccf709b269457bd790cdb50ac7..defd7d2e99832df774d75787b099f0f059bd86a1 100644 (file)
@@ -67,7 +67,7 @@ class L2DevicePluginBase(object):
         pass
 
     @abstractmethod
-    def rename_network(self, tenant_id, net_id, new_name, **kwargs):
+    def update_network(self, tenant_id, net_id, name, **kwargs):
         """
         :returns:
         :raises:
@@ -99,7 +99,7 @@ class L2DevicePluginBase(object):
         pass
 
     @abstractmethod
-    def update_port(self, tenant_id, net_id, port_id, port_state, **kwargs):
+    def update_port(self, tenant_id, net_id, port_id, **kwargs):
         """
         :returns:
         :raises:
index 100aa17ea5e30b16c4411a23e78e17e5da192f0f..7d03a3cd9760efafc9a051e47530b68f0e62bef6 100644 (file)
@@ -67,7 +67,7 @@ class L2NetworkModelBase(object):
         pass
 
     @abstractmethod
-    def rename_network(self, args):
+    def update_network(self, args):
         """
         :returns:
         :raises:
index 9b3b60701ef4512a73f87eb270eb5eec5b6d54ae..b5da80f1167c3784031028a3b2346b081b3b01d1 100644 (file)
@@ -72,7 +72,7 @@ class L2Network(QuantumPluginBase):
 
         return new_networks_list
 
-    def create_network(self, tenant_id, net_name):
+    def create_network(self, tenant_id, net_name, **kwargs):
         """
         Creates a new Virtual Network, and assigns it
         a symbolic name.
@@ -140,15 +140,15 @@ class L2Network(QuantumPluginBase):
 
         return new_network
 
-    def rename_network(self, tenant_id, net_id, new_name):
+    def update_network(self, tenant_id, net_id, **kwargs):
         """
         Updates the symbolic name belonging to a particular
         Virtual Network.
         """
-        LOG.debug("rename_network() called\n")
-        network = db.network_rename(tenant_id, net_id, new_name)
+        LOG.debug("update_network() called\n")
+        network = db.network_update(net_id, tenant_id, **kwargs)
         self._invoke_device_plugins(self._func_name(), [tenant_id, net_id,
-                                                     new_name])
+                                                     kwargs])
         net_dict = cutil.make_net_dict(network[const.UUID],
                                        network[const.NETWORKNAME],
                                        [])
@@ -173,7 +173,7 @@ class L2Network(QuantumPluginBase):
 
         return ports_on_net
 
-    def create_port(self, tenant_id, net_id, port_state=None):
+    def create_port(self, tenant_id, net_id, port_state=None, **kwargs):
         """
         Creates a port on the specified Virtual Network.
         """
@@ -212,17 +212,18 @@ class L2Network(QuantumPluginBase):
             raise exc.PortInUse(port_id=port_id, net_id=net_id,
                                 att_id=attachment_id)
 
-    def update_port(self, tenant_id, net_id, port_id, port_state):
+    def update_port(self, tenant_id, net_id, port_id, **kwargs):
         """
         Updates the state of a port on the specified Virtual Network.
         """
         LOG.debug("update_port() called\n")
         network = db.network_get(net_id)
         self._invoke_device_plugins(self._func_name(), [tenant_id, net_id,
-                                                     port_id, port_state])
-        self._validate_port_state(port_state)
-        db.port_set_state(net_id, port_id, port_state)
-        new_port_dict = cutil.make_port_dict(port_id, port_state, net_id,
+                                        port_id, kwargs])
+        self._validate_port_state(kwargs["state"])
+        db.port_update(port_id, net_id, **kwargs)
+
+        new_port_dict = cutil.make_port_dict(port_id, kwargs["state"], net_id,
                                              None)
         return new_port_dict
 
index 539f360eeb092e9de21e5a343733e584d9878639..1a92966aa6ab999280bdfffafefeb7b1d033024d 100644 (file)
@@ -97,6 +97,10 @@ class L2NetworkMultiBlade(L2NetworkModelBase):
 
     def _invoke_plugin(self, plugin_key, function_name, args, kwargs):
         """Invoke only the device plugin"""
+        # If the last param is a dict, add it to kwargs
+        if args and type(args[-1]) is dict:
+            kwargs.update(args.pop())
+
         return getattr(self._plugins[plugin_key], function_name)(*args,
                                                                  **kwargs)
 
@@ -130,7 +134,7 @@ class L2NetworkMultiBlade(L2NetworkModelBase):
         """Not implemented for this model"""
         pass
 
-    def rename_network(self, args):
+    def update_network(self, args):
         """Support for the Quantum core API call"""
         output = []
         ucs_output = self._invoke_plugin_per_device(const.UCS_PLUGIN,
index 4184edb4b981aa90953bd5caf3adbcf9fce30082..256c8098289be1a6290a5d514a485b97c593b90c 100644 (file)
@@ -90,6 +90,10 @@ class L2NetworkSingleBlade(L2NetworkModelBase):
 
     def _invoke_plugin(self, plugin_key, function_name, args, kwargs):
         """Invoke only the device plugin"""
+        # If the last param is a dict, add it to kwargs
+        if args and type(args[-1]) is dict:
+            kwargs.update(args.pop())
+
         return getattr(self._plugins[plugin_key], function_name)(*args,
                                                                  **kwargs)
 
@@ -111,7 +115,7 @@ class L2NetworkSingleBlade(L2NetworkModelBase):
         """Not implemented for this model"""
         pass
 
-    def rename_network(self, args):
+    def update_network(self, args):
         """Support for the Quantum core API call"""
         self._invoke_plugin_per_device(const.UCS_PLUGIN, self._func_name(),
                                        args)
index bef42fd45e140c9e08aeffac814231cc252bfee9..e0d9775c3dec665cfb4a023ba0963cffa1d186cc 100644 (file)
@@ -113,14 +113,14 @@ class NexusPlugin(L2DevicePluginBase):
         network = self._get_network(tenant_id, net_id)
         return network
 
-    def rename_network(self, tenant_id, net_id, new_name, **kwargs):
+    def update_network(self, tenant_id, net_id, **kwargs):
         """
-        Updates the symbolic name belonging to a particular
+        Updates the properties of a particular
         Virtual Network.
         """
-        LOG.debug("NexusPlugin:rename_network() called\n")
+        LOG.debug("NexusPlugin:update_network() called\n")
         network = self._get_network(tenant_id, net_id)
-        network[const.NET_NAME] = new_name
+        network[const.NET_NAME] = kwargs["name"]
         return network
 
     def get_all_ports(self, tenant_id, net_id, **kwargs):
index 5e85a301d1fb7d076add7f92d8002172353b18e8..7a581640a6258a19d7dd0856cc0c3e4bd24f6aa3 100644 (file)
@@ -576,9 +576,9 @@ class UCSInventory(L2NetworkDeviceInventoryBase):
         LOG.debug("get_network_details() called\n")
         return self._get_all_ucsms()
 
-    def rename_network(self, args):
+    def update_network(self, args):
         """Return all UCSM IPs"""
-        LOG.debug("rename_network() called\n")
+        LOG.debug("update_network() called\n")
         return self._get_all_ucsms()
 
     def get_all_ports(self, args):
index 77e1e4dbeac5396d79bd3300721501379023b495..0bb7655dcc313325296f912b6355f73980087423 100644 (file)
@@ -120,12 +120,12 @@ class UCSVICPlugin(L2DevicePluginBase):
 
         return new_network
 
-    def rename_network(self, tenant_id, net_id, new_name, **kwargs):
+    def update_network(self, tenant_id, net_id, **kwargs):
         """
         Updates the symbolic name belonging to a particular
         Virtual Network.
         """
-        LOG.debug("UCSVICPlugin:rename_network() called\n")
+        LOG.debug("UCSVICPlugin:update_network() called\n")
         self._set_ucsm(kwargs[const.DEVICE_IP])
         network = db.network_get(net_id)
         net_dict = cutil.make_net_dict(network[const.UUID],
@@ -198,7 +198,7 @@ class UCSVICPlugin(L2DevicePluginBase):
                                                 blade_id, interface_dn)
         return udb.remove_portbinding(port_id)
 
-    def update_port(self, tenant_id, net_id, port_id, port_state, **kwargs):
+    def update_port(self, tenant_id, net_id, port_id, **kwargs):
         """
         Updates the state of a port on the specified Virtual Network.
         """
index 4a5ffc9d664df37c190bbd4c0d0d2632c85ab8eb..f8298deb8d80e1595ebe75ea5302e1bfdadaca0c 100644 (file)
@@ -469,17 +469,17 @@ class QuantumDB(object):
         except Exception, exc:
             raise Exception("Failed to delete port: %s" % str(exc))
 
-    def rename_network(self, tenant_id, net_id, new_name):
-        """Rename a network"""
+    def update_network(self, tenant_id, net_id, **kwargs):
+        """Update a network"""
         try:
-            net = db.network_rename(tenant_id, net_id, new_name)
-            LOG.debug("Renamed network: %s" % net.uuid)
+            net = db.network_update(net_id, tenant_id, **kwargs)
+            LOG.debug("Updated network: %s" % net.uuid)
             net_dict = {}
             net_dict["net-id"] = str(net.uuid)
             net_dict["net-name"] = net.name
             return net_dict
         except Exception, exc:
-            raise Exception("Failed to rename network: %s" % str(exc))
+            raise Exception("Failed to update network: %s" % str(exc))
 
     def get_all_ports(self, net_id):
         """Get all ports"""
@@ -1039,12 +1039,12 @@ class QuantumDBTest(unittest.TestCase):
         self.assertTrue(count == 0)
         self.teardown_network_port()
 
-    def testd_rename_network(self):
-        """test to rename network"""
+    def testd_update_network(self):
+        """test to update (rename) network"""
         net1 = self.dbtest.create_network(self.tenant_id, "plugin_test1")
         self.assertTrue(net1["net-name"] == "plugin_test1")
-        net = self.dbtest.rename_network(self.tenant_id, net1["net-id"],
-          "plugin_test1_renamed")
+        net = self.dbtest.update_network(self.tenant_id, net1["net-id"],
+          name="plugin_test1_renamed")
         self.assertTrue(net["net-name"] == "plugin_test1_renamed")
         self.teardown_network_port()
 
index 92c0aed1dec17611f61178117ce5df3d9a425b16..452f9acf2830c07424c2cba7e0c0f5b52499798a 100644 (file)
@@ -101,7 +101,7 @@ class CoreAPITestFunc(unittest.TestCase):
         new_net_dict = self._l2network_plugin.create_network(
                                 tenant_id, self.network_name)
         port_dict = self._l2network_plugin.create_port(
-                tenant_id, new_net_dict[const.NET_ID], self.port_state)
+                tenant_id, new_net_dict[const.NET_ID], self.state)
         instance_desc = {'project_id': tenant_id,
                          'user_id': nova_user_id}
         host_list = self._l2network_plugin.schedule_host(instance_tenant_id,
@@ -158,42 +158,43 @@ class CoreAPITestFunc(unittest.TestCase):
                           tenant_id, net_id)
         LOG.debug("test_show_network_not_found - END")
 
-    def test_rename_network(self, net_tenant_id=None,
+    def test_update_network(self, net_tenant_id=None,
                             new_name='new_test_network'):
         """
         Tests rename of a Virtual Network .
         """
 
-        LOG.debug("test_rename_network - START")
+        LOG.debug("test_update_network - START")
         if net_tenant_id:
             tenant_id = net_tenant_id
         else:
             tenant_id = self.tenant_id
         new_net_dict = self._l2network_plugin.create_network(
                         tenant_id, self.network_name)
-        rename_net_dict = self._l2network_plugin.rename_network(
-                        tenant_id, new_net_dict[const.NET_ID], new_name)
+        rename_net_dict = self._l2network_plugin.update_network(
+                            tenant_id, new_net_dict[const.NET_ID],
+                            name=new_name)
         net = db.network_get(new_net_dict[const.NET_ID])
         self.assertEqual(net[const.NETWORKNAME], new_name)
         self.assertEqual(new_name, rename_net_dict[const.NET_NAME])
         self.tearDownNetwork(tenant_id, new_net_dict[const.NET_ID])
-        LOG.debug("test_rename_network - END")
+        LOG.debug("test_update_network - END")
 
-    def test_rename_networkDNE(self, net_tenant_id=None,
+    def test_update_networkDNE(self, net_tenant_id=None,
                                net_id='0005', new_name='new_test_network'):
         """
-        Tests rename of a Virtual Network when Network does not exist.
+        Tests update of a Virtual Network when Network does not exist.
         """
 
-        LOG.debug("test_rename_network_not_found - START")
+        LOG.debug("test_update_network_not_found - START")
         if net_tenant_id:
             tenant_id = net_tenant_id
         else:
             tenant_id = self.tenant_id
         self.assertRaises(exc.NetworkNotFound,
-                          self._l2network_plugin.rename_network,
-                          tenant_id, net_id, new_name)
-        LOG.debug("test_rename_network_not_found - END")
+                          self._l2network_plugin.update_network,
+                          tenant_id, net_id, name=new_name)
+        LOG.debug("test_update_network_not_found - END")
 
     def test_list_networks(self, tenant_id='test_network'):
         """
@@ -232,9 +233,11 @@ class CoreAPITestFunc(unittest.TestCase):
         new_net_dict = self._l2network_plugin.create_network(
                         tenant_id, self.network_name)
         port_dict = self._l2network_plugin.create_port(
-                        tenant_id, new_net_dict[const.NET_ID], self.port_state)
+                        tenant_id, new_net_dict[const.NET_ID],
+                        self.state)
         port_dict2 = self._l2network_plugin.create_port(
-                        tenant_id, new_net_dict[const.NET_ID], self.port_state)
+                        tenant_id, new_net_dict[const.NET_ID],
+                        self.state)
         port_list = self._l2network_plugin.get_all_ports(
                         tenant_id, new_net_dict[const.NET_ID])
         port_temp_list = [port_dict, port_dict2]
@@ -260,7 +263,7 @@ class CoreAPITestFunc(unittest.TestCase):
         LOG.debug("test_list_ports - END")
 
     def test_create_port(self, tenant_id='test_network',
-                         port_state=const.PORT_UP):
+                         state=const.PORT_UP):
         """
         Tests creation of Ports.
         """
@@ -269,19 +272,19 @@ class CoreAPITestFunc(unittest.TestCase):
         new_net_dict = self._l2network_plugin.create_network(
                                 tenant_id, self.network_name)
         port_dict = self._l2network_plugin.create_port(
-                tenant_id, new_net_dict[const.NET_ID], port_state)
+                tenant_id, new_net_dict[const.NET_ID], state)
         port = db.port_get(new_net_dict[const.NET_ID],
                            port_dict[const.PORT_ID])
-        self.assertEqual(port_dict[const.PORT_STATE], port_state)
+        self.assertEqual(port_dict[const.PORT_STATE], state)
         self.assertEqual(port_dict[const.NET_ID], new_net_dict[const.NET_ID])
-        self.assertEqual(port[const.PORTSTATE], port_state)
+        self.assertEqual(port[const.PORTSTATE], state)
         self.assertEqual(port[const.NETWORKID], new_net_dict[const.NET_ID])
         self.tearDownNetworkPort(tenant_id, new_net_dict[const.NET_ID],
                                  port_dict[const.PORT_ID])
         LOG.debug("test_create_port - END")
 
     def test_create_port_network_DNE(
-            self, net_tenant_id=None, net_id='0005', port_state=const.PORT_UP):
+            self, net_tenant_id=None, net_id='0005', state=const.PORT_UP):
 
         """
         Tests creation of Ports when network does not exist.
@@ -294,11 +297,11 @@ class CoreAPITestFunc(unittest.TestCase):
             tenant_id = self.tenant_id
         self.assertRaises(exc.NetworkNotFound,
                           self._l2network_plugin.create_port,
-                          tenant_id, net_id, port_state)
+                          tenant_id, net_id, state)
         LOG.debug("test_create_port_network_DNE - END:")
 
     def test_delete_port(self, tenant_id='test_tenant',
-                         port_state=const.PORT_UP):
+                         state=const.PORT_UP):
         """
         Tests deletion of Ports
         """
@@ -307,7 +310,8 @@ class CoreAPITestFunc(unittest.TestCase):
         new_net_dict = self._l2network_plugin.create_network(
                                 tenant_id, self.network_name)
         port_dict = self._l2network_plugin.create_port(
-                            tenant_id, new_net_dict[const.NET_ID], port_state)
+                            tenant_id, new_net_dict[const.NET_ID],
+                            state=state)
         delete_port_dict = self._l2network_plugin.delete_port(
                                 tenant_id, new_net_dict[const.NET_ID],
                                 port_dict[const.PORT_ID])
@@ -356,7 +360,7 @@ class CoreAPITestFunc(unittest.TestCase):
                                         tenant_id, self.network_name)
         port_dict = self._l2network_plugin.create_port(
                                 tenant_id, new_net_dict[const.NET_ID],
-                                self.port_state)
+                                self.state)
         instance_desc = {'project_id': tenant_id,
                          'user_id': nova_user_id}
         host_list = self._l2network_plugin.schedule_host(instance_tenant_id,
@@ -377,7 +381,7 @@ class CoreAPITestFunc(unittest.TestCase):
         LOG.debug("test_delete_portInUse - END")
 
     def test_update_port(self, tenant_id='test_tenant',
-                         port_state=const.PORT_DOWN):
+                         state=const.PORT_DOWN):
         """
         Tests updation of Ports.
         """
@@ -386,14 +390,15 @@ class CoreAPITestFunc(unittest.TestCase):
         new_net_dict = self._l2network_plugin.create_network(
                                         tenant_id, self.network_name)
         port_dict = self._l2network_plugin.create_port(
-                        tenant_id, new_net_dict[const.NET_ID], self.port_state)
+                        tenant_id, new_net_dict[const.NET_ID],
+                        self.state)
         update_port_dict = self._l2network_plugin.update_port(
-                                tenant_id, new_net_dict[const.NET_ID],
-                                port_dict[const.PORT_ID], port_state)
+                              tenant_id, new_net_dict[const.NET_ID],
+                              port_dict[const.PORT_ID], state=state)
         new_port = db.port_get(new_net_dict[const.NET_ID],
                                port_dict[const.PORT_ID])
-        self.assertEqual(new_port[const.PORTSTATE], port_state)
-        self.assertEqual(update_port_dict[const.PORT_STATE], port_state)
+        self.assertEqual(new_port[const.PORTSTATE], state)
+        self.assertEqual(update_port_dict[const.PORT_STATE], state)
         self.tearDownNetworkPort(tenant_id, new_net_dict[const.NET_ID],
                                  port_dict[const.PORT_ID])
         LOG.debug("test_update_port - END")
@@ -407,7 +412,7 @@ class CoreAPITestFunc(unittest.TestCase):
         LOG.debug("test_update_port_networkDNE - START")
         self.assertRaises(exc.NetworkNotFound,
                           self._l2network_plugin.update_port, tenant_id,
-                          net_id, port_id, const.PORT_UP)
+                          net_id, port_id, const.PORT_UP, state=const.PORT_UP)
         LOG.debug("test_update_port_networkDNE - END")
 
     def test_update_portDNE(self, tenant_id='test_tenant', port_id='p0005'):
@@ -420,7 +425,7 @@ class CoreAPITestFunc(unittest.TestCase):
                                 tenant_id, self.network_name)
         self.assertRaises(
             exc.PortNotFound, self._l2network_plugin.update_port, tenant_id,
-            new_net_dict[const.NET_ID], port_id, const.PORT_UP)
+            new_net_dict[const.NET_ID], port_id, state=const.PORT_UP)
         self.tearDownNetwork(tenant_id, new_net_dict[const.NET_ID])
         LOG.debug("test_update_portDNE - END")
 
@@ -433,14 +438,15 @@ class CoreAPITestFunc(unittest.TestCase):
         new_net_dict = self._l2network_plugin.create_network(
                                 tenant_id, self.network_name)
         port_dict = self._l2network_plugin.create_port(
-                        tenant_id, new_net_dict[const.NET_ID], self.port_state)
+                        tenant_id, new_net_dict[const.NET_ID],
+                        self.state)
         get_port_dict = self._l2network_plugin.get_port_details(
                         tenant_id, new_net_dict[const.NET_ID],
                         port_dict[const.PORT_ID])
         port = db.port_get(new_net_dict[const.NET_ID],
                            port_dict[const.PORT_ID])
-        self.assertEqual(port[const.PORTSTATE], self.port_state)
-        self.assertEqual(get_port_dict[const.PORT_STATE], self.port_state)
+        self.assertEqual(port[const.PORTSTATE], self.state)
+        self.assertEqual(get_port_dict[const.PORT_STATE], self.state)
         self.tearDownNetworkPort(tenant_id, new_net_dict[const.NET_ID],
                                  port_dict[const.PORT_ID])
         LOG.debug("test_show_port - END")
@@ -483,7 +489,7 @@ class CoreAPITestFunc(unittest.TestCase):
         new_net_dict = self._l2network_plugin.create_network(
                                 tenant_id, self.network_name)
         port_dict = self._l2network_plugin.create_port(
-                        tenant_id, new_net_dict[const.NET_ID], self.port_state)
+                        tenant_id, new_net_dict[const.NET_ID], self.state)
         instance_desc = {'project_id': tenant_id,
                          'user_id': nova_user_id}
         host_list = self._l2network_plugin.schedule_host(instance_tenant_id,
@@ -552,7 +558,7 @@ class CoreAPITestFunc(unittest.TestCase):
         new_net_dict = self._l2network_plugin.create_network(
                                 tenant_id, self.network_name)
         port_dict = self._l2network_plugin.create_port(
-                        tenant_id, new_net_dict[const.NET_ID], self.port_state)
+                        tenant_id, new_net_dict[const.NET_ID], self.state)
         instance_desc = {'project_id': tenant_id,
                          'user_id': nova_user_id}
         host_list = self._l2network_plugin.schedule_host(instance_tenant_id,
@@ -589,7 +595,7 @@ class CoreAPITestFunc(unittest.TestCase):
                                 tenant_id, self.network_name)
         port_dict = self._l2network_plugin.create_port(
                                 tenant_id, new_net_dict[const.NET_ID],
-                                self.port_state)
+                                self.state)
         instance_desc = {'project_id': tenant_id,
                          'user_id': nova_user_id}
         host_list = self._l2network_plugin.schedule_host(instance_tenant_id,
@@ -721,7 +727,8 @@ class CoreAPITestFunc(unittest.TestCase):
         new_net_dict = self._l2network_plugin.create_network(
                         tenant_id, 'test_network')
         port_dict = self._l2network_plugin.create_port(
-                        tenant_id, new_net_dict[const.NET_ID], 'const.PORT_UP')
+                        tenant_id, new_net_dict[const.NET_ID],
+                        const.PORT_UP)
         self._l2network_plugin.associate_portprofile(
                         tenant_id, new_net_dict[const.NET_ID],
                         port_dict[const.PORT_ID], port_profile_id)
@@ -846,7 +853,7 @@ class CoreAPITestFunc(unittest.TestCase):
                                 tenant_id, self.network_name)
         port_dict = self._l2network_plugin.create_port(
                                 tenant_id, new_net_dict[const.NET_ID],
-                                self.port_state)
+                                self.state)
         port_profile_dict = self._l2network_plugin.create_portprofile(
                         tenant_id, self.profile_name, self.qos)
         port_profile_id = port_profile_dict['profile_id']
@@ -888,7 +895,7 @@ class CoreAPITestFunc(unittest.TestCase):
                                 tenant_id, self.network_name)
         port_dict = self._l2network_plugin.create_port(
                                 tenant_id, new_net_dict[const.NET_ID],
-                                self.port_state)
+                                self.state)
         port_profile_dict = self._l2network_plugin.create_portprofile(
                                 tenant_id, self.profile_name, self.qos)
         port_profile_id = port_profile_dict['profile_id']
@@ -935,26 +942,26 @@ class CoreAPITestFunc(unittest.TestCase):
         self.assertEqual(result_vlan_name, expected_output)
         LOG.debug("test_get_vlan_name - END")
 
-    def test_validate_port_state(self, port_state=const.PORT_UP):
+    def test_validate_state(self, state=const.PORT_UP):
         """
         Tests validate port state
         """
 
-        LOG.debug("test_validate_port_state - START")
-        result = self._l2network_plugin._validate_port_state(port_state)
+        LOG.debug("test_validate_state - START")
+        result = self._l2network_plugin._validate_state(state)
         self.assertEqual(result, True)
-        LOG.debug("test_validate_port_state - END")
+        LOG.debug("test_validate_state - END")
 
-    def test_invalid_port_state(self, port_state="BADSTATE"):
+    def test_invalid_state(self, state="BADSTATE"):
         """
         Tests invalidate port state
         """
 
-        LOG.debug("test_validate_port_state - START")
+        LOG.debug("test_validate_state - START")
         self.assertRaises(exc.StateInvalid,
-                          self._l2network_plugin._validate_port_state,
-                          port_state)
-        LOG.debug("test_validate_port_state - END")
+                          self._l2network_plugin._validate_state,
+                          state)
+        LOG.debug("test_validate_state - END")
 
     def setUp(self):
         """
@@ -964,11 +971,13 @@ class CoreAPITestFunc(unittest.TestCase):
         self.network_name = "test_network"
         self.profile_name = "test_tenant_port_profile"
         self.qos = "test_qos"
-        self.port_state = const.PORT_UP
+        self.state = const.PORT_UP
         self.net_id = '00005'
         self.port_id = 'p0005'
         self.remote_interface = 'new_interface'
         self._l2network_plugin = l2network_plugin.L2Network()
+        LOG.debug(self._l2network_plugin)
+        LOG.debug("asdfasdfasdfasdfasdf")
 
     """
         Clean up functions after the tests
@@ -1033,8 +1042,8 @@ class CoreAPITestFunc(unittest.TestCase):
         res[const.NET_PORTS] = ports
         return res
 
-    def _make_port_dict(self, port_id, port_state, net_id, attachment):
-        res = {const.PORT_ID: port_id, const.PORT_STATE: port_state}
+    def _make_port_dict(self, port_id, state, net_id, attachment):
+        res = {const.PORT_ID: port_id, const.PORT_STATE: state}
         res[const.NET_ID] = net_id
         res[const.ATTACHMENT] = attachment
         return res
index 6e46381db900baad7a5288a3a34aa2213ad9231d..efbc091031cffc5d2dbff8ae4ec514de59d73358 100644 (file)
@@ -170,35 +170,36 @@ class TestMultiBlade(unittest.TestCase):
 
         LOG.debug("test_delete_networkDNE - END")
 
-    def test_rename_network(self):
+    def test_update_network(self):
         """Support for the Quantum core API call"""
-        LOG.debug("test_rename_network - START")
+        LOG.debug("test_update_network - START")
 
         self.net_id = db.network_create(tenant_id, net_name)[const.UUID]
+
         self._l2network_multiblade.create_network([tenant_id,
                                                    net_name,
                                                    self.net_id,
                                                    vlan_name(self.net_id),
                                                    vlan_id])
 
-        db.network_rename(tenant_id, self.net_id, new_net_name)
-        networks = self._l2network_multiblade.rename_network([tenant_id,
+        db.network_update(self.net_id, tenant_id, name=new_net_name)
+        networks = self._l2network_multiblade.update_network([tenant_id,
                                                    self.net_id,
-                                                   new_net_name])
+                                                   {'name': new_net_name}])
 
         self.assertEqual(networks.__len__(), self.ucs_count)
         for network in networks:
             self.assertEqual(network[const.NET_ID], self.net_id)
             self.assertEqual(network[const.NET_NAME], new_net_name)
-        LOG.debug("test_rename_network - END")
+        LOG.debug("test_update_network - END")
 
-    def test_rename_networkDNE(self):
+    def test_update_networkDNE(self):
         """Support for the Quantum core API call"""
-        LOG.debug("test_rename_networkDNE - START")
+        LOG.debug("test_update_networkDNE - START")
         self.assertRaises(exc.NetworkNotFound,
-                          self._l2network_multiblade.rename_network,
-                          [tenant_id, net_id, new_net_name])
-        LOG.debug("test_rename_networkDNE - END")
+                          self._l2network_multiblade.update_network,
+                          [tenant_id, net_id, {'name': new_net_name}])
+        LOG.debug("test_update_networkDNE - END")
 
     def test_get_all_networks(self):
         """Not implemented for this model"""
index bb8f4b2bd61a00e2cc83140c10984a0dfd47a62e..1892126cec3a9867b0953d0f79b2feced9f8fc38 100644 (file)
@@ -18,6 +18,7 @@ import logging
 import unittest
 from quantum.common import exceptions as exc
 from quantum.plugins.cisco.common import cisco_constants as const
+from quantum.plugins.cisco.common import cisco_credentials as creds
 from quantum.plugins.cisco.db import l2network_db as cdb
 from quantum.plugins.cisco.db import api as db
 from quantum.plugins.cisco.common import cisco_credentials as cred
@@ -38,6 +39,7 @@ class TestNexusPlugin(unittest.TestCase):
         self.vlan_name = "q-" + str(self.net_id) + "vlan"
         self.vlan_id = 267
         self.port_id = "9"
+        db.configure_db({'sql_connection': 'sqlite:///:memory:'})
         cdb.initialize()
         cred.Store.initialize()
         self._cisco_nexus_plugin = cisco_nexus_plugin.NexusPlugin()
@@ -175,13 +177,13 @@ class TestNexusPlugin(unittest.TestCase):
 
         LOG.debug("test_get_network_details_network_does_not_exist - END")
 
-    def test_rename_network(self, new_name="new_network_name",
+    def test_update_network(self, new_name="new_network_name",
                             net_tenant_id=None, network_name=None):
         """
-        Tests rename of a Virtual Network .
+        Tests update of a Virtual Network .
         """
 
-        LOG.debug("test_rename_network - START")
+        LOG.debug("test_update_network - START")
 
         if net_tenant_id:
             tenant_id = net_tenant_id
@@ -199,18 +201,18 @@ class TestNexusPlugin(unittest.TestCase):
                            tenant_id, self.net_name, network_created["net-id"],
                            self.vlan_name, self.vlan_id)
         rename_net_dict = self._cisco_nexus_plugin.rename_network(
-                        tenant_id, new_net_dict[const.NET_ID], new_name)
+                        tenant_id, new_net_dict[const.NET_ID], name=new_name)
         self.assertEqual(rename_net_dict[const.NET_NAME], new_name)
         self.tearDownNetwork(tenant_id, new_net_dict[const.NET_ID])
-        LOG.debug("test_rename_network - END")
+        LOG.debug("test_update_network - END")
 
-    def test_rename_network_DNE(self, new_name="new_network_name",
+    def test_update_network_DNE(self, new_name="new_network_name",
                                 net_tenant_id=None, network_id='0005'):
         """
-        Tests rename of a Virtual Network when Network does not exist.
+        Tests update of a Virtual Network when Network does not exist.
         """
 
-        LOG.debug("test_rename_network_DNE - START")
+        LOG.debug("test_update_network_DNE - START")
 
         if net_tenant_id:
             tenant_id = net_tenant_id
@@ -222,10 +224,10 @@ class TestNexusPlugin(unittest.TestCase):
             net_id = self.net_id
 
         self.assertRaises(exc.NetworkNotFound,
-                          self._cisco_nexus_plugin.rename_network,
-                          new_name, tenant_id, net_id)
+                          self._cisco_nexus_plugin.update_network,
+                          tenant_id, net_id, name=new_name)
 
-        LOG.debug("test_rename_network_DNE - END")
+        LOG.debug("test_update_network_DNE - END")
 
     def test_list_all_networks(self, net_tenant_id=None):
         """
index 06f380615fbd81c3b674f5acbd67c8bf5f0c72ea..2298fdb3ba18e4e5a7c24ac8ef2987d9914b10c7 100644 (file)
@@ -85,7 +85,7 @@ class TestUCSInventory(unittest.TestCase):
         LOG.debug("test_%s - START", cmd)
         net = self._l2network.create_network(tenant, net_name)
         port = self._l2network.create_port(tenant, net[const.NET_ID],
-                                           port_state)
+                                           port_state, state=port_state)
 
         args = [tenant, net[const.NET_ID], port[const.PORT_ID]]
         if params is not None:
@@ -156,9 +156,9 @@ class TestUCSInventory(unittest.TestCase):
         """Test that the UCS Inventory returns the correct devices to use"""
         self._test_get_all_ucms('get_network_details')
 
-    def test_rename_network(self):
+    def test_update_network(self):
         """Test that the UCS Inventory returns the correct devices to use"""
-        self._test_get_all_ucms('rename_network')
+        self._test_get_all_ucms('update_network')
 
     def test_get_all_ports(self):
         """Test that the UCS Inventory returns the correct devices to use"""
index 70e895f8a1d9aa0b14eea64a355778186d9b3a27..c164c258f94277581bcde1de689df2d4d0f30003 100644 (file)
@@ -139,8 +139,8 @@ class OVSQuantumPlugin(QuantumPluginBase):
         ports = self.get_all_ports(tenant_id, net_id)
         return self._make_net_dict(str(net.uuid), net.name, ports)
 
-    def rename_network(self, tenant_id, net_id, new_name):
-        net = db.network_rename(net_id, tenant_id, new_name)
+    def update_network(self, tenant_id, net_id, **kwargs):
+        net = db.network_update(net_id, tenant_id, **kwargs)
         return self._make_net_dict(str(net.uuid), net.name, None)
 
     def _make_port_dict(self, port_id, port_state, net_id, attachment):
@@ -170,13 +170,13 @@ class OVSQuantumPlugin(QuantumPluginBase):
         return self._make_port_dict(str(port.uuid), port.state,
                                         port.network_id, port.interface_id)
 
-    def update_port(self, tenant_id, net_id, port_id, port_state):
+    def update_port(self, tenant_id, net_id, port_id, **kwargs):
         """
         Updates the state of a port on the specified Virtual Network.
         """
         LOG.debug("update_port() called\n")
         port = db.port_get(port_id, net_id)
-        db.port_set_state(port_id, net_id, port_state)
+        db.port_update(port_id, net_id, **kwargs)
         return self._make_port_dict(str(port.uuid), port.state,
                                         port.network_id, port.interface_id)
 
index 151e139048d9dd4b829deeca07ce46727ffb3c86..156347259f124b382ab3bbfa9e5c22a89b0b7834 100644 (file)
@@ -63,12 +63,8 @@ class QuantumEchoPlugin(object):
         """
         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 update_network(self, tenant_id, net_id, **kwargs):
+        print("update_network() called")
 
     def get_all_ports(self, tenant_id, net_id):
         """
@@ -92,9 +88,9 @@ class QuantumEchoPlugin(object):
         """
         print("delete_port() called\n")
 
-    def update_port(self, tenant_id, net_id, port_id, port_state):
+    def update_port(self, tenant_id, net_id, port_id, **kwargs):
         """
-        Updates the state of a port on the specified Virtual Network.
+        Updates the attributes of a port on the specified Virtual Network.
         """
         print("update_port() called\n")
 
@@ -222,14 +218,12 @@ class FakePlugin(object):
         # Network not found
         raise exc.NetworkNotFound(net_id=net_id)
 
-    def rename_network(self, tenant_id, net_id, new_name):
+    def update_network(self, tenant_id, net_id, **kwargs):
         """
-        Updates the symbolic name belonging to a particular
-        Virtual Network.
+        Updates the attributes of a particular Virtual Network.
         """
-        LOG.debug("FakePlugin.rename_network() called")
-        db.network_rename(net_id, tenant_id, new_name)
-        net = self._get_network(tenant_id, net_id)
+        LOG.debug("FakePlugin.update_network() called")
+        net = db.network_update(net_id, tenant_id, **kwargs)
         return net
 
     def get_all_ports(self, tenant_id, net_id):
@@ -267,18 +261,17 @@ class FakePlugin(object):
         port_item = {'port-id': str(port.uuid)}
         return port_item
 
-    def update_port(self, tenant_id, net_id, port_id, new_state):
+    def update_port(self, tenant_id, net_id, port_id, **kwargs):
         """
-        Updates the state of a port on the specified Virtual Network.
+        Updates the attributes of a port on the specified Virtual Network.
         """
         LOG.debug("FakePlugin.update_port() called")
         #validate port and network ids
         self._get_network(tenant_id, net_id)
         self._get_port(tenant_id, net_id, port_id)
-        self._validate_port_state(new_state)
-        db.port_set_state(port_id, net_id, new_state)
+        port = db.port_update(port_id, net_id, **kwargs)
         port_item = {'port-id': port_id,
-                     'port-state': new_state}
+                     'port-state': port['state']}
         return port_item
 
     def delete_port(self, tenant_id, net_id, port_id):
index 9e53f5f3806d1f16336f5ccd932e3fe223c40240..6f81165a9fb43efe8c24690003cce684b542dbe7 100644 (file)
@@ -128,8 +128,8 @@ class Controller(common.QuantumController):
         except exc.HTTPError as e:
             return faults.Fault(e)
         try:
-            self._plugin.rename_network(tenant_id, id,
-                                        request_params['name'])
+            self._plugin.update_network(tenant_id, id,
+                                        **request_params)
             return exc.HTTPNoContent()
         except exception.NetworkNotFound as e:
             return faults.Fault(faults.NetworkNotFound(e))
index ef8b4207af6ff0dc04c2f37bb79f467e7a4bbf77..e2374a26abf50dac5081f29feada12e5b4d8d87c 100644 (file)
@@ -135,7 +135,7 @@ class Controller(common.QuantumController):
             return faults.Fault(e)
         try:
             self._plugin.update_port(tenant_id, network_id, id,
-                                     request_params['state'])
+                                     **request_params)
             return exc.HTTPNoContent()
         except exception.NetworkNotFound as e:
             return faults.Fault(faults.NetworkNotFound(e))
index 9ff738d2a8b19a40b9e3a29ff9409c2551ecb292..a1f32acb5772c75e1095ee27ebf45c2bbea8831d 100644 (file)
@@ -126,11 +126,13 @@ def network_get(net_id):
         raise q_exc.NetworkNotFound(net_id=net_id)
 
 
-def network_rename(net_id, tenant_id, new_name):
+def network_update(net_id, tenant_id, **kwargs):
     session = get_session()
     net = network_get(net_id)
-    _check_duplicate_net_name(tenant_id, new_name)
-    net.name = new_name
+    for key in kwargs.keys():
+        if key == "name":
+            _check_duplicate_net_name(tenant_id, kwargs[key])
+        net[key] = kwargs[key]
     session.merge(net)
     session.flush()
     return net
@@ -191,16 +193,16 @@ def port_get(port_id, net_id):
         raise q_exc.PortNotFound(net_id=net_id, port_id=port_id)
 
 
-def port_set_state(port_id, net_id, new_state):
-    if new_state not in ('ACTIVE', 'DOWN'):
-        raise q_exc.StateInvalid(port_state=new_state)
-
+def port_update(port_id, net_id, **kwargs):
     # confirm network exists
     network_get(net_id)
-
     port = port_get(port_id, net_id)
     session = get_session()
-    port.state = new_state
+    for key in kwargs.keys():
+        if key == "state":
+            if kwargs[key] not in ('ACTIVE', 'DOWN'):
+                raise q_exc.StateInvalid(port_state=kwargs[key])
+        port[key] = kwargs[key]
     session.merge(port)
     session.flush()
     return port
index 07281a020c574c5773d5fac71b82ffd9077f94af..07af86996c89d28b8789724cfd8cb1f60697731a 100644 (file)
@@ -103,10 +103,9 @@ class QuantumPluginBase(object):
         pass
 
     @abstractmethod
-    def rename_network(self, tenant_id, net_id, new_name):
+    def update_network(self, tenant_id, net_id, **kwargs):
         """
-        Updates the symbolic name belonging to a particular
-        Virtual Network.
+        Updates the attributes of a particular Virtual Network.
 
         :returns: a sequence of mappings representing the new network
                     attributes, with the following signature:
@@ -153,9 +152,9 @@ class QuantumPluginBase(object):
         pass
 
     @abstractmethod
-    def update_port(self, tenant_id, net_id, port_id, port_state):
+    def update_port(self, tenant_id, net_id, port_id, **kwargs):
         """
-        Updates the state of a specific port on the
+        Updates the attributes of a specific port on the
         specified Virtual Network.
 
         :returns: a mapping sequence with the following signature:
index 20712e2a3e71778a4fb2a21e56e7153075c38f55..d5728c17f8a307e025164c75150118ed074f864b 100644 (file)
@@ -84,17 +84,18 @@ class QuantumDB(object):
         except Exception, exc:
             LOG.error("Failed to delete network: %s", str(exc))
 
-    def rename_network(self, tenant_id, net_id, new_name):
+    def update_network(self, tenant_id, net_id, param_data):
         """Rename a network"""
         try:
-            net = db.network_rename(net_id, tenant_id, new_name)
-            LOG.debug("Renamed network: %s", net.uuid)
+            print param_data
+            net = db.network_update(net_id, tenant_id, **param_data)
+            LOG.debug("Updated network: %s", net.uuid)
             net_dict = {}
             net_dict["id"] = str(net.uuid)
             net_dict["name"] = net.name
             return net_dict
         except Exception, exc:
-            LOG.error("Failed to rename network: %s", str(exc))
+            LOG.error("Failed to update network: %s", str(exc))
 
     def get_all_ports(self, net_id):
         """Get all ports"""
@@ -153,10 +154,10 @@ class QuantumDB(object):
         except Exception, exc:
             LOG.error("Failed to delete port: %s", str(exc))
 
-    def update_port(self, net_id, port_id, port_state):
+    def update_port(self, net_id, port_id, **kwargs):
         """Update a port"""
         try:
-            port = db.port_set_state(net_id, port_id, port_state)
+            port = db.port_set_state(net_id, port_id, **kwargs)
             LOG.debug("Updated port %s", port.uuid)
             port_dict = {}
             port_dict["id"] = str(port.uuid)
index 0f5e4967e45d6478c9387aaea6286129a7be73b7..8c64021e68d5a869fb6c66e37e89d69a0f71af9a 100644 (file)
@@ -165,8 +165,8 @@ class APITest(unittest.TestCase):
         self.assertEqual(show_network_res.status_int, 420)
         LOG.debug("_test_show_network_not_found - format:%s - END", format)
 
-    def _test_rename_network(self, format):
-        LOG.debug("_test_rename_network - format:%s - START", format)
+    def _test_update_network(self, format):
+        LOG.debug("_test_update_network - format:%s - START", format)
         content_type = "application/%s" % format
         new_name = 'new_network_name'
         network_id = self._create_network(format)
@@ -186,10 +186,10 @@ class APITest(unittest.TestCase):
         self.assertEqual({'id': network_id,
                           'name': new_name},
                          network_data['network'])
-        LOG.debug("_test_rename_network - format:%s - END", format)
+        LOG.debug("_test_update_network - format:%s - END", format)
 
-    def _test_rename_network_badrequest(self, format):
-        LOG.debug("_test_rename_network_badrequest - format:%s - START",
+    def _test_update_network_badrequest(self, format):
+        LOG.debug("_test_update_network_badrequest - format:%s - START",
                   format)
         network_id = self._create_network(format)
         bad_body = {'network': {'bad-attribute': 'very-bad'}}
@@ -199,11 +199,11 @@ class APITest(unittest.TestCase):
                                                     custom_req_body=bad_body)
         update_network_res = update_network_req.get_response(self.api)
         self.assertEqual(update_network_res.status_int, 400)
-        LOG.debug("_test_rename_network_badrequest - format:%s - END",
+        LOG.debug("_test_update_network_badrequest - format:%s - END",
                   format)
 
-    def _test_rename_network_not_found(self, format):
-        LOG.debug("_test_rename_network_not_found - format:%s - START",
+    def _test_update_network_not_found(self, format):
+        LOG.debug("_test_update_network_not_found - format:%s - START",
                   format)
         new_name = 'new_network_name'
         update_network_req = testlib.update_network_request(self.tenant_id,
@@ -212,7 +212,7 @@ class APITest(unittest.TestCase):
                                                             format)
         update_network_res = update_network_req.get_response(self.api)
         self.assertEqual(update_network_res.status_int, 420)
-        LOG.debug("_test_rename_network_not_found - format:%s - END",
+        LOG.debug("_test_update_network_not_found - format:%s - END",
                   format)
 
     def _test_delete_network(self, format):
@@ -872,23 +872,23 @@ class APITest(unittest.TestCase):
     def test_delete_network_xml(self):
         self._test_delete_network('xml')
 
-    def test_rename_network_json(self):
-        self._test_rename_network('json')
+    def test_update_network_json(self):
+        self._test_update_network('json')
 
-    def test_rename_network_xml(self):
-        self._test_rename_network('xml')
+    def test_update_network_xml(self):
+        self._test_update_network('xml')
 
-    def test_rename_network_badrequest_json(self):
-        self._test_rename_network_badrequest('json')
+    def test_update_network_badrequest_json(self):
+        self._test_update_network_badrequest('json')
 
-    def test_rename_network_badrequest_xml(self):
-        self._test_rename_network_badrequest('xml')
+    def test_update_network_badrequest_xml(self):
+        self._test_update_network_badrequest('xml')
 
-    def test_rename_network_not_found_json(self):
-        self._test_rename_network_not_found('json')
+    def test_update_network_not_found_json(self):
+        self._test_update_network_not_found('json')
 
-    def test_rename_network_not_found_xml(self):
-        self._test_rename_network_not_found('xml')
+    def test_update_network_not_found_xml(self):
+        self._test_update_network_not_found('xml')
 
     def test_delete_network_in_use_json(self):
         self._test_delete_network_in_use('json')
index 001db667901d30be345d420d7a7b6cb6ecf55607..6638f062035e9146605b475781d420d0c75021cb 100644 (file)
@@ -95,13 +95,13 @@ class CLITest(unittest.TestCase):
             # Must add newline at the end to match effect of print call
             self.assertEquals(self.fake_stdout.make_string(), output + '\n')
 
-    def _verify_rename_network(self):
+    def _verify_update_network(self):
             # Verification - get raw result from db
             nw_list = db.network_list(self.tenant_id)
             network_data = {'id': nw_list[0].uuid,
                             'name': nw_list[0].name}
             # Fill CLI template
-            output = cli.prepare_output('rename_net', self.tenant_id,
+            output = cli.prepare_output('update_net', self.tenant_id,
                                         dict(network=network_data))
             # Verify!
             # Must add newline at the end to match effect of print call
@@ -158,12 +158,12 @@ class CLITest(unittest.TestCase):
             # Must add newline at the end to match effect of print call
             self.assertEquals(self.fake_stdout.make_string(), output + '\n')
 
-    def _verify_set_port_state(self, network_id, port_id):
+    def _verify_update_port(self, network_id, port_id):
             # Verification - get raw result from db
             port = db.port_get(port_id, network_id)
             port_data = {'id': port.uuid, 'state': port.state}
             # Fill CLI template
-            output = cli.prepare_output('set_port_state', self.tenant_id,
+            output = cli.prepare_output('update_port', self.tenant_id,
                                         dict(network_id=network_id,
                                              port=port_data))
             # Verify!
@@ -263,19 +263,19 @@ class CLITest(unittest.TestCase):
         LOG.debug(self.fake_stdout.content)
         self._verify_show_network()
 
-    def test_rename_network(self):
+    def test_update_network(self):
         try:
             net = db.network_create(self.tenant_id, self.network_name_1)
             network_id = net['uuid']
-            cli.rename_net(self.client, self.tenant_id,
-                           network_id, self.network_name_2)
+            cli.update_net(self.client, self.tenant_id,
+                           network_id, 'name=%s' % self.network_name_2)
         except:
             LOG.exception("Exception caught: %s", sys.exc_info())
-            self.fail("test_rename_network failed due to an exception")
+            self.fail("test_update_network failed due to an exception")
 
         LOG.debug("Operation completed. Verifying result")
         LOG.debug(self.fake_stdout.content)
-        self._verify_rename_network()
+        self._verify_update_network()
 
     def test_list_ports(self):
         try:
@@ -326,22 +326,22 @@ class CLITest(unittest.TestCase):
         LOG.debug(self.fake_stdout.content)
         self._verify_delete_port(network_id, port_id)
 
-    def test_set_port_state(self):
+    def test_update_port(self):
         try:
             net = db.network_create(self.tenant_id, self.network_name_1)
             network_id = net['uuid']
             port = db.port_create(network_id)
             port_id = port['uuid']
             # Default state is DOWN - change to ACTIVE.
-            cli.set_port_state(self.client, self.tenant_id, network_id,
-                               port_id, 'ACTIVE')
+            cli.update_port(self.client, self.tenant_id, network_id,
+                               port_id, 'state=ACTIVE')
         except:
             LOG.exception("Exception caught: %s", sys.exc_info())
-            self.fail("test_set_port_state failed due to an exception")
+            self.fail("test_update_port failed due to an exception")
 
         LOG.debug("Operation completed. Verifying result")
         LOG.debug(self.fake_stdout.content)
-        self._verify_set_port_state(network_id, port_id)
+        self._verify_update_port(network_id, port_id)
 
     def test_show_port_no_attach(self):
         network_id = None
index dae4f24664413606ac571c5267058bed582c730d..44ce0b56142a56fb4e1571a7ae67cd5855adf80f 100644 (file)
@@ -70,12 +70,13 @@ class QuantumDBTest(unittest.TestCase):
         count = len(nets)
         self.assertTrue(count == 0)
 
-    def testd_rename_network(self):
+    def testd_update_network(self):
         """test to rename network"""
         net1 = self.dbtest.create_network(self.tenant_id, "plugin_test1")
         self.assertTrue(net1["name"] == "plugin_test1")
-        net = self.dbtest.rename_network(self.tenant_id, net1["id"],
-          "plugin_test1_renamed")
+        net = self.dbtest.update_network(self.tenant_id, net1["id"],
+          {'name': "plugin_test1_renamed"})
+        print net
         self.assertTrue(net["name"] == "plugin_test1_renamed")
 
     def teste_create_port(self):