From 5ef0bbbda90428378a08d416481b90047f5ba870 Mon Sep 17 00:00:00 2001 From: mrichomme Date: Thu, 8 Oct 2020 13:46:50 +0200 Subject: Add reporting page creation in pythonsdk-tests Issue-ID: TEST-269 Signed-off-by: mrichomme Change-Id: I4ab0a2f7a1a1e98ae5d05166c6aa06212d24eeae Signed-off-by: mrichomme --- requirements.txt | 1 + run_basicvm_nomulticloud.py | 1 + src/onaptests/configuration/settings.py | 1 + .../ubuntu16_multicloud_yaml_settings.py | 3 + .../ubuntu16_nomulticloud_settings.py | 2 + src/onaptests/scenario/basic_vm.py | 4 +- src/onaptests/steps/reports_collection.py | 35 +++- src/onaptests/templates/reporting/base.html.j2 | 231 +++++++++++++++++++++ .../templates/reporting/reporting.html.j2 | 43 ++++ 9 files changed, 316 insertions(+), 5 deletions(-) create mode 100644 src/onaptests/templates/reporting/base.html.j2 create mode 100644 src/onaptests/templates/reporting/reporting.html.j2 diff --git a/requirements.txt b/requirements.txt index 7ed56d2..a2e82b3 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,4 @@ xtesting openstacksdk onapsdk>=7.0.0 +jinja2 diff --git a/run_basicvm_nomulticloud.py b/run_basicvm_nomulticloud.py index e6be410..9ebefb8 100644 --- a/run_basicvm_nomulticloud.py +++ b/run_basicvm_nomulticloud.py @@ -20,3 +20,4 @@ if __name__ == "__main__": basic_vm_instantiate.cleanup() except ValueError as error: logger.info("service instance deleted as expected {0}".format(error)) + basic_vm_instantiate.reports_collection.generate_report() diff --git a/src/onaptests/configuration/settings.py b/src/onaptests/configuration/settings.py index 7385fa0..3339082 100644 --- a/src/onaptests/configuration/settings.py +++ b/src/onaptests/configuration/settings.py @@ -38,4 +38,5 @@ LOG_CONFIG = { } } +REPORTING_FILE_PATH = "/tmp/reporting.html" # SOCK_HTTP = "socks5h://127.0.0.1:8080" diff --git a/src/onaptests/configuration/ubuntu16_multicloud_yaml_settings.py b/src/onaptests/configuration/ubuntu16_multicloud_yaml_settings.py index 341dc16..d45b142 100644 --- a/src/onaptests/configuration/ubuntu16_multicloud_yaml_settings.py +++ b/src/onaptests/configuration/ubuntu16_multicloud_yaml_settings.py @@ -2,6 +2,9 @@ import sys from .settings import * # pylint: disable=W0614 """ Specific ubuntu16 with multicloud and yaml config scenario.""" +SERVICE_DETAILS = ("Onboarding, distribution and instantiation of a VM" + + "using à la carte and Multicloud module") +SERVICE_COMPONENTS="SDC, DMAAP, AAI, SO, SDNC, Multicloud" USE_MULTICLOUD = True # Set ONLY_INSTANTIATE to true to run an instantiation without repeating diff --git a/src/onaptests/configuration/ubuntu16_nomulticloud_settings.py b/src/onaptests/configuration/ubuntu16_nomulticloud_settings.py index c6c9e66..310fafc 100644 --- a/src/onaptests/configuration/ubuntu16_nomulticloud_settings.py +++ b/src/onaptests/configuration/ubuntu16_nomulticloud_settings.py @@ -9,6 +9,8 @@ from .settings import * # pylint: disable=W0614 # pylint: disable=bad-whitespace # The ONAP part +SERVICE_DETAILS="Onboarding, distribution and instanitation of an Ubuntu VM using à la carte" +SERVICE_COMPONENTS="SDC, DMAAP, AAI, SO, SDNC" USE_MULTICLOUD = False # Set ONLY_INSTANTIATE to true to run an instantiation without repeating # onboarding and related AAI configuration (Cloud config) diff --git a/src/onaptests/scenario/basic_vm.py b/src/onaptests/scenario/basic_vm.py index 15a6f5d..48fd169 100644 --- a/src/onaptests/scenario/basic_vm.py +++ b/src/onaptests/scenario/basic_vm.py @@ -42,7 +42,7 @@ class BasicVm(testcase.TestCase): self.__logger.info("No cleanup requested. Test completed.") self.result = 100 - def clean(self): """Clean Additional resources if needed.""" - pass + self.__logger.info("Generate Test report") + self.test.reports_collection.generate_report() diff --git a/src/onaptests/steps/reports_collection.py b/src/onaptests/steps/reports_collection.py index b61b571..62c0447 100644 --- a/src/onaptests/steps/reports_collection.py +++ b/src/onaptests/steps/reports_collection.py @@ -1,5 +1,7 @@ +import sys from typing import Dict - +from jinja2 import Environment, FileSystemLoader, select_autoescape +from onapsdk.configuration import settings class ReportsCollection: """Collection to store steps execution statuses.""" @@ -29,7 +31,34 @@ class ReportsCollection: """ report: Dict[str, str] = {} for element in self._collection[::-1]: - print(element) - print(type(element)) report.update(element) return report + + def generate_report(self) -> None: + step_list = self.report + failing_steps = [] + for step,status in step_list.items(): + if 'FAIL' in status: + failing_steps[step] = status + usecase = settings.SERVICE_NAME + try: + details = settings.SERVICE_DETAILS + except: + details = "" + try: + components = settings.SERVICE_COMPONENTS + except: + components = "" + log_path = settings.LOG_CONFIG['handlers']['file']['filename'] + jinja_env = Environment( + autoescape=select_autoescape(['html']), + loader=FileSystemLoader(sys.path[-1] + '/onaptests/templates/reporting')) + + jinja_env.get_template('reporting.html.j2').stream( + failing_steps=failing_steps, + steps=step_list, + usecase=usecase, + details=details, + components=components, + log_path=log_path).dump( + settings.REPORTING_FILE_PATH) diff --git a/src/onaptests/templates/reporting/base.html.j2 b/src/onaptests/templates/reporting/base.html.j2 new file mode 100644 index 0000000..cbb4e44 --- /dev/null +++ b/src/onaptests/templates/reporting/base.html.j2 @@ -0,0 +1,231 @@ +{% macro color(failing, total) %} +{% if failing == 0 %} +is-success +{% else %} +{% if (failing / total) <= 0.1 %} +is-warning +{% else %} +is-danger +{% endif %} +{% endif %} +{% endmacro %} + +{% macro percentage(failing, total) %} +{{ ((total - failing) / total) | round }} +{% endmacro %} + +{% macro statistic(resource_name, failing, total) %} +{% set success = total - failing %} +
+
+

{{ resource_name | capitalize }}

+

{{ success }}/{{ total }}

+ {{ percentage(failing, total) }} +
+
+{% endmacro %} + +{% macro pods_table(pods) %} +
+ + + + + + + + + + + + {% for pod in pods %} + + + {% if pod.init_done %} + + {% else %} + + {% endif %} + + + {% if pod.init_done %} + + {% else %} + + {% endif %} + + {% endfor %} + +
NameReadyStatusReasonRestarts
{{ pod.k8s.metadata.name }}{{ pod.running_containers }}/{{ (pod.containers | length) }}Init:{{ pod.runned_init_containers }}/{{ (pod.init_containers | length) }}{{ pod.k8s.status.phase }}{{ pod.k8s.status.reason }}{{ pod.restart_count }}{{ pod.init_restart_count }}
+
+{% endmacro %} + +{% macro key_value_description_list(title, dict) %} +
{{ title | capitalize }}:
+
+ {% if dict %} + {% for key, value in dict.items() %} + {% if loop.first %} +
+ {% endif %} +
{{ key }}:
+
{{ value }}
+ {% if loop.last %} +
+ {% endif %} + {% endfor %} + {% endif %} +
+{% endmacro %} + +{% macro description(k8s) %} +
+

Description

+
+
+ {% if k8s.spec.type %} +
Type:
+
{{ k8s.spec.type }}
+ {% if (k8s.spec.type | lower) == "clusterip" %} +
Headless:
+
{% if (k8s.spec.cluster_ip | lower) == "none" %}Yes{% else %}No{% endif %}
+ {% endif %} + {% endif %} + {{ key_value_description_list('Labels', k8s.metadata.labels) | indent(width=6) }} + {{ key_value_description_list('Annotations', k8s.metadata.annotations) | indent(width=6) }} + {% if k8s.spec.selector %} + {% if k8s.spec.selector.match_labels %} + {{ key_value_description_list('Selector', k8s.spec.selector.match_labels) | indent(width=6) }} + {% else %} + {{ key_value_description_list('Selector', k8s.spec.selector) | indent(width=6) }} + {% endif %} + {% endif %} + {% if k8s.phase %} +
Status:
+
{{ k8s.phase }}
+ {% endif %} + {% if k8s.metadata.owner_references %} +
Controlled By:
+
{{ k8s.metadata.owner_references[0].kind }}/{{ k8s.metadata.owner_references[0].name }}
+ {% endif %} +
+
+
+{% endmacro %} + +{% macro pods_container(pods, parent, has_title=True) %} +
+ {% if has_title %} +

Pods

+ {% endif %} + {% if (pods | length) > 0 %} + {{ pods_table(pods) | indent(width=2) }} + {% else %} +
{{ parent }} has no pods!
+ {% endif %} +
+{% endmacro %} + +{% macro two_level_breadcrumb(title, name) %} +
+ +
+{% endmacro %} + +{% macro pod_parent_summary(title, name, failed_pods, pods) %} +{{ summary(title, name, [{'title': 'Pod', 'failing': failed_pods, 'total': (pods | length)}]) }} +{% endmacro %} + +{% macro number_ok(number, none_value, total=None) %} +{% if number %} +{% if total and number < total %} +{{ number }} +{% else %} +{{ number }} +{% endif %} +{% else %} +{{ none_value }} +{% endif %} +{% endmacro %} + +{% macro summary(title, name, statistics) %} +
+
+
+

+ {{ title | capitalize }} {{ name }} Summary +

+ +
+
+
+{% endmacro %} + + + + + + + Tests results - {% block title %}{% endblock %} + + + {% block more_head %}{% endblock %} + + + + + {% block content %}{% endblock %} + + + + diff --git a/src/onaptests/templates/reporting/reporting.html.j2 b/src/onaptests/templates/reporting/reporting.html.j2 new file mode 100644 index 0000000..5dafe3f --- /dev/null +++ b/src/onaptests/templates/reporting/reporting.html.j2 @@ -0,0 +1,43 @@ +{% extends "base.html.j2" %} +{% block title %}Summary{% endblock %} +{% block content %} + {{ summary('Results', "", [ + { 'title': 'Pythonsdk Tests', 'failing': (failing_steps | length), 'total': (steps | length)}, + ]) + }} + +
+
+

+ {{ usecase }} +

+ Description: {{ details }} +
+ Components: {{ components }} +
+ Logs + +
+ + + + + + + + + {% for step,value in steps.items() %} + + + + + {% endfor %} + +
NameStatus
+ {{ step }} + + {{ value }} +
+
+
+{% endblock %} -- cgit 1.2.3-korg