Initial code commit
[armband.git] / patches / fuel-library / 0004-Make-TestVM-creation-architecture-aware.patch
1 From: Stanislaw Kardach <stanislaw.kardach@caviumnetworks.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  .../puppet/osnailyfacter/modular/generate_vms/generate_vms.pp | 11 +++++++++++
10  deployment/puppet/osnailyfacter/templates/vm_libvirt.erb      |  5 ++++-
11  files/fuel-migrate/fuel-migrate                               |  5 ++++-
12  4 files changed, 25 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..57ae256 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/modular/generate_vms/generate_vms.pp b/deployment/puppet/osnailyfacter/modular/generate_vms/generate_vms.pp
47 index 6d5426a..da5954e 100644
48 --- a/deployment/puppet/osnailyfacter/modular/generate_vms/generate_vms.pp
49 +++ b/deployment/puppet/osnailyfacter/modular/generate_vms/generate_vms.pp
50 @@ -11,6 +11,17 @@ define vm_config {
51    $details = $name
52    $id = $details['id']
53  
54 +  case $::architecture {
55 +    'arm64', 'aarch64': {
56 +      $machine_arch = 'aarch64'
57 +      $machine_type = 'virt'
58 +    }
59 +    default: {
60 +      $machine_arch = 'x86_64'
61 +      $machine_type = 'pc-i440fx-trusty'
62 +    }
63 +  }
64 +
65    file { "${template_dir}/template_${id}_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..decf3ab 100644
70 --- a/deployment/puppet/osnailyfacter/templates/vm_libvirt.erb
71 +++ b/deployment/puppet/osnailyfacter/templates/vm_libvirt.erb
72 @@ -3,7 +3,7 @@
73    <memory unit='GiB'><%= @details['mem'] %></memory>
74    <vcpu placement='static'><%= @details['cpu'] %></vcpu>
75    <os>
76 -    <type arch='x86_64' machine='pc-i440fx-trusty'>hvm</type>
77 +    <type arch='<%= @machine_arch %>' machine='<%= @machine_type %>'>hvm</type>
78      <boot dev='network'/>
79      <boot dev='hd'/>
80    </os>
81 @@ -11,6 +11,9 @@
82      <acpi/>
83      <apic/>
84      <pae/>
85 +  <% if $machine_arch == 'arm64' { %>
86 +    <gic version='3' />
87 +  <% } %>
88    </features>
89    <clock offset='utc'/>
90    <on_poweroff>destroy</on_poweroff>
91 diff --git a/files/fuel-migrate/fuel-migrate b/files/fuel-migrate/fuel-migrate
92 index fad9436..667d4a7 100755
93 --- a/files/fuel-migrate/fuel-migrate
94 +++ b/files/fuel-migrate/fuel-migrate
95 @@ -175,6 +175,8 @@ create_vm(){
96              exit 1
97          fi
98      fi
99 +    # figure out atchitecture of the destination
100 +    arch="$(virsh -c "${dkvm_uri}" nodeinfo | awk '/CPU model:/ { print $3}')"
101      # create disk
102      ssh "${dkvm_ip}" qemu-img create -f raw "${dkvm_folder}/${fvm_name}.img" "${fvm_disk_size}"
103      # make template for virsh
104 @@ -184,13 +186,14 @@ create_vm(){
105    <memory unit='MiB'>${fvm_ram}</memory>
106    <vcpu >${fvm_cpu}</vcpu>
107    <os>
108 -    <type arch='x86_64' >hvm</type>
109 +    <type arch='${arch}' >hvm</type>
110      <boot dev='hd'/>
111      <boot dev='network'/>
112   </os>
113    <features>
114      <acpi/>
115      <apic/>
116 +    ${arch/aarch64/<gic version='3'\/>}
117    </features>
118    <clock offset='utc'/>
119    <on_poweroff>destroy</on_poweroff>
120 -- 
121 1.9.1
122