Skip to content

Commit 4805be1

Browse files
committed
fix(clouds): coerce mapped OpenStack config values to strings
YAML parsing can return non-string scalars (for example identity_api_version: 3 -> Integer). fog-openstack expects several auth/config fields as strings and calls regex matching on openstack_identity_api_version, which raised undefined method '=~' for Integer during authentication. Normalize all clouds.yaml and OS_* mapped keys in CLOUDS_YAML_AUTH_MAP and CLOUDS_YAML_TOP_MAP to strings before passing them into Fog. Add regression coverage to ensure numeric YAML scalars are coerced for openstack_project_id, openstack_domain_id, and openstack_identity_api_version. Signed-off-by: Lance Albertson <lance@osuosl.org>
1 parent 56ea3a4 commit 4805be1

2 files changed

Lines changed: 30 additions & 3 deletions

File tree

lib/kitchen/driver/openstack/clouds.rb

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ module Clouds
4848
"identity_api_version" => :openstack_identity_api_version,
4949
}.freeze
5050

51+
# Fog expects these config values to be strings. YAML may parse
52+
# unquoted scalars as integers/booleans, so normalize on ingest.
53+
STRING_CONFIG_KEYS = (CLOUDS_YAML_AUTH_MAP.values + CLOUDS_YAML_TOP_MAP.values).freeze
54+
5155
# Mapping of OS_* environment variables to Fog OpenStack config keys
5256
ENV_VAR_MAP = {
5357
"OS_AUTH_URL" => :openstack_auth_url,
@@ -100,7 +104,7 @@ def load_env_vars
100104
result = {}
101105
ENV_VAR_MAP.each do |env_var, fog_key|
102106
value = ENV[env_var]
103-
result[fog_key] = value if value && !value.empty?
107+
result[fog_key] = normalize_config_value(fog_key, value) if value && !value.empty?
104108
end
105109
result
106110
end
@@ -175,12 +179,14 @@ def translate_cloud_config(cloud)
175179
# Map auth section
176180
auth = cloud["auth"] || {}
177181
CLOUDS_YAML_AUTH_MAP.each do |yaml_key, fog_key|
178-
result[fog_key] = auth[yaml_key] if auth[yaml_key]
182+
value = auth[yaml_key]
183+
result[fog_key] = normalize_config_value(fog_key, value) if value
179184
end
180185

181186
# Map top-level keys
182187
CLOUDS_YAML_TOP_MAP.each do |yaml_key, fog_key|
183-
result[fog_key] = cloud[yaml_key] if cloud[yaml_key]
188+
value = cloud[yaml_key]
189+
result[fog_key] = normalize_config_value(fog_key, value) if value
184190
end
185191

186192
# SSL settings
@@ -189,6 +195,12 @@ def translate_cloud_config(cloud)
189195

190196
result
191197
end
198+
199+
def normalize_config_value(fog_key, value)
200+
return value unless STRING_CONFIG_KEYS.include?(fog_key)
201+
202+
value.to_s
203+
end
192204
end
193205
end
194206
end

spec/kitchen/driver/openstack/clouds_spec.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,21 @@
384384
result = driver.send(:translate_cloud_config, {})
385385
expect(result).to eq({})
386386
end
387+
388+
it "coerces non-string scalar values for fog string config keys" do
389+
cloud = {
390+
"auth" => {
391+
"project_id" => 12_345,
392+
"domain_id" => 9,
393+
},
394+
"identity_api_version" => 3,
395+
}
396+
397+
result = driver.send(:translate_cloud_config, cloud)
398+
expect(result[:openstack_project_id]).to eq("12345")
399+
expect(result[:openstack_domain_id]).to eq("9")
400+
expect(result[:openstack_identity_api_version]).to eq("3")
401+
end
387402
end
388403

389404
describe "#deep_merge" do

0 commit comments

Comments
 (0)