Skip to content

Commit

Permalink
Merge "Check installed and running package version mismatch periodica…
Browse files Browse the repository at this point in the history
…lly"
  • Loading branch information
Zuul authored and opencontrail-ci-admin committed Nov 27, 2016
2 parents 7aa8091 + 3a6ef99 commit 90d613f
Show file tree
Hide file tree
Showing 11 changed files with 151 additions and 9 deletions.
2 changes: 2 additions & 0 deletions src/base/sandesh/nodeinfo.sandesh
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ struct NodeStatus {
12: optional cpuinfo.SystemCpuInfo system_cpu_info
13: optional cpuinfo.SysMemInfo system_mem_usage(tags=".node_type")
14: optional cpuinfo.SysCpuInfo system_cpu_usage(tags=".node_type,.cpu_share")
15: optional string running_package_version
16: optional string installed_package_version
}

/**
Expand Down
36 changes: 36 additions & 0 deletions src/config/utils/contrail_alarm.py
Original file line number Diff line number Diff line change
Expand Up @@ -797,5 +797,41 @@
]
}
},
{
"alarm_rules": {
"or_list": [
{
"and_list": [
{
"operand1": "NodeStatus.running_package_version",
"operation": "!=",
"operand2": {
"uve_attribute": "NodeStatus.installed_package_version"
}

}
]
}
]
},
"alarm_severity": 0,
"fq_name": [
"default-global-system-config",
"package-version-mismatch"
],
"parent_type": "global-system-config",
"id_perms": {
"description": "There is a mismatch between installed and running package version."
},
"uve_keys": {
"uve_key": [
"analytics-node",
"config-node",
"control-node",
"database-node",
"vrouter"
]
}
},
]

3 changes: 2 additions & 1 deletion src/nodemgr/SConscript
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ for file in setup_sources:

local_sources = [
'__init__.py',
'main.py'
'main.py',
'utils.py'
]

local_sources_rules = []
Expand Down
5 changes: 4 additions & 1 deletion src/nodemgr/analytics_nodemgr/analytics_event_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def __init__(self, rule_file, discovery_server,
self.instance_id,
staticmethod(ConnectionState.get_process_state_cb),
NodeStatusUVE, NodeStatus, self.table)
self.send_system_cpu_info()
self.send_init_info()
self.third_party_process_dict = {}
# end __init__

Expand All @@ -80,3 +80,6 @@ def get_node_third_party_process_dict(self):
def get_process_state(self, fail_status_bits):
return self.get_process_state_base(
fail_status_bits, ProcessStateNames, ProcessState)

def get_package_name(self):
return self.node_type
21 changes: 18 additions & 3 deletions src/nodemgr/common/event_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
from buildinfo import build_info
from pysandesh.sandesh_logger import *
from pysandesh.gen_py.sandesh.ttypes import SandeshLevel
from nodemgr.utils import NodeMgrUtils


def package_installed(pkg):
Expand Down Expand Up @@ -81,6 +82,7 @@ def __init__(self, rule_file, discovery_server,
self.send_build_info = send_build_info
self.last_cpu = None
self.last_time = 0
self.installed_package_version = None

# Get all the current processes in the node
def get_current_process(self):
Expand Down Expand Up @@ -387,15 +389,23 @@ def send_nodemgr_process_status_base(self, ProcessStateNames,
SandeshLevel.SYS_INFO), msg)
node_status_uve.send()

def send_system_cpu_info(self):
def send_init_info(self):
# system_cpu_info
mem_cpu_usage_data = MemCpuUsageData(os.getpid(), self.last_cpu, self.last_time)
sys_cpu = SystemCpuInfo()
sys_cpu.num_socket = mem_cpu_usage_data.get_num_socket()
sys_cpu.num_cpu = mem_cpu_usage_data.get_num_cpu()
sys_cpu.num_core_per_socket = mem_cpu_usage_data.get_num_core_per_socket()
sys_cpu.num_thread_per_core = mem_cpu_usage_data.get_num_thread_per_core()
node_status = NodeStatus(name=socket.gethostname(),
system_cpu_info=sys_cpu)

# installed/running package version
self.installed_package_version = NodeMgrUtils.get_package_version \
(self.get_package_name())
node_status = NodeStatus(
name=socket.gethostname(),
system_cpu_info=sys_cpu,
installed_package_version=self.installed_package_version,
running_package_version=self.installed_package_version)
node_status_uve = NodeStatusUVE(table=self.table,
data=node_status)
node_status_uve.send()
Expand Down Expand Up @@ -578,6 +588,11 @@ def event_tick_60(self):
# encode other core file
if self.update_all_core_file():
node_status.all_core_file_list = self.all_core_file_list
installed_package_version = NodeMgrUtils.get_package_version( \
self.get_package_name())
if (installed_package_version != self.installed_package_version):
self.installed_package_version = installed_package_version
node_status.installed_package_version = installed_package_version
if (self.send_build_info):
node_status.build_info = self.get_build_info()
node_status_uve = NodeStatusUVE(table=self.table,
Expand Down
5 changes: 4 additions & 1 deletion src/nodemgr/config_nodemgr/config_event_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def __init__(self, rule_file, discovery_server,
self.module_id, self.instance_id,
staticmethod(ConnectionState.get_process_state_cb),
NodeStatusUVE, NodeStatus, self.table)
self.send_system_cpu_info()
self.send_init_info()
self.third_party_process_dict = {}
# end __init__

Expand Down Expand Up @@ -106,3 +106,6 @@ def do_periodic_events(self):
# Perform nodetool repair every cassandra_repair_interval hours
if self.tick_count % (60 * self.cassandra_repair_interval) == 0:
self.cassandra_mgr.repair()

def get_package_name(self):
return self.node_type
5 changes: 4 additions & 1 deletion src/nodemgr/control_nodemgr/control_event_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def __init__(self, rule_file, discovery_server,
self.instance_id,
staticmethod(ConnectionState.get_process_state_cb),
NodeStatusUVE, NodeStatus, self.table)
self.send_system_cpu_info()
self.send_init_info()
self.third_party_process_dict = {}
# end __init__

Expand All @@ -88,3 +88,6 @@ def get_node_third_party_process_dict(self):
def get_process_state(self, fail_status_bits):
return self.get_process_state_base(
fail_status_bits, ProcessStateNames, ProcessState)

def get_package_name(self):
return self.node_type
5 changes: 4 additions & 1 deletion src/nodemgr/database_nodemgr/database_event_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def __init__(self, rule_file, discovery_server,
self.instance_id,
staticmethod(ConnectionState.get_process_state_cb),
NodeStatusUVE, NodeStatus, self.table)
self.send_system_cpu_info()
self.send_init_info()
self.third_party_process_dict = {}
self.third_party_process_dict["cassandra"] = "Dcassandra-pidfile=.*cassandra\.pid"
self.third_party_process_dict["zookeeper"] = "org.apache.zookeeper.server.quorum.QuorumPeerMain"
Expand Down Expand Up @@ -369,3 +369,6 @@ def runforever(self, test=False):
self.database_periodic()
self.event_tick_60()
self.listener_nodemgr.ok(self.stdout)

def get_package_name(self):
return self.node_type + '-common'
13 changes: 13 additions & 0 deletions src/nodemgr/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#
# Copyright (c) 2016 Juniper Networks, Inc. All rights reserved.
#

import os

class NodeMgrUtils(object):
@staticmethod
def get_package_version(pkg):
#retrieve current installed version of pkg
cmd = "contrail-version %s | grep %s" % (pkg,pkg)
version = os.popen(cmd).read()
return version.split()[1]
5 changes: 4 additions & 1 deletion src/nodemgr/vrouter_nodemgr/vrouter_event_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def __init__(self, rule_file, discovery_server,
NodeStatusUVE, NodeStatus, self.table)

self.lb_stats = LoadbalancerStatsUVE()
self.send_system_cpu_info()
self.send_init_info()
self.third_party_process_dict = {}
# end __init__

Expand Down Expand Up @@ -145,3 +145,6 @@ def runforever(self, test=False):
self.lb_stats.send_loadbalancer_stats()

self.listener_nodemgr.ok(self.stdout)

def get_package_name(self):
return self.node_type + '-common'
60 changes: 60 additions & 0 deletions src/opserver/test/test_alarm_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -2271,6 +2271,66 @@ def test_alarm_pending_cassandra_compaction_tasks(self):
self._verify(tests, alarm_name="pending-cassandra-compaction-tasks")
# end test_alarm_pending_cassandra_compaction_tasks

def test_alarm_package_version(self):
tests = [

TestCase(
name='NodeStatus == null',
input=TestInput(uve_key='ObjectCollectorInfo:host1',
uve_data={}),
output=TestOutput(or_list=None)
),
TestCase(
name='NodeStatus.running_package_version == ' +\
'NodeStatus.installed_package_version',
input=TestInput(uve_key='ObjectCollectorInfo:host1',
uve_data={
'NodeStatus': {
'running_package_version': '"3.1.0.0-2740"',
'installed_package_version': '"3.1.0.0-2740"'
}
}
),
output=TestOutput(or_list=None)
),
TestCase(
name='NodeStatus.running_package_version != ' +\
'NodeStatus.installed_package_version',
input=TestInput(uve_key='ObjectCollectorInfo:host1',
uve_data={
'NodeStatus': {
'running_package_version': '"3.1.0.0-2740"',
'installed_package_version': '"3.1.0.0-18"'
}
}
),
output=TestOutput(or_list=[
{
'and_list': [
{
'condition': {
'operand1': 'NodeStatus.running_package_version',
'operand2': {
'uve_attribute':
'NodeStatus.installed_package_version'
},
'operation': '!='
},
'match': [
{
'json_operand1_val': '"3.1.0.0-2740"',
'json_operand2_val': '"3.1.0.0-18"'
}
]
}
]
}
])
)
]
self._verify(tests, alarm_name="package-version-mismatch")
# end test_alarm_package_version

def _verify(self, tests, plugin=None, alarm_name=None):
for test in tests:
name = alarm_name or plugin.__class__.__name__
Expand Down

0 comments on commit 90d613f

Please sign in to comment.