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
Gabriel Monnerat
slapos.toolbox
Commits
c58dd749
Commit
c58dd749
authored
Sep 01, 2014
by
Nicolas Wavrant
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'slaprunner-paas'
parents
03c664be
05618968
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
170 additions
and
96 deletions
+170
-96
slapos/runner/gittools.py
slapos/runner/gittools.py
+3
-1
slapos/runner/runnertest.py
slapos/runner/runnertest.py
+10
-15
slapos/runner/static/js/scripts/process.js
slapos/runner/static/js/scripts/process.js
+0
-3
slapos/runner/static/js/scripts/repo.js
slapos/runner/static/js/scripts/repo.js
+4
-4
slapos/runner/sup_process.py
slapos/runner/sup_process.py
+89
-0
slapos/runner/templates/layout.html
slapos/runner/templates/layout.html
+2
-0
slapos/runner/templates/manageRepository.html
slapos/runner/templates/manageRepository.html
+2
-2
slapos/runner/utils.py
slapos/runner/utils.py
+47
-67
slapos/runner/views.py
slapos/runner/views.py
+13
-4
No files found.
slapos/runner/gittools.py
View file @
c58dd749
...
@@ -137,8 +137,8 @@ def gitCommit(project, msg):
...
@@ -137,8 +137,8 @@ def gitCommit(project, msg):
git
.
add
(
f
)
git
.
add
(
f
)
#Commit all modified and untracked files
#Commit all modified and untracked files
git
.
commit
(
'-a'
,
'-m'
,
msg
)
git
.
commit
(
'-a'
,
'-m'
,
msg
)
else
:
code
=
1
code
=
1
else
:
json
=
"Nothing to be commited"
json
=
"Nothing to be commited"
return
jsonify
(
code
=
code
,
result
=
json
)
return
jsonify
(
code
=
code
,
result
=
json
)
...
@@ -150,6 +150,8 @@ def gitPush(project):
...
@@ -150,6 +150,8 @@ def gitPush(project):
code
=
0
code
=
0
json
=
""
json
=
""
try
:
try
:
repo
=
Repo
(
project
)
git
=
repo
.
git
#push changes to repo
#push changes to repo
current_branch
=
repo
.
active_branch
.
name
current_branch
=
repo
.
active_branch
.
name
git
.
push
(
'origin'
,
current_branch
)
git
.
push
(
'origin'
,
current_branch
)
...
...
slapos/runner/runnertest.py
View file @
c58dd749
...
@@ -17,16 +17,16 @@ import hashlib
...
@@ -17,16 +17,16 @@ import hashlib
import
json
import
json
import
os
import
os
import
shutil
import
shutil
import
sup_process
import
time
import
time
import
unittest
import
unittest
from
slapos.runner.utils
import
(
getProfilePath
,
getRcode
,
from
slapos.runner.utils
import
(
getProfilePath
,
getSession
,
isInstanceRunning
,
getSession
,
isInstanceRunning
,
isSoftwareRunning
,
startProxy
,
isSoftwareRunning
,
startProxy
,
isSoftwareReleaseReady
,
isSoftwareReleaseReady
,
runSlapgridUntilSuccess
,
runInstanceWithLock
,
runSlapgridUntilSuccess
,
runInstanceWithLock
,
getBuildAndRunParams
,
saveBuildAndRunParams
)
getBuildAndRunParams
,
saveBuildAndRunParams
)
from
slapos.runner.process
import
killRunningProcess
,
isRunning
from
slapos.runner
import
views
from
slapos.runner
import
views
import
slapos.slap
import
slapos.slap
from
slapos.htpasswd
import
HtpasswdFile
from
slapos.htpasswd
import
HtpasswdFile
...
@@ -137,9 +137,9 @@ class SlaprunnerTestCase(unittest.TestCase):
...
@@ -137,9 +137,9 @@ class SlaprunnerTestCase(unittest.TestCase):
if
os
.
path
.
exists
(
self
.
app
.
config
[
'software_link'
]):
if
os
.
path
.
exists
(
self
.
app
.
config
[
'software_link'
]):
shutil
.
rmtree
(
self
.
app
.
config
[
'software_link'
])
shutil
.
rmtree
(
self
.
app
.
config
[
'software_link'
])
#Stop process
#Stop process
killRunningProcess
(
'slapproxy'
,
recursive
=
True
)
sup_process
.
killRunningProcess
(
self
.
app
.
config
,
'slapproxy'
)
killRunningProcess
(
'slapgrid-cp'
,
recursive
=
True
)
sup_process
.
killRunningProcess
(
self
.
app
.
config
,
'slapgrid-cp'
)
killRunningProcess
(
'slapgrid-sr'
,
recursive
=
True
)
sup_process
.
killRunningProcess
(
self
.
app
.
config
,
'slapgrid-sr'
)
def
updateConfigParameter
(
self
,
parameter
,
value
):
def
updateConfigParameter
(
self
,
parameter
,
value
):
config_parser
=
ConfigParser
.
SafeConfigParser
()
config_parser
=
ConfigParser
.
SafeConfigParser
()
...
@@ -186,10 +186,10 @@ class SlaprunnerTestCase(unittest.TestCase):
...
@@ -186,10 +186,10 @@ class SlaprunnerTestCase(unittest.TestCase):
def
proxyStatus
(
self
,
status
=
True
,
sleep_time
=
0
):
def
proxyStatus
(
self
,
status
=
True
,
sleep_time
=
0
):
"""Helper for testslapproxy status"""
"""Helper for testslapproxy status"""
proxy
=
isRunning
(
'slapproxy'
)
proxy
=
sup_process
.
isRunning
(
self
.
app
.
config
,
'slapproxy'
)
if
proxy
!=
status
and
sleep_time
!=
0
:
if
proxy
!=
status
and
sleep_time
!=
0
:
time
.
sleep
(
sleep_time
)
time
.
sleep
(
sleep_time
)
proxy
=
isRunning
(
'slapproxy'
)
proxy
=
sup_process
.
isRunning
(
self
.
app
.
config
,
'slapproxy'
)
self
.
assertEqual
(
proxy
,
status
)
self
.
assertEqual
(
proxy
,
status
)
def
setupProjectFolder
(
self
,
withSoftware
=
False
):
def
setupProjectFolder
(
self
,
withSoftware
=
False
):
...
@@ -232,7 +232,7 @@ class SlaprunnerTestCase(unittest.TestCase):
...
@@ -232,7 +232,7 @@ class SlaprunnerTestCase(unittest.TestCase):
def
stopSlapproxy
(
self
):
def
stopSlapproxy
(
self
):
"""Kill slapproxy process"""
"""Kill slapproxy process"""
killRunningProcess
(
'slapproxy'
,
recursive
=
True
)
pass
def
test_configAccount
(
self
):
def
test_configAccount
(
self
):
"""For the first lauch of slaprunner user need do create first account"""
"""For the first lauch of slaprunner user need do create first account"""
...
@@ -256,12 +256,8 @@ class SlaprunnerTestCase(unittest.TestCase):
...
@@ -256,12 +256,8 @@ class SlaprunnerTestCase(unittest.TestCase):
def
test_startStopProxy
(
self
):
def
test_startStopProxy
(
self
):
"""Test slapproxy"""
"""Test slapproxy"""
self
.
stopSlapproxy
()
self
.
proxyStatus
(
False
)
startProxy
(
self
.
app
.
config
)
startProxy
(
self
.
app
.
config
)
self
.
proxyStatus
(
True
)
self
.
proxyStatus
(
True
)
self
.
stopSlapproxy
()
self
.
proxyStatus
(
False
,
sleep_time
=
1
)
def
test_cloneProject
(
self
):
def
test_cloneProject
(
self
):
"""Start scenario 1 for deploying SR: Clone a project from git repository"""
"""Start scenario 1 for deploying SR: Clone a project from git repository"""
...
@@ -408,7 +404,6 @@ class SlaprunnerTestCase(unittest.TestCase):
...
@@ -408,7 +404,6 @@ class SlaprunnerTestCase(unittest.TestCase):
def
test_requestInstance
(
self
):
def
test_requestInstance
(
self
):
"""Scenarion 6: request software instance"""
"""Scenarion 6: request software instance"""
self
.
test_updateInstanceParameter
()
self
.
test_updateInstanceParameter
()
self
.
proxyStatus
(
False
,
sleep_time
=
1
)
#run Software profile
#run Software profile
response
=
loadJson
(
self
.
app
.
post
(
'/runSoftwareProfile'
,
response
=
loadJson
(
self
.
app
.
post
(
'/runSoftwareProfile'
,
data
=
dict
(),
data
=
dict
(),
...
@@ -459,7 +454,7 @@ class SlaprunnerTestCase(unittest.TestCase):
...
@@ -459,7 +454,7 @@ class SlaprunnerTestCase(unittest.TestCase):
self
.
assertEqual
(
response
,
"2"
)
self
.
assertEqual
(
response
,
"2"
)
# Test that the new call to isSoftwareReleaseReady
# Test that the new call to isSoftwareReleaseReady
# doesn't overwrite the previous installed one
# doesn't overwrite the previous installed one
killRunningProcess
(
'slapgrid-sr'
)
sup_process
.
killRunningProcess
(
self
.
app
.
config
,
'slapgrid-sr'
)
completed_path
=
os
.
path
.
join
(
self
.
app
.
config
[
'runner_workdir'
],
completed_path
=
os
.
path
.
join
(
self
.
app
.
config
[
'runner_workdir'
],
'softwareLink'
,
'slaprunner-test'
,
'.completed'
)
'softwareLink'
,
'slaprunner-test'
,
'.completed'
)
completed_text
=
".completed file: test"
completed_text
=
".completed file: test"
...
@@ -584,7 +579,7 @@ class SlaprunnerTestCase(unittest.TestCase):
...
@@ -584,7 +579,7 @@ class SlaprunnerTestCase(unittest.TestCase):
only by changing the value of slapos.cfg config file. This can happen when
only by changing the value of slapos.cfg config file. This can happen when
slapgrid processes the webrunner's partition.
slapgrid processes the webrunner's partition.
"""
"""
config_file
=
os
.
path
.
join
(
self
.
app
.
config
[
'etc_dir'
],
'slapos.cfg'
)
config_file
=
os
.
path
.
join
(
self
.
app
.
config
[
'etc_dir'
],
'slapos
-test
.cfg'
)
runner_config_old
=
os
.
environ
[
'RUNNER_CONFIG'
]
runner_config_old
=
os
.
environ
[
'RUNNER_CONFIG'
]
os
.
environ
[
'RUNNER_CONFIG'
]
=
config_file
os
.
environ
[
'RUNNER_CONFIG'
]
=
config_file
open
(
config_file
,
'w'
).
write
(
"[section]
\
n
var=value"
)
open
(
config_file
,
'w'
).
write
(
"[section]
\
n
var=value"
)
...
...
slapos/runner/static/js/scripts/process.js
View file @
c58dd749
...
@@ -286,6 +286,3 @@ function runProcess(urlfor) {
...
@@ -286,6 +286,3 @@ function runProcess(urlfor) {
});
});
}
}
}
}
getRunningState
();
setInterval
(
'
getRunningState()
'
,
3000
);
slapos/runner/static/js/scripts/repo.js
View file @
c58dd749
...
@@ -171,7 +171,7 @@ $(document).ready(function () {
...
@@ -171,7 +171,7 @@ $(document).ready(function () {
});
});
$
(
"
#commitbutton
"
).
click
(
function
()
{
$
(
"
#commitbutton
"
).
click
(
function
()
{
if
(
$
(
"
input#commitmsg
"
).
val
()
===
""
||
if
(
$
(
"
input#commitmsg
"
).
val
()
===
""
||
$
(
"
textarea
#commitmsg
"
).
val
()
===
"
Enter message...
"
)
{
$
(
"
input
#commitmsg
"
).
val
()
===
"
Enter message...
"
)
{
$
(
"
#error
"
).
Popup
(
"
Please Enter the commit message
"
,
{
type
:
'
alert
'
,
duration
:
3000
});
$
(
"
#error
"
).
Popup
(
"
Please Enter the commit message
"
,
{
type
:
'
alert
'
,
duration
:
3000
});
return
false
;
return
false
;
}
}
...
@@ -181,12 +181,12 @@ $(document).ready(function () {
...
@@ -181,12 +181,12 @@ $(document).ready(function () {
send
=
true
;
send
=
true
;
var
project
=
$
(
"
#project
"
).
val
();
var
project
=
$
(
"
#project
"
).
val
();
$
(
"
#imgwaitting
"
).
fadeIn
(
'
normal
'
);
$
(
"
#imgwaitting
"
).
fadeIn
(
'
normal
'
);
//$("#commit
").empty();
$
(
"
#commitmsg
"
).
empty
();
$
(
"
#commitb
b
utton
"
).
attr
(
"
value
"
,
"
Wait...
"
);
$
(
"
#commitbutton
"
).
attr
(
"
value
"
,
"
Wait...
"
);
$
.
ajax
({
$
.
ajax
({
type
:
"
POST
"
,
type
:
"
POST
"
,
url
:
$SCRIPT_ROOT
+
'
/commitProjectFiles
'
,
url
:
$SCRIPT_ROOT
+
'
/commitProjectFiles
'
,
data
:
{
project
:
$
(
"
input#workdir
"
).
val
()
+
"
/
"
+
project
,
msg
:
$
(
"
textarea
#commitmsg
"
).
val
()},
data
:
{
project
:
$
(
"
input#workdir
"
).
val
()
+
"
/
"
+
project
,
msg
:
$
(
"
input
#commitmsg
"
).
val
()},
success
:
function
(
data
)
{
success
:
function
(
data
)
{
if
(
data
.
code
===
1
)
{
if
(
data
.
code
===
1
)
{
if
(
data
.
result
!==
""
)
{
if
(
data
.
result
!==
""
)
{
...
...
slapos/runner/sup_process.py
0 → 100644
View file @
c58dd749
# pylint: disable-msg=W0311,C0103
import
os
import
signal
import
time
import
xmlrpclib
# This mini-library is used to communicate with supervisord process
# It aims to replace the file "process.py"
# For the moment, we keep both for compatibility
def
isRunning
(
config
,
process
):
"""
Ask supervisor if given process is currently running
"""
server
=
xmlrpclib
.
Server
(
config
[
'supervisord_server'
])
state
=
server
.
supervisor
.
getProcessInfo
(
process
)[
'state'
]
return
(
True
if
state
in
(
10
,
20
)
else
False
)
def
killRunningProcess
(
config
,
process
,
sig
=
signal
.
SIGTERM
):
"""
Send signal "sig" to given process.
Default signal sent is SIGTERM
"""
server
=
xmlrpclib
.
Server
(
config
[
'supervisord_server'
])
pid
=
server
.
supervisor
.
getProcessInfo
(
process
)[
'pid'
]
if
pid
!=
0
:
os
.
kill
(
pid
,
sig
)
def
returnCode
(
config
,
process
):
"""
Get the returned code of the last run of given process
"""
server
=
xmlrpclib
.
Server
(
config
[
'supervisord_server'
])
code
=
server
.
supervisor
.
getProcessInfo
(
process
)[
'exitstatus'
]
return
code
def
runProcess
(
config
,
process
):
"""
Start a process registered by supervisor
"""
server
=
xmlrpclib
.
Server
(
config
[
'supervisord_server'
])
server
.
supervisor
.
startProcess
(
process
)
def
runProcesses
(
config
,
processes
):
"""
Start by supervisor a list of given processes, one by one
"""
server
=
xmlrpclib
.
Server
(
config
[
'supervisord_server'
])
for
proc
in
processes
:
server
.
supervisor
.
startProcess
(
proc
)
waitForProcessEnd
(
config
,
proc
)
def
stopProcess
(
config
,
process
):
"""
Ask supervisor to stop a process
"""
if
isRunning
(
config
,
process
):
server
=
xmlrpclib
.
Server
(
config
[
'supervisord_server'
])
server
.
supervisor
.
stopProcess
(
process
)
def
stopProcesses
(
config
,
processes
):
"""
Stop a list of processes
"""
server
=
xmlrpclib
.
Server
(
config
[
'supervisord_server'
])
for
proc
in
processes
:
server
.
supervisor
.
stopProcess
(
proc
)
def
waitForProcessEnd
(
config
,
process
):
"""
Block program's execution until given process quits Running state
"""
server
=
xmlrpclib
.
Server
(
config
[
'supervisord_server'
])
while
True
:
state
=
server
.
supervisor
.
getProcessInfo
(
process
)[
'state'
]
if
state
==
20
:
time
.
sleep
(
3
)
else
:
return
True
return
False
slapos/runner/templates/layout.html
View file @
c58dd749
...
@@ -44,6 +44,8 @@
...
@@ -44,6 +44,8 @@
$
(
"
#error
"
).
Popup
(
$
(
"
input#fmsg
"
).
val
(),
{
type
:
'
info
'
,
duration
:
5000
,
load
:
true
});
$
(
"
#error
"
).
Popup
(
$
(
"
input#fmsg
"
).
val
(),
{
type
:
'
info
'
,
duration
:
5000
,
load
:
true
});
}
}
bindRun
();
bindRun
();
getRunningState
();
setInterval
(
'
getRunningState()
'
,
3000
);
$
(
'
ul.sf-menu
'
).
superfish
({
$
(
'
ul.sf-menu
'
).
superfish
({
delay
:
600
,
delay
:
600
,
speed
:
'
fast
'
,
speed
:
'
fast
'
,
...
...
slapos/runner/templates/manageRepository.html
View file @
c58dd749
...
@@ -111,12 +111,12 @@
...
@@ -111,12 +111,12 @@
<!--<img class="waitting" id="pullimgwaitting" src="{{ url_for('static', filename='images/waiting.gif') }}" alt="" />-->
<!--<img class="waitting" id="pullimgwaitting" src="{{ url_for('static', filename='images/waiting.gif') }}" alt="" />-->
</div>
</div>
</div>
</div>
<div
id=
"
push
"
style=
"margin-bottom:20px;"
>
<div
id=
"
commit
"
style=
"margin-bottom:20px;"
>
<h2>
Commit All your changes (On active branch)
</h2>
<h2>
Commit All your changes (On active branch)
</h2>
<div
style=
"margin-left:15px;"
>
<div
style=
"margin-left:15px;"
>
<label
for=
'commitmsg'
>
Commit message:
</label>
<label
for=
'commitmsg'
>
Commit message:
</label>
<input
type=
"text"
name=
"commitmsg"
id=
"commitmsg"
size=
'40'
value=
"Enter message..."
/>
<input
type=
"text"
name=
"commitmsg"
id=
"commitmsg"
size=
'40'
value=
"Enter message..."
/>
<input
type=
"submit"
name=
"commit"
id =
"commit"
value=
"Commit"
class=
"button"
/>
<input
type=
"submit"
name=
"commit"
id =
"commit
button
"
value=
"Commit"
class=
"button"
/>
<img
class=
"waitting"
id=
"imgwaitting"
src=
"{{ url_for('static', filename='images/waiting.gif') }}"
alt=
""
/>
<img
class=
"waitting"
id=
"imgwaitting"
src=
"{{ url_for('static', filename='images/waiting.gif') }}"
alt=
""
/>
</div>
</div>
</div>
</div>
...
...
slapos/runner/utils.py
View file @
c58dd749
...
@@ -7,13 +7,14 @@ import datetime
...
@@ -7,13 +7,14 @@ import datetime
import
json
import
json
import
logging
import
logging
import
md5
import
md5
import
multiprocessing
import
os
import
os
import
sup_process
import
re
import
re
import
shutil
import
shutil
import
thread
import
thread
import
time
import
time
import
urllib
import
urllib
import
xmlrpclib
from
xml.dom
import
minidom
from
xml.dom
import
minidom
import
xml_marshaller
import
xml_marshaller
...
@@ -21,7 +22,7 @@ from flask import jsonify
...
@@ -21,7 +22,7 @@ from flask import jsonify
from
slapos.runner.gittools
import
cloneRepo
from
slapos.runner.gittools
import
cloneRepo
from
slapos.runner.process
import
Popen
,
isRunning
,
killRunningProcess
,
isPidFileProcessRunning
from
slapos.runner.process
import
Popen
from
slapos.htpasswd
import
HtpasswdFile
from
slapos.htpasswd
import
HtpasswdFile
import
slapos.slap
import
slapos.slap
from
slapos.grid.utils
import
md5digest
from
slapos.grid.utils
import
md5digest
...
@@ -236,20 +237,19 @@ def updateInstanceParameter(config, software_type=None):
...
@@ -236,20 +237,19 @@ def updateInstanceParameter(config, software_type=None):
config: Slaprunner configuration.
config: Slaprunner configuration.
software_type: reconfigure Software Instance with software type.
software_type: reconfigure Software Instance with software type.
"""
"""
time
.
sleep
(
1
)
if
not
(
updateProxy
(
config
)
and
requestInstance
(
config
,
software_type
)):
if
not
(
updateProxy
(
config
)
and
requestInstance
(
config
,
software_type
)):
return
False
return
False
def
startProxy
(
config
):
def
startProxy
(
config
):
"""Start Slapproxy server"""
"""Start Slapproxy server"""
if
isRunning
(
'slapproxy'
):
if
sup_process
.
isRunning
(
config
,
'slapproxy'
):
return
return
try
:
log
=
os
.
path
.
join
(
config
[
'log_dir'
],
'slapproxy.log'
)
sup_process
.
runProcess
(
config
,
"slapproxy"
)
Popen
([
config
[
'slapos'
],
'proxy'
,
'start'
,
'--logfile'
,
log
,
except
xmlrpclib
.
Fault
:
'--cfg'
,
config
[
'configuration_file_path'
]],
pass
name
=
'slapproxy'
,
stdout
=
None
)
time
.
sleep
(
4
)
time
.
sleep
(
4
)
...
@@ -265,15 +265,11 @@ def removeProxyDb(config):
...
@@ -265,15 +265,11 @@ def removeProxyDb(config):
os
.
unlink
(
config
[
'database_uri'
])
os
.
unlink
(
config
[
'database_uri'
])
def
isSoftwareRunning
(
config
=
None
):
def
isSoftwareRunning
(
config
):
"""
"""
Return True if slapos is still running and false if slapos if not
Return True if slapos is still running and false if slapos if not
"""
"""
# XXX-Cedric Hardcoded pidfile
return
sup_process
.
isRunning
(
config
,
'slapgrid-sr'
)
if
config
:
slapgrid_pid
=
os
.
path
.
join
(
config
[
'run_dir'
],
'slapgrid-sr.pid'
)
return
isPidFileProcessRunning
(
slapgrid_pid
)
return
isRunning
(
'slapgrid-sr'
)
def
slapgridResultToFile
(
config
,
step
,
returncode
,
datetime
):
def
slapgridResultToFile
(
config
,
step
,
returncode
,
datetime
):
...
@@ -299,17 +295,14 @@ def waitProcess(config, process, step):
...
@@ -299,17 +295,14 @@ def waitProcess(config, process, step):
slapgridResultToFile
(
config
,
step
,
process
.
returncode
,
date
)
slapgridResultToFile
(
config
,
step
,
process
.
returncode
,
date
)
def
runSoftwareWithLock
(
config
,
lock
=
Tru
e
):
def
runSoftwareWithLock
(
config
,
lock
=
Fals
e
):
"""
"""
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
"""
"""
if
isSoftwareRunning
(
):
if
sup_process
.
isRunning
(
config
,
'slapgrid-sr'
):
return
False
return
1
slapgrid_pid
=
os
.
path
.
join
(
config
[
'run_dir'
],
'slapgrid-sr.pid'
)
if
isPidFileProcessRunning
(
slapgrid_pid
):
return
False
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'
])
stopProxy
(
config
)
stopProxy
(
config
)
...
@@ -318,21 +311,16 @@ def runSoftwareWithLock(config, lock=True):
...
@@ -318,21 +311,16 @@ def runSoftwareWithLock(config, lock=True):
if
os
.
path
.
exists
(
config
[
'software_log'
]):
if
os
.
path
.
exists
(
config
[
'software_log'
]):
os
.
remove
(
config
[
'software_log'
])
os
.
remove
(
config
[
'software_log'
])
if
not
updateProxy
(
config
):
if
not
updateProxy
(
config
):
return
False
return
1
slapgrid
=
Popen
([
config
[
'slapos'
],
'node'
,
'software'
,
'--all'
,
try
:
'--cfg'
,
config
[
'slapos_cfg'
],
'--pidfile'
,
slapgrid_pid
,
sup_process
.
runProcess
(
config
,
"slapgrid-sr"
)
'--verbose'
,
'--logfile'
,
config
[
'software_log'
]],
if
lock
:
name
=
'slapgrid-sr'
,
stdout
=
None
)
sup_process
.
waitForProcessEnd
(
config
,
"slapgrid-sr"
)
if
lock
:
slapgrid
.
wait
()
date
=
datetime
.
datetime
.
now
().
strftime
(
"%Y-%m-%d %H:%M:%S"
)
slapgridResultToFile
(
config
,
"software"
,
slapgrid
.
returncode
,
date
)
#Saves the current compile software for re-use
#Saves the current compile software for re-use
config_SR_folder
(
config
)
config_SR_folder
(
config
)
return
(
True
if
slapgrid
.
returncode
==
0
else
False
)
return
sup_process
.
returnCode
(
config
,
"slapgrid-sr"
)
else
:
except
xmlrpclib
.
Fault
:
thread
.
start_new_thread
(
waitProcess
,
(
config
,
slapgrid
,
"software"
))
return
1
return
False
def
config_SR_folder
(
config
):
def
config_SR_folder
(
config
):
...
@@ -396,44 +384,34 @@ def loadSoftwareRList(config):
...
@@ -396,44 +384,34 @@ def loadSoftwareRList(config):
return
list
return
list
def
isInstanceRunning
(
config
=
None
):
def
isInstanceRunning
(
config
):
"""
"""
Return True if slapos is still running and False otherwise
Return True if slapos is still running and False otherwise
"""
"""
# XXX-Cedric Hardcoded pidfile
return
sup_process
.
isRunning
(
config
,
'slapgrid-cp'
)
if
config
:
slapgrid_pid
=
os
.
path
.
join
(
config
[
'run_dir'
],
'slapgrid-cp.pid'
)
return
isPidFileProcessRunning
(
slapgrid_pid
)
return
isRunning
(
'slapgrid-cp'
)
def
runInstanceWithLock
(
config
,
lock
=
Tru
e
):
def
runInstanceWithLock
(
config
,
lock
=
Fals
e
):
"""
"""
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.
"""
"""
if
isInstanceRunning
(
):
if
sup_process
.
isRunning
(
config
,
'slapgrid-cp'
):
return
False
return
1
slapgrid_pid
=
os
.
path
.
join
(
config
[
'run_dir'
],
'slapgrid-cp.pid'
)
startProxy
(
config
)
startProxy
(
config
)
# XXX Hackish and unreliable
# XXX Hackish and unreliable
if
os
.
path
.
exists
(
config
[
'instance_log'
]):
if
os
.
path
.
exists
(
config
[
'instance_log'
]):
os
.
remove
(
config
[
'instance_log'
])
os
.
remove
(
config
[
'instance_log'
])
if
not
(
updateProxy
(
config
)
and
requestInstance
(
config
)):
if
not
(
updateProxy
(
config
)
and
requestInstance
(
config
)):
return
False
return
1
slapgrid
=
Popen
([
config
[
'slapos'
],
'node'
,
'instance'
,
'--all'
,
try
:
'--cfg'
,
config
[
'slapos_cfg'
],
'--pidfile'
,
slapgrid_pid
,
sup_process
.
runProcess
(
config
,
"slapgrid-cp"
)
'--verbose'
,
'--logfile'
,
config
[
'instance_log'
]],
if
lock
:
name
=
'slapgrid-cp'
,
stdout
=
None
)
sup_process
.
waitForProcessEnd
(
config
,
"slapgrid-cp"
)
if
lock
:
return
sup_process
.
returnCode
(
config
,
"slapgrid-cp"
)
slapgrid
.
wait
()
except
xmlrpclib
.
Fault
:
date
=
datetime
.
datetime
.
now
().
strftime
(
"%Y-%m-%d %H:%M:%S"
)
return
1
slapgridResultToFile
(
config
,
"instance"
,
slapgrid
.
returncode
,
date
)
return
(
True
if
slapgrid
.
returncode
==
0
else
False
)
else
:
thread
.
start_new_thread
(
waitProcess
,
(
config
,
slapgrid
,
"instance"
))
return
False
def
getProfilePath
(
projectDir
,
profile
):
def
getProfilePath
(
projectDir
,
profile
):
...
@@ -475,8 +453,11 @@ def getSlapStatus(config):
...
@@ -475,8 +453,11 @@ def getSlapStatus(config):
def
svcStopAll
(
config
):
def
svcStopAll
(
config
):
"""Stop all Instance processes on this computer"""
"""Stop all Instance processes on this computer"""
return
Popen
([
config
[
'supervisor'
],
config
[
'configuration_file_path'
],
try
:
'shutdown'
]).
communicate
()[
0
]
return
Popen
([
config
[
'supervisor'
],
config
[
'configuration_file_path'
],
'shutdown'
]).
communicate
()[
0
]
except
:
pass
def
removeInstanceRoot
(
config
):
def
removeInstanceRoot
(
config
):
...
@@ -566,10 +547,8 @@ def configNewSR(config, projectpath):
...
@@ -566,10 +547,8 @@ def configNewSR(config, projectpath):
"""
"""
folder = realpath(config, projectpath)
folder = realpath(config, projectpath)
if folder:
if folder:
if isInstanceRunning():
sup_process.stopProcess(config, '
slapgrid
-
cp
')
killRunningProcess('
slapgrid
-
cp
')
sup_process.stopProcess(config, '
slapgrid
-
sr
')
if isSoftwareRunning():
killRunningProcess('
slapgrid
-
sr
')
stopProxy(config)
stopProxy(config)
removeProxyDb(config)
removeProxyDb(config)
startProxy(config)
startProxy(config)
...
@@ -661,7 +640,7 @@ def removeSoftwareByName(config, md5, folderName):
...
@@ -661,7 +640,7 @@ def removeSoftwareByName(config, md5, folderName):
config: slaprunner configuration
config: slaprunner configuration
foldername: the link name given to the software release
foldername: the link name given to the software release
md5: the md5 filename given by slapgrid to SR folder"""
md5: the md5 filename given by slapgrid to SR folder"""
if isSoftwareRunning(
) or isInstanceRunning(
):
if isSoftwareRunning(
config) or isInstanceRunning(config
):
raise Exception("Software installation or instantiation in progress, cannot remove")
raise Exception("Software installation or instantiation in progress, cannot remove")
path = os.path.join(config['
software_root
'], md5)
path = os.path.join(config['
software_root
'], md5)
linkpath = os.path.join(config['
software_link
'], folderName)
linkpath = os.path.join(config['
software_link
'], folderName)
...
@@ -899,8 +878,9 @@ def runSlapgridUntilSuccess(config, step):
...
@@ -899,8 +878,9 @@ def runSlapgridUntilSuccess(config, step):
# XXX-Nico runSoftwareWithLock can return 0 or False (0==False)
# XXX-Nico runSoftwareWithLock can return 0 or False (0==False)
while counter > 0:
while counter > 0:
counter -= 1
counter -= 1
slapgrid = runSlapgridWithLock(config)
slapgrid = runSlapgridWithLock(config, lock=True)
if slapgrid:
# slapgrid == 0 because EXIT_SUCCESS == 0
if slapgrid == 0:
break
break
times_left = int(open(counter_file).read()) - 1
times_left = int(open(counter_file).read()) - 1
if times_left > 0 :
if times_left > 0 :
...
@@ -911,7 +891,7 @@ def runSlapgridUntilSuccess(config, step):
...
@@ -911,7 +891,7 @@ def runSlapgridUntilSuccess(config, step):
max_tries -= counter
max_tries -= counter
# run instance only if we are deploying the software release,
# run instance only if we are deploying the software release,
# if it is defined so, and sr is correctly deployed
# if it is defined so, and sr is correctly deployed
if step == "software" and params['
run_instance
'] and slapgrid:
if step == "software" and params['
run_instance
'] and slapgrid
== 0
:
return (max_tries, runSlapgridUntilSuccess(config, "instance"))
return (max_tries, runSlapgridUntilSuccess(config, "instance"))
else:
else:
return max_tries
return max_tries
...
...
slapos/runner/views.py
View file @
c58dd749
...
@@ -7,13 +7,13 @@ import json
...
@@ -7,13 +7,13 @@ import json
import
os
import
os
import
shutil
import
shutil
import
subprocess
import
subprocess
import
sup_process
import
thread
import
thread
import
urllib
import
urllib
from
flask
import
(
Flask
,
request
,
redirect
,
url_for
,
render_template
,
from
flask
import
(
Flask
,
request
,
redirect
,
url_for
,
render_template
,
g
,
flash
,
jsonify
,
session
,
abort
,
send_file
)
g
,
flash
,
jsonify
,
session
,
abort
,
send_file
)
from
slapos.runner.process
import
killRunningProcess
from
slapos.runner.utils
import
(
checkSoftwareFolder
,
configNewSR
,
from
slapos.runner.utils
import
(
checkSoftwareFolder
,
configNewSR
,
createNewUser
,
getBuildAndRunParams
,
createNewUser
,
getBuildAndRunParams
,
getProfilePath
,
getSlapgridResult
,
getProfilePath
,
getSlapgridResult
,
...
@@ -25,8 +25,7 @@ from slapos.runner.utils import (checkSoftwareFolder, configNewSR,
...
@@ -25,8 +25,7 @@ from slapos.runner.utils import (checkSoftwareFolder, configNewSR,
loadSoftwareRList
,
md5sum
,
newSoftware
,
loadSoftwareRList
,
md5sum
,
newSoftware
,
readFileFrom
,
readParameters
,
realpath
,
readFileFrom
,
readParameters
,
realpath
,
removeInstanceRoot
,
removeProxyDb
,
removeInstanceRoot
,
removeProxyDb
,
removeSoftwareByName
,
runInstanceWithLock
,
removeSoftwareByName
,
runSlapgridUntilSuccess
,
runSoftwareWithLock
,
runSlapgridUntilSuccess
,
saveSession
,
saveBuildAndRunParams
,
saveSession
,
saveBuildAndRunParams
,
setMiniShellHistory
,
setMiniShellHistory
,
svcStartStopProcess
,
svcStopAll
,
tail
,
svcStartStopProcess
,
svcStopAll
,
tail
,
...
@@ -403,6 +402,14 @@ def getProjectDiff():
...
@@ -403,6 +402,14 @@ def getProjectDiff():
result
=
"Error: No such file or directory. PERMISSION DENIED!"
)
result
=
"Error: No such file or directory. PERMISSION DENIED!"
)
def
commitProjectFiles
():
path
=
realpath
(
app
.
config
,
request
.
form
[
'project'
])
if
path
:
return
gitCommit
(
path
,
request
.
form
[
'msg'
])
else
:
return
jsonify
(
code
=
0
,
result
=
"Can not read folder: Permission Denied"
)
def
pushProjectFiles
():
def
pushProjectFiles
():
path
=
realpath
(
app
.
config
,
request
.
form
[
'project'
])
path
=
realpath
(
app
.
config
,
request
.
form
[
'project'
])
if
path
:
if
path
:
...
@@ -470,7 +477,7 @@ def slapgridResult():
...
@@ -470,7 +477,7 @@ def slapgridResult():
def
stopSlapgrid
():
def
stopSlapgrid
():
counter_file
=
os
.
path
.
join
(
app
.
config
[
'runner_workdir'
],
'.turn-left'
)
counter_file
=
os
.
path
.
join
(
app
.
config
[
'runner_workdir'
],
'.turn-left'
)
open
(
counter_file
,
'w+'
).
write
(
str
(
0
))
open
(
counter_file
,
'w+'
).
write
(
str
(
0
))
result
=
killRunningProcess
(
request
.
form
[
'type'
])
result
=
sup_process
.
killRunningProcess
(
app
.
config
,
request
.
form
[
'type'
])
return
jsonify
(
result
=
result
)
return
jsonify
(
result
=
result
)
...
@@ -787,6 +794,8 @@ app.add_url_rule("/slapgridResult", 'slapgridResult',
...
@@ -787,6 +794,8 @@ app.add_url_rule("/slapgridResult", 'slapgridResult',
app
.
add_url_rule
(
"/getmd5sum"
,
'getmd5sum'
,
getmd5sum
,
methods
=
[
'POST'
])
app
.
add_url_rule
(
"/getmd5sum"
,
'getmd5sum'
,
getmd5sum
,
methods
=
[
'POST'
])
app
.
add_url_rule
(
"/checkFileType"
,
'checkFileType'
,
checkFileType
,
app
.
add_url_rule
(
"/checkFileType"
,
'checkFileType'
,
checkFileType
,
methods
=
[
'POST'
])
methods
=
[
'POST'
])
app
.
add_url_rule
(
"/commitProjectFiles"
,
'commitProjectFiles'
,
commitProjectFiles
,
methods
=
[
'POST'
])
app
.
add_url_rule
(
"/pullProjectFiles"
,
'pullProjectFiles'
,
pullProjectFiles
,
app
.
add_url_rule
(
"/pullProjectFiles"
,
'pullProjectFiles'
,
pullProjectFiles
,
methods
=
[
'POST'
])
methods
=
[
'POST'
])
app
.
add_url_rule
(
"/pushProjectFiles"
,
'pushProjectFiles'
,
pushProjectFiles
,
app
.
add_url_rule
(
"/pushProjectFiles"
,
'pushProjectFiles'
,
pushProjectFiles
,
...
...
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