Uploaded image for project: 'Red Hat OpenStack Services on OpenShift'
  1. Red Hat OpenStack Services on OpenShift
  2. OSPRH-15097

unmarshalling of yaml data leads to wrong conversion from string/integers to floats

XMLWordPrintable

    • 5
    • False
    • Hide

      None

      Show
      None
    • False
    • ?
    • openstack-operator-container-1.0.11-2
    • rhos-ops-day1day2-edpm
    • None
    • EDPM Sprint 1, EDPM Sprint 2
    • 2
    • Critical

      To Reproduce Steps to reproduce the behavior:

      1. problematic code is at: 
        https://github.com/openstack-k8s-operators/openstack-operator/blob/225d2ebd19baeac0c8a099fb935687ca5e87000a/pkg/dataplane/inventory.go#L75C5-L75C37
      2. reproducer in plain go code is at:
        https://go.dev/play/p/gdjz5YolNgY

      for posterity, here is the reproducer:

      package main
      
      import (
          "encoding/json"
          "fmt"
      )
      
      func main() {
          subscription_manager_org_id := `12345567890`
          var value any
          v := []byte(subscription_manager_org_id)
          err := json.Unmarshal(v, &value)
          if err != nil {
              fmt.Printf("Got error %v, assuming string ...\n", err)
              value = string(v)
          }
          fmt.Printf("'%v' is %T\n", value, value)
      }
      
      // output: '1.234556789e+10' is float64

      we stumbled upon this, when deploying RHOSO for a customer, when we wanted to provide the org_id for the subscription manager to register systems via ansible/edpm ansible like this:

      org_id: "1234567890"

      error code during execution:

      TASK [osp.edpm.edpm_bootstrap : Bootstrap command output] **********************
      fatal: [srv12d]: FAILED! => {
          "msg": {
              "stderr": [
                  "Organization 123456789.0 does not exist. (HTTP error code 401: Unauthorized)"
              ],
              "stdout": [
                  "Changing password for user root.",
                  "passwd: all authentication tokens updated successfully."
              ]
          }
      } 

      Expected behavior

      • I think there must be a check in the code, before unmarshalling to json if the string is a pure number or something and in that case not unmarshal it.

      Workaround: directly use edpm-ansible/playbooks/redhat.yml to configure this

              drosenfe David Rosenfeld
              rh-ee-skieske Sven Kieske
              rhos-dfg-df
              Votes:
              0 Vote for this issue
              Watchers:
              10 Start watching this issue

                Created:
                Updated:
                Resolved: