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
f794af3c
Commit
f794af3c
authored
5 years ago
by
Nicolas KAROLAK
Browse files
Options
Downloads
Patches
Plain Diff
get dns servers from dbus
parent
6fb27ad8
No related branches found
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
+25
-7
25 additions, 7 deletions
tests/test_dns_records.py
with
25 additions
and
7 deletions
tests/test_dns_records.py
+
25
−
7
View file @
f794af3c
...
...
@@ -5,6 +5,7 @@ Criticality: Normal
Checks that DNS records are provided by the customer servers are correctly set
"""
import
dbus
from
pathlib
import
Path
import
re
import
subprocess
...
...
@@ -20,21 +21,39 @@ def get_dns_servers() -> set:
servers
=
list
()
ip_pattern
=
re
.
compile
(
r
"
^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$
"
)
if
subprocess
.
getstatusoutput
(
"
command -v nmcli
"
)[
0
]
==
0
:
# network-manager
# dbus method
try
:
bus
=
dbus
.
SystemBus
()
proxy
=
bus
.
get_object
(
bus_name
=
"
org.freedesktop.resolve1
"
,
object_path
=
"
/org/freedesktop/resolve1
"
)
iface
=
dbus
.
Interface
(
object
=
proxy
,
dbus_interface
=
"
org.freedesktop.DBus.Properties
"
)
data
=
iface
.
Get
(
"
org.freedesktop.resolve1.Manager
"
,
"
DNS
"
)
for
dns
in
iface
.
Get
(
"
org.freedesktop.resolve1.Manager
"
,
"
DNS
"
):
delimiter
=
"
:
"
if
len
(
dns
[
2
])
==
16
else
"
.
"
# if IPv6 else IPv4
servers
.
append
(
delimiter
.
join
([
str
(
int
(
o
))
for
o
in
dns
[
2
]]))
except
Exception
as
dbus_err
:
u
.
info
(
"
DBus method failed: {}
"
.
format
(
dbus_err
))
# network-manager method
if
not
len
(
servers
)
and
subprocess
.
getstatusoutput
(
"
command -v nmcli
"
)[
0
]
==
0
:
_
,
output
=
subprocess
.
getstatusoutput
(
"
nmcli -f all device show | grep IP4.DNS | awk
'
{ print $2 }
'"
)
servers
=
[
l
for
l
in
output
.
split
(
"
\n
"
)
if
ip_pattern
.
match
(
l
)]
if
not
len
(
servers
):
#
resolvconf
# resolvconf method
if
not
len
(
servers
)
and
Path
(
"
/etc/
resolv
.
conf
"
).
exists
():
with
open
(
"
/etc/resolv.conf
"
,
"
r
"
)
as
f
:
d
=
f
.
read
().
strip
()
servers
=
[
l
.
split
()[
1
]
for
l
in
d
.
split
(
"
\n
"
)
if
l
.
startswith
(
"
nameserver
"
)]
servers
=
[
l
.
split
()[
1
]
for
l
in
d
.
split
(
"
\n
"
)
if
l
.
startswith
(
"
nameserver
"
)
]
# systemd-resolved method
if
"
127.0.0.53
"
in
servers
:
# systemd-resolved
servers
.
remove
(
"
127.0.0.53
"
)
_
,
output
=
subprocess
.
getstatusoutput
(
"
systemd-resolve --status
"
)
lines
=
[
l
.
strip
()
for
l
in
output
.
split
(
"
\n
"
)]
...
...
@@ -48,7 +67,6 @@ def get_dns_servers() -> set:
else
:
dns_line
=
False
return
set
(
servers
)
...
...
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