Refactoring osd cmd
* Use util/apt function for construct sources * Use util/apt function for contrstruct preferences Change-Id: I3bbdeb3a0bc31154be4cce7d8d354e05b0700084 Partial-Bug: 1620277
This commit is contained in:
parent
19ae8ddcdb
commit
12160e1676
|
@ -13,6 +13,7 @@
|
|||
import contextlib
|
||||
import json
|
||||
import logging
|
||||
import operator
|
||||
import os
|
||||
import time
|
||||
|
||||
|
@ -22,6 +23,7 @@ from fuelclient.objects import environment as env_obj
|
|||
|
||||
from octane.handlers import backup_restore
|
||||
from octane import magic_consts
|
||||
from octane.util import apt
|
||||
from octane.util import env
|
||||
from octane.util import fuel_client
|
||||
from octane.util import ssh
|
||||
|
@ -52,22 +54,20 @@ def write_content_to_tmp_file_on_node(node, content, directory, template):
|
|||
|
||||
|
||||
def generate_source_content(repos):
|
||||
return '\n'.join([magic_consts.OSD_UPGRADE_SOURCE_TEMPLATE.format(**repo)
|
||||
for repo in repos])
|
||||
return '\n\n'.join([apt.create_repo_source(r)[1] for r in repos])
|
||||
|
||||
|
||||
def generate_preference_pin(repos, priority):
|
||||
packages = " ".join(magic_consts.OSD_UPGRADE_REQUIRED_PACKAGES)
|
||||
contents = []
|
||||
for repo in repos:
|
||||
suite = repo['suite']
|
||||
contents.append(
|
||||
magic_consts.OSD_UPGADE_PREFERENCE_TEMPLATE.format(
|
||||
packages=packages,
|
||||
suite=suite,
|
||||
priority=priority
|
||||
))
|
||||
return '\n'.join(contents)
|
||||
priority_getter = operator.itemgetter('priority')
|
||||
for repo in sorted(repos, key=priority_getter):
|
||||
if repo['priority'] is None:
|
||||
continue
|
||||
repo['priority'] = max(repo['priority'], priority)
|
||||
_, content = apt.create_repo_preferences(repo, packages)
|
||||
contents.append(content)
|
||||
return '\n\n'.join(contents)
|
||||
|
||||
|
||||
def apply_source_for_node(node, content):
|
||||
|
|
|
@ -60,12 +60,7 @@ OSD_UPGRADE_REQUIRED_PACKAGES = [
|
|||
"python-rados", "python-rbd", "ceph", "ceph-common", "ceph-fs-common",
|
||||
"ceph-mds",
|
||||
]
|
||||
OSD_UPGRADE_SOURCE_TEMPLATE = "{type} {uri} {suite} {section}"
|
||||
|
||||
OSD_UPGADE_PREFERENCE_TEMPLATE = \
|
||||
"Package: {packages}\n" \
|
||||
"Pin: release a={suite},n={suite},l={suite}\n" \
|
||||
"Pin-Priority: {priority}"
|
||||
COBBLER_DROP_VERSION = "7.0"
|
||||
CEPH_UPSTART_VERSION = "7.0"
|
||||
NOVA_FLAVOR_DATA_MIGRATION_VERSION = "7.0"
|
||||
|
|
|
@ -215,7 +215,7 @@ def test_upgrade_osd(
|
|||
u'type': u'deb',
|
||||
}
|
||||
],
|
||||
"deb http://ubuntu/ trusty main universe multiverse\n"
|
||||
"deb http://ubuntu/ trusty main universe multiverse\n\n"
|
||||
"deb http://ubuntu/ trusty-updates main universe multiverse"
|
||||
),
|
||||
])
|
||||
|
@ -223,7 +223,7 @@ def test_generate_source_content(repos, result):
|
|||
assert result == osd_upgrade.generate_source_content(repos)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("repos,priority,result", [
|
||||
@pytest.mark.parametrize("repos,priority,call_repos", [
|
||||
(
|
||||
[
|
||||
{
|
||||
|
@ -244,18 +244,68 @@ def test_generate_source_content(repos, result):
|
|||
}
|
||||
],
|
||||
1000,
|
||||
"Package: libcephfs1 librados2 librbd1 python-ceph python-cephfs "
|
||||
"python-rados python-rbd ceph ceph-common ceph-fs-common ceph-mds\n"
|
||||
"Pin: release a=trusty,n=trusty,l=trusty\n"
|
||||
"Pin-Priority: 1000\n"
|
||||
"Package: libcephfs1 librados2 librbd1 python-ceph python-cephfs "
|
||||
"python-rados python-rbd ceph ceph-common ceph-fs-common ceph-mds\n"
|
||||
"Pin: release a=trusty-updates,n=trusty-updates,l=trusty-updates\n"
|
||||
"Pin-Priority: 1000"
|
||||
[]
|
||||
),
|
||||
(
|
||||
[
|
||||
{
|
||||
u'name': u'ubuntu',
|
||||
u'section': u'main universe multiverse',
|
||||
u'uri': u'http://ubuntu/',
|
||||
u'priority': 1001,
|
||||
u'suite': u'trusty',
|
||||
u'type': u'deb',
|
||||
},
|
||||
{
|
||||
u'name': u'ubuntu-updates',
|
||||
u'section': u'main universe multiverse',
|
||||
u'uri': u'http://ubuntu/',
|
||||
u'priority': 99,
|
||||
u'suite': u'trusty-updates',
|
||||
u'type': u'deb',
|
||||
}
|
||||
],
|
||||
1000,
|
||||
[
|
||||
{
|
||||
u'name': u'ubuntu-updates',
|
||||
u'section': u'main universe multiverse',
|
||||
u'uri': u'http://ubuntu/',
|
||||
u'priority': 1000,
|
||||
u'suite': u'trusty-updates',
|
||||
u'type': u'deb',
|
||||
},
|
||||
{
|
||||
u'name': u'ubuntu',
|
||||
u'section': u'main universe multiverse',
|
||||
u'uri': u'http://ubuntu/',
|
||||
u'priority': 1001,
|
||||
u'suite': u'trusty',
|
||||
u'type': u'deb',
|
||||
},
|
||||
]
|
||||
),
|
||||
])
|
||||
def test_generate_preference_pin(repos, priority, result):
|
||||
assert result == osd_upgrade.generate_preference_pin(repos, priority)
|
||||
@pytest.mark.parametrize("packages", [["pack_1", "pack_2"]])
|
||||
def test_generate_preference_pin(
|
||||
mocker, repos, priority, call_repos, packages):
|
||||
mocker.patch("octane.magic_consts.OSD_UPGRADE_REQUIRED_PACKAGES", packages)
|
||||
|
||||
mock_call_repos = []
|
||||
|
||||
def foo(repo, packages):
|
||||
repo = repo.copy()
|
||||
repo['priority'] = max(priority, repo['priority'])
|
||||
repo['packages'] = packages
|
||||
mock_call_repos.append(repo)
|
||||
return None, repo["name"]
|
||||
|
||||
mocker.patch("octane.util.apt.create_repo_preferences", side_effect=foo)
|
||||
result_repos = '\n\n'.join(r['name'] for r in call_repos)
|
||||
assert result_repos == osd_upgrade.generate_preference_pin(repos, priority)
|
||||
for repo in call_repos:
|
||||
repo['packages'] = ' '.join(packages)
|
||||
assert call_repos == mock_call_repos
|
||||
|
||||
|
||||
@pytest.mark.parametrize("content", ["content"])
|
||||
|
|
Loading…
Reference in New Issue