Code Coverage

Cobertura Coverage Report > osm_lcm >

prometheus.py

Trend

File Coverage summary

NameClassesLinesConditionals
prometheus.py
100%
1/1
82%
9/11
100%
0/0

Coverage Breakdown by Class

NameLinesConditionals
prometheus.py
82%
9/11
N/A

Source

osm_lcm/prometheus.py
1 # -*- coding: utf-8 -*-
2
3 ##
4 # Copyright 2020 Telefonica S.A.
5 #
6 # Licensed under the Apache License, Version 2.0 (the "License"); you may
7 # not use this file except in compliance with the License. You may obtain
8 # a copy of the License at
9 #
10 #         http://www.apache.org/licenses/LICENSE-2.0
11 #
12 # Unless required by applicable law or agreed to in writing, software
13 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15 # License for the specific language governing permissions and limitations
16 # under the License.
17 ##
18
19 1 import yaml
20 1 from osm_lcm.lcm_utils import LcmException
21 1 from jinja2 import Template, TemplateError, TemplateNotFound, TemplateSyntaxError
22
23 1 __author__ = "Alfonso Tierno <alfonso.tiernosepulveda@telefonica.com>"
24
25
26 1 def parse_job(job_data: str, variables: dict) -> dict:
27 1     try:
28 1         template = Template(job_data)
29 1         job_parsed = template.render(variables or {})
30 1         return yaml.safe_load(job_parsed)
31 0     except (TemplateError, TemplateNotFound, TemplateSyntaxError) as e:
32         # TODO yaml exceptions
33 0         raise LcmException(
34             "Error parsing Jinja2 to prometheus job. job_data={}, variables={}. Error={}".format(
35                 job_data, variables, e
36             )
37         )