Add five zabbix functional tests.

Add test_zabbix_deployment test.
Add check_zabbix_api test.
Add check_zabbix_dashboard_configuration test.
Add test_triggers test.
Add test_trigger_api test.
Add related zabbix API methods.

Change-Id: Ibb01f12a4be1492b457c889143784789edc4b742
This commit is contained in:
Vladimir Ushakov 2016-09-08 09:14:35 +03:00 committed by vgusev
parent ac02c218b1
commit d9aadcbffe
3 changed files with 192 additions and 8 deletions

View File

@ -70,6 +70,7 @@ def import_tests():
from stacklight_tests.toolchain import test_reduced_footprint # noqa
from stacklight_tests.toolchain import test_smoke_bvt # noqa
from stacklight_tests.toolchain import test_system # noqa
from stacklight_tests.zabbix import test_functional # noqa
from stacklight_tests.zabbix import test_smoke_bvt # noqa
from stacklight_tests.zabbix import test_system # noqa

View File

@ -141,19 +141,19 @@ class ZabbixApi(base_test.PluginApi):
return self.helpers.check_plugin_cannot_be_uninstalled(
self.settings.name, self.settings.version)
def get_zabbix_web(self, username='', password=''):
def get_zabbix_web(self, username='', password='', protocol=None):
username = username or self.settings.zabbix_username
password = password or self.settings.zabbix_password
protocol = protocol if protocol else self.protocol
return ZabbixWeb(
self.get_zabbix_url(), username, password, self.protocol)
self.get_zabbix_url(), username, password, protocol)
def get_zabbix_api(self):
zabbix_api = ZabbixAPI(
url=self.get_zabbix_url(),
user=self.settings.zabbix_username,
password=self.settings.zabbix_password)
zabbix_api.session.verify = False
def get_zabbix_api(self, url='', user='', password=''):
url = url or self.get_zabbix_url()
user = user or self.settings.zabbix_username
password = password or self.settings.zabbix_password
zabbix_api = ZabbixAPI(url=url, user=user, password=password)
return zabbix_api
def get_node_with_zabbix_vip_fqdn(self):

View File

@ -0,0 +1,183 @@
# Copyright 2016 Mirantis, Inc.
#
# 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 fuelweb_test.helpers.decorators import log_snapshot_after_test
from proboscis import asserts
from proboscis import test
from pyzabbix import ZabbixAPIException
from stacklight_tests.zabbix import api
@test(groups=["plugins"])
class TestFunctionalZabbix(api.ZabbixApi):
"""Class for functional testing of Zabbix plugin."""
@test(depends_on_groups=["deploy_zabbix_monitoring_ha"],
groups=["test_zabbix_deployment", "zabbix", "functional"])
@log_snapshot_after_test
def test_zabbix_deployment(self):
"""Verify that zabbix packages are installed on all controllers
and zabbix service is started.
Scenario:
1. Revert snapshot with zabbix ha configuration
2. Connect to controller node.
3. Check that zabbix packages installed.
4. Check that zabbix service is started.
5. Repeat steps 2-4 for all controllers.
Duration 20m
"""
self.env.revert_snapshot("deploy_zabbix_monitoring_ha")
controllers = self.fuel_web.get_nailgun_cluster_nodes_by_roles(
self.helpers.cluster_id, ['controller'])
for controller in controllers:
with self.fuel_web.get_ssh_for_nailgun_node(controller) as remote:
remote.check_call("dpkg --get-selections | grep zabbix")
self.get_node_with_zabbix_vip_fqdn()
@test(depends_on_groups=["deploy_zabbix_monitoring_ha"],
groups=["check_zabbix_api", "zabbix", "functional"])
@log_snapshot_after_test
def check_zabbix_api(self):
"""Verify that zabbix login works correctly.
Scenario:
1. Revert snapshot with zabbix ha configuration
2. Check that it is possible to login with valid
credentials
3. Check that it is impossible to login with invalid
credentials
4. Check that it is possible to login with over https
Duration 20m
"""
self.env.revert_snapshot("deploy_zabbix_monitoring_ha")
flag = False
try:
self.get_zabbix_api(user='invalid_username',
password='invalid_password')
except ZabbixAPIException:
flag = True
asserts.assert_true(
flag, "Zabbix allows authenticate with incorrect credentials!")
self.get_zabbix_web(protocol='http').zabbix_web_login()
self.get_zabbix_web(protocol='https').zabbix_web_login()
@test(depends_on_groups=["deploy_zabbix_monitoring_ha"],
groups=["check_zabbix_dashboard_configuration", "zabbix",
"functional"])
@log_snapshot_after_test
def check_zabbix_dashboard_configuration(self):
"""Verify that zabbix dashboard is preconfigured
Scenario:
1. Revert snapshot with zabbix ha configuration
2. Login to zabbix web
2. Get zabbix/screens.php
3. Check preconfigured graphs:
- screen 'OpenStack Cluster'
- screen 'Ceph' if Ceph is deployed
Duration 10m
"""
self.env.revert_snapshot("deploy_zabbix_monitoring_ha")
zabbix_web = self.get_zabbix_web()
zabbix_web.zabbix_web_login()
screens_html = zabbix_web.get_zabbix_web_screen()
found = False
for tag in screens_html.find_all('td'):
if 'Openstack Cluster' == tag.text:
found = True
asserts.assert_true(found, "'Openstack cluster' screen was not found"
" on screens.php")
ceph_nodes = self.fuel_web.get_nailgun_cluster_nodes_by_roles(
self.helpers.cluster_id, ['ceph-osd'])
if ceph_nodes:
found = False
for tag in screens_html.find_all('td'):
if 'Openstack Cluster' == tag.text:
found = True
asserts.assert_true(found, "'Ceph' screen was not found"
" on screens.php")
@test(depends_on_groups=["deploy_zabbix_monitoring_ha"],
groups=["test_triggers", "zabbix", "functional"])
@log_snapshot_after_test
def test_triggers(self):
"""Verify that zabbix login works correctly.
Scenario:
1. Revert snapshot with zabbix ha configuration
2. Check that all services have '0' status
Duration 10m
"""
self.env.revert_snapshot("deploy_zabbix_monitoring_ha")
result = self.get_zabbix_api().do_request('trigger.get', {
"output": ["triggerid"], "filter": {"value": 1},
"sortfield": "priority"})
asserts.assert_true(len(result['result']) == 0,
"Some triggers have '1' status: {0}".format(
result['result']))
@test(depends_on_groups=["deploy_zabbix_monitoring_ha"],
groups=["test_trigger_api", "zabbix", "functional"])
@log_snapshot_after_test
def test_trigger_api(self):
"""Verify that the API is detected as down.
Scenario:
1. Revert snapshot with zabbix ha configuration.
2. Log into on controller node.
3. Stop neutron-server.
4. On dashboard verify that alerts are present.
Duration 10m
"""
self.env.revert_snapshot("deploy_zabbix_monitoring_ha")
controller = self.fuel_web.get_nailgun_cluster_nodes_by_roles(
self.helpers.cluster_id, ['controller'])[0]
with self.fuel_web.get_ssh_for_nailgun_node(controller) as remote:
remote.check_call("stop neutron-server",
"Cannot stop neutron-server on {0}!".format(
controller['name']))
alerts = [
{'priority': '4',
'description': 'Neutron API test failed on {HOST.NAME}'},
{'priority': '4',
'description': 'Neutron Server service is down on {HOST.NAME}'},
{'priority': '4', 'description': 'Neutron Server process '
'is not running on {HOST.NAME}'},
{'priority': '3',
'description': '{} backend of neutron proxy down'.format(
controller["hostname"])}
]
self.wait_for_trigger(alerts)