]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
update vsm credential correctly
authoraaronzhang231 <fenzhang@cisco.com>
Tue, 15 Jul 2014 00:04:17 +0000 (17:04 -0700)
committeraaronzhang231 <fenzhang@cisco.com>
Tue, 15 Jul 2014 17:50:12 +0000 (10:50 -0700)
Today if we modify the n1kv VSM credential in the cisco_plugins.ini, the
older VSM ip address remains in the db, and all requests are sent to
the older VSM. This patch deletes all n1kv VSM credentials on neutron
start up before adding the newer VSM credentials. Hence making sure
that there is only one n1kv VSM IP address and credential in the db.

Change-Id: I772a86bf896a1d3d9c69c545ce6918b0fe3a2e48
Closes-Bug: #1341014

neutron/plugins/cisco/db/network_db_v2.py
neutron/plugins/cisco/n1kv/n1kv_neutron_plugin.py
neutron/tests/unit/cisco/test_network_db.py

index 350950e175a4dede178189dda569f96585ecfc29..e7adf1a92d541df7fe643e3aa475fc8f1e6c3baa 100644 (file)
@@ -185,6 +185,11 @@ def get_all_n1kv_credentials():
             filter_by(type='n1kv'))
 
 
+def delete_all_n1kv_credentials():
+    session = db.get_session()
+    session.query(network_models_v2.Credential).filter_by(type='n1kv').delete()
+
+
 def add_provider_network(network_id, network_type, segmentation_id):
     """Add a network to the provider network table."""
     session = db.get_session()
index 6e259ccc17e23e43c63e9b55b54ce260726fdb2b..73ef2779c3274f20b406afd0de68306270e278bb 100644 (file)
@@ -100,8 +100,9 @@ class N1kvNeutronPluginV2(db_base_plugin_v2.NeutronDbPluginV2,
         Initialize Nexus1000V Neutron plugin.
 
         1. Initialize VIF type to OVS
-        2. Initialize Nexus1000v and Credential DB
-        3. Establish communication with Cisco Nexus1000V
+        2. clear N1kv credential
+        3. Initialize Nexus1000v and Credential DB
+        4. Establish communication with Cisco Nexus1000V
         """
         super(N1kvNeutronPluginV2, self).__init__()
         self.base_binding_dict = {
@@ -110,6 +111,7 @@ class N1kvNeutronPluginV2(db_base_plugin_v2.NeutronDbPluginV2,
                 # TODO(rkukura): Replace with new VIF security details
                 portbindings.CAP_PORT_FILTER:
                 'security-group' in self.supported_extension_aliases}}
+        network_db_v2.delete_all_n1kv_credentials()
         c_cred.Store.initialize()
         self._setup_vsm()
         self._setup_rpc()
index ef09c81c2a89e3bcb4b813c6e0e299e837e47198..931f85b5b7960ecf8c5799635b9e68782396fc3f 100644 (file)
@@ -262,6 +262,33 @@ class CiscoNetworkCredentialDbTest(CiscoNetworkDbTest):
                           self._network_plugin.get_credential_details,
                           "dummyCredentialId")
 
+    def test_credential_delete_all_n1kv(self):
+        cred_nexus_1 = self._cred_test_obj('nexus', 1)
+        cred_nexus_2 = self._cred_test_obj('nexus', 2)
+        cred_n1kv_1 = self.CredObj('n1kv-1', 'cisco', '123456', 'n1kv')
+        cred_n1kv_2 = self.CredObj('n1kv-2', 'cisco', '123456', 'n1kv')
+        cred_nexus_1_id = cdb.add_credential(
+            cred_nexus_1.cname, cred_nexus_1.usr,
+            cred_nexus_1.pwd, cred_nexus_1.ctype).credential_id
+        cred_nexus_2_id = cdb.add_credential(
+            cred_nexus_2.cname, cred_nexus_2.usr,
+            cred_nexus_2.pwd, cred_nexus_2.ctype).credential_id
+        cred_n1kv_1_id = cdb.add_credential(
+            cred_n1kv_1.cname, cred_n1kv_1.usr,
+            cred_n1kv_1.pwd, cred_n1kv_1.ctype).credential_id
+        cred_n1kv_2_id = cdb.add_credential(
+            cred_n1kv_2.cname, cred_n1kv_2.usr,
+            cred_n1kv_2.pwd, cred_n1kv_2.ctype).credential_id
+        cdb.delete_all_n1kv_credentials()
+        cred = cdb.get_credential(cred_nexus_1_id)
+        self.assertIsNotNone(cred)
+        cred = cdb.get_credential(cred_nexus_2_id)
+        self.assertIsNotNone(cred)
+        self.assertRaises(c_exc.CredentialNotFound,
+                          cdb.get_credential, cred_n1kv_1_id)
+        self.assertRaises(c_exc.CredentialNotFound,
+                          cdb.get_credential, cred_n1kv_2_id)
+
 
 class CiscoCredentialStoreTest(base.BaseTestCase):