diff --git a/packstack/installer/core/arch.py b/packstack/installer/core/arch.py new file mode 100644 index 000000000..a1fea7ab5 --- /dev/null +++ b/packstack/installer/core/arch.py @@ -0,0 +1,42 @@ +# -*- coding: utf-8 -*- +# 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. + +""" +Simple routines to map host architectures as expected by various components. +""" + +import os + + +def kernel_arch(): + """Return the kernel arch.""" + return os.uname()[4] + + +def dib_arch(): + """Return the kernel arch or the more appropriate DiB arch.""" + DIB_MAP = { + 'x86_64': 'amd64', + 'aarch64': 'arm64', + } + return DIB_MAP.get(kernel_arch(), kernel_arch()) + + +def cirros_arch(): + """Return the kernel arch or the more appropriate cirros arch.""" + CIRROS_MAP = { + 'ppc64le': 'powerpc', + 'aarch64': 'arm', + } + return CIRROS_MAP.get(kernel_arch(), kernel_arch()) diff --git a/packstack/plugins/provision_700.py b/packstack/plugins/provision_700.py index 810b8bf8a..cd06aa68e 100644 --- a/packstack/plugins/provision_700.py +++ b/packstack/plugins/provision_700.py @@ -20,6 +20,7 @@ from packstack.installer import basedefs from packstack.installer import utils from packstack.installer import validators from packstack.installer import processors +from packstack.installer.core import arch from packstack.modules.documentation import update_params_usage @@ -30,19 +31,23 @@ PLUGIN_NAME_COLORED = utils.color_text(PLUGIN_NAME, 'blue') DEMO_IMAGE_NAME = 'cirros' DEMO_IMAGE_URL = ( - 'http://download.cirros-cloud.net/0.3.4/cirros-0.3.4-x86_64-disk.img' + 'http://download.cirros-cloud.net/0.3.4/cirros-0.3.4-%s-disk.img' + % (arch.cirros_arch()) ) DEMO_IMAGE_SSH_USER = 'cirros' DEMO_IMAGE_FORMAT = 'qcow2' UEC_IMAGE_NAME = 'cirros-uec' UEC_IMAGE_KERNEL_URL = ( - 'http://download.cirros-cloud.net/0.3.4/cirros-0.3.4-x86_64-kernel' + 'http://download.cirros-cloud.net/0.3.4/cirros-0.3.4-%s-kernel' + % (arch.cirros_arch()) ) UEC_IMAGE_RAMDISK_URL = ( - 'http://download.cirros-cloud.net/0.3.4/cirros-0.3.4-x86_64-initramfs' + 'http://download.cirros-cloud.net/0.3.4/cirros-0.3.4-%s-initramfs' + % (arch.cirros_arch()) ) UEC_IMAGE_DISK_URL = ( - 'http://download.cirros-cloud.net/0.3.4/cirros-0.3.4-x86_64-disk.img' + 'http://download.cirros-cloud.net/0.3.4/cirros-0.3.4-%s-disk.img' + % (arch.cirros_arch()) ) diff --git a/test-requirements.txt b/test-requirements.txt index 013f1390c..8cfc54a0d 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -4,3 +4,4 @@ reno>=0.1.1 # Apache2 os-testr>=0.4.1 # Apache-2.0 coverage hacking!=0.13.0,<0.14,>=0.12.0 +mock>=2.0 # BSD diff --git a/tests/installer/test_arch.py b/tests/installer/test_arch.py new file mode 100644 index 000000000..33d474c10 --- /dev/null +++ b/tests/installer/test_arch.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# vim: tabstop=4 shiftwidth=4 softtabstop=4 + +# Copyright 2017, Red Hat, Inc. +# +# 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. + +""" +Test cases for packstack.installer.core.arch module. +""" + +import mock + +from unittest import TestCase + +from packstack.installer.core import arch + + +class ArchTestCase(TestCase): + def test_kernel_arch(self): + for (expected, _arch) in [('x86_64', 'x86_64'), + ('ppc64le', 'ppc64le')]: + with mock.patch('os.uname', return_value=('', '', '', '', _arch)): + self.assertEqual(expected, arch.kernel_arch()) + + def test_dib_arch(self): + for (expected, _arch) in [('amd64', 'x86_64'), + ('ppc64le', 'ppc64le')]: + with mock.patch('os.uname', return_value=('', '', '', '', _arch)): + self.assertEqual(expected, arch.dib_arch()) + + def test_cirros_arch(self): + for (expected, _arch) in [('x86_64', 'x86_64'), + ('powerpc', 'ppc64le')]: + with mock.patch('os.uname', return_value=('', '', '', '', _arch)): + self.assertEqual(expected, arch.cirros_arch())