Skip to content

Baremetal V1 API Ports#1453

Merged
jtopjian merged 9 commits intogophercloud:masterfrom
iurygregory:ironic_port_api
Feb 26, 2019
Merged

Baremetal V1 API Ports#1453
jtopjian merged 9 commits intogophercloud:masterfrom
iurygregory:ironic_port_api

Conversation

@iurygregory
Copy link
Copy Markdown
Contributor

@iurygregory iurygregory commented Feb 16, 2019

For #1429

This PR covers the Ports API calls according to the Baremetal API reference

  • List Ports (GET)
  • Create Port (POST)
  • List Detailed Ports (GET)
  • Show Port Details (GET)
  • Update a Port (PATCH)
  • Delete Port (DELETE)

You can view the source code here

This commit add the Ports API calls according to [1]
- List Ports (GET)
- Create Port (POST)
- List Detailed Ports (GET)
- Show Port Details (GET)
- Update a Port (PATCH)
- Delete Port (DELETE)

[1] https://developer.openstack.org/api-ref/baremetal/?expanded=#ports-ports
@theopenlab-ci
Copy link
Copy Markdown

theopenlab-ci bot commented Feb 16, 2019

Build failed.

Copy link
Copy Markdown
Contributor

@dtantsur dtantsur left a comment

Choose a reason for hiding this comment

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

A few comments inline, but nothing stands out as blocking.

// Example to Create a Port
createPort, err := ports.Create(client, ports.CreateOpts{
NodeUUID: "e8920409-e07e-41bb-8cc1-72acb103e2dd",
Address: "00-1B-63-84-45-E6",
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 think ironic accepts addresses only separated by colon. I may be wrong though, needs double-checking.

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.

yeah I will update

Node string `q:"node"`

// Filter the list by the Node uuid
NodeUUID string `q:"node_uuid"`
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.

This is unfortunate, node_uuid is so ancient (API 1.6, Liberty era?), I'd love to avoid it. I wonder if we can default to microversion 1.6 and get rid of this..

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.

Is it not supported on 1.6 or later? It's still listed in the most current API docs

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.

Well, was in the documentation .-.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I think Dmitry might be thinking of /v1/nodes/$uuid/ports/, although that is not how the API is documented.. and I think we should conform to how the API is documented.

Links []string `json:"links"`

// Indicates whether the Port is a Smart NIC port.
IsSmartnic bool `json:"is_smartnic"`
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 wonder if it should be IsSmartNIC, depending on the Go rules.

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.

IsSmartNIC looks best to me

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.

Tks I will update!

Copy link
Copy Markdown
Contributor

@stbenjam stbenjam left a comment

Choose a reason for hiding this comment

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

To me this looks pretty good, a couple comments below

// List request.
type ListOptsBuilder interface {
ToPortListQuery() (string, error)
ToPortListDetailQuery() (string, error)
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.

Indentation is off here and elsewhere, I would run gofmt on all your files. go is rather opinionated, there's "one" way to format the code, I use this in vim: https://github.com/stbenjam/dotfiles/blob/master/vimrc#L73. GoLand IDE also does it. There's git hooks out there too to run the CLI before commit.

Node string `q:"node"`

// Filter the list by the Node uuid
NodeUUID string `q:"node_uuid"`
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.

Is it not supported on 1.6 or later? It's still listed in the most current API docs

@stbenjam
Copy link
Copy Markdown
Contributor

@iurygregory Also can you update the description, so it references #1429 without the brackets so GitHub makes the link automagically?

@iurygregory
Copy link
Copy Markdown
Contributor Author

@stbenjam going to update

- Fix Address in doc
- Renamed IsSmartnic to IsSmartNIC
- Fixed Indentation using go fmt
- Fixed acceptance test
- Fix acceptance for noauth and v1 to use correct field
- Fix undefined field for Port in requests_test
@theopenlab-ci
Copy link
Copy Markdown

theopenlab-ci bot commented Feb 19, 2019

Build failed.

})
}

// HandlePortListSuccessfully sets up the test server to respond to a server List request.
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.

nit: should change comment based on the actual function HandlePortListDetailSuccessfully

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.

Tks Riccardo

-Fixed acceptance tests (validated using DevStack - Stein on Ubuntu)
-Fixed unnit tests
-Fixed Links variable type
- Missing v1 before the functions to create fake node and delete
@coveralls
Copy link
Copy Markdown

coveralls commented Feb 20, 2019

Coverage Status

Coverage increased (+0.2%) to 76.501% when pulling 40ede77 on iurygregory:ironic_port_api into 9e57e2f on gophercloud:master.

@theopenlab-ci
Copy link
Copy Markdown

theopenlab-ci bot commented Feb 20, 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.

Hi all,

I'm not sure if this is ready for an official review yet (when ready, please leave a comment of something like "ready for review"), but figured I would look it over.

First, thank you for the collaborative effort on this. All comments and changes were relevant.

I've left two general comments, possibly requiring no actions.

As I've mentioned before, I'm not familiar with Ironic so I can't comment on the functionality, but the code itself looks good to me. I can merge this when it's ready.

Also, the acceptance test failure can be ignored - I'm in the process of fixing that now.

LocalLinkConnection map[string]interface{} `json:"local_link_connection,omitempty"`

// Indicates whether PXE is enabled or disabled on the Port.
PXEEnabled bool `json:"pxe_enabled,omitempty"`
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.

Having bool and omitempty together will never allow a value of false to be sent to the API service. This is because false is bool's zero-value and omitempty omits zero-values.

If it is acceptable for a value of false to never be sent, then this is fine as-is. But if you want the ability to send both true and false, then change this to *bool and keep omitempty.

Alternatively, use bool but remove omitempty to cause false to always be sent as default - but that's rarely the desired behavior.

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.

@jtopjian Thanks i will update.

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.

Updated PXEEnabled and IsSmartNIC

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.

Hmm, the default for pxe_enabled is true, so we must be able to send false.

type UpdateOperation struct {
Op UpdateOp `json:"op,required"`
Path string `json:"path,required"`
Value string `json:"value,omitempty"`
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.

A recent issue that was reported is: #1458

I'm not sure if this is applicable here, but wanted to mention it in case.

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 will setup a env with Python3 for Ironic and check if this will be a problem

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.

Oops - actually I just spotted two minor changes.

These changes allow the acceptance tests to only run when explicitly triggered.

@@ -0,0 +1,71 @@
package noauth
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.

There needs to be the following two lines before the package statement:

// +build acceptance baremetal ports
                                    

The newline is required.

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.

Ack

@@ -0,0 +1,70 @@
package v1
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.

Same here

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.

Ack

-Added header for acceptance tests
-Change `bool` to `*bool` to allow true and false for
PXEEnabled and IsSmartNIC
-Change UpdateOperation Value to `interface{}` to avoid problems
when not using string (e.g, booleans, jsons)
@theopenlab-ci
Copy link
Copy Markdown

theopenlab-ci bot commented Feb 25, 2019

Build failed.

@jtopjian
Copy link
Copy Markdown
Contributor

@iurygregory with the change from bool to *bool, variables will need to be updated to use a reference For example, instead of:

	port, err := ports.Create(client, ports.CreateOpts{
		NodeUUID:   node.UUID,
		Address:    mac,
		PXEEnabled: true,
	}).Extract()

It'll now need to be:

        iTrue := true
	port, err := ports.Create(client, ports.CreateOpts{
		NodeUUID:   node.UUID,
		Address:    mac,
		PXEEnabled: &iTrue,
	}).Extract()

Type `*bool` requires the pointer for a variable with `bool` value
- `itrue` is undefined, change to `iTrue` that is defined
on line 71.
@theopenlab-ci
Copy link
Copy Markdown

theopenlab-ci bot commented Feb 26, 2019

Build succeeded.

Don't set bool value directly to PXEEnabled since it's `*bool` type
@theopenlab-ci
Copy link
Copy Markdown

theopenlab-ci bot commented Feb 26, 2019

Build succeeded.

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

@jtopjian
Copy link
Copy Markdown
Contributor

@iurygregory This looks good to me. Let me know if it's ready to be merged?

@iurygregory
Copy link
Copy Markdown
Contributor Author

@jtopjian Yeah it's =)

@jtopjian jtopjian merged commit 490361a into gophercloud:master Feb 26, 2019
@iurygregory iurygregory deleted the ironic_port_api branch October 13, 2023 20:49
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.

7 participants