Example #1
0
def test_component_property_set_value(mock_component_properties):
    mock_sdc_resource = mock.MagicMock()
    service = Service(name="test")
    service.unique_identifier = "toto"
    component = Component(created_from_csar=False,
                          actual_component_uid="123",
                          unique_id="123",
                          normalized_name="123",
                          name="123",
                          origin_type="123",
                          customization_uuid="123",
                          tosca_component_name="123",
                          component_name="123",
                          component_uid="123",
                          component_version="123",
                          sdc_resource=mock_sdc_resource,
                          parent_sdc_resource=service)
    mock_component_properties.return_value = [
        ComponentProperty(unique_id="123",
                          property_type="string",
                          name="test_property",
                          component=component)
    ]
    with pytest.raises(AttributeError):
        component.get_property(property_name="non_exists")
    prop1 = component.get_property(property_name="test_property")
    assert prop1.name == "test_property"
    assert prop1.unique_id == "123"
    assert prop1.property_type == "string"
    assert not prop1.value

    prop1.value = "123"
    mock_sdc_resource.send_message_json.assert_called_once()
Example #2
0
    def components(self) -> Iterator[Component]:
        """Resource components.

        Iterate resource components.

        Yields:
            Component: Resource component object

        """
        for component_instance in self.send_message_json(\
                "GET",
                f"Get {self.name} resource inputs",
                f"{self.resource_inputs_url}/filteredDataByParams?include=componentInstances",
                exception=AttributeError).get("componentInstances", []):
            sdc_resource: "SdcResource" = SdcResource.import_from_sdc(self.send_message_json(\
                "GET",
                f"Get {self.name} component's SDC resource metadata",
                (f"{self.base_front_url}/sdc1/feProxy/rest/v1/catalog/resources/"
                 f"{component_instance['actualComponentUid']}/"
                 "filteredDataByParams?include=metadata"),
                exception=AttributeError)["metadata"])
            yield Component.create_from_api_response(
                api_response=component_instance,
                sdc_resource=sdc_resource,
                parent_sdc_resource=self)
Example #3
0
def test_component_properties():
    sdc_resource = mock.MagicMock()
    service = Service(name="test")
    service.unique_identifier = "toto"

    component = Component(created_from_csar=False,
                          actual_component_uid="123",
                          unique_id="123",
                          normalized_name="123",
                          name="123",
                          origin_type="123",
                          customization_uuid="123",
                          tosca_component_name="123",
                          component_name="123",
                          component_uid="123",
                          component_version="123",
                          sdc_resource=sdc_resource,
                          parent_sdc_resource=service)
    sdc_resource.send_message_json.return_value = {}
    assert not len(list(component.properties))

    sdc_resource.send_message_json.return_value = COMPONENT_PROPERTIES
    properties = list(component.properties)
    assert len(properties) == 2
    prop1, prop2 = properties

    assert prop1.unique_id == "3d9a184f-4268-4a0e-9ddd-252e49670013.vf_module_id"
    assert prop1.property_type == "string"
    assert prop1.name == "vf_module_id"
    assert prop1.value is None

    assert prop2.unique_id == "74f79006-ae56-4d58-947e-6a5089000774.skip_post_instantiation_configuration"
    assert prop2.property_type == "boolean"
    assert prop2.name == "skip_post_instantiation_configuration"
    assert prop2.value == "true"
def test_sdc_component_delete():
    mock_sdc_resource = mock.MagicMock()
    mock_parent_sdc_resource = mock.MagicMock()
    mock_parent_sdc_resource.resource_inputs_url = "http://test.onap.org"
    component = Component(created_from_csar=False,
                          actual_component_uid="123",
                          unique_id="456",
                          normalized_name="789",
                          name="test_component",
                          origin_type="test-origin-type",
                          customization_uuid="098",
                          component_uid="765",
                          component_version="432",
                          tosca_component_name="test-tosca-component-name",
                          component_name="test-component-name",
                          sdc_resource=mock_sdc_resource,
                          parent_sdc_resource=mock_parent_sdc_resource,
                          group_instances=None)
    component.delete()
    mock_sdc_resource.send_message_json.assert_called_once_with(
        "DELETE", "Delete test_component component",
        f"http://test.onap.org/resourceInstance/{component.unique_id}")
    def assign_properties_to_component(
            self, component: Component,
            component_properties: Dict[str, Any]) -> None:
        """Assign properties to component.

        Args:
            component (Component): Component to which properites are going to be assigned
            component_properties (Dict[str, Any]): Properties dictionary

        """
        for property_name, property_value in component_properties.items():
            prop: ComponentProperty = component.get_property(property_name)
            prop.value = property_value
Example #6
0
def test_get_component(mock_components):
    sdc_resource = SdcResource()

    mock_components.return_value = [
        Component(created_from_csar=False,
                  actual_component_uid="123",
                  unique_id="123",
                  normalized_name="123",
                  name="123",
                  origin_type="123",
                  customization_uuid="123",
                  tosca_component_name="123",
                  component_name="123",
                  component_uid="123",
                  component_version="123",
                  sdc_resource=SdcResource(name="test"),
                  parent_sdc_resource=sdc_resource)
    ]
    assert sdc_resource.get_component(SdcResource(name="test"))
    with pytest.raises(AttributeError):
        sdc_resource.get_component(SdcResource(name="test2"))