Merge "Add functions to set/unset upgrade_levels for compute service" into stable/7.0

This commit is contained in:
Jenkins 2015-12-11 10:50:24 +00:00 committed by Gerrit Code Review
commit a263dfe794
3 changed files with 71 additions and 0 deletions

View File

@ -27,3 +27,11 @@ BRIDGES = ['br-ex', 'br-mgmt']
DEFAULT_DISKS = True
DEFAULT_NETS = True
ISCSI_CONFIG_PATH = "/etc/iscsi/initiatorname.iscsi"
VERSIONS = {
'7.0': 'kilo',
'6.1': 'juno',
'6.0': 'juno',
'5.2.9': 'icehouse',
'5.1.1': 'icehouse',
'5.1': 'icehouse',
}

View File

@ -10,6 +10,7 @@
# License for the specific language governing permissions and limitations
# under the License.
import contextlib
import io
import mock
import pytest
@ -96,3 +97,47 @@ def test_untar_files(node, mock_ssh_popen, mock_open):
stdin=ssh.PIPE, node=node)
mock_open.assert_called_once_with('filename', 'rb')
assert buf.getvalue() == content
@contextlib.contextmanager
def _check_upgrade_levels(mocker, node, content, expected_content):
mock_sftp = mocker.patch('octane.util.ssh.sftp')
old = io.BytesIO(content)
mock_new = mocker.Mock()
buf = io.BytesIO()
mock_new.write = buf.write
mock_update_file = mocker.patch('octane.util.ssh.update_file')
mock_update_file.return_value.__enter__.return_value = (old, mock_new)
yield
mock_sftp.assert_called_once_with(node)
mock_update_file.assert_called_once_with(mock_sftp.return_value,
'/etc/nova/nova.conf')
assert buf.getvalue() == expected_content
NOVA_DEFAULT = b"#\u0444\n[DEFAULT]\ndebug = True\n"
NOVA_WITH_EMPTY_LEVELS = NOVA_DEFAULT + b"[upgrade_levels]\n"
NOVA_WITH_KILO_LEVELS = NOVA_WITH_EMPTY_LEVELS + b"compute=kilo\n"
@pytest.mark.parametrize("content,expected_content", [
(NOVA_DEFAULT, NOVA_DEFAULT),
(NOVA_WITH_EMPTY_LEVELS, NOVA_WITH_KILO_LEVELS),
])
def test_add_compute_upgrade_levels(mocker, node, content, expected_content):
with _check_upgrade_levels(mocker, node, content, expected_content):
node_util.add_compute_upgrade_levels(node, 'kilo')
@pytest.mark.parametrize("content,expected_content", [
(NOVA_DEFAULT, NOVA_DEFAULT),
(NOVA_WITH_EMPTY_LEVELS, NOVA_WITH_EMPTY_LEVELS),
(NOVA_WITH_KILO_LEVELS, NOVA_WITH_EMPTY_LEVELS),
])
def test_remove_compute_upgrade_levels(mocker, node, content,
expected_content):
with _check_upgrade_levels(mocker, node, content, expected_content):
node_util.remove_compute_upgrade_levels(node)

View File

@ -119,3 +119,21 @@ def wait_for_mcollective_start(nodes, timeout=600):
raise Exception("Timeout waiting for nodes {0} to start"
" mcollective".format(failed))
wait_list -= done
def add_compute_upgrade_levels(node, version):
sftp = ssh.sftp(node)
with ssh.update_file(sftp, '/etc/nova/nova.conf') as (old, new):
for line in old:
new.write(line)
if line.startswith("[upgrade_levels]"):
new.write("compute={0}\n".format(version))
def remove_compute_upgrade_levels(node):
sftp = ssh.sftp(node)
with ssh.update_file(sftp, '/etc/nova/nova.conf') as (old, new):
for line in old:
if line.startswith("compute="):
continue
new.write(line)