| 1 |
# Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 2 |
# not use this file except in compliance with the License. You may obtain |
| 3 |
# a copy of the License at |
| 4 |
# |
| 5 |
# http://www.apache.org/licenses/LICENSE-2.0 |
| 6 |
# |
| 7 |
# Unless required by applicable law or agreed to in writing, software |
| 8 |
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 9 |
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 10 |
# License for the specific language governing permissions and limitations |
| 11 |
# under the License. |
| 12 |
|
| 13 |
|
| 14 |
from tempest.lib import exceptions |
| 15 |
import testtools |
| 16 |
|
| 17 |
from magnum_tempest_plugin.tests.api import base |
| 18 |
|
| 19 |
|
| 20 |
class MagnumServiceTest(base.BaseTempestTest): |
| 21 |
|
| 22 |
"""Tests for magnum-service .""" |
| 23 |
|
| 24 |
def __init__(self, *args, **kwargs): |
| 25 |
super(MagnumServiceTest, self).__init__(*args, **kwargs) |
| 26 |
self.service_client = None |
| 27 |
|
| 28 |
@testtools.testcase.attr('negative') |
| 29 |
def test_magnum_service_list_needs_admin(self): |
| 30 |
# Ensure that policy enforcement does not allow 'default' user |
| 31 |
(self.service_client, _) = self.get_clients_with_new_creds( |
| 32 |
type_of_creds='default', |
| 33 |
request_type='service') |
| 34 |
self.assertRaises(exceptions.Forbidden, |
| 35 |
self.service_client.magnum_service_list) |
| 36 |
|
| 37 |
@testtools.testcase.attr('positive') |
| 38 |
def test_magnum_service_list(self): |
| 39 |
# get json object |
| 40 |
(self.service_client, _) = self.get_clients_with_new_creds( |
| 41 |
type_of_creds='admin', |
| 42 |
request_type='service', |
| 43 |
class_cleanup=False) |
| 44 |
resp, msvcs = self.service_client.magnum_service_list() |
| 45 |
self.assertEqual(200, resp.status) |
| 46 |
# Note(suro-patz): Following code assumes that we have only |
| 47 |
# one service, magnum-conductor enabled, as of now. |
| 48 |
self.assertEqual(1, len(msvcs.mservices)) |
| 49 |
mcond_svc = msvcs.mservices[0] |
| 50 |
self.assertEqual(mcond_svc['id'], 1) |
| 51 |
self.assertEqual('up', mcond_svc['state']) |
| 52 |
self.assertEqual('magnum-conductor', mcond_svc['binary']) |
| 53 |
self.assertGreater(mcond_svc['report_count'], 0) |