Add try-except in _get_policy_profile_by_name to raise
proper PolicyProfileNameNotFound if profile not found in
database.
Also unittest is added.
Closes-bug: #
1393399
Change-Id: I3ab50a6870ff77a95e0977c75255e9cbd7286fbb
message = _("Policy Profile %(profile_id)s could not be found.")
+class PolicyProfileNameNotFound(exceptions.NotFound):
+ """Policy Profile with the given name cannot be found."""
+ message = _("Policy Profile %(profile_name)s could not be found.")
+
+
class NetworkProfileAlreadyExists(exceptions.NeutronException):
"""Network Profile cannot be created since it already exists."""
message = _("Network Profile %(profile_id)s "
"""
db_session = db.get_session()
with db_session.begin(subtransactions=True):
- return (db_session.query(n1kv_models_v2.PolicyProfile).
- filter_by(name=name).one())
+ try:
+ return (db_session.query(n1kv_models_v2.PolicyProfile).
+ filter_by(name=name).one())
+ except exc.NoResultFound:
+ raise c_exc.PolicyProfileNameNotFound(profile_name=name)
def _remove_all_fake_policy_profiles(self):
"""
# Request the list using admin and verify it returns
self._test_get_policy_profiles(expected_profiles=profiles, admin=True)
+ def test_get_policy_profiles_by_name(self):
+ with mock.patch(n1kv_client.__name__ + ".Client",
+ new=fake_client.TestClient):
+ instance = n1kv_neutron_plugin.N1kvNeutronPluginV2()
+ profile = instance._get_policy_profile_by_name('pp-1')
+ self.assertEqual('pp-1', profile['name'])
+ self.assertEqual('00000000-0000-0000-0000-000000000001',
+ profile['id'])
+ self.assertRaises(c_exc.PolicyProfileNameNotFound,
+ instance._get_policy_profile_by_name,
+ "name")
+
class TestN1kvNetworks(test_plugin.TestNetworksV2,
N1kvPluginTestCase):