Commit 5c613eb5 authored by Marco Mariani's avatar Marco Mariani

whitespace, indentation, light cleanup

parent 630ed441
This diff is collapsed.
......@@ -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')
......
This diff is collapsed.
......@@ -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.assertFalse('buildout:networkcache-section=networkcache'
in command_list)
self.assertFalse('networkcache:signature-private-key-file=%s' %
self.signature_private_key_file in command_list)
self.assertFalse('networkcache:upload-cache-url=%s' % self.upload_cache_url
in command_list)
self.assertFalse('networkcache:upload-dir-url=%s' % self.upload_dir_url
in command_list)
self.assertNotIn('buildout:networkcache-section=networkcache', command_list)
self.assertNotIn('networkcache:signature-private-key-file=%s' %
self.signature_private_key_file,
command_list)
self.assertNotIn('networkcache:upload-cache-url=%s' % self.upload_cache_url,
command_list)
self.assertNotIn('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))
This diff is collapsed.
......@@ -29,6 +29,7 @@ import slapos.util
import tempfile
import unittest
class TestMkdirP(unittest.TestCase):
"""
Tests methods available in the slapos.util module.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment