Skip to content

Commit

Permalink
[ignore] Added the ability for the provider_test to run tests based o…
Browse files Browse the repository at this point in the history
…n a version check
  • Loading branch information
shrsr committed Jun 11, 2024
1 parent 936e2a3 commit 9f97fd7
Show file tree
Hide file tree
Showing 79 changed files with 3,043 additions and 2,706 deletions.
1 change: 1 addition & 0 deletions docs/data-sources/netflow_monitor_policy.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Data source for Netflow Monitor Policy

* Class: [netflowMonitorPol](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/netflowMonitorPol/overview)

* Supported in ACI versions: 2.2(1k) and later.

* Distinguished Name Formats:
- `uni/infra/monitorpol-{name}`
Expand Down
1 change: 1 addition & 0 deletions docs/data-sources/relation_to_netflow_exporter.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Data source for Relation To Netflow Exporter

* Class: [netflowRsMonitorToExporter](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/netflowRsMonitorToExporter/overview)

* Supported in ACI versions: 2.2(1k) and later.

* Distinguished Name Formats:
- `uni/infra/monitorpol-{name}/rsmonitorToExporter-{tnNetflowExporterPolName}`
Expand Down
1 change: 1 addition & 0 deletions docs/resources/netflow_monitor_policy.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Manages ACI Netflow Monitor Policy

* Class: [netflowMonitorPol](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/netflowMonitorPol/overview)

* Supported in ACI versions: 2.2(1k) and later.

* Distinguished Name Formats:
- `uni/infra/monitorpol-{name}`
Expand Down
1 change: 1 addition & 0 deletions docs/resources/relation_to_netflow_exporter.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Manages ACI Relation To Netflow Exporter

* Class: [netflowRsMonitorToExporter](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/netflowRsMonitorToExporter/overview)

* Supported in ACI versions: 2.2(1k) and later.

* Distinguished Name Formats:
- `uni/infra/monitorpol-{name}/rsmonitorToExporter-{tnNetflowExporterPolName}`
Expand Down
64 changes: 64 additions & 0 deletions gen/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -660,6 +660,7 @@ func main() {
model.TestType = classifyTests(model.PkgName, predecessorPaths, testCloudApic, testApic)
}
addGetTestClassificationFunc(model.TestType)
setTestApplicableFromVersion(&model)
// Only render resources and datasources when the class has a unique identifier or is marked as include in the classes definitions YAML file
if (len(model.IdentifiedBy) > 0 && !model.Exclude) || model.Include {
// All classmodels have been read, thus now the model, child and relational resources names can be set
Expand Down Expand Up @@ -806,6 +807,63 @@ func calculatePredecessors(predecessor []string, classPkgName string, classModel
return results
}

type Version struct {
Major int
Minor int
Patch int
Tag int
}

func parseVersion(rawVersion string) Version {
versionRegex := regexp.MustCompile(`(\d+)\.(\d+)\((\d+)([a-z])\)`)
matches := versionRegex.FindStringSubmatch(rawVersion)
if matches == nil {
panic("The files included in the metadata do not contain the version of APIC where the properties were first introduced. Please ensure that only the correct metadata files are included.")
}
major, _ := strconv.Atoi(matches[1])
minor, _ := strconv.Atoi(matches[2])
patch, _ := strconv.Atoi(matches[3])
tag := int(matches[4][0])

return Version{Major: major, Minor: minor, Patch: patch, Tag: tag}

}

func isVersionGreater(v1, v2 Version) bool {
if v1.Major != v2.Major {
return v1.Major > v2.Major
}
if v1.Minor != v2.Minor {
return v1.Minor > v2.Minor
}
if v1.Patch != v2.Patch {
return v1.Patch > v2.Patch
}
return v1.Tag > v2.Tag
}

func setTestApplicableFromVersion(model *Model) {
var latestVersion Version

var checkLatestVersion func(*Model)
checkLatestVersion = func(m *Model) {
for _, property := range m.Properties {
version := parseVersion(property.RawVersion)

if isVersionGreater(version, latestVersion) {
latestVersion = version
m.TestApplicableFromVersion = property.RawVersion
}
}

for _, childModel := range m.Children {
checkLatestVersion(&childModel)
}
}

checkLatestVersion(model)
}

// A Model that represents the provider
type ProviderModel struct {
Example string
Expand Down Expand Up @@ -844,6 +902,7 @@ type Model struct {
TargetResourceClassName string
TargetResourceName string
TargetDn string
TestApplicableFromVersion string
ChildClasses []string
ContainedBy []string
Contains []string
Expand Down Expand Up @@ -904,6 +963,7 @@ type Property struct {
DefaultValue string
Versions string
NamedPropertyClass string
RawVersion string
ValidValues []string
IdentifiedBy []interface{}
Validators []interface{}
Expand Down Expand Up @@ -1379,6 +1439,10 @@ func (m *Model) SetClassProperties(classDetails interface{}) {
// property.Versions = formatVersion(propertyValue.(map[string]interface{})["versions"].(string))
// }

if propertyValue.(map[string]interface{})["versions"] != nil {
property.RawVersion = strings.TrimSuffix(propertyValue.(map[string]interface{})["versions"].(string), "-")
}

properties[propertyName] = property

}
Expand Down
50 changes: 39 additions & 11 deletions gen/meta/cloudCertStore.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,11 @@
"stats": {

},
"versions": "4.1(1i)-",
"isAbstract": false,
"isConfigurable": true,
"isContextRoot": false,
"isNxosConverged": false,
"isDeprecated": false,
"isHidden": false,
"isEncrypted": false,
Expand Down Expand Up @@ -94,6 +96,7 @@
"label": "Certificate Store",
"properties": {
"annotation": {
"versions": "4.1(1i)-",
"comment": [
"User annotation. Suggested format orchestrator:value"
],
Expand Down Expand Up @@ -124,10 +127,12 @@
"platformFlavors": [

],
"isNxosConverged": false,
"isDeprecated": false,
"isHidden": false
},
"childAction": {
"versions": "1.0(1e)-",
"comment": [
"Delete or ignore. For internal use only."
],
Expand All @@ -153,25 +158,27 @@
"platformFlavors": [

],
"label": "deleteAll "},
"label": "Delete All "},
{ "value": "8192", "localName": "deleteNonPresent",
"platformFlavors": [

],
"label": "deleteNonPresent "},
"label": "Delete Non Present "},
{ "value": "4096", "localName": "ignore",
"platformFlavors": [

],
"label": "ignore "}
"label": "Ignore "}
],
"platformFlavors": [

],
"isNxosConverged": false,
"isDeprecated": false,
"isHidden": false
},
"dn": {
"versions": "1.0(1e)-",
"comment": [
"A tag or metadata is a non-hierarchical keyword or term assigned to the fabric module."
],
Expand All @@ -195,10 +202,12 @@
"platformFlavors": [

],
"isNxosConverged": false,
"isDeprecated": false,
"isHidden": false
},
"extMngdBy": {
"versions": "4.1(1i)-",
"comment": [
"Indicates which orchestrator is managing this MO"
],
Expand Down Expand Up @@ -229,21 +238,23 @@
"platformFlavors": [

],
"label": "msc "},
"label": "MSC "},
{ "value": "0", "localName": "undefined",
"platformFlavors": [

],
"label": "undefined "}
"label": "Undefined "}
],
"default": "undefined",
"platformFlavors": [

],
"isNxosConverged": false,
"isDeprecated": false,
"isHidden": false
},
"lcOwn": {
"versions": "1.0(1e)-",
"comment": [
"A value that indicates how this object was created. For internal use only."
],
Expand Down Expand Up @@ -294,16 +305,18 @@
"platformFlavors": [

],
"label": "ResolvedOnBehalf "}
"label": "Resolved On Behalf "}
],
"default": "local",
"platformFlavors": [

],
"isNxosConverged": false,
"isDeprecated": false,
"isHidden": false
},
"modTs": {
"versions": "1.0(1e)-",
"comment": [
"The time when this object was last modified."
],
Expand Down Expand Up @@ -334,23 +347,25 @@
"platformFlavors": [

],
"label": "never "}
"label": "Never "}
],
"default": "never",
"platformFlavors": [

],
"isNxosConverged": false,
"isDeprecated": false,
"isHidden": false
},
"monPolDn": {
"versions": "4.1(1i)-",
"comment": [
"The monitoring policy attached to this observable object."
],
"isConfigurable": false,
"propGlobalId": "52687",
"propLocalId": "228",
"label": "Monitoring policy",
"label": "Monitoring Policy",
"baseType": "reference:BinRef",
"modelType": "reference:BinRef",
"needsPropDelimiters": true,
Expand All @@ -367,10 +382,12 @@
"platformFlavors": [

],
"isNxosConverged": false,
"isDeprecated": false,
"isHidden": false
},
"name": {
"versions": "1.0(1e)-",
"comment": [
"The name of the object."
],
Expand Down Expand Up @@ -402,10 +419,12 @@
"platformFlavors": [

],
"isNxosConverged": false,
"isDeprecated": false,
"isHidden": false
},
"nameAlias": {
"versions": "2.2(1k)-",
"isConfigurable": true,
"propGlobalId": "28417",
"propLocalId": "6719",
Expand Down Expand Up @@ -433,10 +452,12 @@
"platformFlavors": [

],
"isNxosConverged": false,
"isDeprecated": false,
"isHidden": false
},
"rn": {
"versions": "1.0(1e)-",
"comment": [
"Identifies an object from its siblings within the context of its parent object. The distinguished name contains a sequence of relative names."
],
Expand All @@ -460,10 +481,12 @@
"platformFlavors": [

],
"isNxosConverged": false,
"isDeprecated": false,
"isHidden": false
},
"status": {
"versions": "1.0(1e)-",
"comment": [
"The upgrade status. This property is for internal use only."
],
Expand Down Expand Up @@ -492,31 +515,33 @@
"comment": [
"In a setter method: specifies that an object should be created. An error is returned if the object already exists. \nIn the return value of a setter method: indicates that an object has been created. \n"
],
"label": "created "},
"label": "Created "},
{ "value": "8", "localName": "deleted",
"platformFlavors": [

],
"comment": [
"In a setter method: specifies that an object should be deleted. \nIn the return value of a setter method: indicates that an object has been deleted.\n"
],
"label": "deleted "},
"label": "Deleted "},
{ "value": "4", "localName": "modified",
"platformFlavors": [

],
"comment": [
"In a setter method: specifies that an object should be modified \nIn the return value of a setter method: indicates that an object has been modified.\n"
],
"label": "modified "}
"label": "Modified "}
],
"platformFlavors": [

],
"isNxosConverged": false,
"isDeprecated": false,
"isHidden": false
},
"uid": {
"versions": "1.0(1e)-",
"comment": [
"A unique identifier for this object."
],
Expand All @@ -540,10 +565,12 @@
"platformFlavors": [

],
"isNxosConverged": false,
"isDeprecated": false,
"isHidden": false
},
"userdom": {
"versions": "5.0(1k)-",
"isConfigurable": true,
"propGlobalId": "60657",
"propLocalId": "13244",
Expand Down Expand Up @@ -579,6 +606,7 @@
"platformFlavors": [

],
"isNxosConverged": false,
"isDeprecated": false,
"isHidden": false
}
Expand Down
Loading

0 comments on commit 9f97fd7

Please sign in to comment.