diff --git a/neutron/plugins/cisco/db/network_db_v2.py b/neutron/plugins/cisco/db/network_db_v2.py index 94c5a37de76..1a4f997cab2 100644 --- a/neutron/plugins/cisco/db/network_db_v2.py +++ b/neutron/plugins/cisco/db/network_db_v2.py @@ -187,6 +187,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() diff --git a/neutron/plugins/cisco/n1kv/n1kv_neutron_plugin.py b/neutron/plugins/cisco/n1kv/n1kv_neutron_plugin.py index d31e5f26506..c7fc11e5703 100644 --- a/neutron/plugins/cisco/n1kv/n1kv_neutron_plugin.py +++ b/neutron/plugins/cisco/n1kv/n1kv_neutron_plugin.py @@ -112,8 +112,9 @@ def __init__(self, configfile=None): 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 = { @@ -122,6 +123,7 @@ def __init__(self, configfile=None): # 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() diff --git a/neutron/tests/unit/cisco/test_network_db.py b/neutron/tests/unit/cisco/test_network_db.py index ef09c81c2a8..931f85b5b79 100644 --- a/neutron/tests/unit/cisco/test_network_db.py +++ b/neutron/tests/unit/cisco/test_network_db.py @@ -262,6 +262,33 @@ def test_get_credential_not_found_exception(self): 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):