diff options
author | Michal Jagiello <michal.jagiello@t-mobile.pl> | 2022-02-04 14:00:57 +0000 |
---|---|---|
committer | Michal Jagiello <michal.jagiello@t-mobile.pl> | 2022-02-08 08:46:36 +0000 |
commit | 0384b57fa175d45f5c3947adb488ef572669bce1 (patch) | |
tree | 9c4d4ecf9693475a4e7b053338760cddc31606e3 /onap_data_provider | |
parent | e9dbe96626c23204bac7426bba69b4e2aedfbd8f (diff) |
Declare nested inputs in services
Distinguish service and xNFs inputs in schema
Add 'coverage' env in tox
Issue-ID: INT-2060
Signed-off-by: Michal Jagiello <michal.jagiello@t-mobile.pl>
Change-Id: I15c4ac2b2ddb28c938044b7e0a130a1644146f8b
Diffstat (limited to 'onap_data_provider')
-rw-r--r-- | onap_data_provider/resources/sdc_properties_mixins.py | 88 | ||||
-rw-r--r-- | onap_data_provider/resources/xnf_resource.py | 2 | ||||
-rw-r--r-- | onap_data_provider/schemas/infra_1_1.schema | 30 |
3 files changed, 89 insertions, 31 deletions
diff --git a/onap_data_provider/resources/sdc_properties_mixins.py b/onap_data_provider/resources/sdc_properties_mixins.py index 9a2b625..28d06c3 100644 --- a/onap_data_provider/resources/sdc_properties_mixins.py +++ b/onap_data_provider/resources/sdc_properties_mixins.py @@ -14,15 +14,17 @@ See the License for the specific language governing permissions and limitations under the License. """ -from typing import Any, List, Union +import logging +from abc import ABC +from typing import Any, Dict, List, Union from onapsdk.exceptions import SDKException, ValidationError, ParameterError # type: ignore from onapsdk.sdc.component import Component # type: ignore -from onapsdk.sdc.properties import Property # type: ignore +from onapsdk.sdc.properties import NestedInput, Property # type: ignore from onapsdk.sdc.sdc_resource import SdcResource # type: ignore -class SdcPropertiesMixins: +class SdcPropertiesMixins(ABC): """Mixins class for properties handling. Mixin class for propoerties preparation for SdcResources and Components. @@ -66,20 +68,67 @@ class SdcPropertiesMixins: f"for resourceclass '{str(propresource.__class__.__name__)}' is not provided yet!" ) + def declare_input(self, propresource: Union[SdcResource, Component], property_data: Dict[str, Any]) -> None: + """Declare input. + + Method to get a property from a component and create an input for it. + + Args: + propresource (Union[SdcResource, Component]): Resource to create an input + property_data (Dict[str, Any]): Data used to create an input + + Raises: + ValidationError: Provided data is invalid - missing property type + ParameterError: Declaring input returns an SDC error + + """ + proptype = property_data.get("type") + if proptype is None: + raise ValidationError( + "New input '{0}' is missing a type!".format( + str(property_data["name"]) + ) + ) + + property = Property( + name=property_data["name"], + property_type=proptype, + value=property_data.get("value"), + ) + try: + propresource.add_property(property) + propresource.declare_input(property) + except SDKException: + raise ParameterError( + f"Creation of new input '{str(property_data['name'])}' is not provided yet!" + ) + + def declare_nested_input(self, propresource: Union[SdcResource, Component], data: Dict[str, Any]) -> None: + """Declare nested input. + + Args: + propresource (SdcResource): Resource for which nested input is going to be declared + data (Dict[str, Any]): Data used for input creation. + """ + if not isinstance(propresource, SdcResource): + logging.error("Can't declare nested inputs for components!") + return + comp: Component = propresource.get_component_by_name(data["resource"]) + propresource.declare_input(NestedInput(comp.sdc_resource, comp.sdc_resource.get_input(data["name"]))) + def set_inputs( - self, propresource: Union[SdcResource, Component], data: List[Any] + self, propresource: Union[SdcResource, Component], data: List[Dict[str, Any]] ) -> None: """Set inputs of an SdcResource. Args: sdcresource (SdcResource): the SdcResource the inputs should belong to data (Dict[str, Any]): Data needed to create resource. - - Raises ValidationError """ - for property_data in data: - - if any( + for property_data in data: # type: Dict[str, Any] + if property_data.get("nested-input"): + self.declare_nested_input(propresource, property_data) + elif any( (prop.name == property_data["name"] for prop in propresource.inputs) ): propresource.set_input_default_value( @@ -87,23 +136,4 @@ class SdcPropertiesMixins: property_data.get("value"), ) else: - proptype = property_data.get("type") - if proptype is None: - raise ValidationError( - "New input '{0}' is missing a type!".format( - str(property_data["name"]) - ) - ) - - property = Property( - name=property_data["name"], - property_type=proptype, - value=property_data.get("value"), - ) - try: - propresource.add_property(property) - propresource.declare_input(property) - except SDKException: - raise ParameterError( - f"Creation of new input '{str(property_data['name'])}' is not provided yet!" - ) + self.declare_input(propresource, property_data) diff --git a/onap_data_provider/resources/xnf_resource.py b/onap_data_provider/resources/xnf_resource.py index efede03..63b01dc 100644 --- a/onap_data_provider/resources/xnf_resource.py +++ b/onap_data_provider/resources/xnf_resource.py @@ -24,7 +24,7 @@ from onapsdk.sdc.properties import Property # type: ignore from .sdc_properties_mixins import SdcPropertiesMixins -class XnfResource(ABC, SdcPropertiesMixins): +class XnfResource(SdcPropertiesMixins, ABC): """Xnf resource class. Network function base class. diff --git a/onap_data_provider/schemas/infra_1_1.schema b/onap_data_provider/schemas/infra_1_1.schema index 7514acc..063e78a 100644 --- a/onap_data_provider/schemas/infra_1_1.schema +++ b/onap_data_provider/schemas/infra_1_1.schema @@ -281,7 +281,35 @@ properties: - required: - name - value - inputs: *props + inputs: &inputs + type: array + items: + type: object + properties: + name: + type: string + type: + type: string + nested-input: + type: boolean + resource: + type: string + value: + type: + - string + - number + - boolean + anyOf: + - required: + - name + - type + - required: + - name + - value + - required: + - name + - nested-input + - resource required: - name required: |