Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
slapos.toolbox
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
Xavier Thompson
slapos.toolbox
Commits
5f34b3f6
Commit
5f34b3f6
authored
Jul 25, 2013
by
Marco Mariani
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
some pep8 love
parent
17a77af3
Changes
7
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
272 additions
and
133 deletions
+272
-133
slapos/runner/__init__.py
slapos/runner/__init__.py
+8
-4
slapos/runner/decorators.py
slapos/runner/decorators.py
+0
-1
slapos/runner/fileBrowser.py
slapos/runner/fileBrowser.py
+8
-7
slapos/runner/gittools.py
slapos/runner/gittools.py
+11
-4
slapos/runner/runnertest.py
slapos/runner/runnertest.py
+69
-54
slapos/runner/utils.py
slapos/runner/utils.py
+100
-48
slapos/runner/views.py
slapos/runner/views.py
+76
-15
No files found.
slapos/runner/__init__.py
View file @
5f34b3f6
...
...
@@ -21,8 +21,7 @@ class Parser(OptionParser):
"""
Initialize all possible options.
"""
OptionParser
.
__init__
(
self
,
usage
=
usage
,
version
=
version
,
option_list
=
[
option_list
=
[
Option
(
"-l"
,
"--log_file"
,
help
=
"The path to the log file used by the script."
,
type
=
str
),
...
...
@@ -38,7 +37,10 @@ class Parser(OptionParser):
default
=
False
,
action
=
"store_true"
,
help
=
"Debug mode."
),
])
]
OptionParser
.
__init__
(
self
,
usage
=
usage
,
version
=
version
,
option_list
=
option_list
)
def
check_args
(
self
):
"""
...
...
@@ -50,6 +52,7 @@ class Parser(OptionParser):
return
options
,
args
[
0
]
class
Config
:
def
__init__
(
self
):
self
.
configuration_file_path
=
None
...
...
@@ -125,6 +128,7 @@ def run():
sys
.
exit
(
return_code
)
def
serve
(
config
):
from
views
import
app
from
werkzeug.contrib.fixers
import
ProxyFix
...
...
@@ -134,7 +138,7 @@ def serve(config):
app
.
config
.
update
(
software_log
=
config
.
software_root
.
rstrip
(
'/'
)
+
'.log'
,
instance_log
=
config
.
instance_root
.
rstrip
(
'/'
)
+
'.log'
,
workspace
=
workdir
,
workspace
=
workdir
,
software_link
=
software_link
,
instance_profile
=
'instance.cfg'
,
software_profile
=
'software.cfg'
,
...
...
slapos/runner/decorators.py
View file @
5f34b3f6
...
...
@@ -11,4 +11,3 @@ def as_json(f):
def
inner
(
*
args
,
**
kwargs
):
return
Response
(
json
.
dumps
(
f
(
*
args
,
**
kwargs
)),
mimetype
=
'application/json'
)
return
inner
slapos/runner/fileBrowser.py
View file @
5f34b3f6
...
...
@@ -31,14 +31,14 @@ class FileBrowser(object):
html
=
'var gsdirs = [], gsfiles = [];'
dir
=
urllib
.
unquote
(
dir
)
#
'dir' is used below. XXX should not shadow a builtin name
#
XXX-Marco 'dir' and 'all' should not shadow builtin names
realdir
=
realpath
(
self
.
config
,
dir
)
if
not
realdir
:
raise
NameError
(
'Could not load directory %s: Permission denied'
%
dir
)
ldir
=
sorted
(
os
.
listdir
(
realdir
),
key
=
str
.
lower
)
for
f
in
ldir
:
if
f
.
startswith
(
'.'
)
and
not
all
:
#
do not display this file/folder
if
f
.
startswith
(
'.'
)
and
not
all
:
#
do not display this file/folder
continue
ff
=
os
.
path
.
join
(
dir
,
f
)
realfile
=
os
.
path
.
join
(
realdir
,
f
)
...
...
@@ -61,7 +61,6 @@ class FileBrowser(object):
ff + '", "
0
", "' + md5sum + '", "
dir
", "' + mdate + '"));'
return html
def makeDirectory(self, dir, filename):
"""Create a directory"""
realdir = self._realdir(dir)
...
...
@@ -72,7 +71,6 @@ class FileBrowser(object):
else:
return '{result:
\
'
0
\
'
}'
def makeFile(self, dir, filename):
"""Create a file in a directory dir taken"""
realdir = self._realdir(dir)
...
...
@@ -85,17 +83,19 @@ class FileBrowser(object):
def deleteItem(self, dir, files):
"""Delete a list of files or directories"""
# XXX-Marco do not shadow 'dir'
realdir = self._realdir(dir)
lfiles = urllib.unquote(files).split(',,,')
try:
# XXX-Marco do not shadow 'file'
for file in lfiles:
file = os.path.join(realdir, file)
if not os.path.exists(file):
continue
#
silent skip file....
continue
#
silent skip file....
details = file.split('/')
last = details[-1]
if last and last.startswith('.'):
continue
#
cannot delete this file/directory, to prevent security
continue
#
cannot delete this file/directory, to prevent security
if os.path.isdir(file):
shutil.rmtree(file)
else:
...
...
@@ -109,6 +109,7 @@ class FileBrowser(object):
realdir = self._realdir(dir)
lfiles = urllib.unquote(files).split(',,,')
try:
# XXX-Marco do not shadow 'file'
for file in lfiles:
realfile = realpath(self.config, file)
if not realfile:
...
...
slapos/runner/gittools.py
View file @
5f34b3f6
...
...
@@ -29,7 +29,7 @@ def cloneRepo(data):
json
=
""
try
:
if
os
.
path
.
exists
(
workDir
)
and
len
(
os
.
listdir
(
workDir
))
<
2
:
shutil
.
rmtree
(
workDir
)
#
delete useless files
shutil
.
rmtree
(
workDir
)
#
delete useless files
repo
=
Repo
.
clone_from
(
data
[
"repo"
],
workDir
)
config_writer
=
repo
.
config_writer
()
config_writer
.
add_section
(
"user"
)
...
...
@@ -42,6 +42,7 @@ def cloneRepo(data):
json
=
safeResult
(
str
(
e
))
return
jsonify
(
code
=
code
,
result
=
json
)
def
gitStatus
(
project
):
"""Run git status and return status of specified project folder
Args:
...
...
@@ -61,6 +62,7 @@ def gitStatus(project):
json
=
safeResult
(
str
(
e
))
return
jsonify
(
code
=
code
,
result
=
json
,
branch
=
branch
,
dirty
=
isdirty
)
def
switchBranch
(
project
,
name
):
"""Switch a git branch
Args:
...
...
@@ -83,6 +85,7 @@ def switchBranch(project, name):
json
=
safeResult
(
str
(
e
))
return
jsonify
(
code
=
code
,
result
=
json
)
def
addBranch
(
project
,
name
,
onlyCheckout
=
False
):
"""Add new git branch to the repository
Args:
...
...
@@ -105,6 +108,7 @@ def addBranch(project, name, onlyCheckout=False):
json
=
safeResult
(
str
(
e
))
return
jsonify
(
code
=
code
,
result
=
json
)
def
getDiff
(
project
):
"""Get git diff for the specified project directory"""
result
=
""
...
...
@@ -117,6 +121,7 @@ def getDiff(project):
result
=
safeResult
(
str
(
e
))
return
result
def
gitPush
(
project
,
msg
):
"""Commit and Push changes for the specified repository
Args:
...
...
@@ -145,10 +150,11 @@ def gitPush(project, msg):
code
=
1
except
Exception
as
e
:
if
undo_commit
:
git
.
reset
(
"HEAD~"
)
#
undo previous commit
git
.
reset
(
"HEAD~"
)
#
undo previous commit
json
=
safeResult
(
str
(
e
))
return
jsonify
(
code
=
code
,
result
=
json
)
def
gitPull
(
project
):
result
=
""
code
=
0
...
...
@@ -161,6 +167,7 @@ def gitPull(project):
result
=
safeResult
(
str
(
e
))
return
jsonify
(
code
=
code
,
result
=
result
)
def
safeResult
(
result
):
"""Parse string and remove credential of the user"""
regex
=
re
.
compile
(
"(https:
\
/
\
/)([
\
w
\
d
\
._-]+:[
\
w
\
d
\
._-]+)
\
@([
\
S]+
\
s)
"
, re.VERBOSE)
...
...
slapos/runner/runnertest.py
View file @
5f34b3f6
...
...
@@ -18,6 +18,7 @@ from slapos.runner.process import killRunningProcess, isRunning
from
slapos.runner
import
views
import
slapos.slap
#Helpers
def
loadJson
(
response
):
return
json
.
loads
(
response
.
data
)
...
...
@@ -48,6 +49,7 @@ class Config:
if
not
getattr
(
self
,
key
,
None
):
setattr
(
self
,
key
,
configuration_dict
[
key
])
class
SlaprunnerTestCase
(
unittest
.
TestCase
):
def
setUp
(
self
):
...
...
@@ -57,8 +59,8 @@ class SlaprunnerTestCase(unittest.TestCase):
self
.
updateUser
=
[
"newslapuser"
,
"newslappwd"
,
"slaprunner@nexedi.com"
,
"SlapOS web runner"
]
self
.
rcode
=
"41bf2657"
self
.
repo
=
'http://git.erp5.org/repos/slapos.git'
self
.
software
=
"workspace/slapos/software/"
#
relative directory fo SR
self
.
project
=
'slapos'
#
Default project name
self
.
software
=
"workspace/slapos/software/"
#
relative directory fo SR
self
.
project
=
'slapos'
#
Default project name
self
.
template
=
'template.cfg'
self
.
partitionPrefix
=
'slappart'
self
.
slaposBuildout
=
"1.6.0-dev-SlapOS-010"
...
...
@@ -77,7 +79,7 @@ class SlaprunnerTestCase(unittest.TestCase):
views
.
app
.
config
.
update
(
software_log
=
config
.
software_root
.
rstrip
(
'/'
)
+
'.log'
,
instance_log
=
config
.
instance_root
.
rstrip
(
'/'
)
+
'.log'
,
workspace
=
workdir
,
workspace
=
workdir
,
software_link
=
software_link
,
instance_profile
=
'instance.cfg'
,
software_profile
=
'software.cfg'
,
...
...
@@ -117,20 +119,24 @@ class SlaprunnerTestCase(unittest.TestCase):
def
configAccount
(
self
,
username
,
password
,
email
,
name
,
rcode
):
"""Helper for configAccount"""
return
self
.
app
.
post
(
'/configAccount'
,
data
=
dict
(
return
self
.
app
.
post
(
'/configAccount'
,
data
=
dict
(
username
=
username
,
password
=
password
,
email
=
email
,
name
=
name
,
rcode
=
rcode
),
follow_redirects
=
True
)
),
follow_redirects
=
True
)
def
login
(
self
,
username
,
password
):
"""Helper for Login method"""
return
self
.
app
.
post
(
'/doLogin'
,
data
=
dict
(
return
self
.
app
.
post
(
'/doLogin'
,
data
=
dict
(
clogin
=
username
,
cpwd
=
password
),
follow_redirects
=
True
)
),
follow_redirects
=
True
)
def
setAccount
(
self
):
"""Initialize user account and log user in"""
...
...
@@ -146,13 +152,15 @@ class SlaprunnerTestCase(unittest.TestCase):
def
updateAccount
(
self
,
newaccount
,
rcode
):
"""Helper for update user account data"""
return
self
.
app
.
post
(
'/updateAccount'
,
data
=
dict
(
return
self
.
app
.
post
(
'/updateAccount'
,
data
=
dict
(
username
=
newaccount
[
0
],
password
=
newaccount
[
1
],
email
=
newaccount
[
2
],
name
=
newaccount
[
3
],
rcode
=
rcode
),
follow_redirects
=
True
)
),
follow_redirects
=
True
)
def
getCurrentSR
(
self
):
return
getProfilePath
(
self
.
app
.
config
[
'etc_dir'
],
...
...
@@ -189,7 +197,8 @@ class SlaprunnerTestCase(unittest.TestCase):
"""Helper for setup compiled software release dir"""
self
.
setupProjectFolder
(
withSoftware
=
True
)
md5
=
hashlib
.
md5
(
os
.
path
.
join
(
self
.
app
.
config
[
'workspace'
],
"slapos/software/slaprunner-test"
,
self
.
app
.
config
[
'software_profile'
])
"slapos/software/slaprunner-test"
,
self
.
app
.
config
[
'software_profile'
])
).
hexdigest
()
base
=
os
.
path
.
join
(
self
.
app
.
config
[
'software_root'
],
md5
)
template
=
os
.
path
.
join
(
base
,
self
.
template
)
...
...
@@ -208,7 +217,6 @@ class SlaprunnerTestCase(unittest.TestCase):
"""Kill slapproxy process"""
killRunningProcess
(
'slapproxy'
,
recursive
=
True
)
#Begin test case here
def
test_wrong_login
(
self
):
"""Test Login user before create session. This should return error value"""
...
...
@@ -266,12 +274,16 @@ class SlaprunnerTestCase(unittest.TestCase):
"""Start scenario 1 for deploying SR: Clone a project from git repository"""
self
.
setAccount
()
folder
=
'workspace/'
+
self
.
project
data
=
{
"repo"
:
self
.
repo
,
"user"
:
'Slaprunner test'
,
"email"
:
'slaprunner@nexedi.com'
,
"name"
:
folder
}
data
=
{
'repo'
:
self
.
repo
,
'user'
:
'Slaprunner test'
,
'email'
:
'slaprunner@nexedi.com'
,
'name'
:
folder
}
response
=
loadJson
(
self
.
app
.
post
(
'/cloneRepository'
,
data
=
data
,
follow_redirects
=
True
))
self
.
assertEqual
(
response
[
'result'
],
""
)
#Get realpath of create project
#
Get realpath of create project
path_data
=
dict
(
file
=
folder
)
response
=
loadJson
(
self
.
app
.
post
(
'/getPath'
,
data
=
path_data
,
follow_redirects
=
True
))
...
...
@@ -281,10 +293,12 @@ class SlaprunnerTestCase(unittest.TestCase):
config
=
open
(
os
.
path
.
join
(
realFolder
,
'.git/config'
),
'r'
).
read
()
assert
"slaprunner@nexedi.com"
in
config
and
"Slaprunner test"
in
config
#Checkout to slaprunner branch, this supose that branch slaprunner exit
response
=
loadJson
(
self
.
app
.
post
(
'/newBranch'
,
data
=
dict
(
response
=
loadJson
(
self
.
app
.
post
(
'/newBranch'
,
data
=
dict
(
project
=
folder
,
create
=
'0'
,
name
=
'slaprunner'
),
name
=
'slaprunner'
),
follow_redirects
=
True
))
self
.
assertEqual
(
response
[
'result'
],
""
)
self
.
logout
()
...
...
@@ -308,7 +322,7 @@ class SlaprunnerTestCase(unittest.TestCase):
self
.
test_cloneProject
()
#Login
self
.
login
(
self
.
users
[
0
],
self
.
users
[
1
])
software
=
os
.
path
.
join
(
self
.
software
,
'drupal'
)
#
Drupal SR must exist in SR folder
software
=
os
.
path
.
join
(
self
.
software
,
'drupal'
)
#
Drupal SR must exist in SR folder
response
=
loadJson
(
self
.
app
.
post
(
'/setCurrentProject'
,
data
=
dict
(
path
=
software
),
follow_redirects
=
True
))
...
...
@@ -391,8 +405,8 @@ class SlaprunnerTestCase(unittest.TestCase):
self
.
assertNotEqual
(
partitionList
,
[])
#Assume that the requested partition is partition 0
slapParameterDict
=
partitionList
[
0
].
getInstanceParameterDict
()
self
.
assertTrue
(
slapParameterDict
.
has_key
(
'appname'
)
)
self
.
assertTrue
(
slapParameterDict
.
has_key
(
'cacountry'
)
)
self
.
assertTrue
(
'appname'
in
slapParameterDict
)
self
.
assertTrue
(
'cacountry'
in
slapParameterDict
)
self
.
assertEqual
(
slapParameterDict
[
'appname'
],
'slaprunnerTest'
)
self
.
assertEqual
(
slapParameterDict
[
'cacountry'
],
'France'
)
self
.
assertEqual
(
slapParameterDict
[
'slap_software_type'
],
'production'
)
...
...
@@ -439,6 +453,7 @@ class SlaprunnerTestCase(unittest.TestCase):
self
.
stopSlapproxy
()
self
.
logout
()
def
main
():
# Empty parser for now - so that erp5testnode is happy when doing --help
parser
=
argparse
.
ArgumentParser
()
...
...
slapos/runner/utils.py
View file @
5f34b3f6
This diff is collapsed.
Click to expand it.
slapos/runner/views.py
View file @
5f34b3f6
This diff is collapsed.
Click to expand it.
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