Return complete response from compute/keypairs_client

Currently compute keypairs_client returns Response by removing
top key from Response.
For example- return service_client.ResponseBody(resp, body['keypair'])

As service clients are in direction to move to Tempest-lib, all
service clients should return Response without any truncation.
One good example is Resource pagination links which are lost with current
way of return value. Resource pagination links are present in parallel
(not inside) to top key of Response.

This patch makes compute keypairs_client to return complete Response body.

Change-Id: I5bbc2c15155e6a25da7c44d00d5ac1214c0462bf
Implements: blueprint method-return-value-and-move-service-clients-to-lib
This commit is contained in:
ghanshyam
2015-08-17 11:41:47 +09:00
parent eb87b44c5a
commit dee01f2f28
10 changed files with 21 additions and 27 deletions

View File

@@ -33,6 +33,6 @@ class BaseKeypairTest(base.BaseComputeTest):
kwargs = {'name': keypair_name}
if pub_key:
kwargs.update({'public_key': pub_key})
body = self.client.create_keypair(**kwargs)
body = self.client.create_keypair(**kwargs)['keypair']
self.addCleanup(self._delete_keypair, keypair_name)
return body

View File

@@ -34,9 +34,7 @@ class KeyPairsV2TestJSON(base.BaseKeypairTest):
key_list.append(keypair)
# Fetch all keypairs and verify the list
# has all created keypairs
fetched_list = self.client.list_keypairs()
# We need to remove the extra 'keypair' element in the
# returned dict. See comment in keypairs_client.list_keypairs()
fetched_list = self.client.list_keypairs()['keypairs']
new_list = list()
for keypair in fetched_list:
new_list.append(keypair['keypair'])
@@ -65,7 +63,7 @@ class KeyPairsV2TestJSON(base.BaseKeypairTest):
# Keypair should be created, Got details by name and deleted
k_name = data_utils.rand_name('keypair')
self._create_keypair(k_name)
keypair_detail = self.client.show_keypair(k_name)
keypair_detail = self.client.show_keypair(k_name)['keypair']
self.assertIn('name', keypair_detail)
self.assertIn('public_key', keypair_detail)
self.assertEqual(keypair_detail['name'], k_name,

View File

@@ -96,7 +96,7 @@ class BaseOrchestrationTest(tempest.test.BaseTestCase):
@classmethod
def _create_keypair(cls, name_start='keypair-heat-'):
kp_name = data_utils.rand_name(name_start)
body = cls.keypairs_client.create_keypair(name=kp_name)
body = cls.keypairs_client.create_keypair(name=kp_name)['keypair']
cls.keypairs.append(kp_name)
return body

View File

@@ -245,7 +245,7 @@ class KeyPairService(BaseService):
def list(self):
client = self.client
keypairs = client.list_keypairs()
keypairs = client.list_keypairs()['keypairs']
LOG.debug("List count, %s Keypairs" % len(keypairs))
return keypairs

View File

@@ -48,8 +48,8 @@ def create_validation_resources(os, validation_resources=None):
if validation_resources:
if validation_resources['keypair']:
keypair_name = data_utils.rand_name('keypair')
validation_data['keypair'] = \
os.keypairs_client.create_keypair(name=keypair_name)
validation_data.update(os.keypairs_client.create_keypair(
name=keypair_name))
LOG.debug("Validation resource key %s created" % keypair_name)
add_rule = False
if validation_resources['security_group']:

View File

@@ -142,7 +142,7 @@ class ScenarioTest(tempest.test.BaseTestCase):
# We don't need to create a keypair by pubkey in scenario
body = client.create_keypair(name=name)
self.addCleanup(client.delete_keypair, name)
return body
return body['keypair']
def create_server(self, name=None, image=None, flavor=None,
wait_on_boot=True, wait_on_delete=True,

View File

@@ -24,26 +24,21 @@ class KeyPairsClient(service_client.ServiceClient):
def list_keypairs(self):
resp, body = self.get("os-keypairs")
body = json.loads(body)
# Each returned keypair is embedded within an unnecessary 'keypair'
# element which is a deviation from other resources like floating-ips,
# servers, etc. A bug?
# For now we shall adhere to the spec, but the spec for keypairs
# is yet to be found
self.validate_response(schema.list_keypairs, resp, body)
return service_client.ResponseBodyList(resp, body['keypairs'])
return service_client.ResponseBody(resp, body)
def show_keypair(self, keypair_name):
resp, body = self.get("os-keypairs/%s" % keypair_name)
body = json.loads(body)
self.validate_response(schema.get_keypair, resp, body)
return service_client.ResponseBody(resp, body['keypair'])
return service_client.ResponseBody(resp, body)
def create_keypair(self, **kwargs):
post_body = json.dumps({'keypair': kwargs})
resp, body = self.post("os-keypairs", body=post_body)
body = json.loads(body)
self.validate_response(schema.create_keypair, resp, body)
return service_client.ResponseBody(resp, body['keypair'])
return service_client.ResponseBody(resp, body)
def delete_keypair(self, keypair_name):
resp, body = self.delete("os-keypairs/%s" % keypair_name)

View File

@@ -26,7 +26,8 @@ class VolumeVerifyStress(stressaction.StressAction):
def _create_keypair(self):
keyname = data_utils.rand_name("key")
self.key = self.manager.keypairs_client.create_keypair(name=keyname)
self.key = (self.manager.keypairs_client.create_keypair(name=keyname)
['keypair'])
def _delete_keypair(self):
self.manager.keypairs_client.delete_keypair(self.key['name'])

View File

@@ -38,7 +38,7 @@ def cleanup():
except Exception:
pass
keypairs = admin_manager.keypairs_client.list_keypairs()
keypairs = admin_manager.keypairs_client.list_keypairs()['keypairs']
LOG.info("Cleanup::remove %s keypairs" % len(keypairs))
for k in keypairs:
try:

View File

@@ -25,12 +25,12 @@ from tempest.tests import fake_auth_provider
class TestKeyPairsClient(base.TestCase):
FAKE_KEYPAIR = {
FAKE_KEYPAIR = {"keypair": {
"public_key": "ssh-rsa foo Generated-by-Nova",
"name": u'\u2740(*\xb4\u25e1`*)\u2740',
"user_id": "525d55f98980415ba98e634972fa4a10",
"fingerprint": "76:24:66:49:d7:ca:6e:5c:77:ea:8e:bb:9c:15:5f:98"
}
}}
def setUp(self):
super(TestKeyPairsClient, self).setUp()
@@ -42,7 +42,7 @@ class TestKeyPairsClient(base.TestCase):
body = '{"keypairs": []}'
if bytes_body:
body = body.encode('utf-8')
expected = []
expected = {"keypairs": []}
response = (httplib2.Response({'status': 200}), body)
self.useFixture(mockpatch.Patch(
'tempest.common.service_client.ServiceClient.get',
@@ -57,14 +57,14 @@ class TestKeyPairsClient(base.TestCase):
def _test_show_keypair(self, bytes_body=False):
fake_keypair = copy.deepcopy(self.FAKE_KEYPAIR)
fake_keypair.update({
fake_keypair["keypair"].update({
"deleted": False,
"created_at": "2015-07-22T04:53:52.000000",
"updated_at": None,
"deleted_at": None,
"id": 1
})
serialized_body = json.dumps({"keypair": fake_keypair})
serialized_body = json.dumps(fake_keypair)
if bytes_body:
serialized_body = serialized_body.encode('utf-8')
@@ -83,8 +83,8 @@ class TestKeyPairsClient(base.TestCase):
def _test_create_keypair(self, bytes_body=False):
fake_keypair = copy.deepcopy(self.FAKE_KEYPAIR)
fake_keypair.update({"private_key": "foo"})
serialized_body = json.dumps({"keypair": fake_keypair})
fake_keypair["keypair"].update({"private_key": "foo"})
serialized_body = json.dumps(fake_keypair)
if bytes_body:
serialized_body = serialized_body.encode('utf-8')