From 935aa906ba25bd6631db54d254a93dadb709aecf Mon Sep 17 00:00:00 2001 From: Tao Liu Date: Thu, 16 Aug 2018 11:45:01 -0400 Subject: [PATCH] Decouple Fault Management from stx-config Update NFV to use FM rest API service: Add a NFVI open stack plugin for FM Update the NFV infrastructure and web server to use FM plugin Update sysinv plugin and remove get alarms and logs calls Story: 2002828 Task: 22747 Depends-On: https://review.openstack.org/#/c/591452/ Change-Id: I60ff74ccfb2ec2eaad427a23fe4d58d4fc49ab79 Signed-off-by: Tao Liu --- .../nfv_plugins/nfvi_plugins/config.ini | 8 +- .../nfvi_plugins/nfvi_infrastructure_api.py | 9 +- .../nfv_plugins/nfvi_plugins/openstack/fm.py | 84 +++++++++++++++++++ .../nfvi_plugins/openstack/objects.py | 3 +- .../nfvi_plugins/openstack/sysinv.py | 74 +--------------- .../nfv_scenario_tests/tests/_alarms.py | 4 +- .../nfv_scenario_tests/tests/_test_hosts.py | 9 +- .../tests/_test_instances.py | 9 +- nfv/nfv-vim/nfv_vim/api/openstack/_objects.py | 1 + nfv/nfv-vim/nfv_vim/webserver/_webserver.py | 6 +- 10 files changed, 115 insertions(+), 92 deletions(-) create mode 100755 nfv/nfv-plugins/nfv_plugins/nfvi_plugins/openstack/fm.py diff --git a/nfv/nfv-plugins/nfv_plugins/nfvi_plugins/config.ini b/nfv/nfv-plugins/nfv_plugins/nfvi_plugins/config.ini index 2f8c393e..075c08f0 100755 --- a/nfv/nfv-plugins/nfv_plugins/nfvi_plugins/config.ini +++ b/nfv/nfv-plugins/nfv_plugins/nfvi_plugins/config.ini @@ -1,5 +1,5 @@ # -# Copyright (c) 2015-2016 Wind River Systems, Inc. +# Copyright (c) 2015-2018 Wind River Systems, Inc. # # SPDX-License-Identifier: Apache-2.0 # @@ -71,6 +71,12 @@ service_name=patching service_type=patching endpoint_type=admin +[fm] +region_name=RegionOne +service_name=fm +service_type=faultmanagement +endpoint_type=admin + [amqp] host=192.168.204.2 port=5672 diff --git a/nfv/nfv-plugins/nfv_plugins/nfvi_plugins/nfvi_infrastructure_api.py b/nfv/nfv-plugins/nfv_plugins/nfvi_plugins/nfvi_infrastructure_api.py index 8002e264..0fb1f4a3 100755 --- a/nfv/nfv-plugins/nfv_plugins/nfvi_plugins/nfvi_infrastructure_api.py +++ b/nfv/nfv-plugins/nfv_plugins/nfvi_plugins/nfvi_infrastructure_api.py @@ -16,6 +16,7 @@ from openstack import rest_api from openstack import exceptions from openstack import openstack from openstack import sysinv +from openstack import fm from openstack import mtc from openstack import nova from openstack import neutron @@ -2412,7 +2413,7 @@ class NFVIInfrastructureAPI(nfvi.api.v1.NFVIInfrastructureAPI): self._token = future.result.data - future.work(sysinv.get_alarms, self._token) + future.work(fm.get_alarms, self._token) future.result = (yield) if not future.result.is_complete(): @@ -2420,7 +2421,7 @@ class NFVIInfrastructureAPI(nfvi.api.v1.NFVIInfrastructureAPI): alarms = list() - for alarm_data in future.result.data['ialarms']: + for alarm_data in future.result.data['alarms']: alarm = nfvi.objects.v1.Alarm( alarm_data['uuid'], alarm_data['alarm_id'], alarm_data['entity_instance_id'], alarm_data['severity'], @@ -2470,7 +2471,7 @@ class NFVIInfrastructureAPI(nfvi.api.v1.NFVIInfrastructureAPI): self._token = future.result.data - future.work(sysinv.get_logs, self._token, start_period, end_period) + future.work(fm.get_logs, self._token, start_period, end_period) future.result = (yield) if not future.result.is_complete(): @@ -2517,7 +2518,7 @@ class NFVIInfrastructureAPI(nfvi.api.v1.NFVIInfrastructureAPI): self._token = future.result.data - future.work(sysinv.get_alarm_history, self._token, start_period, + future.work(fm.get_alarm_history, self._token, start_period, end_period) future.result = (yield) diff --git a/nfv/nfv-plugins/nfv_plugins/nfvi_plugins/openstack/fm.py b/nfv/nfv-plugins/nfv_plugins/nfvi_plugins/openstack/fm.py new file mode 100755 index 00000000..38f1b1ed --- /dev/null +++ b/nfv/nfv-plugins/nfv_plugins/nfvi_plugins/openstack/fm.py @@ -0,0 +1,84 @@ +# +# Copyright (c) 2018 Wind River Systems, Inc. +# +# SPDX-License-Identifier: Apache-2.0 +# + +from nfv_common import debug + +from objects import OPENSTACK_SERVICE +from rest_api import rest_api_request + +DLOG = debug.debug_get_logger('nfv_plugins.nfvi_plugins.openstack.fm') + + +def get_alarms(token): + """ + Asks Fault Management for customer alarms + """ + url = token.get_service_url(OPENSTACK_SERVICE.FM) + if url is None: + raise ValueError("OpenStack FM URL is invalid") + + api_cmd = url + "/alarms?include_suppress=True" + + response = rest_api_request(token, "GET", api_cmd) + return response + + +def get_logs(token, start=None, end=None): + """ + Asks Fault Management for customer logs + """ + url = token.get_service_url(OPENSTACK_SERVICE.FM) + if url is None: + raise ValueError("OpenStack SysInv URL is invalid") + + api_cmd = url + "/event_log?logs=True" + + if start is not None and end is not None: + api_cmd += ("&q.field=start&q.field=end&q.op=eq&q.op=eq" + "&q.value=%s&q.value=%s" + % (str(start).replace(' ', 'T').replace(':', '%3A'), + str(end).replace(' ', 'T').replace(':', '%3A'))) + + elif start is not None: + api_cmd += ("&q.field=start;q.op=eq;q.value=%s" + % str(start).replace(' ', 'T').replace(':', '%3A')) + elif end is not None: + api_cmd += ("&q.field=end;q.op=eq;q.value=%s" + % str(end).replace(' ', 'T').replace(':', '%3A')) + + api_cmd += '&limit=100' + + response = rest_api_request(token, "GET", api_cmd) + return response + + +def get_alarm_history(token, start=None, end=None): + """ + Asks Fault Management for customer alarm history + """ + url = token.get_service_url(OPENSTACK_SERVICE.FM) + if url is None: + raise ValueError("OpenStack SysInv URL is invalid") + + api_cmd = url + "/event_log?alarms=True" + + if start is not None and end is not None: + api_cmd += ("&q.field=start&q.field=end&q.op=eq&q.op=eq" + "&q.value=%s&q.value=%s" + % (str(start).replace(' ', 'T').replace(':', '%3A'), + str(end).replace(' ', 'T').replace(':', '%3A'))) + + elif start is not None: + api_cmd += ("&q.field=start;q.op=eq;q.value='%s'" + % str(start).replace(' ', 'T').replace(':', '%3A')) + elif end is not None: + api_cmd += ("&q.field=end;q.op=eq;q.value='%s'" + % str(end).replace(' ', 'T').replace(':', '%3A')) + + api_cmd += '&limit=100' + + response = rest_api_request(token, "GET", api_cmd) + return response diff --git a/nfv/nfv-plugins/nfv_plugins/nfvi_plugins/openstack/objects.py b/nfv/nfv-plugins/nfv_plugins/nfvi_plugins/openstack/objects.py index 6012e8f9..e1ae7eb7 100755 --- a/nfv/nfv-plugins/nfv_plugins/nfvi_plugins/openstack/objects.py +++ b/nfv/nfv-plugins/nfv_plugins/nfvi_plugins/openstack/objects.py @@ -1,5 +1,5 @@ # -# Copyright (c) 2015-2016 Wind River Systems, Inc. +# Copyright (c) 2015-2018 Wind River Systems, Inc. # # SPDX-License-Identifier: Apache-2.0 # @@ -30,6 +30,7 @@ class OpenStackServices(Constants): SYSINV = Constant('sysinv') HEAT = Constant('heat') PATCHING = Constant('patching') + FM = Constant('fm') # OpenStack Services Constant diff --git a/nfv/nfv-plugins/nfv_plugins/nfvi_plugins/openstack/sysinv.py b/nfv/nfv-plugins/nfv_plugins/nfvi_plugins/openstack/sysinv.py index f4990b96..a0aa4cae 100755 --- a/nfv/nfv-plugins/nfv_plugins/nfvi_plugins/openstack/sysinv.py +++ b/nfv/nfv-plugins/nfv_plugins/nfvi_plugins/openstack/sysinv.py @@ -1,5 +1,5 @@ # -# Copyright (c) 2015-2016 Wind River Systems, Inc. +# Copyright (c) 2015-2018 Wind River Systems, Inc. # # SPDX-License-Identifier: Apache-2.0 # @@ -443,75 +443,3 @@ def swact_from_host(token, host_uuid): response = rest_api_request(token, "PATCH", api_cmd, api_cmd_headers, json.dumps(api_cmd_payload)) return response - - -def get_alarms(token): - """ - Asks System Inventory for customer alarms - """ - url = token.get_service_url(OPENSTACK_SERVICE.SYSINV) - if url is None: - raise ValueError("OpenStack SysInv URL is invalid") - - api_cmd = url + "/ialarms?include_suppress=True" - - response = rest_api_request(token, "GET", api_cmd) - return response - - -def get_logs(token, start=None, end=None): - """ - Asks System Inventory for customer logs - """ - url = token.get_service_url(OPENSTACK_SERVICE.SYSINV) - if url is None: - raise ValueError("OpenStack SysInv URL is invalid") - - api_cmd = url + "/event_log?logs=True" - - if start is not None and end is not None: - api_cmd += ("&q.field=start&q.field=end&q.op=eq&q.op=eq" - "&q.value=%s&q.value=%s" - % (str(start).replace(' ', 'T').replace(':', '%3A'), - str(end).replace(' ', 'T').replace(':', '%3A'))) - - elif start is not None: - api_cmd += ("&q.field=start;q.op=eq;q.value=%s" - % str(start).replace(' ', 'T').replace(':', '%3A')) - elif end is not None: - api_cmd += ("&q.field=end;q.op=eq;q.value=%s" - % str(end).replace(' ', 'T').replace(':', '%3A')) - - api_cmd += '&limit=100' - - response = rest_api_request(token, "GET", api_cmd) - return response - - -def get_alarm_history(token, start=None, end=None): - """ - Asks System Inventory for customer alarm history - """ - url = token.get_service_url(OPENSTACK_SERVICE.SYSINV) - if url is None: - raise ValueError("OpenStack SysInv URL is invalid") - - api_cmd = url + "/event_log?alarms=True" - - if start is not None and end is not None: - api_cmd += ("&q.field=start&q.field=end&q.op=eq&q.op=eq" - "&q.value=%s&q.value=%s" - % (str(start).replace(' ', 'T').replace(':', '%3A'), - str(end).replace(' ', 'T').replace(':', '%3A'))) - - elif start is not None: - api_cmd += ("&q.field=start;q.op=eq;q.value='%s'" - % str(start).replace(' ', 'T').replace(':', '%3A')) - elif end is not None: - api_cmd += ("&q.field=end;q.op=eq;q.value='%s'" - % str(end).replace(' ', 'T').replace(':', '%3A')) - - api_cmd += '&limit=100' - - response = rest_api_request(token, "GET", api_cmd) - return response diff --git a/nfv/nfv-tests/nfv_scenario_tests/tests/_alarms.py b/nfv/nfv-tests/nfv_scenario_tests/tests/_alarms.py index dccc55a2..f3894a3e 100755 --- a/nfv/nfv-tests/nfv_scenario_tests/tests/_alarms.py +++ b/nfv/nfv-tests/nfv_scenario_tests/tests/_alarms.py @@ -1,5 +1,5 @@ # -# Copyright (c) 2015-2016 Wind River Systems, Inc. +# Copyright (c) 2015-2018 Wind River Systems, Inc. # # SPDX-License-Identifier: Apache-2.0 # @@ -7,7 +7,7 @@ from fm_api import constants as fm_constants def _instance_alarm_raised(alarms, expected_alarm, instance): - for alarm in alarms['ialarms']: + for alarm in alarms['alarms']: if expected_alarm['alarm_id'] == str(alarm['alarm_id']): if expected_alarm['severity'] == str(alarm['severity']): return True diff --git a/nfv/nfv-tests/nfv_scenario_tests/tests/_test_hosts.py b/nfv/nfv-tests/nfv_scenario_tests/tests/_test_hosts.py index b014c3d7..550eb6c6 100755 --- a/nfv/nfv-tests/nfv_scenario_tests/tests/_test_hosts.py +++ b/nfv/nfv-tests/nfv_scenario_tests/tests/_test_hosts.py @@ -1,5 +1,5 @@ # -# Copyright (c) 2015-2016 Wind River Systems, Inc. +# Copyright (c) 2015-2018 Wind River Systems, Inc. # # SPDX-License-Identifier: Apache-2.0 # @@ -13,6 +13,7 @@ from nfv_common import debug from nfv_plugins.nfvi_plugins import config from nfv_plugins.nfvi_plugins.openstack import nova from nfv_plugins.nfvi_plugins.openstack import sysinv +from nfv_plugins.nfvi_plugins.openstack import fm from nfv_plugins.nfvi_plugins.openstack import openstack import _hosts @@ -175,7 +176,7 @@ class TestHost(_test_base.Test): """ Fetch the customer alarms raised """ - self._customer_alarms = sysinv.get_alarms(self.token).result_data + self._customer_alarms = fm.get_alarms(self.token).result_data return @@ -183,14 +184,14 @@ class TestHost(_test_base.Test): """ Fetch the customer logs """ - self._customer_logs = sysinv.get_logs(self.token, self.start_datetime, + self._customer_logs = fm.get_logs(self.token, self.start_datetime, self.end_datetime).result_data def _refresh_customer_alarm_history(self): """ Fetch the customer alarm history """ - self._customer_alarm_history = sysinv.get_alarm_history( + self._customer_alarm_history = fm.get_alarm_history( self.token, self.start_datetime, self.end_datetime).result_data diff --git a/nfv/nfv-tests/nfv_scenario_tests/tests/_test_instances.py b/nfv/nfv-tests/nfv_scenario_tests/tests/_test_instances.py index c5d63078..93e21c56 100755 --- a/nfv/nfv-tests/nfv_scenario_tests/tests/_test_instances.py +++ b/nfv/nfv-tests/nfv_scenario_tests/tests/_test_instances.py @@ -1,5 +1,5 @@ # -# Copyright (c) 2015-2016 Wind River Systems, Inc. +# Copyright (c) 2015-2018 Wind River Systems, Inc. # # SPDX-License-Identifier: Apache-2.0 # @@ -13,6 +13,7 @@ from nfv_common import debug from nfv_plugins.nfvi_plugins import config from nfv_plugins.nfvi_plugins.openstack import nova from nfv_plugins.nfvi_plugins.openstack import sysinv +from nfv_plugins.nfvi_plugins.openstack import fm from nfv_plugins.nfvi_plugins.openstack import openstack import _instances @@ -162,20 +163,20 @@ class TestInstance(_test_base.Test): """ Fetch the customer alarms raised """ - self._customer_alarms = sysinv.get_alarms(self.token).result_data + self._customer_alarms = fm.get_alarms(self.token).result_data def _refresh_customer_logs(self): """ Fetch the customer logs """ - self._customer_logs = sysinv.get_logs(self.token, self.start_datetime, + self._customer_logs = fm.get_logs(self.token, self.start_datetime, self.end_datetime).result_data def _refresh_customer_alarm_history(self): """ Fetch the customer alarm history """ - self._customer_alarm_history = sysinv.get_alarm_history( + self._customer_alarm_history = fm.get_alarm_history( self.token, self.start_datetime, self.end_datetime).result_data diff --git a/nfv/nfv-vim/nfv_vim/api/openstack/_objects.py b/nfv/nfv-vim/nfv_vim/api/openstack/_objects.py index 38d3c0b6..ad092363 100755 --- a/nfv/nfv-vim/nfv_vim/api/openstack/_objects.py +++ b/nfv/nfv-vim/nfv_vim/api/openstack/_objects.py @@ -29,6 +29,7 @@ class OpenStackServices(Constants): NOVA = Constant('nova') SYSINV = Constant('sysinv') HEAT = Constant('heat') + FM = Constant('fm') # OpenStack Services Constant diff --git a/nfv/nfv-vim/nfv_vim/webserver/_webserver.py b/nfv/nfv-vim/nfv_vim/webserver/_webserver.py index ca0991ac..ca0a4f30 100755 --- a/nfv/nfv-vim/nfv_vim/webserver/_webserver.py +++ b/nfv/nfv-vim/nfv_vim/webserver/_webserver.py @@ -15,7 +15,7 @@ from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer from nfv_common import debug from nfv_plugins.nfvi_plugins import config from nfv_plugins.nfvi_plugins.openstack import openstack -from nfv_plugins.nfvi_plugins.openstack import sysinv +from nfv_plugins.nfvi_plugins.openstack import fm from nfv_vim import database DLOG = debug.debug_get_logger('nfv_vim.webserver.webserver') @@ -226,9 +226,9 @@ class HTTPRequestHandler(BaseHTTPRequestHandler): _token = openstack.get_token(_directory) _lock.release() - result = sysinv.get_alarms(_token) + result = fm.get_alarms(_token) if result.result_data: - for alarm in result.result_data['ialarms']: + for alarm in result.result_data['alarms']: if 'critical' == alarm['severity']: critical_alarms += 1 elif 'major' == alarm['severity']: