Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
erp5
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
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Xiaowu Zhang
erp5
Commits
bac6a51f
Commit
bac6a51f
authored
Jul 22, 2011
by
Łukasz Nowak
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Convert from recipe to tool.
Use argparse and configparser in order to being able to pass parameters.
parent
e813bca5
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
69 additions
and
121 deletions
+69
-121
erp5/util/testnode/__init__.py
erp5/util/testnode/__init__.py
+68
-119
erp5/util/testnode/testnode.py
erp5/util/testnode/testnode.py
+1
-2
No files found.
erp5/util/testnode/__init__.py
View file @
bac6a51f
##############################################################################
#
# Copyright (c) 2010
Vifib SARL
and Contributors. All Rights Reserved.
# Copyright (c) 2010
Nexedi SA
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 advi
c
ed to contract a Free Software
# guarantees and support are strongly advi
s
ed to contract a Free Software
# Service Company
#
# This program is Free Software; you can redistribute it and/or
...
...
@@ -24,136 +24,85 @@
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
##############################################################################
from
slapos.recipe.librecipe
import
BaseSlapRecipe
import
ConfigParser
import
argparse
import
os
import
pkg_resources
import
zc.buildout
import
zc.recipe.egg
import
sys
import
testnode
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'
],
def
main
(
*
args
):
parser
=
argparse
.
ArgumentParser
()
parser
.
add_argument
(
"configuration_file"
,
nargs
=
1
,
type
=
argparse
.
FileType
(),
help
=
"Configuration file."
)
if
args
:
parsed_argument
=
parser
.
parse_args
(
list
(
args
))
else
:
parsed_argument
=
parser
.
parse_args
()
config
=
ConfigParser
.
SafeConfigParser
()
config
.
readfp
(
parsed_argument
.
configuration_file
[
0
])
def
geto
(
o
):
return
config
.
get
(
'testnode'
,
o
)
CONFIG
[
'slapos_directory'
]
=
geto
(
'slapos_directory'
)
CONFIG
[
'working_directory'
]
=
geto
(
'working_directory'
)
for
d
in
CONFIG
[
'slapos_directory'
],
CONFIG
[
'working_directory'
]:
if
not
os
.
path
.
isdir
(
d
):
raise
ValueError
(
'Directory %r does not exists.'
%
d
)
CONFIG
[
'software_root'
]
=
os
.
path
.
join
(
CONFIG
[
'slapos_directory'
],
'software'
)
CONFIG
[
'instance_root'
]
=
os
.
path
.
join
(
CONFIG
[
'slapos_directory'
],
CONFIG
[
'instance_root'
]
=
os
.
path
.
join
(
CONFIG
[
'slapos_directory'
],
'instance'
)
CONFIG
[
'proxy_database'
]
=
os
.
path
.
join
(
CONFIG
[
'slapos_directory'
],
for
d
in
CONFIG
[
'software_root'
],
CONFIG
[
'instance_root'
]:
if
not
os
.
path
.
lexists
(
d
):
os
.
mkdir
(
d
)
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_host'
]
=
geto
(
'proxy_host'
)
CONFIG
[
'proxy_port'
]
=
geto
(
'proxy_port'
)
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_list
=
eval
(
self
.
parameter_dict
.
get
(
'vcs_repository_list'
),),
node_quantity
=
self
.
parameter_dict
.
get
(
'node_quantity'
,
'1'
),
test_suite_master_url
=
self
.
parameter_dict
.
get
(
'test_suite_master_url'
,
None
),
test_suite
=
self
.
parameter_dict
.
get
(
'test_suite'
),
test_suite_title
=
self
.
parameter_dict
.
get
(
'test_suite_title'
),
test_node_title
=
self
.
parameter_dict
.
get
(
'test_node_title'
),
project_title
=
self
.
parameter_dict
.
get
(
'project_title'
),
bin_directory
=
self
.
bin_directory
,
# 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'
]),
vcs_authentication_list
=
eval
(
self
.
parameter_dict
.
get
(
'vcs_authentication_list'
,
'None'
)),
)
]))
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_authentication_list'
,
None
)
is
not
None
:
vcs_authentication_list
=
eval
(
git_dict
[
'vcs_authentication_list'
])
netrc_file
=
open
(
os
.
path
.
join
(
home_directory
,
'.netrc'
),
'w'
)
for
vcs_authentication_dict
in
vcs_authentication_list
:
netrc_file
.
write
(
"""
machine %(host)s
login %(user_name)s
password %(password)s
"""
%
vcs_authentication_dict
)
netrc_file
.
close
()
def
installLocalRepository
(
self
):
self
.
installLocalGit
()
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
)
slapos_config
=
pkg_resources
.
resource_string
(
'erp5.util.testnode'
,
'template/slapos.cfg.in'
)
slapos_config
=
slapos_config
%
CONFIG
CONFIG
[
'slapos_config'
]
=
os
.
path
.
join
(
CONFIG
[
'slapos_directory'
],
'slapos.cfg'
)
open
(
CONFIG
[
'slapos_config'
],
'w'
).
write
(
slapos_config
)
CONFIG
[
'git_binary'
]
=
geto
(
'git_binary'
)
CONFIG
[
'zip_binary'
]
=
geto
(
'zip_binary'
)
CONFIG
[
'runUnitTest'
]
=
os
.
path
.
join
(
CONFIG
[
'instance_root'
],
CONFIG
[
'partition_reference'
],
'bin'
,
'runUnitTest'
)
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'
))
# generate vcs_repository_list
vcs_repository_list
=
[]
for
section
in
config
.
sections
():
if
section
.
startswith
(
'vcs_repository'
):
vcs_repository_list
.
append
(
dict
(
config
.
items
(
section
)))
CONFIG
[
'vcs_repository_list'
]
=
vcs_repository_list
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
)
CONFIG
[
'profile_path'
]
=
geto
(
'profile_path'
)
CONFIG
[
'test_suite_title'
]
=
geto
(
'test_suite_title'
)
CONFIG
[
'test_node_title'
]
=
geto
(
'test_node_title'
)
CONFIG
[
'test_suite'
]
=
geto
(
'test_suite'
)
CONFIG
[
'project_title'
]
=
geto
(
'project_title'
)
CONFIG
[
'node_quantity'
]
=
geto
(
'node_quantity'
)
CONFIG
[
'ipv4_address'
]
=
geto
(
'ipv4_address'
)
CONFIG
[
'ipv6_address'
]
=
geto
(
'ipv6_address'
)
CONFIG
[
'test_suite_master_url'
]
=
geto
(
'test_suite_master_url'
)
CONFIG
[
'slapgrid_partition_binary'
]
=
geto
(
'slapgrid_partition_binary'
)
CONFIG
[
'slapgrid_software_binary'
]
=
geto
(
'slapgrid_software_binary'
)
bot_environment
=
{}
if
'bot_environment'
in
config
.
sections
():
bot_environment
=
dict
(
config
.
items
(
'bot_environment'
))
CONFIG
[
'bot_environment'
]
=
bot_environment
environment
=
{}
if
'environment'
in
config
.
sections
():
environment
=
dict
(
config
.
items
(
'environment'
))
CONFIG
[
'environment'
]
=
environment
def
_install
(
self
):
self
.
requirements
,
self
.
ws
=
self
.
egg
.
working_set
()
self
.
path_list
=
[]
self
.
installSlapOs
()
self
.
setupRunningWrapper
()
self
.
installLocalRepository
()
self
.
installLocalZip
()
self
.
installLocalPython
()
self
.
installLocalRunUnitTest
()
return
self
.
path_list
testnode
.
run
(
CONFIG
)
erp5/util/testnode/testnode.py
View file @
bac6a51f
...
...
@@ -67,8 +67,7 @@ def getInputOutputFileList(config, command_name):
slapos_controler
=
None
def
run
(
args
):
config
=
args
[
0
]
def
run
(
config
):
slapgrid
=
None
supervisord_pid_file
=
os
.
path
.
join
(
config
[
'instance_root'
],
'var'
,
'run'
,
'supervisord.pid'
)
...
...
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