Bug 1381129

Summary: Post & GET /api/v2/discovery_rules/ doesn't return all attributes like locations, organizations
Product: Red Hat Satellite Reporter: Sachin Ghai <sghai>
Component: Discovery PluginAssignee: Lukas Zapletal <lzap>
Status: CLOSED WONTFIX QA Contact: Jan Hutař <jhutar>
Severity: high Docs Contact:
Priority: high    
Version: 6.3.0CC: jcallaha, jhutar, oshtaier, rabajaj
Target Milestone: UnspecifiedKeywords: Triaged
Target Release: Unused   
Hardware: Unspecified   
OS: Unspecified   
URL: http://projects.theforeman.org/issues/19647
Whiteboard:
Fixed In Version: Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2018-09-04 17:44:22 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Sachin Ghai 2016-10-03 07:52:27 UTC
Description of problem:

When we create discovery rule with org and location, post request failed with error:

MissingValueError: Cannot find a value for the "location" field. Searched for keys named ('location_ids', 'location', 'locations'), but available keys are [u'name', u'updated_at', u'created_at', u'hostname', u'enabled', u'hostgroup_id', u'max_count', u'priority', 'search_', u'id'].


In [13]: attrs1 = DiscoveryRule(server_config).create_json(create_missing=True)

In [14]: attrs1.keys()
Out[14]: 
[u'search',
 u'name',
 u'updated_at',
 u'created_at',
 u'hostname',
 u'enabled',
 u'hostgroup_id',
 u'max_count',
 u'priority',
 u'id']

In [15]: attrs2 = DiscoveryRule(server_config, id=attrs1['id']).read_json()

In [16]: attrs2.keys()
Out[16]: 
[u'organizations',
 u'search',
 u'name',
 u'hosts_limit',
 u'hostname',
 u'enabled',
 u'hostgroup_id',
 u'locations',
 u'priority',
 u'hostgroup_name',
 u'hosts',
 u'id']


 >>> set(attrs2.keys()) - set(attrs1.keys())  # Keys In GET response, but not POST.

Out[18]: {u'hostgroup_name', u'hosts', u'hosts_limit', u'locations', u'organizations'}



Version-Release number of selected component (if applicable):
sat6.3 snap2

How reproducible:


Steps to Reproduce:
1. Make an HTTP POST call to /api/v2/discovery_rules/ with organization & location
2. Look at the keys of the JSON response payload.

Actual results:


Expected results:


Additional info:

Comment 1 Sachin Ghai 2016-10-03 09:49:44 UTC
Similar issue with PUT requests..

MissingValueError: Cannot find a value for the "location" field. Searched for keys named ('location_ids', 'location', 'locations'), but available keys are [u'name', u'updated_at', u'created_at', u'hostname', u'enabled', u'hostgroup_id', u'max_count', u'priority', 'search_', u'id'].

Comment 3 Lukas Zapletal 2017-05-24 07:52:58 UTC
Now we show it in Discovery 9.1.

$ curl-foreman /api/v2/discovery_rules/
{
    "total": 1,
    "subtotal": 1,
    "page": 1,
    "per_page": 100,
    "search": null,
    "sort": {
        "by": null,
        "order": null
    },
    "results": [
        {
            "name": "always",
            "enabled": true,
            "hostgroup_id": 1,
            "hostgroup_name": "CentOS 7.0",
            "hostname": "somehost-<%= rand(999999) %>",
            "priority": 200,
            "search": "cpu_count > 0",
            "hosts_limit": 0,
            "id": 1,
            "hosts": [

            ],
            "organizations": [
                {
                    "id": 1,
                    "name": "MyOrg"
                },
                {
                    "id": 4,
                    "name": "OtherOrg"
                }
            ],
            "locations": [
                {
                    "id": 2,
                    "name": "MyLoc"
                },
                {
                    "id": 3,
                    "name": "SecondLoc"
                }
            ]
        }
    ]
}

Comment 4 Satellite Program 2017-05-30 12:00:40 UTC
Moving this bug to POST for triage into Satellite 6 since the upstream issue http://projects.theforeman.org/issues/19647 has been resolved.

Comment 7 Jan Hutař 2017-09-22 14:44:30 UTC
So, documentation says both "discovery_rule[location_ids]" and "discovery_rule[organization_ids]" are optional for POST, but they seem to be required. Created bug 1494585 for that.

Comment 12 Satellite Program 2017-10-09 08:01:08 UTC
Upstream bug assigned to lzap

Comment 13 Bryan Kearney 2018-09-04 17:44:22 UTC
Thank you for your interest in Satellite 6. We have evaluated this request, and we do not expect this to be implemented in the product in the foreseeable future. We are therefore closing this out as WONTFIX. If you have any concerns about this, please feel free to contact Rich Jerrido or Bryan Kearney. Thank you.