Merge "Add image_id method and update openstack_command"
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
# CHANGELOG for cookbook-openstack-common
|
||||
|
||||
This file is used to list changes made in each version of cookbook-openstack-common.
|
||||
## 9.5.0
|
||||
* Add new image_id cli library method for obtaining glance ID from image name
|
||||
|
||||
## 9.4.1
|
||||
* Fix to allow database connection options for telemetry nosql
|
||||
|
||||
|
||||
@@ -53,7 +53,11 @@ module ::Openstack # rubocop:disable Documentation
|
||||
# update the provider to use this.
|
||||
#
|
||||
def openstack_command(cmd, options = '', env = {}, args = {})
|
||||
openstackcmd = [cmd] << options
|
||||
# NOTE: Here we split options (which creates an array) and then merge that
|
||||
# array into [cmd]. This is done to accomdate cmd + options like:
|
||||
# keystone user-list
|
||||
# glance image-show <id|name>
|
||||
openstackcmd = [cmd].concat(options.split)
|
||||
args.each do |key, val|
|
||||
openstackcmd << "--#{key}" << val.to_s
|
||||
end
|
||||
@@ -87,4 +91,21 @@ module ::Openstack # rubocop:disable Documentation
|
||||
end
|
||||
nil
|
||||
end
|
||||
|
||||
# return id for a glance image.
|
||||
#
|
||||
# @param [String] name of image
|
||||
# @param [Hash] environment to use.
|
||||
# @return [String] id or nil
|
||||
def image_id(name, env, args = {})
|
||||
begin
|
||||
output = openstack_command('glance', "image-show #{name}", env, args)
|
||||
prettytable_to_array(output).each do |obj|
|
||||
return obj['id'] if obj.key?('id')
|
||||
end
|
||||
rescue RuntimeError => e
|
||||
raise "Could not lookup ID for image #{name}. Error was #{e.message}"
|
||||
end
|
||||
nil
|
||||
end
|
||||
end
|
||||
|
||||
@@ -4,7 +4,7 @@ maintainer_email 'cookbooks@lists.tfoundry.com'
|
||||
license 'Apache 2.0'
|
||||
description 'Common OpenStack attributes, libraries and recipes.'
|
||||
long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
|
||||
version '9.4.1'
|
||||
version '9.5.0'
|
||||
|
||||
recipe 'openstack-common', 'Installs/Configures common recipes'
|
||||
recipe 'openstack-common::set_endpoints_by_interface', 'Set endpoints by interface'
|
||||
|
||||
@@ -100,5 +100,32 @@ describe 'openstack-common::default' do
|
||||
expect(result).to eq('1234567890ABCDEFGH')
|
||||
end
|
||||
end
|
||||
|
||||
describe 'image_id' do
|
||||
let(:env) do
|
||||
{
|
||||
'OS_USERNAME' => 'name',
|
||||
'OS_PASSWORD' => 'pass',
|
||||
'OS_TENANT_NAME' => 'tenant',
|
||||
'OS_AUTH_URL' => 'http://127.0.0.1:35357/v2.0'
|
||||
}
|
||||
end
|
||||
|
||||
it 'runs glance command to query valid id' do
|
||||
subject.stub(:openstack_command).with('glance', 'image-show cirros', :env, {})
|
||||
subject.stub(:prettytable_to_array)
|
||||
.and_return([{ 'id' => '87f38e15-9737-46cc-a612-7c67ee29a24f', 'name' => 'cirros' }])
|
||||
|
||||
result = subject.image_id('cirros', :env)
|
||||
expect(result).to eq('87f38e15-9737-46cc-a612-7c67ee29a24f')
|
||||
end
|
||||
|
||||
it 'runs glance command to query invalid id' do
|
||||
subject.stub(:openstack_command).with('glance', 'image-show test', :env, {})
|
||||
.and_raise("No image with a name or ID of 'test' exists. (1)")
|
||||
|
||||
expect { subject.image_id('test', :env) }.to raise_error
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user