summaryrefslogtreecommitdiffstats
path: root/csarvalidation
diff options
context:
space:
mode:
authorBartosz Gardziejewski <bartosz.gardziejewski@nokia.com>2020-10-21 10:34:42 +0200
committerBartosz Gardziejewski <bartosz.gardziejewski@nokia.com>2020-12-01 14:22:29 +0100
commit97f2131b263b4beed8fe4b2dd3c07b44edbac396 (patch)
tree004957710ff2cea79c011efea093e8838849ac95 /csarvalidation
parent35d4e259c80c9edeb362de0af9bd77bd3f4412b0 (diff)
Add python script to generate table with active validation rules.
Signed-off-by: Bartosz Gardziejewski <bartosz.gardziejewski@nokia.com> Change-Id: I4c944fe6c5bd3cb7f8807d954cc85ad16743841b Issue-ID: VNFSDK-696
Diffstat (limited to 'csarvalidation')
-rw-r--r--csarvalidation/README.md18
-rw-r--r--csarvalidation/pom.xml68
-rwxr-xr-xcsarvalidation/python/main/generate_active_validation_rules_table.py65
-rw-r--r--csarvalidation/python/main/validation/FileManager.py37
-rw-r--r--csarvalidation/python/main/validation/__init__.py0
-rw-r--r--csarvalidation/python/main/validation/rules/ActiveRulesTableGenerator.py70
-rw-r--r--csarvalidation/python/main/validation/rules/__init__.py0
-rw-r--r--csarvalidation/python/main/validation/rules/providers/ActiveRulesProvider.py43
-rw-r--r--csarvalidation/python/main/validation/rules/providers/RulesDescriptionsProvider.py40
-rw-r--r--csarvalidation/python/main/validation/rules/providers/__init__.py0
-rw-r--r--csarvalidation/python/main/validation/rules/table/ActiveRuleEntity.py24
-rw-r--r--csarvalidation/python/main/validation/rules/table/ActiveRulesTable.py37
-rw-r--r--csarvalidation/python/main/validation/rules/table/__init__.py0
-rw-r--r--csarvalidation/python/requirements.txt1
-rw-r--r--csarvalidation/python/setup.py30
-rw-r--r--csarvalidation/python/test/__init__.py0
-rw-r--r--csarvalidation/python/test/test_ActiveRulesTableGenerator.py78
-rw-r--r--csarvalidation/python/test/test_FileManager.py95
18 files changed, 603 insertions, 3 deletions
diff --git a/csarvalidation/README.md b/csarvalidation/README.md
index d940d1d..65c12fb 100644
--- a/csarvalidation/README.md
+++ b/csarvalidation/README.md
@@ -77,7 +77,14 @@ How to configure vnfreqs.properties
How to run CSAR validation
--------------------------
-Follow the setups given below to run as csar-validate command
+Follow the setups given below to run as csar-validate command.
+
+<u><b>Warning !!!</b>
+Be default, during project building, documentation generation is being disabled
+(see point "Documentation generation" for more details).</u>
+In order to enable this process, add parameter `-DskipDocsGeneration=false` to mvn command, example:
+`mvn clean package -DskipDocsGeneration=false`
+
1. Install OCLIP (`wget -O - https://raw.githubusercontent.com/onap/cli/master/deployment/zip/installer/install-latest.sh | sh`)
@@ -85,6 +92,13 @@ Follow the setups given below to run as csar-validate command
3. Run `oclip --product onap-vtp csar-validate --csar <CSAR path>`
+Documentation generation
+--------------------------
+During project build, automated generation of tables, containing supported rules, is being performed.
+Created tables are being saved in target directory, `target/generated-docs/{current_release}`.
+This generation is being performed by `exec-maven-plugin`, defined in pom.xml.
+In order to generate tables <b>python3 and pip3 are required</b>.
+
Contact
-------
-Kanagaraj.Manickam@huawei.com \ No newline at end of file
+Kanagaraj.Manickam@huawei.com
diff --git a/csarvalidation/pom.xml b/csarvalidation/pom.xml
index ff4cb54..7af3f8b 100644
--- a/csarvalidation/pom.xml
+++ b/csarvalidation/pom.xml
@@ -50,6 +50,8 @@
<maven-war-plugin.version>2.6</maven-war-plugin.version>
<maven-dependency-plugin.version>3.0.0</maven-dependency-plugin.version>
<mockito-core.version>3.5.0</mockito-core.version>
+ <exec-maven-plugin.version>1.6.0</exec-maven-plugin.version>
+ <skipDocsGeneration>true</skipDocsGeneration>
</properties>
<dependencies>
@@ -160,8 +162,72 @@
<build>
<finalName>${project.artifactId}-${project.version}</finalName>
-
<plugins>
+
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>exec-maven-plugin</artifactId>
+ <version>${exec-maven-plugin.version}</version>
+ <executions>
+ <execution>
+ <configuration>
+ <skip>${skipDocsGeneration}</skip>
+ <executable>pip3</executable>
+ <workingDirectory>./python</workingDirectory>
+ <arguments>
+ <argument>install</argument>
+ <argument>-r</argument>
+ <argument>./requirements.txt</argument>
+ </arguments>
+ </configuration>
+ <id>python-requirements</id>
+ <phase>initialize</phase>
+ <goals>
+ <goal>exec</goal>
+ </goals>
+ </execution>
+ <execution>
+ <configuration>
+ <skip>${skipDocsGeneration}</skip>
+ <executable>python3</executable>
+ <workingDirectory>./python/</workingDirectory>
+ <environmentVariables>
+ <PYTHONPATH>./main</PYTHONPATH>
+ </environmentVariables>
+ <arguments>
+ <argument>-m</argument>
+ <argument>unittest</argument>
+ <argument>discover</argument>
+ <argument>./test</argument>
+ </arguments>
+ </configuration>
+ <id>python-test</id>
+ <phase>test</phase>
+ <goals>
+ <goal>exec</goal>
+ </goals>
+ </execution>
+ <execution>
+ <configuration>
+ <skip>${skipDocsGeneration}</skip>
+ <executable>python3</executable>
+ <workingDirectory>./python/main</workingDirectory>
+ <arguments>
+ <argument>generate_active_validation_rules_table.py</argument>
+ </arguments>
+ <environmentVariables>
+ <OUTPUT_DIRECTORY>${project.build.directory}/generated-docs/${onap.release}/</OUTPUT_DIRECTORY>
+ </environmentVariables>
+ </configuration>
+ <id>python_build</id>
+ <phase>generate-resources</phase>
+ <goals>
+ <goal>exec</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
diff --git a/csarvalidation/python/main/generate_active_validation_rules_table.py b/csarvalidation/python/main/generate_active_validation_rules_table.py
new file mode 100755
index 0000000..8367e44
--- /dev/null
+++ b/csarvalidation/python/main/generate_active_validation_rules_table.py
@@ -0,0 +1,65 @@
+# ============LICENSE_START====================================
+# vnfsdk-validation
+# =========================================================
+# Copyright (C) 2020 Nokia. All rights reserved.
+# =========================================================
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# ============LICENSE_END=====================================
+
+import os
+
+from validation.FileManager import FileManager
+from validation.rules.ActiveRulesTableGenerator import ActiveRulesTableGenerator
+
+from validation.rules.providers.ActiveRulesProvider import ActiveRulesProvider
+from validation.rules.providers.RulesDescriptionsProvider import RulesDescriptionsProvider
+
+RESOURCES_DIRECTORY = '../../src/main/resources/'
+RULE_DESCRIPTION_SOL001_PATH = RESOURCES_DIRECTORY + 'open-cli-schema/sol001/'
+RULE_DESCRIPTION_SOL004_PATH = RESOURCES_DIRECTORY + 'open-cli-schema/sol004/'
+VNFREWS_PROPERTIES_PATH = RESOURCES_DIRECTORY + 'vnfreqs.properties'
+RULE_DESCRIPTION_FILE_NAME_PATTERN = 'vtp-validate-csar-%s.yaml'
+
+DEFAULT_OUTPUT_DIRECTORY = RESOURCES_DIRECTORY + 'generated/active-validation-rules/'
+
+VNF_REQS_TAG = "vnfreqs"
+PNF_REQS_TAG = "pnfreqs"
+
+def main():
+ output_directory = get_output_directory()
+ table_with_vnf_rules = output_directory + 'VnfActiveRulesTable.csv'
+ table_with_pnf_rules = output_directory + 'PnfActiveRulesTable.csv'
+ requs_tags = [VNF_REQS_TAG, PNF_REQS_TAG]
+
+ tables = ActiveRulesTableGenerator(
+ [
+ RulesDescriptionsProvider(RULE_DESCRIPTION_SOL001_PATH, RULE_DESCRIPTION_FILE_NAME_PATTERN),
+ RulesDescriptionsProvider(RULE_DESCRIPTION_SOL004_PATH, RULE_DESCRIPTION_FILE_NAME_PATTERN)
+ ],
+ ActiveRulesProvider(VNFREWS_PROPERTIES_PATH)
+ ).generate_active_validation_rule_tables(requs_tags)
+ file_manager = FileManager(output_directory)
+ file_manager.save_rule_table(tables[0].get_table_in_csv_format(), table_with_vnf_rules)
+ file_manager.save_rule_table(tables[1].get_table_in_csv_format(), table_with_pnf_rules)
+
+
+def get_output_directory():
+ if 'OUTPUT_DIRECTORY' in os.environ:
+ output_directory = os.getenv('OUTPUT_DIRECTORY')
+ else:
+ output_directory = DEFAULT_OUTPUT_DIRECTORY
+ return output_directory
+
+
+if __name__ == '__main__':
+ main()
diff --git a/csarvalidation/python/main/validation/FileManager.py b/csarvalidation/python/main/validation/FileManager.py
new file mode 100644
index 0000000..2cdaab5
--- /dev/null
+++ b/csarvalidation/python/main/validation/FileManager.py
@@ -0,0 +1,37 @@
+# ============LICENSE_START====================================
+# vnfsdk-validation
+# =========================================================
+# Copyright (C) 2020 Nokia. All rights reserved.
+# =========================================================
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# ============LICENSE_END=====================================
+
+import os
+
+
+class FileManager:
+
+ def __init__(self, output_directory: str):
+ self._output_directory = output_directory
+
+ def save_rule_table(self, csv_table: str, table_name: str):
+ self._create_output_directory()
+ self._write_rules_to_file(csv_table, table_name)
+
+ def _create_output_directory(self):
+ if not os.path.isdir(self._output_directory):
+ os.makedirs(self._output_directory)
+
+ def _write_rules_to_file(self, csv_table: str, file_name: str):
+ with open(file_name, 'w') as vnf_rules_file:
+ vnf_rules_file.write(csv_table)
diff --git a/csarvalidation/python/main/validation/__init__.py b/csarvalidation/python/main/validation/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/csarvalidation/python/main/validation/__init__.py
diff --git a/csarvalidation/python/main/validation/rules/ActiveRulesTableGenerator.py b/csarvalidation/python/main/validation/rules/ActiveRulesTableGenerator.py
new file mode 100644
index 0000000..c8a0f37
--- /dev/null
+++ b/csarvalidation/python/main/validation/rules/ActiveRulesTableGenerator.py
@@ -0,0 +1,70 @@
+# ============LICENSE_START====================================
+# vnfsdk-validation
+# =========================================================
+# Copyright (C) 2020 Nokia. All rights reserved.
+# =========================================================
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# ============LICENSE_END=====================================
+
+from validation.rules.providers.ActiveRulesProvider import ActiveRulesProvider
+
+from validation.rules.table.ActiveRuleEntity import ActiveRuleEntity
+from validation.rules.table.ActiveRulesTable import ActiveRulesTable
+
+
+class ActiveRulesTableGenerator:
+
+ def __init__(self,
+ rules_descriptions_providers: list,
+ active_rules_provider: ActiveRulesProvider
+ ):
+ self._rules_descriptions = rules_descriptions_providers
+ self._active_rules = active_rules_provider
+
+ def generate_active_validation_rule_tables(self, reqs_tags: list) -> list:
+ tables = []
+ for reqs_tag in reqs_tags:
+ tables.append(
+ self._create_rules_table(reqs_tag)
+ )
+ return tables
+
+ def _create_rules_table(self, reqs_tag: str) -> ActiveRulesTable:
+ active_rules_table = ActiveRulesTable()
+ active_rules = self._active_rules.get_active_rules(reqs_tag)
+ for rule in active_rules:
+ yaml_description = self._get_rule_description(rule)
+ active_rules_table.add_entity(
+ ActiveRuleEntity(
+ rule,
+ self._get_description_from_yaml(yaml_description),
+ self._get_product_from_yaml(yaml_description)
+ )
+ )
+ return active_rules_table
+
+ def _get_rule_description(self, rule: str) -> dict:
+ yaml_description = ""
+ for rules_description in self._rules_descriptions:
+ if rules_description.contains_rule(rule):
+ yaml_description = rules_description.get_rule_description(rule)
+ break
+ return yaml_description
+
+ @staticmethod
+ def _get_description_from_yaml(yaml_file: dict) -> str:
+ return yaml_file['description'].replace("\n", " ")
+
+ @staticmethod
+ def _get_product_from_yaml(yaml_file: dict) -> str:
+ return yaml_file['info']['product']
diff --git a/csarvalidation/python/main/validation/rules/__init__.py b/csarvalidation/python/main/validation/rules/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/csarvalidation/python/main/validation/rules/__init__.py
diff --git a/csarvalidation/python/main/validation/rules/providers/ActiveRulesProvider.py b/csarvalidation/python/main/validation/rules/providers/ActiveRulesProvider.py
new file mode 100644
index 0000000..1d601f2
--- /dev/null
+++ b/csarvalidation/python/main/validation/rules/providers/ActiveRulesProvider.py
@@ -0,0 +1,43 @@
+# ============LICENSE_START====================================
+# vnfsdk-validation
+# =========================================================
+# Copyright (C) 2020 Nokia. All rights reserved.
+# =========================================================
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# ============LICENSE_END=====================================
+
+class ActiveRulesProvider:
+
+ def __init__(self, properties_file_path: str, rules_separator: str = ",", key_value_separator: str = "="):
+ self.properties_file_path = properties_file_path
+ self._rules_separator = rules_separator
+ self._key_value_separator = key_value_separator
+
+ def get_active_rules(self, reqs: str) -> list:
+ active_rules = []
+ for line in self._load_file_by_lines():
+ if line.startswith(reqs):
+ active_rules = self._split_properties_line(line, self._rules_separator, self._key_value_separator)
+ break
+ return active_rules
+
+ def _load_file_by_lines(self) -> list:
+ with open(self.properties_file_path, 'r') as properties_file:
+ lines = properties_file.read().splitlines()
+ return lines
+
+ @staticmethod
+ def _split_properties_line(line: str, splitter: str, key_value_separator: str) -> list:
+ key_value_separation_index = line.index(key_value_separator) + 1
+ value = line[key_value_separation_index:]
+ return value.split(splitter)
diff --git a/csarvalidation/python/main/validation/rules/providers/RulesDescriptionsProvider.py b/csarvalidation/python/main/validation/rules/providers/RulesDescriptionsProvider.py
new file mode 100644
index 0000000..a34bbe3
--- /dev/null
+++ b/csarvalidation/python/main/validation/rules/providers/RulesDescriptionsProvider.py
@@ -0,0 +1,40 @@
+# ============LICENSE_START====================================
+# vnfsdk-validation
+# =========================================================
+# Copyright (C) 2020 Nokia. All rights reserved.
+# =========================================================
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# ============LICENSE_END=====================================
+
+import os
+import yaml
+
+
+class RulesDescriptionsProvider:
+
+ def __init__(self, directory_containing_rules: str, rule_description_file_name_pattern: str):
+ self._directory_containing_rules = directory_containing_rules
+ self._rule_description_file_name_pattern = rule_description_file_name_pattern
+
+ def contains_rule(self, rule: str) -> bool:
+ description_file_name = self._rule_description_file_name_pattern % rule
+ return os.path.isfile(self._directory_containing_rules + description_file_name)
+
+ def get_rule_description(self, rule: str) -> str:
+ description_file_name = self._rule_description_file_name_pattern % rule
+ return self._get_yaml_description(description_file_name)
+
+ def _get_yaml_description(self, yaml_file: str) -> str:
+ with open(self._directory_containing_rules + yaml_file, 'r') as description_file:
+ description_yaml = yaml.load(description_file, Loader=yaml.FullLoader)
+ return description_yaml
diff --git a/csarvalidation/python/main/validation/rules/providers/__init__.py b/csarvalidation/python/main/validation/rules/providers/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/csarvalidation/python/main/validation/rules/providers/__init__.py
diff --git a/csarvalidation/python/main/validation/rules/table/ActiveRuleEntity.py b/csarvalidation/python/main/validation/rules/table/ActiveRuleEntity.py
new file mode 100644
index 0000000..ed8c7d5
--- /dev/null
+++ b/csarvalidation/python/main/validation/rules/table/ActiveRuleEntity.py
@@ -0,0 +1,24 @@
+# ============LICENSE_START====================================
+# vnfsdk-validation
+# =========================================================
+# Copyright (C) 2020 Nokia. All rights reserved.
+# =========================================================
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# ============LICENSE_END=====================================
+
+class ActiveRuleEntity:
+
+ def __init__(self, rule, description, product):
+ self.rule = rule
+ self.description = description
+ self.product = product
diff --git a/csarvalidation/python/main/validation/rules/table/ActiveRulesTable.py b/csarvalidation/python/main/validation/rules/table/ActiveRulesTable.py
new file mode 100644
index 0000000..70bb10d
--- /dev/null
+++ b/csarvalidation/python/main/validation/rules/table/ActiveRulesTable.py
@@ -0,0 +1,37 @@
+# ============LICENSE_START====================================
+# vnfsdk-validation
+# =========================================================
+# Copyright (C) 2020 Nokia. All rights reserved.
+# =========================================================
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# ============LICENSE_END=====================================
+
+from validation.rules.table.ActiveRuleEntity import ActiveRuleEntity
+
+
+class ActiveRulesTable:
+
+ def __init__(self):
+ self._active_rules_entities = []
+
+ def add_entity(self, active_rule_entity: ActiveRuleEntity):
+ self._active_rules_entities.append(active_rule_entity)
+
+ def get_table_in_csv_format(self, values_separator=";", entity_separator="\n") -> str:
+ csv_table = ""
+ for entity in self._active_rules_entities:
+ csv_table += \
+ entity.product + values_separator + \
+ entity.rule + values_separator + \
+ entity.description + entity_separator
+ return csv_table
diff --git a/csarvalidation/python/main/validation/rules/table/__init__.py b/csarvalidation/python/main/validation/rules/table/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/csarvalidation/python/main/validation/rules/table/__init__.py
diff --git a/csarvalidation/python/requirements.txt b/csarvalidation/python/requirements.txt
new file mode 100644
index 0000000..7a997b5
--- /dev/null
+++ b/csarvalidation/python/requirements.txt
@@ -0,0 +1 @@
+PyYAML==5.3.1
diff --git a/csarvalidation/python/setup.py b/csarvalidation/python/setup.py
new file mode 100644
index 0000000..060d45c
--- /dev/null
+++ b/csarvalidation/python/setup.py
@@ -0,0 +1,30 @@
+# ============LICENSE_START====================================
+# vnfsdk-validation
+# =========================================================
+# Copyright (C) 2020 Nokia. All rights reserved.
+# =========================================================
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# ============LICENSE_END=====================================
+
+from setuptools import setup
+
+with open('requirements.txt') as f:
+ required = f.read().splitlines()
+
+setup(
+ name='Active rules table generator',
+ version='1.0',
+ description='This project allow generation of tables containing rules that are active for given vnfsdk/validation release.',
+ packages=['main.validation'],
+ install_requires=required
+)
diff --git a/csarvalidation/python/test/__init__.py b/csarvalidation/python/test/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/csarvalidation/python/test/__init__.py
diff --git a/csarvalidation/python/test/test_ActiveRulesTableGenerator.py b/csarvalidation/python/test/test_ActiveRulesTableGenerator.py
new file mode 100644
index 0000000..3103a23
--- /dev/null
+++ b/csarvalidation/python/test/test_ActiveRulesTableGenerator.py
@@ -0,0 +1,78 @@
+# ============LICENSE_START====================================
+# vnfsdk-validation
+# =========================================================
+# Copyright (C) 2020 Nokia. All rights reserved.
+# =========================================================
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# ============LICENSE_END=====================================
+
+import unittest
+
+from validation.rules.ActiveRulesTableGenerator import ActiveRulesTableGenerator
+from validation.rules.providers.ActiveRulesProvider import ActiveRulesProvider
+from validation.rules.providers.RulesDescriptionsProvider import RulesDescriptionsProvider
+
+RESOURCES_DIRECTORY = '../src/main/resources/'
+RULE_DESCRIPTION_SOL001_PATH = RESOURCES_DIRECTORY + 'open-cli-schema/sol001/'
+RULE_DESCRIPTION_SOL004_PATH = RESOURCES_DIRECTORY + 'open-cli-schema/sol004/'
+VNFREWS_PROPERTIES_PATH = RESOURCES_DIRECTORY + 'vnfreqs.properties'
+RULE_DESCRIPTION_FILE_NAME_PATTERN = 'vtp-validate-csar-%s.yaml'
+
+CSV_DELIMITER = ";"
+
+VNF_REQS_TAG = "vnfreqs"
+PNF_REQS_TAG = "pnfreqs"
+
+
+class ActiveRulesTableGeneratorTest(unittest.TestCase):
+
+ @staticmethod
+ def generate_tables_with_active_rules(requs_tags: list) -> list:
+ return ActiveRulesTableGenerator(
+ [
+ RulesDescriptionsProvider(RULE_DESCRIPTION_SOL001_PATH, RULE_DESCRIPTION_FILE_NAME_PATTERN),
+ RulesDescriptionsProvider(RULE_DESCRIPTION_SOL004_PATH, RULE_DESCRIPTION_FILE_NAME_PATTERN)
+ ],
+ ActiveRulesProvider(VNFREWS_PROPERTIES_PATH)
+ ).generate_active_validation_rule_tables(requs_tags)
+
+ def test_generate_table_with_active_pnf_rules(self):
+ tables = self.generate_tables_with_active_rules([PNF_REQS_TAG])
+
+ self.assertTrue(len(tables) == 1)
+ self.validate_csv_table_with_rules(tables[0].get_table_in_csv_format())
+
+ def test_generate_table_with_active_vnf_rules(self):
+ tables = self.generate_tables_with_active_rules([VNF_REQS_TAG])
+
+ self.assertTrue(len(tables) == 1)
+ self.validate_csv_table_with_rules(tables[0].get_table_in_csv_format())
+
+ def test_generate_tables_with_active_vnf_and_pnf_rules(self):
+ tables = self.generate_tables_with_active_rules([PNF_REQS_TAG, VNF_REQS_TAG])
+
+ self.assertTrue(len(tables) == 2)
+ self.validate_csv_table_with_rules(tables[0].get_table_in_csv_format(values_separator=CSV_DELIMITER))
+ self.validate_csv_table_with_rules(tables[1].get_table_in_csv_format(values_separator=CSV_DELIMITER))
+
+ def validate_csv_table_with_rules(self, vnf_rules: str):
+ lines = vnf_rules.splitlines()
+ for line in lines:
+ values = line.split(CSV_DELIMITER)
+ self.assertTrue(len(values) == 3)
+ self.assertTrue(values[0].startswith("onap-"))
+ self.assertTrue(values[1].startswith("r"))
+
+
+if __name__ == '__main__':
+ unittest.main()
diff --git a/csarvalidation/python/test/test_FileManager.py b/csarvalidation/python/test/test_FileManager.py
new file mode 100644
index 0000000..722d1a9
--- /dev/null
+++ b/csarvalidation/python/test/test_FileManager.py
@@ -0,0 +1,95 @@
+# ============LICENSE_START====================================
+# vnfsdk-validation
+# =========================================================
+# Copyright (C) 2020 Nokia. All rights reserved.
+# =========================================================
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# ============LICENSE_END=====================================
+
+import os
+import shutil
+import unittest
+
+from validation.FileManager import FileManager
+from validation.rules.ActiveRulesTableGenerator import ActiveRulesTableGenerator
+from validation.rules.providers.ActiveRulesProvider import ActiveRulesProvider
+from validation.rules.providers.RulesDescriptionsProvider import RulesDescriptionsProvider
+
+RESOURCES_DIRECTORY = '../src/main/resources/'
+RULE_DESCRIPTION_SOL001_PATH = RESOURCES_DIRECTORY + 'open-cli-schema/sol001/'
+RULE_DESCRIPTION_SOL004_PATH = RESOURCES_DIRECTORY + 'open-cli-schema/sol004/'
+VNFREWS_PROPERTIES_PATH = RESOURCES_DIRECTORY + 'vnfreqs.properties'
+RULE_DESCRIPTION_FILE_NAME_PATTERN = 'vtp-validate-csar-%s.yaml'
+
+CSV_DELIMITER = ";"
+
+VNF_REQS_TAG = "vnfreqs"
+PNF_REQS_TAG = "pnfreqs"
+
+OUTPUT_DIRECTORY = './active_rules_table_generator_test/'
+
+TABLE_WITH_VNF_RULES = OUTPUT_DIRECTORY + 'VnfActiveRulesTable.csv'
+TABLE_WITH_PNF_RULES = OUTPUT_DIRECTORY + 'PnfActiveRulesTable.csv'
+
+
+class FileManagerTest(unittest.TestCase):
+
+
+ @staticmethod
+ def generate_tables_with_active_rules(requs_tags: list) -> list:
+ return ActiveRulesTableGenerator(
+ [
+ RulesDescriptionsProvider(RULE_DESCRIPTION_SOL001_PATH, RULE_DESCRIPTION_FILE_NAME_PATTERN),
+ RulesDescriptionsProvider(RULE_DESCRIPTION_SOL004_PATH, RULE_DESCRIPTION_FILE_NAME_PATTERN)
+ ],
+ ActiveRulesProvider(VNFREWS_PROPERTIES_PATH)
+ ).generate_active_validation_rule_tables(requs_tags)
+
+ def generate_and_save_tables(self):
+ tables = self.generate_tables_with_active_rules([VNF_REQS_TAG, PNF_REQS_TAG])
+ file_manager = FileManager(OUTPUT_DIRECTORY)
+ file_manager.save_rule_table(
+ tables[0].get_table_in_csv_format(values_separator=CSV_DELIMITER),
+ TABLE_WITH_VNF_RULES
+ )
+ file_manager.save_rule_table(
+ tables[1].get_table_in_csv_format(values_separator=CSV_DELIMITER),
+ TABLE_WITH_PNF_RULES
+ )
+
+ def tearDown(self):
+ shutil.rmtree(OUTPUT_DIRECTORY)
+
+ def test_generate_and_save_table_with_active_rules(self):
+ self.generate_and_save_tables()
+ self.assertTrue(os.path.isdir(OUTPUT_DIRECTORY))
+
+ self.assertTrue(os.path.isfile(TABLE_WITH_VNF_RULES))
+ with open(TABLE_WITH_VNF_RULES, 'r') as vnf_rules:
+ self.validate_csv_table_with_rules(vnf_rules)
+
+ self.assertTrue(os.path.isfile(TABLE_WITH_PNF_RULES))
+ with open(TABLE_WITH_PNF_RULES, 'r') as pnf_rules:
+ self.validate_csv_table_with_rules(pnf_rules)
+
+ def validate_csv_table_with_rules(self, vnf_rules):
+ lines = vnf_rules.read().splitlines()
+ for line in lines:
+ values = line.split(CSV_DELIMITER)
+ self.assertTrue(len(values) == 3)
+ self.assertTrue(values[0].startswith("onap-"))
+ self.assertTrue(values[1].startswith("r"))
+
+
+if __name__ == '__main__':
+ unittest.main()