Delete old images after restoring
Remove exists images after restore call because they are contains old ssh keys and can't be used anymore. Change-Id: Ib8887621d2fef69c2ee00ebad486415a9be476d3 Closes-Bug: #1558057
This commit is contained in:
parent
a3c7657951
commit
18f2a6b09e
|
@ -11,6 +11,7 @@
|
|||
# under the License.
|
||||
|
||||
from octane.handlers.backup_restore import base
|
||||
from octane.util import fuel_bootstrap
|
||||
from octane.util import subprocess
|
||||
|
||||
|
||||
|
@ -23,3 +24,6 @@ class SshArchivator(base.PathArchivator):
|
|||
subprocess.call(
|
||||
["fuel-bootstrap", "build", "--activate"],
|
||||
env=self.context.get_credentials_env())
|
||||
|
||||
# Remove old images cause they were created with old ssh keys pair
|
||||
fuel_bootstrap.delete_not_active_images()
|
||||
|
|
|
@ -70,3 +70,5 @@ RELEASE_STATUS_MANAGED = "manageonly"
|
|||
UPGRADE_NODE_PATCHES = [
|
||||
os.path.join(CWD, "patches/puppet/fix_mysql.patch")
|
||||
]
|
||||
|
||||
BOOTSTRAP_UNSUPPORTED_IMAGES = ["centos"]
|
||||
|
|
|
@ -145,7 +145,13 @@ class TestArchive(object):
|
|||
),
|
||||
])
|
||||
def test_path_restore(mocker, cls, path, members):
|
||||
fake_uuids = ['00000000-1111-2222-3333-444444444444', 'centos']
|
||||
subprocess_mock = mocker.patch("octane.util.subprocess.call")
|
||||
get_images = mocker.patch(
|
||||
"octane.util.fuel_bootstrap.get_not_active_images_uuids",
|
||||
return_value=fake_uuids)
|
||||
delete_image = mocker.patch("octane.util.fuel_bootstrap.delete_image")
|
||||
|
||||
members = [TestMember(n, f, e) for n, f, e in members]
|
||||
archive = TestArchive(members, cls)
|
||||
mocker.patch("os.environ", new_callable=mock.PropertyMock(return_value={}))
|
||||
|
@ -158,6 +164,8 @@ def test_path_restore(mocker, cls, path, members):
|
|||
subprocess_mock.assert_called_once_with(
|
||||
["fuel-bootstrap", "build", "--activate"],
|
||||
env={'OS_PASSWORD': 'password', 'OS_USERNAME': 'user'})
|
||||
get_images.assert_called_once()
|
||||
delete_image.assert_called_once_with(fake_uuids[0])
|
||||
else:
|
||||
assert not subprocess_mock.called
|
||||
|
||||
|
|
|
@ -0,0 +1,38 @@
|
|||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import json
|
||||
|
||||
from octane.util import fuel_bootstrap
|
||||
|
||||
|
||||
def test_get_images_uuids(mocker):
|
||||
fake_output = [{"status": "active",
|
||||
"uuid": "00000000-1111-2222-3333-444444444444",
|
||||
"label": "00000000-1111-2222-3333-444444444444"},
|
||||
{"status": "",
|
||||
"uuid": "55555555-6666-7777-8888-999999999999",
|
||||
"label": "55555555-6666-7777-8888-999999999999"}]
|
||||
|
||||
mocker.patch('octane.util.subprocess.call_output',
|
||||
return_value=json.dumps(fake_output))
|
||||
|
||||
uuids = fuel_bootstrap.get_not_active_images_uuids()
|
||||
|
||||
assert uuids == [fake_output[1]['uuid']]
|
||||
|
||||
|
||||
def test_delete_image(mocker):
|
||||
fake_uuid = "00000000-1111-2222-3333-444444444444"
|
||||
call = mocker.patch('octane.util.subprocess.call')
|
||||
fuel_bootstrap.delete_image(fake_uuid)
|
||||
call.assert_called_once_with(['fuel-bootstrap', 'delete', fake_uuid])
|
|
@ -0,0 +1,33 @@
|
|||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import json
|
||||
|
||||
from octane import magic_consts
|
||||
from octane.util import subprocess
|
||||
|
||||
|
||||
def get_not_active_images_uuids():
|
||||
fuel_bootstrap_list = ["fuel-bootstrap", "list", "--format", "json"]
|
||||
images = json.loads(subprocess.call_output(fuel_bootstrap_list))
|
||||
return [img["uuid"] for img in images if img["status"] != "active"]
|
||||
|
||||
|
||||
def delete_image(uuid):
|
||||
subprocess.call(["fuel-bootstrap", "delete", uuid])
|
||||
|
||||
|
||||
def delete_not_active_images():
|
||||
# Remove old images cause they were created with old ssh keys pair
|
||||
for image_uuid in get_not_active_images_uuids():
|
||||
if image_uuid not in magic_consts.BOOTSTRAP_UNSUPPORTED_IMAGES:
|
||||
delete_image(image_uuid)
|
Loading…
Reference in New Issue