Move image upload part from api recipe to new recipe of image_upload.

Since for bug 1257169 openstack-image api recipe should be executed before
openstack-image registry recipe, the image upload part in the api recipe need
to be moved to a new recipe of image_upload.

Change-Id: I1f557d2e817643a9e3e06788dc446c970ef2df89
Closes-Bug: #1257169
This commit is contained in:
Eric Zhou 2013-12-03 18:40:40 +08:00 committed by zyouzhou-cn
parent 900c9eef12
commit bc3b8270b6
7 changed files with 135 additions and 77 deletions

View File

@ -33,6 +33,10 @@ keystone-registration
---------------------
- Registers the API endpoint and glance service Keystone user
image-upload
------------
- Upload image to glance. If you want to upload image during openstack installation, you need to add this recipe or the os-image role to the run list in a certain role and ensure before this recipe or the os-image role glance api and glance registry recipes have been executed.
The Glance cookbook currently supports file, swift, and Rackspace Cloud Files (swift API compliant) backing stores. NOTE: changing the storage location from cloudfiles to swift (and vice versa) requires that you manually export and import your stored images.
To enable these features set the following in the default attributes section in your environment:
@ -48,8 +52,7 @@ Files
},
"upload_images": [
"cirros"
],
"image_upload": true
]
}
}
```
@ -65,8 +68,7 @@ Swift
},
"upload_images": [
"cirros"
],
"image_upload": true
]
}
}
```
@ -106,7 +108,6 @@ Attributes for the Image service are in the ['openstack']['image'] namespace.
* `openstack['image']['service_role']` - User role used by glance when interacting with keystone - used in the API and registry paste.ini files
* `openstack['image']['api']['auth']['cache_dir']` - Defaults to `/var/cache/glance/api`. Directory where `auth_token` middleware writes certificates for glance-api
* `openstack['image']['registry']['auth']['cache_dir']` - Defaults to `/var/cache/glance/registry`. Directory where `auth_token` middleware writes certificates for glance-registry
* `openstack['image']['image_upload']` - Toggles whether to automatically upload images in the `openstack['image']['upload_images']` array
* `openstack['image']['upload_images']` - Default list of images to upload to the glance repository as part of the install
* `openstack['image']['upload_image']['<imagename>']` - URL location of the `<imagename>` image. There can be multiple instances of this line to define multiple imagess (eg natty, maverick, fedora17 etc)
--- example `openstack['image']['upload_image']['natty']` - "http://c250663.r63.cf1.rackcdn.com/ubuntu-11.04-server-uec-amd64-multinic.tar.gz"

View File

@ -126,7 +126,6 @@ default["openstack"]["image"]["registry"]["bind_interface"] = nil
default["openstack"]["image"]["data_api"] = "glance.db.sqlalchemy.api"
# Default Image Locations
default["openstack"]["image"]["image_upload"] = false
default["openstack"]["image"]["upload_images"] = [ "cirros" ]
default["openstack"]["image"]["upload_image"]["precise"] = "http://cloud-images.ubuntu.com/precise/current/precise-server-cloudimg-amd64-disk1.img"
default["openstack"]["image"]["upload_image"]["oneiric"] = "http://cloud-images.ubuntu.com/oneiric/current/oneiric-server-cloudimg-amd64-disk1.img"
@ -151,7 +150,8 @@ when "fedora", "redhat", "centos" # :pragma-foodcritic: ~FC024 - won't fix this
default["openstack"]["image"]["platform"] = {
"postgresql_python_packages" => [ "python-psycopg2" ],
"mysql_python_packages" => [ "MySQL-python" ],
"image_packages" => [ "openstack-glance", "cronie" ],
"image_packages" => [ "openstack-glance", "cronie", "python-glanceclient"],
"image_client_packages" => ["python-glanceclient"],
"swift_packages" => [ "openstack-swift" ],
"image_api_service" => "openstack-glance-api",
"image_registry_service" => "openstack-glance-registry",
@ -165,6 +165,7 @@ when "suse"
"postgresql_python_packages" => [ "python-psycopg2" ],
"mysql_python_packages" => [ "python-mysql" ],
"image_packages" => [ "openstack-glance", "python-glanceclient" ],
"image_client_packages" => ["python-glanceclient"],
"swift_packages" => [ "openstack-swift" ],
"image_api_service" => "openstack-glance-api",
"image_registry_service" => "openstack-glance-registry",
@ -178,6 +179,7 @@ when "ubuntu"
"postgresql_python_packages" => [ "python-psycopg2" ],
"mysql_python_packages" => [ "python-mysqldb" ],
"image_packages" => [ "glance" ],
"image_client_packages" => ["python-glanceclient"],
"swift_packages" => [ "python-swift" ],
"image_api_service" => "glance-api",
"image_registry_service" => "glance-registry",

View File

@ -7,6 +7,7 @@ version "8.0.0"
recipe "openstack-image::api", "Installs packages required for a glance api server"
recipe "openstack-image::registry", "Installs packages required for a glance registry server"
recipe "openstack-image::identity_registration", "Registers Glance endpoints and service with Keystone"
recipe "openstack-image::image_upload", "Upload image using glance image-create command"
%w{ ubuntu fedora redhat centos suse }.each do |os|
supports os

View File

@ -6,6 +6,7 @@
# Copyright 2012-2013, Opscode, Inc.
# Copyright 2012-2013, AT&T Services, Inc.
# Copyright 2013, Craig Tracey <craigtracey@gmail.com>
# Copyright 2013, IBM Corp.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@ -236,17 +237,3 @@ template "/etc/glance/glance-scrubber-paste.ini" do
group node["openstack"]["image"]["group"]
mode 00644
end
if node["openstack"]["image"]["image_upload"]
node["openstack"]["image"]["upload_images"].each do |img|
openstack_image_image "Image setup for #{img.to_s}" do
image_url node["openstack"]["image"]["upload_image"][img.to_sym]
image_name img
identity_user service_user
identity_pass service_pass
identity_tenant service_tenant_name
identity_uri auth_uri
action :upload
end
end
end

63
recipes/image_upload.rb Normal file
View File

@ -0,0 +1,63 @@
#
## Cookbook Name:: openstack-image
## Recipe:: image_upload
##
## Copyright 2013, IBM Corp.
##
## Licensed under the Apache License, Version 2.0 (the "License");
## you may not use this file except in compliance with the License.
## You may obtain a copy of the License at
##
## http://www.apache.org/licenses/LICENSE-2.0
##
## Unless required by applicable law or agreed to in writing, software
## distributed under the License is distributed on an "AS IS" BASIS,
## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
## See the License for the specific language governing permissions and
## limitations under the License.
##
#
class ::Chef::Recipe
include ::Openstack
end
if node["openstack"]["image"]["syslog"]["use"]
include_recipe "openstack-common::logging"
end
platform_options = node["openstack"]["image"]["platform"]
platform_options["image_client_packages"].each do |pkg|
package pkg do
action :upgrade
end
end
identity_endpoint = endpoint "identity-api"
#TODO(jaypipes): Move this logic and stuff into the openstack-common
# library cookbook.
auth_uri = identity_endpoint.to_s
if node["openstack"]["image"]["api"]["auth"]["version"] != "v2.0"
# The auth_uri should contain /v2.0 in most cases, but if the
# auth_version is v3.0, we leave it off. This is only necessary
# for environments that need to support V3 non-default-domain
# tokens, which is really the only reason to set version to
# something other than v2.0 (the default)
auth_uri = auth_uri.gsub('/v2.0', '')
end
service_pass = service_password "openstack-image"
service_tenant_name = node["openstack"]["image"]["service_tenant_name"]
service_user = node["openstack"]["image"]["service_user"]
node["openstack"]["image"]["upload_images"].each do |img|
openstack_image_image "Image setup for #{img.to_s}" do
image_url node["openstack"]["image"]["upload_image"][img.to_sym]
image_name img
identity_user service_user
identity_pass service_pass
identity_tenant service_tenant_name
identity_uri auth_uri
action :upload
end
end

View File

@ -404,61 +404,5 @@ describe "openstack-image::api" do
pending "TODO: implement"
end
end
it "uploads qcow image when one does not exist" do
opts = {
:step_into => ["openstack_image_image"]
}
chef_run = ::ChefSpec::Runner.new ::UBUNTU_OPTS.merge(opts) do |n|
n.set["openstack"]["image"] = {
"image_upload" => true,
"upload_images" => [
"image1"
],
"upload_image" => {
"image1" => "http://example.com/image.qcow2"
}
}
end
list_cmd = "glance --insecure " \
"--os-username glance " \
"--os-password glance-pass " \
"--os-tenant-name service "\
"--os-image-url http://127.0.0.1:9292 " \
"--os-auth-url http://127.0.0.1:5000/v2.0 " \
"image-list | grep image1"
stub_command(list_cmd).and_return(false)
chef_run.converge("openstack-image::api")
expect(chef_run).to run_execute("Uploading QCOW2 image image1")
end
it "does not upload qcow image if it already exists" do
opts = {
:step_into => ["openstack_image_image"]
}
chef_run = ::ChefSpec::Runner.new ::UBUNTU_OPTS.merge(opts) do |n|
n.set["openstack"]["image"] = {
"image_upload" => true,
"upload_images" => [
"image1"
],
"upload_image" => {
"image1" => "http://example.com/image.qcow2"
}
}
end
list_cmd = "glance --insecure " \
"--os-username glance " \
"--os-password glance-pass " \
"--os-tenant-name service "\
"--os-image-url http://127.0.0.1:9292 " \
"--os-auth-url http://127.0.0.1:5000/v2.0 " \
"image-list | grep image1"
stub_command(list_cmd).and_return(true)
chef_run.converge("openstack-image::api")
expect(chef_run).to_not run_execute("Uploading QCOW2 image image1")
end
end
end

60
spec/image_upload_spec.rb Normal file
View File

@ -0,0 +1,60 @@
require_relative "spec_helper"
describe "openstack-image::image_upload" do
before { image_stubs }
describe "ubuntu" do
it "uploads qcow image when one does not exist" do
opts = {
:step_into => ["openstack_image_image"]
}
chef_run = ::ChefSpec::Runner.new ::UBUNTU_OPTS.merge(opts) do |n|
n.set["openstack"]["image"] = {
"upload_images" => [
"image1"
],
"upload_image" => {
"image1" => "http://example.com/image.qcow2"
}
}
end
list_cmd = "glance --insecure " \
"--os-username glance " \
"--os-password glance-pass " \
"--os-tenant-name service "\
"--os-image-url http://127.0.0.1:9292 " \
"--os-auth-url http://127.0.0.1:5000/v2.0 " \
"image-list | grep image1"
stub_command(list_cmd).and_return(false)
chef_run.converge("openstack-image::image_upload")
expect(chef_run).to run_execute("Uploading QCOW2 image image1")
end
it "does not upload qcow image if it already exists" do
opts = {
:step_into => ["openstack_image_image"]
}
chef_run = ::ChefSpec::Runner.new ::UBUNTU_OPTS.merge(opts) do |n|
n.set["openstack"]["image"] = {
"upload_images" => [
"image1"
],
"upload_image" => {
"image1" => "http://example.com/image.qcow2"
}
}
end
list_cmd = "glance --insecure " \
"--os-username glance " \
"--os-password glance-pass " \
"--os-tenant-name service "\
"--os-image-url http://127.0.0.1:9292 " \
"--os-auth-url http://127.0.0.1:5000/v2.0 " \
"image-list | grep image1"
stub_command(list_cmd).and_return(true)
chef_run.converge("openstack-image::image_upload")
expect(chef_run).to_not run_execute("Uploading QCOW2 image image1")
end
end
end