Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
settingsd
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
etersoft
settingsd
Commits
4498bce4
Commit
4498bce4
authored
Nov 15, 2010
by
Devaev Maxim
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Moved raising SubprocessFailure to tools module
parent
d1d97e64
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
29 additions
and
70 deletions
+29
-70
fmod_common_info.py
plugins/functions/fmod_common_info.py
+2
-14
fmod_disks_smart.py
plugins/functions/fmod_disks_smart.py
+3
-15
fmod_machine.py
plugins/functions/fmod_machine.py
+4
-11
fmod_ntp_config.py
plugins/functions/fmod_ntp_config.py
+1
-5
fmod_system_services.py
plugins/functions/fmod_system_services.py
+9
-24
tools.py
settingsd/tools.py
+10
-1
No files found.
plugins/functions/fmod_common_info.py
View file @
4498bce4
...
...
@@ -94,23 +94,11 @@ class CommonInfo(service.FunctionObject) :
def
lsbOption
(
self
,
option
)
:
proc_args
=
"
%
s
%
s"
%
(
config
.
value
(
SERVICE_NAME
,
"lsb_release_prog_path"
),
option
)
(
proc_stdout
,
proc_stderr
,
proc_returncode
)
=
tools
.
execProcess
(
proc_args
)
if
proc_returncode
!=
0
:
raise
tools
.
SubprocessFailure
(
"Error while execute
\"
%
s
\"\n
Stdout:
%
s
\n
Stderr:
%
s
\n
Return code:
%
d"
%
(
proc_args
,
proc_stdout
.
strip
(),
proc_stderr
.
strip
(),
proc_returncode
))
return
":"
.
join
(
proc_stdout
.
split
(
":"
)[
1
:])
.
strip
()
return
":"
.
join
(
tools
.
execProcess
(
proc_args
)[
0
]
.
split
(
":"
)[
1
:])
.
strip
()
def
unameOption
(
self
,
option
)
:
proc_args
=
"
%
s
%
s"
%
(
config
.
value
(
SERVICE_NAME
,
"uname_prog_path"
),
option
)
(
proc_stdout
,
proc_stderr
,
proc_returncode
)
=
tools
.
execProcess
(
proc_args
)
if
proc_returncode
!=
0
:
raise
tools
.
SubprocessFailure
(
"Error while execute
\"
%
s
\"\n
Stdout:
%
s
\n
Stderr:
%
s
\n
Return code:
%
d"
%
(
proc_args
,
proc_stdout
.
strip
(),
proc_stderr
.
strip
(),
proc_returncode
))
return
proc_stdout
.
strip
()
return
tools
.
execProcess
(
proc_args
)[
0
]
.
strip
()
##### Public classes #####
...
...
plugins/functions/fmod_disks_smart.py
View file @
4498bce4
...
...
@@ -37,15 +37,10 @@ class Disk(service.FunctionObject) :
@service.functionMethod
(
SMART_METHODS_NAMESPACE
,
out_signature
=
"a(isiiiissss)"
)
def
attributes
(
self
)
:
proc_args
=
"
%
s -A
%
s"
%
(
config
.
value
(
SERVICE_NAME
,
"smartctl_prog_path"
),
self
.
__device_file_path
)
(
proc_stdout
,
proc_stderr
,
proc_returncode
)
=
tools
.
execProcess
(
proc_args
)
if
proc_returncode
!=
0
:
raise
tools
.
SubprocessFailure
(
"Error while execute
\"
%
s
\"\n
Stdout:
%
s
\n
Stderr:
%
s
\n
Return code:
%
d"
%
(
proc_args
,
proc_stdout
.
strip
(),
proc_stderr
.
strip
(),
proc_returncode
))
attrs_list
=
[]
attrs_found_flag
=
False
for
attrs_list_item
in
proc_stdout
.
split
(
"
\n
"
)
:
for
attrs_list_item
in
tools
.
execProcess
(
proc_args
)[
0
]
.
split
(
"
\n
"
)
:
attrs_list_item
=
attrs_list_item
.
strip
()
if
attrs_found_flag
:
...
...
@@ -69,15 +64,10 @@ class Disk(service.FunctionObject) :
@service.functionMethod
(
SMART_METHODS_NAMESPACE
,
out_signature
=
"b"
)
def
health
(
self
)
:
proc_args
=
"
%
s -H
%
s"
%
(
config
.
value
(
SERVICE_NAME
,
"smartctl_prog_path"
),
self
.
__device_file_path
)
(
proc_stdout
,
proc_stderr
,
proc_returncode
)
=
tools
.
execProcess
(
proc_args
)
if
proc_returncode
!=
0
:
raise
tools
.
SubprocessFailure
(
"Error while execute
\"
%
s
\"\n
Stdout:
%
s
\n
Stderr:
%
s
\n
Return code:
%
d"
%
(
proc_args
,
proc_stdout
.
strip
(),
proc_stderr
.
strip
(),
proc_returncode
))
disk_health_flag
=
False
health_found_flag
=
False
for
health_list_item
in
proc_stdout
.
split
(
"
\n
"
)
:
for
health_list_item
in
tools
.
execProcess
(
proc_args
)[
0
]
.
split
(
"
\n
"
)
:
health_list_item
=
health_list_item
.
strip
()
if
health_found_flag
:
...
...
@@ -150,10 +140,8 @@ class Service(service.Service) :
### Private ###
def
smartAvailable
(
self
,
device_file_path
)
:
# FIXME: Add normal checking for SMART support
proc_args
=
"
%
s
%
s"
%
(
config
.
value
(
SERVICE_NAME
,
"smartctl_prog_path"
),
device_file_path
)
(
proc_stdout
,
proc_stderr
,
proc_returncode
)
=
tools
.
execProcess
(
proc_args
)
return
not
bool
(
proc_returncode
)
return
not
bool
(
tools
.
execProcess
(
proc_args
,
False
)[
2
])
###
...
...
plugins/functions/fmod_machine.py
View file @
4498bce4
...
...
@@ -17,9 +17,6 @@ RUNLEVELS_METHODS_NAMESPACE = "runlevels"
RUNLEVELS
=
"0123456"
SHUTDOWN_OPTION_HALT
=
"-h"
SHUTDOWN_OPTION_REBOOT
=
"-r"
##### Private classes #####
class
Machine
(
service
.
FunctionObject
)
:
...
...
@@ -28,13 +25,11 @@ class Machine(service.FunctionObject) :
@service.functionMethod
(
POWER_METHODS_NAMESPACE
,
out_signature
=
"i"
)
def
shutdown
(
self
)
:
proc_args
=
"
%
s
%
s now"
%
(
config
.
value
(
SERVICE_NAME
,
"shutdown_prog_path"
),
SHUTDOWN_OPTION_HALT
)
return
tools
.
execProcess
(
proc_args
)[
2
]
return
tools
.
execProcess
(
"
%
s -h now"
%
(
config
.
value
(
SERVICE_NAME
,
"shutdown_prog_path"
)))[
2
]
@service.functionMethod
(
POWER_METHODS_NAMESPACE
,
out_signature
=
"i"
)
def
reboot
(
self
)
:
proc_args
=
"
%
s
%
s now"
%
(
config
.
value
(
SERVICE_NAME
,
"shutdown_prog_path"
),
SHUTDOWN_OPTION_REBOOT
)
return
tools
.
execProcess
(
proc_args
)[
2
]
return
tools
.
execProcess
(
"
%
s -r now"
%
(
config
.
value
(
SERVICE_NAME
,
"shutdown_prog_path"
)))[
2
]
@service.functionMethod
(
POWER_METHODS_NAMESPACE
,
out_signature
=
"i"
)
def
suspend
(
self
)
:
...
...
@@ -54,9 +49,8 @@ class Machine(service.FunctionObject) :
@service.functionMethod
(
RUNLEVELS_METHODS_NAMESPACE
,
out_signature
=
"i"
)
def
currentLevel
(
self
)
:
proc_args
=
config
.
value
(
SERVICE_NAME
,
"runlevel_prog_path"
)
(
proc_stdout
,
proc_stderr
,
proc_returncode
)
=
tools
.
execProcess
(
proc_args
)
level_pairs_list
=
proc_stdout
.
strip
()
.
split
(
" "
)
level_pairs_list
=
tools
.
execProcess
(
proc_args
)[
0
]
.
strip
()
.
split
(
" "
)
if
len
(
level_pairs_list
)
!=
2
or
not
level_pairs_list
[
1
]
in
RUNLEVELS
:
raise
tools
.
SubprocessFailure
(
"Error while execute
\"
%
s
\"\n
Stdout:
%
s
\n
Stderr:
%
s
\n
Return code:
%
d"
%
(
proc_args
,
proc_stdout
.
strip
(),
proc_stderr
.
strip
(),
proc_returncode
))
...
...
@@ -66,9 +60,8 @@ class Machine(service.FunctionObject) :
@service.functionMethod
(
RUNLEVELS_METHODS_NAMESPACE
,
out_signature
=
"i"
)
def
previousLevel
(
self
)
:
proc_args
=
config
.
value
(
SERVICE_NAME
,
"runlevel_prog_path"
)
(
proc_stdout
,
proc_stderr
,
proc_returncode
)
=
tools
.
execProcess
(
proc_args
)
level_pairs_list
=
proc_stdout
.
strip
()
.
split
(
" "
)
level_pairs_list
=
tools
.
execProcess
(
proc_args
)[
0
]
.
strip
()
.
split
(
" "
)
if
len
(
level_pairs_list
)
!=
2
or
not
level_pairs_list
[
1
]
in
RUNLEVELS
+
"N"
:
raise
tools
.
SubprocessFailure
(
"Error while execute
\"
%
s
\"\n
Stdout:
%
s
\n
Stderr:
%
s
\n
Return code:
%
d"
%
(
proc_args
,
proc_stdout
.
strip
(),
proc_stderr
.
strip
(),
proc_returncode
))
...
...
plugins/functions/fmod_ntp_config.py
View file @
4498bce4
...
...
@@ -59,11 +59,7 @@ class NtpConfig(service.FunctionObject) :
@service.functionMethod
(
NTP_METHODS_NAMESPACE
)
def
request
(
self
)
:
proc_args
=
"
%
s
%
s"
%
(
config
.
value
(
SERVICE_NAME
,
"ntpdate_prog_path"
),
" "
.
join
(
self
.
servers
()))
(
proc_stdout
,
proc_stderr
,
proc_returncode
)
=
tools
.
execProcess
(
proc_args
)
if
proc_returncode
!=
0
:
raise
tools
.
SubprocessFailure
(
"Error while execute
\"
%
s
\"\n
Stdout:
%
s
\n
Stderr:
%
s
\n
Return code:
%
d"
%
(
proc_args
,
proc_stdout
.
strip
(),
proc_stderr
.
strip
(),
proc_returncode
))
tools
.
execProcess
(
proc_args
)
##### Public classes #####
...
...
plugins/functions/fmod_system_services.py
View file @
4498bce4
...
...
@@ -48,13 +48,9 @@ class SystemService(service.FunctionObject) :
@service.functionMethod
(
SYSTEM_SERVICE_METHODS_NAMESPACE
,
out_signature
=
"s"
)
def
levelsMap
(
self
)
:
proc_args
=
"
%
s --list
%
s"
%
(
config
.
value
(
SERVICE_NAME
,
"chkconfig_prog_path"
),
self
.
systemServiceName
()
)
proc_args
=
"
%
s --list
%
s"
%
(
config
.
value
(
SERVICE_NAME
,
"chkconfig_prog_path"
),
self
.
__system_service_name
)
(
proc_stdout
,
proc_stderr
,
proc_returncode
)
=
tools
.
execProcess
(
proc_args
)
if
proc_returncode
!=
0
:
raise
tools
.
SubprocessFailure
(
"Error while execute
\"
%
s
\"\n
Stdout:
%
s
\n
Stderr:
%
s
\n
Return code:
%
d"
%
(
proc_args
,
proc_stdout
.
strip
(),
proc_stderr
.
strip
(),
proc_returncode
))
service_record_list
=
re
.
split
(
r"\s+"
,
proc_stdout
.
split
(
"
\n
"
)[
0
])
levels_list
=
[
"0"
]
*
(
len
(
service_record_list
)
-
1
)
for
count
in
xrange
(
1
,
len
(
service_record_list
))
:
...
...
@@ -77,41 +73,30 @@ class SystemService(service.FunctionObject) :
@service.functionMethod
(
SYSTEM_SERVICE_METHODS_NAMESPACE
,
out_signature
=
"i"
)
def
start
(
self
)
:
logger
.
verbose
(
"{mod}: Request to start service
\"
%
s
\"
"
%
(
self
.
systemServiceName
()
))
return
tools
.
execProcess
(
"
%
s start"
%
(
os
.
path
.
join
(
config
.
value
(
SERVICE_NAME
,
"initd_dir_path"
),
self
.
systemServiceName
()
)))[
2
]
logger
.
verbose
(
"{mod}: Request to start service
\"
%
s
\"
"
%
(
self
.
__system_service_name
))
return
tools
.
execProcess
(
"
%
s start"
%
(
os
.
path
.
join
(
config
.
value
(
SERVICE_NAME
,
"initd_dir_path"
),
self
.
__system_service_name
)))[
2
]
@service.functionMethod
(
SYSTEM_SERVICE_METHODS_NAMESPACE
,
out_signature
=
"i"
)
def
stop
(
self
)
:
logger
.
verbose
(
"{mod}: Request to stop service
\"
%
s
\"
"
%
(
self
.
systemServiceName
()
))
return
tools
.
execProcess
(
"
%
s stop"
%
(
os
.
path
.
join
(
config
.
value
(
SERVICE_NAME
,
"initd_dir_path"
),
self
.
systemServiceName
()
)))[
2
]
logger
.
verbose
(
"{mod}: Request to stop service
\"
%
s
\"
"
%
(
self
.
__system_service_name
))
return
tools
.
execProcess
(
"
%
s stop"
%
(
os
.
path
.
join
(
config
.
value
(
SERVICE_NAME
,
"initd_dir_path"
),
self
.
__system_service_name
)))[
2
]
@service.functionMethod
(
SYSTEM_SERVICE_METHODS_NAMESPACE
,
out_signature
=
"i"
)
def
status
(
self
)
:
return
tools
.
execProcess
(
"
%
s status"
%
(
os
.
path
.
join
(
config
.
value
(
SERVICE_NAME
,
"initd_dir_path"
),
self
.
systemServiceName
()
)))[
2
]
return
tools
.
execProcess
(
"
%
s status"
%
(
os
.
path
.
join
(
config
.
value
(
SERVICE_NAME
,
"initd_dir_path"
),
self
.
__system_service_name
)))[
2
]
### Private ###
def
systemServiceName
(
self
)
:
return
self
.
__system_service_name
###
def
setLevels
(
self
,
levels
,
enabled_flag
)
:
levels
=
self
.
validLevels
(
levels
)
logger
.
verbose
(
"Request to
%
s service
\"
%
s
\"
on runlevels
\"
%
s
\"
"
%
(
(
"enable"
if
enabled_flag
else
"disable"
),
self
.
systemServiceName
()
,
(
levels
if
levels
!=
None
else
"default"
)
))
self
.
__system_service_name
,
(
levels
if
levels
!=
None
else
"default"
)
))
proc_args
=
"
%
s
%
s
%
s
%
s"
%
(
config
.
value
(
SERVICE_NAME
,
"chkconfig_prog_path"
),
(
"--level
%
s"
%
(
levels
)
if
levels
!=
None
else
""
),
self
.
systemServiceName
(),
(
"on"
if
enabled_flag
else
"off"
)
)
(
proc_stdout
,
proc_stderr
,
proc_returncode
)
=
tools
.
execProcess
(
proc_args
)
if
proc_returncode
!=
0
:
raise
tools
.
SubprocessFailure
(
"Error while execute
\"
%
s
\"\n
Stdout:
%
s
\n
Stderr:
%
s
\n
Return code:
%
d"
%
(
proc_args
,
proc_stdout
.
strip
(),
proc_stderr
.
strip
(),
proc_returncode
))
return
proc_returncode
self
.
__system_service_name
,
(
"on"
if
enabled_flag
else
"off"
)
)
return
tools
.
execProcess
(
proc_args
,
False
)[
2
]
###
...
...
settingsd/tools.py
View file @
4498bce4
...
...
@@ -12,12 +12,21 @@ class SubprocessFailure(Exception) :
##### Public methods #####
def
execProcess
(
proc_args
)
:
def
execProcess
(
proc_args
,
fatal_flag
=
True
)
:
logger
.
debug
(
"{submod}: Executing child process
\"
%
s
\"
"
%
(
proc_args
))
proc
=
subprocess
.
Popen
(
proc_args
,
shell
=
True
,
bufsize
=
1024
,
close_fds
=
True
,
stdin
=
subprocess
.
PIPE
,
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
PIPE
,
env
=
{
"LC_ALL"
:
"C"
})
(
proc_stdout
,
proc_stderr
)
=
proc
.
communicate
()
if
proc
.
returncode
!=
0
:
error_text
=
"Error while execute
\"
%
s
\"\n
Stdout:
%
s
\n
Stderr:
%
s
\n
Return code:
%
d"
%
(
proc_args
,
proc_stdout
.
strip
(),
proc_stderr
.
strip
(),
proc
.
returncode
)
if
fatal_flag
:
raise
SubprocessFailure
(
error_text
)
logger
.
error
(
"{submod}: "
+
error_text
)
logger
.
debug
(
"{submod}: Child process
\"
%
s
\"
finished, return_code=
%
d"
%
(
proc_args
,
proc
.
returncode
))
return
(
proc_stdout
,
proc_stderr
,
proc
.
returncode
)
...
...
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