Fix rc cli to work with bay identifier

Fix replication controller cli to work with the bay identifier. As
part of object from bay changes we now create k8s objects per bay.
The server patches to take into consideration this change is in
review. This change passes bay_ident as a mandatory parameter to
the replication controller api's. Also, the URL is changed to
GET/PUT/POST/DEL data.

Partially-Implements: bp objects-from-bay

Change-Id: Ib65bac270da7056262000ffb2184af297e370daa
This commit is contained in:
Vilobh Meshram
2015-11-09 13:20:11 -08:00
parent 4d038e1a17
commit 64db5eed62
2 changed files with 36 additions and 23 deletions

View File

@@ -55,7 +55,14 @@ fake_responses = {
CREATE_RC,
),
},
'/v1/rcs/%s/%s' % (RC1['id'], RC1['bay_uuid']):
'/v1/rcs/?bay_ident=%s' % (RC1['bay_uuid']):
{
'GET': (
{},
{'rcs': [RC1, RC2]},
),
},
'/v1/rcs/%s/?bay_ident=%s' % (RC1['id'], RC1['bay_uuid']):
{
'GET': (
{},
@@ -70,7 +77,7 @@ fake_responses = {
UPDATED_RC,
),
},
'/v1/rcs/%s/%s' % (RC1['name'], RC1['bay_uuid']):
'/v1/rcs/%s/?bay_ident=%s' % (RC1['name'], RC1['bay_uuid']):
{
'GET': (
{},
@@ -106,7 +113,8 @@ class RCManagerTest(testtools.TestCase):
def test_rc_show_by_id(self):
rc = self.mgr.get(RC1['id'], RC1['bay_uuid'])
expect = [
('GET', '/v1/rcs/%s/%s' % (RC1['id'], RC1['bay_uuid']), {}, None)
('GET', '/v1/rcs/%s/?bay_ident=%s' % (RC1['id'],
RC1['bay_uuid']), {}, None)
]
self.assertEqual(expect, self.api.calls)
self.assertEqual(RC1['name'], rc.name)
@@ -116,8 +124,8 @@ class RCManagerTest(testtools.TestCase):
def test_rc_show_by_name(self):
rc = self.mgr.get(RC1['name'], RC1['bay_uuid'])
expect = [
('GET', '/v1/rcs/%s/%s' % (RC1['name'],
RC1['bay_uuid']), {}, None)
('GET', '/v1/rcs/%s/?bay_ident=%s' % (RC1['name'],
RC1['bay_uuid']), {}, None)
]
self.assertEqual(expect, self.api.calls)
self.assertEqual(RC1['name'], rc.name)
@@ -144,8 +152,9 @@ class RCManagerTest(testtools.TestCase):
def test_rc_delete_by_id(self):
rc = self.mgr.delete(RC1['id'], RC1['bay_uuid'])
expect = [
('DELETE', '/v1/rcs/%s/%s' % (RC1['id'],
RC1['bay_uuid']), {}, None),
('DELETE', '/v1/rcs/%s/?bay_ident=%s' % (RC1['id'],
RC1['bay_uuid']),
{}, None),
]
self.assertEqual(expect, self.api.calls)
self.assertIsNone(rc)
@@ -153,8 +162,9 @@ class RCManagerTest(testtools.TestCase):
def test_rc_delete_by_name(self):
rc = self.mgr.delete(RC1['name'], RC1['bay_uuid'])
expect = [
('DELETE', '/v1/rcs/%s/%s' % (RC1['name'],
RC1['bay_uuid']), {}, None),
('DELETE', '/v1/rcs/%s/?bay_ident=%s' % (RC1['name'],
RC1['bay_uuid']),
{}, None),
]
self.assertEqual(expect, self.api.calls)
self.assertIsNone(rc)
@@ -164,11 +174,12 @@ class RCManagerTest(testtools.TestCase):
'value': NEW_REPLICAS,
'path': '/replicas'}
rc = self.mgr.update(id=RC1['id'],
bay_uuid=RC1['bay_uuid'],
bay_ident=RC1['bay_uuid'],
patch=patch)
expect = [
('PATCH', '/v1/rcs/%s/%s' % (RC1['id'],
RC1['bay_uuid']), {}, patch),
('PATCH', '/v1/rcs/%s/?bay_ident=%s' % (RC1['id'],
RC1['bay_uuid']), {},
patch),
]
self.assertEqual(expect, self.api.calls)
self.assertEqual(NEW_REPLICAS, rc.replicas)

View File

@@ -29,9 +29,11 @@ class ReplicationControllerManager(base.Manager):
resource_class = ReplicationController
@staticmethod
def _path(id=None, bay_uuid=None):
if id and bay_uuid:
return '/v1/rcs/%s/%s' % (id, bay_uuid)
def _path(id=None, bay_ident=None):
if id and bay_ident:
return '/v1/rcs/%s/?bay_ident=%s' % (id, bay_ident)
elif bay_ident:
return '/v1/rcs/?bay_ident=%s' % (bay_ident)
else:
return '/v1/rcs'
@@ -76,14 +78,14 @@ class ReplicationControllerManager(base.Manager):
path += '?' + '&'.join(filters)
if limit is None:
return self._list(self._path(path), "rcs")
return self._list(self._path(bay_ident), "rcs")
else:
return self._list_pagination(self._path(path), "rcs",
return self._list_pagination(self._path(bay_ident), "rcs",
limit=limit)
def get(self, id, bay_uuid):
def get(self, id, bay_ident):
try:
return self._list(self._path(id, bay_uuid))[0]
return self._list(self._path(id, bay_ident))[0]
except IndexError:
return None
@@ -97,8 +99,8 @@ class ReplicationControllerManager(base.Manager):
"Key must be in %s" % ",".join(CREATION_ATTRIBUTES))
return self._create(self._path(), new)
def delete(self, id, bay_uuid):
return self._delete(self._path(id, bay_uuid))
def delete(self, id, bay_ident):
return self._delete(self._path(id, bay_ident))
def update(self, id, bay_uuid, patch):
return self._update(self._path(id, bay_uuid), patch)
def update(self, id, bay_ident, patch):
return self._update(self._path(id, bay_ident), patch)