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