Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
slapos
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Merge Requests
74
Merge Requests
74
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Jobs
Commits
Open sidebar
nexedi
slapos
Commits
43653c40
Commit
43653c40
authored
May 26, 2011
by
Łukasz Nowak
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Import some important instantiation recipes.
parent
ff17fae0
Changes
51
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
51 changed files
with
2862 additions
and
0 deletions
+2862
-0
CHANGES.txt
slapos/erp5.recipe.testnode/CHANGES.txt
+6
-0
MANIFEST.in
slapos/erp5.recipe.testnode/MANIFEST.in
+2
-0
README.txt
slapos/erp5.recipe.testnode/README.txt
+1
-0
setup.py
slapos/erp5.recipe.testnode/setup.py
+40
-0
__init__.py
slapos/erp5.recipe.testnode/src/erp5/__init__.py
+6
-0
__init__.py
slapos/erp5.recipe.testnode/src/erp5/recipe/__init__.py
+6
-0
SlapOSControler.py
...cipe.testnode/src/erp5/recipe/testnode/SlapOSControler.py
+90
-0
Updater.py
.../erp5.recipe.testnode/src/erp5/recipe/testnode/Updater.py
+189
-0
__init__.py
...erp5.recipe.testnode/src/erp5/recipe/testnode/__init__.py
+170
-0
slapos.cfg.in
....testnode/src/erp5/recipe/testnode/template/slapos.cfg.in
+10
-0
testnode.py
...erp5.recipe.testnode/src/erp5/recipe/testnode/testnode.py
+229
-0
CHANGES.txt
slapos/slapos.recipe.erp5/CHANGES.txt
+7
-0
MANIFEST.in
slapos/slapos.recipe.erp5/MANIFEST.in
+2
-0
README.txt
slapos/slapos.recipe.erp5/README.txt
+2
-0
setup.py
slapos/slapos.recipe.erp5/setup.py
+41
-0
__init__.py
slapos/slapos.recipe.erp5/src/slapos/__init__.py
+6
-0
__init__.py
slapos/slapos.recipe.erp5/src/slapos/recipe/__init__.py
+6
-0
__init__.py
slapos/slapos.recipe.erp5/src/slapos/recipe/erp5/__init__.py
+912
-0
apache.py
slapos/slapos.recipe.erp5/src/slapos/recipe/erp5/apache.py
+22
-0
catdatefile.py
.../slapos.recipe.erp5/src/slapos/recipe/erp5/catdatefile.py
+14
-0
certificate_authority.py
...cipe.erp5/src/slapos/recipe/erp5/certificate_authority.py
+112
-0
erp5.py
slapos/slapos.recipe.erp5/src/slapos/recipe/erp5/erp5.py
+107
-0
execute.py
slapos/slapos.recipe.erp5/src/slapos/recipe/erp5/execute.py
+48
-0
innobackupex.py
...slapos.recipe.erp5/src/slapos/recipe/erp5/innobackupex.py
+25
-0
killpidfromfile.py
...pos.recipe.erp5/src/slapos/recipe/erp5/killpidfromfile.py
+12
-0
mysql.py
slapos/slapos.recipe.erp5/src/slapos/recipe/erp5/mysql.py
+71
-0
apache.location-snippet.conf.in
...apos/recipe/erp5/template/apache.location-snippet.conf.in
+5
-0
apache.ssl-snippet.conf.in
...rc/slapos/recipe/erp5/template/apache.ssl-snippet.conf.in
+6
-0
apache.zope.conf.in
....erp5/src/slapos/recipe/erp5/template/apache.zope.conf.in
+55
-0
apache.zope.conf.path-protected.in
...s/recipe/erp5/template/apache.zope.conf.path-protected.in
+7
-0
apache.zope.conf.path.in
.../src/slapos/recipe/erp5/template/apache.zope.conf.path.in
+5
-0
cloudooo.cfg.in
...cipe.erp5/src/slapos/recipe/erp5/template/cloudooo.cfg.in
+54
-0
haproxy.cfg.in
...ecipe.erp5/src/slapos/recipe/erp5/template/haproxy.cfg.in
+26
-0
initmysql.sql.in
...ipe.erp5/src/slapos/recipe/erp5/template/initmysql.sql.in
+2
-0
kumo_gateway.in
...cipe.erp5/src/slapos/recipe/erp5/template/kumo_gateway.in
+2
-0
kumo_manager.in
...cipe.erp5/src/slapos/recipe/erp5/template/kumo_manager.in
+2
-0
kumo_server.in
...ecipe.erp5/src/slapos/recipe/erp5/template/kumo_server.in
+2
-0
logrotate_entry.in
...e.erp5/src/slapos/recipe/erp5/template/logrotate_entry.in
+13
-0
memcached.in
....recipe.erp5/src/slapos/recipe/erp5/template/memcached.in
+2
-0
my.cnf.in
...pos.recipe.erp5/src/slapos/recipe/erp5/template/my.cnf.in
+52
-0
openssl.cnf.ca.in
...pe.erp5/src/slapos/recipe/erp5/template/openssl.cnf.ca.in
+350
-0
tidstorage.py.in
...ipe.erp5/src/slapos/recipe/erp5/template/tidstorage.py.in
+15
-0
zeo.conf.in
...s.recipe.erp5/src/slapos/recipe/erp5/template/zeo.conf.in
+15
-0
zope-deadlockdebugger-snippet.conf.in
...ecipe/erp5/template/zope-deadlockdebugger-snippet.conf.in
+7
-0
zope-tidstorage-snippet.conf.in
...apos/recipe/erp5/template/zope-tidstorage-snippet.conf.in
+6
-0
zope-zeo-snippet.conf.in
.../src/slapos/recipe/erp5/template/zope-zeo-snippet.conf.in
+8
-0
zope-zodb-snippet.conf.in
...src/slapos/recipe/erp5/template/zope-zodb-snippet.conf.in
+6
-0
zope.conf.in
....recipe.erp5/src/slapos/recipe/erp5/template/zope.conf.in
+58
-0
zope.conf.timerservice.in
...src/slapos/recipe/erp5/template/zope.conf.timerservice.in
+6
-0
test_suite_runner.py
...s.recipe.erp5/src/slapos/recipe/erp5/test_suite_runner.py
+11
-0
testrunner.py
...s/slapos.recipe.erp5/src/slapos/recipe/erp5/testrunner.py
+11
-0
No files found.
slapos/erp5.recipe.testnode/CHANGES.txt
0 → 100644
View file @
43653c40
Changelog
=========
1.0 (unreleased)
----------------
slapos/erp5.recipe.testnode/MANIFEST.in
0 → 100644
View file @
43653c40
include CHANGES.txt
recursive-include src/erp5/recipe/testnode *.in
slapos/erp5.recipe.testnode/README.txt
0 → 100644
View file @
43653c40
The erp5.recipe.tesnode aims to install generic erp5 testnode.
slapos/erp5.recipe.testnode/setup.py
0 → 100644
View file @
43653c40
from
setuptools
import
setup
,
find_packages
name
=
"erp5.recipe.testnode"
version
=
'1.0.23'
def
read
(
name
):
return
open
(
name
)
.
read
()
long_description
=
(
read
(
'README.txt'
)
+
'
\n
'
+
read
(
'CHANGES.txt'
)
)
setup
(
name
=
name
,
version
=
version
,
description
=
"ZC Buildout recipe for create an testnode instance"
,
long_description
=
long_description
,
license
=
"GPLv3"
,
keywords
=
"buildout erp5 test"
,
classifiers
=
[
"Framework :: Buildout :: Recipe"
,
"Programming Language :: Python"
,
],
packages
=
find_packages
(
'src'
),
package_dir
=
{
''
:
'src'
},
include_package_data
=
True
,
install_requires
=
[
'setuptools'
,
'slapos.lib.recipe'
,
'xml_marshaller'
,
'zc.buildout'
,
'zc.recipe.egg'
,
# below are requirements to provide full blown python interpreter
'lxml'
,
'PyXML'
,
],
namespace_packages
=
[
'erp5'
,
'erp5.recipe'
],
entry_points
=
{
'zc.buildout'
:
[
'default =
%
s:Recipe'
%
name
]},
)
slapos/erp5.recipe.testnode/src/erp5/__init__.py
0 → 100644
View file @
43653c40
# See http://peak.telecommunity.com/DevCenter/setuptools#namespace-packages
try
:
__import__
(
'pkg_resources'
)
.
declare_namespace
(
__name__
)
except
ImportError
:
from
pkgutil
import
extend_path
__path__
=
extend_path
(
__path__
,
__name__
)
slapos/erp5.recipe.testnode/src/erp5/recipe/__init__.py
0 → 100644
View file @
43653c40
# See http://peak.telecommunity.com/DevCenter/setuptools#namespace-packages
try
:
__import__
(
'pkg_resources'
)
.
declare_namespace
(
__name__
)
except
ImportError
:
from
pkgutil
import
extend_path
__path__
=
extend_path
(
__path__
,
__name__
)
slapos/erp5.recipe.testnode/src/erp5/recipe/testnode/SlapOSControler.py
0 → 100644
View file @
43653c40
import
slapos.slap
,
subprocess
,
os
,
time
from
xml_marshaller
import
xml_marshaller
class
SlapOSControler
(
object
):
def
__init__
(
self
,
config
,
process_group_pid_set
=
None
):
self
.
config
=
config
# By erasing everything, we make sure that we are able to "update"
# existing profiles. This is quite dirty way to do updates...
if
os
.
path
.
exists
(
config
[
'proxy_database'
]):
os
.
unlink
(
config
[
'proxy_database'
])
proxy
=
subprocess
.
Popen
([
config
[
'slapproxy_binary'
],
config
[
'slapos_config'
]],
close_fds
=
True
,
preexec_fn
=
os
.
setsid
)
process_group_pid_set
.
add
(
proxy
.
pid
)
# XXX: dirty, giving some time for proxy to being able to accept
# connections
time
.
sleep
(
10
)
slap
=
slapos
.
slap
.
slap
()
slap
.
initializeConnection
(
config
[
'master_url'
])
# register software profile
self
.
software_profile
=
config
[
'custom_profile_path'
]
slap
.
registerSupply
()
.
supply
(
self
.
software_profile
,
computer_guid
=
config
[
'computer_id'
])
computer
=
slap
.
registerComputer
(
config
[
'computer_id'
])
# create partition and configure computer
partition_reference
=
config
[
'partition_reference'
]
partition_path
=
os
.
path
.
join
(
config
[
'instance_root'
],
partition_reference
)
if
not
os
.
path
.
exists
(
partition_path
):
os
.
mkdir
(
partition_path
)
os
.
chmod
(
partition_path
,
0750
)
computer
.
updateConfiguration
(
xml_marshaller
.
dumps
({
'address'
:
config
[
'ipv4_address'
],
'instance_root'
:
config
[
'instance_root'
],
'netmask'
:
'255.255.255.255'
,
'partition_list'
:
[{
'address_list'
:
[{
'addr'
:
config
[
'ipv4_address'
],
'netmask'
:
'255.255.255.255'
},
{
'addr'
:
config
[
'ipv6_address'
],
'netmask'
:
'ffff:ffff:ffff::'
},
],
'path'
:
partition_path
,
'reference'
:
partition_reference
,
'tap'
:
{
'name'
:
partition_reference
},
}
],
'reference'
:
config
[
'computer_id'
],
'software_root'
:
config
[
'software_root'
]}))
def
runSoftwareRelease
(
self
,
config
,
environment
,
process_group_pid_set
=
None
):
print
"SlapOSControler.runSoftwareRelease"
while
True
:
cpu_count
=
os
.
sysconf
(
"SC_NPROCESSORS_ONLN"
)
os
.
putenv
(
'MAKEFLAGS'
,
'-j
%
s'
%
cpu_count
)
os
.
environ
[
'PATH'
]
=
environment
[
'PATH'
]
stdout
=
open
(
os
.
path
.
join
(
config
[
'instance_root'
],
'.runSoftwareRelease_out'
),
'w+'
)
stderr
=
open
(
os
.
path
.
join
(
config
[
'instance_root'
],
'.runSoftwareRelease_err'
),
'w+'
)
slapgrid
=
subprocess
.
Popen
([
config
[
'slapgrid_software_binary'
],
'-v'
,
'-c'
,
#'--buildout-parameter',"'-U -N' -o",
config
[
'slapos_config'
]],
stdout
=
stdout
,
stderr
=
stderr
,
close_fds
=
True
,
preexec_fn
=
os
.
setsid
)
process_group_pid_set
.
add
(
slapgrid
.
pid
)
slapgrid
.
wait
()
stdout
.
seek
(
0
)
stderr
.
seek
(
0
)
process_group_pid_set
.
remove
(
slapgrid
.
pid
)
status_dict
=
{
'status_code'
:
slapgrid
.
returncode
,
'stdout'
:
stdout
.
read
(),
'stderr'
:
stderr
.
read
()}
stdout
.
close
()
stderr
.
close
()
return
status_dict
def
runComputerPartition
(
self
,
config
,
process_group_pid_set
=
None
):
print
"SlapOSControler.runSoftwareRelease"
slap
=
slapos
.
slap
.
slap
()
slap
.
registerOpenOrder
()
.
request
(
self
.
software_profile
,
partition_reference
=
'testing partition'
,
partition_parameter_kw
=
config
[
'instance_dict'
])
slapgrid
=
subprocess
.
Popen
([
config
[
'slapgrid_partition_binary'
],
config
[
'slapos_config'
],
'-c'
,
'-v'
],
close_fds
=
True
,
preexec_fn
=
os
.
setsid
)
process_group_pid_set
.
add
(
slapgrid
.
pid
)
slapgrid
.
wait
()
process_group_pid_set
.
remove
(
slapgrid
.
pid
)
if
slapgrid
.
returncode
!=
0
:
raise
ValueError
(
'Slapgrid instance failed'
)
slapos/erp5.recipe.testnode/src/erp5/recipe/testnode/Updater.py
0 → 100644
View file @
43653c40
import
os
,
sys
,
subprocess
,
re
,
threading
from
testnode
import
SubprocessError
_format_command_search
=
re
.
compile
(
"[[
\\
s $({?*
\\
`#~';<>&|]"
)
.
search
_format_command_escape
=
lambda
s
:
"'
%
s'"
%
r"'\''"
.
join
(
s
.
split
(
"'"
))
def
format_command
(
*
args
,
**
kw
):
cmdline
=
[]
for
k
,
v
in
sorted
(
kw
.
items
()):
if
_format_command_search
(
v
):
v
=
_format_command_escape
(
v
)
cmdline
.
append
(
'
%
s=
%
s'
%
(
k
,
v
))
for
v
in
args
:
if
_format_command_search
(
v
):
v
=
_format_command_escape
(
v
)
cmdline
.
append
(
v
)
return
' '
.
join
(
cmdline
)
def
subprocess_capture
(
p
,
quiet
=
False
):
def
readerthread
(
input
,
output
,
buffer
):
while
True
:
data
=
input
.
readline
()
if
not
data
:
break
output
(
data
)
buffer
.
append
(
data
)
if
p
.
stdout
:
stdout
=
[]
output
=
quiet
and
(
lambda
data
:
None
)
or
sys
.
stdout
.
write
stdout_thread
=
threading
.
Thread
(
target
=
readerthread
,
args
=
(
p
.
stdout
,
output
,
stdout
))
stdout_thread
.
setDaemon
(
True
)
stdout_thread
.
start
()
if
p
.
stderr
:
stderr
=
[]
stderr_thread
=
threading
.
Thread
(
target
=
readerthread
,
args
=
(
p
.
stderr
,
sys
.
stderr
.
write
,
stderr
))
stderr_thread
.
setDaemon
(
True
)
stderr_thread
.
start
()
if
p
.
stdout
:
stdout_thread
.
join
()
if
p
.
stderr
:
stderr_thread
.
join
()
p
.
wait
()
return
(
p
.
stdout
and
''
.
join
(
stdout
),
p
.
stderr
and
''
.
join
(
stderr
))
GIT_TYPE
=
'git'
SVN_TYPE
=
'svn'
class
Updater
(
object
):
_git_cache
=
{}
realtime_output
=
True
stdin
=
file
(
os
.
devnull
)
def
__init__
(
self
,
repository_path
,
revision
=
None
,
git_binary
=
None
):
self
.
revision
=
revision
self
.
_path_list
=
[]
self
.
repository_path
=
repository_path
self
.
git_binary
=
git_binary
def
getRepositoryPath
(
self
):
return
self
.
repository_path
def
getRepositoryType
(
self
):
try
:
return
self
.
repository_type
except
AttributeError
:
# guess the type of repository we have
if
os
.
path
.
isdir
(
os
.
path
.
join
(
self
.
getRepositoryPath
(),
'.git'
)):
repository_type
=
GIT_TYPE
elif
os
.
path
.
isdir
(
os
.
path
.
join
(
self
.
getRepositoryPath
(),
'.svn'
)):
repository_type
=
SVN_TYPE
else
:
raise
NotImplementedError
self
.
repository_type
=
repository_type
return
repository_type
def
deletePycFiles
(
self
,
path
):
"""Delete *.pyc files so that deleted/moved files can not be imported"""
for
path
,
dir_list
,
file_list
in
os
.
walk
(
path
):
for
file
in
file_list
:
if
file
[
-
4
:]
in
(
'.pyc'
,
'.pyo'
):
# allow several processes clean the same folder at the same time
try
:
os
.
remove
(
os
.
path
.
join
(
path
,
file
))
except
OSError
,
e
:
if
e
.
errno
!=
errno
.
ENOENT
:
raise
def
spawn
(
self
,
*
args
,
**
kw
):
quiet
=
kw
.
pop
(
'quiet'
,
False
)
env
=
kw
and
dict
(
os
.
environ
,
**
kw
)
or
None
command
=
format_command
(
*
args
,
**
kw
)
print
'
\n
$ '
+
command
sys
.
stdout
.
flush
()
p
=
subprocess
.
Popen
(
args
,
stdin
=
self
.
stdin
,
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
PIPE
,
env
=
env
,
cwd
=
self
.
getRepositoryPath
())
if
self
.
realtime_output
:
stdout
,
stderr
=
subprocess_capture
(
p
,
quiet
)
else
:
stdout
,
stderr
=
p
.
communicate
()
if
not
quiet
:
sys
.
stdout
.
write
(
stdout
)
sys
.
stderr
.
write
(
stderr
)
result
=
dict
(
status_code
=
p
.
returncode
,
command
=
command
,
stdout
=
stdout
,
stderr
=
stderr
)
if
p
.
returncode
:
raise
SubprocessError
(
result
)
return
result
def
_git
(
self
,
*
args
,
**
kw
):
return
self
.
spawn
(
self
.
git_binary
,
*
args
,
**
kw
)[
'stdout'
]
.
strip
()
def
_git_find_rev
(
self
,
ref
):
try
:
return
self
.
_git_cache
[
ref
]
except
KeyError
:
if
os
.
path
.
exists
(
'.git/svn'
):
r
=
self
.
_git
(
'svn'
,
'find-rev'
,
ref
)
assert
r
self
.
_git_cache
[
ref
[
0
]
!=
'r'
and
'r
%
u'
%
int
(
r
)
or
r
]
=
ref
else
:
r
=
self
.
_git
(
'rev-list'
,
'--topo-order'
,
'--count'
,
ref
),
ref
self
.
_git_cache
[
ref
]
=
r
return
r
def
getRevision
(
self
,
*
path_list
):
if
not
path_list
:
path_list
=
self
.
_path_list
if
self
.
getRepositoryType
()
==
GIT_TYPE
:
h
=
self
.
_git
(
'log'
,
'-1'
,
'--format=
%
H'
,
'--'
,
*
path_list
)
return
self
.
_git_find_rev
(
h
)
elif
self
.
getRepositoryType
()
==
SVN_TYPE
:
stdout
=
self
.
spawn
(
'svn'
,
'info'
,
*
path_list
)[
'stdout'
]
return
str
(
max
(
map
(
int
,
SVN_CHANGED_REV
.
findall
(
stdout
))))
raise
NotImplementedError
def
checkout
(
self
,
*
path_list
):
if
not
path_list
:
path_list
=
'.'
,
revision
=
self
.
revision
if
self
.
getRepositoryType
()
==
GIT_TYPE
:
# edit .git/info/sparse-checkout if you want sparse checkout
if
revision
:
if
type
(
revision
)
is
str
:
h
=
self
.
_git_find_rev
(
'r'
+
revision
)
else
:
h
=
revision
[
1
]
if
h
!=
self
.
_git
(
'rev-parse'
,
'HEAD'
):
self
.
deletePycFiles
(
'.'
)
self
.
_git
(
'reset'
,
'--merge'
,
h
)
else
:
self
.
deletePycFiles
(
'.'
)
if
os
.
path
.
exists
(
'.git/svn'
):
self
.
_git
(
'svn'
,
'rebase'
)
else
:
self
.
_git
(
'pull'
,
'--ff-only'
)
self
.
revision
=
self
.
_git_find_rev
(
self
.
_git
(
'rev-parse'
,
'HEAD'
))
elif
self
.
getRepositoryType
()
==
SVN_TYPE
:
# following code allows sparse checkout
def
svn_mkdirs
(
path
):
path
=
os
.
path
.
dirname
(
path
)
if
path
and
not
os
.
path
.
isdir
(
path
):
svn_mkdirs
(
path
)
self
.
spawn
(
*
(
args
+
[
'--depth=empty'
,
path
]))
for
path
in
path_list
:
args
=
[
'svn'
,
'up'
,
'--force'
,
'--non-interactive'
]
if
revision
:
args
.
append
(
'-r
%
s'
%
revision
)
svn_mkdirs
(
path
)
args
+=
'--set-depth=infinity'
,
path
self
.
deletePycFiles
(
path
)
try
:
status_dict
=
self
.
spawn
(
*
args
)
except
SubprocessError
,
e
:
if
'cleanup'
not
in
e
.
stderr
:
raise
self
.
spawn
(
'svn'
,
'cleanup'
,
path
)
status_dict
=
self
.
spawn
(
*
args
)
if
not
revision
:
self
.
revision
=
revision
=
SVN_UP_REV
.
findall
(
status_dict
[
'stdout'
]
.
splitlines
()[
-
1
])[
0
]
else
:
raise
NotImplementedError
self
.
_path_list
+=
path_list
slapos/erp5.recipe.testnode/src/erp5/recipe/testnode/__init__.py
0 → 100644
View file @
43653c40
##############################################################################
#
# Copyright (c) 2010 Vifib SARL and Contributors. All Rights Reserved.
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsibility of assessing all potential
# consequences resulting from its eventual inadequacies and bugs
# End users who are looking for a ready-to-use solution with commercial
# guarantees and support are strongly adviced to contract a Free Software
# Service Company
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 3
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
##############################################################################
from
slapos.lib.recipe.BaseSlapRecipe
import
BaseSlapRecipe
import
os
import
pkg_resources
import
zc.buildout
import
zc.recipe.egg
import
sys
CONFIG
=
dict
(
proxy_port
=
'5000'
,
computer_id
=
'COMPUTER'
,
partition_reference
=
'test0'
,
)
class
Recipe
(
BaseSlapRecipe
):
def
__init__
(
self
,
buildout
,
name
,
options
):
self
.
egg
=
zc
.
recipe
.
egg
.
Egg
(
buildout
,
options
[
'recipe'
],
options
)
BaseSlapRecipe
.
__init__
(
self
,
buildout
,
name
,
options
)
def
installSlapOs
(
self
):
CONFIG
[
'slapos_directory'
]
=
self
.
createDataDirectory
(
'slapos'
)
CONFIG
[
'working_directory'
]
=
self
.
createDataDirectory
(
'testnode'
)
CONFIG
[
'software_root'
]
=
os
.
path
.
join
(
CONFIG
[
'slapos_directory'
],
'software'
)
CONFIG
[
'instance_root'
]
=
os
.
path
.
join
(
CONFIG
[
'slapos_directory'
],
'instance'
)
CONFIG
[
'proxy_database'
]
=
os
.
path
.
join
(
CONFIG
[
'slapos_directory'
],
'proxy.db'
)
CONFIG
[
'proxy_host'
]
=
self
.
getLocalIPv4Address
()
CONFIG
[
'master_url'
]
=
'http://
%
s:
%
s'
%
(
CONFIG
[
'proxy_host'
],
CONFIG
[
'proxy_port'
])
self
.
_createDirectory
(
CONFIG
[
'software_root'
])
self
.
_createDirectory
(
CONFIG
[
'instance_root'
])
CONFIG
[
'slapos_config'
]
=
self
.
createConfigurationFile
(
'slapos.cfg'
,
self
.
substituteTemplate
(
pkg_resources
.
resource_filename
(
__name__
,
'template/slapos.cfg.in'
),
CONFIG
))
self
.
path_list
.
append
(
CONFIG
[
'slapos_config'
])
def
setupRunningWrapper
(
self
):
self
.
path_list
.
extend
(
zc
.
buildout
.
easy_install
.
scripts
([(
'testnode'
,
__name__
+
'.testnode'
,
'run'
)],
self
.
ws
,
sys
.
executable
,
self
.
wrapper_directory
,
arguments
=
[
dict
(
computer_id
=
CONFIG
[
'computer_id'
],
instance_dict
=
eval
(
self
.
parameter_dict
.
get
(
'instance_dict'
,
'{}'
)),
instance_root
=
CONFIG
[
'instance_root'
],
ipv4_address
=
self
.
getLocalIPv4Address
(),
ipv6_address
=
self
.
getGlobalIPv6Address
(),
master_url
=
CONFIG
[
'master_url'
],
profile_path
=
self
.
parameter_dict
[
'profile_path'
],
proxy_database
=
CONFIG
[
'proxy_database'
],
proxy_port
=
CONFIG
[
'proxy_port'
],
slapgrid_partition_binary
=
self
.
options
[
'slapgrid_partition_binary'
],
slapgrid_software_binary
=
self
.
options
[
'slapgrid_software_binary'
],
slapos_config
=
CONFIG
[
'slapos_config'
],
slapproxy_binary
=
self
.
options
[
'slapproxy_binary'
],
git_binary
=
self
.
options
[
'git_binary'
],
software_root
=
CONFIG
[
'software_root'
],
working_directory
=
CONFIG
[
'working_directory'
],
vcs_repository
=
self
.
parameter_dict
.
get
(
'vcs_repository'
),
node_quantity
=
self
.
parameter_dict
.
get
(
'node_quantity'
,
'1'
),
branch
=
self
.
parameter_dict
.
get
(
'branch'
,
None
),
test_suite_master_url
=
self
.
parameter_dict
.
get
(
'test_suite_master_url'
,
None
),
test_suite_name
=
self
.
parameter_dict
.
get
(
'test_suite_name'
),
test_suite_title
=
self
.
parameter_dict
.
get
(
'test_suite_title'
),
bin_directory
=
self
.
bin_directory
,
foo
=
'bar'
,
# botenvironemnt is splittable string of key=value to substitute
# environment of running bot
bot_environment
=
self
.
parameter_dict
.
get
(
'bot_environment'
,
''
),
partition_reference
=
CONFIG
[
'partition_reference'
],
environment
=
dict
(
PATH
=
os
.
environ
[
'PATH'
]),
)
]))
def
installLocalSvn
(
self
):
svn_dict
=
dict
(
svn_binary
=
self
.
options
[
'svn_binary'
])
svn_dict
.
update
(
self
.
parameter_dict
)
self
.
_writeExecutable
(
os
.
path
.
join
(
self
.
bin_directory
,
'svn'
),
"""
\
#!/bin/sh
%(svn_binary)
s --username
%(svn_username)
s --password
%(svn_password)
s
\
--non-interactive --trust-server-cert --no-auth-cache "$@" """
%
svn_dict
)
svnversion
=
os
.
path
.
join
(
self
.
bin_directory
,
'svnversion'
)
if
os
.
path
.
lexists
(
svnversion
):
os
.
unlink
(
svnversion
)
os
.
symlink
(
self
.
options
[
'svnversion_binary'
],
svnversion
)
def
installLocalGit
(
self
):
git_dict
=
dict
(
git_binary
=
self
.
options
[
'git_binary'
])
git_dict
.
update
(
self
.
parameter_dict
)
double_slash_end_position
=
1
# XXX, this should be provided by slapos
print
"bin_directory :
%
r"
%
self
.
bin_directory
home_directory
=
os
.
path
.
join
(
*
os
.
path
.
split
(
self
.
bin_directory
)[
0
:
-
1
])
print
"home_directory :
%
r"
%
home_directory
git_dict
.
setdefault
(
"git_server_name"
,
"git.erp5.org"
)
if
git_dict
.
get
(
'vcs_username'
,
None
)
is
not
None
:
netrc_file
=
open
(
os
.
path
.
join
(
home_directory
,
'.netrc'
),
'w'
)
netrc_file
.
write
(
"""
machine
%(git_server_name)
s
login
%(vcs_username)
s
password
%(vcs_password)
s"""
%
git_dict
)
netrc_file
.
close
()
def
installLocalRepository
(
self
):
if
self
.
parameter_dict
.
get
(
'vcs_repository'
)
.
endswith
(
'git'
):
self
.
installLocalGit
()
else
:
self
.
installLocalSvn
()
def
installLocalZip
(
self
):
zip
=
os
.
path
.
join
(
self
.
bin_directory
,
'zip'
)
if
os
.
path
.
lexists
(
zip
):
os
.
unlink
(
zip
)
os
.
symlink
(
self
.
options
[
'zip_binary'
],
zip
)
def
installLocalPython
(
self
):
"""Installs local python fully featured with eggs"""
self
.
path_list
.
extend
(
zc
.
buildout
.
easy_install
.
scripts
([],
self
.
ws
,
sys
.
executable
,
self
.
bin_directory
,
scripts
=
None
,
interpreter
=
'python'
))
def
installLocalRunUnitTest
(
self
):
link
=
os
.
path
.
join
(
self
.
bin_directory
,
'runUnitTest'
)
destination
=
os
.
path
.
join
(
CONFIG
[
'instance_root'
],
CONFIG
[
'partition_reference'
],
'bin'
,
'runUnitTest'
)
if
os
.
path
.
lexists
(
link
):
if
not
os
.
readlink
(
link
)
!=
destination
:
os
.
unlink
(
link
)
if
not
os
.
path
.
lexists
(
link
):
os
.
symlink
(
destination
,
link
)
def
_install
(
self
):
self
.
requirements
,
self
.
ws
=
self
.
egg
.
working_set
([
__name__
])
self
.
path_list
=
[]
self
.
installSlapOs
()
self
.
setupRunningWrapper
()
self
.
installLocalRepository
()
self
.
installLocalZip
()
self
.
installLocalPython
()
self
.
installLocalRunUnitTest
()
return
self
.
path_list
slapos/erp5.recipe.testnode/src/erp5/recipe/testnode/template/slapos.cfg.in
0 → 100644
View file @
43653c40
[slapos]
software_root = %(software_root)s
instance_root = %(instance_root)s
master_url = %(master_url)s
computer_id = %(computer_id)s
[slapproxy]
host = %(proxy_host)s
port = %(proxy_port)s
database_uri = %(proxy_database)s
slapos/erp5.recipe.testnode/src/erp5/recipe/testnode/testnode.py
0 → 100644
View file @
43653c40
from
xml_marshaller
import
xml_marshaller
import
os
,
xmlrpclib
,
time
,
imp
from
glob
import
glob
import
signal
import
slapos.slap
import
subprocess
import
sys
import
socket
import
pprint
from
SlapOSControler
import
SlapOSControler
class
SubprocessError
(
EnvironmentError
):
def
__init__
(
self
,
status_dict
):
self
.
status_dict
=
status_dict
def
__getattr__
(
self
,
name
):
return
self
.
status_dict
[
name
]
def
__str__
(
self
):
return
'Error
%
i'
%
self
.
status_code
from
Updater
import
Updater
process_group_pid_set
=
set
()
process_pid_file_list
=
[]
process_command_list
=
[]
def
sigterm_handler
(
signal
,
frame
):
for
pgpid
in
process_group_pid_set
:
try
:
os
.
killpg
(
pgpid
,
signal
.
SIGTERM
)
except
:
pass
for
pid_file
in
process_pid_file_list
:
try
:
os
.
kill
(
int
(
open
(
pid_file
)
.
read
()
.
strip
()),
signal
.
SIGTERM
)
except
:
pass
for
p
in
process_command_list
:
try
:
subprocess
.
call
(
p
)
except
:
pass
sys
.
exit
(
1
)
signal
.
signal
(
signal
.
SIGTERM
,
sigterm_handler
)
def
safeRpcCall
(
function
,
*
args
):
retry
=
64
while
True
:
try
:
return
function
(
*
args
)
except
(
socket
.
error
,
xmlrpclib
.
ProtocolError
),
e
:
print
>>
sys
.
stderr
,
e
pprint
.
pprint
(
args
,
file
(
function
.
_Method__name
,
'w'
))
time
.
sleep
(
retry
)
retry
+=
retry
>>
1
slapos_controler
=
None
def
run
(
args
):
config
=
args
[
0
]
slapgrid
=
None
branch
=
config
.
get
(
'branch'
,
None
)
supervisord_pid_file
=
os
.
path
.
join
(
config
[
'instance_root'
],
'var'
,
'run'
,
'supervisord.pid'
)
subprocess
.
check_call
([
config
[
'git_binary'
],
"config"
,
"--global"
,
"http.sslVerify"
,
"false"
])
previous_revision
=
None
run_software
=
True
# find what will be the path of the repository
repository_name
=
config
[
'vcs_repository'
]
.
split
(
'/'
)[
-
1
]
.
split
(
'.'
)[
0
]
repository_path
=
os
.
path
.
join
(
config
[
'working_directory'
],
repository_name
)
config
[
'repository_path'
]
=
repository_path
sys
.
path
.
append
(
repository_path
)
# Write our own software.cfg to use the local repository
custom_profile_path
=
os
.
path
.
join
(
config
[
'working_directory'
],
'software.cfg'
)
config
[
'custom_profile_path'
]
=
custom_profile_path
# create a profile in order to use the repository we already have
custom_profile
=
open
(
custom_profile_path
,
'w'
)
profile_content
=
"""
[buildout]
extends =
%(software_config_path)
s
[
%(repository_name)
s]
repository =
%(repository_path)
s
"""
%
{
'software_config_path'
:
os
.
path
.
join
(
repository_path
,
config
[
'profile_path'
]),
'repository_name'
:
repository_name
,
'repository_path'
:
repository_path
}
if
branch
is
not
None
:
profile_content
+=
"
\n
branch =
%
s"
%
branch
custom_profile
.
write
(
profile_content
)
custom_profile
.
close
()
retry_software
=
False
try
:
while
True
:
# kill processes from previous loop if any
try
:
for
pgpid
in
process_group_pid_set
:
try
:
os
.
killpg
(
pgpid
,
signal
.
SIGTERM
)
except
:
pass
process_group_pid_set
.
clear
()
# Make sure we have local repository
if
not
os
.
path
.
exists
(
repository_path
):
parameter_list
=
[
config
[
'git_binary'
],
'clone'
,
config
[
'vcs_repository'
]]
if
branch
is
not
None
:
parameter_list
.
extend
([
'-b'
,
branch
])
parameter_list
.
append
(
repository_path
)
subprocess
.
check_call
(
parameter_list
)
# XXX this looks like to not wait the end of the command
# Make sure we have local repository
updater
=
Updater
(
repository_path
,
git_binary
=
config
[
'git_binary'
])
updater
.
checkout
()
revision
=
updater
.
getRevision
()
if
previous_revision
==
revision
:
time
.
sleep
(
120
)
if
not
(
retry_software
):
continue
retry_software
=
False
previous_revision
=
revision