Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
slapos.package
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
Alain Takoudjou
slapos.package
Commits
0e4dc50e
Commit
0e4dc50e
authored
Jul 15, 2014
by
Rafael Monnerat
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
slapos.package: Fixes for Tests
parent
045cbe91
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
131 additions
and
11 deletions
+131
-11
slapos/package/distribution.py
slapos/package/distribution.py
+1
-1
slapos/package/promise/core.py
slapos/package/promise/core.py
+1
-1
slapos/package/test/base.py
slapos/package/test/base.py
+46
-0
slapos/package/test/test_promise_core.py
slapos/package/test/test_promise_core.py
+70
-5
slapos/package/test/test_signature.py
slapos/package/test/test_signature.py
+13
-4
No files found.
slapos/package/distribution.py
View file @
0e4dc50e
...
@@ -165,7 +165,7 @@ class AptGet:
...
@@ -165,7 +165,7 @@ class AptGet:
def
addKey
(
self
,
caller
,
url
,
alias
):
def
addKey
(
self
,
caller
,
url
,
alias
):
""" Download and add a gpg key """
""" 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
):
if
os
.
path
.
exists
(
gpg_path
):
# File already exists, skip
# File already exists, skip
return
return
...
...
slapos/package/promise/core.py
View file @
0e4dc50e
...
@@ -51,7 +51,7 @@ class Promise(BasePromise):
...
@@ -51,7 +51,7 @@ class Promise(BasePromise):
repository_tuple_list
.
append
((
alias
.
strip
(),
url
.
strip
()))
repository_tuple_list
.
append
((
alias
.
strip
(),
url
.
strip
()))
key_tuple_list
=
[]
key_tuple_list
=
[]
for
key
in
upgrade_goal
[
'key-list'
]
:
for
key
in
upgrade_goal
.
get
(
'key-list'
,
[])
:
alias
,
url
=
key
.
split
(
"="
)
alias
,
url
=
key
.
split
(
"="
)
key_tuple_list
.
append
((
alias
.
strip
(),
url
.
strip
()))
key_tuple_list
.
append
((
alias
.
strip
(),
url
.
strip
()))
...
...
slapos/package/test/base.py
View file @
0e4dc50e
...
@@ -104,3 +104,49 @@ reboot = 2011-10-10
...
@@ -104,3 +104,49 @@ reboot = 2011-10-10
upgrade = 2014-06-04
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
"""
slapos/package/test/test_promise_core.py
View file @
0e4dc50e
...
@@ -27,8 +27,10 @@
...
@@ -27,8 +27,10 @@
#
#
##############################################################################
##############################################################################
import
datetime
from
slapos.package.promise
import
core
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
slapos.package.signature
import
NetworkCache
from
optparse
import
Values
from
optparse
import
Values
...
@@ -51,8 +53,11 @@ class TestCoreCase(unittest.TestCase):
...
@@ -51,8 +53,11 @@ class TestCoreCase(unittest.TestCase):
def
setUp
(
self
):
def
setUp
(
self
):
core
.
Promise
.
_call
=
_fake_call
core
.
Promise
.
_call
=
_fake_call
core
.
Promise
.
log
=
_log_message_list
core
.
Promise
.
log
=
_log_message_list
self
.
original_promise_update
=
core
.
Promise
.
update
core
.
Promise
.
update
=
_fake_update
core
.
Promise
.
update
=
_fake_update
self
.
original_network_cache_download
=
NetworkCache
.
download
self
.
original_network_cache_download
=
NetworkCache
.
download
# Patch Download
# Patch Download
...
@@ -71,6 +76,9 @@ class TestCoreCase(unittest.TestCase):
...
@@ -71,6 +76,9 @@ class TestCoreCase(unittest.TestCase):
"verbose"
:
False
"verbose"
:
False
}
}
def
tearDown
(
self
):
NetworkCache
.
download
=
self
.
original_network_cache_download
core
.
Promise
.
update
=
self
.
original_promise_update
def
_createConfigurationFile
(
self
):
def
_createConfigurationFile
(
self
):
with
open
(
"/tmp/test_base_promise_configuration.cfg"
,
"w"
)
as
configuration_file
:
with
open
(
"/tmp/test_base_promise_configuration.cfg"
,
"w"
)
as
configuration_file
:
...
@@ -144,9 +152,11 @@ reboot = 2100-11-11
...
@@ -144,9 +152,11 @@ reboot = 2100-11-11
# Patch Download
# Patch Download
def
_fake_signature_download
(
self
,
path
,
*
args
,
**
kwargs
):
def
_fake_signature_download
(
self
,
path
,
*
args
,
**
kwargs
):
copy_of_upgrade_key
=
UPGRADE_KEY
with
open
(
path
,
'w'
)
as
upgrade_signature
:
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 = 2100-01-01"
)
"upgrade = 2014-06-04"
,
"upgrade = 2100-01-01"
)
upgrade_signature
.
write
(
modified_upgrade_key
)
upgrade_signature
.
write
(
modified_upgrade_key
)
return
True
return
True
...
@@ -187,7 +197,7 @@ reboot = 2100-11-11
...
@@ -187,7 +197,7 @@ reboot = 2100-11-11
'Expected Reboot early them 2011-10-10'
,
'Expected Reboot early them 2011-10-10'
,
'Expected Upgrade early them 2014-06-04'
,
'Expected Upgrade early them 2014-06-04'
,
'Last reboot : 2100-11-11'
,
'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'
,
'Your system is up to date'
,
'No need to reboot.'
,
'No need to reboot.'
,
'No need to reboot.'
]
'No need to reboot.'
]
...
@@ -212,3 +222,58 @@ reboot = 2100-11-11
...
@@ -212,3 +222,58 @@ reboot = 2100-11-11
self
.
assertEquals
(
promise
.
_fake_update_call
[
2
],
key_list
)
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
)
slapos/package/test/test_signature.py
View file @
0e4dc50e
...
@@ -62,9 +62,14 @@ signature-certificate-list =
...
@@ -62,9 +62,14 @@ signature-certificate-list =
-----END CERTIFICATE-----
-----END CERTIFICATE-----
"""
"""
UPDATE_CFG_DATA
=
"""
UPDATE_CFG_DATA
=
"""
[slapupdate]
[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
upgrade_key = slapos-upgrade-testing-key-with-config-file
"""
+
BASE_UPDATE_CFG_DATA
"""
+
BASE_UPDATE_CFG_DATA
...
@@ -142,6 +147,7 @@ def _fake_upload(self, *args, **kwargs):
...
@@ -142,6 +147,7 @@ def _fake_upload(self, *args, **kwargs):
class
NetworkCacheTestCase
(
unittest
.
TestCase
):
class
NetworkCacheTestCase
(
unittest
.
TestCase
):
def
setUp
(
self
):
def
setUp
(
self
):
self
.
original_networkcache_upload
=
NetworkcacheClient
.
upload
NetworkcacheClient
.
upload
=
_fake_upload
NetworkcacheClient
.
upload
=
_fake_upload
...
@@ -152,6 +158,8 @@ class NetworkCacheTestCase(unittest.TestCase):
...
@@ -152,6 +158,8 @@ class NetworkCacheTestCase(unittest.TestCase):
"verbose"
:
False
"verbose"
:
False
}
}
def
tearDown
(
self
):
NetworkcacheClient
.
upload
=
self
.
original_networkcache_upload
def
_createConfigurationFile
(
self
):
def
_createConfigurationFile
(
self
):
with
open
(
"/tmp/test_signature_000000_configuration.cfg"
,
"w"
)
as
configuration_file
:
with
open
(
"/tmp/test_signature_000000_configuration.cfg"
,
"w"
)
as
configuration_file
:
...
@@ -173,7 +181,7 @@ class NetworkCacheTestCase(unittest.TestCase):
...
@@ -173,7 +181,7 @@ class NetworkCacheTestCase(unittest.TestCase):
SIGNATURE
)
SIGNATURE
)
self
.
assertEqual
(
shacache
.
directory_key
,
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
# Check keys that don't exist
# Not mandatory
# Not mandatory
self
.
assertEqual
(
shacache
.
dir_url
,
None
)
self
.
assertEqual
(
shacache
.
dir_url
,
None
)
...
@@ -200,7 +208,7 @@ class NetworkCacheTestCase(unittest.TestCase):
...
@@ -200,7 +208,7 @@ class NetworkCacheTestCase(unittest.TestCase):
SIGNATURE
)
SIGNATURE
)
self
.
assertEqual
(
shacache
.
directory_key
,
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
# Check keys that don't exist
# Not mandatory
# Not mandatory
self
.
assertEqual
(
shacache
.
dir_url
,
'https://www.shacache.org/shadir'
)
self
.
assertEqual
(
shacache
.
dir_url
,
'https://www.shacache.org/shadir'
)
...
@@ -239,6 +247,7 @@ class NetworkCacheTestCase(unittest.TestCase):
...
@@ -239,6 +247,7 @@ class NetworkCacheTestCase(unittest.TestCase):
strategy
=
signature
.
strategy
)
strategy
=
signature
.
strategy
)
self
.
maxDiff
=
None
self
.
maxDiff
=
None
self
.
assertEquals
(
UPGRADE_KEY
.
splitlines
(),
self
.
assertEquals
(
UPGRADE_KEY
.
splitlines
(),
open
(
path
,
'r'
).
read
().
splitlines
())
open
(
path
,
'r'
).
read
().
splitlines
())
...
@@ -260,7 +269,7 @@ class NetworkCacheTestCase(unittest.TestCase):
...
@@ -260,7 +269,7 @@ class NetworkCacheTestCase(unittest.TestCase):
signature_private_key_file
,
signature_private_key_file
,
"COMP-123A"
)
"COMP-123A"
)
configuration_content
=
UPDATE_CFG_DATA
+
"""
configuration_content
=
UPDATE_
UPLOAD_
CFG_DATA
+
"""
signature_private_key_file = %(signature_private_key_file)s
signature_private_key_file = %(signature_private_key_file)s
signature_certificate_file = %(signature_certificate_file)s
signature_certificate_file = %(signature_certificate_file)s
upload-cache-url = https://www.shacache.org/shacache
upload-cache-url = https://www.shacache.org/shacache
...
...
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