Merge "remove zabbix from nailgun"

This commit is contained in:
Jenkins 2016-06-08 10:29:25 +00:00 committed by Gerrit Code Review
commit 095fc570ed
17 changed files with 45 additions and 345 deletions

View File

@ -28,4 +28,3 @@ from .parses import *
from .plugins import *
from .rpc import *
from .validation import *
from .zabbix import *

View File

@ -1,29 +0,0 @@
# coding: utf-8
# 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 .base import NailgunException
class ZabbixException(NailgunException):
"""Base zabbix exception"""
class CannotMakeZabbixRequest(ZabbixException):
message = "Can't make a request to Zabbix"
class ZabbixRequestError(ZabbixException):
message = "Zabbix request returned an error"

View File

@ -37,7 +37,6 @@ from nailgun import objects
from nailgun.settings import settings
from nailgun import utils as nailgun_utils
from nailgun.utils.restrictions import RestrictionBase
from nailgun.utils.zabbix import ZabbixManager
class NetworkManager(object):
@ -1093,16 +1092,6 @@ class NetworkManager(object):
return ip
return None
@classmethod
def get_zabbix_url(cls, cluster):
zabbix_node = ZabbixManager.get_zabbix_node(cluster)
if zabbix_node is None:
return None
ip_cidr = cls.get_network_by_netname(
'public', cls.get_node_networks(zabbix_node))['ip']
ip = ip_cidr.split('/')[0]
return 'http://{0}/zabbix'.format(ip)
@classmethod
def is_same_network(cls, ipaddress, ipnetwork):
"""Verifies that ipaddress belongs to network.

View File

@ -65,18 +65,10 @@
parameters:
strategy:
type: parallel
- id: zabbix-server
type: group
roles: [zabbix-server]
required_for: [deploy_end]
requires: [deploy_start]
parameters:
strategy:
type: one_by_one
- id: mongo
type: group
roles: [mongo]
requires: [zabbix-server]
requires: [deploy_start]
required_for: [deploy_end, primary-controller, controller]
parameters:
strategy:
@ -135,7 +127,7 @@
type: puppet
groups: [primary-controller, controller,
cinder, compute, ceph-osd,
zabbix-server, primary-mongo, mongo]
primary-mongo, mongo]
required_for: [deploy_end]
requires: [deploy_start]
parameters:

View File

@ -58,18 +58,10 @@ DEPLOYMENT_51_60 = """
parameters:
strategy:
type: parallel
- id: zabbix-server
type: group
role: [zabbix-server]
required_for: [deploy_end]
requires: [deploy_start]
parameters:
strategy:
type: one_by_one
- id: mongo
type: group
role: [mongo]
requires: [zabbix-server]
requires: [deploy_start]
required_for: [deploy_end, primary-controller, controller]
parameters:
strategy:
@ -102,7 +94,7 @@ DEPLOYMENT_51_60 = """
type: puppet
groups: [primary-controller, controller,
cinder, compute, ceph-osd,
zabbix-server, primary-mongo, mongo]
primary-mongo, mongo]
required_for: [deploy_end]
requires: [deploy_start]
parameters:
@ -153,18 +145,10 @@ DEPLOYMENT_50 = """
parameters:
strategy:
type: parallel
- id: zabbix-server
type: group
role: [zabbix-server]
required_for: [deploy_end]
requires: [deploy_start]
parameters:
strategy:
type: one_by_one
- id: mongo
type: group
role: [mongo]
requires: [zabbix-server]
requires: [deploy_start]
required_for: [deploy_end, primary-controller, controller]
parameters:
strategy:
@ -190,7 +174,7 @@ DEPLOYMENT_50 = """
type: puppet
groups: [primary-controller, controller,
cinder, compute, ceph-osd,
zabbix-server, primary-mongo, mongo]
primary-mongo, mongo]
required_for: [deploy_end]
requires: [deploy_start]
parameters:

View File

@ -595,14 +595,6 @@ class NailgunReceiver(object):
else:
message = u"{0} is done. No changes.".format(task_name)
zabbix_url = objects.Cluster.get_network_manager(
task.cluster
).get_zabbix_url(task.cluster)
if zabbix_url:
message = "{0} Access Zabbix dashboard at {1}".format(
message, zabbix_url)
if task.name != consts.TASK_NAMES.provision:
plugins_msg = cls._make_plugins_success_message(
ClusterPlugin.get_enabled(task.cluster.id))

View File

@ -294,12 +294,6 @@ LOGS:
<<: *remote_syslog_log_format
<<: *main_install_log_group
path: 'mcollective.log'
- id: 'zabbix'
name: "zabbix"
<<: *remote_log_type
<<: *remote_syslog_log_format
<<: *main_install_log_group
path: 'zabbix_server.log'
- id: 'install/anaconda'
name: "anaconda"
<<: *remote_log_type

View File

@ -57,7 +57,6 @@ from nailgun.task.legacy_tasks_adapter import adapt_legacy_tasks
from nailgun.utils import logs as logs_utils
from nailgun.utils.restrictions import VmwareAttributesRestriction
from nailgun.utils.role_resolver import RoleResolver
from nailgun.utils.zabbix import ZabbixManager
def make_astute_message(task, method, respond_to, args):
@ -789,22 +788,6 @@ class DeletionTask(object):
nodes_to_delete = nodes['nodes_to_delete']
nodes_to_restore = nodes['nodes_to_restore']
# check if there's a Zabbix server in an environment
# and if there is, remove hosts
if (task.name != consts.TASK_NAMES.cluster_deletion and
ZabbixManager.get_zabbix_node(task.cluster)):
zabbix_credentials = ZabbixManager.get_zabbix_credentials(
task.cluster
)
logger.debug("Removing nodes %s from zabbix", nodes_to_delete)
try:
ZabbixManager.remove_from_zabbix(
zabbix_credentials, nodes_to_delete
)
except (errors.CannotMakeZabbixRequest,
errors.ZabbixRequestError) as e:
logger.warning("%s, skipping removing nodes from Zabbix", e)
nodes_to_delete = cls.remove_undeployed_nodes_from_db(nodes_to_delete)
logger.debug(

View File

@ -68,29 +68,6 @@ class TestDeletionTask(BaseIntegrationTest):
self.assertEqual(len(self.cluster_db.nodes), 0)
self.assertEqual(len(ret), 0)
@mock.patch('nailgun.task.task.rpc')
@mock.patch('nailgun.task.task.make_astute_message')
@mock.patch('nailgun.task.task.ZabbixManager')
def test_execute_with_zabbix_node(
self,
mock_zabbix_manager,
mmake_astute_message,
mrpc):
self.add_node(consts.NODE_STATUSES.ready)
nodes = DeletionTask.get_task_nodes_for_cluster(self.cluster_db)
self.assertEqual(len(nodes['nodes_to_delete']), 1)
task = models.Task(
name=consts.TASK_NAMES.cluster_deletion,
cluster=self.cluster_db
)
db().add(task)
db().commit()
DeletionTask.execute(task, nodes=nodes)
self.assertEqual(mock_zabbix_manager.get_zabbix_node.called, False)
@mock.patch('nailgun.task.task.rpc')
@mock.patch('nailgun.task.task.make_astute_message')
@mock.patch.object(DeletionTask, 'remove_undeployed_nodes_from_db')

View File

@ -568,7 +568,7 @@ class TestReleasePluginsGraphHandler(BaseGraphTasksTests,
headers=self.default_headers,
)
self.assertEqual(resp.status_code, 200)
self.assertEqual(len(resp.json), 25) # default release tasks
self.assertEqual(len(resp.json), 24) # default release tasks
def test_get_existing_custom_deployment_tasks(self):
resp = self.app.get(

View File

@ -1251,7 +1251,6 @@ class TestNovaOrchestratorHASerializer(OrchestratorSerializerTestBase):
def test_set_deployment_priorities(self):
nodes = [
{'role': 'zabbix-server'},
{'role': 'mongo'},
{'role': 'primary-mongo'},
{'role': 'primary-controller'},
@ -1262,20 +1261,18 @@ class TestNovaOrchestratorHASerializer(OrchestratorSerializerTestBase):
self.add_default_params(nodes)
self.serializer.set_deployment_priorities(nodes)
expected_priorities = [
{'role': 'zabbix-server', 'priority': 100},
{'role': 'mongo', 'priority': 200},
{'role': 'primary-mongo', 'priority': 300},
{'role': 'primary-controller', 'priority': 400},
{'role': 'mongo', 'priority': 100},
{'role': 'primary-mongo', 'priority': 200},
{'role': 'primary-controller', 'priority': 300},
{'role': 'controller', 'priority': 400},
{'role': 'controller', 'priority': 500},
{'role': 'controller', 'priority': 600},
{'role': 'ceph-osd', 'priority': 700},
{'role': 'ceph-osd', 'priority': 600},
]
self.add_default_params(expected_priorities)
self.assertEqual(expected_priorities, nodes)
def test_set_deployment_priorities_many_cntrls(self):
nodes = [
{'role': 'zabbix-server'},
{'role': 'mongo'},
{'role': 'primary-mongo'},
{'role': 'primary-controller'},
@ -1292,10 +1289,10 @@ class TestNovaOrchestratorHASerializer(OrchestratorSerializerTestBase):
self.add_default_params(nodes)
self.serializer.set_deployment_priorities(nodes)
expected_priorities = [
{'role': 'zabbix-server', 'priority': 100},
{'role': 'mongo', 'priority': 200},
{'role': 'primary-mongo', 'priority': 300},
{'role': 'primary-controller', 'priority': 400},
{'role': 'mongo', 'priority': 100},
{'role': 'primary-mongo', 'priority': 200},
{'role': 'primary-controller', 'priority': 300},
{'role': 'controller', 'priority': 400},
{'role': 'controller', 'priority': 500},
{'role': 'controller', 'priority': 600},
{'role': 'controller', 'priority': 700},
@ -1303,8 +1300,7 @@ class TestNovaOrchestratorHASerializer(OrchestratorSerializerTestBase):
{'role': 'controller', 'priority': 900},
{'role': 'controller', 'priority': 1000},
{'role': 'controller', 'priority': 1100},
{'role': 'controller', 'priority': 1200},
{'role': 'ceph-osd', 'priority': 1300}
{'role': 'ceph-osd', 'priority': 1200}
]
self.add_default_params(expected_priorities)
self.assertEqual(expected_priorities, nodes)
@ -1391,7 +1387,6 @@ class TestNovaOrchestratorHASerializer51(TestNovaOrchestratorHASerializer):
def test_set_deployment_priorities(self):
nodes = [
{'role': 'zabbix-server'},
{'role': 'mongo'},
{'role': 'primary-mongo'},
{'role': 'primary-controller'},
@ -1402,20 +1397,18 @@ class TestNovaOrchestratorHASerializer51(TestNovaOrchestratorHASerializer):
self.add_default_params(nodes)
self.serializer.set_deployment_priorities(nodes)
expected_priorities = [
{'role': 'zabbix-server', 'priority': 100},
{'role': 'mongo', 'priority': 200},
{'role': 'primary-mongo', 'priority': 300},
{'role': 'primary-controller', 'priority': 400},
{'role': 'controller', 'priority': 500},
{'role': 'controller', 'priority': 500},
{'role': 'ceph-osd', 'priority': 600},
{'role': 'mongo', 'priority': 100},
{'role': 'primary-mongo', 'priority': 200},
{'role': 'primary-controller', 'priority': 300},
{'role': 'controller', 'priority': 400},
{'role': 'controller', 'priority': 400},
{'role': 'ceph-osd', 'priority': 500},
]
self.add_default_params(expected_priorities)
self.assertEqual(expected_priorities, nodes)
def test_set_deployment_priorities_many_cntrls(self):
nodes = [
{'role': 'zabbix-server'},
{'role': 'mongo'},
{'role': 'primary-mongo'},
{'role': 'primary-controller'},
@ -1432,19 +1425,18 @@ class TestNovaOrchestratorHASerializer51(TestNovaOrchestratorHASerializer):
self.add_default_params(nodes)
self.serializer.set_deployment_priorities(nodes)
expected_priorities = [
{'role': 'zabbix-server', 'priority': 100},
{'role': 'mongo', 'priority': 200},
{'role': 'primary-mongo', 'priority': 300},
{'role': 'primary-controller', 'priority': 400},
{'role': 'mongo', 'priority': 100},
{'role': 'primary-mongo', 'priority': 200},
{'role': 'primary-controller', 'priority': 300},
{'role': 'controller', 'priority': 400},
{'role': 'controller', 'priority': 400},
{'role': 'controller', 'priority': 400},
{'role': 'controller', 'priority': 400},
{'role': 'controller', 'priority': 400},
{'role': 'controller', 'priority': 400},
{'role': 'controller', 'priority': 500},
{'role': 'controller', 'priority': 500},
{'role': 'controller', 'priority': 500},
{'role': 'controller', 'priority': 500},
{'role': 'controller', 'priority': 500},
{'role': 'controller', 'priority': 500},
{'role': 'controller', 'priority': 600},
{'role': 'controller', 'priority': 600},
{'role': 'ceph-osd', 'priority': 700}
{'role': 'ceph-osd', 'priority': 600}
]
self.add_default_params(expected_priorities)
self.assertEqual(expected_priorities, nodes)

View File

@ -425,8 +425,7 @@ class TestInstallationInfo(BaseTestCase):
('external_mongo', 'mongo_user'), ('syslog', 'syslog_port'),
('syslog', 'syslog_server'), ('workloads_collector', 'password'),
('workloads_collector', 'tenant'),
('workloads_collector', 'user'), ('zabbix', 'password'),
('zabbix', 'username'),
('workloads_collector', 'user'),
('common', 'use_vcenter'), # removed attribute
('murano_settings', 'murano_repo_url'),
('use_fedora_lt', 'kernel'),

View File

@ -103,8 +103,7 @@ class TestDataMigration(BaseTestCase):
"database for storage of metering data "
"from OpenStack Telemetry (Ceilometer)",
'conflicts': ['compute',
'ceph-osd',
'zabbix-server'],
'ceph-osd'],
'depends': [ceilometer_depends]
}
}
@ -221,8 +220,7 @@ class TestDataMigration(BaseTestCase):
"database for storage of metering data "
"from OpenStack Telemetry (Ceilometer)",
'conflicts': ['compute',
'ceph-osd',
'zabbix-server'],
'ceph-osd'],
'depends': [
operational_restriction,
ceilometer_restriction

View File

@ -286,20 +286,18 @@ class TestLegacyGraphSerialized(base.BaseTestCase):
{'uid': '8', 'role': 'compute'},
{'uid': '9', 'role': 'mongo'},
{'uid': '10', 'role': 'primary-mongo'},
{'uid': '11', 'role': 'ceph-osd'},
{'uid': '12', 'role': 'zabbix-server'}]
{'uid': '11', 'role': 'ceph-osd'}]
self.graph.add_priorities(nodes)
by_priority = defaultdict(list)
for role, group in groupby(nodes, lambda node: node['priority']):
by_priority[role].extend(list(group))
self.assertEqual(by_priority[100][0]['role'], 'zabbix-server')
self.assertEqual(by_priority[200][0]['role'], 'mongo')
self.assertEqual(by_priority[300][0]['role'], 'primary-mongo')
self.assertEqual(by_priority[400][0]['role'], 'primary-controller')
self.assertEqual(by_priority[500][0]['role'], 'controller')
self.assertEqual(by_priority[500][1]['role'], 'controller')
self.assertEqual(by_priority[100][0]['role'], 'mongo')
self.assertEqual(by_priority[200][0]['role'], 'primary-mongo')
self.assertEqual(by_priority[300][0]['role'], 'primary-controller')
self.assertEqual(by_priority[400][0]['role'], 'controller')
self.assertEqual(by_priority[400][1]['role'], 'controller')
self.assertEqual(
set([i['role'] for i in by_priority[600]]),
set([i['role'] for i in by_priority[500]]),
set(['compute', 'cinder', 'ceph-osd']))

View File

@ -41,10 +41,8 @@ class TestTaskSerializerContext(BaseUnitTest):
def test_transform_legacy_condition(self):
cases = [
(
'settings:additional_components.ceilometer.value == 1 or '
'settings:additional_components.zabbix.value == 1',
'settings:ceilometer.enabled == 1 or '
'settings:zabbix.enabled == 1',
'settings:additional_components.ceilometer.value == 1 or ',
'settings:ceilometer.enabled == 1 or ',
),
(
'settings:common.vms_create.value == 1 or '

View File

@ -1,44 +0,0 @@
# -*- coding: utf-8 -*-
# Copyright 2015 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.
import json
from mock import Mock
from mock import patch
from nailgun import errors
from nailgun.test.base import BaseTestCase
from nailgun.utils.zabbix import ZabbixManager
class TestZabbixManager(BaseTestCase):
@patch('nailgun.utils.zabbix.urllib2.urlopen')
def test_error_zabbix_request(self, mock_urlopen):
urlopen_value = Mock()
urlopen_value.read.return_value = json.dumps({
'jsonrpc': '2.0',
'id': '1',
'error': {
'message': "Error connecting to database]",
'code': 1}})
mock_urlopen.return_value = urlopen_value
with self.assertRaises(errors.ZabbixRequestError):
ZabbixManager._make_zabbix_request(
'fake_url',
'user.authenticate',
{'password': 'zabbix', 'user': 'admin'},
auth=None),

View File

@ -1,122 +0,0 @@
# -*- coding: utf-8 -*-
# Copyright 2013 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.
import simplejson as json
import urllib2
from nailgun import errors
from nailgun.logger import logger
class ZabbixManager(object):
@classmethod
def _make_zabbix_request(cls, url, method, params, auth=None):
header = {'Content-type': 'application/json'}
data = {'jsonrpc': '2.0',
'id': '1',
'method': method,
'params': params}
if auth:
data['auth'] = auth
logger.debug("Zabbix request: %s", data)
request = urllib2.Request(url, json.dumps(data), header)
try:
response = urllib2.urlopen(request)
except urllib2.URLError as e:
raise errors.CannotMakeZabbixRequest(
"Can't make a request to Zabbix: {0}".format(e)
)
result = json.loads(response.read())
logger.debug("Zabbix response: %s", result)
if 'error' in result:
code = result['error']['code']
msg = result['error']['message']
data = result['error'].get('data', '')
raise errors.ZabbixRequestError(
"Zabbix returned error code {0}, {1}: {2}".format(
code, msg, data
)
)
return result['result']
@classmethod
def _zabbix_auth(cls, url, user, password):
method = 'user.authenticate'
params = {'user': user,
'password': password}
auth_hash = cls._make_zabbix_request(url, method, params)
return auth_hash
@classmethod
def _get_zabbix_hostid(cls, url, auth, name):
method = 'host.get'
params = {'filter': {'host': name}}
result = cls._make_zabbix_request(url, method, params, auth=auth)
if len(result) == 0:
logger.info("Host %s does not exist in zabbix, skipping", name)
return None
return result[0]['hostid']
@classmethod
def remove_from_zabbix(cls, zabbix, nodes):
url = zabbix['url']
user = zabbix['user']
password = zabbix['password']
auth = cls._zabbix_auth(url, user, password)
hostids = []
method = "host.delete"
for node in nodes:
name = node['slave_name']
hostid = cls._get_zabbix_hostid(url, auth, name)
if hostid:
hostids.append(hostid)
if hostids:
cls._make_zabbix_request(url, method, hostids, auth=auth)
@classmethod
def get_zabbix_node(cls, cluster):
zabbix_nodes = filter(
lambda node: 'zabbix-server' in node.roles,
cluster.nodes)
if not zabbix_nodes:
return None
return zabbix_nodes[0]
@classmethod
def get_zabbix_credentials(cls, cluster):
creds = {}
zabbix_node = cls.get_zabbix_node(cluster)
attributes = cluster.attributes
zabbix_attrs = attributes.editable['zabbix']
creds['user'] = zabbix_attrs['username']['value']
creds['password'] = zabbix_attrs['password']['value']
creds['url'] = "http://{0}/zabbix/api_jsonrpc.php".format(
zabbix_node.ip
)
return creds