Add a nova functional test for the os-server-groups GET API with all_projects parameter
Add a nova functional test to exercise the all_projects parameter in the index function of: https://github.com/openstack/nova/blob/master/nova/api/openstack/compute/server_groups.py Closes bug: 1503042 Change-Id: Ic52511a830ab27249d116e2cb14b071587c9747f
This commit is contained in:
@@ -315,16 +315,18 @@ class OSAPIFixture(fixtures.Fixture):
|
||||
|
||||
"""
|
||||
|
||||
def __init__(self, api_version='v2'):
|
||||
def __init__(self, api_version='v2', project_id='openstack'):
|
||||
"""Constructor
|
||||
|
||||
:param api_version: the API version that we're interested in
|
||||
using. Currently this expects 'v2' or 'v2.1' as possible
|
||||
options.
|
||||
:param project_id: the project id to use on the API.
|
||||
|
||||
"""
|
||||
super(OSAPIFixture, self).__init__()
|
||||
self.api_version = api_version
|
||||
self.project_id = project_id
|
||||
|
||||
def setUp(self):
|
||||
super(OSAPIFixture, self).setUp()
|
||||
@@ -347,9 +349,10 @@ class OSAPIFixture(fixtures.Fixture):
|
||||
self.auth_url = 'http://%(host)s:%(port)s/%(api_version)s' % ({
|
||||
'host': self.osapi.host, 'port': self.osapi.port,
|
||||
'api_version': self.api_version})
|
||||
self.api = client.TestOpenStackClient('fake', 'fake', self.auth_url)
|
||||
self.api = client.TestOpenStackClient('fake', 'fake', self.auth_url,
|
||||
self.project_id)
|
||||
self.admin_api = client.TestOpenStackClient(
|
||||
'admin', 'admin', self.auth_url)
|
||||
'admin', 'admin', self.auth_url, self.project_id)
|
||||
|
||||
|
||||
class PoisonFunctions(fixtures.Fixture):
|
||||
|
||||
@@ -116,14 +116,14 @@ class TestOpenStackClient(object):
|
||||
|
||||
"""
|
||||
|
||||
def __init__(self, auth_user, auth_key, auth_uri):
|
||||
def __init__(self, auth_user, auth_key, auth_uri,
|
||||
project_id='openstack'):
|
||||
super(TestOpenStackClient, self).__init__()
|
||||
self.auth_result = None
|
||||
self.auth_user = auth_user
|
||||
self.auth_key = auth_key
|
||||
self.auth_uri = auth_uri
|
||||
# default project_id
|
||||
self.project_id = 'openstack'
|
||||
self.project_id = project_id
|
||||
|
||||
def request(self, url, method='GET', body=None, headers=None):
|
||||
_headers = {'Content-Type': 'application/json'}
|
||||
@@ -335,8 +335,12 @@ class TestOpenStackClient(object):
|
||||
return self.api_post('/servers/%s/metadata' % server_id,
|
||||
post_body).body['metadata']
|
||||
|
||||
def get_server_groups(self):
|
||||
return self.api_get('/os-server-groups').body['server_groups']
|
||||
def get_server_groups(self, all_projects=None):
|
||||
if all_projects:
|
||||
return self.api_get(
|
||||
'/os-server-groups?all_projects').body['server_groups']
|
||||
else:
|
||||
return self.api_get('/os-server-groups').body['server_groups']
|
||||
|
||||
def get_server_group(self, group_id):
|
||||
return self.api_get('/os-server-groups/%s' %
|
||||
|
||||
@@ -177,6 +177,37 @@ class ServerGroupTest(ServerGroupTestBase):
|
||||
self.assertIn('Invalid input', ex.response.text)
|
||||
self.assertIn('wrong-policy', ex.response.text)
|
||||
|
||||
def test_get_groups_all_projects(self):
|
||||
# This test requires APIs using two projects.
|
||||
|
||||
# Create an API using project 'openstack1'.
|
||||
# This is a non-admin API.
|
||||
api_openstack1 = self.useFixture(nova_fixtures.OSAPIFixture(
|
||||
project_id='openstack1')).api
|
||||
|
||||
# Create a server group in project 'openstack'
|
||||
# Project 'openstack' is used by self.api
|
||||
group1 = self.anti_affinity
|
||||
openstack_group = self.api.post_server_groups(group1)
|
||||
|
||||
# Create a server group in project 'openstack1'
|
||||
group2 = self.affinity
|
||||
openstack1_group = api_openstack1.post_server_groups(group2)
|
||||
|
||||
# The admin should be able to get server groups in all projects.
|
||||
all_projects_admin = self.admin_api.get_server_groups(
|
||||
all_projects=True)
|
||||
self.assertIn(openstack_group, all_projects_admin)
|
||||
self.assertIn(openstack1_group, all_projects_admin)
|
||||
|
||||
# The non-admin should only be able to get server groups
|
||||
# in his project.
|
||||
# The all_projects parameter is ignored for non-admin clients.
|
||||
all_projects_non_admin = api_openstack1.get_server_groups(
|
||||
all_projects=True)
|
||||
self.assertNotIn(openstack_group, all_projects_non_admin)
|
||||
self.assertIn(openstack1_group, all_projects_non_admin)
|
||||
|
||||
def _boot_servers_to_group(self, group, flavor=None):
|
||||
servers = []
|
||||
for _ in range(0, 2):
|
||||
|
||||
Reference in New Issue
Block a user