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
Boxiang Sun
slapos.toolbox
Commits
c26eb8c3
Commit
c26eb8c3
authored
Oct 08, 2012
by
Alain Takoudjou
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move process pid to var/run dir
parent
914ed815
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
110 additions
and
23 deletions
+110
-23
slapos/runner/runnertest.py
slapos/runner/runnertest.py
+98
-7
slapos/runner/static/js/scripts/folder.js
slapos/runner/static/js/scripts/folder.js
+1
-1
slapos/runner/utils.py
slapos/runner/utils.py
+11
-15
No files found.
slapos/runner/runnertest.py
View file @
c26eb8c3
...
@@ -41,18 +41,24 @@ class SlaprunnerTestCase(unittest.TestCase):
...
@@ -41,18 +41,24 @@ class SlaprunnerTestCase(unittest.TestCase):
self
.
users
=
[
"slapuser"
,
"slappwd"
,
"slaprunner@nexedi.com"
,
"SlapOS web runner"
]
self
.
users
=
[
"slapuser"
,
"slappwd"
,
"slaprunner@nexedi.com"
,
"SlapOS web runner"
]
self
.
updateUser
=
[
"newslapuser"
,
"newslappwd"
,
"slaprunner@nexedi.com"
,
"SlapOS web runner"
]
self
.
updateUser
=
[
"newslapuser"
,
"newslappwd"
,
"slaprunner@nexedi.com"
,
"SlapOS web runner"
]
self
.
rcode
=
"41bf2657"
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
#create slaprunner configuration
#create slaprunner configuration
config
=
Config
()
config
=
Config
()
config
.
setConfig
()
config
.
setConfig
()
workdir
=
os
.
path
.
join
(
config
.
runner_workdir
,
'project'
)
workdir
=
os
.
path
.
join
(
config
.
runner_workdir
,
'project'
)
software_link
=
os
.
path
.
join
(
config
.
runner_workdir
,
'softwareLink'
)
views
.
app
.
config
.
update
(
**
config
.
__dict__
)
views
.
app
.
config
.
update
(
**
config
.
__dict__
)
#update or create all runner base directory to test_dir
#update or create all runner base directory to test_dir
if
not
os
.
path
.
exists
(
workdir
):
if
not
os
.
path
.
exists
(
workdir
):
os
.
mkdir
(
workdir
)
os
.
mkdir
(
workdir
)
views
.
app
.
config
.
update
(
views
.
app
.
config
.
update
(
software_log
=
config
.
software_root
.
rstrip
(
'/'
)
+
'.log'
,
software_log
=
config
.
software_root
.
rstrip
(
'/'
)
+
'.log'
,
instance_log
=
config
.
instance_root
.
rstrip
(
'/'
)
+
'.log'
,
instance_log
=
config
.
instance_root
.
rstrip
(
'/'
)
+
'.log'
,
workspace
=
workdir
,
workspace
=
workdir
,
software_link
=
software_link
,
instance_profile
=
'instance.cfg'
,
instance_profile
=
'instance.cfg'
,
software_profile
=
'software.cfg'
,
software_profile
=
'software.cfg'
,
SECRET_KEY
=
"123456"
,
SECRET_KEY
=
"123456"
,
...
@@ -69,17 +75,16 @@ class SlaprunnerTestCase(unittest.TestCase):
...
@@ -69,17 +75,16 @@ class SlaprunnerTestCase(unittest.TestCase):
"""Remove all test data"""
"""Remove all test data"""
os
.
unlink
(
os
.
path
.
join
(
self
.
app
.
config
[
'etc_dir'
],
'.rcode'
))
os
.
unlink
(
os
.
path
.
join
(
self
.
app
.
config
[
'etc_dir'
],
'.rcode'
))
project
=
os
.
path
.
join
(
self
.
app
.
config
[
'etc_dir'
],
'.project'
)
project
=
os
.
path
.
join
(
self
.
app
.
config
[
'etc_dir'
],
'.project'
)
sr_data
=
project
=
os
.
path
.
join
(
self
.
app
.
config
[
'etc_dir'
],
'.softdata'
)
proxy
=
os
.
path
.
join
(
self
.
app
.
config
[
'run_dir'
],
'proxy.pid'
)
proxy
=
os
.
path
.
join
(
self
.
app
.
config
[
'etc_dir'
],
'.proxy.pid'
)
slapgrid_cp
=
os
.
path
.
join
(
self
.
app
.
config
[
'run_dir'
],
'slapgrid-cp.pid'
)
slapgrid_cp
=
os
.
path
.
join
(
self
.
app
.
config
[
'etc_dir'
],
'.slapgrid-cp.pid'
)
slapgrid_sr
=
os
.
path
.
join
(
self
.
app
.
config
[
'run_dir'
],
'slapgrid-sr.pid'
)
slapgrid_sr
=
os
.
path
.
join
(
self
.
app
.
config
[
'etc_dir'
],
'.slapgrid-sr.pid'
)
users
=
os
.
path
.
join
(
self
.
app
.
config
[
'etc_dir'
],
'.users'
)
users
=
os
.
path
.
join
(
self
.
app
.
config
[
'etc_dir'
],
'.users'
)
#Stop process
#self.stopSlapproxy()
if
os
.
path
.
exists
(
users
):
if
os
.
path
.
exists
(
users
):
os
.
unlink
(
users
)
os
.
unlink
(
users
)
if
os
.
path
.
exists
(
project
):
if
os
.
path
.
exists
(
project
):
os
.
unlink
(
project
)
os
.
unlink
(
project
)
if
os
.
path
.
exists
(
sr_data
):
os
.
unlink
(
sr_data
)
if
os
.
path
.
exists
(
proxy
):
if
os
.
path
.
exists
(
proxy
):
os
.
unlink
(
proxy
)
os
.
unlink
(
proxy
)
if
os
.
path
.
exists
(
slapgrid_cp
):
if
os
.
path
.
exists
(
slapgrid_cp
):
...
@@ -146,6 +151,25 @@ class SlaprunnerTestCase(unittest.TestCase):
...
@@ -146,6 +151,25 @@ class SlaprunnerTestCase(unittest.TestCase):
rcode
=
rcode
rcode
=
rcode
),
follow_redirects
=
True
)
),
follow_redirects
=
True
)
def
getCurrentSR
(
self
):
return
getProfilePath
(
self
.
app
.
config
[
'etc_dir'
],
self
.
app
.
config
[
'software_profile'
])
def
proxyStatus
(
self
,
status
=
True
):
"""Helper for testslapproxy status"""
proxy_pid
=
os
.
path
.
join
(
self
.
app
.
config
[
'run_dir'
],
'proxy.pid'
)
pid
=
readPid
(
proxy_pid
)
try
:
os
.
kill
(
pid
,
0
)
proxy
=
True
except
Exception
:
proxy
=
False
self
.
assertEqual
(
proxy
,
status
)
def
stopSlapproxy
(
self
):
"""Kill slapproxy process"""
proxy_pid
=
os
.
path
.
join
(
self
.
app
.
config
[
'run_dir'
],
'proxy.pid'
)
pid
=
readPid
(
proxy_pid
)
recursifKill
([
pid
])
#Begin test case here
#Begin test case here
def
test_wrong_login
(
self
):
def
test_wrong_login
(
self
):
...
@@ -192,10 +216,77 @@ class SlaprunnerTestCase(unittest.TestCase):
...
@@ -192,10 +216,77 @@ class SlaprunnerTestCase(unittest.TestCase):
#log out now!
#log out now!
self
.
logout
()
self
.
logout
()
def
test_startProxy
(
self
):
"""Test slapproxy"""
startProxy
(
self
.
app
.
config
)
self
.
proxyStatus
(
True
)
self
.
stopSlapproxy
()
def
test_cloneProject
(
self
):
"""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
}
response
=
self
.
loadJson
(
self
.
app
.
post
(
'/cloneRepository'
,
data
=
data
,
follow_redirects
=
True
))
self
.
assertEqual
(
response
[
'result'
],
""
)
#Get realpath of create project
path_data
=
dict
(
file
=
folder
)
response
=
self
.
loadJson
(
self
.
app
.
post
(
'/getPath'
,
data
=
path_data
,
follow_redirects
=
True
))
self
.
assertEqual
(
response
[
'code'
],
1
)
realFolder
=
response
[
'result'
].
split
(
'#'
)[
0
]
#Check git configuration
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
=
self
.
loadJson
(
self
.
app
.
post
(
'/newBranch'
,
data
=
dict
(
project
=
folder
,
create
=
'0'
,
name
=
'slaprunner'
),
follow_redirects
=
True
))
self
.
assertEqual
(
response
[
'result'
],
""
)
self
.
logout
()
def
test_createSR
(
self
):
"""Scenario 2: Create a new software release"""
self
.
test_cloneProject
()
#Login
self
.
login
(
self
.
users
[
0
],
self
.
users
[
1
])
#test create SR
newSoftware
=
os
.
path
.
join
(
self
.
software
,
'slaprunner-test'
)
response
=
self
.
loadJson
(
self
.
app
.
post
(
'/createSoftware'
,
data
=
dict
(
folder
=
newSoftware
),
follow_redirects
=
True
))
self
.
assertEqual
(
response
[
'result'
],
""
)
currentSR
=
self
.
getCurrentSR
()
assert
newSoftware
in
currentSR
self
.
logout
()
def
test_openSR
(
self
):
"""Scenario 3: Open software release"""
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
response
=
self
.
loadJson
(
self
.
app
.
post
(
'/setCurrentProject'
,
data
=
dict
(
path
=
software
),
follow_redirects
=
True
))
self
.
assertEqual
(
response
[
'result'
],
""
)
currentSR
=
self
.
getCurrentSR
()
assert
software
in
currentSR
self
.
assertFalse
(
isInstanceRunning
(
self
.
app
.
config
))
self
.
assertFalse
(
isSoftwareRunning
(
self
.
app
.
config
))
#Slapproxy process is supose to be started
self
.
proxyStatus
(
True
)
self
.
stopSlapproxy
()
self
.
logout
()
def
main
():
def
main
():
argv
=
[
''
,
'test_wrong_login'
,
'test_configAccount'
,
argv
=
[
''
,
'test_wrong_login'
,
'test_configAccount'
,
'test_login_logout'
,
'test_updateAccount'
]
'test_login_logout'
,
'test_updateAccount'
,
'test_startProxy'
,
'test_cloneProject'
,
'test_createSR'
,
'test_openSR'
]
unittest
.
main
(
module
=
SlaprunnerTestCase
,
argv
=
argv
)
unittest
.
main
(
module
=
SlaprunnerTestCase
,
argv
=
argv
)
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
...
...
slapos/runner/static/js/scripts/folder.js
View file @
c26eb8c3
...
@@ -84,7 +84,7 @@ $(document).ready( function() {
...
@@ -84,7 +84,7 @@ $(document).ready( function() {
$
(
"
#error
"
).
Popup
(
"
Your repository is cloned!
"
,
{
type
:
'
confirm
'
,
duration
:
3000
});
$
(
"
#error
"
).
Popup
(
"
Your repository is cloned!
"
,
{
type
:
'
confirm
'
,
duration
:
3000
});
$
(
"
input#repo
"
).
val
(
"
Enter the url of your repository...
"
);
$
(
"
input#repo
"
).
val
(
"
Enter the url of your repository...
"
);
$
(
"
input#name
"
).
val
(
"
Enter the project name...
"
);
$
(
"
input#name
"
).
val
(
"
Enter the project name...
"
);
$
(
'
#fileNavigator
'
).
gsFileManager
({
script
:
$SCRIPT_ROOT
+
"
/fileBrowser
"
,
root
:
"
workspace
"
});
$
(
'
#fileNavigator
'
).
gsFileManager
({
script
:
$SCRIPT_ROOT
+
"
/fileBrowser
"
,
root
:
"
workspace
/
"
});
}
}
else
{
else
{
$
(
"
#error
"
).
Popup
(
data
.
result
,
{
type
:
'
error
'
});
$
(
"
#error
"
).
Popup
(
data
.
result
,
{
type
:
'
error
'
});
...
...
slapos/runner/utils.py
View file @
c26eb8c3
...
@@ -200,7 +200,7 @@ def updateInstanceParameter(config, software_type=None):
...
@@ -200,7 +200,7 @@ def updateInstanceParameter(config, software_type=None):
def
startProxy
(
config
):
def
startProxy
(
config
):
"""Start Slapproxy server"""
"""Start Slapproxy server"""
proxy_pid
=
os
.
path
.
join
(
config
[
'
etc
_dir'
],
'proxy.pid'
)
proxy_pid
=
os
.
path
.
join
(
config
[
'
run
_dir'
],
'proxy.pid'
)
pid
=
readPid
(
proxy_pid
)
pid
=
readPid
(
proxy_pid
)
running
=
False
running
=
False
if
pid
:
if
pid
:
...
@@ -211,20 +211,16 @@ def startProxy(config):
...
@@ -211,20 +211,16 @@ def startProxy(config):
else
:
else
:
running
=
True
running
=
True
if
not
running
:
if
not
running
:
proxy
=
Popen
([
config
[
'slapproxy'
],
config
[
'configuration_file_path'
]])
log
=
os
.
path
.
join
(
config
[
'log_dir'
],
'slapproxy.log'
)
proxy_pid
=
os
.
path
.
join
(
config
[
'etc_dir'
],
'proxy.pid'
)
proxy
=
Popen
([
config
[
'slapproxy'
],
'--log_file'
,
log
,
config
[
'configuration_file_path'
]])
writePid
(
proxy_pid
,
proxy
.
pid
)
writePid
(
proxy_pid
,
proxy
.
pid
)
time
.
sleep
(
5
)
time
.
sleep
(
4
)
def
stopProxy
(
config
):
def
stopProxy
(
config
):
"""Stop Slapproxy server"""
"""Stop Slapproxy server"""
pid
=
readPid
(
os
.
path
.
join
(
config
[
'etc_dir'
],
'proxy.pid'
))
pass
if
pid
:
try
:
os
.
kill
(
pid
)
except
:
pass
def
removeProxyDb
(
config
):
def
removeProxyDb
(
config
):
...
@@ -237,7 +233,7 @@ def isSoftwareRunning(config):
...
@@ -237,7 +233,7 @@ def isSoftwareRunning(config):
"""
"""
Return True if slapgrid-sr is still running and false if slapgrid if not
Return True if slapgrid-sr is still running and false if slapgrid if not
"""
"""
slapgrid_pid
=
os
.
path
.
join
(
config
[
'
etc
_dir'
],
'slapgrid-sr.pid'
)
slapgrid_pid
=
os
.
path
.
join
(
config
[
'
run
_dir'
],
'slapgrid-sr.pid'
)
pid
=
readPid
(
slapgrid_pid
)
pid
=
readPid
(
slapgrid_pid
)
if
pid
:
if
pid
:
try
:
try
:
...
@@ -256,7 +252,7 @@ def runSoftwareWithLock(config):
...
@@ -256,7 +252,7 @@ def runSoftwareWithLock(config):
Use Slapgrid to compile current Software Release and wait until
Use Slapgrid to compile current Software Release and wait until
compilation is done
compilation is done
"""
"""
slapgrid_pid
=
os
.
path
.
join
(
config
[
'
etc
_dir'
],
'slapgrid-sr.pid'
)
slapgrid_pid
=
os
.
path
.
join
(
config
[
'
run
_dir'
],
'slapgrid-sr.pid'
)
if
not
isSoftwareRunning
(
config
):
if
not
isSoftwareRunning
(
config
):
if
not
os
.
path
.
exists
(
config
[
'software_root'
]):
if
not
os
.
path
.
exists
(
config
[
'software_root'
]):
os
.
mkdir
(
config
[
'software_root'
])
os
.
mkdir
(
config
[
'software_root'
])
...
@@ -332,7 +328,7 @@ def isInstanceRunning(config):
...
@@ -332,7 +328,7 @@ def isInstanceRunning(config):
"""
"""
Return True if slapgrid-cp is still running and false if slapgrid if not
Return True if slapgrid-cp is still running and false if slapgrid if not
"""
"""
slapgrid_pid
=
os
.
path
.
join
(
config
[
'
etc
_dir'
],
'slapgrid-cp.pid'
)
slapgrid_pid
=
os
.
path
.
join
(
config
[
'
run
_dir'
],
'slapgrid-cp.pid'
)
pid
=
readPid
(
slapgrid_pid
)
pid
=
readPid
(
slapgrid_pid
)
if
pid
:
if
pid
:
try
:
try
:
...
@@ -347,7 +343,7 @@ def isInstanceRunning(config):
...
@@ -347,7 +343,7 @@ def isInstanceRunning(config):
def
killRunningSlapgrid
(
config
,
ptype
):
def
killRunningSlapgrid
(
config
,
ptype
):
"""Kill slapgrid process and all running children process"""
"""Kill slapgrid process and all running children process"""
slapgrid_pid
=
os
.
path
.
join
(
config
[
'
etc
_dir'
],
ptype
)
slapgrid_pid
=
os
.
path
.
join
(
config
[
'
run
_dir'
],
ptype
)
pid
=
readPid
(
slapgrid_pid
)
pid
=
readPid
(
slapgrid_pid
)
if
pid
:
if
pid
:
recursifKill
([
pid
])
recursifKill
([
pid
])
...
@@ -379,7 +375,7 @@ def runInstanceWithLock(config):
...
@@ -379,7 +375,7 @@ def runInstanceWithLock(config):
Use Slapgrid to deploy current Software Release and wait until
Use Slapgrid to deploy current Software Release and wait until
deployment is done.
deployment is done.
"""
"""
slapgrid_pid
=
os
.
path
.
join
(
config
[
'
etc
_dir'
],
'slapgrid-cp.pid'
)
slapgrid_pid
=
os
.
path
.
join
(
config
[
'
run
_dir'
],
'slapgrid-cp.pid'
)
if
not
isInstanceRunning
(
config
):
if
not
isInstanceRunning
(
config
):
startProxy
(
config
)
startProxy
(
config
)
logfile
=
open
(
config
[
'instance_log'
],
'w'
)
logfile
=
open
(
config
[
'instance_log'
],
'w'
)
...
...
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