add a new service list api tests

Depends-On: Iecb2ae810dd2a6a6b544c2ed7dbfe6288f393178
Change-Id: I2996afcd4f05c87847db1f9be64a362a2593f5b6
This commit is contained in:
Eyal 2019-02-07 13:53:36 +02:00
parent 31667cc78a
commit 11fd7859ba
4 changed files with 72 additions and 4 deletions

View File

@ -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

View File

@ -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))

View File

@ -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.