6e6c18fbad9ca2a356758af3e5f5f1339ea90bd6
[fuel.git] / mcp / patches / 0003-maas-region-force-artifact-download.patch
1 ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
2 : Copyright (c) 2017 Mirantis Inc., Enea AB and others.
3 :
4 : All rights reserved. This program and the accompanying materials
5 : are made available under the terms of the Apache License, Version 2.0
6 : which accompanies this distribution, and is available at
7 : http://www.apache.org/licenses/LICENSE-2.0
8 ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
9 From: Alexandru Avadanii <Alexandru.Avadanii@enea.com>
10 Date: Sat, 5 Aug 2017 02:03:01 +0200
11 Subject: [PATCH] maas: region: force artifact download
12
13 MaaS configuration fails until all required artifacts are in place,
14 including bootloaders and target images.
15
16 Hack around this by forcing an explicit artifact sync.
17
18 NOTE: This is probably achievable through existing maas salt custom
19 module (py) and/or minor rework on that.
20 This fixup should be temporary at best.
21
22 Signed-off-by: Alexandru Avadanii <Alexandru.Avadanii@enea.com>
23 ---
24
25 diff --git a/maas/region.sls b/maas/region.sls
26 --- a/maas/region.sls
27 +++ b/maas/region.sls
28 @@ -109,11 +109,19 @@
29    cmd.run:
30    - name: "maas-region apikey --username {{ region.admin.username }} > /var/lib/maas/.maas_credentials"
31
32 +maas_force_artifact_sync:
33 +  cmd.script:
34 +  - name: salt://maas/files/maas-artifact-sync.sh
35 +  - template: jinja
36 +  - shell: /bin/bash
37 +  - require:
38 +    - cmd: maas_login_admin
39 +
40  maas_config:
41    module.run:
42    - name: maas.process_maas_config
43    - require:
44 -    - cmd: maas_login_admin
45 +    - cmd: maas_force_artifact_sync
46
47  maas_commissioning_scripts:
48    module.run:
49 diff --git a/maas/files/maas-artifact-sync.sh b/maas/files/maas-artifact-sync.sh
50 new file mode 100644
51 --- /dev/null
52 +++ b/maas/files/maas-artifact-sync.sh
53 @@ -0,0 +1,20 @@
54 +{%- from "maas/map.jinja" import region with context %}
55 +#!/bin/bash
56 +function wait_for {
57 +  local total_attempts=$1; shift
58 +  local cmdstr=$@
59 +  local sleep_time=10
60 +  echo -e "\n[NOTE] Waiting for cmd to return success: ${cmdstr}\n"
61 +  for attempt in $(seq "${total_attempts}"); do
62 +    eval "${cmdstr}" && break || true
63 +    echo -n '.'; sleep "${sleep_time}"
64 +  done
65 +}
66 +maas login {{ region.admin.username }} \
67 +  http://{{ region.bind.host }}:5240/MAAS/api/2.0 - < \
68 +  /var/lib/maas/.maas_credentials || exit 1
69 +# wait max 5 min for service up, 15 min image download, 5 min region to rack sync
70 +wait_for 30 "maas opnfv boot-resources import"
71 +wait_for 90 "! maas opnfv boot-resources is-importing | grep -q 'true'"
72 +maas opnfv rack-controllers import-boot-images || exit 3
73 +wait_for 30 "test -d /var/lib/maas/boot-resources/current/ubuntu/amd64"