tripleo-ci/scripts/emit_releases_file/test_write_bash_script.py
Sofer Athlan-Guyot f3702f4335 Add standalone upgrade to emit release.
This also add dlrn_hash_newest variable to be able to make proper repo
switching.

The $title is just adding the necessary bits into emit_release to take
standalone_upgrade into account.

The dlrn_hash_newest is a forgotten variable from the initial emit
release.  It has been included for standalone upgrade where the
problem first appeared, but will likely be needed for other upgrade
jobs as well when they switch to non specific release file.

Currently we only set dlrn_hash which becomes TRIPLEO_DLRN_REPO which
becomes delorean url. We don't do anything about dlrn_hash_tag_newest
which becomes RDO_DLRN_REPO which becomes delorean-current.

This means that when we are upgrading we get the dlrn_hash_tag_newest
that was defined in the previous run, ie during deployment.

Change-Id: I0e298fc37eb7b3fd0afaa13ab021330b789b2f5e
Closes-Bug: #1795367
2018-10-24 00:18:40 +02:00

81 lines
2.6 KiB
Python

from emit_releases_file import write_releases_dictionary_to_bash
import mock
from mock import mock_open
import os
from six import PY2
import pytest
if PY2:
BUILTINS_OPEN = "__builtin__.open"
else:
BUILTINS_OPEN = "builtins.open"
def test_empty_relases_dictionary_fails():
assert (not write_releases_dictionary_to_bash({}, ""))
@pytest.fixture
def releases_dictionary():
return {
'undercloud_install_release': 'queens',
'undercloud_install_hash': 'current-tripleo',
'undercloud_target_release': 'master',
'undercloud_target_hash': 'current-tripleo',
'overcloud_deploy_release': 'master',
'overcloud_deploy_hash': 'current-tripleo',
'overcloud_target_release': 'master',
'overcloud_target_hash': 'current-tripleo',
'standalone_deploy_release': 'master',
'standalone_deploy_newest_hash': 'current',
'standalone_deploy_hash': 'current-tripleo',
'standalone_target_release': 'master',
'standalone_target_newest_hash': 'current',
'standalone_target_hash': 'current-tripleo',
}
@pytest.mark.parametrize('deleted_key', [
'undercloud_install_release',
'undercloud_install_hash',
'undercloud_target_release',
'undercloud_target_hash',
'overcloud_deploy_release',
'overcloud_deploy_hash',
'overcloud_target_release',
'overcloud_target_hash',
'standalone_deploy_release',
'standalone_deploy_newest_hash',
'standalone_deploy_hash',
'standalone_target_release',
'standalone_target_newest_hash',
'standalone_target_hash',
])
def test_missing_key_fails(releases_dictionary, deleted_key):
wrong_releases_dictionary = releases_dictionary.pop(deleted_key)
assert (not write_releases_dictionary_to_bash(wrong_releases_dictionary,
""))
@mock.patch(BUILTINS_OPEN, new_callable=mock_open)
def test_open_exception_fails(mock, releases_dictionary):
bash_script = '/foo/bar.sh'
mock.side_effect = IOError
assert (not write_releases_dictionary_to_bash(releases_dictionary,
bash_script))
@mock.patch(BUILTINS_OPEN, new_callable=mock_open)
def test_output_is_sourceable(mock, releases_dictionary):
bash_script = '/foo/bar.sh'
assert (write_releases_dictionary_to_bash(releases_dictionary,
bash_script))
mock.assert_called_once_with(bash_script, 'w')
handle = mock()
args, _ = handle.write.call_args
written_content = args[0]
# TODO(Llorente): check environment variables
assert (0 == os.system(written_content))