Merge "Rewrite upload_cirros using puppet"
This commit is contained in:
commit
2b6e4f4a30
|
@ -0,0 +1,28 @@
|
|||
# == Class: osnailyfacter::astute::upload_cirros
|
||||
#
|
||||
# Task to upload a basic cirros image to the evironment.
|
||||
#
|
||||
# == Paramters:
|
||||
#
|
||||
# N/A
|
||||
#
|
||||
class osnailyfacter::astute::upload_cirros {
|
||||
|
||||
notice('MODULAR: astute/upload_cirros.pp')
|
||||
|
||||
$test_vm_image = hiera_hash('test_vm_image')
|
||||
|
||||
include ::osnailyfacter::wait_for_glance_backends
|
||||
|
||||
glance_image { $test_vm_image['img_name']:
|
||||
ensure => present,
|
||||
container_format => $test_vm_image['container_format'],
|
||||
disk_format => $test_vm_image['disk_format'],
|
||||
is_public => $test_vm_image['public'],
|
||||
min_ram => $test_vm_image['min_ram'],
|
||||
source => $test_vm_image['img_path'],
|
||||
properties => $test_vm_image['properties'],
|
||||
}
|
||||
|
||||
Class['osnailyfacter::wait_for_glance_backends'] -> Glance_image<||>
|
||||
}
|
|
@ -0,0 +1,55 @@
|
|||
# == Class: osnailyfacter::wait_for_glance_backends
|
||||
#
|
||||
# This class is created to introduce one entry
|
||||
# point to check for glance backends
|
||||
#
|
||||
class osnailyfacter::wait_for_glance_backends
|
||||
{
|
||||
$management_vip = hiera('management_vip')
|
||||
$service_endpoint = hiera('service_endpoint')
|
||||
$external_lb = hiera('external_lb', false)
|
||||
$ssl_hash = hiera_hash('use_ssl', {})
|
||||
|
||||
$glance_api_protocol = get_ssl_property($ssl_hash, {}, 'glance', 'admin', 'protocol', 'http')
|
||||
$glance_api_address = get_ssl_property($ssl_hash, {}, 'glance', 'admin', 'hostname', [$service_endpoint, $management_vip])
|
||||
$glance_api_url = "${glance_api_protocol}://${glance_api_address}:9292"
|
||||
$glance_registry_protocol = get_ssl_property($ssl_hash, {}, 'glance', 'internal', 'protocol', 'http')
|
||||
$glance_registry_address = get_ssl_property($ssl_hash, {}, 'glance', 'internal', 'hostname', [$service_endpoint, $management_vip])
|
||||
$glance_registry_url = "${glance_registry_protocol}://${glance_registry_address}:9191"
|
||||
|
||||
$haproxy_stats_url = "http://${service_endpoint}:10000/;csv"
|
||||
|
||||
$lb_defaults = {
|
||||
step => 6,
|
||||
count => 200,
|
||||
provider => 'haproxy',
|
||||
url => $haproxy_stats_url
|
||||
}
|
||||
|
||||
if $external_lb {
|
||||
$lb_glance_api = {
|
||||
provider => 'http',
|
||||
url => $glance_api_url
|
||||
}
|
||||
$lb_glance_registry = {
|
||||
provider => 'http',
|
||||
url => $glance_registry_url
|
||||
}
|
||||
}
|
||||
$lb_hash = {
|
||||
'glance-api' => merge(
|
||||
{ name => 'glance-api' },
|
||||
$lb_glance_api
|
||||
),
|
||||
'glance-registry' => merge(
|
||||
{ name => 'glance-registry' },
|
||||
$lb_glance_registry
|
||||
)
|
||||
}
|
||||
|
||||
::osnailyfacter::wait_for_backend { 'glance':
|
||||
lb_hash => $lb_hash,
|
||||
lb_defaults => $lb_defaults
|
||||
}
|
||||
|
||||
}
|
|
@ -16,7 +16,7 @@
|
|||
timeout: 180
|
||||
|
||||
- id: upload_cirros
|
||||
type: shell
|
||||
type: puppet
|
||||
version: 2.1.0
|
||||
role: [primary-controller]
|
||||
requires: [enable_quorum]
|
||||
|
@ -28,10 +28,10 @@
|
|||
cross-depends:
|
||||
- name: enable_quorum
|
||||
parameters:
|
||||
cmd: ruby /etc/puppet/modules/osnailyfacter/modular/astute/upload_cirros.rb
|
||||
retries: 3
|
||||
interval: 20
|
||||
timeout: 180
|
||||
puppet_manifest: /etc/puppet/modules/osnailyfacter/modular/astute/upload_cirros.pp
|
||||
puppet_modules: /etc/puppet/modules
|
||||
timeout: 300
|
||||
cwd: /
|
||||
|
||||
- id: upload_nodes_info
|
||||
type: skipped
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
class { '::osnailyfacter::astute::upload_cirros': }
|
|
@ -1,127 +0,0 @@
|
|||
#!/usr/bin/env ruby
|
||||
require 'hiera'
|
||||
|
||||
ENV['LANG'] = 'C'
|
||||
|
||||
hiera = Hiera.new(:config => '/etc/hiera.yaml')
|
||||
test_vm_images = hiera.lookup 'test_vm_image', {}, {}
|
||||
glanced = hiera.lookup 'glance', {} , {}, nil, :hash
|
||||
management_vip = hiera.lookup 'management_vip', nil, {}
|
||||
auth_addr = hiera.lookup 'service_endpoint', "#{management_vip}", {}
|
||||
tenant_name = glanced['tenant'].nil? ? "services" : glanced['tenant']
|
||||
user_name = glanced['user'].nil? ? "glance" : glanced['user']
|
||||
endpoint_type = glanced['endpoint_type'].nil? ? "internalURL" : glanced['endpoint_type']
|
||||
region_name = hiera.lookup 'region', 'RegionOne', {}
|
||||
ssl_hash = hiera.lookup 'use_ssl', {}, {}
|
||||
|
||||
if ssl_hash['keystone_internal']
|
||||
auth_proto = 'https'
|
||||
auth_addr = ssl_hash['keystone_internal_hostname'] || auth_addr
|
||||
else
|
||||
auth_proto = 'http'
|
||||
end
|
||||
|
||||
puts "Auth URL is #{auth_proto}://#{auth_addr}:5000/v2.0"
|
||||
|
||||
ENV['OS_TENANT_NAME']="#{tenant_name}"
|
||||
ENV['OS_USERNAME']="#{user_name}"
|
||||
ENV['OS_PASSWORD']="#{glanced['user_password']}"
|
||||
ENV['OS_AUTH_URL']="#{auth_proto}://#{auth_addr}:5000/v2.0"
|
||||
ENV['OS_ENDPOINT_TYPE'] = "#{endpoint_type}"
|
||||
ENV['OS_REGION_NAME']="#{region_name}"
|
||||
|
||||
raise 'Not test_vm_image data!' unless [Array, Hash].include?(test_vm_images.class) && test_vm_images.any?
|
||||
|
||||
test_vm_images = [test_vm_images] unless test_vm_images.is_a? Array
|
||||
|
||||
test_vm_images.each do |image|
|
||||
%w(
|
||||
disk_format
|
||||
img_path
|
||||
img_name
|
||||
os_name
|
||||
public
|
||||
container_format
|
||||
min_ram
|
||||
).each do |f|
|
||||
raise "Data field '#{f}' is missing!" unless image[f]
|
||||
end
|
||||
end
|
||||
|
||||
def image_list
|
||||
stdout = `glance --verbose image-list`
|
||||
return_code = $?.exitstatus
|
||||
images = []
|
||||
stdout.split("\n").each do |line|
|
||||
fields = line.split('|').map { |f| f.chomp.strip }
|
||||
next if fields[1] == 'ID'
|
||||
next unless fields[2]
|
||||
images << {fields[2] => fields[6]}
|
||||
end
|
||||
{:images => images, :exit_code => return_code}
|
||||
end
|
||||
|
||||
def image_create(image_hash)
|
||||
command = <<-EOF
|
||||
/usr/bin/glance image-create \
|
||||
--name '#{image_hash['img_name']}' \
|
||||
--visibility '#{image_hash['visibility']}' \
|
||||
--container-format='#{image_hash['container_format']}' \
|
||||
--disk-format='#{image_hash['disk_format']}' \
|
||||
--min-ram='#{image_hash['min_ram']}' \
|
||||
#{image_hash['glance_properties']} \
|
||||
--file '#{image_hash['img_path']}'
|
||||
EOF
|
||||
puts command
|
||||
stdout = `#{command}`
|
||||
return_code = $?.exitstatus
|
||||
[ stdout, return_code ]
|
||||
end
|
||||
|
||||
# check if Glance is online
|
||||
# waited until the glance is started because when vCenter used as a glance
|
||||
# backend launch may takes up to 1 minute.
|
||||
def wait_for_glance
|
||||
5.times.each do |retries|
|
||||
sleep 10 if retries > 0
|
||||
return if image_list[:exit_code] == 0
|
||||
end
|
||||
raise 'Could not get a list of glance images!'
|
||||
end
|
||||
|
||||
# upload image to Glance
|
||||
# if it have not been already uploaded
|
||||
def upload_image(image)
|
||||
list_of_images = image_list
|
||||
if list_of_images[:images].include?(image['img_name'] => "active") && list_of_images[:exit_code] == 0
|
||||
puts "Image '#{image['img_name']}' is already present!"
|
||||
return 0
|
||||
end
|
||||
|
||||
# convert old API v1 'public' property to API v2 'visibility' property
|
||||
if image['public'] == 'true'
|
||||
image['visibility'] = 'public'
|
||||
else
|
||||
image['visibility'] = 'private'
|
||||
end
|
||||
stdout, return_code = image_create(image)
|
||||
if return_code == 0
|
||||
puts "Image '#{image['img_name']}' was uploaded from '#{image['img_path']}'"
|
||||
else
|
||||
puts "Image '#{image['img_name']}' upload from '#{image['img_path']}' FAILED!"
|
||||
end
|
||||
puts stdout
|
||||
return return_code
|
||||
end
|
||||
|
||||
########################
|
||||
|
||||
wait_for_glance
|
||||
errors = 0
|
||||
|
||||
test_vm_images.each do |image|
|
||||
errors += upload_image(image)
|
||||
end
|
||||
|
||||
exit 1 unless errors == 0
|
||||
|
|
@ -0,0 +1,37 @@
|
|||
# ROLE: primary-controller
|
||||
|
||||
require 'spec_helper'
|
||||
require 'shared-examples'
|
||||
manifest = 'astute/upload_cirros.pp'
|
||||
|
||||
describe manifest do
|
||||
shared_examples 'catalog' do
|
||||
|
||||
let(:test_vm_image) { Noop.hiera_hash('test_vm_image') }
|
||||
it 'should contain upload_cirros class' do
|
||||
should contain_class('osnailyfacter::astute::upload_cirros')
|
||||
end
|
||||
|
||||
it 'should wait for glance backends' do
|
||||
should contain_class('osnailyfacter::wait_for_glance_backends')
|
||||
end
|
||||
|
||||
it 'should use glance_image provider' do
|
||||
should contain_glance_image(test_vm_image['img_name']).with(
|
||||
:ensure => 'present',
|
||||
:container_format => test_vm_image['container_format'],
|
||||
:disk_format => test_vm_image['disk_format'],
|
||||
:is_public => test_vm_image['public'],
|
||||
:min_ram => test_vm_image['min_ram'],
|
||||
:source => test_vm_image['img_path']
|
||||
)
|
||||
end
|
||||
|
||||
it 'should have explicit ordering between LB classes and images' do
|
||||
expect(graph).to ensure_transitive_dependency("Haproxy_backend_status[glance-api]", "Glance_image[#{test_vm_image['img_name']}]")
|
||||
expect(graph).to ensure_transitive_dependency("Haproxy_backend_status[glance-registry]", "Glance_image[#{test_vm_image['img_name']}]")
|
||||
end
|
||||
end
|
||||
|
||||
test_ubuntu_and_centos manifest
|
||||
end
|
Loading…
Reference in New Issue