From f317a24a25cd03afd48b4ff6d4d4b8d85c28a540 Mon Sep 17 00:00:00 2001 From: suzhengwei Date: Tue, 18 Feb 2020 17:30:43 +0800 Subject: [PATCH] reset nova-compute process name In masakari-engine, it enable/disable nova-compute service by the process name. So process-monitor need to reset the nova process name to "nova-compute" when trigger process notification. Change-Id: Ia6f22bd1d183093bb0345f323a80268fb62df388 Close-Bug: #1858757 --- lower-constraints.txt | 1 + .../process_handler/handle_process.py | 2 +- .../process_handler/test_handle_process.py | 29 ++++++++++++++----- test-requirements.txt | 2 +- 4 files changed, 24 insertions(+), 10 deletions(-) diff --git a/lower-constraints.txt b/lower-constraints.txt index baf09ed..c86264a 100644 --- a/lower-constraints.txt +++ b/lower-constraints.txt @@ -10,6 +10,7 @@ cliff==2.11.0 cmd2==0.8.1 coverage==4.0 cryptography==2.1.4 +ddt==1.0.1 debtcollector==1.19.0 decorator==4.2.1 deprecation==2.0 diff --git a/masakarimonitors/processmonitor/process_handler/handle_process.py b/masakarimonitors/processmonitor/process_handler/handle_process.py index 04217e0..9678f75 100644 --- a/masakarimonitors/processmonitor/process_handler/handle_process.py +++ b/masakarimonitors/processmonitor/process_handler/handle_process.py @@ -131,7 +131,7 @@ class HandleProcess(object): 'generated_time': current_time, 'payload': { 'event': ec.EventConstants.EVENT_STOPPED, - 'process_name': process_name + 'process_name': process_name.split('/')[-1] } } } diff --git a/masakarimonitors/tests/unit/processmonitor/process_handler/test_handle_process.py b/masakarimonitors/tests/unit/processmonitor/process_handler/test_handle_process.py index fa20d8c..d9bb1bb 100644 --- a/masakarimonitors/tests/unit/processmonitor/process_handler/test_handle_process.py +++ b/masakarimonitors/tests/unit/processmonitor/process_handler/test_handle_process.py @@ -16,6 +16,7 @@ import socket import testtools from unittest import mock +import ddt import eventlet from oslo_utils import timeutils @@ -28,10 +29,12 @@ from masakarimonitors import utils CONF = masakarimonitors.conf.CONF eventlet.monkey_patch(os=False) +NOVA_COMPUTE = 'nova-compute' + MOCK_PROCESS_LIST = [ { 'id': 1, - 'process_name': 'mock_process_name_A', + 'process_name': '/usr/local/bin/nova-compute', 'start_command': 'mock_start_command', 'pre_start_command': 'mock_pre_start_command', 'post_start_command': 'mock_post_start_command', @@ -45,7 +48,7 @@ MOCK_PROCESS_LIST = [ MOCK_DOWN_PROCESS_LIST = [ { 'id': 1, - 'process_name': 'mock_process_name_A', + 'process_name': '/usr/local/bin/nova-compute', 'start_command': 'mock_start_command', 'pre_start_command': 'mock_pre_start_command', 'post_start_command': 'mock_post_start_command', @@ -56,11 +59,13 @@ MOCK_DOWN_PROCESS_LIST = [ }, ] -PS_RESULT = "\n" \ - "UID PID PPID C STIME TTY TIME CMD\n" \ - "root 11187 1 0 18:52 ? 00:00:00 mock_process_name_A\n" +PS_RESULT = \ + "\n" \ + "UID PID PPID C STIME TTY TIME CMD\n" \ + "root 11187 1 0 18:52 ? 00:00:00 /usr/local/bin/nova-compute\n" +@ddt.ddt class TestHandleProcess(testtools.TestCase): def setUp(self): @@ -73,6 +78,14 @@ class TestHandleProcess(testtools.TestCase): self.assertEqual(process_list, obj.process_list) + @ddt.data("/usr/local/bin/nova-compute", "nova-compute") + def test_make_event(self, process_name): + obj = handle_process.HandleProcess() + event = obj._make_event(process_name) + self.assertEqual( + NOVA_COMPUTE, + event['notification']['payload']['process_name']) + @mock.patch.object(utils, 'execute') def test_start_processes(self, mock_execute): @@ -227,7 +240,7 @@ class TestHandleProcess(testtools.TestCase): 'generated_time': current_time, 'payload': { 'event': ec.EventConstants.EVENT_STOPPED, - 'process_name': down_process_list[0].get('process_name') + 'process_name': NOVA_COMPUTE } } } @@ -289,7 +302,7 @@ class TestHandleProcess(testtools.TestCase): 'generated_time': current_time, 'payload': { 'event': ec.EventConstants.EVENT_STOPPED, - 'process_name': down_process_list[0].get('process_name') + 'process_name': NOVA_COMPUTE } } } @@ -356,7 +369,7 @@ class TestHandleProcess(testtools.TestCase): 'generated_time': current_time, 'payload': { 'event': ec.EventConstants.EVENT_STOPPED, - 'process_name': down_process_list[0].get('process_name') + 'process_name': NOVA_COMPUTE } } } diff --git a/test-requirements.txt b/test-requirements.txt index 6f59c5e..333d672 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -13,6 +13,6 @@ os-testr>=1.0.0 # Apache-2.0 testrepository>=0.0.18 # Apache-2.0/BSD testscenarios>=0.4 # Apache-2.0/BSD testtools>=2.2.0 # MIT - +ddt>=1.0.1 # MIT # releasenotes reno>=2.5.0 # Apache-2.0