Commit 0e4dc50e authored by Rafael Monnerat's avatar Rafael Monnerat

slapos.package: Fixes for Tests

parent 045cbe91
......@@ -165,7 +165,7 @@ class AptGet:
def addKey(self, caller, url, alias):
""" Download and add a gpg key """
gpg_path = open("%s/%s.gpg" % self.trusted_gpg_d_path, alias)
gpg_path = open("%s/%s.gpg" % (self.trusted_gpg_d_path, alias))
if os.path.exists(gpg_path):
# File already exists, skip
return
......
......@@ -51,7 +51,7 @@ class Promise(BasePromise):
repository_tuple_list.append((alias.strip(), url.strip()))
key_tuple_list = []
for key in upgrade_goal['key-list']:
for key in upgrade_goal.get('key-list', []):
alias, url = key.split("=")
key_tuple_list.append((alias.strip(), url.strip()))
......
......@@ -104,3 +104,49 @@ reboot = 2011-10-10
upgrade = 2014-06-04
"""
UPGRADE_KEY_WITHOUT_KEY_LIST = """[debian-default]
repository-list =
main = http://ftp.fr.debian.org/debian/ wheezy main
main-src = http://ftp.fr.debian.org/debian/ wheezy main
update = http://ftp.fr.debian.org/debian/ wheezy-updates main
update-src = http://ftp.fr.debian.org/debian/ wheezy-updates main
slapos = http://download.opensuse.org/repositories/home:/VIFIBnexedi:/branches:/home:/VIFIBnexedi/Debian_7.0/ ./
re6stnet = http://git.erp5.org/dist/deb ./
filter-package-list =
ntp
openvpn
slapos.node
re6stnet
filter-promise-list =
core
signature-list =
debian+++jessie/sid+++
debian+++7.4+++
debian+++7.5+++
debian+++7.3+++
debian+++7+++
[opensuse-legacy]
repository-list =
suse = http://download.opensuse.org/distribution/12.1/repo/oss/
slapos = http://download.opensuse.org/repositories/home:/VIFIBnexedi:/branches:/home:/VIFIBnexedi/openSUSE_12.1/
re6st = http://git.erp5.org/dist/rpm
filter-promise-list =
core
filter-package-list =
ntp
openvpn
slapos.node
re6stnet
signature-list =
opensuse+++12.1+++x86_64
[system]
reboot = 2011-10-10
upgrade = 2014-06-04
"""
......@@ -27,8 +27,10 @@
#
##############################################################################
import datetime
from slapos.package.promise import core
from slapos.package.test.base import CONFIGURATION_FILE, UPGRADE_KEY, _fake_call
from slapos.package.test.base import CONFIGURATION_FILE, UPGRADE_KEY, \
_fake_call, UPGRADE_KEY_WITHOUT_KEY_LIST
from slapos.package.signature import NetworkCache
from optparse import Values
......@@ -52,7 +54,10 @@ class TestCoreCase(unittest.TestCase):
def setUp(self):
core.Promise._call = _fake_call
core.Promise.log = _log_message_list
self.original_promise_update = core.Promise.update
core.Promise.update = _fake_update
self.original_network_cache_download = NetworkCache.download
# Patch Download
......@@ -71,6 +76,9 @@ class TestCoreCase(unittest.TestCase):
"verbose": False
}
def tearDown(self):
NetworkCache.download = self.original_network_cache_download
core.Promise.update = self.original_promise_update
def _createConfigurationFile(self):
with open("/tmp/test_base_promise_configuration.cfg", "w") as configuration_file:
......@@ -144,8 +152,10 @@ reboot = 2100-11-11
# Patch Download
def _fake_signature_download(self, path, *args, **kwargs):
copy_of_upgrade_key = UPGRADE_KEY
with open(path, 'w') as upgrade_signature:
modified_upgrade_key = UPGRADE_KEY.replace("upgrade = 2014-06-04",
modified_upgrade_key = copy_of_upgrade_key.replace(
"upgrade = 2014-06-04",
"upgrade = 2100-01-01")
upgrade_signature.write(modified_upgrade_key)
return True
......@@ -187,7 +197,7 @@ reboot = 2100-11-11
'Expected Reboot early them 2011-10-10',
'Expected Upgrade early them 2014-06-04',
'Last reboot : 2100-11-11',
'Last upgrade : 2014-06-14',
'Last upgrade : %s' % datetime.datetime.today().strftime("%Y-%m-%d"),
'Your system is up to date',
'No need to reboot.',
'No need to reboot.']
......@@ -212,3 +222,58 @@ reboot = 2100-11-11
self.assertEquals(promise._fake_update_call[2], key_list)
def testFixConsistency_without_key_list(self):
modified_config_dict = self.config_dict.copy()
# Patch Download
def _fake_signature_download(self, path, *args, **kwargs):
with open(path, 'w') as upgrade_signature:
modified_upgrade_key = UPGRADE_KEY_WITHOUT_KEY_LIST.replace(
"upgrade = 2014-06-04", "upgrade = 2100-01-01")
upgrade_signature.write(modified_upgrade_key)
return True
NetworkCache.download = _fake_signature_download
def _fake_update(self, repository_list=[], package_list=[], key_list=[]):
self._fake_update_call = (repository_list, package_list, key_list)
slapupdate_path = "/tmp/testFixConsistencyUpgrade"
with open(slapupdate_path, 'w') as slapupdate:
slapupdate.write("""[system]
upgrade = 2000-11-11
reboot = 2100-11-11
""")
modified_config_dict["srv_file"] = slapupdate_path
promise = core.Promise(Values(modified_config_dict))
self.assertEquals(promise.checkConsistency(fixit=1), True)
self.maxDiff = None
expected_message_list = [
'Expected Reboot early them 2011-10-10',
'Expected Upgrade early them 2100-01-01',
'Last reboot : 2100-11-11',
'Last upgrade : 2000-11-11',
'Upgrade will happens on 2100-01-01']
self.assertEquals(promise._message_list, expected_message_list)
repository_list = [
('main', 'http://ftp.fr.debian.org/debian/ wheezy main'),
('main-src', 'http://ftp.fr.debian.org/debian/ wheezy main'),
('update', 'http://ftp.fr.debian.org/debian/ wheezy-updates main'),
('update-src', 'http://ftp.fr.debian.org/debian/ wheezy-updates main'),
('slapos', 'http://download.opensuse.org/repositories/home:/VIFIBnexedi:/branches:/home:/VIFIBnexedi/Debian_7.0/ ./'),
('re6stnet', 'http://git.erp5.org/dist/deb ./')]
filter_package_list = ['ntp', 'openvpn', 'slapos.node', 're6stnet']
key_list = []
self.assertEquals(promise._fake_update_call[0], repository_list)
self.assertEquals(promise._fake_update_call[1], filter_package_list)
self.assertEquals(promise._fake_update_call[2], key_list)
......@@ -62,9 +62,14 @@ signature-certificate-list =
-----END CERTIFICATE-----
"""
UPDATE_CFG_DATA = """
[slapupdate]
upgrade_key = slapos-upgrade-testing-key-with-config-file-invalid
""" + BASE_UPDATE_CFG_DATA
UPDATE_UPLOAD_CFG_DATA = """
[slapupdate]
upgrade_key = slapos-upgrade-testing-key-with-config-file
""" + BASE_UPDATE_CFG_DATA
......@@ -142,6 +147,7 @@ def _fake_upload(self, *args, **kwargs):
class NetworkCacheTestCase(unittest.TestCase):
def setUp(self):
self.original_networkcache_upload = NetworkcacheClient.upload
NetworkcacheClient.upload = _fake_upload
......@@ -152,6 +158,8 @@ class NetworkCacheTestCase(unittest.TestCase):
"verbose": False
}
def tearDown(self):
NetworkcacheClient.upload = self.original_networkcache_upload
def _createConfigurationFile(self):
with open("/tmp/test_signature_000000_configuration.cfg", "w") as configuration_file:
......@@ -173,7 +181,7 @@ class NetworkCacheTestCase(unittest.TestCase):
SIGNATURE)
self.assertEqual(shacache.directory_key,
'slapos-upgrade-testing-key-with-config-file')
'slapos-upgrade-testing-key-with-config-file-invalid')
# Check keys that don't exist
# Not mandatory
self.assertEqual(shacache.dir_url , None)
......@@ -200,7 +208,7 @@ class NetworkCacheTestCase(unittest.TestCase):
SIGNATURE)
self.assertEqual(shacache.directory_key,
'slapos-upgrade-testing-key-with-config-file')
'slapos-upgrade-testing-key-with-config-file-invalid')
# Check keys that don't exist
# Not mandatory
self.assertEqual(shacache.dir_url , 'https://www.shacache.org/shadir')
......@@ -239,6 +247,7 @@ class NetworkCacheTestCase(unittest.TestCase):
strategy=signature.strategy)
self.maxDiff = None
self.assertEquals(UPGRADE_KEY.splitlines(),
open(path, 'r').read().splitlines())
......@@ -260,7 +269,7 @@ class NetworkCacheTestCase(unittest.TestCase):
signature_private_key_file,
"COMP-123A")
configuration_content = UPDATE_CFG_DATA + """
configuration_content = UPDATE_UPLOAD_CFG_DATA + """
signature_private_key_file = %(signature_private_key_file)s
signature_certificate_file = %(signature_certificate_file)s
upload-cache-url = https://www.shacache.org/shacache
......
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