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
Labels
Merge Requests
18
Merge Requests
18
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Jobs
Commits
Open sidebar
nexedi
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
Show 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 = []
...
@@ -45,9 +45,11 @@ USER_LIST = []
GROUP_LIST
=
[]
GROUP_LIST
=
[]
INTERFACE_DICT
=
{}
INTERFACE_DICT
=
{}
class
FakeConfig
:
class
FakeConfig
:
pass
pass
class
TestLoggerHandler
(
logging
.
Handler
):
class
TestLoggerHandler
(
logging
.
Handler
):
def
__init__
(
self
,
*
args
,
**
kwargs
):
def
__init__
(
self
,
*
args
,
**
kwargs
):
self
.
bucket
=
[]
self
.
bucket
=
[]
...
@@ -56,6 +58,7 @@ class TestLoggerHandler(logging.Handler):
...
@@ -56,6 +58,7 @@ class TestLoggerHandler(logging.Handler):
def
emit
(
self
,
record
):
def
emit
(
self
,
record
):
self
.
bucket
.
append
(
record
.
msg
)
self
.
bucket
.
append
(
record
.
msg
)
class
FakeCallAndRead
:
class
FakeCallAndRead
:
def
__init__
(
self
):
def
__init__
(
self
):
self
.
external_command_list
=
[]
self
.
external_command_list
=
[]
...
@@ -89,6 +92,7 @@ class FakeCallAndRead:
...
@@ -89,6 +92,7 @@ class FakeCallAndRead:
self
.
external_command_list
.
append
(
' '
.
join
(
argument_list
))
self
.
external_command_list
.
append
(
' '
.
join
(
argument_list
))
return
retval
return
retval
class
LoggableWrapper
:
class
LoggableWrapper
:
def
__init__
(
self
,
logger
,
name
):
def
__init__
(
self
,
logger
,
name
):
self
.
__logger
=
logger
self
.
__logger
=
logger
...
@@ -99,11 +103,13 @@ class LoggableWrapper:
...
@@ -99,11 +103,13 @@ class LoggableWrapper:
'%s=%r'
%
(
x
,
y
)
for
x
,
y
in
kwargs
.
iteritems
()]
'%s=%r'
%
(
x
,
y
)
for
x
,
y
in
kwargs
.
iteritems
()]
self
.
__logger
.
debug
(
'%s(%s)'
%
(
self
.
__name
,
', '
.
join
(
arg_list
)))
self
.
__logger
.
debug
(
'%s(%s)'
%
(
self
.
__name
,
', '
.
join
(
arg_list
)))
class
TimeMock
:
class
TimeMock
:
@
classmethod
@
classmethod
def
sleep
(
self
,
seconds
):
def
sleep
(
self
,
seconds
):
return
return
class
GrpMock
:
class
GrpMock
:
@
classmethod
@
classmethod
def
getgrnam
(
self
,
name
):
def
getgrnam
(
self
,
name
):
...
@@ -112,6 +118,7 @@ class GrpMock:
...
@@ -112,6 +118,7 @@ class GrpMock:
return
True
return
True
raise
KeyError
raise
KeyError
class
PwdMock
:
class
PwdMock
:
@
classmethod
@
classmethod
def
getpwnam
(
self
,
name
):
def
getpwnam
(
self
,
name
):
...
@@ -123,6 +130,7 @@ class PwdMock:
...
@@ -123,6 +130,7 @@ class PwdMock:
return
result
return
result
raise
KeyError
raise
KeyError
class
NetifacesMock
:
class
NetifacesMock
:
@
classmethod
@
classmethod
def
ifaddresses
(
self
,
name
):
def
ifaddresses
(
self
,
name
):
...
@@ -136,12 +144,14 @@ class NetifacesMock:
...
@@ -136,12 +144,14 @@ class NetifacesMock:
global
INTERFACE_DICT
global
INTERFACE_DICT
return
INTERFACE_DICT
.
keys
()
return
INTERFACE_DICT
.
keys
()
class
SlapformatMixin
(
unittest
.
TestCase
):
class
SlapformatMixin
(
unittest
.
TestCase
):
# keep big diffs
# keep big diffs
maxDiff
=
None
maxDiff
=
None
def
patchNetifaces
(
self
):
def
patchNetifaces
(
self
):
self
.
netifaces
=
NetifacesMock
()
self
.
netifaces
=
NetifacesMock
()
self
.
saved_netifaces
=
dict
()
self
.
saved_netifaces
=
{}
for
fake
in
vars
(
NetifacesMock
):
for
fake
in
vars
(
NetifacesMock
):
self
.
saved_netifaces
[
fake
]
=
getattr
(
netifaces
,
fake
,
None
)
self
.
saved_netifaces
[
fake
]
=
getattr
(
netifaces
,
fake
,
None
)
setattr
(
netifaces
,
fake
,
getattr
(
self
.
netifaces
,
fake
))
setattr
(
netifaces
,
fake
,
getattr
(
self
.
netifaces
,
fake
))
...
@@ -152,7 +162,7 @@ class SlapformatMixin(unittest.TestCase):
...
@@ -152,7 +162,7 @@ class SlapformatMixin(unittest.TestCase):
del
self
.
saved_netifaces
del
self
.
saved_netifaces
def
patchPwd
(
self
):
def
patchPwd
(
self
):
self
.
saved_pwd
=
dict
()
self
.
saved_pwd
=
{}
for
fake
in
vars
(
PwdMock
):
for
fake
in
vars
(
PwdMock
):
self
.
saved_pwd
[
fake
]
=
getattr
(
pwd
,
fake
,
None
)
self
.
saved_pwd
[
fake
]
=
getattr
(
pwd
,
fake
,
None
)
setattr
(
pwd
,
fake
,
getattr
(
PwdMock
,
fake
))
setattr
(
pwd
,
fake
,
getattr
(
PwdMock
,
fake
))
...
@@ -163,7 +173,7 @@ class SlapformatMixin(unittest.TestCase):
...
@@ -163,7 +173,7 @@ class SlapformatMixin(unittest.TestCase):
del
self
.
saved_pwd
del
self
.
saved_pwd
def
patchTime
(
self
):
def
patchTime
(
self
):
self
.
saved_time
=
dict
()
self
.
saved_time
=
{}
for
fake
in
vars
(
TimeMock
):
for
fake
in
vars
(
TimeMock
):
self
.
saved_time
[
fake
]
=
getattr
(
time
,
fake
,
None
)
self
.
saved_time
[
fake
]
=
getattr
(
time
,
fake
,
None
)
setattr
(
time
,
fake
,
getattr
(
TimeMock
,
fake
))
setattr
(
time
,
fake
,
getattr
(
TimeMock
,
fake
))
...
@@ -174,7 +184,7 @@ class SlapformatMixin(unittest.TestCase):
...
@@ -174,7 +184,7 @@ class SlapformatMixin(unittest.TestCase):
del
self
.
saved_time
del
self
.
saved_time
def
patchGrp
(
self
):
def
patchGrp
(
self
):
self
.
saved_grp
=
dict
()
self
.
saved_grp
=
{}
for
fake
in
vars
(
GrpMock
):
for
fake
in
vars
(
GrpMock
):
self
.
saved_grp
[
fake
]
=
getattr
(
grp
,
fake
,
None
)
self
.
saved_grp
[
fake
]
=
getattr
(
grp
,
fake
,
None
)
setattr
(
grp
,
fake
,
getattr
(
GrpMock
,
fake
))
setattr
(
grp
,
fake
,
getattr
(
GrpMock
,
fake
))
...
@@ -185,7 +195,7 @@ class SlapformatMixin(unittest.TestCase):
...
@@ -185,7 +195,7 @@ class SlapformatMixin(unittest.TestCase):
del
self
.
saved_grp
del
self
.
saved_grp
def
patchOs
(
self
,
logger
):
def
patchOs
(
self
,
logger
):
self
.
saved_os
=
dict
()
self
.
saved_os
=
{}
for
fake
in
[
'mkdir'
,
'chown'
,
'chmod'
,
'makedirs'
]:
for
fake
in
[
'mkdir'
,
'chown'
,
'chmod'
,
'makedirs'
]:
self
.
saved_os
[
fake
]
=
getattr
(
os
,
fake
,
None
)
self
.
saved_os
[
fake
]
=
getattr
(
os
,
fake
,
None
)
f
=
LoggableWrapper
(
logger
,
fake
)
f
=
LoggableWrapper
(
logger
,
fake
)
...
@@ -231,6 +241,7 @@ class SlapformatMixin(unittest.TestCase):
...
@@ -231,6 +241,7 @@ class SlapformatMixin(unittest.TestCase):
self
.
restoreNetifaces
()
self
.
restoreNetifaces
()
slapos
.
format
.
callAndRead
=
self
.
real_callAndRead
slapos
.
format
.
callAndRead
=
self
.
real_callAndRead
class
TestComputer
(
SlapformatMixin
):
class
TestComputer
(
SlapformatMixin
):
def
test_getAddress_empty_computer
(
self
):
def
test_getAddress_empty_computer
(
self
):
computer
=
slapos
.
format
.
Computer
(
'computer'
)
computer
=
slapos
.
format
.
Computer
(
'computer'
)
...
@@ -276,8 +287,7 @@ class TestComputer(SlapformatMixin):
...
@@ -276,8 +287,7 @@ class TestComputer(SlapformatMixin):
"makedirs('/software_root', 493)"
,
"makedirs('/software_root', 493)"
,
"chmod('/software_root', 493)"
],
"chmod('/software_root', 493)"
],
self
.
test_result
.
bucket
)
self
.
test_result
.
bucket
)
self
.
assertEqual
([
self
.
assertEqual
([
'ip addr list bridge'
],
'ip addr list bridge'
,],
self
.
fakeCallAndRead
.
external_command_list
)
self
.
fakeCallAndRead
.
external_command_list
)
@
unittest
.
skip
(
"Not implemented"
)
@
unittest
.
skip
(
"Not implemented"
)
...
@@ -377,7 +387,7 @@ class TestComputer(SlapformatMixin):
...
@@ -377,7 +387,7 @@ class TestComputer(SlapformatMixin):
partition
=
slapos
.
format
.
Partition
(
'partition'
,
'/part_path'
,
partition
=
slapos
.
format
.
Partition
(
'partition'
,
'/part_path'
,
slapos
.
format
.
User
(
'testuser'
),
[],
None
)
slapos
.
format
.
User
(
'testuser'
),
[],
None
)
global
USER_LIST
global
USER_LIST
USER_LIST
=
[
'testuser'
]
USER_LIST
=
[
'testuser'
]
partition
.
tap
=
slapos
.
format
.
Tap
(
'tap'
)
partition
.
tap
=
slapos
.
format
.
Tap
(
'tap'
)
computer
.
partition_list
=
[
partition
]
computer
.
partition_list
=
[
partition
]
global
INTERFACE_DICT
global
INTERFACE_DICT
...
@@ -488,6 +498,7 @@ class TestComputer(SlapformatMixin):
...
@@ -488,6 +498,7 @@ class TestComputer(SlapformatMixin):
],
],
self
.
fakeCallAndRead
.
external_command_list
)
self
.
fakeCallAndRead
.
external_command_list
)
class
TestPartition
(
SlapformatMixin
):
class
TestPartition
(
SlapformatMixin
):
def
test_createPath
(
self
):
def
test_createPath
(
self
):
...
@@ -513,6 +524,7 @@ class TestPartition(SlapformatMixin):
...
@@ -513,6 +524,7 @@ class TestPartition(SlapformatMixin):
self
.
test_result
.
bucket
self
.
test_result
.
bucket
)
)
class
TestUser
(
SlapformatMixin
):
class
TestUser
(
SlapformatMixin
):
def
test_create
(
self
):
def
test_create
(
self
):
user
=
slapos
.
format
.
User
(
'doesnotexistsyet'
)
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
...
@@ -53,6 +53,7 @@ originalBootstrapBuildout = utils.bootstrapBuildout
originalLaunchBuildout
=
utils
.
launchBuildout
originalLaunchBuildout
=
utils
.
launchBuildout
originalUploadSoftwareRelease
=
SlapObject
.
Software
.
uploadSoftwareRelease
originalUploadSoftwareRelease
=
SlapObject
.
Software
.
uploadSoftwareRelease
class
TestSoftwareSlapObject
(
BasicMixin
,
unittest
.
TestCase
):
class
TestSoftwareSlapObject
(
BasicMixin
,
unittest
.
TestCase
):
"""
"""
Test for Software class.
Test for Software class.
...
@@ -121,23 +122,21 @@ class TestSoftwareSlapObject(BasicMixin, unittest.TestCase):
...
@@ -121,23 +122,21 @@ class TestSoftwareSlapObject(BasicMixin, unittest.TestCase):
Check if the networkcache parameters are not propagated if they are not
Check if the networkcache parameters are not propagated if they are not
available.
available.
"""
"""
software
=
SlapObject
.
Software
(
software
=
SlapObject
.
Software
(
url
=
'http://example.com/software.cfg'
,
url
=
'http://example.com/software.cfg'
,
software_root
=
self
.
software_root
,
software_root
=
self
.
software_root
,
buildout
=
self
.
buildout
,
buildout
=
self
.
buildout
,
logger
=
logging
.
getLogger
())
logger
=
logging
.
getLogger
())
software
.
install
()
software
.
install
()
command_list
=
FakeCallAndRead
.
external_command_list
command_list
=
FakeCallAndRead
.
external_command_list
self
.
assert
False
(
'buildout:networkcache-section=networkcache'
self
.
assert
NotIn
(
'buildout:networkcache-section=networkcache'
,
command_list
)
in
command_list
)
self
.
assertNotIn
(
'networkcache:signature-private-key-file=%s'
%
self
.
assertFalse
(
'networkcache:signature-private-key-file=%s'
%
self
.
signature_private_key_file
,
self
.
signature_private_key_file
in
command_list
)
command_list
)
self
.
assert
False
(
'networkcache:upload-cache-url=%s'
%
self
.
upload_cache_url
self
.
assert
NotIn
(
'networkcache:upload-cache-url=%s'
%
self
.
upload_cache_url
,
in
command_list
)
command_list
)
self
.
assert
False
(
'networkcache:upload-dir-url=%s'
%
self
.
upload_dir_url
self
.
assert
NotIn
(
'networkcache:upload-dir-url=%s'
%
self
.
upload_dir_url
,
in
command_list
)
command_list
)
# XXX-Cedric: do the same with upload
# XXX-Cedric: do the same with upload
def
test_software_install_networkcache_upload_blacklist
(
self
):
def
test_software_install_networkcache_upload_blacklist
(
self
):
...
@@ -146,9 +145,12 @@ class TestSoftwareSlapObject(BasicMixin, unittest.TestCase):
...
@@ -146,9 +145,12 @@ class TestSoftwareSlapObject(BasicMixin, unittest.TestCase):
"""
"""
def
fakeBuildout
(
*
args
,
**
kw
):
def
fakeBuildout
(
*
args
,
**
kw
):
pass
pass
SlapObject
.
Software
.
_install_from_buildout
=
fakeBuildout
SlapObject
.
Software
.
_install_from_buildout
=
fakeBuildout
def
fake_upload_network_cached
(
*
args
,
**
kw
):
def
fake_upload_network_cached
(
*
args
,
**
kw
):
self
.
assertFalse
(
True
)
self
.
assertFalse
(
True
)
networkcache
.
upload_network_cached
=
fake_upload_network_cached
networkcache
.
upload_network_cached
=
fake_upload_network_cached
upload_to_binary_cache_url_blacklist
=
[
"http://example.com"
]
upload_to_binary_cache_url_blacklist
=
[
"http://example.com"
]
...
@@ -165,7 +167,7 @@ class TestSoftwareSlapObject(BasicMixin, unittest.TestCase):
...
@@ -165,7 +167,7 @@ class TestSoftwareSlapObject(BasicMixin, unittest.TestCase):
shacache_key_file
=
self
.
shacache_key_file
,
shacache_key_file
=
self
.
shacache_key_file
,
shadir_cert_file
=
self
.
shadir_cert_file
,
shadir_cert_file
=
self
.
shadir_cert_file
,
shadir_key_file
=
self
.
shadir_key_file
,
shadir_key_file
=
self
.
shadir_key_file
,
upload_to_binary_cache_url_blacklist
=
\
upload_to_binary_cache_url_blacklist
=
upload_to_binary_cache_url_blacklist
,
upload_to_binary_cache_url_blacklist
,
)
)
software
.
install
()
software
.
install
()
...
@@ -178,10 +180,11 @@ class TestSoftwareSlapObject(BasicMixin, unittest.TestCase):
...
@@ -178,10 +180,11 @@ class TestSoftwareSlapObject(BasicMixin, unittest.TestCase):
def
fakeBuildout
(
*
args
,
**
kw
):
def
fakeBuildout
(
*
args
,
**
kw
):
pass
pass
SlapObject
.
Software
.
_install_from_buildout
=
fakeBuildout
SlapObject
.
Software
.
_install_from_buildout
=
fakeBuildout
def
fakeUploadSoftwareRelease
(
*
args
,
**
kw
):
def
fakeUploadSoftwareRelease
(
*
args
,
**
kw
):
self
.
uploaded
=
True
self
.
uploaded
=
True
SlapObject
.
Software
.
uploadSoftwareRelease
=
fakeUploadSoftwareRelease
SlapObject
.
Software
.
uploadSoftwareRelease
=
fakeUploadSoftwareRelease
upload_to_binary_cache_url_blacklist
=
[
"http://anotherexample.com"
]
upload_to_binary_cache_url_blacklist
=
[
"http://anotherexample.com"
]
...
@@ -199,7 +202,7 @@ class TestSoftwareSlapObject(BasicMixin, unittest.TestCase):
...
@@ -199,7 +202,7 @@ class TestSoftwareSlapObject(BasicMixin, unittest.TestCase):
shacache_key_file
=
self
.
shacache_key_file
,
shacache_key_file
=
self
.
shacache_key_file
,
shadir_cert_file
=
self
.
shadir_cert_file
,
shadir_cert_file
=
self
.
shadir_cert_file
,
shadir_key_file
=
self
.
shadir_key_file
,
shadir_key_file
=
self
.
shadir_key_file
,
upload_to_binary_cache_url_blacklist
=
\
upload_to_binary_cache_url_blacklist
=
upload_to_binary_cache_url_blacklist
,
upload_to_binary_cache_url_blacklist
,
)
)
software
.
install
()
software
.
install
()
...
...
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
...
@@ -29,6 +29,7 @@ import slapos.util
import
tempfile
import
tempfile
import
unittest
import
unittest
class
TestMkdirP
(
unittest
.
TestCase
):
class
TestMkdirP
(
unittest
.
TestCase
):
"""
"""
Tests methods available in the slapos.util module.
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