Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[glance]: handle various image struct member types #3159

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

kayrus
Copy link
Contributor

@kayrus kayrus commented Jul 26, 2024

Fixes #3147

Links to the line numbers/files in the OpenStack source code that support the
code in this PR:

[PUT URLS HERE]

@github-actions github-actions bot added edit:image This PR updates image code semver:patch No API change labels Jul 26, 2024
@coveralls
Copy link

coveralls commented Jul 26, 2024

Coverage Status

coverage: 78.709% (-0.02%) from 78.726%
when pulling 5411d4a on kayrus:glance-formats
into 8caccbb on gophercloud:master.

@kayrus kayrus requested a review from pierreprinetti July 26, 2024 13:26
@pierreprinetti
Copy link
Member

I'd really love to have @stephenfin's eyes on this first

@kayrus kayrus requested a review from stephenfin July 26, 2024 13:47
@kayrus
Copy link
Contributor Author

kayrus commented Sep 20, 2024

@stephenfin any updates?

@kayrus
Copy link
Contributor Author

kayrus commented Sep 24, 2024

This is required to fix the terraform-provider-openstack/terraform-provider-openstack#1703

@kayrus kayrus requested a review from a team September 24, 2024 09:05
Copy link
Contributor

@stephenfin stephenfin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

God I hate the Glance API 😞

Two asks for comments inline but I'm otherwise good. Sorry for the delay: I missed the ask.

Comment on lines 128 to 166
switch t := s.Hidden.(type) {
case nil:
r.Hidden = false
case bool:
r.Hidden = t
case string:
r.Hidden, err = strconv.ParseBool(t)
if err != nil {
return fmt.Errorf("Failed to parse Hidden %q: %v", t, err)
}
default:
return fmt.Errorf("Unknown type for Hidden: %v (value: %v)", reflect.TypeOf(t), t)
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How is this happening. This should always be a boolean since that's how it's stored in the DB (source) and the API is simply using exactly what is stored there (source).

Sorry, you explained this in the issue. It's been a while 😅 Would it be possible to get a comment here explaining what's going on for future us (without needing to search though GitHub Issues)

@@ -267,10 +267,11 @@ func HandleImageGetSuccessfully(t *testing.T) {
"disk_format": "qcow2",
"updated_at": "2014-05-05T17:15:11Z",
"visibility": "public",
"os_hidden": false,
"os_hidden": "False",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could do with a note about what we're simulating here also...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@kayrus kayrus force-pushed the glance-formats branch 3 times, most recently from 520b250 to e96c3c2 Compare October 10, 2024 19:12
@kayrus kayrus changed the title [glance]: handle various Hidden/Properties formats [glance]: handle various image struct member types Oct 10, 2024
@kayrus kayrus force-pushed the glance-formats branch 2 times, most recently from 3815ffc to d4aeae5 Compare October 10, 2024 19:23
@kayrus kayrus added the backport-v2 This PR will be backported to v2 label Oct 11, 2024
Comment on lines +126 to +129
r.Name, err = assert.String(s.Name, "Name")
if err != nil {
return err
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this necessary? What's the difference between this and regular json unmarshalling with omitempty?

Ditto all other uses of String below.

@@ -0,0 +1,70 @@
package assert
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These aren't assertions. These are format conversions. jsonhelpers maybe?


const errf = "unknown type for %s: %T (value: %v)"

func Int(v any, name string) (int, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NumberOrString?

return 0, fmt.Errorf(errf, name, v, v)
}

func Int64(v any, name string) (int64, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you made NumberOrString generic on the return type you wouldn't need this function at all.

type ConvertibleNumber interface { int | int64 | float32 | float64 }

return 0, fmt.Errorf(errf, name, v, v)
}

func String(v any, name string) (string, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure this is necessary.

return "", fmt.Errorf(errf, name, v, v)
}

func Bool(v any, name string) (bool, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BoolOrString?

@bkranendonk
Copy link

@stephenfin @pierreprinetti can anyone take a look at this PR? 😇 thanks!

@kayrus
Copy link
Contributor Author

kayrus commented Dec 13, 2024

I didn't expect that anyone else is interested in this PR.

@stephenfin
Copy link
Contributor

@stephenfin @pierreprinetti can anyone take a look at this PR? 😇 thanks!

It looks like there's a few outstanding comments from @mdbooth that need addressing/response first?

@rmnijgh
Copy link

rmnijgh commented Apr 8, 2025

Any updates? @stephenfin @pierreprinetti @mdbooth

@stephenfin
Copy link
Contributor

@stephenfin @pierreprinetti can anyone take a look at this PR? 😇 thanks!

It looks like there's a few outstanding comments from @mdbooth that need addressing/response first?

This is still true?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport-v2 This PR will be backported to v2 edit:image This PR updates image code semver:patch No API change
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Error when querying images: "json: cannot unmarshal string into Go struct field .images of type bool"
7 participants