Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
slapos.toolbox
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kirill Smelkov
slapos.toolbox
Commits
9de2b6c4
Commit
9de2b6c4
authored
Aug 07, 2023
by
Lu Xu
👀
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
promise/plugin: add PA over output power for Lopcomm RU
parent
c2ebc726
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
138 additions
and
0 deletions
+138
-0
slapos/promise/plugin/check_lopcomm_pa_output_power.py
slapos/promise/plugin/check_lopcomm_pa_output_power.py
+62
-0
slapos/test/promise/plugin/test_check_lopcomm_pa_output_power.py
...test/promise/plugin/test_check_lopcomm_pa_output_power.py
+76
-0
No files found.
slapos/promise/plugin/check_lopcomm_pa_output_power.py
0 → 100644
View file @
9de2b6c4
import
errno
import
json
import
logging
import
os
from
dateutil
import
parser
from
.util
import
iter_logrotate_file_handle
from
.util
import
iter_reverse_lines
from
.util
import
JSONPromise
from
zope.interface
import
implementer
from
slapos.grid.promise
import
interface
@
implementer
(
interface
.
IPromise
)
class
RunPromise
(
JSONPromise
):
def
__init__
(
self
,
config
):
super
(
RunPromise
,
self
).
__init__
(
config
)
self
.
setPeriodicity
(
minute
=
1
)
self
.
netconf_log
=
self
.
getConfig
(
'netconf-log'
)
self
.
testing
=
self
.
getConfig
(
'testing'
)
==
"True"
def
sense
(
self
):
if
self
.
testing
:
self
.
logger
.
info
(
"skipping promise"
)
return
for
f
in
iter_logrotate_file_handle
(
self
.
netconf_log
,
'rb'
):
for
line
in
iter_reverse_lines
(
f
):
l
=
json
.
loads
(
line
.
decode
().
replace
(
"'"
,
'"'
))
alarm_notif
=
l
.
get
(
'data'
,
{}).
get
(
'notification'
,
{}).
get
(
'alarm-notif'
,
None
)
if
alarm_notif
and
alarm_notif
[
'fault-id'
]
==
'9'
:
if
alarm_notif
[
'is-cleared'
]
==
'false'
:
affected_objects
=
alarm_notif
.
get
(
'affected-objects'
,
{})
self
.
logger
.
error
(
'PA Over Output Power Alarm is on, affected objects are: %s'
,
affected_objects
)
self
.
json_logger
.
info
(
"Affected objects"
,
extra
=
{
'data'
:
affected_objects
})
else
:
self
.
logger
.
info
(
'PA Over Output Power Alarm is off'
)
return
self
.
logger
.
info
(
'No PA Over Output Power Alarm received'
)
def
test
(
self
):
"""
Called after sense() if the instance is still converging.
Returns success or failure based on sense results.
In this case, fail if the previous sensor result is negative.
"""
return
self
.
_test
(
result_count
=
1
,
failure_amount
=
1
)
def
anomaly
(
self
):
"""
Called after sense() if the instance has finished converging.
Returns success or failure based on sense results.
Failure signals the instance has diverged.
In this case, fail if two out of the last three results are negative.
"""
return
self
.
_anomaly
(
result_count
=
1
,
failure_amount
=
1
)
slapos/test/promise/plugin/test_check_lopcomm_pa_output_power.py
0 → 100644
View file @
9de2b6c4
# -*- coding: utf-8 -*-
##############################################################################
# Copyright (c) 2018 Vifib SARL and Contributors. All Rights Reserved.
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsibility of assessing all potential
# consequences resulting from its eventual inadequacies and bugs
# End users who are looking for a ready-to-use solution with commercial
# guarantees and support are strongly advised to contract a Free Software
# Service Company
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
##############################################################################
import
os
import
time
from
datetime
import
datetime
from
datetime
import
timedelta
from
slapos.grid.promise
import
PromiseError
from
slapos.promise.plugin.check_lopcomm_pa_output_power
import
RunPromise
from
.
import
TestPromisePluginMixin
class
TestCheckLopcommPAOutputPowerSuccess
(
TestPromisePluginMixin
):
promise_name
=
"check-lopcomm-pa-output-power.py"
def
setUp
(
self
):
super
(
TestCheckLopcommPAOutputPowerSuccess
,
self
).
setUp
()
self
.
netconf_log
=
os
.
path
.
join
(
os
.
path
.
dirname
(
os
.
path
.
realpath
(
__file__
)),
'netconf.json.log'
)
def
writePromise
(
self
,
**
kw
):
super
(
TestCheckLopcommPAOutputPowerSuccess
,
self
).
writePromise
(
self
.
promise_name
,
"from %s import %s
\
n
extra_config_dict = %r
\
n
"
%
(
RunPromise
.
__module__
,
RunPromise
.
__name__
,
kw
))
def
test_promise_success
(
self
):
with
open
(
self
.
netconf_log
,
'w+'
)
as
f
:
f
.
write
(
"""{"time": "%s", "log_level": "INFO", "message": "", "data": {'notification': {'@xmlns': 'urn:ietf:params:xml:ns:netconf:notification:1.0', 'eventTime': '1970-01-05T00:38:50Z', 'alarm-notif': {'@xmlns': 'urn:o-ran:fm:1.0', 'fault-id': '9', 'fault-source': 'PA0', 'affected-objects': {'name': 'PA0'}, 'fault-severity': 'MINOR', 'is-cleared': 'false', 'fault-text': 'PA 1 Over Output Power Alarm', 'event-time': '1970-01-05T00:38:50Z'}}}}
{"time": "%s", "log_level": "INFO", "message": "", "data": {'notification': {'@xmlns': 'urn:ietf:params:xml:ns:netconf:notification:1.0', 'eventTime': '1970-01-05T00:38:50Z', 'alarm-notif': {'@xmlns': 'urn:o-ran:fm:1.0', 'fault-id': '9', 'fault-source': 'PA0', 'affected-objects': {'name': 'PA0'}, 'fault-severity': 'MINOR', 'is-cleared': 'true', 'fault-text': 'PA 1 Over Output Power Alarm', 'event-time': '1970-01-05T00:38:50Z'}}}}"""
%
(
(
datetime
.
now
()
-
timedelta
(
seconds
=
25
)).
strftime
(
"%Y-%m-%d %H:%M:%S,%f"
)[:
-
3
],
(
datetime
.
now
()
-
timedelta
(
seconds
=
15
)).
strftime
(
"%Y-%m-%d %H:%M:%S,%f"
)[:
-
3
],
))
self
.
writePromise
(
**
{
'netconf-log'
:
self
.
netconf_log
,
})
self
.
configureLauncher
()
self
.
launcher
.
run
()
def
test_promise_fail
(
self
):
with
open
(
self
.
netconf_log
,
'w+'
)
as
f
:
f
.
write
(
"""{"time": "%s", "log_level": "INFO", "message": "", "data": {'notification': {'@xmlns': 'urn:ietf:params:xml:ns:netconf:notification:1.0', 'eventTime': '1970-01-05T00:38:50Z', 'alarm-notif': {'@xmlns': 'urn:o-ran:fm:1.0', 'fault-id': '9', 'fault-source': 'PA0', 'affected-objects': {'name': 'PA0'}, 'fault-severity': 'MINOR', 'is-cleared': 'true', 'fault-text': 'PA 1 Over Output Power Alarm', 'event-time': '1970-01-05T00:38:50Z'}}}}
{"time": "%s", "log_level": "INFO", "message": "", "data": {'notification': {'@xmlns': 'urn:ietf:params:xml:ns:netconf:notification:1.0', 'eventTime': '1970-01-05T00:38:50Z', 'alarm-notif': {'@xmlns': 'urn:o-ran:fm:1.0', 'fault-id': '9', 'fault-source': 'PA0', 'affected-objects': {'name': 'PA0'}, 'fault-severity': 'MINOR', 'is-cleared': 'false', 'fault-text': 'PA 1 Over Output Power Alarm', 'event-time': '1970-01-05T00:38:50Z'}}}}"""
%
(
(
datetime
.
now
()
-
timedelta
(
seconds
=
25
)).
strftime
(
"%Y-%m-%d %H:%M:%S,%f"
)[:
-
3
],
(
datetime
.
now
()
-
timedelta
(
seconds
=
15
)).
strftime
(
"%Y-%m-%d %H:%M:%S,%f"
)[:
-
3
],
))
self
.
writePromise
(
**
{
'netconf-log'
:
self
.
netconf_log
,
})
self
.
configureLauncher
()
with
self
.
assertRaises
(
PromiseError
):
self
.
launcher
.
run
()
self
.
assertEqual
(
"PA Over Output Power Alarm is on, affected objects are: {'name': 'PA0'}"
,
self
.
getPromiseResult
(
self
.
promise_name
)[
'result'
][
'message'
])
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment