Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
slapos
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
Lu Xu
slapos
Commits
dfab94f0
Commit
dfab94f0
authored
Feb 08, 2018
by
Julien Muchembled
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Optimize GenericBaseRecipe.createPythonScript API
parent
d55a5d17
Changes
55
Show whitespace changes
Inline
Side-by-side
Showing
55 changed files
with
418 additions
and
660 deletions
+418
-660
slapos/recipe/accords/__init__.py
slapos/recipe/accords/__init__.py
+2
-2
slapos/recipe/addresiliency/__init__.py
slapos/recipe/addresiliency/__init__.py
+6
-14
slapos/recipe/addresiliency/takeover.py
slapos/recipe/addresiliency/takeover.py
+0
-11
slapos/recipe/apacheperl/__init__.py
slapos/recipe/apacheperl/__init__.py
+3
-3
slapos/recipe/apachephpconfigure/__init__.py
slapos/recipe/apachephpconfigure/__init__.py
+1
-1
slapos/recipe/apachephpconfigure/runner.py
slapos/recipe/apachephpconfigure/runner.py
+9
-15
slapos/recipe/boinc/__init__.py
slapos/recipe/boinc/__init__.py
+16
-20
slapos/recipe/boinc/configure.py
slapos/recipe/boinc/configure.py
+34
-48
slapos/recipe/bonjourgrid/__init__.py
slapos/recipe/bonjourgrid/__init__.py
+8
-8
slapos/recipe/certificate_authority/__init__.py
slapos/recipe/certificate_authority/__init__.py
+10
-19
slapos/recipe/certificate_authority/certificate_authority.py
slapos/recipe/certificate_authority/certificate_authority.py
+2
-4
slapos/recipe/cloud9/__init__.py
slapos/recipe/cloud9/__init__.py
+2
-7
slapos/recipe/condor/__init__.py
slapos/recipe/condor/__init__.py
+8
-11
slapos/recipe/condor/configure.py
slapos/recipe/condor/configure.py
+9
-11
slapos/recipe/davstorage/__init__.py
slapos/recipe/davstorage/__init__.py
+5
-11
slapos/recipe/dropbear.py
slapos/recipe/dropbear.py
+7
-14
slapos/recipe/duplicity.py
slapos/recipe/duplicity.py
+2
-4
slapos/recipe/erp5_test/__init__.py
slapos/recipe/erp5_test/__init__.py
+24
-38
slapos/recipe/erp5_test/test.py
slapos/recipe/erp5_test/test.py
+8
-10
slapos/recipe/erp5testnode/__init__.py
slapos/recipe/erp5testnode/__init__.py
+7
-7
slapos/recipe/generic_cloudooo/__init__.py
slapos/recipe/generic_cloudooo/__init__.py
+1
-1
slapos/recipe/generic_mysql/__init__.py
slapos/recipe/generic_mysql/__init__.py
+13
-4
slapos/recipe/generic_mysql/innobackupex.py
slapos/recipe/generic_mysql/innobackupex.py
+2
-3
slapos/recipe/generic_mysql/mysql.py
slapos/recipe/generic_mysql/mysql.py
+2
-4
slapos/recipe/haproxy/__init__.py
slapos/recipe/haproxy/__init__.py
+4
-4
slapos/recipe/haproxy/haproxy.py
slapos/recipe/haproxy/haproxy.py
+2
-2
slapos/recipe/lamp/__init__.py
slapos/recipe/lamp/__init__.py
+3
-3
slapos/recipe/librecipe/execute.py
slapos/recipe/librecipe/execute.py
+15
-42
slapos/recipe/librecipe/generic.py
slapos/recipe/librecipe/generic.py
+14
-12
slapos/recipe/logrotate.py
slapos/recipe/logrotate.py
+3
-2
slapos/recipe/mioga/instantiate.py
slapos/recipe/mioga/instantiate.py
+9
-9
slapos/recipe/mydumper.py
slapos/recipe/mydumper.py
+5
-9
slapos/recipe/mysql/__init__.py
slapos/recipe/mysql/__init__.py
+11
-11
slapos/recipe/novnc/__init__.py
slapos/recipe/novnc/__init__.py
+6
-7
slapos/recipe/pbs.py
slapos/recipe/pbs.py
+11
-27
slapos/recipe/re6stnet/__init__.py
slapos/recipe/re6stnet/__init__.py
+6
-13
slapos/recipe/re6stnet/re6stnet.py
slapos/recipe/re6stnet/re6stnet.py
+26
-57
slapos/recipe/redis/__init__.py
slapos/recipe/redis/__init__.py
+15
-6
slapos/recipe/redis/promise.py
slapos/recipe/redis/promise.py
+0
-18
slapos/recipe/seleniumrunner/__init__.py
slapos/recipe/seleniumrunner/__init__.py
+6
-14
slapos/recipe/seleniumrunner/testrunner.py
slapos/recipe/seleniumrunner/testrunner.py
+1
-6
slapos/recipe/shell.py
slapos/recipe/shell.py
+9
-21
slapos/recipe/shellinabox.py
slapos/recipe/shellinabox.py
+14
-31
slapos/recipe/signal_wrapper.py
slapos/recipe/signal_wrapper.py
+1
-1
slapos/recipe/simplehttpserver/__init__.py
slapos/recipe/simplehttpserver/__init__.py
+3
-4
slapos/recipe/simplelogger.py
slapos/recipe/simplelogger.py
+6
-9
slapos/recipe/sphinx/__init__.py
slapos/recipe/sphinx/__init__.py
+3
-3
slapos/recipe/squid/__init__.py
slapos/recipe/squid/__init__.py
+6
-10
slapos/recipe/sshkeys_authority.py
slapos/recipe/sshkeys_authority.py
+9
-18
slapos/recipe/stunnel/__init__.py
slapos/recipe/stunnel/__init__.py
+17
-23
slapos/recipe/tidstorage/__init__.py
slapos/recipe/tidstorage/__init__.py
+6
-6
slapos/recipe/wrapper.py
slapos/recipe/wrapper.py
+12
-7
slapos/recipe/zabbixagent/__init__.py
slapos/recipe/zabbixagent/__init__.py
+6
-6
slapos/recipe/zeo/__init__.py
slapos/recipe/zeo/__init__.py
+3
-3
slapos/test/recipe/test_re6stnet.py
slapos/test/recipe/test_re6stnet.py
+5
-6
No files found.
slapos/recipe/accords/__init__.py
View file @
dfab94f0
...
...
@@ -91,8 +91,8 @@ class Recipe(GenericSlapRecipe):
# Generate wrapper
wrapper_location
=
self
.
createPythonScript
(
self
.
options
[
'accords-wrapper'
],
'%s.accords.runAccords'
%
__name__
,
parameter_dict
)
__name__
+
'.accords.runAccords'
,
(
parameter_dict
,)
)
path_list
.
append
(
wrapper_location
)
# Generate helper for debug
...
...
slapos/recipe/addresiliency/__init__.py
View file @
dfab94f0
...
...
@@ -38,26 +38,18 @@ class Recipe(GenericSlapRecipe):
"""
def
_install
(
self
):
path_list
=
[]
slap_connection
=
self
.
buildout
[
'slap-connection'
]
takeover_wrapper
=
self
.
createPythonScript
(
name
=
self
.
options
[
'wrapper-takeover'
],
absolute_function
=
'slapos.recipe.addresiliency.takeover.run
'
,
arguments
=
{
return
self
.
createPythonScript
(
self
.
options
[
'wrapper-takeover'
],
__name__
+
'.takeover.takeover
'
,
kw
=
{
'server_url'
:
slap_connection
[
'server-url'
],
'key_file'
:
slap_connection
.
get
(
'key-file'
),
'cert_file'
:
slap_connection
.
get
(
'cert-file'
),
'computer_id'
:
slap_connection
[
'computer-id'
],
'computer_
gu
id'
:
slap_connection
[
'computer-id'
],
'partition_id'
:
slap_connection
[
'partition-id'
],
'software'
:
slap_connection
[
'software-release-url'
],
'software
_release
'
:
slap_connection
[
'software-release-url'
],
'namebase'
:
self
.
parameter_dict
[
'namebase'
],
'takeover_triggered_file_path'
:
self
.
options
[
'takeover-triggered-file-path'
],
})
path_list
.
append
(
takeover_wrapper
)
return
path_list
slapos/recipe/addresiliency/takeover.py
View file @
dfab94f0
...
...
@@ -78,14 +78,3 @@ def takeover(server_url, key_file, cert_file, computer_guid,
# Create "lock" file preventing equeue to run import scripts
# XXX hardcoded
open
(
takeover_triggered_file_path
,
'w'
).
write
(
''
)
def
run
(
args
):
slapos
.
recipe
.
addresiliency
.
takeover
.
takeover
(
server_url
=
args
.
pop
(
'server_url'
),
key_file
=
args
.
pop
(
'key_file'
),
cert_file
=
args
.
pop
(
'cert_file'
),
computer_guid
=
args
.
pop
(
'computer_id'
),
partition_id
=
args
.
pop
(
'partition_id'
),
software_release
=
args
.
pop
(
'software'
),
namebase
=
args
.
pop
(
'namebase'
),
takeover_triggered_file_path
=
args
.
pop
(
'takeover_triggered_file_path'
))
slapos/recipe/apacheperl/__init__.py
View file @
dfab94f0
...
...
@@ -58,9 +58,9 @@ class Recipe(GenericBaseRecipe):
path_list
.
append
(
httpd_conf
)
wrapper
=
self
.
createPythonScript
(
self
.
options
[
'wrapper'
],
'slapos.recipe.librecipe.execute.
execute
'
,
[
self
.
options
[
'httpd-binary'
],
'-f'
,
self
.
options
[
'httpd-conf'
],
'-DFOREGROUND'
]
'slapos.recipe.librecipe.execute.
generic_exec
'
,
((
self
.
options
[
'httpd-binary'
],
'-f'
,
self
.
options
[
'httpd-conf'
],
'-DFOREGROUND'
),)
)
path_list
.
append
(
wrapper
)
...
...
slapos/recipe/apachephpconfigure/__init__.py
View file @
dfab94f0
...
...
@@ -118,7 +118,7 @@ class Recipe(GenericBaseRecipe):
configureinstall_wrapper_path
=
self
.
createPythonScript
(
self
.
options
[
'configureinstall-location'
],
__name__
+
'.runner.executeRunner'
,
[
argument
,
delete
,
rename
,
chmod
,
data
]
(
argument
,
delete
,
rename
,
chmod
,
data
)
)
#TODO finish to port this and remove upper one
...
...
slapos/recipe/apachephpconfigure/runner.py
View file @
dfab94f0
import
subprocess
def
executeRunner
(
arg
s
):
def
executeRunner
(
arg
uments
,
delete
,
rename
,
chmod
,
data
):
"""Start the instance configure. this may run a python script, move or/and rename
file or directory when dondition is filled. the condition may be when file exist or when an entry
exist into database.
"""
arguments
,
delete
,
rename
,
chmod
,
data
=
args
if
delete
!=
[]:
if
delete
:
print
"Calling lampconfigure with 'delete' arguments"
result
=
subprocess
.
Popen
(
arguments
+
delete
)
result
.
wait
()
if
rename
!=
[]:
subprocess
.
call
(
arguments
+
delete
)
if
rename
:
for
parameters
in
rename
:
print
"Calling lampconfigure with 'rename' arguments"
result
=
subprocess
.
Popen
(
arguments
+
parameters
)
result
.
wait
()
if
chmod
!=
[]:
subprocess
.
call
(
arguments
+
parameters
)
if
chmod
:
print
"Calling lampconfigure with 'chmod' arguments"
result
=
subprocess
.
Popen
(
arguments
+
chmod
)
result
.
wait
()
if
data
!=
[]:
subprocess
.
call
(
arguments
+
chmod
)
if
data
:
print
"Calling lampconfigure with 'run' arguments"
print
arguments
+
data
result
=
subprocess
.
Popen
(
arguments
+
data
)
result
.
wait
()
return
subprocess
.
call
(
arguments
+
data
)
slapos/recipe/boinc/__init__.py
View file @
dfab94f0
...
...
@@ -125,11 +125,15 @@ class Recipe(GenericBaseRecipe):
#Generate wrapper for php
wrapperphp
=
os
.
path
.
join
(
self
.
home
,
'bin/php'
)
php_wrapper
=
self
.
createPythonScript
(
wrapperphp
,
'slapos.recipe.librecipe.execute.
executee
'
,
(
[
self
.
phpbin
,
'-c'
,
self
.
phpini
],
os
.
environ
)
'slapos.recipe.librecipe.execute.
generic_exec
'
,
(
(
self
.
phpbin
,
'-c'
,
self
.
phpini
),
)
)
path_list
.
append
(
php_wrapper
)
mysql_dict
=
dict
(
db
=
self
.
database
,
host
=
self
.
mysqlhost
,
port
=
self
.
mysqlport
,
user
=
self
.
username
,
passwd
=
self
.
password
)
#Generate python script for MySQL database test (starting)
file_status
=
os
.
path
.
join
(
self
.
home
,
'.boinc_config'
)
if
os
.
path
.
exists
(
file_status
):
...
...
@@ -137,11 +141,7 @@ class Recipe(GenericBaseRecipe):
mysql_wrapper
=
self
.
createPythonScript
(
os
.
path
.
join
(
self
.
wrapperdir
,
'start_config'
),
'%s.configure.checkMysql'
%
__name__
,
dict
(
mysql_port
=
self
.
mysqlport
,
mysql_host
=
self
.
mysqlhost
,
mysql_user
=
self
.
username
,
mysql_password
=
self
.
password
,
database
=
self
.
database
,
file_status
=
file_status
,
environment
=
environment
)
(
environment
,
mysql_dict
,
file_status
)
)
# Generate make project wrapper file
...
...
@@ -164,8 +164,7 @@ class Recipe(GenericBaseRecipe):
install_wrapper
=
self
.
createPythonScript
(
os
.
path
.
join
(
self
.
wrapperdir
,
'make_project'
),
'%s.configure.makeProject'
%
__name__
,
dict
(
launch_args
=
launch_args
,
request_file
=
request_make_boinc
,
make_sig
=
file_status
,
env
=
environment
)
(
file_status
,
launch_args
,
request_make_boinc
,
environment
)
)
path_list
.
append
(
install_wrapper
)
...
...
@@ -197,7 +196,7 @@ class Recipe(GenericBaseRecipe):
)
start_service
=
self
.
createPythonScript
(
os
.
path
.
join
(
self
.
wrapperdir
,
'config_project'
),
'%s.configure.services'
%
__name__
,
parameter
'%s.configure.services'
%
__name__
,
(
parameter
,)
)
path_list
.
append
(
start_service
)
...
...
@@ -208,14 +207,12 @@ class Recipe(GenericBaseRecipe):
os
.
unlink
(
start_boinc
)
boinc_parameter
=
dict
(
service_status
=
service_status
,
installroot
=
self
.
installroot
,
drop_install
=
drop_install
,
mysql_port
=
self
.
mysqlport
,
mysql_host
=
self
.
mysqlhost
,
mysql_user
=
self
.
username
,
mysql_password
=
self
.
password
,
database
=
self
.
database
,
environment
=
environment
,
mysql_dict
=
mysql_dict
,
environment
=
environment
,
start_boinc
=
start_boinc
)
start_wrapper
=
self
.
createPythonScript
(
os
.
path
.
join
(
self
.
wrapperdir
,
'start_boinc'
),
'%s.configure.restart_boinc'
%
__name__
,
boinc_parameter
(
boinc_parameter
,)
)
path_list
.
append
(
start_wrapper
)
...
...
@@ -362,7 +359,7 @@ class App(GenericBaseRecipe):
)
deploy_app
=
self
.
createPythonScript
(
os
.
path
.
join
(
wrapperdir
,
'boinc_%s'
%
appname
),
'%s.configure.deployApp'
%
__name__
,
parameter
'%s.configure.deployApp'
%
__name__
,
(
parameter
,)
)
path_list
.
append
(
deploy_app
)
...
...
@@ -404,17 +401,16 @@ class Client(GenericBaseRecipe):
cc_cmd
=
'--read_cc_config'
cmd
=
self
.
createPythonScript
(
cmd_wrapper
,
'%s.configure.runCmd'
%
__name__
,
dict
(
base_cmd
=
base_cmd
,
cc_cmd
=
cc_cmd
,
installdir
=
installdir
,
project_url
=
url
,
key
=
key
)
(
base_cmd
,
cc_cmd
,
installdir
,
url
,
key
)
)
path_list
.
append
(
cmd
)
#Generate BOINC client wrapper
boinc
=
self
.
createPythonScript
(
boinc_wrapper
,
'slapos.recipe.librecipe.execute.
execute
'
,
[
boincbin
,
'--allow_multiple_clients'
,
'--gui_rpc_port'
,
'slapos.recipe.librecipe.execute.
generic_exec
'
,
((
boincbin
,
'--allow_multiple_clients'
,
'--gui_rpc_port'
,
str
(
self
.
options
[
'rpc-port'
]),
'--allow_remote_gui_rpc'
,
'--dir'
,
installdir
,
'--redirectio'
,
'--check_all_logins'
]
'--dir'
,
installdir
,
'--redirectio'
,
'--check_all_logins'
),)
)
path_list
.
append
(
boinc
)
...
...
slapos/recipe/boinc/configure.py
View file @
dfab94f0
...
...
@@ -35,27 +35,21 @@ import filecmp
from
lock_file
import
LockFile
def
checkMysql
(
args
):
sys
.
path
+=
args
[
'environment'
]
[
'PYTHONPATH'
].
split
(
':'
)
def
checkMysql
(
environment
,
connect_kw
,
file_status
=
None
):
sys
.
path
+=
environment
[
'PYTHONPATH'
].
split
(
':'
)
import
MySQLdb
#Sleep until mysql server becomes available
while
True
:
try
:
conn
=
MySQLdb
.
connect
(
host
=
args
[
'mysql_host'
],
user
=
args
[
'mysql_user'
],
port
=
int
(
args
[
'mysql_port'
]),
passwd
=
args
[
'mysql_password'
],
db
=
args
[
'database'
])
conn
.
close
()
print
"Successfully connect to MySQL database... "
if
args
.
has_key
(
'file_status'
):
writeFile
(
args
[
'file_status'
],
"starting"
)
MySQLdb
.
connect
(
**
connect_kw
).
close
()
break
except
Exception
,
ex
:
print
"The result is:
\
n
"
+
ex
.
message
print
"Could not connect to MySQL database... sleep for 2 secondes"
time
.
sleep
(
2
)
print
"Successfully connect to MySQL database... "
if
file_status
:
writeFile
(
file_status
,
"starting"
)
def
checkFile
(
file
,
stime
):
"""Loop until 'file' is created (exist)"""
...
...
@@ -70,18 +64,16 @@ def checkFile(file, stime):
def
restart_boinc
(
args
):
"""Stop (if currently is running state) and start all Boinc service"""
environment
=
args
[
'environment'
]
if
args
[
'drop_install'
]:
checkFile
(
args
[
'service_status'
],
3
)
else
:
checkMysql
(
args
)
checkMysql
(
environment
,
args
[
'mysql_dict'
],
args
.
get
(
'file_status'
)
)
print
"Restart Boinc..."
env
=
os
.
environ
env
[
'PATH'
]
=
args
[
'environment'
][
'PATH'
]
env
[
'PYTHONPATH'
]
=
args
[
'environment'
][
'PYTHONPATH'
]
binstart
=
os
.
path
.
join
(
args
[
'installroot'
],
'bin/start'
)
binstop
=
os
.
path
.
join
(
args
[
'installroot'
],
'bin/stop'
)
os
.
system
(
binstop
)
os
.
system
(
binstart
)
env
=
os
.
environ
.
copy
()
env
.
update
(
environment
)
subprocess
.
call
((
os
.
path
.
join
(
args
[
'installroot'
],
'bin'
,
'stop'
),),
env
=
env
)
subprocess
.
call
((
os
.
path
.
join
(
args
[
'installroot'
],
'bin'
,
'start'
),),
env
=
env
)
writeFile
(
args
[
'start_boinc'
],
"started"
)
print
"Done."
...
...
@@ -122,17 +114,16 @@ def startProcess(launch_args, env=None, cwd=None, stdout=subprocess.PIPE):
return
False
return
True
def
makeProject
(
args
):
def
makeProject
(
make_sig
,
launch_args
,
request_file
,
extra_environ
):
"""Run BOINC make_project script but once only"""
#Wait for DateBase initialization...
checkFile
(
args
[
'make_sig'
]
,
3
)
checkFile
(
make_sig
,
3
)
print
"Cheking if needed to run BOINC make_project..."
if
os
.
path
.
exists
(
args
[
'request_file'
]):
env
=
os
.
environ
env
[
'PATH'
]
=
args
[
'env'
][
'PATH'
]
env
[
'PYTHONPATH'
]
=
args
[
'env'
][
'PYTHONPATH'
]
if
startProcess
(
args
[
'launch_args'
],
env
=
env
):
os
.
unlink
(
args
[
'request_file'
])
if
os
.
path
.
exists
(
request_file
):
env
=
os
.
environ
.
copy
()
env
.
update
(
extra_environ
)
if
startProcess
(
launch_args
,
env
=
env
):
os
.
unlink
(
request_file
)
print
"Finished running BOINC make_projet...Ending"
else
:
print
"No new request for make_project. Exiting..."
...
...
@@ -155,9 +146,8 @@ def services(args):
return
print
"execute script xadd..."
env
=
os
.
environ
env
[
'PATH'
]
=
args
[
'environment'
][
'PATH'
]
env
[
'PYTHONPATH'
]
=
args
[
'environment'
][
'PYTHONPATH'
]
env
=
os
.
environ
.
copy
()
env
.
update
(
args
[
'environment'
])
if
not
startProcess
([
os
.
path
.
join
(
args
[
'installroot'
],
'bin/xadd'
)],
env
):
return
print
"Update files and directories permissions..."
...
...
@@ -212,9 +202,8 @@ def deployManagement(args):
newInstall
=
True
#Sleep until file .start_boinc exist (File indicate that BOINC has been started)
checkFile
(
args
[
'start_boinc'
],
3
)
env
=
os
.
environ
env
[
'PATH'
]
=
args
[
'environment'
][
'PATH'
]
env
[
'PYTHONPATH'
]
=
args
[
'environment'
][
'PYTHONPATH'
]
env
=
os
.
environ
.
copy
()
env
.
update
(
args
[
'environment'
])
print
"setup directories..."
numversion
=
args
[
'version'
].
replace
(
'.'
,
''
)
...
...
@@ -263,7 +252,7 @@ def deployManagement(args):
privateKeyFile
=
os
.
path
.
join
(
args
[
'installroot'
],
'keys/code_sign_private'
)
output
=
open
(
binary
+
'.sig'
,
'w'
)
p_sign
=
subprocess
.
Popen
([
sign
,
binary
,
privateKeyFile
],
stdout
=
output
,
stderr
=
subprocess
.
STDOUT
)
stderr
=
subprocess
.
STDOUT
,
env
=
env
)
result
=
p_sign
.
communicate
()[
0
]
if
p_sign
.
returncode
is
None
or
p_sign
.
returncode
!=
0
:
print
"Failed to execute bin/sign_executable.
\
n
The error was: %s"
%
result
...
...
@@ -290,10 +279,8 @@ def deployManagement(args):
create_wu
(
args
,
env
)
print
"Restart Boinc..."
binstart
=
os
.
path
.
join
(
args
[
'installroot'
],
'bin/start'
)
binstop
=
os
.
path
.
join
(
args
[
'installroot'
],
'bin/stop'
)
os
.
system
(
binstop
)
os
.
system
(
binstart
)
subprocess
.
call
((
os
.
path
.
join
(
args
[
'installroot'
],
'bin'
,
'stop'
),),
env
=
env
)
subprocess
.
call
((
os
.
path
.
join
(
args
[
'installroot'
],
'bin'
,
'start'
),),
env
=
env
)
print
"Boinc Application deployment is done... writing end signal file..."
writeFile
(
token
,
str
(
args
[
'wu_number'
]))
...
...
@@ -315,22 +302,21 @@ def create_wu(args, env):
startProcess
(
launch_args
,
env
,
args
[
'installroot'
])
def
runCmd
(
args
):
def
runCmd
(
base_cmd
,
cc_cmd
,
installdir
,
url
,
key
):
"""Wait for Boinc Client started and run boinc cmd"""
client_config
=
os
.
path
.
join
(
args
[
'installdir'
]
,
'client_state.xml'
)
client_config
=
os
.
path
.
join
(
installdir
,
'client_state.xml'
)
checkFile
(
client_config
,
5
)
time
.
sleep
(
10
)
#Scan client state xml to find client ipv4 adress
host
=
re
.
search
(
"<ip_addr>([
\
w
\
d
\
.:]+)</ip_
a
ddr>"
,
open
(
client_config
,
'r'
).
read
()).
group
(
1
)
args
[
'base_cmd'
][
2
]
=
host
+
':'
+
args
[
'base_cmd'
][
2
]
print
"Run boinccmd with host at %s "
%
args
[
'base_cmd'
][
2
]
project_args
=
args
[
'base_cmd'
]
+
[
'--project_attach'
,
args
[
'project_url'
],
args
[
'key'
]]
startProcess
(
project_args
,
cwd
=
args
[
'installdir'
])
if
args
[
'cc_cmd'
]
!=
''
:
base_cmd
[
2
]
=
host
+
':'
+
base_cmd
[
2
]
print
"Run boinccmd with host at %s "
%
base_cmd
[
2
]
project_args
=
base_cmd
+
[
'--project_attach'
,
url
,
key
]
startProcess
(
project_args
,
cwd
=
installdir
)
if
cc_cmd
:
#Load or reload cc_config file
startProcess
(
args
[
'base_cmd'
]
+
[
args
[
'cc_cmd'
]],
cwd
=
args
[
'installdir'
]
)
startProcess
(
base_cmd
+
[
cc_cmd
],
cwd
=
installdir
)
def
writeFile
(
file
,
content
):
...
...
slapos/recipe/bonjourgrid/__init__.py
View file @
dfab94f0
...
...
@@ -62,8 +62,8 @@ class Recipe(GenericBaseRecipe):
condor_wrapper_list
=
condor_wrapper_list
,
boinc_wrapper_list
=
boinc_wrapper_list
)
bonjourGrid_wrapper
=
self
.
createPythonScript
(
grid_wrapper
,
'%s.configure.launchScript'
%
__name__
,
parameters
__name__
+
'.configure.launchScript'
,
(
parameters
,)
)
path_list
.
append
(
bonjourGrid_wrapper
)
...
...
@@ -74,15 +74,15 @@ class Recipe(GenericBaseRecipe):
log
=
self
.
options
[
'log_file'
].
strip
()
pid_file
=
self
.
options
[
'pid_file'
].
strip
()
wrapper
=
self
.
createPythonScript
(
bg_wrapper
,
'slapos.recipe.librecipe.execute.
execute
'
,
(
[
python
,
bonjourgrid_master
,
'--log_file'
,
log
,
'slapos.recipe.librecipe.execute.
generic_exec
'
,
(
(
python
,
bonjourgrid_master
,
'--log_file'
,
log
,
'--pid_file'
,
pid_file
,
'--master_wrapper'
,
grid_wrapper
,
'--directory'
,
self
.
options
[
'work_dir'
].
strip
(),
'--server'
,
self
.
options
[
'redis-url'
].
strip
(),
'--port'
,
self
.
options
[
'redis-port'
].
strip
(),
'--num_workers'
,
self
.
options
[
'nworkers'
].
strip
(),
]
)
),
)
)
path_list
.
append
(
wrapper
)
...
...
@@ -114,8 +114,8 @@ class Client(GenericBaseRecipe):
log
=
self
.
options
[
'log_file'
].
strip
()
pid_file
=
self
.
options
[
'pid_file'
].
strip
()
wrapper
=
self
.
createPythonScript
(
bg_wrapper
,
'slapos.recipe.librecipe.execute.
execute
'
,
(
[
python
,
bonjourgrid_client
,
'--log_file'
,
log
,
'slapos.recipe.librecipe.execute.
generic_exec
'
,
(
(
python
,
bonjourgrid_client
,
'--log_file'
,
log
,
'--pid_file'
,
pid_file
,
'--boinc_wrapper'
,
boinc_script
,
'--condor_wrapper'
,
condor_script
,
...
...
@@ -123,7 +123,7 @@ class Client(GenericBaseRecipe):
'--install_directory'
,
self
.
options
[
'install_dir'
].
strip
(),
'--server'
,
self
.
options
[
'redis-url'
].
strip
(),
'--port'
,
self
.
options
[
'redis-port'
].
strip
(),
]
)
),
)
)
path_list
.
append
(
wrapper
)
...
...
slapos/recipe/certificate_authority/__init__.py
View file @
dfab94f0
...
...
@@ -40,13 +40,10 @@ class Recipe(GenericBaseRecipe):
self
.
ca_private
=
self
.
options
[
'ca-private'
]
self
.
ca_certs
=
self
.
options
[
'ca-certs'
]
self
.
ca_newcerts
=
self
.
options
[
'ca-newcerts'
]
self
.
ca_crl
=
self
.
options
[
'ca-crl'
]
self
.
ca_key_ext
=
'.key'
self
.
ca_crt_ext
=
'.crt'
def
install
(
self
):
path_list
=
[]
ca_country_code
=
self
.
options
.
get
(
'country-code'
,
'XX'
)
ca_email
=
self
.
options
.
get
(
'email'
,
'xx@example.com'
)
# XXX-BBB: State by mistake has been configured as string "('State',)"
...
...
@@ -77,21 +74,15 @@ class Recipe(GenericBaseRecipe):
self
.
createFile
(
openssl_configuration
,
self
.
substituteTemplate
(
self
.
getTemplateFilename
(
'openssl.cnf.ca.in'
),
config
))
ca_wrapper
=
self
.
createPythonScript
(
return
self
.
createPythonScript
(
self
.
options
[
'wrapper'
],
'%s.certificate_authority.runCertificateAuthority'
%
__name__
,
dict
(
openssl_configuration
=
openssl_configuration
,
openssl_binary
=
self
.
options
[
'openssl-binary'
],
certificate
=
os
.
path
.
join
(
self
.
ca_dir
,
'cacert.pem'
),
key
=
os
.
path
.
join
(
self
.
ca_private
,
'cakey.pem'
),
crl
=
self
.
ca_crl
,
request_dir
=
self
.
request_directory
)
__name__
+
'.certificate_authority.runCertificateAuthority'
,
(
os
.
path
.
join
(
self
.
ca_private
,
'cakey.pem'
),
os
.
path
.
join
(
self
.
ca_dir
,
'cacert.pem'
),
self
.
options
[
'openssl-binary'
],
openssl_configuration
,
self
.
request_directory
)
)
path_list
.
append
(
ca_wrapper
)
return
path_list
class
Request
(
Recipe
):
...
...
@@ -148,9 +139,9 @@ class Request(Recipe):
if
request_needed
:
wrapper
=
self
.
createPythonScript
(
self
.
options
[
'wrapper'
],
'slapos.recipe.librecipe.execute.
execute_wait
'
,
[
[
self
.
options
[
'executable'
]]
,
[
certificate
,
key
]
]
,
'slapos.recipe.librecipe.execute.
generic_exec
'
,
((
self
.
options
[
'executable'
],),)
,
{
'wait_list'
:
(
certificate
,
key
)}
,
)
path_list
.
append
(
wrapper
)
...
...
slapos/recipe/certificate_authority/certificate_authority.py
View file @
dfab94f0
...
...
@@ -102,10 +102,8 @@ class CertificateAuthority:
'certificate_file'
)):
print
'Created certificate %r'
%
parser
.
get
(
'certificate'
,
'name'
)
def
runCertificateAuthority
(
ca_conf
):
ca
=
CertificateAuthority
(
ca_conf
[
'key'
],
ca_conf
[
'certificate'
],
ca_conf
[
'openssl_binary'
],
ca_conf
[
'openssl_configuration'
],
ca_conf
[
'request_dir'
])
def
runCertificateAuthority
(
*
args
):
ca
=
CertificateAuthority
(
*
args
)
while
True
:
ca
.
checkAuthority
()
ca
.
checkRequestDir
()
...
...
slapos/recipe/cloud9/__init__.py
View file @
dfab94f0
...
...
@@ -42,8 +42,6 @@ class Recipe(GenericBaseRecipe):
options
[
'access-url'
]
=
'http://[%s]:%s'
%
(
self
.
ip
,
self
.
port
)
def
install
(
self
):
path_list
=
[]
environment
=
{
'PATH'
:
os
.
path
.
dirname
(
self
.
git
)
+
':'
+
os
.
environ
[
'PATH'
],
}
...
...
@@ -51,10 +49,7 @@ class Recipe(GenericBaseRecipe):
cloud9_args
=
[
self
.
node_executable
,
self
.
cloud9
,
'-l'
,
self
.
ip
,
'-p'
,
self
.
port
,
'-w'
,
self
.
workdir
]
wrapper
=
self
.
createPythonScript
(
self
.
wrapper
,
'slapos.recipe.librecipe.execute.
executee
'
,
return
self
.
createPythonScript
(
self
.
wrapper
,
'slapos.recipe.librecipe.execute.
generic_exec
'
,
(
cloud9_args
,
environment
)
)
path_list
.
append
(
wrapper
)
return
path_list
slapos/recipe/condor/__init__.py
View file @
dfab94f0
...
...
@@ -178,12 +178,11 @@ class Recipe(GenericBaseRecipe):
os
.
chmod
(
wrapper_location
,
0744
)
#generate script for start condor
start_condor
=
os
.
path
.
join
(
self
.
wrapperdir
,
'start_condor'
)
start_bin
=
os
.
path
.
join
(
self
.
wrapper_sbin
,
'condor_master'
)
condor_reconfig
=
os
.
path
.
join
(
self
.
wrapper_sbin
,
'condor_reconfig'
)
wrapper
=
self
.
createPythonScript
(
start_condor
,
'%s.configure.condorStart'
%
__name__
,
dict
(
start_bin
=
start_bin
,
condor_reconfig
=
condor_reconfig
)
wrapper
=
self
.
createPythonScript
(
os
.
path
.
join
(
self
.
wrapperdir
,
'start_condor'
),
__name__
+
'.configure.condorStart'
,
(
os
.
path
.
join
(
self
.
wrapper_sbin
,
'condor_reconfig'
),
os
.
path
.
join
(
self
.
wrapper_sbin
,
'condor_master'
))
)
path_list
.
append
(
wrapper
)
return
path_list
...
...
@@ -276,13 +275,11 @@ class AppSubmit(GenericBaseRecipe):
os
.
unlink
(
destination
)
os
.
symlink
(
app_list
[
appname
][
'files'
][
file
],
destination
)
#generate wrapper for submitting job
condor_submit
=
os
.
path
.
join
(
self
.
options
[
'bin'
].
strip
(),
'condor_submit'
)
parameter
=
dict
(
submit
=
condor_submit
,
sig_install
=
sig_install
,
submit_file
=
'submit'
,
appname
=
appname
,
appdir
=
appdir
)
submit_job
=
self
.
createPythonScript
(
os
.
path
.
join
(
self
.
options
[
'wrapper-dir'
].
strip
(),
appname
),
'%s.configure.submitJob'
%
__name__
,
parameter
__name__
+
'.configure.submitJob'
,
(
os
.
path
.
join
(
self
.
options
[
'bin'
].
strip
(),
'condor_submit'
),
'submit'
,
appdir
,
appname
,
sig_install
)
)
path_list
.
append
(
submit_job
)
return
path_list
\ No newline at end of file
slapos/recipe/condor/configure.py
View file @
dfab94f0
...
...
@@ -29,27 +29,25 @@ import os
import
subprocess
import
time
def
submitJob
(
args
):
def
submitJob
(
submit
,
submit_file
,
appdir
,
appname
,
sig_install
):
"""Run condor_submit (if needed) for job deployment"""
time
.
sleep
(
10
)
print
"Check if needed to submit %s job's"
%
a
rgs
[
'appname'
]
if
not
os
.
path
.
exists
(
args
[
'sig_install'
]
):
print
"Check if needed to submit %s job's"
%
a
ppname
if
not
os
.
path
.
exists
(
sig_install
):
print
"Nothing for install or update...Exited"
return
# '-a', "log = out.log", '-a', "error = error.log",
launch_args
=
[
args
[
'submit'
],
'-verbose'
,
args
[
'submit_file'
]]
launch_args
=
submit
,
'-verbose'
,
submit_file
process
=
subprocess
.
Popen
(
launch_args
,
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
STDOUT
,
cwd
=
a
rgs
[
'appdir'
]
)
stderr
=
subprocess
.
STDOUT
,
cwd
=
a
ppdir
)
result
=
process
.
communicate
()[
0
]
if
process
.
returncode
is
None
or
process
.
returncode
!=
0
:
print
"Failed to execute condor_submit.
\
n
The error was: %s"
%
result
else
:
os
.
unlink
(
args
[
'sig_install'
]
)
os
.
unlink
(
sig_install
)
def
condorStart
(
args
):
def
condorStart
(
condor_reconfig
,
start_bin
):
"""Start Condor if deamons is currently stopped"""
result
=
os
.
system
(
args
[
'condor_reconfig'
])
if
result
!=
0
:
if
subprocess
.
call
(
condor_reconfig
):
#process failled to reconfig condor that mean that condor deamons is not curently started
os
.
system
(
args
[
'start_bin'
])
\ No newline at end of file
subprocess
.
call
(
start_bin
)
slapos/recipe/davstorage/__init__.py
View file @
dfab94f0
...
...
@@ -99,25 +99,19 @@ class Recipe(GenericBaseRecipe):
path_list
.
append
(
config_file
)
wrapper
=
self
.
createPythonScript
(
self
.
options
[
'wrapper'
],
'slapos.recipe.librecipe.execute.
execute
'
,
[
self
.
options
[
'apache-binary'
],
'-f'
,
config_file
,
'-DFOREGROUND'
]
)
'slapos.recipe.librecipe.execute.
generic_exec
'
,
((
self
.
options
[
'apache-binary'
],
'-f'
,
config_file
,
'-DFOREGROUND'
),)
)
path_list
.
append
(
wrapper
)
promise
=
self
.
createPythonScript
(
self
.
options
[
'promise'
],
__name__
+
'.promise'
,
dict
(
host
=
self
.
options
[
'ip'
],
port
=
int
(
self
.
options
[
'port_webdav'
]),
user
=
self
.
options
[
'user'
],
password
=
self
.
options
[
'password'
])
)
(
self
.
options
[
'ip'
],
int
(
self
.
options
[
'port_webdav'
]),
self
.
options
[
'user'
],
self
.
options
[
'password'
]))
path_list
.
append
(
promise
)
return
path_list
def
promise
(
args
):
host
=
args
[
'host'
]
port
=
args
[
'port'
]
user
=
args
[
'user'
]
password
=
args
[
'password'
]
def
promise
(
host
,
port
,
user
,
password
):
connection
=
httplib
.
HTTPSConnection
(
host
,
port
)
auth
=
base64
.
b64encode
(
'%s:%s'
%
(
user
,
password
))
connection
.
request
(
'OPTIONS'
,
'/'
,
...
...
slapos/recipe/dropbear.py
View file @
dfab94f0
...
...
@@ -57,8 +57,6 @@ class KnownHostsFile(dict):
class
Recipe
(
GenericBaseRecipe
):
def
install
(
self
):
path_list
=
[]
dropbear_cmd
=
[
self
.
options
[
'dropbear-binary'
]]
# Don't fork into background
dropbear_cmd
.
append
(
'-F'
)
...
...
@@ -95,19 +93,16 @@ class Recipe(GenericBaseRecipe):
if
'shell'
in
self
.
options
:
env
[
'DROPBEAR_OVERRIDE_SHELL'
]
=
self
.
options
[
'shell'
]
wrapper
=
self
.
createPythonScript
(
return
self
.
createPythonScript
(
self
.
options
[
'wrapper'
],
'slapos.recipe.librecipe.execute.
executee
'
,
(
dropbear_cmd
,
env
,
)
'slapos.recipe.librecipe.execute.
generic_exec
'
,
(
dropbear_cmd
,
env
)
)
path_list
.
append
(
wrapper
)
return
path_list
class
Client
(
GenericBaseRecipe
):
def
install
(
self
):
env
=
dict
()
env
=
{}
if
'home'
in
self
.
options
:
env
[
'HOME'
]
=
self
.
options
[
'home'
]
...
...
@@ -120,14 +115,12 @@ class Client(GenericBaseRecipe):
if
'identity-file'
in
self
.
options
:
dropbear_cmd
.
extend
([
'-i'
,
self
.
options
[
'identity-file'
]])
wrapper
=
self
.
createPythonScript
(
return
self
.
createPythonScript
(
self
.
options
[
'wrapper'
],
'slapos.recipe.librecipe.execute.
executee
'
,
(
dropbear_cmd
,
env
,
)
'slapos.recipe.librecipe.execute.
generic_exec
'
,
(
dropbear_cmd
,
env
)
)
return
[
wrapper
]
class
AddAuthorizedKey
(
GenericBaseRecipe
):
...
...
slapos/recipe/duplicity.py
View file @
dfab94f0
...
...
@@ -46,7 +46,5 @@ class Recipe(GenericBaseRecipe):
cmd
.
extend
(
options
)
cmd
.
extend
([
backup_directory
,
remote_url
])
wrapper
=
self
.
createPythonScript
(
self
.
options
[
'wrapper'
],
'slapos.recipe.librecipe.execute.execute'
,
cmd
)
return
[
wrapper
]
return
self
.
createPythonScript
(
self
.
options
[
'wrapper'
],
'slapos.recipe.librecipe.execute.generic_exec'
,
(
cmd
,))
slapos/recipe/erp5_test/__init__.py
View file @
dfab94f0
...
...
@@ -67,7 +67,7 @@ class Recipe(GenericBaseRecipe):
openssl_binary
=
self
.
options
[
'openssl-binary'
],
test_ca_path
=
self
.
options
[
'certificate-authority-path'
],
)
common_list
=
[
common_list
=
(
'--conversion_server_url='
+
cloudooo_url
,
# BBB: We still have test suites that only accept the following 2 options.
'--conversion_server_hostname=%s'
%
cloudooo_parsed
.
hostname
,
...
...
@@ -76,19 +76,19 @@ class Recipe(GenericBaseRecipe):
'--volatile_memcached_server_port=%s'
%
memcached_parsed
.
port
,
'--persistent_memcached_server_hostname=%s'
%
kumofs_parsed
.
hostname
,
'--persistent_memcached_server_port=%s'
%
kumofs_parsed
.
port
,
]
)
path_list
.
append
(
self
.
createPythonScript
(
self
.
options
[
'run-unit-test'
],
__name__
+
'.test.runUnitTest'
,
[
dict
(
call_list
=
[
self
.
options
[
'run-unit-test-binary'
],
__name__
+
'.test.runUnitTest'
,
((
self
.
options
[
'run-unit-test-binary'
],
'--erp5_sql_connection_string'
,
mysql_connection_string
,
'--extra_sql_connection_string_list'
,
','
.
join
(
mysql_connection_string_list
),
]
+
common_list
,
**
common_dict
)]
))
)
+
common_list
,
common_dict
)
))
path_list
.
append
(
self
.
createPythonScript
(
self
.
options
[
'run-test-suite'
],
__name__
+
'.test.runTestSuite'
,
[
dict
(
call_list
=
[
self
.
options
[
'run-test-suite-binary'
],
__name__
+
'.test.runTestSuite'
,
((
self
.
options
[
'run-test-suite-binary'
],
'--db_list'
,
','
.
join
(
mysql_connection_string_list
),
]
+
common_list
,
**
common_dict
)]
))
)
+
common_list
,
common_dict
)
))
return
path_list
...
...
@@ -98,20 +98,18 @@ class CloudoooRecipe(GenericBaseRecipe):
common_dict
=
dict
(
prepend_path
=
self
.
options
[
'prepend-path'
],
)
common_list
=
[
common_list
=
(
"--paster_path"
,
self
.
options
[
'ooo-paster'
],
self
.
options
[
'configuration-file'
]
]
run_unit_test_path
=
self
.
createPythonScript
(
self
.
options
[
'run-unit-test'
],
__name__
+
'.test.runUnitTest'
,
[
dict
(
call_list
=
[
self
.
options
[
'run-unit-test-binary'
],
]
+
common_list
,
**
common_dict
)])
path_list
.
append
(
run_unit_test_path
)
)
path_list
.
append
(
self
.
createPythonScript
(
self
.
options
[
'run-unit-test'
],
__name__
+
'.test.runUnitTest'
,
((
self
.
options
[
'run-unit-test-binary'
],
)
+
common_list
,
common_dict
)))
path_list
.
append
(
self
.
createPythonScript
(
self
.
options
[
'run-test-suite'
],
__name__
+
'.test.runTestSuite'
,
[
dict
(
call_list
=
[
self
.
options
[
'run-test-suite-binary'
],
],
**
common_dict
)]
))
__name__
+
'.test.runTestSuite'
,
((
self
.
options
[
'run-test-suite-binary'
],
),
common_dict
)
))
return
path_list
...
...
@@ -121,32 +119,20 @@ class EggTestRecipe(GenericBaseRecipe):
off a list of Python eggs.
"""
def
install
(
self
):
path_list
=
[]
test_list
=
self
.
options
[
'test-list'
].
strip
().
replace
(
'
\
n
'
,
','
)
common_dict
=
{}
environment
_dict
=
{}
common
_dict
=
{}
if
self
.
options
.
get
(
'environment'
):
environment_part
=
self
.
buildout
.
get
(
self
.
options
[
'environment'
])
if
environment_part
:
for
key
,
value
in
environment_part
.
iteritems
():
environment_dict
[
key
]
=
value
common_list
=
[
"--source_code_path_list"
,
test_list
]
common_dict
[
'environment'
]
=
dict
(
environment_part
)
argument_dict
=
dict
(
call_list
=
[
self
.
options
[
'run-test-suite-binary'
],]
+
common_list
,
environment
=
environment_dict
,
**
common_dict
)
if
'prepend-path'
in
self
.
options
:
argument
_dict
[
'prepend_path'
]
=
self
.
options
[
'prepend-path'
]
common
_dict
[
'prepend_path'
]
=
self
.
options
[
'prepend-path'
]
r
un_test_suite_script
=
self
.
createPythonScript
(
r
eturn
self
.
createPythonScript
(
self
.
options
[
'run-test-suite'
],
__name__
+
'.test.runTestSuite'
,
[
argument_dict
]
((
self
.
options
[
'run-test-suite-binary'
],
"--source_code_path_list"
,
test_list
),
common_dict
)
)
path_list
.
append
(
run_test_suite_script
)
return
path_list
slapos/recipe/erp5_test/test.py
View file @
dfab94f0
...
...
@@ -26,9 +26,9 @@
##############################################################################
import
os
import
sys
def
runTestSuite
(
args
):
def
runTestSuite
(
args
,
d
):
env
=
os
.
environ
.
copy
()
d
=
args
[
0
]
if
'openssl_binary'
in
d
:
env
[
'OPENSSL_BINARY'
]
=
d
[
'openssl_binary'
]
if
'test_ca_path'
in
d
:
...
...
@@ -47,17 +47,15 @@ def runTestSuite(args):
env
.
update
(
d
[
'environment'
])
# Deal with Shebang size limitation
executable_filepath
=
d
[
'call_list'
][
0
]
file_object
=
open
(
executable_filepath
,
'r'
)
line
=
file_object
.
readline
()
file_object
.
close
()
executable_filepath
=
args
[
0
]
with
open
(
executable_filepath
,
'r'
)
as
f
:
line
=
f
.
readline
()
argument_list
=
[]
if
line
[:
2
]
==
'#!'
:
executable_filepath
=
line
[
2
:].
strip
()
argument_list
.
append
(
executable_filepath
)
argument_list
.
extend
(
d
[
'call_list'
])
argument_list
.
extend
(
sys
.
argv
[
1
:])
argument_list
.
append
(
env
)
os
.
execle
(
executable_filepath
,
*
argument_list
)
argument_list
+=
args
argument_list
+=
sys
.
argv
[
1
:]
os
.
execve
(
executable_filepath
,
argument_list
,
env
)
runUnitTest
=
runTestSuite
slapos/recipe/erp5testnode/__init__.py
View file @
dfab94f0
...
...
@@ -70,15 +70,15 @@ class Recipe(GenericBaseRecipe):
self
.
path_list
.
append
(
self
.
createPythonScript
(
self
.
options
[
'wrapper'
],
'slapos.recipe.librecipe.execute.
executee
'
,
[
# Executable
[
self
.
options
[
'testnode'
],
'-l'
,
self
.
options
[
'log-file'
],
configuration_file
]
,
'slapos.recipe.librecipe.execute.
generic_exec
'
,
(
# Command
(
self
.
options
[
'testnode'
],
'-l'
,
self
.
options
[
'log-file'
],
configuration_file
)
,
# Environment
{
'GIT_SSL_NO_VERIFY'
:
'1'
,
}
]
,
)
,
)
)
self
.
installApache
()
...
...
@@ -107,8 +107,8 @@ class Recipe(GenericBaseRecipe):
)
self
.
path_list
.
append
(
config_file
)
wrapper
=
self
.
createPythonScript
(
self
.
options
[
'httpd-wrapper'
],
'slapos.recipe.librecipe.execute.
execute
'
,
[
self
.
options
[
'apache-binary'
],
'-f'
,
config_file
,
'-DFOREGROUND'
]
)
'slapos.recipe.librecipe.execute.
generic_exec
'
,
((
self
.
options
[
'apache-binary'
],
'-f'
,
config_file
,
'-DFOREGROUND'
),)
)
self
.
path_list
.
append
(
wrapper
)
# create empty html page to not allow listing of /
page
=
open
(
os
.
path
.
join
(
self
.
options
[
'log-directory'
],
"index.html"
),
"w"
)
...
...
slapos/recipe/generic_cloudooo/__init__.py
View file @
dfab94f0
...
...
@@ -118,5 +118,5 @@ class Recipe(GenericBaseRecipe):
path_list
.
append
(
config_file
)
path_list
.
append
(
self
.
createPythonScript
(
self
.
options
[
'wrapper'
],
'slapos.recipe.librecipe.execute.execute_with_signal_translation'
,
[
self
.
options
[
'ooo-paster'
].
strip
(),
'serve'
,
config_file
]
))
((
self
.
options
[
'ooo-paster'
].
strip
(),
'serve'
,
config_file
),)
))
return
path_list
slapos/recipe/generic_mysql/__init__.py
View file @
dfab94f0
...
...
@@ -154,7 +154,7 @@ class Recipe(GenericBaseRecipe):
)]
)
path_list
.
append
(
mysqld
)
environment
=
dict
(
PATH
=
'%s'
%
self
.
options
[
'bin-directory'
])
environment
=
{
'PATH'
:
self
.
options
[
'bin-directory'
]}
# TODO: move to a separate recipe (ack'ed by Cedric)
if
'backup-script'
in
self
.
options
:
# backup configuration
...
...
@@ -165,9 +165,15 @@ class Recipe(GenericBaseRecipe):
'--defaults-file=%s'
%
mysql_conf_file
,
'--socket=%s'
%
socket
.
strip
(),
'--user=root'
,
'--ibbackup=%s'
%
self
.
options
[
'xtrabackup-binary'
]]
innobackupex_incremental
=
self
.
createPythonScript
(
self
.
options
[
'innobackupex-incremental'
],
'slapos.recipe.librecipe.execute.executee'
,
[
innobackupex_argument_list
+
[
'--incremental'
],
environment
])
innobackupex_incremental
=
self
.
createPythonScript
(
self
.
options
[
'innobackupex-incremental'
],
'slapos.recipe.librecipe.execute.generic_exec'
,
(
innobackupex_argument_list
+
[
'--incremental'
],
environment
))
path_list
.
append
(
innobackupex_incremental
)
innobackupex_full
=
self
.
createPythonScript
(
self
.
options
[
'innobackupex-full'
],
'slapos.recipe.librecipe.execute.executee'
,
[
innobackupex_argument_list
,
environment
])
innobackupex_full
=
self
.
createPythonScript
(
self
.
options
[
'innobackupex-full'
],
'slapos.recipe.librecipe.execute.generic_exec'
,
(
innobackupex_argument_list
,
environment
))
path_list
.
append
(
innobackupex_full
)
backup_controller
=
self
.
createPythonScript
(
self
.
options
[
'backup-script'
],
__name__
+
'.innobackupex.controller'
,
[
innobackupex_incremental
,
innobackupex_full
,
full_backup
,
incremental_backup
])
path_list
.
append
(
backup_controller
)
...
...
@@ -215,7 +221,10 @@ class Recipe(GenericBaseRecipe):
'--defaults-file=%s'
%
mysql_conf_file
,
'--socket=%s'
%
socket
.
strip
(),
'--user=root'
,
]
pt_exe
=
self
.
createPythonScript
(
os
.
path
.
join
(
self
.
options
[
'bin-directory'
],
pt_script_name
),
'slapos.recipe.librecipe.execute.executee'
,
[
pt_argument_list
,
environment
])
pt_exe
=
self
.
createPythonScript
(
os
.
path
.
join
(
self
.
options
[
'bin-directory'
],
pt_script_name
),
'slapos.recipe.librecipe.execute.generic_exec'
,
(
pt_argument_list
,
environment
))
path_list
.
append
(
pt_exe
)
return
path_list
...
...
slapos/recipe/generic_mysql/innobackupex.py
View file @
dfab94f0
import
os
import
glob
def
controller
(
args
):
def
controller
(
innobackupex_incremental
,
innobackupex_full
,
full_backup
,
incremental_backup
):
"""Creates full or incremental backup
If no full backup is done, it is created
...
...
@@ -9,8 +10,6 @@ def controller(args):
base is the newest (according to date) full or incremental backup
"""
innobackupex_incremental
,
innobackupex_full
,
full_backup
,
incremental_backup
\
=
args
if
len
(
os
.
listdir
(
full_backup
))
==
0
:
print
'Doing full backup in %r'
%
full_backup
os
.
execv
(
innobackupex_full
,
[
innobackupex_full
,
full_backup
])
...
...
slapos/recipe/generic_mysql/mysql.py
View file @
dfab94f0
...
...
@@ -5,9 +5,8 @@ import sys
import
pytz
def
runMysql
(
args
):
def
runMysql
(
conf
):
sleep
=
60
conf
=
args
[
0
]
mysqld_wrapper_list
=
[
conf
[
'mysqld_binary'
],
'--defaults-file=%s'
%
conf
[
'configuration_file'
]]
# we trust mysql_install that if mysql directory is available mysql was
...
...
@@ -54,8 +53,7 @@ def runMysql(args):
os
.
execl
(
mysqld_wrapper_list
[
0
],
*
mysqld_wrapper_list
)
def
updateMysql
(
args
):
conf
=
args
[
0
]
def
updateMysql
(
conf
):
sleep
=
30
is_succeed
=
False
try
:
...
...
slapos/recipe/haproxy/__init__.py
View file @
dfab94f0
...
...
@@ -122,10 +122,10 @@ class Recipe(GenericBaseRecipe):
)
wrapper_path
=
self
.
createPythonScript
(
self
.
options
[
'wrapper-path'
],
'slapos.recipe.librecipe.execute.
execute
'
,
arguments
=
[
self
.
options
[
'binary-path'
].
strip
(),
'-f'
,
configuration_path
],
)
'slapos.recipe.librecipe.execute.
generic_exec
'
,
((
self
.
options
[
'binary-path'
].
strip
(),
'-f'
,
configuration_path
),)
)
ctl_path
=
self
.
createPythonScript
(
self
.
options
[
'ctl-path'
],
'%s.haproxy.haproxyctl'
%
__name__
,
{
'socket_path'
:
self
.
options
[
'socket-path'
]}
)
__name__
+
'.haproxy.haproxyctl'
,
(
self
.
options
[
'socket-path'
],)
)
return
[
configuration_path
,
wrapper_path
,
ctl_path
]
slapos/recipe/haproxy/haproxy.py
View file @
dfab94f0
...
...
@@ -4,7 +4,7 @@ try:
except
ImportError
:
pass
def
haproxyctl
(
conf
):
def
haproxyctl
(
socket_path
):
while
True
:
try
:
l
=
raw_input
(
'> '
)
...
...
@@ -14,7 +14,7 @@ def haproxyctl(conf):
if
l
==
'quit'
:
break
s
=
socket
.
socket
(
socket
.
AF_UNIX
,
socket
.
SOCK_STREAM
)
s
.
connect
(
conf
[
'socket_path'
]
)
s
.
connect
(
socket_path
)
s
.
send
(
'%s
\
n
'
%
l
)
while
True
:
r
=
s
.
recv
(
1024
)
...
...
slapos/recipe/lamp/__init__.py
View file @
dfab94f0
...
...
@@ -298,9 +298,9 @@ class Request(BaseRecipe):
'local_host'
:
local_host
,
'local_port'
:
local_port
,
}))
wrapper
=
zc
.
buildout
.
easy_install
.
scripts
([(
'stunnel'
,
'slapos.recipe.librecipe.execute'
,
'
execute
'
)],
self
.
ws
,
sys
.
executable
,
self
.
wrapper_directory
,
arguments
=
[
self
.
options
[
'stunnel_binary'
].
strip
(),
stunnel_conf_path
]
'slapos.recipe.librecipe.execute'
,
'
generic_exec
'
)],
self
.
ws
,
sys
.
executable
,
self
.
wrapper_directory
,
arguments
=
'%r, %r'
%
(
self
.
options
[
'stunnel_binary'
].
strip
(),
stunnel_conf_path
)
)[
0
]
self
.
path_list
.
append
(
wrapper
)
return
(
local_host
,
local_port
,)
slapos/recipe/librecipe/execute.py
View file @
dfab94f0
...
...
@@ -2,7 +2,6 @@ import sys
import
os
import
signal
import
subprocess
import
time
from
collections
import
defaultdict
from
inotify_simple
import
INotify
,
flags
...
...
@@ -29,65 +28,39 @@ def _wait_files_creation(file_list):
if
event
.
name
in
directory
:
directory
[
event
.
name
]
=
event
.
mask
&
(
flags
.
CREATE
|
flags
.
MOVED_TO
)
def
execute
(
args
):
"""Portable execution with process replacement"""
# XXX: Kept for backward compatibility
generic_exec
([
args
,
None
,
None
])
def
generic_exec
(
args
,
extra_environ
=
None
,
wait_list
=
None
):
args
+=
sys
.
argv
[
1
:]
def
execute_wait
(
args
):
"""Execution but after all files in args[1] exists"""
# XXX: Kept for backward compatibility
generic_exec
([
args
[
0
],
args
[
1
],
None
])
if
wait_list
:
_wait_files_creation
(
wait_list
)
if
extra_environ
:
env
=
os
.
environ
.
copy
()
env
.
update
(
extra_environ
)
os
.
execve
(
args
[
0
],
args
,
env
)
else
:
os
.
execv
(
args
[
0
],
args
)
child_pg
=
None
def
executee
(
args
):
"""Portable execution with process replacement and environment manipulation"""
# XXX: Kept for backward compatibility
generic_exec
([
args
[
0
],
None
,
args
[
1
]])
def
executee_wait
(
args
):
"""Portable execution with process replacement and environment manipulation"""
# XXX: Kept for backward compatibility
generic_exec
(
args
)
def
generic_exec
(
args
):
exec_list
=
list
(
args
[
0
])
file_list
=
args
[
1
]
environment_overriding
=
args
[
2
]
exec_env
=
os
.
environ
.
copy
()
if
environment_overriding
is
not
None
:
exec_env
.
update
(
environment_overriding
)
if
file_list
is
not
None
:
_wait_files_creation
(
file_list
)
os
.
execve
(
exec_list
[
0
],
exec_list
+
sys
.
argv
[
1
:],
exec_env
)
def
sig_handler
(
sig
,
frame
):
print
'Received signal %r, killing children and exiting'
%
sig
if
child_pg
is
not
None
:
os
.
killpg
(
child_pg
,
signal
.
SIGHUP
)
os
.
killpg
(
child_pg
,
signal
.
SIGTERM
)
sys
.
exit
(
0
)
signal
.
signal
(
signal
.
SIGINT
,
sig_handler
)
signal
.
signal
(
signal
.
SIGQUIT
,
sig_handler
)
signal
.
signal
(
signal
.
SIGTERM
,
sig_handler
)
sys
.
exit
()
def
execute_with_signal_translation
(
args
):
"""Run process as children and translate from SIGTERM to another signal"""
global
child_pg
signal
.
signal
(
signal
.
SIGINT
,
sig_handler
)
signal
.
signal
(
signal
.
SIGQUIT
,
sig_handler
)
signal
.
signal
(
signal
.
SIGTERM
,
sig_handler
)
child
=
subprocess
.
Popen
(
args
,
close_fds
=
True
,
preexec_fn
=
os
.
setsid
)
child_pg
=
child
.
pid
try
:
print
'Process %r started'
%
args
while
True
:
time
.
sleep
(
10
)
signal
.
pause
()
finally
:
os
.
killpg
(
child_pg
,
signal
.
SIGHUP
)
os
.
killpg
(
child_pg
,
signal
.
SIGTERM
)
slapos/recipe/librecipe/generic.py
View file @
dfab94f0
...
...
@@ -116,26 +116,28 @@ class GenericBaseRecipe(object):
with
io
.
open
(
filepath
,
'w+'
,
encoding
=
encoding
)
as
f
:
f
.
write
(
u'
\
n
'
.
join
(
lines
))
def
createPythonScript
(
self
,
name
,
absolute_function
,
arg
uments
=
''
):
def
createPythonScript
(
self
,
name
,
absolute_function
,
arg
s
=
(),
kw
=
{}
):
"""Create a python script using zc.buildout.easy_install.scripts
* function should look like 'module.function', or only 'function'
if it is a builtin function."""
absolute_function
=
tuple
(
absolute_function
.
rsplit
(
'.'
,
1
))
if
len
(
absolute_function
)
==
1
:
absolute_function
=
(
'__builtin__'
,)
+
absolute_function
if
len
(
absolute_function
)
!=
2
:
raise
ValueError
(
"A non valid function was given"
)
module
,
function
=
absolute_function
function
=
absolute_function
.
rsplit
(
'.'
,
1
)
if
len
(
function
)
==
1
:
module
=
'__builtin__'
function
,
=
function
else
:
module
,
function
=
function
path
,
filename
=
os
.
path
.
split
(
os
.
path
.
abspath
(
name
))
script
=
zc
.
buildout
.
easy_install
.
scripts
(
assert
not
isinstance
(
args
,
(
basestring
,
dict
)),
args
args
=
map
(
repr
,
args
)
args
+=
map
(
'%s=%r'
.
__mod__
,
kw
.
iteritems
())
return
zc
.
buildout
.
easy_install
.
scripts
(
[(
filename
,
module
,
function
)],
self
.
_ws
,
sys
.
executable
,
path
,
arguments
=
arguments
)[
0
]
return
script
path
,
arguments
=
', '
.
join
(
args
))[
0
]
def
createWrapper
(
self
,
name
,
command
,
parameters
,
comments
=
[]
,
def
createWrapper
(
self
,
name
,
command
,
parameters
,
comments
=
()
,
parameters_extra
=
False
,
environment
=
None
,
pidfile
=
None
,
reserve_cpu
=
False
):
...
...
slapos/recipe/logrotate.py
View file @
dfab94f0
...
...
@@ -48,8 +48,9 @@ class Recipe(GenericBaseRecipe):
logrotate
=
self
.
createPythonScript
(
self
.
options
[
'wrapper'
],
'slapos.recipe.librecipe.execute.execute'
,
[
self
.
options
[
'logrotate-binary'
],
'-s'
,
state_file
,
logrotate_conf_file
,
]
'slapos.recipe.librecipe.execute.generic_exec'
,
((
self
.
options
[
'logrotate-binary'
],
'-s'
,
state_file
,
logrotate_conf_file
),)
)
return
[
logrotate
,
logrotate_conf_file
]
...
...
slapos/recipe/mioga/instantiate.py
View file @
dfab94f0
...
...
@@ -205,9 +205,9 @@ Include conf/extra/httpd-autoindex.conf
httpd_wrapper
=
self
.
createPythonScript
(
os
.
path
.
join
(
services_dir
,
'httpd_wrapper'
),
'slapos.recipe.librecipe.execute.
execute
'
,
[
self
.
options
[
'httpd_binary'
],
'-f'
,
self
.
options
[
'httpd_conf
'
],
'-DFOREGROUND'
]
'slapos.recipe.librecipe.execute.
generic_exec
'
,
((
self
.
options
[
'httpd_binary
'
],
'-f'
,
self
.
options
[
'httpd_conf'
],
'-DFOREGROUND'
),)
)
path_list
.
append
(
httpd_wrapper
)
...
...
@@ -222,17 +222,17 @@ Include conf/extra/httpd-autoindex.conf
mioga_conf_path
=
os
.
path
.
join
(
mioga_base
,
'conf'
,
'Mioga.conf'
)
notifier_wrapper
=
self
.
createPythonScript
(
os
.
path
.
join
(
services_dir
,
'notifier'
),
'slapos.recipe.librecipe.execute.
execute
'
,
[
os
.
path
.
join
(
site_perl_bin
,
'notifier.pl'
),
mioga_conf_path
]
'slapos.recipe.librecipe.execute.
generic_exec
'
,
((
os
.
path
.
join
(
site_perl_bin
,
'notifier.pl'
),
mioga_conf_path
),)
)
path_list
.
append
(
notifier_wrapper
)
searchengine_wrapper
=
self
.
createPythonScript
(
os
.
path
.
join
(
services_dir
,
'searchengine'
),
'slapos.recipe.librecipe.execute.
execute
'
,
[
os
.
path
.
join
(
site_perl_bin
,
'searchengine.pl'
),
mioga_conf_path
]
'slapos.recipe.librecipe.execute.
generic_exec
'
,
((
os
.
path
.
join
(
site_perl_bin
,
'searchengine.pl'
),
mioga_conf_path
),)
)
path_list
.
append
(
searchengine_wrapper
)
...
...
slapos/recipe/mydumper.py
View file @
dfab94f0
...
...
@@ -24,7 +24,7 @@
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
##############################################################################
import
subproces
s
import
o
s
from
slapos.recipe.librecipe
import
GenericBaseRecipe
...
...
@@ -58,14 +58,14 @@ def do_export(args):
cmd
.
extend
([
'-o'
,
args
[
'directory'
]])
subprocess
.
check_call
(
cmd
)
os
.
execv
(
cmd
[
0
],
cmd
)
def
do_import
(
args
):
cmd
=
_mydumper_base_cmd
(
**
args
)
cmd
.
append
(
'--overwrite-tables'
)
cmd
.
extend
([
'-d'
,
args
[
'directory'
]])
subprocess
.
check_call
(
cmd
)
os
.
execv
(
cmd
[
0
],
cmd
)
class
Recipe
(
GenericBaseRecipe
):
...
...
@@ -95,9 +95,5 @@ class Recipe(GenericBaseRecipe):
config
[
'compression'
]
=
self
.
optionIsTrue
(
'compression'
,
default
=
False
)
config
[
'rows'
]
=
self
.
options
.
get
(
'rows'
)
wrapper
=
self
.
createPythonScript
(
name
=
self
.
options
[
'wrapper'
],
absolute_function
=
'%s.%s'
%
(
__name__
,
function
.
func_name
),
arguments
=
config
)
return
[
wrapper
]
return
self
.
createPythonScript
(
self
.
options
[
'wrapper'
],
'%s.%s'
%
(
function
.
__module__
,
function
.
__name__
),
(
config
,))
slapos/recipe/mysql/__init__.py
View file @
dfab94f0
...
...
@@ -55,9 +55,9 @@ class Recipe(GenericBaseRecipe):
socket
=
self
.
options
[
'socket'
],
post_rotate
=
self
.
createPythonScript
(
self
.
options
[
'logrotate-post'
],
'slapos.recipe.librecipe.execute.
execute
'
,
[
mysql_binary
,
'--no-defaults'
,
'-B'
,
'-u'
,
'root'
,
'--socket=%s'
%
socket
,
'-e
'
,
'FLUSH LOGS'
]
'slapos.recipe.librecipe.execute.
generic_exec
'
,
((
mysql_binary
,
'--no-defaults'
,
'-B'
,
'-u'
,
'root
'
,
'--socket=%s'
%
socket
,
'-e'
,
'FLUSH LOGS'
),)
)
path_list
.
append
(
post_rotate
)
...
...
@@ -85,12 +85,12 @@ class Recipe(GenericBaseRecipe):
mysql_update
=
self
.
createPythonScript
(
self
.
options
[
'update-wrapper'
],
'%s.mysql.updateMysql'
%
__name__
,
dict
(
(
dict
(
mysql_script
=
mysql_script
,
mysql_binary
=
mysql_binary
,
mysql_upgrade_binary
=
mysql_upgrade_binary
,
socket
=
socket
,
)
),
)
)
path_list
.
append
(
mysql_update
)
...
...
@@ -98,7 +98,7 @@ class Recipe(GenericBaseRecipe):
mysqld
=
self
.
createPythonScript
(
self
.
options
[
'wrapper'
],
'%s.mysql.runMysql'
%
__name__
,
dict
(
(
dict
(
mysql_install_binary
=
self
.
options
[
'mysql-install-binary'
],
mysqld_binary
=
mysqld_binary
,
data_directory
=
mysql_conf
[
'data_directory'
],
...
...
@@ -106,7 +106,7 @@ class Recipe(GenericBaseRecipe):
socket
=
socket
,
configuration_file
=
mysql_conf_file
,
cwd
=
self
.
options
[
'mysql-base-directory'
],
)
)
,)
)
path_list
.
append
(
mysqld
)
...
...
@@ -115,12 +115,12 @@ class Recipe(GenericBaseRecipe):
backup_script
=
self
.
createPythonScript
(
self
.
options
[
'backup-script'
],
'%s.do_backup'
%
__name__
,
dict
(
(
dict
(
mydumper_binary
=
self
.
options
[
'mydumper-binary'
],
database
=
mysql_conf
[
'mysql_database'
],
socket
=
mysql_conf
[
'socket'
],
backup_directory
=
self
.
options
[
'backup-directory'
]
),
),)
)
path_list
.
append
(
backup_script
)
...
...
@@ -129,7 +129,7 @@ class Recipe(GenericBaseRecipe):
recovering_script
=
self
.
createPythonScript
(
self
.
options
[
'recovering-wrapper'
],
'%s.import_dump'
%
__name__
,
{
(
{
'lock_file'
:
os
.
path
.
join
(
self
.
work_directory
,
'import_done'
),
'database'
:
mysql_conf
[
'mysql_database'
],
...
...
@@ -140,7 +140,7 @@ class Recipe(GenericBaseRecipe):
'local_directory'
:
self
.
mysql_backup_directory
,
'dump_name'
:
dump_filename
,
'zcat_binary'
:
self
.
options
[
'zcat-binary'
],
}
}
,)
)
path_list
.
append
(
recovering_script
)
...
...
slapos/recipe/novnc/__init__.py
View file @
dfab94f0
...
...
@@ -35,10 +35,10 @@ class Recipe(GenericBaseRecipe):
"""
def
install
(
self
):
r
unner_path
=
self
.
createPythonScript
(
r
eturn
self
.
createPythonScript
(
self
.
options
[
'path'
],
'slapos.recipe.librecipe.execute.
execute_wait
'
,
[[
'slapos.recipe.librecipe.execute.
generic_exec
'
,
((
self
.
options
[
'websockify-path'
],
'--web'
,
self
.
options
[
'novnc-location'
],
...
...
@@ -47,8 +47,7 @@ class Recipe(GenericBaseRecipe):
'--ssl-only'
,
'%s:%s'
%
(
self
.
options
[
'ip'
],
self
.
options
[
'port'
]),
'%s:%s'
%
(
self
.
options
[
'vnc-ip'
],
self
.
options
[
'vnc-port'
]),
],
[
self
.
options
[
'ssl-key-path'
],
self
.
options
[
'ssl-cert-path'
]]],
),),
{
'wait_list'
:
(
self
.
options
[
'ssl-key-path'
],
self
.
options
[
'ssl-cert-path'
])},
)
return
[
runner_path
]
slapos/recipe/pbs.py
View file @
dfab94f0
...
...
@@ -39,30 +39,18 @@ from slapos.recipe.notifier import Callback
from
slapos.recipe.librecipe
import
shlex
def
promise
(
args
):
def
promise
(
ssh_client
,
user
,
host
,
port
):
# Redirect output to /dev/null
with
open
(
"/dev/null"
)
as
_dev_null
:
with
open
(
os
.
devnull
)
as
_dev_null
:
ssh
=
subprocess
.
Popen
(
[
args
[
'ssh_client'
],
'%(user)s@%(host)s'
%
args
,
'-p'
,
'%(port)s'
%
args
],
stdin
=
subprocess
.
PIPE
,
stdout
=
_dev_null
,
stderr
=
None
)
# Rdiff Backup protocol quit command
quitcommand
=
'q'
+
chr
(
255
)
+
chr
(
0
)
*
7
ssh
.
stdin
.
write
(
quitcommand
)
ssh
.
stdin
.
flush
()
ssh
.
stdin
.
close
()
ssh
.
wait
()
if
ssh
.
poll
()
is
None
:
return
1
if
ssh
.
returncode
!=
0
:
(
ssh_client
,
'%s@%s'
%
(
user
,
host
),
'-p'
,
str
(
port
)),
stdin
=
subprocess
.
PIPE
,
stdout
=
_dev_null
)
ssh
.
communicate
(
'q'
+
chr
(
255
)
+
chr
(
0
)
*
7
)
if
ssh
.
returncode
:
sys
.
stderr
.
write
(
"SSH Connection failed
\
n
"
)
return
ssh
.
returncode
class
Recipe
(
GenericSlapRecipe
,
Notify
,
Callback
):
def
_options
(
self
,
options
):
options
[
'rdiff-backup-data-folder'
]
=
""
...
...
@@ -244,15 +232,11 @@ class Recipe(GenericSlapRecipe, Notify, Callback):
print
'Processing PBS slave %s with type %s'
%
(
slave_id
,
slave_type
)
promise_path
=
os
.
path
.
join
(
self
.
options
[
'promises-directory'
],
"ssh-to-%s"
%
slave_id
)
promise_dict
=
dict
(
ssh_client
=
self
.
options
[
'sshclient-binary'
],
user
=
parsed_url
.
username
,
host
=
parsed_url
.
hostname
,
port
=
parsed_url
.
port
)
promise
=
self
.
createPythonScript
(
promise_path
,
path_list
.
append
(
self
.
createPythonScript
(
os
.
path
.
join
(
self
.
options
[
'promises-directory'
],
"ssh-to-%s"
%
slave_id
),
__name__
+
'.promise'
,
promise_dict
)
path_list
.
append
(
promise
)
(
self
.
options
[
'sshclient-binary'
],
parsed_url
.
username
,
parsed_url
.
hostname
,
parsed_url
.
port
))
)
# Create known_hosts file by default.
# In some case, we don't want to create it (case where we share IP mong partitions)
...
...
slapos/recipe/re6stnet/__init__.py
View file @
dfab94f0
...
...
@@ -162,7 +162,6 @@ class Recipe(GenericBaseRecipe):
return
hash_string
def
install
(
self
):
path_list
=
[]
token_save_path
=
os
.
path
.
join
(
self
.
options
[
'conf-dir'
],
'token.json'
)
token_list_path
=
self
.
options
[
'token-dir'
]
...
...
@@ -190,20 +189,14 @@ class Recipe(GenericBaseRecipe):
self
.
createFile
(
token_save_path
,
json
.
dumps
(
token_dict
))
service_dict
=
dict
(
token_base_path
=
token_list_path
,
token_json
=
token_save_path
,
partition_id
=
self
.
computer_partition_id
,
computer_id
=
self
.
computer_id
,
registry_url
=
registry_url
,
server_url
=
self
.
server_url
,
computer_dict
=
dict
(
partition_id
=
self
.
computer_partition_id
,
computer_guid
=
self
.
computer_id
,
master_url
=
self
.
server_url
,
cert_file
=
self
.
cert_file
,
key_file
=
self
.
key_file
)
re
quest_add
=
self
.
createPythonScript
(
re
turn
self
.
createPythonScript
(
self
.
options
[
'manager-wrapper'
].
strip
(),
'%s.re6stnet.manage'
%
__name__
,
service_dict
__name__
+
'.re6stnet.manage'
,
(
registry_url
,
token_list_path
,
token_save_path
,
computer_dict
)
)
path_list
.
append
(
request_add
)
return
path_list
slapos/recipe/re6stnet/re6stnet.py
View file @
dfab94f0
...
...
@@ -17,9 +17,7 @@ logging.trace = logging.debug
def
loadJsonFile
(
path
):
if
os
.
path
.
exists
(
path
):
with
open
(
path
,
'r'
)
as
f
:
content
=
f
.
read
()
return
json
.
loads
(
content
)
else
:
return
json
.
load
(
f
)
return
{}
def
writeFile
(
path
,
data
):
...
...
@@ -39,29 +37,25 @@ def updateFile(file_path, value):
return
True
return
False
def
getComputerPartition
(
server_url
,
key_file
,
cert_file
,
computer_guid
,
partition_id
):
def
getComputerPartition
(
master_url
,
key_file
,
cert_file
,
computer_guid
,
partition_id
):
slap
=
slapos
.
slap
.
slap
()
# Redeploy instance to update published information
slap
.
initializeConnection
(
server_url
,
key_file
,
cert_file
)
slap
.
initializeConnection
(
master_url
,
key_file
,
cert_file
)
return
slap
.
registerComputerPartition
(
computer_guid
,
partition_id
)
return
slap
.
registerComputerPartition
(
computer_guid
=
computer_guid
,
partition_id
=
partition_id
)
def
requestAddToken
(
client
,
base_token_path
):
def
requestAddToken
(
client
,
token_base_path
):
time
.
sleep
(
3
)
path_list
=
[
x
for
x
in
os
.
listdir
(
base_token
_path
)
if
x
.
endswith
(
'.add'
)]
path_list
=
[
x
for
x
in
os
.
listdir
(
token_base
_path
)
if
x
.
endswith
(
'.add'
)]
log
.
info
(
"Searching tokens to add at %s and found %s."
%
(
base_token
_path
,
path_list
))
log
.
info
(
"Searching tokens to add at %s and found %s."
%
(
token_base
_path
,
path_list
))
if
not
path_list
:
log
.
info
(
"No new token to add. Exiting..."
)
return
for
reference_key
in
path_list
:
request_file
=
os
.
path
.
join
(
base_token
_path
,
reference_key
)
request_file
=
os
.
path
.
join
(
token_base
_path
,
reference_key
)
token
=
readFile
(
request_file
)
log
.
info
(
"Including token %s for %s"
%
(
token
,
reference_key
))
if
token
:
...
...
@@ -79,21 +73,21 @@ def requestAddToken(client, base_token_path):
# update information
log
.
info
(
"New token added for slave instance %s. Updating file status..."
%
reference
)
status_file
=
os
.
path
.
join
(
base_token
_path
,
'%s.status'
%
reference
)
status_file
=
os
.
path
.
join
(
token_base
_path
,
'%s.status'
%
reference
)
updateFile
(
status_file
,
'TOKEN_ADDED'
)
os
.
unlink
(
request_file
)
else
:
log
.
debug
(
'Bad token. Request add token fail for %s...'
%
request_file
)
def
requestRemoveToken
(
client
,
base_token
_path
):
path_list
=
[
x
for
x
in
os
.
listdir
(
base_token
_path
)
if
x
.
endswith
(
'.remove'
)]
def
requestRemoveToken
(
client
,
token_base
_path
):
path_list
=
[
x
for
x
in
os
.
listdir
(
token_base
_path
)
if
x
.
endswith
(
'.remove'
)]
if
not
path_list
:
log
.
info
(
"No token to delete. Exiting..."
)
return
for
reference_key
in
path_list
:
request_file
=
os
.
path
.
join
(
base_token
_path
,
reference_key
)
request_file
=
os
.
path
.
join
(
token_base
_path
,
reference_key
)
token
=
readFile
(
request_file
)
if
token
:
reference
=
reference_key
.
split
(
'.'
)[
0
]
...
...
@@ -108,7 +102,7 @@ def requestRemoveToken(client, base_token_path):
continue
else
:
# certificate is invalidated, it will be revoked
writeFile
(
os
.
path
.
join
(
base_token
_path
,
'%s.revoke'
%
reference
),
''
)
writeFile
(
os
.
path
.
join
(
token_base
_path
,
'%s.revoke'
%
reference
),
''
)
if
result
in
(
True
,
'True'
):
# update information
...
...
@@ -117,33 +111,17 @@ def requestRemoveToken(client, base_token_path):
if
result
in
[
'True'
,
'False'
]:
os
.
unlink
(
request_file
)
status_file
=
os
.
path
.
join
(
base_token
_path
,
'%s.status'
%
reference
)
status_file
=
os
.
path
.
join
(
token_base
_path
,
'%s.status'
%
reference
)
if
os
.
path
.
exists
(
status_file
):
os
.
unlink
(
status_file
)
ipv6_file
=
os
.
path
.
join
(
base_token
_path
,
'%s.ipv6'
%
reference
)
ipv6_file
=
os
.
path
.
join
(
token_base
_path
,
'%s.ipv6'
%
reference
)
if
os
.
path
.
exists
(
ipv6_file
):
os
.
unlink
(
ipv6_file
)
else
:
log
.
debug
(
'Bad token. Request add token fail for %s...'
%
request_file
)
def
requestRevoqueCertificate
(
args
):
base_token_path
=
args
[
'token_base_path'
]
path_list
=
[
x
for
x
in
os
.
listdir
(
base_token_path
)
if
x
.
endswith
(
'.revoke'
)]
for
reference_key
in
path_list
:
reference
=
reference_key
.
split
(
'.'
)[
0
]
if
revokeByMail
(
args
[
'registry_url'
],
'%s@slapos'
%
reference
.
lower
(),
args
[
'db'
]):
os
.
unlink
(
os
.
path
.
join
(
base_token_path
,
reference_key
))
log
.
info
(
"Certificate revoked for slave instance %s."
%
reference
)
return
log
.
info
(
"Failed to revoke email for %s"
%
reference
)
def
checkService
(
client
,
base_token_path
,
token_json
,
computer_partition
):
def
checkService
(
client
,
token_base_path
,
token_json
,
computer_partition
):
token_dict
=
loadJsonFile
(
token_json
)
updated
=
False
if
not
token_dict
:
...
...
@@ -152,7 +130,7 @@ def checkService(client, base_token_path, token_json, computer_partition):
# Check token status
for
slave_reference
,
token
in
token_dict
.
iteritems
():
log
.
info
(
"%s %s"
%
(
slave_reference
,
token
))
status_file
=
os
.
path
.
join
(
base_token
_path
,
'%s.status'
%
slave_reference
)
status_file
=
os
.
path
.
join
(
token_base
_path
,
'%s.status'
%
slave_reference
)
if
not
os
.
path
.
exists
(
status_file
):
# This token is not added yet!
log
.
info
(
"Token %s dont exist yet."
%
status_file
)
...
...
@@ -206,31 +184,22 @@ def checkService(client, base_token_path, token_json, computer_partition):
slave_reference
,
traceback
.
format_exc
())
def
manage
(
args
,
can_bang
=
True
):
computer_guid
=
args
[
'computer_id'
]
partition_id
=
args
[
'partition_id'
]
server_url
=
args
[
'server_url'
]
key_file
=
args
[
'key_file'
]
cert_file
=
args
[
'cert_file'
]
def
manage
(
registry_url
,
token_base_path
,
token_json
,
computer_dict
,
can_bang
=
True
):
client
=
registry
.
RegistryClient
(
args
[
'registry_url'
])
base_token_path
=
args
[
'token_base_path'
]
token_json
=
args
[
'token_json'
]
client
=
registry
.
RegistryClient
(
registry_url
)
log
.
info
(
"ADD TOKEN"
)
# Request Add new tokens
requestAddToken
(
client
,
base_token
_path
)
requestAddToken
(
client
,
token_base
_path
)
log
.
info
(
"Remove TOKEN"
)
# Request delete removed token
requestRemoveToken
(
client
,
base_token
_path
)
requestRemoveToken
(
client
,
token_base
_path
)
computer_partition
=
getComputerPartition
(
server_url
,
key_file
,
cert_file
,
computer_guid
,
partition_id
)
computer_partition
=
getComputerPartition
(
**
computer_dict
)
log
.
info
(
"Update Services"
)
# check status of all token
checkService
(
client
,
base_token_path
,
token_json
,
computer_partition
)
checkService
(
client
,
token_base_path
,
token_json
,
computer_partition
)
slapos/recipe/redis/__init__.py
View file @
dfab94f0
...
...
@@ -25,7 +25,7 @@
#
##############################################################################
import
os
import
sys
from
slapos.recipe.librecipe
import
GenericBaseRecipe
class
Recipe
(
GenericBaseRecipe
):
...
...
@@ -58,8 +58,8 @@ class Recipe(GenericBaseRecipe):
redis
=
self
.
createPythonScript
(
self
.
options
[
'wrapper'
],
'slapos.recipe.librecipe.execute.
execute
'
,
[
self
.
options
[
'server_bin'
],
config_file
]
'slapos.recipe.librecipe.execute.
generic_exec
'
,
((
self
.
options
[
'server_bin'
],
config_file
),)
)
path_list
.
append
(
redis
)
...
...
@@ -67,11 +67,20 @@ class Recipe(GenericBaseRecipe):
if
promise_script
:
promise
=
self
.
createPythonScript
(
promise_script
,
'%s.promise.main'
%
__name__
,
dict
(
host
=
self
.
options
[
'ipv6'
],
port
=
self
.
options
[
'port'
]
,
unixsocket
=
self
.
options
.
get
(
'unixsocket'
)
)
__name__
+
'.promise'
,
(
self
.
options
[
'ipv6'
],
int
(
self
.
options
[
'port'
])
,
self
.
options
.
get
(
'unixsocket'
)
)
)
path_list
.
append
(
promise
)
return
path_list
def
promise
(
host
,
port
,
unixsocket
):
from
.MyRedis2410
import
Redis
try
:
r
=
Redis
(
host
=
host
,
port
=
port
,
unix_socket_path
=
unixsocket
,
db
=
0
)
r
.
publish
(
"Promise-Service"
,
"SlapOS Promise"
)
r
.
connection_pool
.
disconnect
()
except
Exception
,
e
:
sys
.
exit
(
e
)
slapos/recipe/redis/promise.py
deleted
100644 → 0
View file @
d55a5d17
#! /usr/bin/env python
# -*- coding: utf-8 -*-
import
slapos.recipe.redis.MyRedis2410
as
redis
import
sys
def
main
(
args
):
host
=
args
[
'host'
]
port
=
int
(
args
[
'port'
])
unixsocket
=
args
[
'unixsocket'
]
try
:
r
=
redis
.
Redis
(
host
=
host
,
port
=
port
,
unix_socket_path
=
unixsocket
,
db
=
0
)
r
.
publish
(
"Promise-Service"
,
"SlapOS Promise"
)
r
.
connection_pool
.
disconnect
()
sys
.
exit
(
0
)
except
Exception
,
e
:
print
str
(
e
)
sys
.
exit
(
1
)
\ No newline at end of file
slapos/recipe/seleniumrunner/__init__.py
View file @
dfab94f0
...
...
@@ -25,23 +25,15 @@
#
#############################################################################
import
os
import
sys
import
zc.buildout
from
slapos.recipe.librecipe
import
BaseSlapRecipe
from
slapos.recipe.librecipe
import
GenericBaseRecipe
class
Recipe
(
GenericBaseRecipe
):
def
install
(
self
):
runner
=
self
.
createPythonScript
(
def
install
(
self
):
return
self
.
createPythonScript
(
self
.
options
[
'runner-path'
],
__name__
+
'.testrunner.run'
,
arguments
=
[
self
.
options
[
'suite-url'
],
(
self
.
options
[
'suite-url'
],
self
.
options
[
'report-url'
],
self
.
options
[
'report-project'
],
self
.
options
[
'browser'
],
])
return
[
runner
]
self
.
options
[
'browser'
]))
slapos/recipe/seleniumrunner/testrunner.py
View file @
dfab94f0
...
...
@@ -36,12 +36,7 @@ import urlparse
from
subprocess
import
Popen
,
PIPE
import
signal
def
run
(
args
):
suite_url
=
args
[
0
]
report_url
=
args
[
1
]
project
=
args
[
2
]
browser_binary
=
args
[
3
]
def
run
(
suite_url
,
report_url
,
project
,
browser_binary
):
suite_parsed
=
urlparse
.
urlparse
(
suite_url
)
config
=
{
...
...
slapos/recipe/shell.py
View file @
dfab94f0
...
...
@@ -31,27 +31,15 @@ from slapos.recipe.librecipe import GenericBaseRecipe
class
Recipe
(
GenericBaseRecipe
):
def
install
(
self
):
env
=
os
.
environ
.
copy
()
path_list
=
self
.
options
[
'path'
].
split
(
'
\
n
'
)
env
.
update
(
PATH
=
':'
.
join
(
path_list
))
env
.
update
(
SHELL
=
self
.
options
[
'shell'
])
env
.
update
(
HOME
=
self
.
options
[
'home'
])
ps1
=
self
.
options
.
get
(
'ps1'
)
if
ps1
is
not
None
:
env
.
update
(
PS1
=
str
(
json
.
loads
(
ps1
)))
else
:
env
.
update
(
PS1
=
env
.
get
(
'PS1'
,
'> '
))
wrapper
=
self
.
createPythonScript
(
env
=
{
'HOME'
:
self
.
options
[
'home'
],
'PATH'
:
':'
.
join
(
self
.
options
[
'path'
].
split
(
'
\
n
'
)),
'PS1'
:
str
(
json
.
loads
(
ps1
))
if
ps1
else
os
.
getenv
(
'PS1'
,
'> '
),
'SHELL'
:
self
.
options
[
'shell'
],
}
return
self
.
createPythonScript
(
self
.
options
[
'wrapper'
],
'slapos.recipe.librecipe.execute.executee'
,
[
# Executable
[
self
.
options
[
'shell'
]],
# Environment
env
]
'slapos.recipe.librecipe.execute.generic_exec'
,
((
self
.
options
[
'shell'
],),
env
),
)
return
[
wrapper
]
slapos/recipe/shellinabox.py
View file @
dfab94f0
...
...
@@ -33,24 +33,14 @@ import shlex
from
slapos.recipe.librecipe
import
GenericBaseRecipe
def
login_shell
(
args
):
password_file
=
args
[
'password-file'
]
def
login_shell
(
password_file
,
shell
):
if
password_file
:
with
open
(
password_file
,
'r'
)
as
password_file
:
password
=
password_file
.
read
()
if
(
password
!=
''
):
entered_password
=
getpass
()
else
:
entered_password
=
''
if
not
hmac
.
compare_digest
(
entered_password
,
password
):
return
1
else
:
commandline
=
shlex
.
split
(
args
[
'shell'
])
path
=
commandline
[
0
]
os
.
execv
(
path
,
commandline
)
else
:
if
not
password
or
hmac
.
compare_digest
(
getpass
(),
password
):
commandline
=
shlex
.
split
(
shell
)
os
.
execv
(
commandline
[
0
],
commandline
)
return
1
def
shellinabox
(
args
):
...
...
@@ -95,22 +85,16 @@ def shellinabox(args):
class
Recipe
(
GenericBaseRecipe
):
def
install
(
self
):
path_list
=
[]
login_shell
=
self
.
createPythonScript
(
login_shell_wrapper
=
self
.
createPythonScript
(
self
.
options
[
'login-shell'
],
'%s.login_shell'
%
__name__
,
{
'password-file'
:
self
.
options
[
'password-file'
],
'shell'
:
self
.
options
[
'shell'
]
}
__name__
+
'.login_shell'
,
(
self
.
options
[
'password-file'
],
self
.
options
[
'shell'
])
)
path_list
.
append
(
login_shell
)
wrapper
=
self
.
createPythonScript
(
shellinabox_
wrapper
=
self
.
createPythonScript
(
self
.
options
[
'wrapper'
],
'%s.shellinabox'
%
__name__
,
dict
(
__name__
+
'.shellinabox'
,
(
dict
(
certificate_dir
=
self
.
options
[
'certificate-directory'
],
ssl_key
=
self
.
options
[
'key-file'
],
ssl_certificate
=
self
.
options
[
'cert-file'
],
...
...
@@ -118,9 +102,8 @@ class Recipe(GenericBaseRecipe):
directory
=
self
.
options
[
'directory'
],
ipv6
=
self
.
options
[
'ipv6'
],
port
=
self
.
options
[
'port'
],
login_shell
=
login_shell
,
)
login_shell
=
login_shell
_wrapper
,
),
)
)
path_list
.
append
(
wrapper
)
return
[
wrapper
]
return
login_shell_wrapper
,
shellinabox_wrapper
slapos/recipe/signal_wrapper.py
View file @
dfab94f0
...
...
@@ -32,6 +32,6 @@ class Recipe(GenericBaseRecipe):
self
.
createPythonScript
(
self
.
options
[
'wrapper-path'
],
'slapos.recipe.librecipe.execute.execute_with_signal_translation'
,
[
self
.
options
[
'wrapped-path'
]]
((
self
.
options
[
'wrapped-path'
],),)
)
]
slapos/recipe/simplehttpserver/__init__.py
View file @
dfab94f0
...
...
@@ -68,9 +68,8 @@ class Recipe(GenericBaseRecipe):
'root-dir'
:
self
.
options
[
'root-dir'
]
}
server
=
self
.
createPythonScript
(
return
self
.
createPythonScript
(
self
.
options
[
'wrapper'
].
strip
(),
'%s.simplehttpserver.run'
%
__name__
,
parameters
__name__
+
'.simplehttpserver.run'
,
(
parameters
,)
)
return
[
server
]
slapos/recipe/simplelogger.py
View file @
dfab94f0
...
...
@@ -29,9 +29,9 @@ import time
from
slapos.recipe.librecipe
import
GenericBaseRecipe
def
log
(
args
):
def
log
(
filename
):
prefix
=
time
.
strftime
(
'%Y-%m-%d.%H:%M.%s:'
)
with
open
(
args
[
'filename'
],
'aw
'
)
as
logfile
:
with
open
(
filename
,
'a
'
)
as
logfile
:
for
line
in
sys
.
stdin
:
print
>>
logfile
,
prefix
,
line
,
print
>>
logfile
,
prefix
,
'------------------------'
...
...
@@ -39,10 +39,7 @@ def log(args):
class
Recipe
(
GenericBaseRecipe
):
def
install
(
self
):
wrapper
=
self
.
options
[
'wrapper'
]
log
=
self
.
options
[
'log'
]
script
=
self
.
createPythonScript
(
wrapper
,
return
self
.
createPythonScript
(
self
.
options
[
'wrapper'
],
__name__
+
'.log'
,
arguments
=
dict
(
filename
=
log
))
return
[
script
]
(
self
.
options
[
'log'
],))
slapos/recipe/sphinx/__init__.py
View file @
dfab94f0
...
...
@@ -50,9 +50,9 @@ class Recipe(GenericBaseRecipe):
# Create init script
wrapper
=
self
.
createPythonScript
(
self
.
options
[
'wrapper'
],
'slapos.recipe.librecipe.execute.
execute
'
,
[
self
.
options
[
'sphinx-searchd-binary'
].
strip
(),
'-c'
,
sphinx_conf_path
,
'--nodetach'
]
,
'slapos.recipe.librecipe.execute.
generic_exec
'
,
((
self
.
options
[
'sphinx-searchd-binary'
].
strip
(),
'-c'
,
sphinx_conf_path
,
'--nodetach'
),)
,
)
return
[
wrapper
,
sphinx_conf_path
]
slapos/recipe/squid/__init__.py
View file @
dfab94f0
...
...
@@ -80,19 +80,15 @@ class Recipe(GenericBaseRecipe):
# Prepare directories
prepare_path
=
self
.
createPythonScript
(
self
.
options
[
'prepare-path'
],
'slapos.recipe.librecipe.execute.execute'
,
arguments
=
[
self
.
options
[
'binary-path'
].
strip
(),
'-z'
,
'-f'
,
configuration_path
,
],)
'slapos.recipe.librecipe.execute.generic_exec'
,
((
self
.
options
[
'binary-path'
].
strip
(),
'-z'
,
'-f'
,
configuration_path
),))
# Create running wrapper
wrapper_path
=
self
.
createPythonScript
(
self
.
options
[
'wrapper-path'
],
'slapos.recipe.librecipe.execute.execute'
,
arguments
=
[
self
.
options
[
'binary-path'
].
strip
(),
'-N'
,
'-f'
,
configuration_path
,
],)
'slapos.recipe.librecipe.execute.generic_exec'
,
((
self
.
options
[
'binary-path'
].
strip
(),
'-N'
,
'-f'
,
configuration_path
),))
return
[
configuration_path
,
wrapper_path
,
prepare_path
]
slapos/recipe/sshkeys_authority.py
View file @
dfab94f0
...
...
@@ -34,17 +34,14 @@ from slapos.recipe.librecipe import GenericBaseRecipe
from
slapos.recipe.librecipe.inotify
import
subfiles
# This authority only works with dropbear or openssh sshkey generators
def
sshkeys_authority
(
args
):
requests_directory
=
args
[
'requests'
]
keygen_binary
=
args
[
'sshkeygen'
]
def
sshkeys_authority
(
request_directory
,
keygen_binary
):
if
'openssh'
in
keygen_binary
:
authority_type
=
'openssh'
else
:
# Keep dropbear for compatibility
authority_type
=
'dropbear'
for
request_filename
in
subfiles
(
request
s
_directory
):
for
request_filename
in
subfiles
(
request_directory
):
with
open
(
request_filename
)
as
request_file
:
request
=
json
.
load
(
request_file
)
...
...
@@ -98,18 +95,13 @@ def sshkeys_authority(args):
public_key_file
.
write
(
public_key_value
)
class
Recipe
(
GenericBaseRecipe
):
def
install
(
self
):
args
=
dict
(
requests
=
self
.
options
[
'request-directory'
],
sshkeygen
=
self
.
options
[
'keygen-binary'
],
)
wrapper
=
self
.
createPythonScript
(
self
.
options
[
'wrapper'
],
__name__
+
'.sshkeys_authority'
,
args
)
return
[
wrapper
]
return
self
.
createPythonScript
(
self
.
options
[
'wrapper'
],
__name__
+
'.sshkeys_authority'
,
(
self
.
options
[
'request-directory'
],
self
.
options
[
'keygen-binary'
]))
class
Request
(
GenericBaseRecipe
):
...
...
@@ -162,9 +154,8 @@ class Request(GenericBaseRecipe):
wrapper
=
self
.
createPythonScript
(
self
.
options
[
'wrapper'
],
'slapos.recipe.librecipe.execute.execute_wait'
,
[
[
self
.
options
[
'executable'
]],
[
self
.
private_key
,
self
.
public_key
]
])
'slapos.recipe.librecipe.execute.generic_exec'
,
((
self
.
options
[
'executable'
],),),
{
'wait_list'
:
(
self
.
private_key
,
self
.
public_key
)})
return
[
request_file
,
wrapper
,
public_key_link
,
private_key_link
]
slapos/recipe/stunnel/__init__.py
View file @
dfab94f0
...
...
@@ -30,13 +30,16 @@ import errno
from
slapos.recipe.librecipe
import
GenericBaseRecipe
def
post_rotate
(
args
):
pid_file
=
args
[
'pid_file'
]
if
os
.
path
.
exist
(
pid_file
):
with
open
(
pid_file
,
'r'
)
as
file_
:
pid
=
file_
.
read
().
strip
()
os
.
kill
(
pid
,
signal
.
SIGUSR1
)
def
kill
(
pid_file
,
sig
=
signal
.
SIGUSR1
):
if
os
.
path
.
exists
(
pid_file
):
with
open
(
pid_file
)
as
f
:
pid
=
int
(
f
.
read
().
strip
())
try
:
os
.
kill
(
pid
,
sig
)
except
OSError
,
e
:
if
e
.
errno
!=
errno
.
ESRCH
:
# No such process
raise
e
os
.
unlink
(
pid_file
)
class
Recipe
(
GenericBaseRecipe
):
...
...
@@ -78,26 +81,17 @@ class Recipe(GenericBaseRecipe):
wrapper
=
self
.
createPythonScript
(
self
.
options
[
'wrapper'
],
'slapos.recipe.librecipe.execute.
execute
'
,
[
self
.
options
[
'stunnel-binary'
],
conf_file
]
'slapos.recipe.librecipe.execute.
generic_exec
'
,
((
self
.
options
[
'stunnel-binary'
],
conf_file
),)
)
path_list
.
append
(
wrapper
)
if
os
.
path
.
exists
(
pid_file
):
with
open
(
pid_file
,
'r'
)
as
file_
:
pid
=
file_
.
read
().
strip
()
# Reload configuration
try
:
os
.
kill
(
int
(
pid
,
10
),
signal
.
SIGHUP
)
except
OSError
,
e
:
if
e
.
errno
==
errno
.
ESRCH
:
# No such process
os
.
unlink
(
pid_file
)
else
:
raise
e
kill
(
pid_file
,
signal
.
SIGHUP
)
if
'post-rotate-script'
in
self
.
options
:
self
.
createPythonScript
(
self
.
options
[
'post-rotate-script'
],
__name__
+
'post_rotate'
,
dict
(
pid_file
=
pid_file
))
path_list
.
append
(
self
.
createPythonScript
(
self
.
options
[
'post-rotate-script'
]
,
__name__
+
'.kill'
,
(
pid_file
,)
))
return
path_list
slapos/recipe/tidstorage/__init__.py
View file @
dfab94f0
...
...
@@ -37,18 +37,18 @@ class Recipe(GenericBaseRecipe):
wrapper
=
self
.
options
.
get
(
'tidstorage-wrapper'
)
wrapper
and
r
.
append
(
self
.
createPythonScript
(
wrapper
,
'slapos.recipe.librecipe.execute.
execute
'
,
[
self
.
options
[
'tidstoraged-binary'
],
'--nofork'
,
'--config'
,
configuration_file
]
))
'slapos.recipe.librecipe.execute.
generic_exec
'
,
((
self
.
options
[
'tidstoraged-binary'
]
,
'--nofork'
,
'--config'
,
configuration_file
),)
))
r
.
append
(
self
.
createPythonScript
(
self
.
options
[
'repozo-wrapper'
],
'slapos.recipe.librecipe.execute.
execute
'
,
[
self
.
options
[
'tidstorage-repozo-binary'
],
'slapos.recipe.librecipe.execute.
generic_exec
'
,
((
self
.
options
[
'tidstorage-repozo-binary'
],
'--config'
,
configuration_file
,
'--repozo'
,
self
.
options
[
'repozo-binary'
],
'--gzip'
,
'--quick'
,
]
))
),)
))
return
r
slapos/recipe/wrapper.py
View file @
dfab94f0
...
...
@@ -63,12 +63,17 @@ class Recipe(GenericBaseRecipe):
# More complex needs: create a Python script as wrapper
if
wait_files
is
not
None
:
wait_files
=
[
filename
.
strip
()
for
filename
in
wait_files
.
split
()
if
filename
.
strip
()]
if
environment
is
not
None
:
environment
=
dict
((
k
.
strip
(),
v
.
strip
())
for
k
,
v
in
[
line
.
split
(
'='
)
for
line
in
environment
.
splitlines
()
if
line
.
strip
()
])
extra_environ
=
{}
if
environment
:
for
line
in
environment
.
splitlines
():
line
=
line
.
strip
()
if
line
:
k
,
v
=
line
.
split
(
'='
)
extra_environ
[
k
.
rstrip
()]
=
v
.
lstrip
()
args
=
[
command_line
,
extra_environ
]
if
wait_files
:
args
.
append
(
wait_files
.
split
())
# We create a python script and a wrapper around the python
# script because the python script might have a too long #! line
...
...
@@ -81,7 +86,7 @@ class Recipe(GenericBaseRecipe):
python_script
=
self
.
createPythonScript
(
base_script_path
+
'.py'
,
'slapos.recipe.librecipe.execute.generic_exec'
,
(
command_line
,
wait_files
,
environment
,),
)
args
)
return
[
python_script
,
self
.
createWrapper
(
name
=
wrapper_path
,
command
=
python_script
,
...
...
slapos/recipe/zabbixagent/__init__.py
View file @
dfab94f0
...
...
@@ -71,10 +71,10 @@ class Recipe(BaseSlapRecipe):
self
.
_createDirectory
(
cron_d
)
self
.
_createDirectory
(
crontabs
)
wrapper
=
zc
.
buildout
.
easy_install
.
scripts
([(
'crond'
,
'slapos.recipe.librecipe.execute'
,
'
execute'
)],
self
.
ws
,
sys
.
executable
,
s
elf
.
wrapper_directory
,
arguments
=
[
'slapos.recipe.librecipe.execute'
,
'
generic_exec'
)],
self
.
ws
,
s
ys
.
executable
,
self
.
wrapper_directory
,
arguments
=
repr
((
self
.
options
[
'dcrond_binary'
].
strip
(),
'-s'
,
cron_d
,
'-c'
,
crontabs
,
'-t'
,
timestamps
,
'-f'
,
'-l'
,
'5'
,
'-M'
,
catcher
]
'-t'
,
timestamps
,
'-f'
,
'-l'
,
'5'
,
'-M'
,
catcher
))[
1
:
-
1
]
)[
0
]
self
.
path_list
.
append
(
wrapper
)
return
cron_d
...
...
@@ -101,10 +101,10 @@ class Recipe(BaseSlapRecipe):
self
.
path_list
.
append
(
zabbix_agentd_path
)
wrapper
=
zc
.
buildout
.
easy_install
.
scripts
([(
'zabbixagentd'
,
'slapos.recipe.librecipe.execute'
,
'
execute'
)],
self
.
ws
,
sys
.
executable
,
s
elf
.
bin_directory
,
arguments
=
[
'slapos.recipe.librecipe.execute'
,
'
generic_exec'
)],
self
.
ws
,
s
ys
.
executable
,
self
.
bin_directory
,
arguments
=
repr
((
self
.
options
[
'zabbix_agentd_binary'
].
strip
(),
'-c'
,
zabbix_agentd_path
])[
0
]
zabbix_agentd_path
))[
1
:
-
1
])[
0
]
self
.
path_list
.
extend
(
zc
.
buildout
.
easy_install
.
scripts
([
(
'zabbixagentd'
,
__name__
+
'.svcdaemon'
,
'svcdaemon'
)],
...
...
slapos/recipe/zeo/__init__.py
View file @
dfab94f0
...
...
@@ -91,8 +91,8 @@ class Recipe(GenericBaseRecipe):
# Create running wrapper
wrapper_path
=
self
.
createPythonScript
(
self
.
options
[
'wrapper-path'
],
'slapos.recipe.librecipe.execute.
execute
'
,
arguments
=
[
self
.
options
[
'binary-path'
].
strip
(),
'-C'
,
self
.
options
[
'conf-path'
]],
)
'slapos.recipe.librecipe.execute.
generic_exec
'
,
((
self
.
options
[
'binary-path'
].
strip
()
,
'-C'
,
self
.
options
[
'conf-path'
]),)
)
return
[
configuration_path
,
wrapper_path
]
slapos/test/recipe/test_re6stnet.py
View file @
dfab94f0
...
...
@@ -79,15 +79,14 @@ class Re6stnetTest(unittest.TestCase):
token_file
=
os
.
path
.
join
(
self
.
options
[
'conf-dir'
],
'token.json'
)
with
open
(
path
,
'r'
)
as
f
:
content
=
f
.
read
()
self
.
assertIn
(
"'token_json': '%s'"
%
token_file
,
content
)
self
.
assertIn
(
"('http://%s:%s/', %r, %r,"
%
(
self
.
options
[
'ipv4'
],
self
.
options
[
'port'
],
self
.
token_dir
,
token_file
),
content
)
self
.
assertIn
(
"'partition_id': 'slappart0'"
,
content
)
self
.
assertIn
(
"'computer_id': 'comp-test'"
,
content
)
self
.
assertIn
(
"'computer_
gu
id': 'comp-test'"
,
content
)
self
.
assertIn
(
"'key_file': '/path/to/key'"
,
content
)
self
.
assertIn
(
"'cert_file': '/path/to/cert'"
,
content
)
self
.
assertIn
(
"'server_url': 'http://server.com'"
,
content
)
self
.
assertIn
(
"'token_base_path': '%s'"
%
self
.
token_dir
,
content
)
self
.
assertIn
(
"'registry_url': 'http://%s:%s/'"
%
(
self
.
options
[
'ipv4'
],
self
.
options
[
'port'
]),
content
)
self
.
assertIn
(
"'master_url': 'http://server.com'"
,
content
)
def
fake_generateCertificates
(
self
):
return
...
...
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