Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
slapos.core
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
Roque
slapos.core
Commits
0d691d7f
Commit
0d691d7f
authored
May 05, 2023
by
Xavier Thompson
Browse files
Options
Browse Files
Download
Plain Diff
grid/utils: Improve parsing of instance's python
See merge request
!520
parents
f9f4510e
06e9266d
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
34 additions
and
2 deletions
+34
-2
slapos/grid/utils.py
slapos/grid/utils.py
+8
-2
slapos/tests/test_grid_utils.py
slapos/tests/test_grid_utils.py
+26
-0
No files found.
slapos/grid/utils.py
View file @
0d691d7f
...
...
@@ -37,6 +37,7 @@ import stat
import
sys
import
logging
import
psutil
import
shlex
import
time
if
sys
.
version_info
>=
(
3
,):
...
...
@@ -221,10 +222,15 @@ def getPythonExecutableFromSoftwarePath(software_path):
try
:
with
open
(
os
.
path
.
join
(
software_path
,
'bin'
,
'buildout'
))
as
f
:
shebang
=
f
.
readline
()
if
shebang
.
startswith
(
'#!'
):
executable
=
shebang
[
2
:].
split
(
None
,
1
)[
0
]
if
executable
==
'/bin/sh'
:
exec_wrapper
=
shlex
.
split
(
f
.
readline
())
if
len
(
exec_wrapper
)
>=
2
and
exec_wrapper
[
0
]
==
'exec'
:
return
exec_wrapper
[
1
]
return
executable
except
(
IOError
,
OSError
):
return
if
shebang
.
startswith
(
'#!'
):
return
shebang
[
2
:].
split
(
None
,
1
)[
0
]
def
getCleanEnvironment
(
logger
,
home_path
=
'/tmp'
):
...
...
slapos/tests/test_grid_utils.py
View file @
0d691d7f
...
...
@@ -40,6 +40,7 @@ else:
import
subprocess32
as
subprocess
import
mock
import
six
import
slapos.grid.utils
...
...
@@ -473,3 +474,28 @@ class TestSetRunning(unittest.TestCase):
tf
.
name
)
with
open
(
tf
.
name
)
as
f
:
self
.
assertEqual
(
f
.
read
(),
str
(
os
.
getpid
()))
@
unittest
.
skipIf
(
six
.
PY2
,
"Python3 only"
)
class
TestGetPythonExecutableFromBinBuildout
(
unittest
.
TestCase
):
def
test_simple_shebang
(
self
):
with
tempfile
.
TemporaryDirectory
()
as
d
:
binpath
=
os
.
path
.
join
(
d
,
'bin'
)
python
=
os
.
path
.
realpath
(
os
.
path
.
join
(
d
,
'python'
))
os
.
mkdir
(
binpath
)
with
open
(
os
.
path
.
join
(
binpath
,
'buildout'
),
'w'
)
as
f
:
f
.
write
(
'#!'
+
python
)
self
.
assertEqual
(
slapos
.
grid
.
utils
.
getPythonExecutableFromSoftwarePath
(
d
),
python
)
def
test_exec_wrapper
(
self
):
with
tempfile
.
TemporaryDirectory
()
as
d
:
binpath
=
os
.
path
.
join
(
d
,
'bin'
)
python
=
os
.
path
.
realpath
(
os
.
path
.
join
(
d
,
'python'
))
os
.
mkdir
(
binpath
)
with
open
(
os
.
path
.
join
(
binpath
,
'buildout'
),
'w'
)
as
f
:
f
.
write
(
'#!/bin/sh
\
n
"exec" "%s" "$0" "$@"'
%
python
)
self
.
assertEqual
(
slapos
.
grid
.
utils
.
getPythonExecutableFromSoftwarePath
(
d
),
python
)
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