Skip to content

fix(driver): coerce OpenStack auth/config values to strings before Fog#239

Open
ramereth wants to merge 1 commit intomainfrom
fix/clouds-config-string-coercion
Open

fix(driver): coerce OpenStack auth/config values to strings before Fog#239
ramereth wants to merge 1 commit intomainfrom
fix/clouds-config-string-coercion

Conversation

@ramereth
Copy link
Copy Markdown
Contributor

@ramereth ramereth commented Apr 22, 2026

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 an instance of Integer

during authentication.

Fix this in two layers so values from any source are normalized:

  • Normalize values when ingesting from clouds.yaml and OS_* env vars in
    Kitchen::Driver::Openstack::Clouds, covering the keys mapped by
    CLOUDS_YAML_AUTH_MAP and CLOUDS_YAML_TOP_MAP.

  • Normalize values at the final Fog handoff in Kitchen::Driver::Openstack
    via FOG_STRING_SETTINGS and normalize_fog_setting, so values supplied
    directly via .kitchen.yml (or any other source) are also coerced.
    Nil values are preserved so Fog's required-argument validation still
    fires as before.

Add regression tests:

  • clouds.yaml integer values are coerced for openstack_project_id,
    openstack_domain_id, and openstack_identity_api_version.
  • Direct Kitchen config integer values are coerced when building the
    Fog server definition.

Signed-off-by: Lance Albertson lance@osuosl.org

Description

Please describe what this change achieves

Issues Resolved

List any existing issues this PR resolves, or any Discourse or
StackOverflow discussions that are relevant

Type of Change

Our release process assumes you are using Conventional Commit messages.

The most important prefixes you should have in mind are:

  • _fix_: which represents bug fixes, and correlates to a SemVer patch.
  • _feat_: which represents a new feature, and correlates to a SemVer minor.
  • _feat!_:, or fix!:, refactor!:, etc., which represent a breaking change (indicated by the !) and will result in a major version change.

If you have not included a conventional commit message this can be fixed on merge.

Check List

@ramereth ramereth force-pushed the fix/clouds-config-string-coercion branch from 4805be1 to fde979b Compare April 22, 2026 19:11
@ramereth ramereth changed the title fix(clouds): coerce mapped OpenStack config values to strings fix(driver): coerce OpenStack auth/config values to strings before Fog Apr 22, 2026
@ramereth ramereth force-pushed the fix/clouds-config-string-coercion branch 2 times, most recently from a3e2995 to 6280350 Compare April 22, 2026 19:13
When clouds.yaml or .kitchen.yml provides scalar values such as
`identity_api_version: 3` (Integer) or numeric IDs, fog-openstack
crashes during authentication because `Fog::OpenStack::Auth::Token.build`
calls `=~` on the value:

    NoMethodError: undefined method '=~' for an instance of Integer

Two layers of coercion are applied:

1. `Clouds` ingestion (clouds.rb): values mapped from clouds.yaml,
   secure.yaml, and `OS_*` env vars are normalized to strings via
   `STRING_CONFIG_KEYS`/`normalize_config_value` before being merged
   into `config`.

2. Fog handoff (openstack.rb): `openstack_server` wraps every value
   with `normalize_fog_setting`, which converts known string-typed
   Fog auth/config keys (listed in `FOG_STRING_SETTINGS`) to strings
   while preserving `nil` so that downstream "missing required
   argument" validation still fires.

Additionally, `openstack_identity_api_version` requires special
handling. Fog::Service#coerce_options re-coerces any value where
`value.to_s.to_i.to_s == value.to_s` back to an Integer, undoing the
String coercion before Token.build sees it. The value is now
prefixed with "v" (e.g. `3` -> `"v3"`, `2`/`2.0` -> `"v2.0"`), which
prevents Fog's coercion round-trip while still satisfying
Token.build's `/(v)*2(\.0)*/i` regex check for v2 detection.

Regression specs added:
- spec/kitchen/driver/openstack/clouds_spec.rb verifies that
  `translate_cloud_config` coerces non-string scalars for known
  string keys.
- spec/kitchen/driver/openstack_spec.rb verifies that
  `openstack_server` coerces numeric values for fog string settings
  and that `identity_api_version` is v-prefixed so it survives
  Fog::Service#coerce_options.

Signed-off-by: Lance Albertson <lance@osuosl.org>
@ramereth ramereth force-pushed the fix/clouds-config-string-coercion branch from 6280350 to fec1197 Compare April 22, 2026 19:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant