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
1
Merge Requests
1
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
Romain Courteaud
slapos.core
Commits
854ac7d7
Commit
854ac7d7
authored
Jun 06, 2013
by
Cédric de Saint Martin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Simplify, factor slapobject test mixin
- Clearly define the imports - Refactor specific mockup
parent
be4b0991
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
29 additions
and
24 deletions
+29
-24
slapos/tests/slapobject.py
slapos/tests/slapobject.py
+29
-24
No files found.
slapos/tests/slapobject.py
View file @
854ac7d7
...
...
@@ -29,14 +29,21 @@ import logging
import
os
import
unittest
from
slapos.grid
import
SlapObject
from
slapos.slap
import
ComputerPartition
as
SlapComputerPartition
from
slapos.grid.SlapObject
import
Partition
,
Software
from
slapos.grid
import
utils
from
slapos.grid
import
networkcache
# XXX: BasicMixin should be in a separated module, not in slapgrid test module.
from
slapos.tests.slapgrid
import
BasicMixin
class
FakeCallAndRead
:
# XXX: change name and behavior to be more generic and factor with other tests
class
FakeNetworkCacheCallAndRead
(
object
):
"""
Short-circuit normal calls to slapos buildout helpers, get and store
'additional_buildout_parameter_list' for future analysis.
"""
def
__init__
(
self
):
self
.
external_command_list
=
[]
...
...
@@ -45,15 +52,13 @@ class FakeCallAndRead:
kwargs
.
get
(
'additional_buildout_parameter_list'
)
self
.
external_command_list
.
extend
(
additional_buildout_parameter_list
)
FakeCallAndRead
=
FakeCallAndRead
()
# Backup modules
original_install_from_buildout
=
S
lapObject
.
S
oftware
.
_install_from_buildout
original_install_from_buildout
=
Software
.
_install_from_buildout
original_upload_network_cached
=
networkcache
.
upload_network_cached
originalBootstrapBuildout
=
utils
.
bootstrapBuildout
originalLaunchBuildout
=
utils
.
launchBuildout
originalUploadSoftwareRelease
=
S
lapObject
.
S
oftware
.
uploadSoftwareRelease
originalUploadSoftwareRelease
=
Software
.
uploadSoftwareRelease
originalPartitionGenerateSupervisorConfigurationFile
=
Partition
.
generateSupervisorConfigurationFile
class
MasterMixin
(
BasicMixin
,
unittest
.
TestCase
):
"""
...
...
@@ -62,16 +67,12 @@ class MasterMixin(BasicMixin, unittest.TestCase):
def
setUp
(
self
):
BasicMixin
.
setUp
(
self
)
os
.
mkdir
(
self
.
software_root
)
# Monkey patch utils module
utils
.
bootstrapBuildout
=
FakeCallAndRead
utils
.
launchBuildout
=
FakeCallAndRead
# Reset external command list in case it is dirty from previous test
FakeCallAndRead
.
external_command_list
=
[]
os
.
mkdir
(
self
.
instance_root
)
def
tearDown
(
self
):
BasicMixin
.
tearDown
(
self
)
# Un-monkey patch
utils module
# Un-monkey patch
possible modules
global
originalBootstrapBuildout
global
originalLaunchBuildout
utils
.
bootstrapBuildout
=
originalBootstrapBuildout
...
...
@@ -84,6 +85,10 @@ class TestSoftwareNetworkCacheSlapObject(MasterMixin, unittest.TestCase):
"""
def
setUp
(
self
):
MasterMixin
.
setUp
(
self
)
self
.
fakeCallAndRead
=
FakeNetworkCacheCallAndRead
()
utils
.
bootstrapBuildout
=
self
.
fakeCallAndRead
utils
.
launchBuildout
=
self
.
fakeCallAndRead
self
.
signature_private_key_file
=
'/signature/private/key_file'
self
.
upload_cache_url
=
'http://example.com/uploadcache'
self
.
upload_dir_url
=
'http://example.com/uploaddir'
...
...
@@ -95,16 +100,16 @@ class TestSoftwareNetworkCacheSlapObject(MasterMixin, unittest.TestCase):
def
tearDown
(
self
):
MasterMixin
.
tearDown
(
self
)
S
lapObject
.
S
oftware
.
_install_from_buildout
=
original_install_from_buildout
Software
.
_install_from_buildout
=
original_install_from_buildout
networkcache
.
upload_network_cached
=
original_upload_network_cached
S
lapObject
.
S
oftware
.
uploadSoftwareRelease
=
originalUploadSoftwareRelease
Software
.
uploadSoftwareRelease
=
originalUploadSoftwareRelease
# Test methods
def
test_software_install_with_networkcache
(
self
):
"""
Check if the networkcache parameters are propagated.
"""
software
=
S
lapObject
.
S
oftware
(
software
=
Software
(
url
=
'http://example.com/software.cfg'
,
software_root
=
self
.
software_root
,
buildout
=
self
.
buildout
,
...
...
@@ -119,7 +124,7 @@ class TestSoftwareNetworkCacheSlapObject(MasterMixin, unittest.TestCase):
software
.
install
()
command_list
=
F
akeCallAndRead
.
external_command_list
command_list
=
self
.
f
akeCallAndRead
.
external_command_list
self
.
assertIn
(
'buildout:networkcache-section=networkcache'
,
command_list
)
self
.
assertIn
(
'networkcache:signature-private-key-file=%s'
%
self
.
signature_private_key_file
,
command_list
)
self
.
assertIn
(
'networkcache:upload-cache-url=%s'
%
self
.
upload_cache_url
,
command_list
)
...
...
@@ -134,13 +139,13 @@ class TestSoftwareNetworkCacheSlapObject(MasterMixin, unittest.TestCase):
Check if the networkcache parameters are not propagated if they are not
available.
"""
software
=
S
lapObject
.
S
oftware
(
url
=
'http://example.com/software.cfg'
,
software
=
Software
(
url
=
'http://example.com/software.cfg'
,
software_root
=
self
.
software_root
,
buildout
=
self
.
buildout
,
logger
=
logging
.
getLogger
())
software
.
install
()
command_list
=
F
akeCallAndRead
.
external_command_list
command_list
=
self
.
f
akeCallAndRead
.
external_command_list
self
.
assertNotIn
(
'buildout:networkcache-section=networkcache'
,
command_list
)
self
.
assertNotIn
(
'networkcache:signature-private-key-file=%s'
%
self
.
signature_private_key_file
,
...
...
@@ -158,7 +163,7 @@ class TestSoftwareNetworkCacheSlapObject(MasterMixin, unittest.TestCase):
def
fakeBuildout
(
*
args
,
**
kw
):
pass
S
lapObject
.
S
oftware
.
_install_from_buildout
=
fakeBuildout
Software
.
_install_from_buildout
=
fakeBuildout
def
fake_upload_network_cached
(
*
args
,
**
kw
):
self
.
assertFalse
(
True
)
...
...
@@ -167,7 +172,7 @@ class TestSoftwareNetworkCacheSlapObject(MasterMixin, unittest.TestCase):
upload_to_binary_cache_url_blacklist
=
[
"http://example.com"
]
software
=
S
lapObject
.
S
oftware
(
software
=
Software
(
url
=
'http://example.com/software.cfg'
,
software_root
=
self
.
software_root
,
buildout
=
self
.
buildout
,
...
...
@@ -191,16 +196,16 @@ class TestSoftwareNetworkCacheSlapObject(MasterMixin, unittest.TestCase):
"""
def
fakeBuildout
(
*
args
,
**
kw
):
pass
S
lapObject
.
S
oftware
.
_install_from_buildout
=
fakeBuildout
Software
.
_install_from_buildout
=
fakeBuildout
def
fakeUploadSoftwareRelease
(
*
args
,
**
kw
):
self
.
uploaded
=
True
S
lapObject
.
S
oftware
.
uploadSoftwareRelease
=
fakeUploadSoftwareRelease
Software
.
uploadSoftwareRelease
=
fakeUploadSoftwareRelease
upload_to_binary_cache_url_blacklist
=
[
"http://anotherexample.com"
]
software
=
S
lapObject
.
S
oftware
(
software
=
Software
(
url
=
'http://example.com/software.cfg'
,
software_root
=
self
.
software_root
,
buildout
=
self
.
buildout
,
...
...
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