From abd028a5f6b0e5e139cb53678482299b8c55b0d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Kundr=C3=A1t?= Date: Wed, 1 Oct 2014 01:34:57 +0200 Subject: [PATCH] Run the `glance` CLI tool with appropriate region name This is pretty important in situations where Keystone contains information about multiple regions. The holding assumption is that the glance::image etc are used for image upload for the current region. Change-Id: I0a24cd24ddf3e0b1fab94e693a2fac847cc7271c --- lib/puppet/provider/glance.rb | 10 ++++++---- spec/unit/provider/glance_spec.rb | 6 ++++++ 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/lib/puppet/provider/glance.rb b/lib/puppet/provider/glance.rb index d0a7bb66..ec4e1c08 100644 --- a/lib/puppet/provider/glance.rb +++ b/lib/puppet/provider/glance.rb @@ -15,7 +15,8 @@ class Puppet::Provider::Glance < Puppet::Provider glance_file['keystone_authtoken']['auth_protocol'] and glance_file['keystone_authtoken']['admin_tenant_name'] and glance_file['keystone_authtoken']['admin_user'] and - glance_file['keystone_authtoken']['admin_password'] + glance_file['keystone_authtoken']['admin_password'] and + glance_file['DEFAULT']['os_region_name'] g = {} g['auth_host'] = glance_file['keystone_authtoken']['auth_host'].strip @@ -24,6 +25,7 @@ class Puppet::Provider::Glance < Puppet::Provider g['admin_tenant_name'] = glance_file['keystone_authtoken']['admin_tenant_name'].strip g['admin_user'] = glance_file['keystone_authtoken']['admin_user'].strip g['admin_password'] = glance_file['keystone_authtoken']['admin_password'].strip + g['os_region_name'] = glance_file['DEFAULT']['os_region_name'].strip # auth_admin_prefix not required to be set. g['auth_admin_prefix'] = (glance_file['keystone_authtoken']['auth_admin_prefix'] || '').strip @@ -72,11 +74,11 @@ class Puppet::Provider::Glance < Puppet::Provider def self.auth_glance(*args) begin g = glance_credentials - remove_warnings(glance('--os-tenant-name', g['admin_tenant_name'], '--os-username', g['admin_user'], '--os-password', g['admin_password'], '--os-auth-url', auth_endpoint, args)) + remove_warnings(glance('--os-tenant-name', g['admin_tenant_name'], '--os-username', g['admin_user'], '--os-password', g['admin_password'], '--os-region-name', g['os_region_name'], '--os-auth-url', auth_endpoint, args)) rescue Exception => e if (e.message =~ /\[Errno 111\] Connection refused/) or (e.message =~ /\(HTTP 400\)/) or (e.message =~ /HTTP Unable to establish connection/) sleep 10 - remove_warnings(glance('--os-tenant-name', g['admin_tenant_name'], '--os-username', g['admin_user'], '--os-password', g['admin_password'], '--os-auth-url', auth_endpoint, args)) + remove_warnings(glance('--os-tenant-name', g['admin_tenant_name'], '--os-username', g['admin_user'], '--os-password', g['admin_password'], '--os-region-name', g['os_region_name'], '--os-auth-url', auth_endpoint, args)) else raise(e) end @@ -90,7 +92,7 @@ class Puppet::Provider::Glance < Puppet::Provider def self.auth_glance_stdin(*args) begin g = glance_credentials - command = "glance --os-tenant-name #{g['admin_tenant_name']} --os-username #{g['admin_user']} --os-password #{g['admin_password']} --os-auth-url #{auth_endpoint} #{args.join(' ')}" + command = "glance --os-tenant-name #{g['admin_tenant_name']} --os-username #{g['admin_user']} --os-password #{g['admin_password']} --os-region-name #{g['os_region_name']} --os-auth-url #{auth_endpoint} #{args.join(' ')}" # This is a horrible, horrible hack # Redirect stderr to stdout in order to report errors diff --git a/spec/unit/provider/glance_spec.rb b/spec/unit/provider/glance_spec.rb index 315b0b31..14d418b9 100644 --- a/spec/unit/provider/glance_spec.rb +++ b/spec/unit/provider/glance_spec.rb @@ -35,6 +35,10 @@ describe Puppet::Provider::Glance do 'admin_tenant_name' => 'foo', 'admin_user' => 'user', 'admin_password' => 'pass' + }, + 'DEFAULT' => + { + 'os_region_name' => 'SomeRegion', } } Puppet::Util::IniConfig::File.expects(:new).returns(mock) @@ -47,6 +51,8 @@ describe Puppet::Provider::Glance do 'user', '--os-password', 'pass', + '--os-region-name', + 'SomeRegion', '--os-auth-url', 'http://127.0.0.1:35357/v2.0/', ['test_retries']