Bug 1659899 - Error related to `towhat` while creating Policies via API
Summary: Error related to `towhat` while creating Policies via API
Keywords:
Status: CLOSED NOTABUG
Alias: None
Product: Red Hat CloudForms Management Engine
Classification: Red Hat
Component: API
Version: 5.10.0
Hardware: Unspecified
OS: Unspecified
high
high
Target Milestone: GA
: 5.10.z
Assignee: kwalsh
QA Contact: Parthvi Vala
Red Hat CloudForms Documentation
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2018-12-17 07:15 UTC by Parthvi Vala
Modified: 2019-01-25 19:49 UTC (History)
4 users (show)

Fixed In Version:
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2019-01-04 06:40:30 UTC
Category: ---
Cloudforms Team: CFME Core
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)

Description Parthvi Vala 2018-12-17 07:15:40 UTC
Description of problem:
Sending an API request to create policy gives error - "Towhat is not included in the list", even though it is passed in the query.

Version-Release number of selected component (if applicable):


How reproducible:
Always

Steps to Reproduce:
1. Send a create Policies request via API
Request: POST /api/policies
Query: 
{
    "action": "create",
    "resources": [{
            "name": "test_policy_cNUnZ",
            "conditions_ids": ["3", "4"],
            "towhat": "ManageIQ::Providers::Redhat::InfraManager",
            "policy_contents": [{
                "event_id": 2,
                "actions": [{
                    "opts": {
                        "qualifier": "failure"
                    },
                    "action_id": 1
                }]
            }],
            "mode": "compliance",
            "description": "Test Policy cNUnZ"
        }, {
            "name": "test_policy_swyOR",
            "conditions_ids": ["3", "4"],
            "towhat": "ManageIQ::Providers::Redhat::InfraManager",
            "policy_contents": [{
                "event_id": 2,
                "actions": [{
                    "opts": {
                        "qualifier": "failure"
                    },
                    "action_id": 1
                }]
            }],
            "mode": "compliance",
            "description": "Test Policy swyOR"
        },
        {
            "name": "test_policy_axyOP",
            "conditions_ids": ["3", "4"],
            "towhat": "ManageIQ::Providers::Redhat::InfraManager",
            "policy_contents": [{
                "event_id": 2,
                "actions": [{
                    "opts": {
                        "qualifier": "failure"
                    },
                    "action_id": 1
                }]
            }],
            "mode": "compliance",
            "description": "Test Policy axyOP"
        }
    ]
}
Actual results:
Response:
{
	"error": {
		"kind": "bad_request",
		"message": "Could not create the new policy - Validation failed: MiqPolicy: Towhat is not included in the list",
		"klass": "Api::BadRequestError"
	}
}

Expected results:
Response:
{
	"name": "policies",
	"count": 3,
	"subcount": 3,
	"pages": 1,
	"resources": [
		{
			"href": "https://<ip_address>/api/policies/1"
		},
		{
			"href": "https://<ip_address>/api/policies/2"
		},
		{
			"href": "https://<ip_address>/api/policies/3"
		}
	],
	"actions": [
        ...
	],
	"links": {
		"self": "https://<ip_address>/api/policies?offset=0",
		"first": "https://<ip_address>/api/policies?offset=0",
		"last": "https://<ip_address>/api/policies?offset=0"
	}
}
Additional info:
Works well on 5.9.

Comment 4 Joe Rafaniello 2018-12-19 17:33:48 UTC
Keith, can you take a look at this one?


First of all, you want to install miqversions so you can see that 5.9 is roughly upstream gaprindashvili and 5.10 is roughly hammer.

https://github.com/chrisarcand/miqversions

With that info, you can see that we added a validation change to miq_policy.rb

12:20:29 ~/Code/manageiq (master) (2.4.4) + git log upstream/gaprindashvili...upstream/hammer app/models/miq_policy.rb

commit 28ab0177beb315a791af3d60a7ca5ae1cfc5c29a
Author: Brandon Dunne <brandondunne>
Date:   Fri Sep 28 14:38:24 2018 -0400

    Merge pull request #18032 from jvlcek/bz_1435780_tow_hat_validations

    Validate towhat policy field

    (cherry picked from commit 52704166f4dc48ccc2ced8c6bac0e8001e8d786f)

    https://bugzilla.redhat.com/show_bug.cgi?id=1435780

...


Here: https://github.com/ManageIQ/manageiq/pull/18032

Let me know if you need help recreating the problem.


Note You need to log in before you can comment on or make changes to this bug.