Loading the process list written in YAML

Add the process list file written in YAML, and add
implementation of loading the file.

Change-Id: I1d6be1e7ad3f3235a7769c2ec8ce57e01df79142
Implements: bp change-proc-list-format
This commit is contained in:
Kengo Takahara 2016-12-06 20:39:31 +09:00
parent 1d852ff626
commit 926a0d3e31
7 changed files with 175 additions and 1 deletions

View File

@ -0,0 +1,62 @@
# Define the monitoring processes as follows:
# process_name: [Name of the process as it in 'ps -ef'.]
# start_command: [Start command of the process.]
# pre_start_command: [Command which is executed before start_command.]
# post_start_command: [Command which is executed after start_command.]
# restart_command: [Restart command of the process.]
# pre_restart_command: [Command which is executed before restart_command.]
# post_restart_command: [Command which is executed after restart_command.]
# run_as_root: [Bool value whether to execute commands as root authority.]
#
# These definitions need to be set according to the environment to use.
# Sample of definitions is shown below.
-
# libvirt-bin
process_name: /usr/sbin/libvirtd
start_command: systemctl start libvirt-bin
pre_start_command:
post_start_command:
restart_command: systemctl restart libvirt-bin
pre_restart_command:
post_restart_command:
run_as_root: True
-
# nova-compute
process_name: /usr/local/bin/nova-compute
start_command: systemctl start nova-compute
pre_start_command:
post_start_command:
restart_command: systemctl restart service nova-compute
pre_restart_command:
post_restart_command:
run_as_root: True
-
# instancemonitor
process_name: /usr/bin/python /usr/local/bin/masakari-instancemonitor
start_command: systemctl start masakari-instancemonitor
pre_start_command:
post_start_command:
restart_command: systemctl restart masakari-instancemonitor
pre_restart_command:
post_restart_command:
run_as_root: True
-
# hostmonitor
process_name: /usr/bin/python /usr/local/bin/masakari-hostmonitor
start_command: systemctl start masakari-hostmonitor
pre_start_command:
post_start_command:
restart_command: systemctl restart masakari-hostmonitor
pre_restart_command:
post_restart_command:
run_as_root: True
-
# sshd
process_name: /usr/sbin/sshd
start_command: systemctl start ssh
pre_start_command:
post_start_command:
restart_command: systemctl restart ssh
pre_restart_command:
post_restart_command:
run_as_root: True

View File

@ -16,6 +16,7 @@ from oslo_config import cfg
from masakarimonitors.conf import api
from masakarimonitors.conf import base
from masakarimonitors.conf import instance
from masakarimonitors.conf import process
from masakarimonitors.conf import service
CONF = cfg.CONF
@ -23,4 +24,5 @@ CONF = cfg.CONF
api.register_opts(CONF)
base.register_opts(CONF)
instance.register_opts(CONF)
process.register_opts(CONF)
service.register_opts(CONF)

View File

@ -0,0 +1,31 @@
# Copyright(c) 2016 Nippon Telegraph and Telephone 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 oslo_config import cfg
monitor_process_opts = [
cfg.StrOpt('process_list_path',
default='/etc/masakarimonitors/process_list.yaml',
help='The file path of process list.'),
]
def register_opts(conf):
conf.register_opts(monitor_process_opts, group='process')
def list_opts():
return {
'process': monitor_process_opts
}

View File

@ -12,11 +12,16 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import yaml
from oslo_log import log as oslo_logging
import masakarimonitors.conf
from masakarimonitors.i18n import _LE
from masakarimonitors import manager
LOG = oslo_logging.getLogger(__name__)
CONF = masakarimonitors.conf.CONF
class ProcessmonitorManager(manager.Manager):
@ -26,7 +31,31 @@ class ProcessmonitorManager(manager.Manager):
super(ProcessmonitorManager, self).__init__(
service_name="processmonitor", *args, **kwargs)
def _load_process_list(self):
try:
process_list = yaml.load(file(CONF.process.process_list_path))
LOG.debug("Loaded process list. %s" % process_list)
return process_list
except yaml.YAMLError as e:
LOG.exception(_LE("YAMLError caught: %s"), e)
return
except Exception as e:
LOG.exception(_LE("Exception caught: %s"), e)
return
def main(self):
"""Main method."""
pass
try:
# Load process list.
process_list = self._load_process_list()
if process_list is None:
LOG.error(_LE("Failed to load process list file."))
return
except Exception as e:
LOG.exception(_LE("Exception caught: %s"), e)
return
return

View File

View File

@ -0,0 +1,50 @@
# Copyright(c) 2016 Nippon Telegraph and Telephone 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.
import eventlet
eventlet.monkey_patch(os=False)
import mock
import yaml
import testtools
from masakarimonitors.processmonitor import process as processmonitor_manager
MOCK_PROCESS_LIST = [
{
'process_name': 'mock_process_name_A',
'start_command': 'mock_start_command',
'pre_start_command': 'mock_pre_start_command',
'post_start_command': 'mock_post_start_command',
'restart_command': 'mock_restart_command',
'pre_restart_command': 'mock_pre_restart_command',
'post_restart_command': 'mock_post_restart_command',
'run_as_root': True
},
]
class TestProcessmonitorManager(testtools.TestCase):
def setUp(self):
super(TestProcessmonitorManager, self).setUp()
@mock.patch.object(yaml, 'load')
def test_main(self, mock_load):
mock_load.return_value = MOCK_PROCESS_LIST
obj = processmonitor_manager.ProcessmonitorManager()
obj.main()