Files
deb-tempest/tempest/api/compute/admin/test_hosts.py
ghanshyam e1bd29e352 Return complete response from hosts_client
Currently compute hosts_client returns Response by removing
top key from Response.
For example-
return service_client.ResponseBody(resp, body['host'])

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 hosts_client to return complete
Response body.

Implements: blueprint method-return-value-and-move-service-clients-to-lib

Change-Id: Ife5bdbbcbdd856ecbce66e8b9c74c70dbb93f077
2015-08-18 16:47:24 +09:00

77 lines
3.0 KiB
Python

# Copyright 2013 IBM Corp.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from tempest.api.compute import base
from tempest.common import tempest_fixtures as fixtures
from tempest import test
class HostsAdminTestJSON(base.BaseV2ComputeAdminTest):
"""
Tests hosts API using admin privileges.
"""
@classmethod
def setup_clients(cls):
super(HostsAdminTestJSON, cls).setup_clients()
cls.client = cls.os_adm.hosts_client
@test.idempotent_id('9bfaf98d-e2cb-44b0-a07e-2558b2821e4f')
def test_list_hosts(self):
hosts = self.client.list_hosts()['hosts']
self.assertTrue(len(hosts) >= 2, str(hosts))
@test.idempotent_id('5dc06f5b-d887-47a2-bb2a-67762ef3c6de')
def test_list_hosts_with_zone(self):
self.useFixture(fixtures.LockFixture('availability_zone'))
hosts = self.client.list_hosts()['hosts']
host = hosts[0]
hosts = self.client.list_hosts(zone=host['zone'])['hosts']
self.assertTrue(len(hosts) >= 1)
self.assertIn(host, hosts)
@test.idempotent_id('9af3c171-fbf4-4150-a624-22109733c2a6')
def test_list_hosts_with_a_blank_zone(self):
# If send the request with a blank zone, the request will be successful
# and it will return all the hosts list
hosts = self.client.list_hosts(zone='')['hosts']
self.assertNotEqual(0, len(hosts))
@test.idempotent_id('c6ddbadb-c94e-4500-b12f-8ffc43843ff8')
def test_list_hosts_with_nonexistent_zone(self):
# If send the request with a nonexistent zone, the request will be
# successful and no hosts will be retured
hosts = self.client.list_hosts(zone='xxx')['hosts']
self.assertEqual(0, len(hosts))
@test.idempotent_id('38adbb12-aee2-4498-8aec-329c72423aa4')
def test_show_host_detail(self):
hosts = self.client.list_hosts()['hosts']
hosts = [host for host in hosts if host['service'] == 'compute']
self.assertTrue(len(hosts) >= 1)
for host in hosts:
hostname = host['host_name']
resources = self.client.show_host(hostname)['host']
self.assertTrue(len(resources) >= 1)
host_resource = resources[0]['resource']
self.assertIsNotNone(host_resource)
self.assertIsNotNone(host_resource['cpu'])
self.assertIsNotNone(host_resource['disk_gb'])
self.assertIsNotNone(host_resource['memory_mb'])
self.assertIsNotNone(host_resource['project'])
self.assertEqual(hostname, host_resource['host'])