Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Query Library: keep_previous_results fails when link property mappings return inconsistent results #164

Closed
anish-mudaraddi opened this issue Oct 25, 2023 · 1 comment

Comments

@anish-mudaraddi
Copy link
Collaborator

when we chain queries using:
then("query", keep_previous_results=True)

if the two query link_prop mappings return different values there's no way to link the two queries together.
Right now this fails noisily but if it's a common occurance - we may want to return "Not Found" instead

Change query_output._parse_forwarded_outputs to this:

def _parse_forwarded_outputs(
  self, openstack_resource: OpenstackResourceObj
) -> Dict[str, str]:
  """
  Generates a dictionary of forwarded outputs for the item given
  :param openstack_resource: openstack resource item to parse forwarded outputs for
  """
    forwarded_output_dict = {}
    for grouped_property, outputs in self.forwarded_outputs.items():
        prop_val = self._parse_property(grouped_property, openstack_resource)
  
        # this "should not" error because forwarded outputs should always be a super-set
        # but sometimes resolving the property fails for whatever reason
        # in this case just copy all the keys in one of the dictionaries in the list
        # since they should be equal and set the values to "Not Found"

    try:
        output_list = outputs[prop_val]
        # should only ever contain one element since it's grouped by a unique id
        forwarded_output_dict.update(output_list[0])
    except KeyError as exp:
        first_output_entry = list(outputs.values())[0][0]
        forwarded_output_dict.update(
            {key: "Not Found" for key in list(first_output_entry.keys())}
        )
    return forwarded_output_dict

and equivalent test

def test_parse_forwarded_prop_value_not_found(instance):
    """
    Tests parse_forwarded_prop() method
    where a prop_value is not found, set to "Not Found"
    """
    forwarded_entry = {"forwarded-prop1": "val1", "forwarded-prop2": "val2"}

    instance.update_forwarded_outputs("prop1", {"prop-val1": [forwarded_entry]})
    with patch(
        "openstack_query.query_blocks.query_output.QueryOutput._parse_property"
    ) as mock_parse_property:
        mock_parse_property.return_value = "invalid-prop"
        # pylint:disable=protected-access
        res = instance._parse_forwarded_outputs("obj1")

    mock_parse_property.assert_called_once_with("prop1", "obj1")
    assert res == {key: "Not Found" for key in forwarded_entry}
@anish-mudaraddi
Copy link
Collaborator Author

going to keep this as failing noisily for now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant