Functional tests for magnum service

Adding functional tests for 'magnum service-list'. This ensures
end-to-end working of CLI/API/DB/RPC/CONDUCTOR for this feature.

Change-Id: I0bbf45a799cca232484ed7f3652b14692e47daf2
Closes-bug: #1501002
This commit is contained in:
Surojit Pathak 2015-10-05 19:46:53 +00:00
parent deae4e44b0
commit 3eba5b3969
4 changed files with 137 additions and 0 deletions

View File

@ -0,0 +1,45 @@
# 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 magnum.tests.functional.api.v1.models import magnum_service_model
from magnum.tests.functional.common import client
class MagnumServiceClient(client.ClientMixin):
"""Encapsulates REST calls and maps JSON to/from models"""
@classmethod
def magnum_service_uri(cls, filters=None):
"""Construct magnum services uri with optional filters
:param filters: Optional k:v dict that's converted to url query
:returns: url string
"""
url = "/mservices"
if filters:
url = cls.add_filters(url, filters)
return url
def magnum_service_list(self, filters=None, **kwargs):
"""Makes GET /mservices request and returns MagnumServiceCollection
Abstracts REST call to return all magnum services.
:param filters: Optional k:v dict that's converted to url query
:returns: response object and MagnumServiceCollection object
"""
resp, body = self.client.get(self.magnum_service_uri(filters),
**kwargs)
return self.deserialize(resp, body,
magnum_service_model.MagnumServiceCollection)

View File

@ -0,0 +1,30 @@
# 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 magnum.tests.functional.common import models
class MagnumServiceData(models.BaseModel):
"""Data that encapsulates magnum_service attributes"""
pass
class MagnumServiceEntity(models.EntityModel):
"""Entity Model that represents a single instance of MagnumServiceData"""
ENTITY_NAME = 'mservice'
MODEL_TYPE = MagnumServiceData
class MagnumServiceCollection(models.CollectionModel):
"""Collection Model that represents a list of MagnumServiceData objects"""
COLLECTION_NAME = 'mservicelists'
MODEL_TYPE = MagnumServiceData

View File

@ -0,0 +1,49 @@
# 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_lib import exceptions
import testtools
import unittest
from magnum.tests.functional.api.v1.clients import magnum_service_client as cli
from magnum.tests.functional.common import base
class MagnumServiceTest(base.BaseMagnumTest):
"""Tests for magnum-service ."""
# NOTE(suro-patz): The following test fails in lieu of non-admin user
# available for functional-test-gate.
# For now, I will keep the test, but skipped.
@unittest.skip("Requires non-admin user in functional-test-gate")
@testtools.testcase.attr('negative')
def test_magnum_service_list_needs_admin(self):
# Ensure that policy enforcement does not allow 'default' user
client = cli.MagnumServiceClient.as_user('default')
self.assertRaises(exceptions.ServerFault, client.magnum_service_list)
@testtools.testcase.attr('positive')
def test_magnum_service_list(self):
# get json object
client = cli.MagnumServiceClient.as_user('admin')
resp, msvcs = client.magnum_service_list()
self.assertEqual(resp.status, 200)
# Note(suro-patz): Following code assumes that we have only
# one service, magnum-conductor enabled, as of now.
self.assertEqual(len(msvcs.mservices), 1)
mcond_svc = msvcs.mservices[0]
self.assertEqual(mcond_svc['id'], 1)
self.assertEqual(mcond_svc['state'], 'up')
self.assertEqual(mcond_svc['binary'], 'magnum-conductor')
self.assertGreater(mcond_svc['report_count'], 0)

View File

@ -49,6 +49,18 @@ class MagnumClient(BaseMagnumClient):
)
class AdminMagnumClient(BaseMagnumClient):
"""Responsible for setting up auth provider for admin user"""
def get_auth_provider(self):
mgr = manager.Manager()
return mgr.get_auth_provider(
username=config.Config.admin_user,
password=config.Config.admin_passwd,
tenant_name=config.Config.admin_tenant
)
class ClientMixin(object):
"""Responsible for mapping setting up common client use cases:
@ -62,6 +74,7 @@ class ClientMixin(object):
def get_clients(cls):
return {
'default': MagnumClient(),
'admin': AdminMagnumClient(),
}
def __init__(self, client):