[bugfix] fix child classes to be queried only when apic versions allows (DCNE-589)#1407
[bugfix] fix child classes to be queried only when apic versions allows (DCNE-589)#1407akinross wants to merge 2 commits intoCiscoDevNet:masterfrom
Conversation
dc6fb13 to
a410de7
Compare
gen/templates/resource_test.go.tmpl
Outdated
| resource.TestCheckResourceAttrSet("aci_{{$.resourceName}}.test", "{{$key}}"), | ||
| {{- end}} | ||
| {{- range $key, $value := $.children}} | ||
| // foo |
b6fb1ff to
1622edf
Compare
cd1c8d8 to
0f40f27
Compare
gen/templates/provider.go.tmpl
Outdated
| } | ||
|
|
||
| func getVersionAPIC(ctx context.Context, diags *diag.Diagnostics, client *client.Client) string { | ||
| requestData := DoRestRequest(ctx, diags, client, fmt.Sprintf("/api/node/class/topSystem.json"), "GET", nil) |
There was a problem hiding this comment.
We should add a filter on the query for the role == controller to reduce size as this would query the whole set of switches which could be hundreds.
There was a problem hiding this comment.
good one, adjusted the query, which also simplifies the loop
| } | ||
|
|
||
| if requestData.Search("imdata").Search("topSystem").Data() != nil { | ||
| attributes := requestData.Search("imdata").Search("topSystem").Search("attributes").Data().([]interface{}) |
There was a problem hiding this comment.
Does this merge attributes with same value but not with different values?
There was a problem hiding this comment.
I am not sure what you mean by this comment but I did spot an issue with the version appending. The duplicates should be removed for the length check
gen/templates/provider.go.tmpl
Outdated
| ) | ||
| } else { | ||
| diags.AddError( | ||
| "Data for topSysytem class could not be retrieved", |
There was a problem hiding this comment.
| "Data for topSysytem class could not be retrieved", | |
| "Data for topSystem class could not be retrieved", |
internal/provider/versions.go
Outdated
|
|
||
| package provider | ||
|
|
||
| func classVersions() map[string]string { |
There was a problem hiding this comment.
Any reason to use function for this vs a constant?
There was a problem hiding this comment.
a constant is not possible because a map cannot be a constant in go, will leverage a package-level variable instead of a function
internal/provider/utils.go
Outdated
| @@ -17,6 +18,19 @@ import ( | |||
| "github.com/hashicorp/terraform-plugin-log/tflog" | |||
| ) | |||
|
|
|||
| func getChildClassesForGetRequest(childClasses []string) []string { | |||
| classVersions := classVersions() | |||
There was a problem hiding this comment.
I think this should be defined as a constant and not a function so we avoid re-addressing the list everytime.
There was a problem hiding this comment.
a constant is not possible because a map cannot be a constant in go, will leverage a package-level variable.
|
|
||
| func getAndSetInfraPortBlkAttributes(ctx context.Context, diags *diag.Diagnostics, client *client.Client, data *InfraPortBlkResourceModel) { | ||
| requestData := DoRestRequest(ctx, diags, client, fmt.Sprintf("api/mo/%s.json?rsp-subtree=full&rsp-subtree-class=%s", data.Id.ValueString(), "infraPortBlk,infraRsAccBndlSubgrp,tagAnnotation,tagTag,tagAnnotation,tagTag"), "GET", nil) | ||
| childClasses := getChildClassesForGetRequest([]string{"infraRsAccBndlSubgrp", "tagAnnotation", "tagTag"}) |
There was a problem hiding this comment.
infraPortBlk is the the class being requested in the resource via the DN set in data.Id.ValueString(), so not sure why this would be needed to be set in the rsp-subtree-class ?
|
|
||
| func getAndSetInfraHPortSAttributes(ctx context.Context, diags *diag.Diagnostics, client *client.Client, data *InfraHPortSResourceModel) { | ||
| requestData := DoRestRequest(ctx, diags, client, fmt.Sprintf("api/mo/%s.json?rsp-subtree=full&rsp-subtree-class=%s", data.Id.ValueString(), "infraHPortS,infraRsAccBaseGrp,tagAnnotation,tagTag,tagAnnotation,tagTag"), "GET", nil) | ||
| childClasses := getChildClassesForGetRequest([]string{"infraRsAccBaseGrp", "tagAnnotation", "tagTag"}) |
There was a problem hiding this comment.
infraHPortS is the the class being requested in the resource via the DN set in data.Id.ValueString(), so not sure why this would be needed to be set in the rsp-subtree-class ?
| @@ -1,4 +1,4 @@ | |||
| class_version: 6.0(2h)-6.0(8g),6.1(3f)- | |||
There was a problem hiding this comment.
shouldn't it be defined for both?
There was a problem hiding this comment.
This was done only for testing, the commPol class itself is supported but there was some behaviour of the class which made us skip it in those versions of testing. I did not want to change this behaviour but I needed a way to mention deprecated class like the case of fvRsBDToRelayP. So the class_version is now use for overall override of the class version when not in meta. The class_version_tests is only applied to the tests.
…of possible response by filter the topSystem request
6a21e40
No description provided.