Remove docker related code from AstuteArchivator

Since the removing docker containers from the host re-initialization of
services should be done by applying puppet manifests. The code that
responsible for doing this with containers were removed from
AstuteArchivator and now this archivator responsible only for restoring
the astute.yaml file, this re-initialization will be added as a separate
archivator.

Change-Id: Ied3b5132e9dce1c37b259f74d76c93f56dbcdf67
This commit is contained in:
Ilya Kharin 2016-04-20 10:42:38 +03:00
parent c61d6b0beb
commit 9f99b29f8e
5 changed files with 10 additions and 65 deletions

View File

@ -12,7 +12,7 @@
import os
# from octane.handlers.backup_restore import astute
from octane.handlers.backup_restore import astute
# from octane.handlers.backup_restore import cobbler
from octane.handlers.backup_restore import fuel_keys
from octane.handlers.backup_restore import fuel_uuid
@ -31,7 +31,7 @@ from octane.handlers.backup_restore import version
# services are run now in OS on the host. This major change requires to
# modify current archivators that use containers.
ARCHIVATORS = [
# astute.AstuteArchivator,
astute.AstuteArchivator,
# SSH restore must go before Cobbler restore so it updates
# /etc/cobbler/authorized_keys file automatically
ssh.SshArchivator,

View File

@ -15,8 +15,7 @@ import shutil
import yaml
from octane.handlers.backup_restore import base
from octane import magic_consts
from octane.util import docker
from octane.util import puppet
LOG = logging.getLogger(__name__)
@ -72,12 +71,6 @@ class AstuteArchivator(base.PathArchivator):
return yaml.load(current)
def pre_restore_check(self):
names = docker.get_docker_container_names(status="running")
containers = set(magic_consts.RUNNING_REQUIRED_CONTAINERS) - set(names)
if containers:
raise Exception(
"Required running containers: {0}".format(
", ".join(containers)))
backup_ip = self.get_backup_dict()["ADMIN_NETWORK"]["ipaddress"]
current_ip = self.get_current_dict()["ADMIN_NETWORK"]["ipaddress"]
if backup_ip != current_ip:
@ -116,17 +109,5 @@ class AstuteArchivator(base.PathArchivator):
self._post_restore_action()
def _post_restore_action(self):
# restart all running containers
for name in magic_consts.RUNNING_REQUIRED_CONTAINERS:
docker.stop_container(name)
# FIXME: when astute container restart corrent this may be removed
if "astute" == name:
try:
docker.start_container(name)
except Exception:
LOG.warn(
"Failed to start astute container for the first time")
docker.stop_container(name)
else:
continue
docker.start_container(name)
for task in ["hiera", "host"]:
puppet.apply_task(task)

View File

@ -47,22 +47,6 @@ NAILGUN_URL = "http://127.0.0.1:8000"
KEYSTONE_API_URL = "http://127.0.0.1:5000/v2.0"
KEYSTONE_TENANT_NAME = "admin"
SYNC_CONTAINERS = []
RUNNING_REQUIRED_CONTAINERS = [
"postgres",
"rabbitmq",
"keystone",
"rsync",
"astute",
"rsyslog",
"nailgun",
"ostf",
"nginx",
"cobbler",
"mcollective",
]
OPENSTACK_FIXTURES = "/usr/share/fuel-openstack-metadata/openstack.yaml"
OSD_REPOS_UPDATE = [

View File

@ -450,20 +450,18 @@ def test_astute_restore(mocker, mock_open, keys_in_dump_file, restored):
safe_dump = mocker.patch("yaml.safe_dump")
copy_mock = mocker.patch("shutil.copy2")
move_mock = mocker.patch("shutil.move")
mock_puppet = mocker.patch("octane.util.puppet.apply_task")
cls = astute.AstuteArchivator
archive = TestArchive([member], cls)
post_restore_mock = mocker.patch.object(cls, "_post_restore_action")
try:
cls(archive).restore()
except Exception as exc:
if restored:
raise
assert str(exc).startswith("Not found values in backup for keys: ")
assert not post_restore_mock.called
else:
assert restored
member.assert_extract()
post_restore_mock.assert_called_once_with()
copy_mock.assert_called_once_with(
"/etc/fuel/astute.yaml", "/etc/fuel/astute.yaml.old")
move_mock.assert_called_once_with(
@ -471,24 +469,10 @@ def test_astute_restore(mocker, mock_open, keys_in_dump_file, restored):
safe_dump.assert_called_once_with(dict_to_restore,
mock_open.return_value,
default_flow_style=False)
def test_post_restore_action_astute(mocker):
stopped = []
mocker.patch(
"octane.util.docker.get_docker_container_names",
return_value=["container_1", "container_2"]
)
start = mocker.patch("octane.util.docker.start_container",
side_effect=stopped.remove)
stop = mocker.patch("octane.util.docker.stop_container",
side_effect=stopped.append)
astute.AstuteArchivator(None)._post_restore_action()
assert start.called
assert stop.called
assert not stopped
assert mock_puppet.mock_calls == [
mock.call("hiera"),
mock.call("host"),
]
@pytest.mark.parametrize(("dump", "calls"), [

View File

@ -16,7 +16,6 @@ import pytest
from octane.commands import restore
from octane.handlers import backup_restore
from octane.handlers.backup_restore import astute
from octane import magic_consts
@pytest.mark.parametrize("path,is_file", [
@ -80,9 +79,6 @@ def test_restore_data(mocker):
])
def test_astute_checker(
mocker, mock_open, backup_ip, current_ip):
mocker.patch(
"octane.util.docker.get_docker_container_names",
return_value=magic_consts.RUNNING_REQUIRED_CONTAINERS)
tar_mock = mocker.Mock()
mocker.patch.object(
astute.AstuteArchivator,