-
Notifications
You must be signed in to change notification settings - Fork 37
Port: add propagationUplinkStatus field #641
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
base: main
Are you sure you want to change the base?
Changes from all commits
6901189
4d21547
f4abfe6
7112a07
87a3ecf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -86,3 +86,4 @@ spec: | |
| projectRef: port-create-full | ||
| macAddress: fa:16:3e:23:fd:d7 | ||
| hostID: devstack | ||
| propagateUplinkStatus: false | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,7 +8,7 @@ status: | |
| name: port-create-minimal | ||
| adminStateUp: true | ||
| portSecurityEnabled: true | ||
| propagateUplinkStatus: false | ||
| propagateUplinkStatus: true | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So the default is still true, contrary to what the PR description says. The value changed from
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes. Since we enabled the extension and added the custom struct with the field as a pointer, we're now able to have this value as I'll change the PR description to avoid confusion. |
||
| revisionNumber: 1 | ||
| status: DOWN | ||
| vnicType: normal | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,6 +18,7 @@ package osclients | |
|
|
||
| import ( | ||
| "context" | ||
| "encoding/json" | ||
| "fmt" | ||
| "iter" | ||
|
|
||
|
|
@@ -56,6 +57,24 @@ type PortExt struct { | |
| ports.Port | ||
| portsecurity.PortSecurityExt | ||
| portsbinding.PortsBindingExt | ||
|
|
||
| PropagateUplinkStatusPtr *bool `json:"propagate_uplink_status,omitempty"` | ||
| } | ||
|
|
||
| func (p *PortExt) UnmarshalJSON(b []byte) error { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This custom unmarshaller omits
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is something that I was in doubt about... I'm not sure, and if you can correct me if I'm wrong, I'll appreciate it, but it looks like Gophercloud uses reflection to populate the result rather than simply using a json.Unmarshal, am I wrong? https://github.com/gophercloud/gophercloud/blob/main/results.go#L70 You're right that they will always have the zero value, but maybe in the above phase, the fields are populated using reflection. I need to better understand this. Any initial thought?
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A well crafted test should give us the answer. |
||
| if err := json.Unmarshal(b, &p.Port); err != nil { | ||
| return err | ||
| } | ||
|
|
||
| var tmp struct { | ||
| PropagateUplinkStatusPtr *bool `json:"propagate_uplink_status"` | ||
| } | ||
| if err := json.Unmarshal(b, &tmp); err != nil { | ||
| return err | ||
| } | ||
|
|
||
| p.PropagateUplinkStatusPtr = tmp.PropagateUplinkStatusPtr | ||
| return nil | ||
| } | ||
|
|
||
| type NetworkClient interface { | ||
|
|
@@ -172,13 +191,30 @@ func (c networkClient) UpdateFloatingIP(ctx context.Context, id string, opts flo | |
|
|
||
| func (c networkClient) ListPort(ctx context.Context, opts ports.ListOptsBuilder) iter.Seq2[*PortExt, error] { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We shouldn't have to update ListPort I believe.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IIRC, there was a failing test, and the solution was to change the ListPort function, but I'll double-check this to confirm what exactly the error was. |
||
| extractPortExt := func(p pagination.Page) ([]PortExt, error) { | ||
| var resources []PortExt | ||
| err := ports.ExtractPortsInto(p, &resources) | ||
| bodyMap, ok := p.(ports.PortPage).Body.(map[string]interface{}) | ||
| if !ok { | ||
| return nil, fmt.Errorf("unexpected body type: %T", p.(ports.PortPage).Body) | ||
| } | ||
|
|
||
| portsData, ok := bodyMap["ports"] | ||
| if !ok { | ||
| return nil, fmt.Errorf("ports key not found in response") | ||
| } | ||
|
|
||
| // Marshal and unmarshal to trigger UnmarshalJSON | ||
| jsonData, err := json.Marshal(portsData) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| var resources []PortExt | ||
| if err := json.Unmarshal(jsonData, &resources); err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| return resources, nil | ||
| } | ||
|
|
||
| pager := ports.List(c.serviceClient, opts) | ||
| return func(yield func(*PortExt, error) bool) { | ||
| _ = pager.EachPage(ctx, yieldPage(extractPortExt, yield)) | ||
|
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We've discussed this privately already, after you brought the issue to my attention: gophercloud implements the
PropagateUplinkStatusin the responsePortstructure as aboolwhile it should really be a*boolwithomitempty, and because of this we can't reliably know the status forPropagateUplinkStatus. I suggest that until the issue if fixed in gophercloud, we make that field immutable.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's been a while and I don't remember all of the discussion. From reading the PR comments again, I believe we're past the gophercloud limitation (thanks to custom unmarshalling) but we still need to make the field immutable because dalmatien doesn't support updating the field. If that's effectively the case, we should add that as a comment so we know when we can change that behavior.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, you're absolutely right. I'll add this comment.