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
Boxiang Sun
slapos.core
Commits
5c613eb5
Commit
5c613eb5
authored
May 29, 2013
by
Marco Mariani
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
whitespace, indentation, light cleanup
parent
630ed441
Changes
6
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
405 additions
and
361 deletions
+405
-361
slapos/tests/slap.py
slapos/tests/slap.py
+131
-102
slapos/tests/slapformat.py
slapos/tests/slapformat.py
+21
-9
slapos/tests/slapgrid.py
slapos/tests/slapgrid.py
+98
-99
slapos/tests/slapobject.py
slapos/tests/slapobject.py
+57
-54
slapos/tests/slapproxy.py
slapos/tests/slapproxy.py
+97
-97
slapos/tests/util.py
slapos/tests/util.py
+1
-0
No files found.
slapos/tests/slap.py
View file @
5c613eb5
This diff is collapsed.
Click to expand it.
slapos/tests/slapformat.py
View file @
5c613eb5
...
...
@@ -45,9 +45,11 @@ USER_LIST = []
GROUP_LIST
=
[]
INTERFACE_DICT
=
{}
class
FakeConfig
:
pass
class
TestLoggerHandler
(
logging
.
Handler
):
def
__init__
(
self
,
*
args
,
**
kwargs
):
self
.
bucket
=
[]
...
...
@@ -56,6 +58,7 @@ class TestLoggerHandler(logging.Handler):
def
emit
(
self
,
record
):
self
.
bucket
.
append
(
record
.
msg
)
class
FakeCallAndRead
:
def
__init__
(
self
):
self
.
external_command_list
=
[]
...
...
@@ -89,6 +92,7 @@ class FakeCallAndRead:
self
.
external_command_list
.
append
(
' '
.
join
(
argument_list
))
return
retval
class
LoggableWrapper
:
def
__init__
(
self
,
logger
,
name
):
self
.
__logger
=
logger
...
...
@@ -99,11 +103,13 @@ class LoggableWrapper:
'%s=%r'
%
(
x
,
y
)
for
x
,
y
in
kwargs
.
iteritems
()]
self
.
__logger
.
debug
(
'%s(%s)'
%
(
self
.
__name
,
', '
.
join
(
arg_list
)))
class
TimeMock
:
@
classmethod
def
sleep
(
self
,
seconds
):
return
class
GrpMock
:
@
classmethod
def
getgrnam
(
self
,
name
):
...
...
@@ -112,6 +118,7 @@ class GrpMock:
return
True
raise
KeyError
class
PwdMock
:
@
classmethod
def
getpwnam
(
self
,
name
):
...
...
@@ -123,6 +130,7 @@ class PwdMock:
return
result
raise
KeyError
class
NetifacesMock
:
@
classmethod
def
ifaddresses
(
self
,
name
):
...
...
@@ -136,12 +144,14 @@ class NetifacesMock:
global
INTERFACE_DICT
return
INTERFACE_DICT
.
keys
()
class
SlapformatMixin
(
unittest
.
TestCase
):
# keep big diffs
maxDiff
=
None
def
patchNetifaces
(
self
):
self
.
netifaces
=
NetifacesMock
()
self
.
saved_netifaces
=
dict
()
self
.
saved_netifaces
=
{}
for
fake
in
vars
(
NetifacesMock
):
self
.
saved_netifaces
[
fake
]
=
getattr
(
netifaces
,
fake
,
None
)
setattr
(
netifaces
,
fake
,
getattr
(
self
.
netifaces
,
fake
))
...
...
@@ -152,7 +162,7 @@ class SlapformatMixin(unittest.TestCase):
del
self
.
saved_netifaces
def
patchPwd
(
self
):
self
.
saved_pwd
=
dict
()
self
.
saved_pwd
=
{}
for
fake
in
vars
(
PwdMock
):
self
.
saved_pwd
[
fake
]
=
getattr
(
pwd
,
fake
,
None
)
setattr
(
pwd
,
fake
,
getattr
(
PwdMock
,
fake
))
...
...
@@ -163,7 +173,7 @@ class SlapformatMixin(unittest.TestCase):
del
self
.
saved_pwd
def
patchTime
(
self
):
self
.
saved_time
=
dict
()
self
.
saved_time
=
{}
for
fake
in
vars
(
TimeMock
):
self
.
saved_time
[
fake
]
=
getattr
(
time
,
fake
,
None
)
setattr
(
time
,
fake
,
getattr
(
TimeMock
,
fake
))
...
...
@@ -174,7 +184,7 @@ class SlapformatMixin(unittest.TestCase):
del
self
.
saved_time
def
patchGrp
(
self
):
self
.
saved_grp
=
dict
()
self
.
saved_grp
=
{}
for
fake
in
vars
(
GrpMock
):
self
.
saved_grp
[
fake
]
=
getattr
(
grp
,
fake
,
None
)
setattr
(
grp
,
fake
,
getattr
(
GrpMock
,
fake
))
...
...
@@ -185,7 +195,7 @@ class SlapformatMixin(unittest.TestCase):
del
self
.
saved_grp
def
patchOs
(
self
,
logger
):
self
.
saved_os
=
dict
()
self
.
saved_os
=
{}
for
fake
in
[
'mkdir'
,
'chown'
,
'chmod'
,
'makedirs'
]:
self
.
saved_os
[
fake
]
=
getattr
(
os
,
fake
,
None
)
f
=
LoggableWrapper
(
logger
,
fake
)
...
...
@@ -231,6 +241,7 @@ class SlapformatMixin(unittest.TestCase):
self
.
restoreNetifaces
()
slapos
.
format
.
callAndRead
=
self
.
real_callAndRead
class
TestComputer
(
SlapformatMixin
):
def
test_getAddress_empty_computer
(
self
):
computer
=
slapos
.
format
.
Computer
(
'computer'
)
...
...
@@ -276,9 +287,8 @@ class TestComputer(SlapformatMixin):
"makedirs('/software_root', 493)"
,
"chmod('/software_root', 493)"
],
self
.
test_result
.
bucket
)
self
.
assertEqual
([
'ip addr list bridge'
,],
self
.
fakeCallAndRead
.
external_command_list
)
self
.
assertEqual
([
'ip addr list bridge'
],
self
.
fakeCallAndRead
.
external_command_list
)
@
unittest
.
skip
(
"Not implemented"
)
def
test_construct_empty_prepared_no_alter_network
(
self
):
...
...
@@ -377,7 +387,7 @@ class TestComputer(SlapformatMixin):
partition
=
slapos
.
format
.
Partition
(
'partition'
,
'/part_path'
,
slapos
.
format
.
User
(
'testuser'
),
[],
None
)
global
USER_LIST
USER_LIST
=
[
'testuser'
]
USER_LIST
=
[
'testuser'
]
partition
.
tap
=
slapos
.
format
.
Tap
(
'tap'
)
computer
.
partition_list
=
[
partition
]
global
INTERFACE_DICT
...
...
@@ -488,6 +498,7 @@ class TestComputer(SlapformatMixin):
],
self
.
fakeCallAndRead
.
external_command_list
)
class
TestPartition
(
SlapformatMixin
):
def
test_createPath
(
self
):
...
...
@@ -513,6 +524,7 @@ class TestPartition(SlapformatMixin):
self
.
test_result
.
bucket
)
class
TestUser
(
SlapformatMixin
):
def
test_create
(
self
):
user
=
slapos
.
format
.
User
(
'doesnotexistsyet'
)
...
...
slapos/tests/slapgrid.py
View file @
5c613eb5
This diff is collapsed.
Click to expand it.
slapos/tests/slapobject.py
View file @
5c613eb5
...
...
@@ -53,6 +53,7 @@ originalBootstrapBuildout = utils.bootstrapBuildout
originalLaunchBuildout
=
utils
.
launchBuildout
originalUploadSoftwareRelease
=
SlapObject
.
Software
.
uploadSoftwareRelease
class
TestSoftwareSlapObject
(
BasicMixin
,
unittest
.
TestCase
):
"""
Test for Software class.
...
...
@@ -92,17 +93,17 @@ class TestSoftwareSlapObject(BasicMixin, unittest.TestCase):
Check if the networkcache parameters are propagated.
"""
software
=
SlapObject
.
Software
(
url
=
'http://example.com/software.cfg'
,
software_root
=
self
.
software_root
,
buildout
=
self
.
buildout
,
logger
=
logging
.
getLogger
(),
signature_private_key_file
=
'/signature/private/key_file'
,
upload_cache_url
=
'http://example.com/uploadcache'
,
upload_dir_url
=
'http://example.com/uploaddir'
,
shacache_cert_file
=
self
.
shacache_cert_file
,
shacache_key_file
=
self
.
shacache_key_file
,
shadir_cert_file
=
self
.
shadir_cert_file
,
shadir_key_file
=
self
.
shadir_key_file
)
url
=
'http://example.com/software.cfg'
,
software_root
=
self
.
software_root
,
buildout
=
self
.
buildout
,
logger
=
logging
.
getLogger
(),
signature_private_key_file
=
'/signature/private/key_file'
,
upload_cache_url
=
'http://example.com/uploadcache'
,
upload_dir_url
=
'http://example.com/uploaddir'
,
shacache_cert_file
=
self
.
shacache_cert_file
,
shacache_key_file
=
self
.
shacache_key_file
,
shadir_cert_file
=
self
.
shadir_cert_file
,
shadir_key_file
=
self
.
shadir_key_file
)
software
.
install
()
...
...
@@ -121,23 +122,21 @@ class TestSoftwareSlapObject(BasicMixin, unittest.TestCase):
Check if the networkcache parameters are not propagated if they are not
available.
"""
software
=
SlapObject
.
Software
(
url
=
'http://example.com/software.cfg'
,
software_root
=
self
.
software_root
,
buildout
=
self
.
buildout
,
logger
=
logging
.
getLogger
())
software
=
SlapObject
.
Software
(
url
=
'http://example.com/software.cfg'
,
software_root
=
self
.
software_root
,
buildout
=
self
.
buildout
,
logger
=
logging
.
getLogger
())
software
.
install
()
command_list
=
FakeCallAndRead
.
external_command_list
self
.
assert
False
(
'buildout:networkcache-section=networkcache'
in
command_list
)
self
.
assertFalse
(
'networkcache:signature-private-key-file=%s'
%
self
.
signature_private_key_file
in
command_list
)
self
.
assert
False
(
'networkcache:upload-cache-url=%s'
%
self
.
upload_cache_url
in
command_list
)
self
.
assert
False
(
'networkcache:upload-dir-url=%s'
%
self
.
upload_dir_url
in
command_list
)
self
.
assert
NotIn
(
'buildout:networkcache-section=networkcache'
,
command_list
)
self
.
assertNotIn
(
'networkcache:signature-private-key-file=%s'
%
self
.
signature_private_key_file
,
command_list
)
self
.
assert
NotIn
(
'networkcache:upload-cache-url=%s'
%
self
.
upload_cache_url
,
command_list
)
self
.
assert
NotIn
(
'networkcache:upload-dir-url=%s'
%
self
.
upload_dir_url
,
command_list
)
# XXX-Cedric: do the same with upload
def
test_software_install_networkcache_upload_blacklist
(
self
):
...
...
@@ -146,27 +145,30 @@ class TestSoftwareSlapObject(BasicMixin, unittest.TestCase):
"""
def
fakeBuildout
(
*
args
,
**
kw
):
pass
SlapObject
.
Software
.
_install_from_buildout
=
fakeBuildout
def
fake_upload_network_cached
(
*
args
,
**
kw
):
self
.
assertFalse
(
True
)
networkcache
.
upload_network_cached
=
fake_upload_network_cached
upload_to_binary_cache_url_blacklist
=
[
"http://example.com"
]
software
=
SlapObject
.
Software
(
url
=
'http://example.com/software.cfg'
,
software_root
=
self
.
software_root
,
buildout
=
self
.
buildout
,
logger
=
logging
.
getLogger
(),
signature_private_key_file
=
'/signature/private/key_file'
,
upload_cache_url
=
'http://example.com/uploadcache'
,
upload_dir_url
=
'http://example.com/uploaddir'
,
shacache_cert_file
=
self
.
shacache_cert_file
,
shacache_key_file
=
self
.
shacache_key_file
,
shadir_cert_file
=
self
.
shadir_cert_file
,
shadir_key_file
=
self
.
shadir_key_file
,
upload_to_binary_cache_url_blacklist
=
\
upload_to_binary_cache_url_blacklist
,
url
=
'http://example.com/software.cfg'
,
software_root
=
self
.
software_root
,
buildout
=
self
.
buildout
,
logger
=
logging
.
getLogger
(),
signature_private_key_file
=
'/signature/private/key_file'
,
upload_cache_url
=
'http://example.com/uploadcache'
,
upload_dir_url
=
'http://example.com/uploaddir'
,
shacache_cert_file
=
self
.
shacache_cert_file
,
shacache_key_file
=
self
.
shacache_key_file
,
shadir_cert_file
=
self
.
shadir_cert_file
,
shadir_key_file
=
self
.
shadir_key_file
,
upload_to_binary_cache_url_blacklist
=
upload_to_binary_cache_url_blacklist
,
)
software
.
install
()
...
...
@@ -178,29 +180,30 @@ class TestSoftwareSlapObject(BasicMixin, unittest.TestCase):
def
fakeBuildout
(
*
args
,
**
kw
):
pass
SlapObject
.
Software
.
_install_from_buildout
=
fakeBuildout
def
fakeUploadSoftwareRelease
(
*
args
,
**
kw
):
self
.
uploaded
=
True
SlapObject
.
Software
.
uploadSoftwareRelease
=
fakeUploadSoftwareRelease
SlapObject
.
Software
.
uploadSoftwareRelease
=
fakeUploadSoftwareRelease
upload_to_binary_cache_url_blacklist
=
[
"http://anotherexample.com"
]
software
=
SlapObject
.
Software
(
url
=
'http://example.com/software.cfg'
,
software_root
=
self
.
software_root
,
buildout
=
self
.
buildout
,
logger
=
logging
.
getLogger
(),
signature_private_key_file
=
'/signature/private/key_file'
,
upload_cache_url
=
'http://example.com/uploadcache'
,
upload_dir_url
=
'http://example.com/uploaddir'
,
upload_binary_cache_url
=
'http://example.com/uploadcache'
,
upload_binary_dir_url
=
'http://example.com/uploaddir'
,
shacache_cert_file
=
self
.
shacache_cert_file
,
shacache_key_file
=
self
.
shacache_key_file
,
shadir_cert_file
=
self
.
shadir_cert_file
,
shadir_key_file
=
self
.
shadir_key_file
,
upload_to_binary_cache_url_blacklist
=
\
upload_to_binary_cache_url_blacklist
,
url
=
'http://example.com/software.cfg'
,
software_root
=
self
.
software_root
,
buildout
=
self
.
buildout
,
logger
=
logging
.
getLogger
(),
signature_private_key_file
=
'/signature/private/key_file'
,
upload_cache_url
=
'http://example.com/uploadcache'
,
upload_dir_url
=
'http://example.com/uploaddir'
,
upload_binary_cache_url
=
'http://example.com/uploadcache'
,
upload_binary_dir_url
=
'http://example.com/uploaddir'
,
shacache_cert_file
=
self
.
shacache_cert_file
,
shacache_key_file
=
self
.
shacache_key_file
,
shadir_cert_file
=
self
.
shadir_cert_file
,
shadir_key_file
=
self
.
shadir_key_file
,
upload_to_binary_cache_url_blacklist
=
upload_to_binary_cache_url_blacklist
,
)
software
.
install
()
self
.
assertTrue
(
getattr
(
self
,
'uploaded'
,
False
))
slapos/tests/slapproxy.py
View file @
5c613eb5
This diff is collapsed.
Click to expand it.
slapos/tests/util.py
View file @
5c613eb5
...
...
@@ -29,6 +29,7 @@ import slapos.util
import
tempfile
import
unittest
class
TestMkdirP
(
unittest
.
TestCase
):
"""
Tests methods available in the slapos.util module.
...
...
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