mcp-agent mode for mcp-checker with web-info and REST API
New:
- agent index page serving on 0.0.0.0:8765
- REST API with modular approach to modules
- 'fio' module working via thread-safe Thread able to return
real-time info on its status
- 'fio' module scheduled run option
- ability to preserve multiple testrun results while active
- dockerfile for agent image
Fixed:
- Network report fixes to work on Kube envs
- Fixed function for running commands inside daemonset pods
Related-PROD: PROD-36669
Change-Id: I57e73001247af9187680bfc5744590eef219d93c
diff --git a/cfg_checker/helpers/falcon_jinja2/template.py b/cfg_checker/helpers/falcon_jinja2/template.py
new file mode 100644
index 0000000..cb858ff
--- /dev/null
+++ b/cfg_checker/helpers/falcon_jinja2/template.py
@@ -0,0 +1,85 @@
+# https://github.com/myusko/falcon-jinja
+import falcon
+from falcon.response import Response
+from jinja2 import Environment, FileSystemLoader
+from jinja2.exceptions import TemplateNotFound
+
+__all__ = ['FalconTemplate']
+
+
+class FalconTemplateNotFound(Exception):
+ pass
+
+
+class FalconTemplate:
+ """
+ Args:
+ path (str): Name of an directory where HTML files defined.
+ Attributes:
+ _env (jinja2.Environment): Jinja component which shared
+ variables like configuration and etc.
+ template_path (str): Name of folder where all
+ HTML files are defined.
+ loader (jinja2.FileSystemLoader): Jinja2 class which loaded
+ HTML template from filesystem.
+ """
+
+ BASE_FOLDER = 'templates'
+
+ def __init__(self, path: str = None):
+ self.template_path = path or self.BASE_FOLDER
+ self.loader = FileSystemLoader(self.template_path)
+ self._env = Environment(loader=self.loader)
+
+ @staticmethod
+ def __get_response(objects: tuple):
+ """Retrieve falcon's Response object
+ Args:
+ objects (tuple): An list with falcon.Request,
+ falcon.Response, and other arguments.
+ Returns:
+ An falcon.Response object if it there
+ otherwise False.
+ """
+ for response in objects:
+ if isinstance(response, Response):
+ return response
+ return False
+
+ def _make_template(self, template: str, context: dict):
+ """Makes a jinja template, and rendered passed context
+ Args:
+ template (str): Name of HTML file which will be rendered.
+ context (dict): An dictionary with
+ a response context.
+ Returns:
+ A string representation of HTML content
+ """
+ try:
+ template = self._env.get_template(template)
+ except TemplateNotFound:
+ raise FalconTemplateNotFound(
+ 'Template {} not found '
+ 'in {} folder'.format(template, self.template_path)
+ )
+ return template.render(**context)
+
+ def render(self, template: str):
+ """Decorator which renders HTML content
+ Args:
+ template (str): HTML file for which will
+ be rendered HTML content
+ """
+ def render_template(func):
+ def wrapper(*args, **kwargs):
+
+ response = self.__get_response(args)
+ func(*args, **kwargs)
+
+ response.content_type = falcon.MEDIA_HTML
+ response.status = falcon.HTTP_200
+ response.body = self._make_template(
+ template, response.context
+ )
+ return wrapper
+ return render_template