From fba2902dc6aacffd04697dc72dfd5e5b8a427eec Mon Sep 17 00:00:00 2001 From: Tony Breeds Date: Tue, 1 Aug 2017 15:42:36 +1000 Subject: [PATCH] Default to host CPU architecture if none is supplied Currently the only way to specify the CPU architecture of the overcloud images is by setting it in the appropriate yaml file. This is fine until you need to install a single package on multiple CPU architectures. Then you're either going to attempt to build the wrong image type or you have to edit the yaml files, which makes problems for upgrades. This change removes the default architecture from the yaml files and defaults to the appropriate DiB architecture based on running kernel. This enables builds on multiple CPU architectures from a single unmodified package Change-Id: I34f00a30c1e07869243fb95a437e05d6973a97da --- .../overcloud-hardened-images-centos7.yaml | 1 - .../overcloud-hardened-images-rhel7.yaml | 1 - image-yaml/overcloud-hardened-images.yaml | 1 - image-yaml/overcloud-images-centos7.yaml | 2 - image-yaml/overcloud-images-rhel7.yaml | 2 - image-yaml/overcloud-images.yaml | 2 - image-yaml/overcloud-odl-rhel7.yaml | 1 - ...fault-arch-selection-d5fd2fcdba725dd4.yaml | 6 +++ tripleo_common/arch.py | 34 ++++++++++++++ tripleo_common/image/build.py | 3 +- tripleo_common/tests/test_arch.py | 46 +++++++++++++++++++ 11 files changed, 88 insertions(+), 11 deletions(-) create mode 100644 releasenotes/notes/default-arch-selection-d5fd2fcdba725dd4.yaml create mode 100644 tripleo_common/arch.py create mode 100644 tripleo_common/tests/test_arch.py diff --git a/image-yaml/overcloud-hardened-images-centos7.yaml b/image-yaml/overcloud-hardened-images-centos7.yaml index d9dddd4a7..23d3415c7 100644 --- a/image-yaml/overcloud-hardened-images-centos7.yaml +++ b/image-yaml/overcloud-hardened-images-centos7.yaml @@ -1,7 +1,6 @@ disk_images: - imagename: overcloud-hardened-full - arch: amd64 type: qcow2 distro: centos7 elements: diff --git a/image-yaml/overcloud-hardened-images-rhel7.yaml b/image-yaml/overcloud-hardened-images-rhel7.yaml index 3e965de4c..0069587fe 100644 --- a/image-yaml/overcloud-hardened-images-rhel7.yaml +++ b/image-yaml/overcloud-hardened-images-rhel7.yaml @@ -1,6 +1,5 @@ disk_images: - imagename: overcloud-hardened-full - arch: amd64 type: qcow2 distro: rhel7 diff --git a/image-yaml/overcloud-hardened-images.yaml b/image-yaml/overcloud-hardened-images.yaml index 639cf7beb..b52157611 100644 --- a/image-yaml/overcloud-hardened-images.yaml +++ b/image-yaml/overcloud-hardened-images.yaml @@ -1,7 +1,6 @@ disk_images: - imagename: overcloud-hardened-full - arch: amd64 type: qcow2 elements: - dhcp-all-interfaces diff --git a/image-yaml/overcloud-images-centos7.yaml b/image-yaml/overcloud-images-centos7.yaml index ced72784d..948cc143c 100644 --- a/image-yaml/overcloud-images-centos7.yaml +++ b/image-yaml/overcloud-images-centos7.yaml @@ -1,7 +1,6 @@ disk_images: - imagename: overcloud-full - arch: amd64 type: qcow2 distro: centos7 elements: @@ -12,7 +11,6 @@ disk_images: - yum-plugin-priorities - imagename: ironic-python-agent - arch: amd64 type: qcow2 distro: centos7 elements: diff --git a/image-yaml/overcloud-images-rhel7.yaml b/image-yaml/overcloud-images-rhel7.yaml index d5dad3f91..8bc6b8e0c 100644 --- a/image-yaml/overcloud-images-rhel7.yaml +++ b/image-yaml/overcloud-images-rhel7.yaml @@ -1,13 +1,11 @@ disk_images: - imagename: overcloud-full - arch: amd64 type: qcow2 distro: rhel7 environment: FS_TYPE: xfs - imagename: ironic-python-agent - arch: amd64 type: qcow2 distro: rhel7 diff --git a/image-yaml/overcloud-images.yaml b/image-yaml/overcloud-images.yaml index b072664f3..c3a03125f 100644 --- a/image-yaml/overcloud-images.yaml +++ b/image-yaml/overcloud-images.yaml @@ -1,7 +1,6 @@ disk_images: - imagename: overcloud-full - arch: amd64 type: qcow2 elements: - baremetal @@ -41,7 +40,6 @@ disk_images: DIB_PYTHON_VERSION: '2' - imagename: ironic-python-agent - arch: amd64 # This is bogus, but there's no initrd type in diskimage-builder type: qcow2 # So we just override the extension instead diff --git a/image-yaml/overcloud-odl-rhel7.yaml b/image-yaml/overcloud-odl-rhel7.yaml index 5f815fe96..cb253edf0 100644 --- a/image-yaml/overcloud-odl-rhel7.yaml +++ b/image-yaml/overcloud-odl-rhel7.yaml @@ -2,7 +2,6 @@ disk_images: - imagename: overcloud-odl builder: dib - arch: amd64 type: qcow2 distro: rhel7 elements: diff --git a/releasenotes/notes/default-arch-selection-d5fd2fcdba725dd4.yaml b/releasenotes/notes/default-arch-selection-d5fd2fcdba725dd4.yaml new file mode 100644 index 000000000..d282a3e8c --- /dev/null +++ b/releasenotes/notes/default-arch-selection-d5fd2fcdba725dd4.yaml @@ -0,0 +1,6 @@ +--- +features: + - | + The default architecure for image builds now defaults to the cpu of the + host instead of x86_64/amd64. This allows for a single package of + tripleo-common to be used across multiple architectures to generate images. diff --git a/tripleo_common/arch.py b/tripleo_common/arch.py new file mode 100644 index 000000000..2ec9a16f1 --- /dev/null +++ b/tripleo_common/arch.py @@ -0,0 +1,34 @@ +# -*- 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 appripriate DiB arch.""" + return {'x86_64': 'amd64'}.get(kernel_arch(), kernel_arch()) + + +def cirros_arch(): + """Return the kernel arch or the more appripriate cirros arch.""" + return {'ppc64le': 'powerpc'}.get(kernel_arch(), kernel_arch()) diff --git a/tripleo_common/image/build.py b/tripleo_common/image/build.py index 710f0f912..bd3b31b78 100644 --- a/tripleo_common/image/build.py +++ b/tripleo_common/image/build.py @@ -19,6 +19,7 @@ import re from oslo_log import log from oslo_utils import strutils +import tripleo_common.arch from tripleo_common.image.base import BaseImageManager from tripleo_common.image.exception import ImageSpecificationException from tripleo_common.image.image_builder import ImageBuilder @@ -48,7 +49,7 @@ class ImageBuildManager(BaseImageManager): disk_images = self.load_config_files(self.DISK_IMAGES) for image in disk_images: - arch = image.get('arch', 'amd64') + arch = image.get('arch', tripleo_common.arch.dib_arch()) image_type = image.get('type', 'qcow2') image_name = image.get('imagename') builder = image.get('builder', 'dib') diff --git a/tripleo_common/tests/test_arch.py b/tripleo_common/tests/test_arch.py new file mode 100644 index 000000000..ec330421c --- /dev/null +++ b/tripleo_common/tests/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 tripleo_common.arch module. +""" + +import mock + +from unittest import TestCase + +from tripleo_common 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())