Restore backup on machine with wrong ip not allowed
Change-Id: Ie4b6af9807046df4928f5de54d47f289eb145f61
Closes-Bug: #1547804
(cherry picked from commit 7b5c18ba1d
)
This commit is contained in:
parent
51c28e90b7
commit
f855210a46
|
@ -64,6 +64,13 @@ class AstuteArchivator(base.PathArchivator):
|
|||
("FUEL_ACCESS", ["user", "password"]),
|
||||
]
|
||||
|
||||
def get_backup_dict(self):
|
||||
return yaml.load(self.archive.extractfile(self.name))
|
||||
|
||||
def get_current_dict(self):
|
||||
with open(self.path, "r") as current:
|
||||
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)
|
||||
|
@ -71,12 +78,16 @@ class AstuteArchivator(base.PathArchivator):
|
|||
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:
|
||||
raise Exception(
|
||||
"Restore allowed on machine with same ipaddress. "
|
||||
"Use fuel-menu to set up ipaddress to {0}".format(backup_ip))
|
||||
|
||||
def restore(self):
|
||||
dump = self.archive.extractfile(self.name)
|
||||
backup_yaml = yaml.load(dump)
|
||||
with open(self.path, "r") as current:
|
||||
current_yaml = yaml.load(current)
|
||||
backup_yaml = self.get_backup_dict()
|
||||
current_yaml = self.get_current_dict()
|
||||
not_found_keys = []
|
||||
for key, subkeys in self.keys_to_restore:
|
||||
if not subkeys and key not in backup_yaml:
|
||||
|
|
|
@ -15,6 +15,8 @@ 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", [
|
||||
|
@ -70,3 +72,34 @@ def test_restore_data(mocker):
|
|||
mock.call(tar_mock.return_value, None),
|
||||
mock.call().pre_restore_check(),
|
||||
mock.call().restore()])
|
||||
|
||||
|
||||
@pytest.mark.parametrize("backup_ip,current_ip", [
|
||||
("10.21.10.2", "10.21.10.2"),
|
||||
("10.21.10.2", "10.21.10.12"),
|
||||
])
|
||||
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,
|
||||
"get_backup_dict",
|
||||
return_value={"ADMIN_NETWORK": {"ipaddress": backup_ip}}
|
||||
)
|
||||
mocker.patch.object(
|
||||
astute.AstuteArchivator,
|
||||
"get_current_dict",
|
||||
return_value={"ADMIN_NETWORK": {"ipaddress": current_ip}}
|
||||
)
|
||||
archivator = astute.AstuteArchivator(tar_mock)
|
||||
if backup_ip == current_ip:
|
||||
archivator.pre_restore_check()
|
||||
else:
|
||||
with pytest.raises(Exception) as exc:
|
||||
archivator.pre_restore_check()
|
||||
assert 'Restore allowed on machine with same ipaddress. ' \
|
||||
'Use fuel-menu to set up ipaddress to {0}'.format(
|
||||
backup_ip) == exc.value.message
|
||||
|
|
Loading…
Reference in New Issue