Rebase after "Bugfix Broadcast Group".
[armband.git] / patches / fuel-library / 0006-direct-kernel-boot-for-cirros.patch
1 From: Stanislaw Kardach <stanislaw.kardach@caviumnetworks.com>
2 Date: Tue, 15 Mar 2016 15:01:34 +0100
3 Subject: [PATCH] direct kernel boot for cirros
4
5 ---
6  .../osnailyfacter/modular/astute/upload_cirros.rb  | 58 +++++++++++++++++++++-
7  .../puppet/osnailyfacter/templates/vm_libvirt.erb  |  8 ++-
8  2 files changed, 63 insertions(+), 3 deletions(-)
9
10 diff --git a/deployment/puppet/osnailyfacter/modular/astute/upload_cirros.rb b/deployment/puppet/osnailyfacter/modular/astute/upload_cirros.rb
11 index 04d597c..c342830 100755
12 --- a/deployment/puppet/osnailyfacter/modular/astute/upload_cirros.rb
13 +++ b/deployment/puppet/osnailyfacter/modular/astute/upload_cirros.rb
14 @@ -1,6 +1,7 @@
15  #!/usr/bin/env ruby
16  require 'hiera'
17  
18 +
19  ENV['LANG'] = 'C'
20  
21  hiera = Hiera.new(:config => '/etc/hiera.yaml')
22 @@ -56,11 +57,17 @@ def image_list
23      fields = line.split('|').map { |f| f.chomp.strip }
24      next if fields[1] == 'ID'
25      next unless fields[2]
26 -    images << fields[2]
27 +    images << [fields[1], fields[2]]
28    end
29    {:images => images, :exit_code => return_code}
30  end
31  
32 +def image_name_list
33 +  images = image_list
34 +  images[:images].map! { |i| i[1] }
35 +  images
36 +end
37 +
38  # TODO degorenko: remove --os-image-api-version after liberty (fuel-8.0) release
39  def image_create(image_hash)
40    command = <<-EOF
41 @@ -79,6 +86,15 @@ EOF
42    [ stdout, return_code ]
43  end
44  
45 +# Calls glance update-image with a given property and value
46 +def update_image(image_id, property, value)
47 +  command = "/usr/bin/glance image-update --#{property} #{value} #{image_id}"
48 +  puts command
49 +  stdout = `#{command}`
50 +  return_code = $?.exitstatus
51 +  [ stdout, return_code ]
52 +end
53 +
54  # check if Glance is online
55  # waited until the glance is started because when vCenter used as a glance
56  # backend launch may takes up to 1 minute.
57 @@ -93,7 +109,7 @@ end
58  # upload image to Glance
59  # if it have not been already uploaded
60  def upload_image(image)
61 -  list_of_images = image_list
62 +  list_of_images = image_name_list
63    if list_of_images[:images].include?(image['img_name']) && list_of_images[:exit_code] == 0
64      puts "Image '#{image['img_name']}' is already present!"
65      return 0
66 @@ -109,6 +125,43 @@ def upload_image(image)
67    return return_code
68  end
69  
70 +# For each disk image try to find a kernel and initramfs images and
71 +# attach then to it via kernel_id and ramdisk_id glance properties.
72 +def connect_dependant_images(images)
73 +  # for each image
74 +  # get image id from glance
75 +  img_list = image_list
76 +  return_code = img_list[:exit_code]
77 +  if return_code == 0
78 +    images.each do |image|
79 +      img_list[:images].each do |il|
80 +        if il[1] == image['img_name']
81 +          image['id'] = il[0]
82 +        end
83 +      end
84 +    end
85 +    # for each image that is not in [aki, ari]
86 +    images.each do |image|
87 +      next if ['aki', 'ari'].include?(image['disk_format'])
88 +      images.each do |i|
89 +        # find aki/ari image whose name starts with this image's name
90 +        if i['img_name'].start_with?(image['img_name'])
91 +          ret = 0
92 +          if i['disk_format'] == 'aki'
93 +            _, ret = update_image(image['id'], 'property',
94 +                                        "kernel_id=#{i['id']}")
95 +          elsif i['disk_format'] == 'ari'
96 +            _, ret = update_image(image['id'], 'property',
97 +                                        "ramdisk_id=#{i['id']}")
98 +          end
99 +          return_code += ret
100 +        end
101 +      end
102 +    end
103 +  end
104 +  return return_code
105 +end
106 +
107  ########################
108  
109  wait_for_glance
110 @@ -117,6 +170,7 @@ errors = 0
111  test_vm_images.each do |image|
112    errors += upload_image(image)
113  end
114 +errors = connect_dependant_images(test_vm_images) unless errors != 0
115  
116  exit 1 unless errors == 0
117  
118 diff --git a/deployment/puppet/osnailyfacter/templates/vm_libvirt.erb b/deployment/puppet/osnailyfacter/templates/vm_libvirt.erb
119 index 2d030d9..b33fb25 100644
120 --- a/deployment/puppet/osnailyfacter/templates/vm_libvirt.erb
121 +++ b/deployment/puppet/osnailyfacter/templates/vm_libvirt.erb
122 @@ -3,9 +3,15 @@
123    <memory unit='GiB'><%= @details['mem'] %></memory>
124    <vcpu placement='static'><%= @details['cpu'] %></vcpu>
125    <os>
126 -    <type arch='<%= @machine_arch %>' machine='<%= @machine_type %>'>hvm</type>
127 +  <type arch='<%= @machine_arch %>' machine='<%= @machine_type %>'>hvm</type>
128 +  <% if $machine_arch == 'aarch64' %>
129 +    <kernel>/var/lib/nova/<%= @details['id'] %>_vm.kernel</kernel>
130 +    <initrd>/var/lib/nova/<%= @details['id'] %>_vm.initramfs</initrd>
131 +    <cmdline>root=/dev/vda1 rw rootwait console=tty0 console=ttyS0 console=ttyAMA0</cmdline>
132 +  <% else %>
133      <boot dev='network'/>
134      <boot dev='hd'/>
135 +  <% end %>
136    </os>
137    <features>
138      <acpi/>