Coverage for /opt/conda/envs/apienv/lib/python3.10/site-packages/daiquiri/core/hardware/daiquiri/__init__.py: 57%
21 statements
« prev ^ index » next coverage.py v7.6.5, created at 2024-11-15 02:12 +0000
« prev ^ index » next coverage.py v7.6.5, created at 2024-11-15 02:12 +0000
1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3from marshmallow import INCLUDE, ValidationError, fields
5from daiquiri.core.hardware.abstract import ProtocolHandler
6from daiquiri.core.hardware.daiquiri.object import DaiquiriObject
7from daiquiri.core.schema.hardware import HOConfigSchema
8from daiquiri.core.exceptions import InvalidYAML
9from daiquiri.core.utils import loader
11import logging
13logger = logging.getLogger(__name__)
16class DaiquiriHOConfig(HOConfigSchema):
17 type = fields.Str(required=True, metadata={"description": "The object type"})
20class DaiquiriHandler(ProtocolHandler):
21 def get(self, **kwargs) -> DaiquiriObject:
22 try:
23 kwargs = DaiquiriHOConfig().load(kwargs, unknown=INCLUDE)
24 except ValidationError as err:
25 raise InvalidYAML(
26 {
27 "message": "Daiquiri hardware object definition is invalid",
28 "file": "hardware.yml",
29 "obj": kwargs,
30 "errors": err.messages,
31 }
32 ) from err
34 try:
35 return loader(
36 "daiquiri.core.hardware.daiquiri",
37 "",
38 kwargs["type"],
39 app=self._app,
40 **kwargs
41 )
42 except ModuleNotFoundError:
43 logger.error(
44 "Could not find class for daiquiri object {type}".format(
45 type=kwargs["type"]
46 )
47 )
48 raise