Fixed nwalib.client.create_tenant
Return success only if status code is 200 or 500, otherwise raises AgentProxyException. Change-Id: I06dae271fb19624a582a3adf0284de22ecad5ad4 Closes-Bug: #1548812
This commit is contained in:
parent
1e8bf7394e
commit
65b2e1ae8e
|
@ -56,15 +56,13 @@ class AgentProxyTenant(object):
|
|||
"""
|
||||
nwa_tenant_id = kwargs.get('nwa_tenant_id')
|
||||
|
||||
# ignore result
|
||||
self.client.tenant.create_tenant(nwa_tenant_id)
|
||||
# NOTE(amotoki): At now this method never fails.
|
||||
# If we need to handle a failure, raise nwa_exc.AgentProxyException
|
||||
# and catch the exception in a caller.
|
||||
return {
|
||||
'CreateTenant': True,
|
||||
'NWA_tenant_id': nwa_tenant_id
|
||||
}
|
||||
status_code, __data = self.client.tenant.create_tenant(nwa_tenant_id)
|
||||
if status_code in (200, 500): # success(200), already exists(500)
|
||||
return {
|
||||
'CreateTenant': True,
|
||||
'NWA_tenant_id': nwa_tenant_id
|
||||
}
|
||||
raise nwa_exc.AgentProxyException(value=status_code)
|
||||
|
||||
@utils.log_method_return_value
|
||||
def delete_tenant(self, context, **kwargs):
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
|
||||
import mock
|
||||
|
||||
from networking_nec.nwa.common import exceptions as nwa_exc
|
||||
from networking_nec.tests.unit.nwa.agent import base
|
||||
|
||||
|
||||
|
@ -34,9 +35,9 @@ class TestAgentProxyTenant(base.TestNWAAgentBase):
|
|||
}
|
||||
self.assertEqual(exp_data, body)
|
||||
|
||||
def test__create_tenant_failed(self):
|
||||
def test__create_tenant_already_exists(self):
|
||||
nwa_tenant_id = 'DC1_844eb55f21e84a289e9c22098d387e5d'
|
||||
self.nwacli.tenant.create_tenant.return_value = 400, {}
|
||||
self.nwacli.tenant.create_tenant.return_value = 500, {}
|
||||
body = self.agent.proxy_tenant.create_tenant(
|
||||
mock.sentinel.context,
|
||||
nwa_tenant_id=nwa_tenant_id
|
||||
|
@ -47,6 +48,17 @@ class TestAgentProxyTenant(base.TestNWAAgentBase):
|
|||
}
|
||||
self.assertEqual(exp_data, body)
|
||||
|
||||
def test__create_tenant_failed(self):
|
||||
nwa_tenant_id = 'DC1_844eb55f21e84a289e9c22098d387e5d'
|
||||
self.nwacli.tenant.create_tenant.return_value = 400, {}
|
||||
e = self.assertRaises(
|
||||
nwa_exc.AgentProxyException,
|
||||
self.agent.proxy_tenant.create_tenant,
|
||||
mock.sentinel.context,
|
||||
nwa_tenant_id=nwa_tenant_id
|
||||
)
|
||||
self.assertEqual(400, e.value)
|
||||
|
||||
def test__delete_tenant(self):
|
||||
nwa_tenant_id = 'DC1_844eb55f21e84a289e9c22098d387e5d'
|
||||
nwa_data = self.agent.proxy_tenant.delete_tenant(
|
||||
|
|
Loading…
Reference in New Issue