Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
envsetup
Manage
Activity
Members
Plan
Redmine
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container Registry
Model registry
Analyze
Contributor 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
mediaserver
envsetup
Commits
c97583b2
Verified
Commit
c97583b2
authored
5 years ago
by
Nicolas KAROLAK
Browse files
Options
Downloads
Patches
Plain Diff
blacked
parent
9f3e0833
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tests/test_dns_records.py
+45
-38
45 additions, 38 deletions
tests/test_dns_records.py
with
45 additions
and
38 deletions
tests/test_dns_records.py
+
45
−
38
View file @
c97583b2
#!/usr/bin/env python3
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
# Copyright 2017, Florent Thiery
# Copyright 2017, Florent Thiery
'''
"""
Criticality: Normal
Criticality: Normal
Checks that DNS records are provided by the customer servers are correctly set
Checks that DNS records are provided by the customer servers are correctly set
'''
"""
import
subprocess
import
subprocess
import
os
import
os
import
sys
import
sys
import
imp
import
imp
GREEN
=
'
\033
[92m
'
GREEN
=
"
\033
[92m
"
RED
=
'
\033
[91m
'
RED
=
"
\033
[91m
"
DEF
=
'
\033
[0m
'
DEF
=
"
\033
[0m
"
def
get_dns_servers
():
def
get_dns_servers
():
servers
=
list
()
servers
=
list
()
with
open
(
'
/etc/resolv.conf
'
,
'
r
'
)
as
f
:
with
open
(
"
/etc/resolv.conf
"
,
"
r
"
)
as
f
:
d
=
f
.
read
().
strip
()
d
=
f
.
read
().
strip
()
for
l
in
d
.
split
(
'
\n
'
):
for
l
in
d
.
split
(
"
\n
"
):
if
l
.
startswith
(
'
nameserver
'
):
if
l
.
startswith
(
"
nameserver
"
):
servers
.
append
(
l
.
split
(
'
nameserver
'
)[
1
])
servers
.
append
(
l
.
split
(
"
nameserver
"
)[
1
])
if
servers
==
[
'
127.0.1.1
'
]:
if
servers
==
[
"
127.0.1.1
"
]:
# NetworkManager
# NetworkManager
status
,
output
=
subprocess
.
getstatusoutput
(
'
nmcli -f all device show | grep IP4.DNS | awk
\'
{ print $2 }
\'
'
)
status
,
output
=
subprocess
.
getstatusoutput
(
servers
.
extend
(
output
.
split
(
'
\n
'
))
"
nmcli -f all device show | grep IP4.DNS | awk
'
{ print $2 }
'"
)
servers
.
extend
(
output
.
split
(
"
\n
"
))
return
servers
return
servers
...
@@ -33,15 +35,17 @@ resolvers = get_dns_servers()
...
@@ -33,15 +35,17 @@ resolvers = get_dns_servers()
def
get_result
(
output
):
def
get_result
(
output
):
for
line
in
output
.
split
(
'
\n
'
):
for
line
in
output
.
split
(
"
\n
"
):
if
'
has address
'
in
line
:
if
"
has address
"
in
line
:
return
line
.
split
(
'
has address
'
)[
1
]
return
line
.
split
(
"
has address
"
)[
1
]
def
check_dns
(
hostname
,
expected_ip
):
def
check_dns
(
hostname
,
expected_ip
):
all_ok
=
True
all_ok
=
True
for
resolver
in
resolvers
:
for
resolver
in
resolvers
:
status
,
output
=
subprocess
.
getstatusoutput
(
'
host
"
%s
"
"
%s
"'
%
(
hostname
,
resolver
))
status
,
output
=
subprocess
.
getstatusoutput
(
'
host
"
%s
"
"
%s
"'
%
(
hostname
,
resolver
)
)
if
status
==
0
:
if
status
==
0
:
color
=
GREEN
color
=
GREEN
address
=
get_result
(
output
)
address
=
get_result
(
output
)
...
@@ -54,57 +58,60 @@ def check_dns(hostname, expected_ip):
...
@@ -54,57 +58,60 @@ def check_dns(hostname, expected_ip):
else
:
else
:
color
=
RED
color
=
RED
all_ok
=
False
all_ok
=
False
address
=
'
FAIL
'
address
=
"
FAIL
"
print
(
'
%sDNS resolution of
"
%s
"
on server
"
%s
"
returned
"
%s
"
.%s
'
%
(
color
,
hostname
,
resolver
,
address
,
DEF
))
print
(
'
%sDNS resolution of
"
%s
"
on server
"
%s
"
returned
"
%s
"
.%s
'
%
(
color
,
hostname
,
resolver
,
address
,
DEF
)
)
return
all_ok
return
all_ok
os
.
chdir
(
os
.
path
.
dirname
(
__file__
))
os
.
chdir
(
os
.
path
.
dirname
(
__file__
))
if
not
os
.
path
.
isfile
(
'
../utils.py
'
):
if
not
os
.
path
.
isfile
(
"
../utils.py
"
):
print
(
'
conf.sh not found
'
)
print
(
"
conf.sh not found
"
)
sys
.
exit
(
1
)
sys
.
exit
(
1
)
es_utils
=
imp
.
load_source
(
'
es_utils
'
,
'
../utils.py
'
)
es_utils
=
imp
.
load_source
(
"
es_utils
"
,
"
../utils.py
"
)
conf
=
es_utils
.
load_conf
()
conf
=
es_utils
.
load_conf
()
all_ok
=
True
all_ok
=
True
conf_resolvers_keys
=
(
conf_resolvers_keys
=
(
"
NETWORK_DNS1
"
,
"
NETWORK_DNS2
"
)
'
NETWORK_DNS1
'
,
'
NETWORK_DNS2
'
,
)
for
conf_resolver_key
in
conf_resolvers_keys
:
for
conf_resolver_key
in
conf_resolvers_keys
:
conf_resolver
=
conf
.
get
(
conf_resolver_key
)
conf_resolver
=
conf
.
get
(
conf_resolver_key
)
if
conf_resolver
and
conf_resolver
!=
'
0
'
and
conf_resolver
not
in
resolvers
:
if
conf_resolver
and
conf_resolver
!=
"
0
"
and
conf_resolver
not
in
resolvers
:
print
(
'
Resolver %s not configured on the system.
'
%
conf_resolver
)
print
(
"
Resolver %s not configured on the system.
"
%
conf_resolver
)
all_ok
=
False
all_ok
=
False
ip
=
conf
.
get
(
'
NETWORK_IP_NAT
'
)
ip
=
conf
.
get
(
"
NETWORK_IP_NAT
"
)
if
not
ip
or
ip
==
'
0
'
:
if
not
ip
or
ip
==
"
0
"
:
ip
=
conf
.
get
(
'
NETWORK_IP
'
)
ip
=
conf
.
get
(
"
NETWORK_IP
"
)
if
not
ip
or
ip
==
'
0
'
:
if
not
ip
or
ip
==
"
0
"
:
if
not
all_ok
:
if
not
all_ok
:
sys
.
exit
(
1
)
sys
.
exit
(
1
)
print
(
'
No IP set in configuration file, unable to test DNS.
'
)
print
(
"
No IP set in configuration file, unable to test DNS.
"
)
sys
.
exit
(
2
)
sys
.
exit
(
2
)
services_info
=
(
services_info
=
(
(
'
MS_SERVER_NAME
'
,
'
mediaserver
'
,
'
python3-mediaserver
'
),
(
"
MS_SERVER_NAME
"
,
"
mediaserver
"
,
"
python3-mediaserver
"
),
(
'
MONITOR_SERVER_NAME
'
,
'
monitor
'
,
'
python3-mediaserver-monitor
'
),
(
"
MONITOR_SERVER_NAME
"
,
"
monitor
"
,
"
python3-mediaserver-monitor
"
),
(
'
CM_SERVER_NAME
'
,
'
mirismanager
'
,
'
skyreach
'
),
(
"
CM_SERVER_NAME
"
,
"
mirismanager
"
,
"
skyreach
"
),
)
)
for
conf_name
,
default_domain
,
package
in
services_info
:
for
conf_name
,
default_domain
,
package
in
services_info
:
domain
=
conf
.
get
(
conf_name
)
domain
=
conf
.
get
(
conf_name
)
if
domain
and
domain
not
in
(
'
localhost
'
,
default_domain
):
if
domain
and
domain
not
in
(
"
localhost
"
,
default_domain
):
# check that the service is installed on this system
# check that the service is installed on this system
status
,
output
=
subprocess
.
getstatusoutput
(
'
dpkg -s %s
'
%
package
)
status
,
output
=
subprocess
.
getstatusoutput
(
"
dpkg -s %s
"
%
package
)
if
status
==
0
:
if
status
==
0
:
print
(
'
Checking IP of
"
%s
"
.
'
%
domain
)
print
(
'
Checking IP of
"
%s
"
.
'
%
domain
)
ok
=
check_dns
(
domain
,
ip
)
ok
=
check_dns
(
domain
,
ip
)
if
not
ok
:
if
not
ok
:
all_ok
=
False
all_ok
=
False
else
:
else
:
print
(
'
Package %s is not installed, IP of
"
%s
"
will not be checked.
'
%
(
package
,
domain
))
print
(
'
Package %s is not installed, IP of
"
%s
"
will not be checked.
'
%
(
package
,
domain
)
)
if
not
all_ok
:
if
not
all_ok
:
sys
.
exit
(
1
)
sys
.
exit
(
1
)
...
...
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