diff --git a/devstack/post_test_hook.sh b/devstack/post_test_hook.sh index b9cc986..37ec742 100644 --- a/devstack/post_test_hook.sh +++ b/devstack/post_test_hook.sh @@ -17,7 +17,7 @@ DEVSTACK_PATH="$BASE/new" #Argument is received from Zuul if [ "$1" = "api" ]; then - TESTS="topology|test_rca|test_alarms|test_resources|test_template|test_webhook" + TESTS="topology|test_rca|test_alarms|test_resources|test_template|test_webhook|test_service" elif [ "$1" = "datasources" ]; then TESTS="datasources|test_events|notifiers|e2e|database" elif [ "$1" = "mock" ]; then diff --git a/vitrage_tempest_plugin/tests/api/services/__init__.py b/vitrage_tempest_plugin/tests/api/services/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/vitrage_tempest_plugin/tests/api/services/test_service.py b/vitrage_tempest_plugin/tests/api/services/test_service.py new file mode 100644 index 0000000..735e962 --- /dev/null +++ b/vitrage_tempest_plugin/tests/api/services/test_service.py @@ -0,0 +1,65 @@ +# Copyright 2019 - Nokia Corporation +# +# 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 datetime import date +import socket + +from dateutil import parser +from testtools import matchers + +from vitrage_tempest_plugin.tests.base import BaseVitrageTempest + + +SERVICES = { + 'ApiWorker', + 'EvaluatorWorker', + 'MachineLearningService', + 'PersistorService', + 'SnmpParsingService', + 'vitrageuWSGI', + 'VitrageNotifierService' +} + + +class ServiceTest(BaseVitrageTempest): + def test_service_list(self): + services = self.vitrage_client.service.list() + + # NOTE(eyalb) test will run in the same day of + # process creation, might remove this if it causes + # problems + self.check_created(services, date.today()) + + self.check_all_equal(services, SERVICES) + self.check_all_hosted(services, socket.gethostname()) + self.check_different_process_ids_for(services) + + def check_created(self, services, today): + + created = {parser.parse(service['created']).date() + for service in services} + self.assert_set_equal({today}, created) + + def check_all_equal(self, services, expected_svc_names): + names = {service['name'].split(' ')[0] for service in services} + self.assert_set_equal(expected_svc_names, names) + + def check_all_hosted(self, services, hostname): + hostnames = {service['hostname'] for service in services} + self.assert_set_equal({hostname}, hostnames) + + def check_different_process_ids_for(self, services): + num_services = len(services) + process_ids = {service['process'] for service in services} + self.assertThat(process_ids, matchers.HasLength(num_services)) diff --git a/vitrage_tempest_plugin/tests/base.py b/vitrage_tempest_plugin/tests/base.py index eeccb01..117d2d2 100644 --- a/vitrage_tempest_plugin/tests/base.py +++ b/vitrage_tempest_plugin/tests/base.py @@ -73,12 +73,15 @@ class BaseVitrageTempest(base.BaseTestCase): ADMIN_USERNAME = 'admin' ADMIN_PROJECT_NAME = 'admin' - def assert_list_equal(self, l1, l2): - self.assertListEqual(l1, l2) + def assert_list_equal(self, l1, l2, message=None): + self.assertListEqual(l1, l2, message) - def assert_dict_equal(self, d1, d2, message): + def assert_dict_equal(self, d1, d2, message=None): self.assertDictEqual(d1, d2, message) + def assert_set_equal(self, s1, s2, message=None): + self.assertSetEqual(s1, s2, message) + def assert_timestamp_equal(self, first, second, msg=None): """Checks that two timestamps are equals.