Baremetal Inspector Client Node Introspection#1486
Baremetal Inspector Client Node Introspection#1486jtopjian merged 1 commit intogophercloud:masterfrom
Conversation
|
Build succeeded.
|
200eaf0 to
b8a1a6d
Compare
|
Build succeeded.
|
8639b80 to
4709d12
Compare
|
Build succeeded.
|
4709d12 to
5097e3c
Compare
|
Build succeeded.
|
3ba01a3 to
d752168
Compare
|
Build succeeded.
|
d752168 to
888d5a9
Compare
|
Build succeeded.
|
8f0daef to
67b2d94
Compare
|
Build succeeded.
|
8f08ec9 to
94cd700
Compare
|
Build succeeded.
|
|
@elfosardo Try removing all occurrences of fields that are set to |
94cd700 to
6ffaa15
Compare
|
Build succeeded.
|
|
@jtopjian I tried removing the occurrences but it was giving an error as it was expecting them with a value of I think adding fixtures.go to the ignore list is reasonable at this point considering that the format is actually correct and it's just a problem between go versions. |
7855b16 to
5fb7d9b
Compare
jtopjian
left a comment
There was a problem hiding this comment.
@elfosardo This is looking good - thank you for the time you've put in.
I've added some comments with some links to help with additional structs. I could be wrong with them, though. Please let me know if you have any questions.
openstack/baremetalinspector/v1/introspection/testing/fixtures.go
Outdated
Show resolved
Hide resolved
openstack/baremetalinspector/v1/introspection/testing/fixtures.go
Outdated
Show resolved
Hide resolved
|
@juliakreger @elfosardo Attempting to clarify my comments a little more: First, I fully understand if I'm coming off as being overly picky with an addition of OCD. Can the entire result be combined into a generic If Ironic Inspector doesn't actually have an official API response definition, okay... but that makes API guarantees difficult, not to mention actually using the result in production. If we were to use a generic if v, ok := result["macs"]; ok {
if v, ok := v.([]interface{}); ok {
for _, i := range v {
if mac, ok := i.(string); ok {
fmt.Println(mac)
}
}
}
}Instead of: for _, mac := range result.MACs {
fmt.Println(mac)
}Based on the above, you can see how digging into a more nested piece of data such as This is why I place so much emphasis on data modeling. Second, since I don't have access to an Ironic/Inspector environment, I can only go off of what the fixtures are telling me. Looking at the timestamps of the fixtures, I can tell that the fixtures bundled in this PR were not generated recently in a devstack or prod environment. They were pulled from here:
This means that I must trust that the fixtures are accurate and weren't amended for convenience of writing a quick unit test. This sounds trivial, but incorrect fixtures have occurred before. Go is the kind of language that is going to quickly let you know when a mocked fixture is not the same as what it sees in reality. The fixtures are telling me that well-formed data structures are being returned. This is because of the amount of The latest commit has done a very good job at modeling the API response into a series of well-defined structures. The additional comments I gave are an attempt to model the remaining generic I apologize if I'm coming across as picking on this PR -- that is not my intention at all. This PR has the |
| // and plugins enabled both in the ramdisk and in inspector itself. | ||
| // This structure has been provided for basic compatibility but it | ||
| // will need extensions | ||
| type Data struct { |
There was a problem hiding this comment.
I hope these fields are all optional, because we don't have any guarantees about it. Actually, maybe we should leave only inventory since it's the only thing that has a defined (in IPA) format.
There was a problem hiding this comment.
Please see my other comments in this area. I'm hesitant to have Data as one large map[string]interface{} for reasons mentioned. I'm a bit surprised if this API has no guaranteed / defined structure at all.
However, as I've also stated, I have no knowledge of any of these APIs, so I'm leaning on other peoples' expertise. If it's best to have generic map[string]interfaces{} in certain areas, okay. But using the results is going to be a headache.
Also, if a JSON response does not contain a field that a struct is expecting, all is fine. If a JSON response contains extra fields that the struct does not account for, all is fine.
There was a problem hiding this comment.
The problem with this data is that it's a hybrid of more or less well defined inventory and whatever ironic-inspector plugins put there (which is poorly documented and often legacy). Is it possible in Go to have a hybrid approach as well? I know in serde (Rust serializatin library) you can have a defined structure with one mapping field serving as catch-all for everything that was not mapped to defined fields.
There was a problem hiding this comment.
Go doesn't have anything which natively does that (but it would be nice). We have an internal function that does it, though. We use it for things like Keystone where arbitrary extra key/values can be sent in the API response:
I've never tested it with nested things, but it should work.
If we can get a confirmed set of base/expected fields, I'm more than happy to work on options to catch the undefined/optional pieces.
| Inventory InventoryType `json:"inventory"` | ||
| Error string `json:"error"` | ||
| LocalGB int `json:"local_gb"` | ||
| AllInterfaces map[string]interface{} `json:"all_interfaces"` |
There was a problem hiding this comment.
Speaking of poorly defined interfaces, the extra_hardware plugin defines the extra key, which is a 3 level nested dict: https://github.com/openstack/ironic-inspector/blob/master/ironic_inspector/plugins/extra_hardware.py#L66
There was a problem hiding this comment.
My understanding is that it will not cause any issue if it's not present in the structure.
Of course it will be interpreted and not formally defined.
5fb7d9b to
1b26cc9
Compare
|
@jtopjian @dtantsur @juliakreger I don't mind moving forward defining an even more formal definition of the data structure, or just refine what we already have. |
|
Build succeeded.
|
1b26cc9 to
f6c4085
Compare
|
Build failed.
|
jtopjian
left a comment
There was a problem hiding this comment.
@elfosardo I've done a detailed review and commented on a collection of minor things to update.
Once these are fixed and if you folks are happy with this, I'm comfortable merging it. If you want to make further changes to how the data is modeled (either to be more specific or more generic), I'll trust your judgements on this.
openstack/baremetalintrospection/v1/introspection/testing/fixtures.go
Outdated
Show resolved
Hide resolved
openstack/baremetalintrospection/v1/introspection/testing/requests_test.go
Outdated
Show resolved
Hide resolved
aab8c1f to
ec371f2
Compare
|
Build failed.
|
ec371f2 to
cb74dfa
Compare
|
@jtopjian @dtantsur @juliakreger I made some other changes to be as close as possible to the data defined in the base API code (both inspector and IPA) and modified the json data fixture as well since there were deprecated fields. |
For gophercloud#1485 This patch adds the Node Introspection API calls according to [1] Start Introspection (POST) Get Introspection status (GET) List all Introspection statuses (GET) Abort Introspection (POST) Get Introspection Data (GET) Reapply Introspection on stored data (POST) Source code reference: https://github.com/openstack/ironic-inspector/tree/master/ironic_inspector [1] https://developer.openstack.org/api-ref/baremetal-introspection/#node-introspection
cb74dfa to
9e222ec
Compare
|
Build failed.
|
jtopjian
left a comment
There was a problem hiding this comment.
LGTM. Please let me know when I should merge this or if you all would like to discuss/work on it more.
|
I'm going to merge this, but keep in mind this isn't written in stone - follow-up PRs are totally fine. |
| // and plugins enabled both in the ramdisk and in inspector itself. | ||
| // This structure has been provided for basic compatibility but it | ||
| // will need extensions | ||
| type Data struct { |
There was a problem hiding this comment.
I would repeat my recommendation to leave only Inventory here (and possibly add Extra). Everything else is not set in stone, with some items being legacy from quite ancient times. Instead, I'd provide a way for consumers to retrieve the whole data as map[string]interface and do whatever they want with it.
| HasCarrier bool `json:"has_carrier"` | ||
| IPV4Address string `json:"ipv4_address"` | ||
| IPV6Address string `json:"ipv6_address"` | ||
| Lldp map[string]interface{} `json:"lldp"` |
There was a problem hiding this comment.
Why MAC and BIOS, but Lldp?
| BIOSDevName string `json:"biosdevname"` | ||
| ClientID string `json:"client_id"` | ||
| HasCarrier bool `json:"has_carrier"` | ||
| IPV4Address string `json:"ipv4_address"` |
There was a problem hiding this comment.
I think IPv4Address feels a bit more natural.
dtantsur
left a comment
There was a problem hiding this comment.
Late to the party, but left some comments.
|
@dtantsur thanks for the comments, I will do a follow-up with some minor changes and to define better lldp as it has a defined schema |
For #1485
This patch adds the Node Introspection API calls according to [1]
Start Introspection (POST)
Get Introspection status (GET)
List all Introspection statuses (GET)
Abort Introspection (POST)
Get Introspection Data (GET)
Reapply Introspection on stored data (POST)
Source code reference:
https://github.com/openstack/ironic-inspector/tree/master/ironic_inspector
[1] https://developer.openstack.org/api-ref/baremetal-introspection/#node-introspection