Merge "Remove wrong reference to object attribute in nvplib"

This commit is contained in:
Jenkins 2013-06-13 20:38:11 +00:00 committed by Gerrit Code Review
commit a78207e574
2 changed files with 105 additions and 16 deletions

View File

@ -381,8 +381,9 @@ def create_l2_gw_service(cluster, tenant_id, display_name, devices):
json.dumps(gwservice_obj), cluster=cluster))
except NvpApiClient.NvpApiException:
# just log and re-raise - let the caller handle it
LOG.exception(_("An exception occured while communicating with "
"the NVP controller for cluster:%s"), cluster.name)
LOG.exception(_("Unable to create L2 Gateway Service "
"%(name)s for tenant %(id)s.")
% {'name': display_name, 'id': tenant_id})
raise
@ -419,8 +420,9 @@ def create_lrouter(cluster, tenant_id, display_name, nexthop):
cluster=cluster))
except NvpApiClient.NvpApiException:
# just log and re-raise - let the caller handle it
LOG.exception(_("An exception occured while communicating with "
"the NVP controller for cluster:%s"), cluster.name)
LOG.exception(_("Unable to create Router "
"%(name)s for tenant %(id)s.")
% {'name': display_name, 'id': tenant_id})
raise
@ -432,8 +434,8 @@ def delete_lrouter(cluster, lrouter_id):
cluster=cluster)
except NvpApiClient.NvpApiException:
# just log and re-raise - let the caller handle it
LOG.exception(_("An exception occured while communicating with "
"the NVP controller for cluster:%s"), cluster.name)
LOG.exception(_("Unable to delete Router "
"Service %s."), lrouter_id)
raise
@ -445,8 +447,8 @@ def delete_l2_gw_service(cluster, gateway_id):
cluster=cluster)
except NvpApiClient.NvpApiException:
# just log and re-raise - let the caller handle it
LOG.exception(_("An exception occured while communicating with "
"the NVP controller for cluster:%s"), cluster.name)
LOG.exception(_("Unable to delete L2 Gateway "
"Service %s."), gateway_id)
raise
@ -459,8 +461,8 @@ def get_lrouter(cluster, lrouter_id):
cluster=cluster))
except NvpApiClient.NvpApiException:
# just log and re-raise - let the caller handle it
LOG.exception(_("An exception occured while communicating with "
"the NVP controller for cluster:%s"), cluster.name)
LOG.exception(_("Unable to get Router "
"Service %s."), lrouter_id)
raise
@ -472,8 +474,8 @@ def get_l2_gw_service(cluster, gateway_id):
cluster=cluster))
except NvpApiClient.NvpApiException:
# just log and re-raise - let the caller handle it
LOG.exception(_("An exception occured while communicating with "
"the NVP controller for cluster:%s"), cluster.name)
LOG.exception(_("Unable to get L2 Gateway "
"Service %s."), gateway_id)
raise
@ -520,8 +522,9 @@ def update_l2_gw_service(cluster, gateway_id, display_name):
cluster=cluster))
except NvpApiClient.NvpApiException:
# just log and re-raise - let the caller handle it
LOG.exception(_("An exception occured while communicating with "
"the NVP controller for cluster:%s"), cluster.name)
LOG.exception(_("Unable to update L2 Gateway Service "
"%(id)s with name %(name)s.") %
{'id': gateway_id, 'name': display_name})
raise
@ -546,8 +549,9 @@ def update_lrouter(cluster, lrouter_id, display_name, nexthop):
cluster=cluster))
except NvpApiClient.NvpApiException:
# just log and re-raise - let the caller handle it
LOG.exception(_("An exception occured while communicating with "
"the NVP controller for cluster:%s"), cluster.name)
LOG.exception(_("Unable to update Router "
"%(id)s with name %(name)s.") %
{'id': lrouter_id, 'name': display_name})
raise

View File

@ -94,6 +94,91 @@ class TestNvplibNatRules(NvplibTestCase):
resp_obj['match']['destination_ip_addresses'])
class NvplibNegativeTests(base.BaseTestCase):
def setUp(self):
# mock nvp api client
etc_path = os.path.join(os.path.dirname(__file__), 'etc')
self.fc = fake_nvpapiclient.FakeClient(etc_path)
self.mock_nvpapi = mock.patch('%s.NvpApiClient.NVPApiHelper'
% NICIRA_PKG_PATH, autospec=True)
instance = self.mock_nvpapi.start()
instance.return_value.login.return_value = "the_cookie"
def _faulty_request(*args, **kwargs):
raise nvplib.NvpApiClient.NvpApiException
instance.return_value.request.side_effect = _faulty_request
self.fake_cluster = nvp_cluster.NVPCluster(
name='fake-cluster', nvp_controllers=['1.1.1.1:999'],
default_tz_uuid=_uuid(), nvp_user='foo', nvp_password='bar')
self.fake_cluster.api_client = NvpApiClient.NVPApiHelper(
('1.1.1.1', '999', True),
self.fake_cluster.nvp_user, self.fake_cluster.nvp_password,
self.fake_cluster.req_timeout, self.fake_cluster.http_timeout,
self.fake_cluster.retries, self.fake_cluster.redirects)
super(NvplibNegativeTests, self).setUp()
self.addCleanup(self.fc.reset_all)
self.addCleanup(self.mock_nvpapi.stop)
def test_create_l2_gw_service_on_failure(self):
self.assertRaises(nvplib.NvpApiClient.NvpApiException,
nvplib.create_l2_gw_service,
self.fake_cluster,
'fake-tenant',
'fake-gateway',
[{'id': _uuid(),
'interface_name': 'xxx'}])
def test_delete_l2_gw_service_on_failure(self):
self.assertRaises(nvplib.NvpApiClient.NvpApiException,
nvplib.delete_l2_gw_service,
self.fake_cluster,
'fake-gateway')
def test_get_l2_gw_service_on_failure(self):
self.assertRaises(nvplib.NvpApiClient.NvpApiException,
nvplib.get_l2_gw_service,
self.fake_cluster,
'fake-gateway')
def test_update_l2_gw_service_on_failure(self):
self.assertRaises(nvplib.NvpApiClient.NvpApiException,
nvplib.update_l2_gw_service,
self.fake_cluster,
'fake-gateway',
'pluto')
def test_create_lrouter_on_failure(self):
self.assertRaises(nvplib.NvpApiClient.NvpApiException,
nvplib.create_lrouter,
self.fake_cluster,
'pluto',
'fake_router',
'my_hop')
def test_delete_lrouter_on_failure(self):
self.assertRaises(nvplib.NvpApiClient.NvpApiException,
nvplib.delete_lrouter,
self.fake_cluster,
'fake_router')
def test_get_lrouter_on_failure(self):
self.assertRaises(nvplib.NvpApiClient.NvpApiException,
nvplib.get_lrouter,
self.fake_cluster,
'fake_router')
def test_update_lrouter_on_failure(self):
self.assertRaises(nvplib.NvpApiClient.NvpApiException,
nvplib.update_lrouter,
self.fake_cluster,
'fake_router',
'pluto',
'new_hop')
class NvplibL2GatewayTestCase(NvplibTestCase):
def _create_gw_service(self, node_uuid, display_name):