Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
inventory-provider
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
geant-swd
dashboardv3
inventory-provider
Commits
1e4fdbd9
Commit
1e4fdbd9
authored
6 years ago
by
Robert Latta
Browse files
Options
Downloads
Patches
Plain Diff
Tests for alarmsdb
parent
cb92b26d
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
test/test_alarmsdb.py
+101
-0
101 additions, 0 deletions
test/test_alarmsdb.py
with
101 additions
and
0 deletions
test/test_alarmsdb.py
0 → 100644
+
101
−
0
View file @
1e4fdbd9
import
inventory_provider.alarmsdb
as
alarmsdb
def
test_infinera_interface_status
(
mocker
):
mocked_get_cursor
=
mocker
.
patch
(
'
inventory_provider.alarmsdb.cursor
'
)
mocked_execute
=
mocked_get_cursor
.
\
return_value
.
__enter__
.
return_value
.
execute
mocked_fetchone
=
mocked_get_cursor
.
return_value
.
__enter__
.
\
return_value
.
fetchone
mocked_fetchone
.
return_value
=
(
'
Raised
'
,)
assert
alarmsdb
.
get_last_known_infinera_interface_status
(
None
,
'
eq1
'
,
'
intfc1
'
)
==
"
down
"
mocked_fetchone
.
return_value
=
(
"
Clear
"
,)
assert
alarmsdb
.
get_last_known_infinera_interface_status
(
None
,
'
eq1
'
,
'
intfc1
'
)
==
"
up
"
mocked_fetchone
.
return_value
=
()
assert
alarmsdb
.
get_last_known_infinera_interface_status
(
None
,
'
eq1
'
,
'
intfc1
'
)
==
"
unknown
"
mocked_execute
.
assert_called_with
(
"
SELECT status FROM infinera_alarms WHERE
"
"
CONCAT(ne_name,
'
-
'
, REPLACE(object_name,
'
T
'
,
''
)) = %s
"
"
ORDER BY ne_init_time DESC, ne_clear_time DESC LIMIT 1
"
,
(
"
eq1-intfc1
"
,))
def
test_coriant_interface_status
(
mocker
):
mocked_get_cursor
=
mocker
.
patch
(
'
inventory_provider.alarmsdb.cursor
'
)
mocked_execute
=
mocked_get_cursor
.
\
return_value
.
__enter__
.
return_value
.
execute
mocked_fetchone
=
mocked_get_cursor
.
return_value
.
__enter__
.
\
return_value
.
fetchone
mocked_fetchone
.
return_value
=
(
'
Raised
'
,)
assert
alarmsdb
.
get_last_known_coriant_interface_status
(
None
,
'
eq1
'
,
'
intfc1
'
)
==
"
down
"
mocked_fetchone
.
return_value
=
(
"
Clear
"
,)
assert
alarmsdb
.
get_last_known_coriant_interface_status
(
None
,
'
eq1
'
,
'
intfc1
'
)
==
"
up
"
mocked_fetchone
.
return_value
=
()
assert
alarmsdb
.
get_last_known_coriant_interface_status
(
None
,
'
eq1
'
,
'
intfc1
'
)
==
"
unknown
"
mocked_execute
.
assert_called_with
(
"
SELECT status FROM coriant_alarms
"
"
WHERE ne_id_name = %s AND entity_string LIKE %s
"
"
ORDER BY last_event_time DESC LIMIT 1
"
,
(
"
eq1
"
,
"
intfc1-%
"
))
def
test_juniper_interface_status
(
mocker
):
mocked_get_cursor
=
mocker
.
patch
(
'
inventory_provider.alarmsdb.cursor
'
)
mocked_execute
=
mocked_get_cursor
.
\
return_value
.
__enter__
.
return_value
.
execute
mocked_fetchone
=
mocked_get_cursor
.
return_value
.
__enter__
.
\
return_value
.
fetchone
mocked_fetchone
.
return_value
=
(
0
,)
assert
alarmsdb
.
get_last_known_juniper_link_interface_status
(
None
,
'
eq1
'
,
'
intfc1
'
)
==
"
down
"
mocked_fetchone
.
return_value
=
(
1
,)
assert
alarmsdb
.
get_last_known_juniper_link_interface_status
(
None
,
'
eq1
'
,
'
intfc1
'
)
==
"
up
"
mocked_fetchone
.
return_value
=
()
assert
alarmsdb
.
get_last_known_juniper_link_interface_status
(
None
,
'
eq1
'
,
'
intfc1
'
)
==
"
unknown
"
mocked_execute
.
assert_called_with
(
"
SELECT IF(link_admin_status =
'
up
'"
"
AND link_oper_status =
'
up
'
, 1, 0)
"
"
AS up FROM juniper_alarms
"
"
WHERE equipment_name = %s AND link_interface_name = %s
"
"
ORDER BY alarm_id DESC LIMIT 1
"
,
(
"
lo0.eq1
"
,
"
intfc1
"
))
def
test_interface_status
(
mocker
):
mocked_infinera
=
mocker
.
patch
(
'
inventory_provider.alarmsdb.get_last_known_infinera_interface_status
'
)
mocked_infinera
.
return_value
=
"
unknown
"
mocked_coriant
=
mocker
.
patch
(
'
inventory_provider.alarmsdb.get_last_known_coriant_interface_status
'
)
mocked_coriant
.
return_value
=
"
unknown
"
mocked_juniper
=
mocker
.
patch
(
'
inventory_provider.alarmsdb.
'
'
get_last_known_juniper_link_interface_status
'
)
mocked_juniper
.
return_value
=
"
unknown
"
assert
alarmsdb
.
get_last_known_interface_status
(
None
,
''
,
''
)
==
"
unknown
"
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment