summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--scripts/emit_releases_file/emit_releases_file.py33
-rw-r--r--scripts/emit_releases_file/test_get_dlrn_hash.py20
-rw-r--r--scripts/emit_releases_file/test_write_bash_script.py68
3 files changed, 108 insertions, 13 deletions
diff --git a/scripts/emit_releases_file/emit_releases_file.py b/scripts/emit_releases_file/emit_releases_file.py
index f18f417..f6c936d 100644
--- a/scripts/emit_releases_file/emit_releases_file.py
+++ b/scripts/emit_releases_file/emit_releases_file.py
@@ -43,8 +43,8 @@ def load_featureset_file(featureset_file):
43def get_dlrn_hash(release, hash_name, retries=10): 43def get_dlrn_hash(release, hash_name, retries=10):
44 logger = logging.getLogger('emit-releases') 44 logger = logging.getLogger('emit-releases')
45 full_hash_pattern = re.compile('[a-z,0-9]{40}_[a-z,0-9]{8}') 45 full_hash_pattern = re.compile('[a-z,0-9]{40}_[a-z,0-9]{8}')
46 repo_url = ('https://trunk.rdoproject.org/centos7-%s/%s/delorean.repo' 46 repo_url = ('https://trunk.rdoproject.org/centos7-%s/%s/delorean.repo' %
47 % (release, hash_name)) 47 (release, hash_name))
48 for retry_num in range(retries): 48 for retry_num in range(retries):
49 repo_file = None 49 repo_file = None
50 # Timeout if initial connection is longer than default 50 # Timeout if initial connection is longer than default
@@ -155,6 +155,28 @@ def shim_convert_old_release_names(releases_names):
155 return releases_names 155 return releases_names
156 156
157 157
158def write_releases_dictionary_to_bash(releases_dictionary, bash_file_name):
159 logger = logging.getLogger('emit-releases')
160 # Make it deterministic, expected constants in the proper order
161 try:
162 bash_script = '''#!/bin/env bash
163export UNDERCLOUD_INSTALL_RELEASE="{undercloud_install_release}"
164export UNDERCLOUD_INSTALL_HASH="{undercloud_install_hash}"
165export UNDERCLOUD_TARGET_RELEASE="{undercloud_target_release}"
166export UNDERCLOUD_TARGET_HASH="{undercloud_target_hash}"
167export OVERCLOUD_DEPLOY_RELEASE="{overcloud_deploy_release}"
168export OVERCLOUD_DEPLOY_HASH="{overcloud_deploy_hash}"
169export OVERCLOUD_TARGET_RELEASE="{overcloud_target_release}"
170export OVERCLOUD_TARGET_HASH="{overcloud_target_hash}"
171'''.format(**releases_dictionary)
172 with open(bash_file_name, 'w') as bash_file:
173 bash_file.write(bash_script)
174 except Exception:
175 logger.exception("Writting releases dictionary")
176 return False
177 return True
178
179
158if __name__ == '__main__': 180if __name__ == '__main__':
159 181
160 default_log_file = '{}.log'.format(os.path.basename(__file__)) 182 default_log_file = '{}.log'.format(os.path.basename(__file__))
@@ -193,5 +215,8 @@ if __name__ == '__main__':
193 releases_dictionary = compose_releases_dictionary(args.stable_release, 215 releases_dictionary = compose_releases_dictionary(args.stable_release,
194 featureset) 216 featureset)
195 217
196 releases_dictionary = shim_convert_old_release_names( 218 releases_dictionary = shim_convert_old_release_names(releases_dictionary)
197 releases_dictionary) 219
220 if not write_releases_dictionary_to_bash(
221 releases_dictionary, args.output_file):
222 exit(1)
diff --git a/scripts/emit_releases_file/test_get_dlrn_hash.py b/scripts/emit_releases_file/test_get_dlrn_hash.py
index 2525fb1..d94cf7c 100644
--- a/scripts/emit_releases_file/test_get_dlrn_hash.py
+++ b/scripts/emit_releases_file/test_get_dlrn_hash.py
@@ -7,18 +7,20 @@ import pytest
7@mock.patch('requests.get') 7@mock.patch('requests.get')
8def test_get_dlrn_hash(mock_get): 8def test_get_dlrn_hash(mock_get):
9 mock_response = mock.Mock() 9 mock_response = mock.Mock()
10 mock_response.content = ('[delorean]\nname=delorean-openstack-nova-81c23c04' 10 mock_response.content = (
11 '7e8e0fc03b54164921f49fdb4103202c\nbaseurl=https:/' 11 '[delorean]\nname=delorean-openstack-nova-81c23c04'
12 '/trunk.rdoproject.org/centos7/81/c2/81c23c047e8e0' 12 '7e8e0fc03b54164921f49fdb4103202c\nbaseurl=https:/'
13 'fc03b54164921f49fdb4103202c_b333f915\nenabled=1\n' 13 '/trunk.rdoproject.org/centos7/81/c2/81c23c047e8e0'
14 'gpgcheck=0\npriority=1') 14 'fc03b54164921f49fdb4103202c_b333f915\nenabled=1\n'
15 'gpgcheck=0\npriority=1')
15 release = 'master' 16 release = 'master'
16 hash_name = 'current-tripleo' 17 hash_name = 'current-tripleo'
17 repo_url = ('https://trunk.rdoproject.org/centos7-%s/%s/delorean.repo' 18 repo_url = ('https://trunk.rdoproject.org/centos7-%s/%s/delorean.repo' %
18 % (release, hash_name)) 19 (release, hash_name))
19 mock_get.return_value = mock_response 20 mock_get.return_value = mock_response
20 assert (get_dlrn_hash(release, hash_name) == 21 assert (get_dlrn_hash(
21 '81c23c047e8e0fc03b54164921f49fdb4103202c_b333f915') 22 release,
23 hash_name) == '81c23c047e8e0fc03b54164921f49fdb4103202c_b333f915')
22 mock_get.assert_called_once_with(repo_url, timeout=(3.05, 27)) 24 mock_get.assert_called_once_with(repo_url, timeout=(3.05, 27))
23 25
24 26
diff --git a/scripts/emit_releases_file/test_write_bash_script.py b/scripts/emit_releases_file/test_write_bash_script.py
new file mode 100644
index 0000000..e074d5b
--- /dev/null
+++ b/scripts/emit_releases_file/test_write_bash_script.py
@@ -0,0 +1,68 @@
1from emit_releases_file import write_releases_dictionary_to_bash
2
3import os
4import mock
5from mock import mock_open
6from six import PY2
7
8import pytest
9
10if PY2:
11 BUILTINS_OPEN = "__builtin__.open"
12else:
13 BUILTINS_OPEN = "builtins.open"
14
15
16def test_empty_relases_dictionary_fails():
17 assert (not write_releases_dictionary_to_bash({}, ""))
18
19
20@pytest.fixture
21def releases_dictionary():
22 return {
23 'undercloud_install_release': 'queens',
24 'undercloud_install_hash': 'current-tripleo',
25 'undercloud_target_release': 'master',
26 'undercloud_target_hash': 'current-tripleo',
27 'overcloud_deploy_release': 'master',
28 'overcloud_deploy_hash': 'current-tripleo',
29 'overcloud_target_release': 'master',
30 'overcloud_target_hash': 'current-tripleo',
31 }
32
33
34@pytest.mark.parametrize('deleted_key', [
35 'undercloud_install_release',
36 'undercloud_install_hash',
37 'undercloud_target_release',
38 'undercloud_target_hash',
39 'overcloud_deploy_release',
40 'overcloud_deploy_hash',
41 'overcloud_target_release',
42 'overcloud_target_hash',
43])
44def test_missing_key_fails(releases_dictionary, deleted_key):
45 wrong_releases_dictionary = releases_dictionary.pop(deleted_key)
46 assert (not write_releases_dictionary_to_bash(wrong_releases_dictionary,
47 ""))
48
49
50@mock.patch(BUILTINS_OPEN, new_callable=mock_open)
51def test_open_exception_fails(mock, releases_dictionary):
52 bash_script = '/foo/bar.sh'
53 mock.side_effect = IOError
54 assert (not write_releases_dictionary_to_bash(releases_dictionary,
55 bash_script))
56
57
58@mock.patch(BUILTINS_OPEN, new_callable=mock_open)
59def test_output_is_sourceable(mock, releases_dictionary):
60 bash_script = '/foo/bar.sh'
61 assert (write_releases_dictionary_to_bash(releases_dictionary,
62 bash_script))
63 mock.assert_called_once_with(bash_script, 'w')
64 handle = mock()
65 args, _ = handle.write.call_args
66 written_content = args[0]
67 # TODO: check environment variables
68 assert (0 == os.system(written_content))