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
Cédric Le Ninivin
slapos.core
Commits
966e0bb6
Commit
966e0bb6
authored
May 06, 2013
by
Jean-Baptiste Petre
Committed by
Cédric de Saint Martin
Jun 06, 2013
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
unitest read write file for user slapsoft
parent
13602d7a
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
54 additions
and
0 deletions
+54
-0
slapos/tests/util.py
slapos/tests/util.py
+54
-0
No files found.
slapos/tests/util.py
View file @
966e0bb6
...
...
@@ -28,6 +28,8 @@ import os
import
slapos.util
import
tempfile
import
unittest
import
shutil
from
pwd
import
getpwnam
class
TestMkdirP
(
unittest
.
TestCase
):
"""
...
...
@@ -42,6 +44,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
):
"""
...
...
@@ -50,7 +53,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
()
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