diff options
author | Alexis de Talhouët <adetalhouet89@gmail.com> | 2019-06-18 19:43:50 -0400 |
---|---|---|
committer | Alexis de Talhouët <adetalhouet89@gmail.com> | 2019-06-21 01:10:53 +0000 |
commit | 7ad72c86fbd10888a849eed2b00dc9fddadef5aa (patch) | |
tree | 28ea065a77e3ce60b14603b86748aeed87f9d80b /ms/controllerblueprints/modules/blueprint-core/src/test | |
parent | 091bba704d8e9137b9bca9ed02d139539aa2ac53 (diff) |
Add Jinja2 custom ResourceLocator
This will allow to include template within template to create
template hierarchy
Change-Id: I21c5deaf51d391e1a51b9863a905c26b1891db16
Issue-ID: CCSDK-1417
Signed-off-by: Alexis de Talhouët <adetalhouet89@gmail.com>
Diffstat (limited to 'ms/controllerblueprints/modules/blueprint-core/src/test')
6 files changed, 21 insertions, 110 deletions
diff --git a/ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/service/BluePrintTemplateServiceTest.kt b/ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/service/BluePrintTemplateServiceTest.kt index 6f961c8ed..63c8ad74e 100644 --- a/ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/service/BluePrintTemplateServiceTest.kt +++ b/ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/service/BluePrintTemplateServiceTest.kt @@ -36,7 +36,8 @@ class BluePrintTemplateServiceTest { @BeforeTest fun setup() { - val blueprintBasePath: String = ("./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration") + val blueprintBasePath: String = + ("./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration") blueprintRuntime = BluePrintMetadataUtils.getBluePrintRuntime("1234", blueprintBasePath) } @@ -55,11 +56,12 @@ class BluePrintTemplateServiceTest { @Test fun testJinjaGeneratedContent() { runBlocking { - val template = JacksonUtils.getClassPathFileContent("templates/base-config-jinja-template.jinja") + val template = JacksonUtils.getClassPathFileContent("templates/master.jinja") val json = JacksonUtils.getClassPathFileContent("templates/base-config-data-jinja.json") var element: MutableMap<String, Any> = mutableMapOf() - element["additional_array"] = arrayListOf(hashMapOf("name" to "Element1", "location" to "Region0"), hashMapOf("name" to "Element2", "location" to "Region1")) + element["additional_array"] = arrayListOf(hashMapOf("name" to "Element1", "location" to "Region0"), + hashMapOf("name" to "Element2", "location" to "Region1")) val content = BluePrintJinjaTemplateService.generateContent(template, json, false, element) assertNotNull(content, "failed to generate content for velocity template") @@ -67,42 +69,12 @@ class BluePrintTemplateServiceTest { } - @Test - fun testVelocityGeneratedContentFromFiles() { - runBlocking { - val bluePrintTemplateService = BluePrintTemplateService() - val templateFile = "templates/base-config-velocity-template.vtl" - val jsonFile = "templates/base-config-data-velocity.json" - - val content = bluePrintTemplateService.generateContentFromFiles( - templateFile, BluePrintConstants.ARTIFACT_VELOCITY_TYPE_NAME, jsonFile, false, mutableMapOf()) - assertNotNull(content, "failed to generate content for velocity template") - } - - } - - @Test - fun testJinjaGeneratedContentFromFiles() { - runBlocking { - var element: MutableMap<String, Any> = mutableMapOf() - element["additional_array"] = arrayListOf(hashMapOf("name" to "Element1", "location" to "Region0"), hashMapOf("name" to "Element2", "location" to "Region1")) - - val bluePrintTemplateService = BluePrintTemplateService() - - val templateFile = "templates/base-config-jinja-template.jinja" - val jsonFile = "templates/base-config-data-jinja.json" - - val content = bluePrintTemplateService.generateContentFromFiles( - templateFile, BluePrintConstants.ARTIFACT_JINJA_TYPE_NAME, - jsonFile, false, element) - assertNotNull(content, "failed to generate content for velocity template") - } - } @Test fun `no value variable should evaluate to default value - standalone template mesh test`() { runBlocking { - val template = JacksonUtils.getClassPathFileContent("templates/default-variable-value-velocity-template.vtl") + val template = + JacksonUtils.getClassPathFileContent("templates/default-variable-value-velocity-template.vtl") val json = JacksonUtils.getClassPathFileContent("templates/default-variable-value-data.json") val content = BluePrintVelocityTemplateService.generateContent(template, json) @@ -113,24 +85,5 @@ class BluePrintTemplateServiceTest { } } - @Test - fun `no value variable should evaluate to default value - blueprint processing test`() { - runBlocking { - val bluePrintTemplateService = BluePrintTemplateService() - - val templateFile = "templates/default-variable-value-velocity-template.vtl" - val jsonFile = "templates/default-variable-value-data.json" - - val content = bluePrintTemplateService.generateContentFromFiles(templateFile, - BluePrintConstants.ARTIFACT_VELOCITY_TYPE_NAME, jsonFile, false, mutableMapOf()) - - //first line represents a variable whose value was successfully retrieved, second line contains a variable - // whose value could not be evaluated - val expected = "sample-hostname\n\${node0_backup_router_address}" - assertEquals(expected, content, "No value variable should use default value") - } - - } - } diff --git a/ms/controllerblueprints/modules/blueprint-core/src/test/resources/templates/base-config-data-jinja.json b/ms/controllerblueprints/modules/blueprint-core/src/test/resources/templates/base-config-data-jinja.json index bbfb38d80..ab7abf3d4 100644 --- a/ms/controllerblueprints/modules/blueprint-core/src/test/resources/templates/base-config-data-jinja.json +++ b/ms/controllerblueprints/modules/blueprint-core/src/test/resources/templates/base-config-data-jinja.json @@ -1,16 +1,3 @@ { - "node_hostname": "sdnc-host", - "node_backup_router_address": "2001:1890:1253::192:168:100:1", - "node_backup_router_d_address": "2011:1090:1253::112:158:100:1", - "servers": [ - "Server1", - "Server2", - "Server3" - ], - "classes": [ - "superuser-class", - "tacacs-adv-class", - "tacacs-base-class" - ], - "system_password": "teamops-system-password" + "occurrence": 2 }
\ No newline at end of file diff --git a/ms/controllerblueprints/modules/blueprint-core/src/test/resources/templates/base-config-jinja-template.jinja b/ms/controllerblueprints/modules/blueprint-core/src/test/resources/templates/base-config-jinja-template.jinja deleted file mode 100755 index db900bc8b..000000000 --- a/ms/controllerblueprints/modules/blueprint-core/src/test/resources/templates/base-config-jinja-template.jinja +++ /dev/null @@ -1,42 +0,0 @@ -<configuration xmlns="http://xml.juniper.net/xnm/1.1/xnm" -xmlns:a="http://xml.juniper.net/junos/15.1X49/junos"> - <version>15.1X49-D50.3</version> - <groups> - <name>node0</name> - <system> - {%- for server in servers %} - <server-host-name>{{ server }}</server-host-name> - {%- endfor %} - </system> - <system> - <host-name>{{ node_hostname }}</host-name> - <backup-router> - <address>{{ node_backup_router_address }}</address> - <destination>{{ node_backup_router_d_address }}</destination> - </backup-router> - <login> - <message>ONAP information assets</message> - {%- for class in classes %} - <class> - {{ class }} - </class> - {%- endfor %} - <user> - <name>readwrite</name> - <full-name>Read - Write Account Access</full-name> - <uid>1002</uid> - <class>tacacs-adv-class</class> - <authentication> - <encrypted-password>{{ system_password }}</encrypted-password> - </authentication> - </user> - </login> - {%- for element in additional_array %} - <additionalArray> - <name>{{ element.name }}</name> - <location>{{ element.location }}</location> - </additionalArray> - {%- endfor %} - </system> - </groups> -</configuration>
\ No newline at end of file diff --git a/ms/controllerblueprints/modules/blueprint-core/src/test/resources/templates/interface.jinja b/ms/controllerblueprints/modules/blueprint-core/src/test/resources/templates/interface.jinja new file mode 100755 index 000000000..93114d90a --- /dev/null +++ b/ms/controllerblueprints/modules/blueprint-core/src/test/resources/templates/interface.jinja @@ -0,0 +1,3 @@ + <interface-configurations xmlns="http://cisco.com/ns/yang/Cisco-IOS-XR-ifmgr-cfg"> +blo + </interface-configurations>
\ No newline at end of file diff --git a/ms/controllerblueprints/modules/blueprint-core/src/test/resources/templates/isis.jinja b/ms/controllerblueprints/modules/blueprint-core/src/test/resources/templates/isis.jinja new file mode 100644 index 000000000..f46d91330 --- /dev/null +++ b/ms/controllerblueprints/modules/blueprint-core/src/test/resources/templates/isis.jinja @@ -0,0 +1,3 @@ + <isis xmlns="http://cisco.com/ns/yang/Cisco-IOS-XR-clns-isis-cfg"> +blah + </isis>
\ No newline at end of file diff --git a/ms/controllerblueprints/modules/blueprint-core/src/test/resources/templates/master.jinja b/ms/controllerblueprints/modules/blueprint-core/src/test/resources/templates/master.jinja new file mode 100644 index 000000000..1137b2595 --- /dev/null +++ b/ms/controllerblueprints/modules/blueprint-core/src/test/resources/templates/master.jinja @@ -0,0 +1,7 @@ +{%- for i in range(occurrence) %} +<config> +{% include "templates/isis.jinja" %} +{% include "templates/interface.jinja" %} +</config> +{{ "]]>]]" if not loop.last }} +{%- endfor %}
\ No newline at end of file |