summaryrefslogtreecommitdiffstats
path: root/patches/fuel-agent/cross-bootstrap/0001-Use-qemu-debootstrap-for-image-creation.patch
blob: 97875f10020dbbb9aa8d21645aa27b9308cc4941 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
: Copyright (c) 2017 Enea AB, Cavium and others.
:
: All rights reserved. This program and the accompanying materials
: are made available under the terms of the Apache License, Version 2.0
: which accompanies this distribution, and is available at
: http://www.apache.org/licenses/LICENSE-2.0
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
From: Stanislaw Kardach <stanislaw.kardach@cavium.com>
Date: Thu, 25 Feb 2016 13:38:14 +0100
Subject: [PATCH] Use qemu-debootstrap for image creation

This commit adds qemu-debootstrap support and a command line argument
`target_arch` which can be used for choosing the architecture to build
the image for. The architecture detection from environment settings is
not yet implemented.
---
 .../fuel_bootstrap_cli/fuel_bootstrap/commands/build.py     |  8 ++++++++
 .../fuel_bootstrap/utils/bootstrap_image.py                 |  3 ++-
 debian/control                                              |  2 ++
 fuel_agent/manager.py                                       | 13 ++++++++++++-
 fuel_agent/tests/test_build_utils.py                        |  4 ++--
 fuel_agent/utils/build.py                                   |  2 +-
 specs/fuel-agent.spec                                       |  2 ++
 7 files changed, 29 insertions(+), 5 deletions(-)

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
index b4e9a05..a22d319 100644
--- a/contrib/fuel_bootstrap/fuel_bootstrap_cli/fuel_bootstrap/commands/build.py
+++ b/contrib/fuel_bootstrap/fuel_bootstrap_cli/fuel_bootstrap/commands/build.py
@@ -171,6 +171,14 @@ class BuildCommand(command.Command):
                   " by ssh still rejected by default! This password actual"
                   " only for tty login!"),
         )
+        parser.add_argument(
+            '--target_arch',
+            type=str,
+            choices=['arm64', 'amd64'],
+            help="Choose the target architecture for which image is built",
+            default="amd64"
+        )
+
         return parser

     def take_action(self, parsed_args):
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
index c09d421..a535075 100644
--- 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
@@ -161,7 +161,8 @@ def make_bootstrap(data):

     LOG.info("Try to build image with data:\n%s", yaml.safe_dump(bootdata))

-    opts = ['--data_driver', 'bootstrap_build_image']
+    opts = ['--data_driver', 'bootstrap_build_image',
+            '--target_arch', data['target_arch']]
     if data.get('image_build_dir'):
         opts.extend(['--image_build_dir', data['image_build_dir']])

diff --git a/debian/control b/debian/control
index d24450c..e843980 100644
--- a/debian/control
+++ b/debian/control
@@ -37,6 +37,8 @@ Pre-Depends: dpkg (>= 1.15.6~)
 Depends: bzip2,
          cloud-utils,
 	 debootstrap,
+	 qemu-user-static,
+	 binfmt-support,
 	 dmidecode,
 	 ethtool,
 	 gdisk,
diff --git a/fuel_agent/manager.py b/fuel_agent/manager.py
index df54f65..ba1ab78 100644
--- a/fuel_agent/manager.py
+++ b/fuel_agent/manager.py
@@ -19,6 +19,7 @@ import signal
 import tempfile

 from oslo_config import cfg
 from oslo_log import log as logging
+from oslo_config import types
 import six
 import yaml
@@ -34,5 +35,7 @@ from fuel_agent.utils import md as mu
 from fuel_agent.utils import utils

+ArchType = types.String(choices=['amd64', 'arm64'])
+
 opts = [
     cfg.StrOpt(
         'nc_template_path',
@@ -192,6 +195,13 @@ cli_opts = [
         default='/tmp',
         help='Directory where the image is supposed to be built',
     ),
+    cfg.Opt(
+        'target_arch',
+        default='amd64',
+        type=ArchType,
+        help='Architecture for which image will be built using '
+             'debootstrap',
+    ),
 ]

 CONF = cfg.CONF
@@ -724,7 +734,8 @@ class Manager(object):
         LOG.debug('Preventing services from being get started')
         bu.suppress_services_start(chroot)
         LOG.debug('Installing base operating system using debootstrap')
-        bu.run_debootstrap(uri=uri, suite=suite, chroot=chroot,
+        bu.run_debootstrap(uri=uri, suite=suite, arch=CONF.target_arch,
+                           chroot=chroot,
                            attempts=CONF.fetch_packages_attempts,
                            proxies=proxies.proxies,
                            direct_repo_addr=proxies.direct_repo_addr_list)
diff --git a/fuel_agent/tests/test_build_utils.py b/fuel_agent/tests/test_build_utils.py
index 54f79f9..0ec466f 100644
--- a/fuel_agent/tests/test_build_utils.py
+++ b/fuel_agent/tests/test_build_utils.py
@@ -43,7 +43,7 @@ class BuildUtilsTestCase(unittest2.TestCase):
     def test_run_debootstrap(self, mock_exec, mock_environ):
         bu.run_debootstrap('uri', 'suite', 'chroot', 'arch', attempts=2)
         mock_exec.assert_called_once_with(
-            'debootstrap', '--include={0}'
+            'qemu-debootstrap', '--include={0}'
             .format(','.join(bu.ADDITIONAL_DEBOOTSTRAP_PACKAGES)),
             '--verbose', '--no-check-gpg', '--arch=arch',
             'suite', 'chroot', 'uri', attempts=2, env_variables={})
@@ -54,7 +54,7 @@ class BuildUtilsTestCase(unittest2.TestCase):
         bu.run_debootstrap('uri', 'suite', 'chroot', 'arch', eatmydata=True,
                            attempts=2)
         mock_exec.assert_called_once_with(
-            'debootstrap', '--include={0}'
+            'qemu-debootstrap', '--include={0}'
             .format(','.join(bu.ADDITIONAL_DEBOOTSTRAP_PACKAGES)),
             '--verbose', '--no-check-gpg', '--arch=arch',
             '--include=eatmydata', 'suite',
diff --git a/fuel_agent/utils/build.py b/fuel_agent/utils/build.py
index b1ecc0f..2950ad8 100644
--- a/fuel_agent/utils/build.py
+++ b/fuel_agent/utils/build.py
@@ -76,7 +76,7 @@ def run_debootstrap(uri, suite, chroot, arch='amd64', eatmydata=False,
         env_vars['no_proxy'] = ','.join(direct_repo_addr)
         LOG.debug('Setting no_proxy for: {0}'.format(env_vars['no_proxy']))

-    cmds = ['debootstrap',
+    cmds = ['qemu-debootstrap',
             '--include={0}'.format(",".join(ADDITIONAL_DEBOOTSTRAP_PACKAGES)),
             '--verbose', '--no-check-gpg',
             '--arch={0}'.format(arch)]
diff --git a/specs/fuel-agent.spec b/specs/fuel-agent.spec
index 72cd6a1..18af4b9 100644
--- a/specs/fuel-agent.spec
+++ b/specs/fuel-agent.spec
@@ -50,6 +50,8 @@ Requires:    xfsprogs
 Requires:    pciutils
 Requires:    ethtool
 Requires:    debootstrap
+Requires:    dpkg
+Requires:    qemu-user-static
 Requires:    xz
 Requires:    coreutils
 Requires:    psmisc