Skip to content

Manila: add support for share metadata modification#1656

Merged
jtopjian merged 8 commits intogophercloud:masterfrom
gman0:manila-share-metadata
Aug 1, 2019
Merged

Manila: add support for share metadata modification#1656
jtopjian merged 8 commits intogophercloud:masterfrom
gman0:manila-share-metadata

Conversation

@gman0
Copy link
Copy Markdown
Contributor

@gman0 gman0 commented Jul 26, 2019

@gman0 gman0 force-pushed the manila-share-metadata branch from 2c78f01 to 78507b9 Compare July 26, 2019 16:09
@coveralls
Copy link
Copy Markdown

coveralls commented Jul 26, 2019

Coverage Status

Coverage decreased (-0.08%) to 76.827% when pulling 6e7a961 on gman0:manila-share-metadata into 73bf16e on gophercloud:master.

@theopenlab-ci
Copy link
Copy Markdown

theopenlab-ci bot commented Jul 26, 2019

Build failed.

@gman0
Copy link
Copy Markdown
Contributor Author

gman0 commented Jul 26, 2019

/test gophercloud-acceptance-test

@gman0
Copy link
Copy Markdown
Contributor Author

gman0 commented Jul 26, 2019

PTAL @jtopjian @gouthampacha

@jtopjian
Copy link
Copy Markdown
Contributor

recheck

@theopenlab-ci
Copy link
Copy Markdown

theopenlab-ci bot commented Jul 26, 2019

Build failed.

Copy link
Copy Markdown
Contributor

@jtopjian jtopjian left a comment

Choose a reason for hiding this comment

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

@gman0 Looks good - just some suggestions for two of the functions.

I think the OpenLab error can be ignored for now. I don't see how this PR would affect the test that is failing.

Please let me know if you have any questions.


// ShowMetadata retrieves metadata of the specified share. To extract the retrieved
// metadata from the response, call the Extract method on the ShowMetadataResult.
func ShowMetadata(client *gophercloud.ServiceClient, id string) (r ShowMetadataResult) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It looks like the Manila code has support to retrieve a single metadata/metadatum: https://github.com/openstack/manila/blob/cec13b8057fa025fa1b1c3bef180687a394d6fd6/manila/api/v1/share_metadata.py#L121

To prevent confusion, let's change this to either Metadata or GetMetadata. Both have been used in Gophercloud before.

Copy link
Copy Markdown

@gouthampacha gouthampacha Jul 26, 2019

Choose a reason for hiding this comment

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

+1 GetMetadata corresponds to this project's idioms...

A GetMetadatum call may be useful too, thanks for pointing that out @jtopjian.. It'll make things faster if you're trying to verify if some metadata key exists, or set to a particular value.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If that API call is exposed, I agree. The API documentation doesn't have it listed, but that might just mean it's undocumented :)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Yep! fixing the docs here: https://review.opendev.org/#/c/673112/

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

refactored ShowMetadata into GetMetadata: da281ed

added GetMetadatum: 66bd2c0

}

// UnsetMetadata deletes a single key-value pair from the metadata of the specified share.
func UnsetMetadata(client *gophercloud.ServiceClient, id, key string) (r UnsetMetadataResult) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Because this API call is only for a single piece of metadata/metadatum, let's change this to either UnsetMetadatum or DeleteMetadatum. "Metadatum" is used throughout Gophercloud to denote a single piece of metadata.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I went for DeleteMetadatum: 6a073de

Copy link
Copy Markdown

@gouthampacha gouthampacha left a comment

Choose a reason for hiding this comment

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

This looks great, just a small comment inline... Thanks for working on this @gman0!

}

// SetMetadata sets metadata of the specified share. To extract the updated
// metadata from the response, call the Extract method on the SetMetadataResult.
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Worth calling out the difference between SetMetadata and UpdateMetadata, as a comment for future maintainers:

SetMetadata allows adding new metadata items or updating values of existing metadata items; however, UpdateMetadata will drop existing metadata and replace it with new metadata key=value pairs as specified.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done in 5c226fe

@gman0
Copy link
Copy Markdown
Contributor Author

gman0 commented Jul 27, 2019

@jtopjian @gouthampacha thank you guys for the feedback and guidance!! All your comments are addressed in separate commits, I can squash them later if needed once the review is finished.

@theopenlab-ci
Copy link
Copy Markdown

theopenlab-ci bot commented Jul 27, 2019

Build failed.

@jtopjian
Copy link
Copy Markdown
Contributor

recheck

@theopenlab-ci
Copy link
Copy Markdown

theopenlab-ci bot commented Jul 29, 2019

Build succeeded.

Copy link
Copy Markdown

@gouthampacha gouthampacha left a comment

Choose a reason for hiding this comment

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

Awesome, ty!

Copy link
Copy Markdown
Contributor

@jtopjian jtopjian left a comment

Choose a reason for hiding this comment

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

@gman0 This is looking good. I left a comment about changing the GetMetadatum result and then refactoring 4/5 of the functions as a result (no pun intended) of the change.

Let me know if you have any questions. Also let me know if these suggestions are incorrect and break things - I don't have easy access to a Manila environment so I can't test these out first-hand.

// GetMetadatumResult contains the response body and error from a GetMetadatum request.
type GetMetadatumResult struct {
gophercloud.Result
key string
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I understand the purpose of this, but let's use the style that has been previously used here: https://github.com/gophercloud/gophercloud/blob/master/openstack/compute/v2/servers/results.go#L346-L352

This returns a map[string]string so the user/dev can do:

result, err := shares.GetMetadatum(c, shareID, "foo").Extract()
fmt.Println(result["foo"])

Once it's updated like this, it looks like GetMetadata, GetMetadatum, SetMetadata, and UpdateMetadata can all share a single result type:

type MetadataResult struct {
  gophercloud.Result
}

func (r MetadataResult) Extract() (map[string]string, error) {
 ...
}

Let me know if this makes sense or if you have any questions.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Actually GetMetadatum would still need a separate result type because it uses meta parent in its JSON response instead of metadata like the other methods use (see example responses for show-metadata VS show-metadata-item). I'll merge the result types for the rest of the methods.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Should GetMetadatumResult then still return map[string]string like you're suggesting, or rather keep things as they are in this PR and return string? I'm totally fine with either, especially if it's to keep things consistent...although the latter seems a bit more user-friendly by not having to repeat the metadata key.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actually GetMetadatum would still need a separate result type because it uses meta parent in its JSON response instead of metadata like the other methods use

Good catch.

Should GetMetadatumResult then still return map[string]string like you're suggesting,

Yes, please.

I agree that it can be more intuitive to have only the value returned, but using this method keeps things consistent with other metadata areas in Gophercloud. In addition, it more closely models the API response (since the API response is a dict/object/hash).

@theopenlab-ci
Copy link
Copy Markdown

theopenlab-ci bot commented Jul 31, 2019

Build succeeded.

@gman0
Copy link
Copy Markdown
Contributor Author

gman0 commented Jul 31, 2019

PTAL @jtopjian

Copy link
Copy Markdown
Contributor

@jtopjian jtopjian left a comment

Choose a reason for hiding this comment

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

LGTM - thank you for your patience with this!

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.

4 participants