Rebase for "Improve reliability of upload_cirros"
[armband.git] / patches / fuel-library / 0004-Make-TestVM-creation-architecture-aware.patch
1 From ec3299c72eae195106092a646409564b5b3eb560 Mon Sep 17 00:00:00 2001
2 From: Stanislaw Kardach <stanislaw.kardach@caviumnetworks.com>
3 Date: Wed, 24 Feb 2016 20:08:24 +0100
4 Subject: [PATCH 10/20] Make TestVM creation architecture aware
5
6 This depends on cirros-testvm package to contain both amd64 and arm64
7 images.
8 ---
9  deployment/puppet/openstack/manifests/img/cirros.pp       |  8 ++++++--
10  .../osnailyfacter/manifests/generate_vms/vm_config.pp     | 11 +++++++++++
11  deployment/puppet/osnailyfacter/templates/vm_libvirt.erb  | 15 ++++++++++++++-
12  files/fuel-migrate/fuel-migrate                           |  5 ++++-
13  4 files changed, 35 insertions(+), 4 deletions(-)
14
15 diff --git a/deployment/puppet/openstack/manifests/img/cirros.pp b/deployment/puppet/openstack/manifests/img/cirros.pp
16 index 84e202e..cff06e0 100644
17 --- a/deployment/puppet/openstack/manifests/img/cirros.pp
18 +++ b/deployment/puppet/openstack/manifests/img/cirros.pp
19 @@ -9,6 +9,10 @@ class openstack::img::cirros (
20    $img_name = 'cirros',
21    $os_name = 'cirros',
22  ) {
23 +  $arch = $::architecture ? {
24 +      /(arm64|aarch64)/ => 'aarch64',
25 +      default           => 'x86_64',
26 +  }
27  
28    package { 'cirros-testvm':
29      ensure => "present"
30 @@ -17,14 +21,14 @@ class openstack::img::cirros (
31  case $::osfamily {
32    'RedHat': {
33    exec { 'upload-img':
34 -    command => "/usr/bin/glance -N ${os_auth_url} -T ${os_tenant_name} -I ${os_username} -K ${os_password} add name=${img_name} is_public=${public} container_format=${container_format} disk_format=${disk_format} distro=${os_name} < /opt/vm/cirros-x86_64-disk.img",
35 +    command => "/usr/bin/glance -N ${os_auth_url} -T ${os_tenant_name} -I ${os_username} -K ${os_password} add name=${img_name} is_public=${public} container_format=${container_format} disk_format=${disk_format} distro=${os_name} < /opt/vm/cirros-${arch}-disk.img",
36      unless => "/usr/bin/glance -N ${os_auth_url} -T ${os_tenant_name} -I ${os_username} -K ${os_password} index && (/usr/bin/glance -N ${os_auth_url} -T ${os_tenant_name} -I ${os_username} -K ${os_password} index | grep ${img_name})",
37  
38      }
39    }
40    'Debian': {
41    exec { 'upload-img':
42 -    command => "/usr/bin/glance -N ${os_auth_url} -T ${os_tenant_name} -I ${os_username} -K ${os_password} add name=${img_name} is_public=${public} container_format=${container_format} disk_format=${disk_format} distro=${os_name} < /usr/share/cirros-testvm/cirros-x86_64-disk.img",
43 +    command => "/usr/bin/glance -N ${os_auth_url} -T ${os_tenant_name} -I ${os_username} -K ${os_password} add name=${img_name} is_public=${public} container_format=${container_format} disk_format=${disk_format} distro=${os_name} < /usr/share/cirros-testvm/cirros-${arch}-disk.img",
44      unless => "/usr/bin/glance -N ${os_auth_url} -T ${os_tenant_name} -I ${os_username} -K ${os_password} index && (/usr/bin/glance -N ${os_auth_url} -T ${os_tenant_name} -I ${os_username} -K ${os_password} index | grep ${img_name})",
45  
46      }
47 diff --git a/deployment/puppet/osnailyfacter/manifests/generate_vms/vm_config.pp b/deployment/puppet/osnailyfacter/manifests/generate_vms/vm_config.pp
48 index 70fef32..dfefcbe 100644
49 --- a/deployment/puppet/osnailyfacter/manifests/generate_vms/vm_config.pp
50 +++ b/deployment/puppet/osnailyfacter/manifests/generate_vms/vm_config.pp
51 @@ -4,6 +4,17 @@ define osnailyfacter::generate_vms::vm_config(
52    $details = $name
53    $id = $details['id']
54  
55 +  case $::architecture {
56 +    'arm64', 'aarch64': {
57 +      $machine_arch = 'aarch64'
58 +      $machine_type = 'virt'
59 +    }
60 +    default: {
61 +      $machine_arch = 'x86_64'
62 +      $machine_type = 'pc-i440fx-trusty'
63 +    }
64 +  }
65 +
66    file { "${template_dir}/template_${id}_vm.xml":
67      owner   => 'root',
68      group   => 'root',
69 diff --git a/deployment/puppet/osnailyfacter/templates/vm_libvirt.erb b/deployment/puppet/osnailyfacter/templates/vm_libvirt.erb
70 index ae2ba5b..64e716d 100644
71 --- a/deployment/puppet/osnailyfacter/templates/vm_libvirt.erb
72 +++ b/deployment/puppet/osnailyfacter/templates/vm_libvirt.erb
73 @@ -3,14 +3,23 @@
74    <memory unit='GiB'><%= @details['mem'] %></memory>
75    <vcpu placement='static'><%= @details['cpu'] %></vcpu>
76    <os>
77 -    <type arch='x86_64' machine='pc-i440fx-trusty'>hvm</type>
78 +    <type arch='<%= @machine_arch %>' machine='<%= @machine_type %>'>hvm</type>
79 +  <% if  == 'aarch64' %>
80 +    <kernel>/var/lib/nova/<%= @details['id'] %>_vm.kernel</kernel>
81 +    <initrd>/var/lib/nova/<%= @details['id'] %>_vm.initramfs</initrd>
82 +    <cmdline>root=/dev/vda1 rw rootwait console=tty0 console=ttyS0 console=ttyAMA0</cmdline>
83 +  <% else %>
84      <boot dev='network'/>
85      <boot dev='hd'/>
86 +  <% end %>
87    </os>
88    <features>
89      <acpi/>
90      <apic/>
91      <pae/>
92 +  <% if $machine_arch == 'aarch64' %>
93 +    <gic version='host' />
94 +  <% end %>
95    </features>
96    <clock offset='utc'/>
97    <on_poweroff>destroy</on_poweroff>
98 @@ -57,7 +66,11 @@
99      <input type='keyboard' bus='ps2'/>
100      <graphics type='vnc' port='-1' autoport='yes'/>
101      <video>
102 +<% if $machine_arch == 'aarch64' %>
103 +      <model type='vga' vram='9216' heads='1'/>
104 +<% else %>
105        <model type='cirrus' vram='9216' heads='1'/>
106 +<% end %>
107      </video>
108      <memballoon model='virtio'>
109      </memballoon>
110 diff --git a/files/fuel-migrate/fuel-migrate b/files/fuel-migrate/fuel-migrate
111 index a215e0a..7d5b6cd 100755
112 --- a/files/fuel-migrate/fuel-migrate
113 +++ b/files/fuel-migrate/fuel-migrate
114 @@ -176,6 +176,8 @@ create_vm(){
115              exit 1
116          fi
117      fi
118 +    # figure out atchitecture of the destination
119 +    arch="$(virsh -c "${dkvm_uri}" nodeinfo | awk '/CPU model:/ { print $3}')"
120      # create disk
121      ssh "${dkvm_ip}" qemu-img create -f raw "${dkvm_folder}/${fvm_name}.img" "${fvm_disk_size}"
122      # make template for virsh
123 @@ -185,13 +187,14 @@ create_vm(){
124    <memory unit='MiB'>${fvm_ram}</memory>
125    <vcpu >${fvm_cpu}</vcpu>
126    <os>
127 -    <type arch='x86_64' >hvm</type>
128 +    <type arch='${arch}' >hvm</type>
129      <boot dev='hd'/>
130      <boot dev='network'/>
131   </os>
132    <features>
133      <acpi/>
134      <apic/>
135 +    ${arch/aarch64/<gic version='3'\/>}
136    </features>
137    <clock offset='utc'/>
138    <on_poweroff>destroy</on_poweroff>