1 From: Stanislaw Kardach <stanislaw.kardach@caviumnetworks.com>
2 Date: Thu, 25 Feb 2016 13:38:14 +0100
3 Subject: [PATCH] Use qemu-debootstrap for image creation
5 This commit adds qemu-debootstrap support and a command line argument
6 `target_arch` which can be used for choosing the architecture to build
7 the image for. The architecture detection from environment settings is
10 .../fuel_bootstrap_cli/fuel_bootstrap/commands/build.py | 8 ++++++++
11 .../fuel_bootstrap/utils/bootstrap_image.py | 3 ++-
13 fuel_agent/manager.py | 13 ++++++++++++-
14 fuel_agent/tests/test_build_utils.py | 4 ++--
15 fuel_agent/utils/build.py | 2 +-
16 specs/fuel-agent.spec | 2 ++
17 7 files changed, 29 insertions(+), 5 deletions(-)
19 diff --git a/contrib/fuel_bootstrap/fuel_bootstrap_cli/fuel_bootstrap/commands/build.py b/contrib/fuel_bootstrap/fuel_bootstrap_cli/fuel_bootstrap/commands/build.py
20 index ca2d3e1..b0d410d 100644
21 --- a/contrib/fuel_bootstrap/fuel_bootstrap_cli/fuel_bootstrap/commands/build.py
22 +++ b/contrib/fuel_bootstrap/fuel_bootstrap_cli/fuel_bootstrap/commands/build.py
23 @@ -166,4 +166,12 @@ class BuildCommand(command.Command):
25 + parser.add_argument(
28 + choices=['arm64', 'amd64'],
29 + help="Choose the target architecture for which image is built",
35 def take_action(self, parsed_args):
36 diff --git a/contrib/fuel_bootstrap/fuel_bootstrap_cli/fuel_bootstrap/utils/bootstrap_image.py b/contrib/fuel_bootstrap/fuel_bootstrap_cli/fuel_bootstrap/utils/bootstrap_image.py
37 index 0219961..6e60fb8 100644
38 --- a/contrib/fuel_bootstrap/fuel_bootstrap_cli/fuel_bootstrap/utils/bootstrap_image.py
39 +++ b/contrib/fuel_bootstrap/fuel_bootstrap_cli/fuel_bootstrap/utils/bootstrap_image.py
40 @@ -172,7 +172,8 @@ def make_bootstrap(data):
42 LOG.info("Try to build image with data:\n%s", yaml.safe_dump(bootdata))
44 - opts = ['--data_driver', 'bootstrap_build_image']
45 + opts = ['--data_driver', 'bootstrap_build_image',
46 + '--target_arch', data['target_arch']]
47 if data.get('image_build_dir'):
48 opts.extend(['--image_build_dir', data['image_build_dir']])
50 diff --git a/debian/control b/debian/control
51 index 0a6f947..189dc00 100644
54 @@ -36,6 +36,8 @@ Pre-Depends: dpkg (>= 1.15.6~)
63 diff --git a/fuel_agent/manager.py b/fuel_agent/manager.py
64 index 15cc5d8..f613aef 100644
65 --- a/fuel_agent/manager.py
66 +++ b/fuel_agent/manager.py
67 @@ -18,5 +18,6 @@ import shutil
69 from oslo_config import cfg
70 +from oslo_config import types
74 @@ -33,6 +34,8 @@ from fuel_agent.utils import md as mu
75 from fuel_agent.utils import partition as pu
76 from fuel_agent.utils import utils
78 +ArchType = types.String(choices=['amd64', 'arm64'])
83 @@ -153,6 +156,13 @@ cli_opts = [
85 help='Directory where the image is supposed to be built',
91 + help='Architecture for which image will be built using '
97 @@ -551,7 +561,8 @@ class Manager(object):
98 LOG.debug('Preventing services from being get started')
99 bu.suppress_services_start(chroot)
100 LOG.debug('Installing base operating system using debootstrap')
101 - bu.run_debootstrap(uri=uri, suite=suite, chroot=chroot,
102 + bu.run_debootstrap(uri=uri, suite=suite, arch=CONF.target_arch,
104 attempts=CONF.fetch_packages_attempts,
105 proxies=proxies.proxies,
106 direct_repo_addr=proxies.direct_repo_addr_list)
107 diff --git a/fuel_agent/tests/test_build_utils.py b/fuel_agent/tests/test_build_utils.py
108 index 82c3462..ac5ae82 100644
109 --- a/fuel_agent/tests/test_build_utils.py
110 +++ b/fuel_agent/tests/test_build_utils.py
111 @@ -42,7 +42,7 @@ class BuildUtilsTestCase(unittest2.TestCase):
112 def test_run_debootstrap(self, mock_exec, mock_environ):
113 bu.run_debootstrap('uri', 'suite', 'chroot', 'arch', attempts=2)
114 mock_exec.assert_called_once_with(
115 - 'debootstrap', '--include={0}'
116 + 'qemu-debootstrap', '--include={0}'
117 .format(','.join(bu.ADDITIONAL_DEBOOTSTRAP_PACKAGES)),
118 '--verbose', '--no-check-gpg', '--arch=arch',
119 'suite', 'chroot', 'uri', attempts=2, env_variables={})
120 @@ -53,7 +53,7 @@ class BuildUtilsTestCase(unittest2.TestCase):
121 bu.run_debootstrap('uri', 'suite', 'chroot', 'arch', eatmydata=True,
123 mock_exec.assert_called_once_with(
124 - 'debootstrap', '--include={0}'
125 + 'qemu-debootstrap', '--include={0}'
126 .format(','.join(bu.ADDITIONAL_DEBOOTSTRAP_PACKAGES)),
127 '--verbose', '--no-check-gpg', '--arch=arch',
128 '--include=eatmydata', 'suite',
129 diff --git a/fuel_agent/utils/build.py b/fuel_agent/utils/build.py
130 index 7247965..af41b2b 100644
131 --- a/fuel_agent/utils/build.py
132 +++ b/fuel_agent/utils/build.py
133 @@ -80,7 +80,7 @@ def run_debootstrap(uri, suite, chroot, arch='amd64', eatmydata=False,
134 env_vars['no_proxy'] = ','.join(direct_repo_addr)
135 LOG.debug('Setting no_proxy for: {0}'.format(env_vars['no_proxy']))
137 - cmds = ['debootstrap',
138 + cmds = ['qemu-debootstrap',
139 '--include={0}'.format(",".join(ADDITIONAL_DEBOOTSTRAP_PACKAGES)),
140 '--verbose', '--no-check-gpg',
141 '--arch={0}'.format(arch)]
142 diff --git a/specs/fuel-agent.spec b/specs/fuel-agent.spec
143 index 5c37600..a43f693 100644
144 --- a/specs/fuel-agent.spec
145 +++ b/specs/fuel-agent.spec
146 @@ -50,6 +50,8 @@ Requires: xfsprogs
149 Requires: debootstrap
151 +Requires: qemu-user-static