7af579614ba9e4a81f18167ff6a792a9f43fb203
[armband.git] / patches / fuel-web / 0002-Add-arch-to-nailgun-release-and-target-image.patch
1 From: Stanislaw Kardach <stanislaw.kardach@caviumnetworks.com>
2 Date: Wed, 24 Feb 2016 20:11:54 +0100
3 Subject: [PATCH] Add arch to nailgun release and target image
4
5 Thsi 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  nailgun/nailgun/consts.py                          |  5 ++
10  .../alembic_migrations/versions/armband.py         | 53 ++++++++++++++++++++++
11  nailgun/nailgun/db/sqlalchemy/models/release.py    |  8 ++++
12  nailgun/nailgun/fixtures/openstack.yaml            |  3 ++
13  .../nailgun/orchestrator/deployment_serializers.py |  9 +++-
14  .../orchestrator/provisioning_serializers.py       |  3 +-
15  nailgun/nailgun/orchestrator/tasks_templates.py    |  5 +-
16  .../integration/test_cluster_changes_handler.py    | 12 ++---
17  .../integration/test_orchestrator_serializer.py    |  4 +-
18  nailgun/nailgun/test/unit/test_tasks_templates.py  |  6 ++-
19  10 files changed, 94 insertions(+), 14 deletions(-)
20  create mode 100644 nailgun/nailgun/db/migration/alembic_migrations/versions/armband.py
21
22 diff --git a/nailgun/nailgun/consts.py b/nailgun/nailgun/consts.py
23 index bb69168..2c19ec9 100644
24 --- a/nailgun/nailgun/consts.py
25 +++ b/nailgun/nailgun/consts.py
26 @@ -38,6 +38,11 @@ RELEASE_OS = Enum(
27      )
28  )
29  
30 +RELEASE_ARCHS = Enum(
31 +    'amd64',
32 +    'arm64'
33 +)
34 +
35  CLUSTER_MODES = Enum(
36      'multinode',
37      'ha_full',
38 diff --git a/nailgun/nailgun/db/migration/alembic_migrations/versions/armband.py b/nailgun/nailgun/db/migration/alembic_migrations/versions/armband.py
39 new file mode 100644
40 index 0000000..ad297b1
41 --- /dev/null
42 +++ b/nailgun/nailgun/db/migration/alembic_migrations/versions/armband.py
43 @@ -0,0 +1,53 @@
44 +#    Copyright 2016 Mirantis, Inc.
45 +#
46 +#    Licensed under the Apache License, Version 2.0 (the "License"); you may
47 +#    not use this file except in compliance with the License. You may obtain
48 +#    a copy of the License at
49 +#
50 +#         http://www.apache.org/licenses/LICENSE-2.0
51 +#
52 +#    Unless required by applicable law or agreed to in writing, software
53 +#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
54 +#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
55 +#    License for the specific language governing permissions and limitations
56 +#    under the License.
57 +
58 +"""Armband patches
59 +
60 +Revision ID: f9b7fd91ac19
61 +Revises: 43b2cb64dae6
62 +Create Date: 2016-03-01 23:18:58.712617
63 +
64 +"""
65 +
66 +# revision identifiers, used by Alembic.
67 +revision = 'f9b7fd91ac19'
68 +down_revision = '43b2cb64dae6'
69 +
70 +from alembic import op
71 +from nailgun.utils.migration import drop_enum
72 +import sqlalchemy as sa
73 +
74 +ENUMS = (
75 +    'release_arch',
76 +)
77 +
78 +
79 +def upgrade():
80 +    add_release_arch()
81 +
82 +
83 +def downgrade():
84 +    remove_release_arch()
85 +    map(drop_enum, ENUMS)
86 +
87 +
88 +def add_release_arch():
89 +    arch_enum = sa.Enum('amd64', 'arm64', name='release_arch')
90 +    arch_enum.create(op.get_bind(), checkfirst=False)
91 +    op.add_column('releases', sa.Column('arch', arch_enum, nullable=False,
92 +                  server_default='amd64'))
93 +
94 +
95 +def remove_release_arch():
96 +    op.drop_column('releases', 'arch')
97 diff --git a/nailgun/nailgun/db/sqlalchemy/models/release.py b/nailgun/nailgun/db/sqlalchemy/models/release.py
98 index 96cf2ed..62ac2c1 100644
99 --- a/nailgun/nailgun/db/sqlalchemy/models/release.py
100 +++ b/nailgun/nailgun/db/sqlalchemy/models/release.py
101 @@ -38,6 +38,14 @@ class Release(Base):
102      id = Column(Integer, primary_key=True)
103      name = Column(Unicode(100), nullable=False)
104      version = Column(String(30), nullable=False)
105 +    arch = Column(
106 +        Enum(
107 +            *consts.RELEASE_ARCHS,
108 +            name='release_arch'
109 +        ),
110 +        nullable=False,
111 +        default=consts.RELEASE_ARCHS.amd64
112 +    )
113      can_update_from_versions = Column(JSON, default=[],
114                                        nullable=False, server_default='[]')
115      description = Column(Unicode)
116 diff --git a/nailgun/nailgun/fixtures/openstack.yaml b/nailgun/nailgun/fixtures/openstack.yaml
117 index bf6f7c4..4979fb5 100644
118 --- a/nailgun/nailgun/fixtures/openstack.yaml
119 +++ b/nailgun/nailgun/fixtures/openstack.yaml
120 @@ -1913,6 +1913,7 @@
121      name: "Liberty on CentOS 6.5"
122      state: "unavailable"
123      version: "liberty-8.0"
124 +    arch: "amd64"
125      can_update_from_versions: []
126      operating_system: "CentOS"
127      description: "This option will install the OpenStack Liberty packages using a CentOS based operating system. With high availability features built in, you are getting a robust, enterprise-grade OpenStack deployment."
128 @@ -1986,6 +1987,7 @@
129    fields:
130      name: "Liberty on Ubuntu 14.04"
131      version: "liberty-8.0"
132 +    arch: "amd64"
133      can_update_from_versions: []
134      operating_system: "Ubuntu"
135      description: "This option will install the OpenStack Liberty packages using Ubuntu as a base operating system. With high availability features built in, you are getting a robust, enterprise-grade OpenStack deployment."
136 @@ -2084,6 +2086,7 @@
137    fields:
138      name: "Liberty on Ubuntu 14.04 (aarch64)"
139      version: "liberty-8.0"
140 +    arch: "arm64"
141      can_update_from_versions: []
142      operating_system: "Ubuntu"
143      description: "This option will install the OpenStack Liberty packages using Ubuntu as a base operating system. With high availability features built in, you are getting a robust, enterprise-grade OpenStack deployment."
144 diff --git a/nailgun/nailgun/orchestrator/deployment_serializers.py b/nailgun/nailgun/orchestrator/deployment_serializers.py
145 index 375a1ce..b8b38e2 100644
146 --- a/nailgun/nailgun/orchestrator/deployment_serializers.py
147 +++ b/nailgun/nailgun/orchestrator/deployment_serializers.py
148 @@ -291,7 +291,14 @@ class DeploymentMultinodeSerializer(object):
149              img_dir = '/usr/share/cirros-testvm/'
150          else:
151              img_dir = '/opt/vm/'
152 -        image_data['img_path'] = '{0}cirros-x86_64-disk.img'.format(img_dir)
153 +        release = self.current_release(node.cluster)
154 +        arch = release.arch
155 +        if arch == "amd64":
156 +            arch = "x86_64"
157 +        elif arch == "arm64":
158 +            arch = "aarch64"
159 +        image_data['img_path'] = '{0}cirros-{1}-disk.img'.format(img_dir,
160 +            arch)
161  
162          glance_properties = []
163  
164 diff --git a/nailgun/nailgun/orchestrator/provisioning_serializers.py b/nailgun/nailgun/orchestrator/provisioning_serializers.py
165 index 04ae0b0..c927f03 100644
166 --- a/nailgun/nailgun/orchestrator/provisioning_serializers.py
167 +++ b/nailgun/nailgun/orchestrator/provisioning_serializers.py
168 @@ -313,7 +313,8 @@ class ProvisioningSerializer61(ProvisioningSerializer):
169                      [consts.MASTER_NODE_UID],
170                      attrs['repo_setup']['repos'],
171                      attrs['provision'],
172 -                    cluster.id))
173 +                    cluster.id,
174 +                    cluster.release.arch))
175  
176          # NOTE(kozhukalov): This pre-provision task is going to be
177          # removed by 7.0 because we need this only for classic way of
178 diff --git a/nailgun/nailgun/orchestrator/tasks_templates.py b/nailgun/nailgun/orchestrator/tasks_templates.py
179 index 39f2067..cd2278c 100644
180 --- a/nailgun/nailgun/orchestrator/tasks_templates.py
181 +++ b/nailgun/nailgun/orchestrator/tasks_templates.py
182 @@ -207,7 +207,7 @@ def make_reboot_task(uids, task):
183              'timeout': task['parameters']['timeout']}}
184  
185  
186 -def make_provisioning_images_task(uids, repos, provision_data, cid):
187 +def make_provisioning_images_task(uids, repos, provision_data, cid, arch):
188      conf = {
189          'repos': repos,
190          'image_data': provision_data['image_data'],
191 @@ -224,7 +224,8 @@ def make_provisioning_images_task(uids, repos, provision_data, cid):
192                      "--image_build_dir /var/lib/fuel/ibp "
193                      "--log-file /var/log/fuel-agent-env-{0}.log "
194                      "--data_driver nailgun_build_image "
195 -                    "--input_data '{1}'").format(cid, conf),
196 +                    "--target_arch {1} "
197 +                    "--input_data '{2}'").format(cid, arch, conf),
198              'timeout': settings.PROVISIONING_IMAGES_BUILD_TIMEOUT,
199              'retries': 1}})
200  
201 diff --git a/nailgun/nailgun/test/integration/test_cluster_changes_handler.py b/nailgun/nailgun/test/integration/test_cluster_changes_handler.py
202 index 56bd307..34b4ce3 100644
203 --- a/nailgun/nailgun/test/integration/test_cluster_changes_handler.py
204 +++ b/nailgun/nailgun/test/integration/test_cluster_changes_handler.py
205 @@ -159,7 +159,7 @@ class TestHandlers(BaseIntegrationTest):
206          common_attrs['last_controller'] = controller_nodes[-1]['name']
207          common_attrs['storage']['pg_num'] = 128
208  
209 -        common_attrs['test_vm_image'] = {
210 +        common_attrs['test_vm_image'] = [{
211              'container_format': 'bare',
212              'public': 'true',
213              'disk_format': 'qcow2',
214 @@ -171,7 +171,7 @@ class TestHandlers(BaseIntegrationTest):
215                  """--property murano_image_info="""
216                  """'{"title": "Murano Demo", "type": "cirros.demo"}'"""
217              ),
218 -        }
219 +        }]
220  
221          critical_mapping = {
222              'primary-controller': True,
223 @@ -575,7 +575,7 @@ class TestHandlers(BaseIntegrationTest):
224          common_attrs['last_controller'] = controller_nodes[-1]['name']
225          common_attrs['storage']['pg_num'] = 128
226  
227 -        common_attrs['test_vm_image'] = {
228 +        common_attrs['test_vm_image'] = [{
229              'container_format': 'bare',
230              'public': 'true',
231              'disk_format': 'qcow2',
232 @@ -587,7 +587,7 @@ class TestHandlers(BaseIntegrationTest):
233                  """--property murano_image_info="""
234                  """'{"title": "Murano Demo", "type": "cirros.demo"}'"""
235              ),
236 -        }
237 +        }]
238  
239          critical_mapping = {
240              'primary-controller': True,
241 @@ -1062,7 +1062,7 @@ class TestHandlers(BaseIntegrationTest):
242          common_attrs['last_controller'] = controller_nodes[-1]['name']
243          common_attrs['storage']['pg_num'] = 128
244  
245 -        common_attrs['test_vm_image'] = {
246 +        common_attrs['test_vm_image'] = [{
247              'container_format': 'bare',
248              'public': 'true',
249              'disk_format': 'qcow2',
250 @@ -1074,7 +1074,7 @@ class TestHandlers(BaseIntegrationTest):
251                  """--property murano_image_info="""
252                  """'{"title": "Murano Demo", "type": "cirros.demo"}'"""
253              ),
254 -        }
255 +        }]
256  
257          critical_mapping = {
258              'primary-controller': True,
259 diff --git a/nailgun/nailgun/test/integration/test_orchestrator_serializer.py b/nailgun/nailgun/test/integration/test_orchestrator_serializer.py
260 index 8ce987a..e75b3c2 100644
261 --- a/nailgun/nailgun/test/integration/test_orchestrator_serializer.py
262 +++ b/nailgun/nailgun/test/integration/test_orchestrator_serializer.py
263 @@ -2656,12 +2656,12 @@ class BaseDeploymentSerializer(base.BaseIntegrationTest):
264  
265      def check_no_murano_data(self):
266          glance_properties = self.serializer.generate_test_vm_image_data(
267 -            self.env.nodes[0])['test_vm_image']['glance_properties']
268 +            self.env.nodes[0])['test_vm_image'][0]['glance_properties']
269          self.assertNotIn('murano_image_info', glance_properties)
270  
271      def check_murano_data(self):
272          glance_properties = self.serializer.generate_test_vm_image_data(
273 -            self.env.nodes[0])['test_vm_image']['glance_properties']
274 +            self.env.nodes[0])['test_vm_image'][0]['glance_properties']
275          self.assertIn('murano_image_info', glance_properties)
276  
277  
278 diff --git a/nailgun/nailgun/test/unit/test_tasks_templates.py b/nailgun/nailgun/test/unit/test_tasks_templates.py
279 index a38e975..9cb9171 100644
280 --- a/nailgun/nailgun/test/unit/test_tasks_templates.py
281 +++ b/nailgun/nailgun/test/unit/test_tasks_templates.py
282 @@ -133,7 +133,8 @@ class TestMakeTask(base.BaseTestCase):
283                          'uri': 'http://uri'
284                      }
285                  }},
286 -            cid=123)
287 +            cid=123,
288 +            arch='amd64')
289  
290          fuel_image_conf = {
291              "image_data": {
292 @@ -168,7 +169,8 @@ class TestMakeTask(base.BaseTestCase):
293          cmd = result["parameters"]["cmd"].lstrip(
294              "fa_build_image --image_build_dir /var/lib/fuel/ibp "
295              "--log-file /var/log/fuel-agent-env-123.log "
296 -            "--data_driver nailgun_build_image --input_data '").rstrip("'")
297 +            "--data_driver nailgun_build_image --target_arch amd64"
298 +            " --input_data '").rstrip("'")
299          self.assertEqual(jsonutils.loads(cmd), fuel_image_conf)
300  
301      def test_generate_ironic_bootstrap_keys_task(self):