Add error info detail for magnum cli.

Change-Id: I8c73a9204a4ce17c67ebf3ea09e5930eb43508a7
Closes-Bug: #1443442
This commit is contained in:
Fang fenghua 2015-04-13 14:44:31 +00:00 committed by Fang Fenghua
parent 59729557b9
commit 8ada9281c8
14 changed files with 84 additions and 8 deletions

View File

@ -17,10 +17,10 @@ import copy
import testtools
from testtools import matchers
from magnumclient import exceptions
from magnumclient.tests import utils
from magnumclient.v1 import baymodels
BAYMODEL1 = {'id': 123,
'uuid': '66666666-7777-8888-9999-000000000001',
'name': 'baymodel1',
@ -166,6 +166,15 @@ class BayModelManagerTest(testtools.TestCase):
self.assertEqual(BAYMODEL1['docker_volume_size'],
baymodel.docker_volume_size)
def test_baymodel_create_fail(self):
CREATE_BAYMODEL_FAIL = copy.deepcopy(CREATE_BAYMODEL)
CREATE_BAYMODEL_FAIL["wrong_key"] = "wrong"
self.assertRaisesRegexp(exceptions.InvalidAttribute,
("Key must be in %s" %
','.join(baymodels.CREATION_ATTRIBUTES)),
self.mgr.create, **CREATE_BAYMODEL_FAIL)
self.assertEqual([], self.api.calls)
def test_baymodel_delete_by_id(self):
baymodel = self.mgr.delete(BAYMODEL1['id'])
expect = [

View File

@ -17,6 +17,7 @@ import copy
import testtools
from testtools import matchers
from magnumclient import exceptions
from magnumclient.tests import utils
from magnumclient.v1 import bays
@ -137,6 +138,15 @@ class BayManagerTest(testtools.TestCase):
self.assertEqual(expect, self.api.calls)
self.assertTrue(bay)
def test_bay_create_fail(self):
CREATE_BAY_FAIL = copy.deepcopy(CREATE_BAY)
CREATE_BAY_FAIL["wrong_key"] = "wrong"
self.assertRaisesRegexp(exceptions.InvalidAttribute,
("Key must be in %s" %
','.join(bays.CREATION_ATTRIBUTES)),
self.mgr.create, **CREATE_BAY_FAIL)
self.assertEqual([], self.api.calls)
def test_bay_delete_by_id(self):
bay = self.mgr.delete(BAY1['id'])
expect = [

View File

@ -17,6 +17,7 @@ import copy
import testtools
from testtools import matchers
from magnumclient import exceptions
from magnumclient.tests import utils
from magnumclient.v1 import containers
@ -151,6 +152,15 @@ class ContainerManagerTest(testtools.TestCase):
self.assertEqual(expect, self.api.calls)
self.assertTrue(container)
def test_container_create_fail(self):
CREATE_CONTAINER_FAIL = copy.deepcopy(CREATE_CONTAINER)
CREATE_CONTAINER_FAIL["wrong_key"] = "wrong"
self.assertRaisesRegexp(exceptions.InvalidAttribute,
("Key must be in %s" %
','.join(containers.CREATION_ATTRIBUTES)),
self.mgr.create, **CREATE_CONTAINER_FAIL)
self.assertEqual([], self.api.calls)
def test_container_delete(self):
container = self.mgr.delete(CONTAINER1['id'])
expect = [

View File

@ -17,6 +17,7 @@ import copy
import testtools
from testtools import matchers
from magnumclient import exceptions
from magnumclient.tests import utils
from magnumclient.v1 import nodes
@ -105,6 +106,15 @@ class NodeManagerTest(testtools.TestCase):
self.assertEqual(expect, self.api.calls)
self.assertTrue(node)
def test_node_create_fail(self):
CREATE_NODE_FAIL = copy.deepcopy(CREATE_NODE)
CREATE_NODE_FAIL["wrong_key"] = "wrong"
self.assertRaisesRegexp(exceptions.InvalidAttribute,
("Key must be in %s" %
','.join(nodes.CREATION_ATTRIBUTES)),
self.mgr.create, **CREATE_NODE_FAIL)
self.assertEqual([], self.api.calls)
def test_node_delete(self):
node = self.mgr.delete(NODE1['id'])
expect = [

View File

@ -17,6 +17,7 @@ import copy
import testtools
from testtools import matchers
from magnumclient import exceptions
from magnumclient.tests import utils
from magnumclient.v1 import pods
@ -130,6 +131,15 @@ class PodManagerTest(testtools.TestCase):
self.assertEqual(expect, self.api.calls)
self.assertTrue(pod)
def test_pod_create_fail(self):
CREATE_POD_FAIL = copy.deepcopy(CREATE_POD)
CREATE_POD_FAIL["wrong_key"] = "wrong"
self.assertRaisesRegexp(exceptions.InvalidAttribute,
("Key must be in %s" %
','.join(pods.CREATION_ATTRIBUTES)),
self.mgr.create, **CREATE_POD_FAIL)
self.assertEqual([], self.api.calls)
def test_pod_delete_by_id(self):
pod = self.mgr.delete(POD1['id'])
expect = [

View File

@ -17,6 +17,7 @@ import copy
import testtools
from testtools import matchers
from magnumclient import exceptions
from magnumclient.tests import utils
from magnumclient.v1 import replicationcontrollers as rcs
@ -128,6 +129,15 @@ class RCManagerTest(testtools.TestCase):
self.assertEqual(expect, self.api.calls)
self.assertTrue(rc)
def test_rc_create_fail(self):
CREATE_RC_FAIL = copy.deepcopy(CREATE_RC)
CREATE_RC_FAIL["wrong_key"] = "wrong"
self.assertRaisesRegexp(exceptions.InvalidAttribute,
("Key must be in %s" %
','.join(rcs.CREATION_ATTRIBUTES)),
self.mgr.create, **CREATE_RC_FAIL)
self.assertEqual([], self.api.calls)
def test_rc_delete_by_id(self):
rc = self.mgr.delete(RC1['id'])
expect = [

View File

@ -17,6 +17,7 @@ import copy
import testtools
from testtools import matchers
from magnumclient import exceptions
from magnumclient.tests import utils
from magnumclient.v1 import services
@ -130,6 +131,15 @@ class ServiceManagerTest(testtools.TestCase):
self.assertEqual(expect, self.api.calls)
self.assertTrue(service)
def test_service_create_fail(self):
CREATE_SVC_FAIL = copy.deepcopy(CREATE_SVC)
CREATE_SVC_FAIL["wrong_key"] = "wrong"
self.assertRaisesRegexp(exceptions.InvalidAttribute,
("Key must be in %s" %
','.join(services.CREATION_ATTRIBUTES)),
self.mgr.create, **CREATE_SVC_FAIL)
self.assertEqual([], self.api.calls)
def test_service_delete_by_id(self):
service = self.mgr.delete(SERVICE1['id'])
expect = [

View File

@ -89,7 +89,8 @@ class BayModelManager(base.Manager):
if key in CREATION_ATTRIBUTES:
new[key] = value
else:
raise exceptions.InvalidAttribute()
raise exceptions.InvalidAttribute(
"Key must be in %s" % ",".join(CREATION_ATTRIBUTES))
return self._create(self._path(), new)
def delete(self, id):

View File

@ -88,7 +88,8 @@ class BayManager(base.Manager):
if key in CREATION_ATTRIBUTES:
new[key] = value
else:
raise exceptions.InvalidAttribute()
raise exceptions.InvalidAttribute(
"Key must be in %s" % ",".join(CREATION_ATTRIBUTES))
return self._create(self._path(), new)
def delete(self, id):

View File

@ -94,7 +94,8 @@ class ContainerManager(base.Manager):
if key in CREATION_ATTRIBUTES:
new[key] = value
else:
raise exceptions.InvalidAttribute()
raise exceptions.InvalidAttribute(
"Key must be in %s" % ','.join(CREATION_ATTRIBUTES))
return self._create(self._path(), new)
def delete(self, id):

View File

@ -88,7 +88,8 @@ class NodeManager(base.Manager):
if key in CREATION_ATTRIBUTES:
new[key] = value
else:
raise exceptions.InvalidAttribute()
raise exceptions.InvalidAttribute(
"Key must be in %s" % ",".join(CREATION_ATTRIBUTES))
return self._create(self._path(), new)
def delete(self, id):

View File

@ -88,7 +88,8 @@ class PodManager(base.Manager):
if key in CREATION_ATTRIBUTES:
new[key] = value
else:
raise exceptions.InvalidAttribute()
raise exceptions.InvalidAttribute(
"Key must be in %s" % ",".join(CREATION_ATTRIBUTES))
return self._create(self._path(), new)
def delete(self, id):

View File

@ -88,7 +88,8 @@ class ReplicationControllerManager(base.Manager):
if key in CREATION_ATTRIBUTES:
new[key] = value
else:
raise exceptions.InvalidAttribute()
raise exceptions.InvalidAttribute(
"Key must be in %s" % ",".join(CREATION_ATTRIBUTES))
return self._create(self._path(), new)
def delete(self, id):

View File

@ -87,7 +87,8 @@ class ServiceManager(base.Manager):
if key in CREATION_ATTRIBUTES:
new[key] = value
else:
raise exceptions.InvalidAttribute()
raise exceptions.InvalidAttribute(
"Key must be in %s" % ",".join(CREATION_ATTRIBUTES))
return self._create(self._path(), new)
def delete(self, service_id):