From c5743fbea2d81b2dcbcce6641a1d1fc2c51d02c4 Mon Sep 17 00:00:00 2001 From: ricolin Date: Fri, 10 Mar 2023 17:38:39 +0800 Subject: [PATCH] Add magnum service to rbac tests Although we didn't change policy of magnum service, but we should add this to complete test scope of job `magnum_tempest_plugin.tests.api.v1.rbac`. Change-Id: I5dfbad43d5a515312ef285aff208e1c9e36cf684 --- .../tests/api/v1/rbac/base.py | 2 + .../tests/api/v1/rbac/test_magnum_service.py | 41 +++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 magnum_tempest_plugin/tests/api/v1/rbac/test_magnum_service.py diff --git a/magnum_tempest_plugin/tests/api/v1/rbac/base.py b/magnum_tempest_plugin/tests/api/v1/rbac/base.py index 0baf4f4..342b175 100644 --- a/magnum_tempest_plugin/tests/api/v1/rbac/base.py +++ b/magnum_tempest_plugin/tests/api/v1/rbac/base.py @@ -62,6 +62,8 @@ class RbacBaseTests(base.BaseMagnumTest): cls.cert_reader_client = cls.project_reader.CertClient() cls.cert_member_client = cls.project_member.CertClient() cls.cert_admin_client = cls.project_admin.CertClient() + cls.service_member_client = cls.project_member.MagnumServiceClient() + cls.service_admin_client = cls.project_admin.MagnumServiceClient() @classmethod def setup_credentials(cls): diff --git a/magnum_tempest_plugin/tests/api/v1/rbac/test_magnum_service.py b/magnum_tempest_plugin/tests/api/v1/rbac/test_magnum_service.py new file mode 100644 index 0000000..6085a43 --- /dev/null +++ b/magnum_tempest_plugin/tests/api/v1/rbac/test_magnum_service.py @@ -0,0 +1,41 @@ +# 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. + +import abc +from tempest.lib import exceptions +import testtools + +from magnum_tempest_plugin.tests.api.v1.rbac import base + + +class MagnumServiceTest(base.RbacBaseTests, metaclass=abc.ABCMeta): + + """Tests for magnum-service with RBAC.""" + + def __init__(self, *args, **kwargs): + super(MagnumServiceTest, self).__init__(*args, **kwargs) + + @testtools.testcase.attr('negative') + def test_magnum_service_list_needs_admin(self): + self.assertRaises(exceptions.Forbidden, + self.service_member_client.magnum_service_list) + + @testtools.testcase.attr('positive') + def test_magnum_service_list(self): + # get json object + resp, msvcs = self.service_admin_client.magnum_service_list() + self.assertEqual(200, resp.status) + mcond_svc = msvcs.mservices[0] + self.assertEqual(mcond_svc['id'], 1) + self.assertEqual('up', mcond_svc['state']) + self.assertEqual('magnum-conductor', mcond_svc['binary']) + self.assertGreater(mcond_svc['report_count'], 0)