Skip to content

Commit 1efc6c1

Browse files
check for migration target by matching ISO file name
Detecting migration target by querying RPMs might not work for all versions, so we check by matching ISO file name instead.
1 parent 3499650 commit 1efc6c1

File tree

3 files changed

+38
-29
lines changed

3 files changed

+38
-29
lines changed

suse_migration_services/migration_target.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,10 @@
2020
import yaml
2121
import os
2222
import platform
23+
from glob import glob
24+
from fnmatch import fnmatch
2325

2426
from suse_migration_services.defaults import Defaults
25-
from suse_migration_services.command import Command
2627

2728
log = logging.getLogger(Defaults.get_migration_log_name())
2829

@@ -55,24 +56,22 @@ def get_migration_target():
5556
'version': product[1],
5657
'arch': product[2]
5758
}
58-
sles15_migration = Command.run(
59-
['rpm', '-q', 'SLES15-Migration'], raise_on_error=False
60-
)
61-
if sles15_migration.returncode == 0:
59+
migration_iso = glob('/migration-image/*-*Migration.*.iso')
60+
if not migration_iso:
61+
return {}
62+
migration_iso = migration_iso[0]
63+
64+
if fnmatch(migration_iso, '*SLES16*-*Migration*.iso'):
6265
# return default migration target
6366
return {
6467
'identifier': 'SLES',
65-
'version': '15.3',
68+
'version': '16.0',
6669
'arch': platform.machine()
6770
}
68-
sles16_migration = Command.run(
69-
['rpm', '-q', 'SLES16-Migration'], raise_on_error=False
70-
)
71-
if sles16_migration.returncode == 0:
71+
else:
7272
# return default migration target
7373
return {
7474
'identifier': 'SLES',
75-
'version': '16.0',
75+
'version': '15.4',
7676
'arch': platform.machine()
7777
}
78-
return {}

test/unit/migration_target_test.py

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from unittest.mock import (
2-
patch, Mock
2+
patch
33
)
44

55
from suse_migration_services.migration_target import MigrationTarget
@@ -8,35 +8,45 @@
88
class TestMigrationTarget(object):
99
@patch('platform.machine')
1010
@patch('os.path.isfile')
11-
@patch('suse_migration_services.command.Command.run')
12-
def test_get_migration_target(
13-
self, mock_Command_run, mock_os_path_isfile,
11+
@patch('suse_migration_services.migration_target.glob')
12+
def test_get_migration_target_empty(
13+
self, mock_glob, mock_os_path_isfile,
1414
mock_platform_machine
1515
):
1616
mock_platform_machine.return_value = 'x86_64'
17-
sles15_migration = Mock()
18-
sles15_migration.returncode = 0
19-
mock_Command_run.return_value = sles15_migration
17+
mock_glob.return_value = []
18+
mock_os_path_isfile.return_value = False
19+
assert MigrationTarget.get_migration_target() == {}
20+
21+
@patch('platform.machine')
22+
@patch('os.path.isfile')
23+
@patch('suse_migration_services.migration_target.glob')
24+
def test_get_migration_target_sles15(
25+
self, mock_glob, mock_os_path_isfile,
26+
mock_platform_machine
27+
):
28+
mock_platform_machine.return_value = 'x86_64'
29+
mock_glob.return_value = [
30+
'/migration-image/SLES15-Migration.x86_64-2.1.9-Build6.64.99.iso'
31+
]
2032
mock_os_path_isfile.return_value = False
2133
assert MigrationTarget.get_migration_target() == {
2234
'identifier': 'SLES',
23-
'version': '15.3',
35+
'version': '15.4',
2436
'arch': 'x86_64'
2537
}
2638

2739
@patch('platform.machine')
2840
@patch('os.path.isfile')
29-
@patch('suse_migration_services.command.Command.run')
41+
@patch('suse_migration_services.migration_target.glob')
3042
def test_get_migration_target_sles16(
31-
self, mock_Command_run, mock_os_path_isfile,
43+
self, mock_glob, mock_os_path_isfile,
3244
mock_platform_machine
3345
):
46+
mock_glob.return_value = [
47+
'/migration-image/SLES16-Migration.x86_64-2.1.23-Build2.1.iso'
48+
]
3449
mock_platform_machine.return_value = 'x86_64'
35-
sles15_migration_not_found = Mock()
36-
sles15_migration_not_found.returncode = 1 # SLES15-Migration not found
37-
sles16_migration_found = Mock()
38-
sles16_migration_found.returncode = 0 # SLES16-Migration found
39-
mock_Command_run.side_effect = [sles15_migration_not_found, sles16_migration_found]
4050
mock_os_path_isfile.return_value = False # No /etc/sle-migration-service.yml
4151
assert MigrationTarget.get_migration_target() == {
4252
'identifier': 'SLES',

tools/run_migration

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,8 @@ if ${is_sles16_migration}; then
163163
# SLE16 image panics on CPUs older than x86_64_v2 (i.e. x86_64) (bsc#1249593), so we need to
164164
# block migration before getting into the image.
165165
if [ "$(zypper system-architecture)" == "x86_64" ]; then
166-
echo "CPU Architecture too old. Aborting migration."
167-
exit 1
166+
echo "CPU Architecture too old. Aborting migration."
167+
exit 1
168168
fi
169169

170170
# store snapper pre snapshot if available

0 commit comments

Comments
 (0)