Rebase after "Bugfix Broadcast Group".
[armband.git] / patches / fuel-agent / 0001-Use-qemu-debootstrap-for-image-creation.patch
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
4
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
8 not yet implemented.
9 ---
10  .../fuel_bootstrap_cli/fuel_bootstrap/commands/build.py     |  8 ++++++++
11  .../fuel_bootstrap/utils/bootstrap_image.py                 |  3 ++-
12  debian/control                                              |  2 ++
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(-)
18
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,6 +166,14 @@ class BuildCommand(command.Command):
24                   " files",
25              action='append'
26          )
27 +        parser.add_argument(
28 +            '--target_arch',
29 +            type=str,
30 +            choices=['arm64', 'amd64'],
31 +            help="Choose the target architecture for which image is built",
32 +            default="amd64"
33 +        )
34 +
35          return parser
36  
37      def take_action(self, parsed_args):
38 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
39 index 0219961..1387cf9 100644
40 --- a/contrib/fuel_bootstrap/fuel_bootstrap_cli/fuel_bootstrap/utils/bootstrap_image.py
41 +++ b/contrib/fuel_bootstrap/fuel_bootstrap_cli/fuel_bootstrap/utils/bootstrap_image.py
42 @@ -172,7 +172,8 @@ def make_bootstrap(data):
43  
44      LOG.info("Try to build image with data:\n%s", yaml.safe_dump(bootdata))
45  
46 -    opts = ['--data_driver', 'bootstrap_build_image']
47 +    opts = ['--data_driver', 'bootstrap_build_image',
48 +            '--target_arch', data['target_arch']]
49      if data.get('image_build_dir'):
50          opts.extend(['--image_build_dir', data['image_build_dir']])
51  
52 diff --git a/debian/control b/debian/control
53 index 0a6f947..189dc00 100644
54 --- a/debian/control
55 +++ b/debian/control
56 @@ -36,6 +36,8 @@ Pre-Depends: dpkg (>= 1.15.6~)
57  Depends: bzip2,
58           cloud-utils,
59          debootstrap,
60 +        qemu-user-static,
61 +        binfmt-support,
62          dmidecode,
63          ethtool,
64          gdisk,
65 diff --git a/fuel_agent/manager.py b/fuel_agent/manager.py
66 index 15cc5d8..f613aef 100644
67 --- a/fuel_agent/manager.py
68 +++ b/fuel_agent/manager.py
69 @@ -18,6 +18,7 @@ import shutil
70  import signal
71  
72  from oslo_config import cfg
73 +from oslo_config import types
74  import six
75  import yaml
76  
77 @@ -33,6 +34,8 @@ from fuel_agent.utils import md as mu
78  from fuel_agent.utils import partition as pu
79  from fuel_agent.utils import utils
80  
81 +ArchType = types.String(choices=['amd64', 'arm64'])
82 +
83  opts = [
84      cfg.StrOpt(
85          'nc_template_path',
86 @@ -153,6 +156,13 @@ cli_opts = [
87          default='/tmp',
88          help='Directory where the image is supposed to be built',
89      ),
90 +    cfg.Opt(
91 +        'target_arch',
92 +        default='amd64',
93 +        type=ArchType,
94 +        help='Architecture for which image will be built using '
95 +             'debootstrap',
96 +    ),
97  ]
98  
99  CONF = cfg.CONF
100 @@ -551,7 +561,8 @@ class Manager(object):
101          LOG.debug('Preventing services from being get started')
102          bu.suppress_services_start(chroot)
103          LOG.debug('Installing base operating system using debootstrap')
104 -        bu.run_debootstrap(uri=uri, suite=suite, chroot=chroot,
105 +        bu.run_debootstrap(uri=uri, suite=suite, arch=CONF.target_arch,
106 +                           chroot=chroot,
107                             attempts=CONF.fetch_packages_attempts,
108                             proxies=proxies.proxies,
109                             direct_repo_addr=proxies.direct_repo_addr_list)
110 diff --git a/fuel_agent/tests/test_build_utils.py b/fuel_agent/tests/test_build_utils.py
111 index 82c3462..ac5ae82 100644
112 --- a/fuel_agent/tests/test_build_utils.py
113 +++ b/fuel_agent/tests/test_build_utils.py
114 @@ -42,7 +42,7 @@ class BuildUtilsTestCase(unittest2.TestCase):
115      def test_run_debootstrap(self, mock_exec, mock_environ):
116          bu.run_debootstrap('uri', 'suite', 'chroot', 'arch', attempts=2)
117          mock_exec.assert_called_once_with(
118 -            'debootstrap', '--include={0}'
119 +            'qemu-debootstrap', '--include={0}'
120              .format(','.join(bu.ADDITIONAL_DEBOOTSTRAP_PACKAGES)),
121              '--verbose', '--no-check-gpg', '--arch=arch',
122              'suite', 'chroot', 'uri', attempts=2, env_variables={})
123 @@ -53,7 +53,7 @@ class BuildUtilsTestCase(unittest2.TestCase):
124          bu.run_debootstrap('uri', 'suite', 'chroot', 'arch', eatmydata=True,
125                             attempts=2)
126          mock_exec.assert_called_once_with(
127 -            'debootstrap', '--include={0}'
128 +            'qemu-debootstrap', '--include={0}'
129              .format(','.join(bu.ADDITIONAL_DEBOOTSTRAP_PACKAGES)),
130              '--verbose', '--no-check-gpg', '--arch=arch',
131              '--include=eatmydata', 'suite',
132 diff --git a/fuel_agent/utils/build.py b/fuel_agent/utils/build.py
133 index 7247965..af41b2b 100644
134 --- a/fuel_agent/utils/build.py
135 +++ b/fuel_agent/utils/build.py
136 @@ -80,7 +80,7 @@ def run_debootstrap(uri, suite, chroot, arch='amd64', eatmydata=False,
137          env_vars['no_proxy'] = ','.join(direct_repo_addr)
138          LOG.debug('Setting no_proxy for: {0}'.format(env_vars['no_proxy']))
139  
140 -    cmds = ['debootstrap',
141 +    cmds = ['qemu-debootstrap',
142              '--include={0}'.format(",".join(ADDITIONAL_DEBOOTSTRAP_PACKAGES)),
143              '--verbose', '--no-check-gpg',
144              '--arch={0}'.format(arch)]
145 diff --git a/specs/fuel-agent.spec b/specs/fuel-agent.spec
146 index 5c37600..a43f693 100644
147 --- a/specs/fuel-agent.spec
148 +++ b/specs/fuel-agent.spec
149 @@ -50,6 +50,8 @@ Requires:    xfsprogs
150  Requires:    pciutils
151  Requires:    ethtool
152  Requires:    debootstrap
153 +Requires:    dpkg
154 +Requires:    qemu-user-static
155  Requires:    xz
156  Requires:    coreutils
157  Requires:    psmisc