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
Carlos Ramos Carreño
slapos.core
Commits
e5ad44c2
Commit
e5ad44c2
authored
Jun 06, 2013
by
Cédric de Saint Martin
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'chownDirectory'
Conflicts: slapos/format.py
parents
2e1a7478
d671e3d5
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
65 additions
and
3 deletions
+65
-3
slapos/format.py
slapos/format.py
+4
-3
slapos/tests/util.py
slapos/tests/util.py
+54
-0
slapos/util.py
slapos/util.py
+7
-0
No files found.
slapos/format.py
View file @
e5ad44c2
...
...
@@ -52,6 +52,7 @@ import zipfile
import
lxml.etree
import
xml_marshaller.xml_marshaller
from
slapos.util
import
chownDirectory
from
slapos.util
import
mkdir_p
import
slapos.slap
as
slap
...
...
@@ -386,7 +387,7 @@ class Computer(object):
if
alter_user
:
slapsoft
.
create
()
slapsoft_pw
=
pwd
.
getpwnam
(
slapsoft
.
name
)
os
.
chown
(
self
.
software_root
,
slapsoft_pw
.
pw_uid
,
slapsoft_pw
.
pw_gid
)
chownDirectory
(
slapsoft
.
path
,
slapsoft_pw
.
pw_uid
,
slapsoft_pw
.
pw_gid
)
os
.
chmod
(
self
.
software_root
,
0o755
)
# Speed hack:
...
...
@@ -513,8 +514,8 @@ class Partition(object):
os
.
mkdir
(
self
.
path
,
0o750
)
if
alter_user
:
owner_pw
=
pwd
.
getpwnam
(
owner
.
name
)
os
.
chown
(
self
.
path
,
owner_pw
.
pw_uid
,
owner_pw
.
pw_gid
)
os
.
chmod
(
self
.
path
,
0o75
0
)
chownDirectory
(
self
.
path
,
owner_pw
.
pw_uid
,
owner_pw
.
pw_gid
)
os
.
chmod
(
self
.
path
,
0o75
5
)
class
User
(
object
):
...
...
slapos/tests/util.py
View file @
e5ad44c2
...
...
@@ -28,6 +28,8 @@ import os
import
slapos.util
import
tempfile
import
unittest
import
shutil
from
pwd
import
getpwnam
class
TestMkdirP
(
unittest
.
TestCase
):
...
...
@@ -43,6 +45,7 @@ class TestMkdirP(unittest.TestCase):
wanted_directory
=
os
.
path
.
join
(
root_directory
,
'foo'
,
'bar'
)
slapos
.
util
.
mkdir_p
(
wanted_directory
)
self
.
assertTrue
(
os
.
path
.
isdir
(
wanted_directory
))
shutil
.
rmtree
(
root_directory
)
def
test_mkdir_already_existing
(
self
):
"""
...
...
@@ -51,7 +54,58 @@ class TestMkdirP(unittest.TestCase):
root_directory
=
tempfile
.
mkdtemp
()
slapos
.
util
.
mkdir_p
(
root_directory
)
self
.
assertTrue
(
os
.
path
.
isdir
(
root_directory
))
shutil
.
rmtree
(
root_directory
)
def
test_chown_directory
(
self
):
"""
Test that slapos.util.chownDirectory correctly changes owner.
Note: requires root privileges.
"""
root_slaptest
=
tempfile
.
mkdtemp
()
wanted_directory0
=
os
.
path
.
join
(
root_slaptest
,
'slap-write0'
)
wanted_directory1
=
os
.
path
.
join
(
root_slaptest
,
'slap-write0'
,
'write-slap1'
)
wanted_directory2
=
os
.
path
.
join
(
root_slaptest
,
'slap-write0'
,
'write-slap1'
,
'write-teste2'
)
wanted_directory_mkdir0
=
os
.
makedirs
(
wanted_directory0
,
mode
=
0777
)
wanted_directory_mkdir1
=
os
.
makedirs
(
wanted_directory1
,
mode
=
0777
)
wanted_directory_mkdir2
=
os
.
makedirs
(
wanted_directory2
,
mode
=
0777
)
create_file_txt
=
tempfile
.
mkstemp
(
suffix
=
'.txt'
,
prefix
=
'tmp'
,
dir
=
wanted_directory2
,
text
=
True
)
user
=
'nobody'
try
:
uid
=
getpwnam
(
user
)[
2
]
gid
=
getpwnam
(
user
)[
3
]
except
KeyError
:
raise
unittest
.
SkipTest
(
"user %s doesn't exist."
%
user
)
try
:
slapos
.
util
.
chownDirectory
(
root_slaptest
,
uid
,
gid
)
except
OSError
:
raise
unittest
.
SkipTest
(
"No root privileges, impossible to chown."
)
uid_check_root_slaptest
=
os
.
stat
(
root_slaptest
)[
4
]
gid_check_root_slaptest
=
os
.
stat
(
root_slaptest
)[
5
]
self
.
assertTrue
(
uid
==
uid_check_root_slaptest
)
self
.
assertTrue
(
gid
==
gid_check_root_slaptest
)
uid_check_wanted_directory0
=
os
.
stat
(
wanted_directory0
)[
4
]
gid_check_wanted_directory0
=
os
.
stat
(
wanted_directory0
)[
5
]
self
.
assertTrue
(
uid
==
uid_check_wanted_directory0
)
self
.
assertTrue
(
gid
==
gid_check_wanted_directory0
)
uid_check_wanted_directory1
=
os
.
stat
(
wanted_directory1
)[
4
]
gid_check_wanted_directory1
=
os
.
stat
(
wanted_directory1
)[
5
]
self
.
assertTrue
(
uid
==
uid_check_wanted_directory1
)
self
.
assertTrue
(
gid
==
gid_check_wanted_directory1
)
uid_check_wanted_directory2
=
os
.
stat
(
wanted_directory2
)[
4
]
gid_check_wanted_directory2
=
os
.
stat
(
wanted_directory2
)[
5
]
self
.
assertTrue
(
uid
==
uid_check_wanted_directory2
)
self
.
assertTrue
(
gid
==
gid_check_wanted_directory2
)
uid_check_file_txt
=
os
.
stat
(
create_file_txt
[
1
])[
4
]
gid_check_file_txt
=
os
.
stat
(
create_file_txt
[
1
])[
5
]
self
.
assertTrue
(
uid
==
uid_check_file_txt
)
self
.
assertTrue
(
gid
==
gid_check_file_txt
)
shutil
.
rmtree
(
root_slaptest
)
if
__name__
==
'__main__'
:
unittest
.
main
()
slapos/util.py
View file @
e5ad44c2
...
...
@@ -17,3 +17,10 @@ def mkdir_p(path, mode=0o777):
else
:
raise
def
chownDirectory
(
path
,
uid
,
gid
):
os
.
chown
(
path
,
uid
,
gid
)
for
root
,
dirs
,
files
in
os
.
walk
(
path
):
for
items
in
dirs
,
files
:
for
item
in
items
:
if
not
os
.
path
.
islink
(
os
.
path
.
join
(
root
,
item
)):
os
.
chown
(
os
.
path
.
join
(
root
,
item
),
uid
,
gid
)
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