Skip to content

Fix value_specs implementation#2886

Merged
pierreprinetti merged 1 commit intogophercloud:masterfrom
Nordix:lentzi90/fix-value-specs
Feb 6, 2024
Merged

Fix value_specs implementation#2886
pierreprinetti merged 1 commit intogophercloud:masterfrom
Nordix:lentzi90/fix-value-specs

Conversation

@lentzi90
Copy link
Copy Markdown
Contributor

@lentzi90 lentzi90 commented Feb 2, 2024

The current implementation does not do anything useful. The key-pairs must be extracted and added directly in the body instead of under "value_specs".

This commit fixes the implementation and also adds validation of the value_specs based on what is done in Heat. There are some banned keys that are not allowed in value_specs, and values are not allowed to overwrite existing fields either.

Fixes #2870

@github-actions github-actions bot added the semver:major Breaking change label Feb 2, 2024
@lentzi90 lentzi90 force-pushed the lentzi90/fix-value-specs branch from 17f6dc9 to 23b3306 Compare February 2, 2024 12:55
@github-actions github-actions bot added semver:major Breaking change and removed semver:major Breaking change labels Feb 2, 2024
Comment on lines +151 to +160
if port["value_specs"] != nil {
for k, v := range port["value_specs"].(map[string]interface{}) {
if slices.Contains(bannedKeys, k) {
return nil, errors.New(fmt.Sprintf("forbidden key in value_specs: %s", k))
}
if _, ok := port[k]; ok {
return nil, errors.New(fmt.Sprintf("value_specs would overwrite key: %s", k))
}
port[k] = v
}
delete(port, "value_specs")
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 totally don't like the concept behind this and introducing Heat's mistakes into our API - Heat shouldn't be a standard we're following.

Despite of that - this code does it in an acceptable way, i.e. applications won't break when putting foo in value_specs and in new version foo is available directly.

@coveralls
Copy link
Copy Markdown

coveralls commented Feb 2, 2024

Coverage Status

coverage: 77.882% (+0.01%) from 77.871%
when pulling 63e3079 on Nordix:lentzi90/fix-value-specs
into 9f29754 on gophercloud:master.

@lentzi90 lentzi90 force-pushed the lentzi90/fix-value-specs branch from 23b3306 to 091f8e0 Compare February 2, 2024 13:26
@github-actions github-actions bot added semver:major Breaking change and removed semver:major Breaking change labels Feb 2, 2024
@pierreprinetti
Copy link
Copy Markdown
Member

Did we ever return anything in the ValueSpecs field of ports.Port?

@EmilienM
Copy link
Copy Markdown
Contributor

EmilienM commented Feb 2, 2024

@lentzi90 doesn't Heat remove value_specs from the body before sending to neutron? shouldn't we do the same?
openstack/heat@d4b6f37

@lentzi90
Copy link
Copy Markdown
Contributor Author

lentzi90 commented Feb 5, 2024

@lentzi90 doesn't Heat remove value_specs from the body before sending to neutron? shouldn't we do the same? openstack/heat@d4b6f37

Yes! I hope it is what I'm doing with

delete(port, "value_specs")

So first we take all keys under value_specs, check if they are banned, check if they would overwrite an existing field, if not we add them to the body and finally remove the value_specs field.

@lentzi90
Copy link
Copy Markdown
Contributor Author

lentzi90 commented Feb 5, 2024

Did we ever return anything in the ValueSpecs field of ports.Port?

I don't think so

@lentzi90
Copy link
Copy Markdown
Contributor Author

lentzi90 commented Feb 5, 2024

Any way to re-trigger that one failed test besides pushing again?
Everything passed already before I changed errors.New -> fmt.Errorf, which is trivial, so it is probably a flake...

@pierreprinetti
Copy link
Copy Markdown
Member

I have manually retriggered the run

Copy link
Copy Markdown
Contributor

@EmilienM EmilienM left a comment

Choose a reason for hiding this comment

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

Minor change is required before we can merge, I think today.

@lentzi90 lentzi90 force-pushed the lentzi90/fix-value-specs branch from 091f8e0 to 8374114 Compare February 5, 2024 13:55
@github-actions github-actions bot added semver:major Breaking change and removed semver:major Breaking change labels Feb 5, 2024
@lentzi90 lentzi90 force-pushed the lentzi90/fix-value-specs branch from 8374114 to 8df0181 Compare February 5, 2024 13:58
@github-actions github-actions bot added semver:major Breaking change and removed semver:major Breaking change labels Feb 5, 2024
@lentzi90 lentzi90 force-pushed the lentzi90/fix-value-specs branch from 8df0181 to 3f3e49d Compare February 5, 2024 14:02
@lentzi90
Copy link
Copy Markdown
Contributor Author

lentzi90 commented Feb 5, 2024

Thanks for the swift reviews! I think it should be in good order now 🙂

@github-actions github-actions bot added semver:major Breaking change and removed semver:major Breaking change labels Feb 5, 2024
@EmilienM
Copy link
Copy Markdown
Contributor

EmilienM commented Feb 5, 2024

unit test job is broken but it's not your PR

@EmilienM
Copy link
Copy Markdown
Contributor

EmilienM commented Feb 5, 2024

LGTM for me. I'll let a chance to other reviewers to have another look as well (cc @pierreprinetti).

@EmilienM
Copy link
Copy Markdown
Contributor

EmilienM commented Feb 5, 2024

might need a rebase in fact

The current implementation does not do anything useful. The key-pairs
must be extracted and added directly in the body instead of under
"value_specs".
This commit fixes the implementation and also adds validation of the
value_specs based on what is done in Heat. There are some banned keys
that are not allowed in value_specs, and values are not allowed to
overwrite existing fields either.

Signed-off-by: Lennart Jern <lennart.jern@est.tech>
@lentzi90 lentzi90 force-pushed the lentzi90/fix-value-specs branch from 3f3e49d to 63e3079 Compare February 6, 2024 06:11
@github-actions github-actions bot added semver:major Breaking change and removed semver:major Breaking change labels Feb 6, 2024
@EmilienM
Copy link
Copy Markdown
Contributor

EmilienM commented Feb 6, 2024

I approve this change, I just want to see @dulek, @pierreprinetti and @mdbooth ack'ing it too.
Thanks

Copy link
Copy Markdown
Contributor

@dulek dulek left a comment

Choose a reason for hiding this comment

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

Looks okay from my perspective.

// from the request body. It will return error if the value specs would overwrite
// an existing field or contains forbidden keys.
func AddValueSpecs(body map[string]interface{}) (map[string]interface{}, error) {
// Banned the same as in heat. See https://github.com/openstack/heat/blob/dd7319e373b88812cb18897f742b5196a07227ea/heat/engine/resources/openstack/neutron/neutron.py#L59
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.

Would probably be better to link to opendev.org instead of GitHub mirrors, no big deal.

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.

Ah my bad 🤦
Just say the word and I'll update...

@pierreprinetti pierreprinetti merged commit f17fe29 into gophercloud:master Feb 6, 2024
@lentzi90 lentzi90 deleted the lentzi90/fix-value-specs branch February 6, 2024 14:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

semver:major Breaking change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ValueSpecs in port CreateOpts is a no-op

5 participants