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
Titouan Soulard
slapos.core
Commits
7298da38
Commit
7298da38
authored
Nov 14, 2024
by
Alain Takoudjou
Browse files
Options
Browse Files
Download
Plain Diff
slapos.grid: copy .netrc file to buildout home path
See merge request
!696
parents
66d7d1cb
e5ea6d74
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
70 additions
and
0 deletions
+70
-0
slapos/grid/utils.py
slapos/grid/utils.py
+17
-0
slapos/tests/test_slapgrid.py
slapos/tests/test_slapgrid.py
+53
-0
No files found.
slapos/grid/utils.py
View file @
7298da38
...
...
@@ -39,6 +39,7 @@ import logging
import
psutil
import
shlex
import
time
import
shutil
if
sys
.
version_info
>=
(
3
,):
import
selectors
...
...
@@ -252,6 +253,20 @@ def getCleanEnvironment(logger, home_path='/tmp'):
logger
.
debug
(
'Removed from environment: %s'
,
', '
.
join
(
sorted
(
removed_env
)))
return
env
def
copyNetrcFile
(
dest_path
):
user_home
=
os
.
environ
[
'HOME'
]
netrc_file
=
os
.
path
.
join
(
user_home
,
'.netrc'
)
buildout_netrc
=
os
.
path
.
join
(
dest_path
,
'.netrc'
)
if
os
.
path
.
abspath
(
netrc_file
)
==
buildout_netrc
:
return
if
os
.
path
.
exists
(
netrc_file
):
shutil
.
copyfile
(
netrc_file
,
buildout_netrc
)
os
.
chmod
(
buildout_netrc
,
0o600
)
def
cleanupNetrcFile
(
dest_path
):
buildout_netrc
=
os
.
path
.
join
(
dest_path
,
'.netrc'
)
if
os
.
path
.
exists
(
buildout_netrc
):
os
.
unlink
(
buildout_netrc
)
def
setRunning
(
logger
,
pidfile
):
"""Creates a pidfile. If a pidfile already exists, we exit"""
...
...
@@ -440,6 +455,7 @@ def launchBuildout(path, buildout_binary, logger,
path
))
if
timeout
is
not
None
:
logger
.
debug
(
'Launching buildout with %ss timeout'
,
timeout
)
copyNetrcFile
(
path
)
process_handler
=
SlapPopen
(
invocation_list
,
preexec_fn
=
lambda
:
dropPrivileges
(
uid
,
gid
,
logger
=
logger
),
cwd
=
path
,
...
...
@@ -456,6 +472,7 @@ def launchBuildout(path, buildout_binary, logger,
logger
.
exception
(
exc
)
raise
BuildoutFailedError
(
exc
)
finally
:
cleanupNetrcFile
(
path
)
old_umask
=
os
.
umask
(
umask
)
logger
.
debug
(
'Restore umask from %03o to %03o'
%
(
old_umask
,
umask
))
...
...
slapos/tests/test_slapgrid.py
View file @
7298da38
...
...
@@ -2224,6 +2224,14 @@ class TestSlapgridUsageReport(MasterMixin, unittest.TestCase):
class
TestSlapgridSoftwareRelease
(
MasterMixin
,
unittest
.
TestCase
):
def
setUp
(
self
):
MasterMixin
.
setUp
(
self
)
self
.
orginal_home
=
os
.
environ
[
'HOME'
]
os
.
environ
[
'HOME'
]
=
self
.
_tempdir
def
tearDown
(
self
):
os
.
environ
[
'HOME'
]
=
self
.
orginal_home
fake_waiting_time
=
0.05
def
test_one_software_buildout_fail_is_correctly_logged
(
self
):
"""
...
...
@@ -2291,6 +2299,51 @@ chmod a-rxw directory
self
.
launchSlapgridSoftware
()
self
.
assertEqual
(
os
.
listdir
(
self
.
software_root
),
[])
def
test_build_software_with_netrc
(
self
):
computer
=
self
.
getTestComputerClass
()(
self
.
software_root
,
self
.
instance_root
,
1
,
1
)
home
=
os
.
environ
[
'HOME'
]
netrc_file
=
os
.
path
.
join
(
home
,
'.netrc'
)
with
open
(
netrc_file
,
'w'
)
as
f
:
f
.
write
(
'machine localhost login foo password bar'
)
with
open
(
os
.
path
.
join
(
home
,
'testing'
),
'w'
)
as
f
:
f
.
write
(
'this is not buildout home'
)
os
.
chmod
(
netrc_file
,
0o600
)
with
httmock
.
HTTMock
(
computer
.
request_handler
):
software
=
computer
.
software_list
[
0
]
software_path
=
os
.
path
.
join
(
self
.
software_root
,
software
.
software_hash
)
buildout_netrc
=
os
.
path
.
join
(
software_path
,
'.netrc'
)
test_file
=
os
.
path
.
join
(
software_path
,
'd/file'
)
command
=
"""#!/bin/sh
mkdir -p d
if [ -s "$HOME/testing" ]; then
echo "testing file exists"
exit 1
fi
if [ -s "$HOME/.netrc" ]; then
cp $HOME/.netrc d/file
else
echo ".netrc file not found"
rm -f d/file
fi
"""
software
.
setBuildout
(
command
)
self
.
launchSlapgridSoftware
()
self
.
assertTrue
(
os
.
path
.
exists
(
netrc_file
))
self
.
assertFalse
(
os
.
path
.
exists
(
buildout_netrc
))
self
.
assertTrue
(
os
.
path
.
exists
(
test_file
))
with
open
(
test_file
)
as
f
:
content
=
f
.
read
()
self
.
assertEqual
(
content
,
'machine localhost login foo password bar'
)
completed
=
os
.
path
.
join
(
software_path
,
'.completed'
)
os
.
remove
(
netrc_file
)
# force rerun of software
os
.
remove
(
completed
)
self
.
launchSlapgridSoftware
()
self
.
assertFalse
(
os
.
path
.
exists
(
buildout_netrc
))
self
.
assertFalse
(
os
.
path
.
exists
(
test_file
))
class
SlapgridInitialization
(
unittest
.
TestCase
):
"""
...
...
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