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
16ecd7b2
Commit
16ecd7b2
authored
6 years ago
by
Stéphane Diemer
Browse files
Options
Downloads
Patches
Plain Diff
Handle pool in ntp test (refs
#25518
).
parent
74d5e972
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_ntp.py
+34
-28
34 additions, 28 deletions
tests/test_ntp.py
with
34 additions
and
28 deletions
tests/test_ntp.py
+
34
−
28
View file @
16ecd7b2
...
@@ -5,52 +5,58 @@
...
@@ -5,52 +5,58 @@
Criticality: Low
Criticality: Low
Checks that the server is synchronized with the configured NTP server.
Checks that the server is synchronized with the configured NTP server.
'''
'''
import
imp
import
os
import
os
import
sys
import
re
import
subprocess
import
subprocess
import
imp
import
sys
YELLOW
=
'
\033
[93m
'
GREEN
=
'
\033
[92m
'
RED
=
'
\033
[91m
'
DEF
=
'
\033
[0m
'
# Check that ntpd is synced
# Check that ntpd is synced
if
os
.
path
.
isfile
(
'
/usr/bin/ntpq
'
):
if
os
.
path
.
isfile
(
'
/usr/bin/ntpq
'
):
cmd
=
'
LANG=C ntpq -pd
'
cmd
=
'
LANG=C ntpq -pd
'
expected
=
'
remote
'
expected
=
'
remote
'
ntpconf
=
'
/etc/ntp.conf
'
ntpconf
=
'
/etc/ntp.conf
'
ntpconf_expected
=
'
server
'
ntpconf_expected
=
r
'
^(?:server|pool)\s(.*)$
'
else
:
else
:
cmd
=
'
LANG=C timedatectl
'
cmd
=
'
LANG=C timedatectl
'
expected
=
'
NTP synchronized
'
expected
=
'
NTP synchronized
'
ntpconf
=
'
/etc/systemd/timesyncd.conf
'
ntpconf
=
'
/etc/systemd/timesyncd.conf
'
ntpconf_expected
=
'
NTP=
'
ntpconf_expected
=
r
'
^
NTP=
(.*)$
'
print
(
'
Running %s
'
%
cmd
)
print
(
'
Running %s
'
%
cmd
)
status
=
subprocess
.
getoutput
(
cmd
)
status
=
subprocess
.
getoutput
(
cmd
)
if
expected
not
in
status
:
if
expected
not
in
status
:
print
(
'
NTP not working: %s
'
%
status
)
print
(
'
%s
NTP not working:
%s
%s
'
%
(
RED
,
status
,
DEF
)
)
sys
.
exit
(
1
)
sys
.
exit
(
1
)
else
:
print
(
'
%sSystem is NTP synchronized.%s
'
%
(
GREEN
,
DEF
))
print
(
'
System is NTP synchronized
'
)
os
.
chdir
(
os
.
path
.
dirname
(
__file__
))
os
.
chdir
(
os
.
path
.
dirname
(
__file__
))
print
(
'
Checking NTP server conforms to conf
'
)
print
(
'
Checking NTP server conforms to conf...
'
)
if
os
.
path
.
isfile
(
'
../utils.py
'
):
if
not
os
.
path
.
isfile
(
'
../utils.py
'
):
es_utils
=
imp
.
load_source
(
'
es_utils
'
,
'
../utils.py
'
)
print
(
'
%sCould not find envsetup conf file or not running from expected location.%s
'
%
(
RED
,
DEF
))
conf
=
es_utils
.
load_conf
()
expected_servers
=
[
s
.
strip
()
for
s
in
(
conf
.
get
(
'
NTP_SERVER
'
)
or
'
ntp.ubuntu.com
'
).
split
(
'
,
'
)]
with
open
(
ntpconf
,
'
r
'
)
as
f
:
d
=
f
.
read
()
servers
=
list
()
for
l
in
d
.
split
(
'
\n
'
):
if
l
.
startswith
(
ntpconf_expected
):
servers
.
append
(
l
[
len
(
ntpconf_expected
):].
strip
())
for
expected_server
in
expected_servers
:
if
expected_server
not
in
servers
:
print
(
'
Expected NTP server %s not found in %s, found %s instead.
'
%
(
expected_server
,
ntpconf
,
servers
))
sys
.
exit
(
1
)
else
:
print
(
'
Expected NTP server %s found in configuration (total servers: %s).
'
%
(
expected_server
,
len
(
servers
)))
print
(
'
NTP OK
'
)
else
:
print
(
'
Could not find envsetup conf file or not running from expected location.
'
)
sys
.
exit
(
1
)
sys
.
exit
(
1
)
es_utils
=
imp
.
load_source
(
'
es_utils
'
,
'
../utils.py
'
)
conf
=
es_utils
.
load_conf
()
expected_servers
=
[
s
.
strip
()
for
s
in
(
conf
.
get
(
'
NTP_SERVER
'
)
or
'
ntp.ubuntu.com
'
).
split
(
'
,
'
)]
with
open
(
ntpconf
,
'
r
'
)
as
f
:
content
=
f
.
read
()
servers
=
list
()
for
l
in
content
.
split
(
'
\n
'
):
m
=
re
.
match
(
ntpconf_expected
,
l
)
if
m
:
servers
.
append
(
m
.
groups
()[
0
].
strip
())
for
expected_server
in
expected_servers
:
if
expected_server
not
in
servers
:
print
(
'
%sWarning: Expected NTP server %s not found in %s, found %s instead.%s
'
%
(
YELLOW
,
expected_server
,
ntpconf
,
'
,
'
.
join
(
servers
),
DEF
))
sys
.
exit
(
3
)
else
:
print
(
'
Expected NTP server %s found in configuration (total servers: %s).
'
%
(
expected_server
,
len
(
servers
)))
print
(
'
%sNTP OK.%s
'
%
(
GREEN
,
DEF
))
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