Uplift Armband to Fuel Newton
[armband.git] / patches / fuel-web / 0002-Add-arch-to-nailgun-release-and-target-image.patch
1 From: Stanislaw Kardach <stanislaw.kardach@cavium.com>
2 Date: Sun, 18 Dec 2016 21:28:21 +0100
3 Subject: [PATCH] Add arch to nailgun release and target image
4
5 This is required so that the TestVM image is created using a cirros
6 image that is compatible with the architecture of the deployment setup.
7 As a bonus, it is also used when building the target image.
8
9 [ Alexandru Avadanii ]
10 Rebased onto Newton.
11
12 Signed-off-by: Alexandru Avadanii <Alexandru.Avadanii@enea.com>
13 Signed-off-by: Stanislaw Kardach <stanislaw.kardach@cavium.com>
14 ---
15  nailgun/nailgun/consts.py                          |  5 ++
16  .../alembic_migrations/versions/armband.py         | 53 ++++++++++++++++++++++
17  nailgun/nailgun/db/sqlalchemy/models/release.py    |  8 ++++
18  nailgun/nailgun/fixtures/openstack.yaml            |  5 ++
19  .../nailgun/orchestrator/deployment_serializers.py |  8 +++-
20  .../orchestrator/provisioning_serializers.py       |  3 +-
21  nailgun/nailgun/orchestrator/tasks_templates.py    |  5 +-
22  .../integration/test_cluster_changes_handler.py    | 12 ++---
23  .../integration/test_orchestrator_serializer.py    |  4 +-
24  nailgun/nailgun/test/unit/test_tasks_templates.py  |  6 ++-
25  10 files changed, 95 insertions(+), 14 deletions(-)
26  create mode 100644 nailgun/nailgun/db/migration/alembic_migrations/versions/armband.py
27
28 diff --git a/nailgun/nailgun/consts.py b/nailgun/nailgun/consts.py
29 index ccbe860..a3875ce 100644
30 --- a/nailgun/nailgun/consts.py
31 +++ b/nailgun/nailgun/consts.py
32 @@ -38,6 +38,11 @@ RELEASE_OS = Enum(
33      )
34  )
35
36 +RELEASE_ARCHS = Enum(
37 +    'amd64',
38 +    'arm64'
39 +)
40 +
41  CLUSTER_MODES = Enum(
42      'multinode',
43      'ha_full',
44 diff --git a/nailgun/nailgun/db/migration/alembic_migrations/versions/armband.py b/nailgun/nailgun/db/migration/alembic_migrations/versions/armband.py
45 new file mode 100644
46 index 0000000..6e42b3f
47 --- /dev/null
48 +++ b/nailgun/nailgun/db/migration/alembic_migrations/versions/armband.py
49 @@ -0,0 +1,53 @@
50 +#    Copyright 2016 Cavium, Inc.
51 +#
52 +#    Licensed under the Apache License, Version 2.0 (the "License"); you may
53 +#    not use this file except in compliance with the License. You may obtain
54 +#    a copy of the License at
55 +#
56 +#         http://www.apache.org/licenses/LICENSE-2.0
57 +#
58 +#    Unless required by applicable law or agreed to in writing, software
59 +#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
60 +#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
61 +#    License for the specific language governing permissions and limitations
62 +#    under the License.
63 +
64 +"""Armband patches
65 +
66 +Revision ID: f9b7fd91ac19
67 +Revises: c6edea552f1e
68 +Create Date: 2016-03-01 23:18:58.712617
69 +
70 +"""
71 +
72 +# revision identifiers, used by Alembic.
73 +revision = 'f9b7fd91ac19'
74 +down_revision = 'c6edea552f1e'
75 +
76 +from alembic import op
77 +from nailgun.utils.migration import drop_enum
78 +import sqlalchemy as sa
79 +
80 +ENUMS = (
81 +    'release_arch',
82 +)
83 +
84 +
85 +def upgrade():
86 +    add_release_arch()
87 +
88 +
89 +def downgrade():
90 +    remove_release_arch()
91 +    map(drop_enum, ENUMS)
92 +
93 +
94 +def add_release_arch():
95 +    arch_enum = sa.Enum('amd64', 'arm64', name='release_arch')
96 +    arch_enum.create(op.get_bind(), checkfirst=False)
97 +    op.add_column('releases', sa.Column('arch', arch_enum, nullable=False,
98 +                  server_default='amd64'))
99 +
100 +
101 +def remove_release_arch():
102 +    op.drop_column('releases', 'arch')
103 diff --git a/nailgun/nailgun/db/sqlalchemy/models/release.py b/nailgun/nailgun/db/sqlalchemy/models/release.py
104 index a069b61..882d32c 100644
105 --- a/nailgun/nailgun/db/sqlalchemy/models/release.py
106 +++ b/nailgun/nailgun/db/sqlalchemy/models/release.py
107 @@ -40,6 +40,14 @@ class Release(Base):
108      id = Column(Integer, primary_key=True)
109      name = Column(Unicode(100), nullable=False)
110      version = Column(String(30), nullable=False)
111 +    arch = Column(
112 +        Enum(
113 +            *consts.RELEASE_ARCHS,
114 +            name='release_arch'
115 +        ),
116 +        nullable=False,
117 +        default=consts.RELEASE_ARCHS.amd64
118 +    )
119      description = Column(Unicode)
120      operating_system = Column(String(50), nullable=False)
121      state = Column(
122 diff --git a/nailgun/nailgun/fixtures/openstack.yaml b/nailgun/nailgun/fixtures/openstack.yaml
123 index ba967d7..c1d2a71 100644
124 --- a/nailgun/nailgun/fixtures/openstack.yaml
125 +++ b/nailgun/nailgun/fixtures/openstack.yaml
126 @@ -2113,6 +2113,7 @@
127      name: "Newton on CentOS 6.5"
128      state: "unavailable"
129      version: "newton-10.0"
130 +    arch: "amd64"
131      operating_system: "CentOS"
132      description: "This option will install the OpenStack Mitaka packages using a CentOS based operating system. With high availability features built in, you are getting a robust, enterprise-grade OpenStack deployment."
133      attributes_metadata:
134 @@ -2186,6 +2187,7 @@
135    fields:
136      name: "Newton on Ubuntu 16.04"
137      version: "newton-10.0"
138 +    arch: "amd64"
139      operating_system: "Ubuntu"
140      description: "This option will install the OpenStack Newton packages using Ubuntu as a base operating system. With high availability features built in, you are getting a robust, enterprise-grade OpenStack deployment."
141      attributes_metadata:
142 @@ -2417,6 +2419,7 @@
143    fields:
144      name: "Newton on Ubuntu+UCA 16.04"
145      version: "newton-10.0"
146 +    arch: "amd64"
147      description: "This option will install the OpenStack Newton packages using Ubuntu as a base operating system, including Ubuntu Cloud Archive OpenStack packages. With high availability features built in, you are getting a robust, enterprise-grade OpenStack deployment."
148      attributes_metadata:
149        editable:
150 @@ -2517,6 +2520,7 @@
151    fields:
152      name: "Newton on Ubuntu 16.04 (aarch64)"
153      version: "newton-10.0"
154 +    arch: "arm64"
155      operating_system: "Ubuntu"
156      description: "This option will install the OpenStack Newton packages using Ubuntu as a base operating system. With high availability features built in, you are getting a robust, enterprise-grade OpenStack deployment."
157      attributes_metadata:
158 @@ -2754,6 +2758,7 @@
159    fields:
160      name: "Newton on Ubuntu+UCA 16.04 (aarch64)"
161      version: "newton-10.0"
162 +    arch: "arm64"
163      description: "This option will install the OpenStack Newton packages using Ubuntu as a base operating system, including Ubuntu Cloud Archive OpenStack packages. With high availability features built in, you are getting a robust, enterprise-grade OpenStack deployment."
164      attributes_metadata:
165        editable:
166 diff --git a/nailgun/nailgun/orchestrator/deployment_serializers.py b/nailgun/nailgun/orchestrator/deployment_serializers.py
167 index f983ae3..2f9cec2 100644
168 --- a/nailgun/nailgun/orchestrator/deployment_serializers.py
169 +++ b/nailgun/nailgun/orchestrator/deployment_serializers.py
170 @@ -261,7 +261,13 @@ class DeploymentMultinodeSerializer(object):
171              img_dir = '/usr/share/cirros-testvm/'
172          else:
173              img_dir = '/opt/vm/'
174 -        image_data['img_path'] = '{0}cirros-x86_64-disk.img'.format(img_dir)
175 +        arch = node.cluster.release.arch
176 +        if arch == "amd64":
177 +            arch = "x86_64"
178 +        elif arch == "arm64":
179 +            arch = "aarch64"
180 +        image_data['img_path'] = '{0}cirros-{1}-disk.img'.format(img_dir,
181 +            arch)
182
183          properties_data = {}
184
185 diff --git a/nailgun/nailgun/orchestrator/provisioning_serializers.py b/nailgun/nailgun/orchestrator/provisioning_serializers.py
186 index 7b2c6ac..f2c05e1 100644
187 --- a/nailgun/nailgun/orchestrator/provisioning_serializers.py
188 +++ b/nailgun/nailgun/orchestrator/provisioning_serializers.py
189 @@ -329,7 +329,8 @@ class ProvisioningSerializer61(ProvisioningSerializer):
190                      attrs['repo_setup']['repos'],
191                      attrs['provision'],
192                      cluster.id,
193 -                    packages))
194 +                    packages,
195 +                    cluster.release.arch))
196
197          PriorityStrategy().one_by_one(tasks)
198          return tasks
199 diff --git a/nailgun/nailgun/orchestrator/tasks_templates.py b/nailgun/nailgun/orchestrator/tasks_templates.py
200 index 8252891..84bebe6 100644
201 --- a/nailgun/nailgun/orchestrator/tasks_templates.py
202 +++ b/nailgun/nailgun/orchestrator/tasks_templates.py
203 @@ -208,7 +208,7 @@ def make_reboot_task(uids, task):
204
205
206  def make_provisioning_images_task(
207 -        uids, repos, provision_data, cid, packages):
208 +        uids, repos, provision_data, cid, packages, arch):
209      conf = {
210          'repos': repos,
211          'image_data': provision_data['image_data'],
212 @@ -230,7 +230,8 @@ def make_provisioning_images_task(
213                      "--image_build_dir /var/lib/fuel/ibp "
214                      "--log-file /var/log/fuel-agent-env-{0}.log "
215                      "--data_driver nailgun_build_image "
216 -                    "--input_data '{1}'").format(cid, conf),
217 +                    "--target_arch {1} "
218 +                    "--input_data '{2}'").format(cid, arch, conf),
219              'timeout': settings.PROVISIONING_IMAGES_BUILD_TIMEOUT,
220              'retries': 1}})
221
222 diff --git a/nailgun/nailgun/test/integration/test_cluster_changes_handler.py b/nailgun/nailgun/test/integration/test_cluster_changes_handler.py
223 index d7e964e..bce8289 100644
224 --- a/nailgun/nailgun/test/integration/test_cluster_changes_handler.py
225 +++ b/nailgun/nailgun/test/integration/test_cluster_changes_handler.py
226 @@ -148,7 +148,7 @@ class TestHandlers(BaseIntegrationTest):
227          common_attrs['last_controller'] = controller_nodes[-1]['name']
228          common_attrs['storage']['pg_num'] = 128
229
230 -        common_attrs['test_vm_image'] = {
231 +        common_attrs['test_vm_image'] = [{
232              'container_format': 'bare',
233              'public': 'true',
234              'disk_format': 'qcow2',
235 @@ -164,7 +164,7 @@ class TestHandlers(BaseIntegrationTest):
236                  'murano_image_info': """'{"title": "Murano Demo", "type":"""
237                  """ "cirros.demo"}'""",
238              },
239 -        }
240 +        }]
241
242          critical_mapping = {
243              'primary-controller': True,
244 @@ -565,7 +565,7 @@ class TestHandlers(BaseIntegrationTest):
245          common_attrs['last_controller'] = controller_nodes[-1]['name']
246          common_attrs['storage']['pg_num'] = 128
247
248 -        common_attrs['test_vm_image'] = {
249 +        common_attrs['test_vm_image'] = [{
250              'container_format': 'bare',
251              'public': 'true',
252              'disk_format': 'qcow2',
253 @@ -581,7 +581,7 @@ class TestHandlers(BaseIntegrationTest):
254                  'murano_image_info': """'{"title": "Murano Demo", "type":"""
255                  """ "cirros.demo"}'""",
256              },
257 -        }
258 +        }]
259
260          critical_mapping = {
261              'primary-controller': True,
262 @@ -1053,7 +1053,7 @@ class TestHandlers(BaseIntegrationTest):
263          common_attrs['last_controller'] = controller_nodes[-1]['name']
264          common_attrs['storage']['pg_num'] = 128
265
266 -        common_attrs['test_vm_image'] = {
267 +        common_attrs['test_vm_image'] = [{
268              'container_format': 'bare',
269              'public': 'true',
270              'disk_format': 'qcow2',
271 @@ -1069,7 +1069,7 @@ class TestHandlers(BaseIntegrationTest):
272                  'murano_image_info': """'{"title": "Murano Demo", "type":"""
273                  """ "cirros.demo"}'""",
274              },
275 -        }
276 +        }]
277
278          critical_mapping = {
279              'primary-controller': True,
280 diff --git a/nailgun/nailgun/test/integration/test_orchestrator_serializer.py b/nailgun/nailgun/test/integration/test_orchestrator_serializer.py
281 index f399602..6034f30 100644
282 --- a/nailgun/nailgun/test/integration/test_orchestrator_serializer.py
283 +++ b/nailgun/nailgun/test/integration/test_orchestrator_serializer.py
284 @@ -2565,12 +2565,12 @@ class BaseDeploymentSerializer(BaseSerializerTest):
285
286      def check_no_murano_data(self):
287          glance_properties = self.serializer.generate_test_vm_image_data(
288 -            self.env.nodes[0])['test_vm_image']['glance_properties']
289 +            self.env.nodes[0])['test_vm_image'][0]['glance_properties']
290          self.assertNotIn('murano_image_info', glance_properties)
291
292      def check_murano_data(self):
293          glance_properties = self.serializer.generate_test_vm_image_data(
294 -            self.env.nodes[0])['test_vm_image']['glance_properties']
295 +            self.env.nodes[0])['test_vm_image'][0]['glance_properties']
296          self.assertIn('murano_image_info', glance_properties)
297
298      @staticmethod
299 diff --git a/nailgun/nailgun/test/unit/test_tasks_templates.py b/nailgun/nailgun/test/unit/test_tasks_templates.py
300 index 4db183f..4f5d2cb 100644
301 --- a/nailgun/nailgun/test/unit/test_tasks_templates.py
302 +++ b/nailgun/nailgun/test/unit/test_tasks_templates.py
303 @@ -140,7 +140,8 @@ class TestMakeTask(base.BaseTestCase):
304                      }
305                  }},
306              cid=123,
307 -            packages=packages
308 +            packages=packages,
309 +            arch='amd64'
310          )
311
312          fuel_image_conf = {
313 @@ -177,7 +178,8 @@ class TestMakeTask(base.BaseTestCase):
314          cmd = result["parameters"]["cmd"].lstrip(
315              "fa_build_image --image_build_dir /var/lib/fuel/ibp "
316              "--log-file /var/log/fuel-agent-env-123.log "
317 -            "--data_driver nailgun_build_image --input_data '").rstrip("'")
318 +            "--data_driver nailgun_build_image --target_arch amd64"
319 +            " --input_data '").rstrip("'")
320          self.assertEqual(jsonutils.loads(cmd), fuel_image_conf)
321
322      def test_generate_ironic_bootstrap_keys_task(self):