Merge "Default to host CPU architecture if none is supplied"

This commit is contained in:
Jenkins 2017-09-08 18:41:48 +00:00 committed by Gerrit Code Review
commit 93fb65d4b0
11 changed files with 88 additions and 11 deletions

View File

@ -1,7 +1,6 @@
disk_images:
-
imagename: overcloud-hardened-full
arch: amd64
type: qcow2
distro: centos7
elements:

View File

@ -1,6 +1,5 @@
disk_images:
-
imagename: overcloud-hardened-full
arch: amd64
type: qcow2
distro: rhel7

View File

@ -1,7 +1,6 @@
disk_images:
-
imagename: overcloud-hardened-full
arch: amd64
type: qcow2
elements:
- dhcp-all-interfaces

View File

@ -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:

View File

@ -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

View File

@ -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

View File

@ -2,7 +2,6 @@ disk_images:
-
imagename: overcloud-odl
builder: dib
arch: amd64
type: qcow2
distro: rhel7
elements:

View File

@ -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.

34
tripleo_common/arch.py Normal file
View File

@ -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())

View File

@ -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')

View File

@ -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())