Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
slapos.core
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
Klaus Wölfel
slapos.core
Commits
06d7e1aa
Commit
06d7e1aa
authored
Oct 12, 2016
by
Alain Takoudjou
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
better check result of firewalld command and raise on any failure
parent
7b59f9a4
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
28 additions
and
11 deletions
+28
-11
slapos/grid/slapgrid.py
slapos/grid/slapgrid.py
+28
-11
No files found.
slapos/grid/slapgrid.py
View file @
06d7e1aa
...
@@ -691,13 +691,21 @@ stderr_logfile_backups=1
...
@@ -691,13 +691,21 @@ stderr_logfile_backups=1
"""
"""
query_cmd
=
rule_command
.
replace
(
'--add-rule'
,
'--query-rule'
)
query_cmd
=
rule_command
.
replace
(
'--add-rule'
,
'--query-rule'
)
process
=
FPopen
(
query_cmd
)
process
=
FPopen
(
query_cmd
)
result
=
process
.
communicate
()[
0
]
result
,
stderr
=
process
.
communicate
()
if
result
.
strip
()
==
'no'
:
if
result
.
strip
()
==
'no'
:
# rule doesn't exist add to firewall
self
.
logger
.
debug
(
rule_command
)
self
.
logger
.
debug
(
rule_command
)
process
=
FPopen
(
rule_command
)
process
=
FPopen
(
rule_command
)
process
.
communicate
()[
0
]
rule_result
,
stderr
=
process
.
communicate
()
if
process
.
returncode
==
1
and
result
.
strip
()
!=
'no'
:
if
process
.
returncode
==
0
:
raise
Exception
(
"Failed to add firewalld rule %s."
%
rule_command
)
if
rule_result
.
strip
()
!=
'success'
:
raise
Exception
(
rule_result
)
else
:
raise
Exception
(
"Failed to add firewalld rule %s
\
n
%s.
\
n
%s"
%
(
rule_command
,
rule_result
,
stderr
))
elif
result
.
strip
()
!=
'no'
and
process
.
returncode
!=
0
:
raise
Exception
(
"Failed to run firewalld rule %s
\
n
%s.
\
n
%s"
%
(
query_cmd
,
result
,
stderr
))
return
result
.
strip
()
==
'no'
return
result
.
strip
()
==
'no'
...
@@ -706,14 +714,22 @@ stderr_logfile_backups=1
...
@@ -706,14 +714,22 @@ stderr_logfile_backups=1
"""
"""
query_cmd
=
rule_command
.
replace
(
'--add-rule'
,
'--query-rule'
)
query_cmd
=
rule_command
.
replace
(
'--add-rule'
,
'--query-rule'
)
process
=
FPopen
(
query_cmd
)
process
=
FPopen
(
query_cmd
)
result
=
process
.
communicate
()[
0
]
result
,
stderr
=
process
.
communicate
()
if
result
.
strip
()
==
'yes'
:
if
result
.
strip
()
==
'yes'
:
# The rule really exist, remove it
remove_command
=
rule_command
.
replace
(
'--add-rule'
,
'--remove-rule'
)
remove_command
=
rule_command
.
replace
(
'--add-rule'
,
'--remove-rule'
)
self
.
logger
.
debug
(
remove_command
)
self
.
logger
.
debug
(
remove_command
)
process
=
FPopen
(
remove_command
)
process
=
FPopen
(
remove_command
)
process
.
communicate
()[
0
]
rule_result
,
stderr
=
process
.
communicate
()
if
process
.
returncode
==
1
and
result
.
strip
()
!=
'no'
:
if
process
.
returncode
==
0
:
raise
Exception
(
"Failed to remove firewalld rule %s."
%
remove_command
)
if
rule_result
.
strip
()
!=
'success'
:
raise
Exception
(
rule_result
)
else
:
raise
Exception
(
"Failed to add firewalld rule %s
\
n
%s.
\
n
%s"
%
(
rule_command
,
rule_result
,
stderr
))
elif
result
.
strip
()
!=
'no'
and
process
.
returncode
!=
0
:
raise
Exception
(
"Failed to run firewalld rule %s
\
n
%s.
\
n
%s"
%
(
query_cmd
,
result
,
stderr
))
return
result
.
strip
()
==
'yes'
return
result
.
strip
()
==
'yes'
...
@@ -757,9 +773,10 @@ stderr_logfile_backups=1
...
@@ -757,9 +773,10 @@ stderr_logfile_backups=1
self
.
logger
.
info
(
"Reloading firewall configuration..."
)
self
.
logger
.
info
(
"Reloading firewall configuration..."
)
reload_cmd
=
self
.
firewall_conf
[
'reload_config_cmd'
]
reload_cmd
=
self
.
firewall_conf
[
'reload_config_cmd'
]
reload_process
=
FPopen
(
reload_cmd
)
reload_process
=
FPopen
(
reload_cmd
)
result
=
reload_process
.
communicate
()[
0
]
stdout
,
stderr
=
reload_process
.
communicate
()
if
reload_process
.
returncode
==
1
:
if
reload_process
.
returncode
!=
0
:
raise
Exception
(
"Failed to load firewalld rules with command %s"
%
reload_cmd
)
raise
Exception
(
"Failed to load firewalld rules with command %s.
\
n
%"
%
(
stderr
,
reload_cmd
))
with
open
(
firewall_rules_path
,
'w'
)
as
frules
:
with
open
(
firewall_rules_path
,
'w'
)
as
frules
:
frules
.
write
(
json
.
dumps
(
json_list
))
frules
.
write
(
json
.
dumps
(
json_list
))
...
...
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