Merge "Add support of rc resource management with "name""

This commit is contained in:
Jenkins 2015-03-19 05:10:48 +00:00 committed by Gerrit Code Review
commit cf3b8209a6
3 changed files with 46 additions and 14 deletions

View File

@ -69,6 +69,21 @@ fake_responses = {
UPDATED_RC,
),
},
'/v1/rcs/%s' % RC1['name']:
{
'GET': (
{},
RC1
),
'DELETE': (
{},
None,
),
'PATCH': (
{},
UPDATED_RC,
),
},
}
@ -87,7 +102,7 @@ class RCManagerTest(testtools.TestCase):
self.assertEqual(expect, self.api.calls)
self.assertThat(rcs, matchers.HasLength(2))
def test_rc_show(self):
def test_rc_show_by_id(self):
rc = self.mgr.get(RC1['id'])
expect = [
('GET', '/v1/rcs/%s' % RC1['id'], {}, None)
@ -96,6 +111,15 @@ class RCManagerTest(testtools.TestCase):
self.assertEqual(RC1['name'], rc.name)
self.assertEqual(RC1['replicas'], rc.replicas)
def test_rc_show_by_name(self):
rc = self.mgr.get(RC1['name'])
expect = [
('GET', '/v1/rcs/%s' % RC1['name'], {}, None)
]
self.assertEqual(expect, self.api.calls)
self.assertEqual(RC1['name'], rc.name)
self.assertEqual(RC1['replicas'], rc.replicas)
def test_rc_create(self):
rc = self.mgr.create(**CREATE_RC)
expect = [
@ -104,7 +128,7 @@ class RCManagerTest(testtools.TestCase):
self.assertEqual(expect, self.api.calls)
self.assertTrue(rc)
def test_rc_delete(self):
def test_rc_delete_by_id(self):
rc = self.mgr.delete(RC1['id'])
expect = [
('DELETE', '/v1/rcs/%s' % RC1['id'], {}, None),
@ -112,6 +136,14 @@ class RCManagerTest(testtools.TestCase):
self.assertEqual(expect, self.api.calls)
self.assertIsNone(rc)
def test_rc_delete_by_name(self):
rc = self.mgr.delete(RC1['name'])
expect = [
('DELETE', '/v1/rcs/%s' % RC1['name'], {}, None),
]
self.assertEqual(expect, self.api.calls)
self.assertIsNone(rc)
def test_rc_update(self):
patch = {'op': 'replace',
'value': NEW_REPLICAS,

View File

@ -211,7 +211,7 @@ class ShellTest(base.TestCase):
client_mock = mock.MagicMock()
args = mock.MagicMock()
rc_id = 'id'
args.id = [rc_id]
args.rcs = [rc_id]
shell.do_rc_delete(client_mock, args)
client_mock.rcs.delete.assert_called_once_with(rc_id)
@ -220,7 +220,7 @@ class ShellTest(base.TestCase):
client_mock = mock.MagicMock()
args = mock.MagicMock()
rc_id = 'id'
args.id = rc_id
args.rc = rc_id
shell.do_rc_show(client_mock, args)
client_mock.rcs.get.assert_called_once_with(rc_id)

View File

@ -332,26 +332,26 @@ def do_rc_create(cs, args):
_show_rc(rc)
@utils.arg('id',
metavar='<rc_id>',
@utils.arg('rcs',
metavar='<rcs>',
nargs='+',
help='ID of the replication (controller)s to delete.')
help='ID or name of the replication (controller)s to delete.')
def do_rc_delete(cs, args):
"""Delete specified replication controller."""
for id in args.id:
for rc in args.rcs:
try:
cs.rcs.delete(id)
cs.rcs.delete(rc)
except Exception as e:
print("Delete for rc %(rc)s failed: %(e)s" %
{'rc': id, 'e': e})
{'rc': rc, 'e': e})
@utils.arg('id',
metavar='<rc_id>',
help='ID of the replication controller to show.')
@utils.arg('rc',
metavar='<rc>',
help='ID or name of the replication controller to show.')
def do_rc_show(cs, args):
"""Show details about the given replication controller."""
rc = cs.rcs.get(args.id)
rc = cs.rcs.get(args.rc)
_show_rc(rc)