Rebase: upstream DEA mechanism changes
[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,4 +166,12 @@ class BuildCommand(command.Command):
24          )
25 +        parser.add_argument(
26 +            '--target_arch',
27 +            type=str,
28 +            choices=['arm64', 'amd64'],
29 +            help="Choose the target architecture for which image is built",
30 +            default="amd64"
31 +        )
32 +
33          return parser
34  
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):
41  
42      LOG.info("Try to build image with data:\n%s", yaml.safe_dump(bootdata))
43  
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']])
49  
50 diff --git a/debian/control b/debian/control
51 index 0a6f947..189dc00 100644
52 --- a/debian/control
53 +++ b/debian/control
54 @@ -36,6 +36,8 @@ Pre-Depends: dpkg (>= 1.15.6~)
55  Depends: bzip2,
56           cloud-utils,
57          debootstrap,
58 +        qemu-user-static,
59 +        binfmt-support,
60          dmidecode,
61          ethtool,
62          gdisk,
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
68  
69  from oslo_config import cfg
70 +from oslo_config import types
71  import six
72  import yaml
73  
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
77  
78 +ArchType = types.String(choices=['amd64', 'arm64'])
79 +
80  opts = [
81      cfg.StrOpt(
82          'nc_template_path',
83 @@ -153,6 +156,13 @@ cli_opts = [
84          default='/tmp',
85          help='Directory where the image is supposed to be built',
86      ),
87 +    cfg.Opt(
88 +        'target_arch',
89 +        default='amd64',
90 +        type=ArchType,
91 +        help='Architecture for which image will be built using '
92 +             'debootstrap',
93 +    ),
94  ]
95  
96  CONF = cfg.CONF
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,
103 +                           chroot=chroot,
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,
122                             attempts=2)
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']))
136  
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
147  Requires:    pciutils
148  Requires:    ethtool
149  Requires:    debootstrap
150 +Requires:    dpkg
151 +Requires:    qemu-user-static
152  Requires:    xz
153  Requires:    coreutils
154  Requires:    psmisc