Skip to content

Commit

Permalink
[ignore] add legacy testvars with dependecies for all legacy attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
akinross committed Jan 30, 2025
1 parent c0cd67d commit aa081eb
Show file tree
Hide file tree
Showing 13 changed files with 365 additions and 88 deletions.
38 changes: 29 additions & 9 deletions gen/definitions/properties.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,8 @@ fvRsCons:
parent_dependency: "fvAp"
targets:
- class_name: "vzBrCP"
shared_classes:
- "fvRsProv"
parent_dependency: "fvTenant"
overwrite_parent_dn_key: "tenant_dn"
target_dn: "uni/tn-test_tenant/brc-contract_name_0"
Expand All @@ -515,6 +517,7 @@ fvRsProv:
parent_dependency: "fvAp"
- class_name: "fvAEPg"
parent_dependency: "fvAp"


fvRsConsIf:
ignore_custom_type_docs:
Expand Down Expand Up @@ -601,17 +604,17 @@ fvRsSecInherited:
- class_name: "fvAEPg"
parent_dependency: "fvAp"
overwrite_parent_dn_key: "application_profile_dn"
target_dn: "uni/tn-test_tenant/ap-test_ap/epg-epg_2"
target_dn: "uni/tn-test_tenant/ap-test_ap/epg-epg_0"
relation_resource_name: "contract_master"
properties:
name: "epg_2"
name: "epg_0"
- class_name: "fvAEPg"
parent_dependency: "fvAp"
overwrite_parent_dn_key: "application_profile_dn"
target_dn: "uni/tn-test_tenant/ap-test_ap/epg-epg_3"
target_dn: "uni/tn-test_tenant/ap-test_ap/epg-epg_1"
relation_resource_name: "contract_master"
properties:
name: "epg_3"
name: "epg_1"

fvCrtrn:
overwrites:
Expand Down Expand Up @@ -858,9 +861,19 @@ fvRsDppPol:
name: "data_plane_policing_policy_name_1"

fvRsBd:
test_values:
all:
bridge_domain_name: "default"
targets:
- class_name: "fvBD"
parent_dependency: "fvTenant"
target_dn: "uni/tn-test_tenant/BD-bridge_domain_name_1"
relation_resource_name: "bridge_domain_name"
properties:
name: "bridge_domain_name_1"
- class_name: "fvBD"
parent_dependency: "fvTenant"
target_dn: "uni/tn-test_tenant/BD-bridge_domain_name_0"
relation_resource_name: "bridge_domain_name"
properties:
name: "bridge_domain_name_0"

fvRsFcPathAtt:
default_values:
Expand Down Expand Up @@ -1625,6 +1638,13 @@ fvRsBDToNetflowMonitorPol:
- class_name: "fvBD"
parent_dependency: "fvTenant"
parent_dn: "aci_bridge_domain.test.id"
targets:
- class_name: "netflowMonitorPol"
parent_dependency: "fvTenant"
target_dn: "uni/tn-test_tenant/monitorpol-netflow_monitor_policy_name_1"
relation_resource_name: "netflow_monitor_policy_name"
properties:
name: "netflow_monitor_policy_name_1"

fvRsBDToOut:
overwrites:
Expand Down Expand Up @@ -1652,15 +1672,15 @@ fvRsBDToProfile:
relation_resource_name: "l3_outside"
properties:
name: "l3_outside_name_1"
relation_l3ext_rs_ectx: aci_vrf.test_vrf_1.id
relation_l3ext_rs_ectx: aci_vrf.test_vrf_0.id
- class_name: "l3extOut"
parent_dependency: "fvTenant"
overwrite_parent_dn_key: "tenant_dn"
target_dn: "uni/tn-test_tenant/out-abr_l3_outside_name_0"
relation_resource_name: "l3_outside"
properties:
name: "l3_outside_name_0"
relation_l3ext_rs_ectx: aci_vrf.test_vrf_1.id
relation_l3ext_rs_ectx: aci_vrf.test_vrf_0.id
- class_name: "rtctrlProfile"
parent_dependency: "l3extOut"
target_dn: "uni/tn-test_tenant/out-abr_l3_outside_name_0/prof-route_control_profile_name_1"
Expand Down
87 changes: 84 additions & 3 deletions gen/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,80 @@ var templateFuncs = template.FuncMap{
"excludeForNullInSetCheck": ExcludeForNullInSetCheck,
"getTestTargetValue": GetTestTargetValue,
"isReference": IsReference,
"getLegacyPropertyTestValue": GetTestValue,
"getLegacyBlockTestValue": GetBlockTestValue,
}

func getChildTarget(model Model, childKey, childValue string, tDn bool) string {
for index, childDependency := range model.ChildTestDependencies {
targetResourceName := childDependency.TargetResourceName
if !tDn {
if childKey == fmt.Sprintf("%s_name", targetResourceName) {
childKey = "name"
}
if result, ok := childDependency.Properties[childKey]; ok && childValue == result {
return fmt.Sprintf(`aci_%s.test_%s_%d.id`, targetResourceName, targetResourceName, index%2)
}
} else {
if childDependency.Source == childKey || DefinedInList(childDependency.SharedClasses, childKey) {
if !childDependency.Static {
return fmt.Sprintf(`aci_%s.test_%s_%d.id`, targetResourceName, targetResourceName, index%2)
} else {
return childDependency.TargetDn
}
}
}
}
return childValue
}

func GetBlockTestValue(className, attributeName string, model Model) string {
for _, child := range model.Children {
if child.PkgName == className {
if attributeName == "TargetDn" {
return getChildTarget(model, className, "target_dn_2", true)
}
for _, property := range child.Properties {
if property.Name == attributeName {
if len(property.ValidValues) > 0 {
return property.ValidValues[0]
} else if property.PropertyName == "tDn" {
return getChildTarget(model, className, "target_dn_1", true)
}
childKey := GetOverwriteAttributeName(child.PkgName, property.SnakeCaseName, model.Definitions)
childValue := fmt.Sprintf("%s_1", childKey)
return getChildTarget(model, childKey, childValue, false)
}
}
}
}
return attributeName
}

func GetTestValue(name string, model Model) string {

for _, property := range model.Properties {
if property.Name == name {
if len(property.ValidValues) > 0 {
return property.ValidValues[0]
}
return fmt.Sprintf("test_%s", property.SnakeCaseName)
}
}
for _, child := range model.Children {
if Capitalize(child.PkgName) == name {
for _, property := range child.Properties {
if strings.HasSuffix(property.PropertyName, "Name") {
childKey := GetOverwriteAttributeName(child.PkgName, property.SnakeCaseName, model.Definitions)
childValue := fmt.Sprintf("%s_1", childKey)
return getChildTarget(model, childKey, childValue, false)
} else if property.PropertyName == "tDn" {
return getChildTarget(model, child.PkgName, "target_dn_0", true) // getTestTargetDn
}
}
}
}
return name
}

func GetTestTargetValue(targets []interface{}, key, value string) string {
Expand Down Expand Up @@ -1281,6 +1355,8 @@ type TypeChange struct {
}

type TestDependency struct {
Source string
SharedClasses interface{}
ClassName string
ParentDependency string
ParentDependencyDnRef string
Expand Down Expand Up @@ -2727,7 +2803,7 @@ func (m *Model) SetModelTestDependencies(classModels map[string]Model, definitio
for index, v := range value.([]interface{}) {
targetMap := v.(map[interface{}]interface{})
if className, ok := targetMap["class_name"]; ok {
testDependencies = append(testDependencies, getTestDependency(className.(string), targetMap, definitions, index))
testDependencies = append(testDependencies, getTestDependency(m.PkgName, className.(string), targetMap, definitions, index))
}
}
}
Expand All @@ -2742,7 +2818,7 @@ func (m *Model) SetModelTestDependencies(classModels map[string]Model, definitio
for index, v := range value.([]interface{}) {
targetMap := v.(map[interface{}]interface{})
if className, ok := targetMap["class_name"]; ok && !slices.Contains(m.getExcludeTargets(), className.(string)) {
childTestDependencies = append(childTestDependencies, getTestDependency(className.(string), targetMap, definitions, index))
childTestDependencies = append(childTestDependencies, getTestDependency(child, className.(string), targetMap, definitions, index))
}
}
}
Expand All @@ -2769,9 +2845,10 @@ func (m *Model) getExcludeTargets() []string {
return excludeTargets
}

func getTestDependency(className string, targetMap map[interface{}]interface{}, definitions Definitions, index int) TestDependency {
func getTestDependency(sourceClassName, className string, targetMap map[interface{}]interface{}, definitions Definitions, index int) TestDependency {

testDependency := TestDependency{}
testDependency.Source = sourceClassName
testDependency.ClassName = className
testDependency.TargetResourceName = GetResourceName(className, definitions)
testDependency.RelationResourceName = testDependency.TargetResourceName
Expand All @@ -2781,6 +2858,10 @@ func getTestDependency(className string, targetMap map[interface{}]interface{},
testDependency.RelationResourceName = relationResourceName.(string)
}

if sharedClasses, ok := targetMap["shared_classes"]; ok {
testDependency.SharedClasses = sharedClasses
}

if parentDependency, ok := targetMap["parent_dependency"]; ok {
testDependency.ParentDependency = parentDependency.(string)
if parentDependencyDn, ok := targetMap["parent_dependency_dn_ref"]; ok {
Expand Down
28 changes: 28 additions & 0 deletions gen/templates/testvars.yaml.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,34 @@
# In order to regenerate this file execute `go generate` from the repository root.
# More details can be found in the [README](https://github.com/CiscoDevNet/terraform-provider-aci/blob/master/README.md).

{{- if .LegacyAttributes}}
legacy_attributes:
{{- range .LegacyAttributes}}
{{- if ne .ReplacedBy.AttributeName "" }}
{{- if eq (getMigrationType .ValueType) "String"}}
{{.AttributeName}}: "{{getLegacyPropertyTestValue .Name $}}"
{{- else if eq (getMigrationType .ValueType) "Set"}}
{{.AttributeName}}: "{{getLegacyPropertyTestValue .Name $}}"
{{- end}}
{{- end}}
{{- end }}
{{- end}}
{{- if .LegacyBlocks}}
legacy_blocks:
{{- range .LegacyBlocks}}{{$ClassName := .ClassName}}
{{.Name }}:
{{- range .Attributes}}
{{- if ne .ReplacedBy.AttributeName "" }}
{{- if eq (getMigrationType .ValueType) "String"}}
{{.AttributeName}}: "{{getLegacyBlockTestValue $ClassName .Name $}}"
{{- else if eq (getMigrationType .ValueType) "Set"}}
{{.AttributeName}}: "{{getLegacyBlockTestValue $ClassName .Name $}}"
{{- end}}
{{- end}}
{{- end }}
{{- end}}
{{ end}}

{{ $versionMismatch := .VersionMismatched}}
default:
{{- $versionMismatchExists := false}}
Expand Down
64 changes: 59 additions & 5 deletions gen/testvars/fvAEPg.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,38 @@
# Code generated by "gen/generator.go"; DO NOT EDIT.
# In order to regenerate this file execute `go generate` from the repository root.
# More details can be found in the [README](https://github.com/CiscoDevNet/terraform-provider-aci/blob/master/README.md).
legacy_attributes:
exception_tag: "test_exception_tag"
flood_on_encap: "disabled"
fwd_ctrl: "none"
has_mcast_source: "no"
is_attr_based_epg: "no"
match_t: "All"
application_profile_dn: "ParentDn"
pc_enf_pref: "enforced"
pref_gr_memb: "exclude"
prio: "level1"
shutdown: "no"
relation_fv_rs_aepg_mon_pol: "aci_monitoring_policy.test_monitoring_policy_0.id"
relation_fv_rs_bd: "aci_bridge_domain.test_bridge_domain_1.id"
relation_fv_rs_cons: "aci_contract.test_contract_0.id"
relation_fv_rs_sec_inherited: "aci_application_epg.test_application_epg_0.id"
relation_fv_rs_cust_qos_pol: "custom_qos_policy_name_1"
relation_fv_rs_dpp_pol: "aci_data_plane_policing_policy.test_data_plane_policing_policy_1.id"
relation_fv_rs_fc_path_att: "topology/pod-1/paths-101/pathep-[eth1/1]"
relation_fv_rs_cons_if: "aci_imported_contract.test_imported_contract_0.id"
relation_fv_rs_intra_epg: "aci_contract.test_contract_0.id"
relation_fv_rs_prov: "aci_contract.test_contract_0.id"
relation_fv_rs_prot_by: "aci_taboo_contract.test_taboo_contract_1.id"
relation_fv_rs_trust_ctrl: "aci_trust_control_policy.test_trust_control_policy_0.id"
legacy_blocks:
relation_fv_rs_node_att:
deployment_immediacy: "immediate"
description: "description_1"
encap: "encapsulation_1"
mode: "native"
node_dn: "topology/pod-1/node-101"



default:
Expand Down Expand Up @@ -104,7 +136,7 @@ children:

relation_to_bridge_domain:
- annotation: "annotation_1"
bridge_domain_name: "default"
bridge_domain_name: "bridge_domain_name_1"
deletable_child: false

children:
Expand Down Expand Up @@ -660,6 +692,28 @@ child_targets:
parent_dn_key: "tenant_dn"
properties:
name: "monitoring_policy_name_1"
- class_name: "fvBD"
target_dn: "uni/tn-test_tenant/BD-bridge_domain_name_1"
relation_resource_name: "bridge_domain_name"
static: false
target_dn_ref: "aci_bridge_domain.test_bridge_domain_0.id"
parent_dependency: "fvTenant"
parent_dependency_dn_ref: "aci_tenant.test.id"
target_resource_name: "bridge_domain"
parent_dn_key: "parent_dn"
properties:
name: "bridge_domain_name_1"
- class_name: "fvBD"
target_dn: "uni/tn-test_tenant/BD-bridge_domain_name_0"
relation_resource_name: "bridge_domain_name"
static: false
target_dn_ref: "aci_bridge_domain.test_bridge_domain_1.id"
parent_dependency: "fvTenant"
parent_dependency_dn_ref: "aci_tenant.test.id"
target_resource_name: "bridge_domain"
parent_dn_key: "parent_dn"
properties:
name: "bridge_domain_name_0"
- class_name: "vzBrCP"
target_dn: "uni/tn-test_tenant/brc-contract_name_0"
relation_resource_name: "contract"
Expand Down Expand Up @@ -770,7 +824,7 @@ child_targets:
properties:
name: "taboo_contract_name_1"
- class_name: "fvAEPg"
target_dn: "uni/tn-test_tenant/ap-test_ap/epg-epg_2"
target_dn: "uni/tn-test_tenant/ap-test_ap/epg-epg_0"
relation_resource_name: "contract_master"
static: false
target_dn_ref: "aci_application_epg.test_application_epg_0.id"
Expand All @@ -779,9 +833,9 @@ child_targets:
target_resource_name: "application_epg"
parent_dn_key: "application_profile_dn"
properties:
name: "epg_2"
name: "epg_0"
- class_name: "fvAEPg"
target_dn: "uni/tn-test_tenant/ap-test_ap/epg-epg_3"
target_dn: "uni/tn-test_tenant/ap-test_ap/epg-epg_1"
relation_resource_name: "contract_master"
static: false
target_dn_ref: "aci_application_epg.test_application_epg_1.id"
Expand All @@ -790,7 +844,7 @@ child_targets:
target_resource_name: "application_epg"
parent_dn_key: "application_profile_dn"
properties:
name: "epg_3"
name: "epg_1"
- class_name: "fhsTrustCtrlPol"
target_dn: "uni/tn-test_tenant/trustctrlpol-trust_control_policy_name_1"
relation_resource_name: "trust_control_policy"
Expand Down
Loading

0 comments on commit aa081eb

Please sign in to comment.