Bug 1614768

Summary: [RFE] API Support for easier use of Smart-Class Param Overrides
Product: Red Hat Satellite Reporter: Satellite Program <pm-sat>
Component: APIAssignee: orabin
Status: CLOSED ERRATA QA Contact: Jitendra Yejare <jyejare>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: 6.3.0CC: akarsale, apatel, bkearney, ehelms, mhulan, orabin, pcreech
Target Milestone: 6.5.0Keywords: FutureFeature, Triaged
Target Release: Unused   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: foreman-1.20.1.15-1 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2019-05-14 12:37:41 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Satellite Program 2018-08-10 11:46:06 UTC
Similiar to #15003 around using Hammer to remove smart-class param overrides to hosts.

Currently there is a trivial API call to add an override by FQDN for a specific host - this is very useful for us;

<pre>
-X POST --/api/v2/puppetclasses/:puppetclass_name/smart_class_parameters/:parameter_name/override_values -d '{"match":"fqdn=:hostname","value":":parameter_value}"}}'
</pre>

e.g
<pre>

--/api/v2/puppetclasses/apache::vhost/smart_class_parameters/port/override_values -d '{"match":"fqdn=myhost1","value":"4055"}}'
</pre>

this is really nice and clean way of assigning values to hosts on a single basis, particularly when interfacing with external systems.

However when it comes to changing or removing this override, the calls are more elaborate, as you need to know both the specific numeric ID of the parameter, as well as the numeric ID of the *override itself*.

e.g

<pre>
-X PUT --/api/v2/smart_class_parameters/412/override_values/1021 -d '{"override_value":{"match":"fqdn=myhost1","value":"4056"}}'
-X DELETE --/api/v2/smart_class_parameters/412/override_values/1021
</pre>

This means external systems need to cache a list potentially of *all* override ids, parse and choose the related one. 

Hence I would like to be able to edit using the same call as adding an override, or equivalent functionality for delete, eg.

<pre>
-X PUT --/api/v2/puppetclasses/apache::vhost/smart_class_parameters/port/override_values -d '{"match":"fqdn=host1","value":"4057"}}'
</pre>

Comment 1 Satellite Program 2018-08-10 11:46:11 UTC
Created from redmine issue https://projects.theforeman.org/issues/22090

Comment 2 Satellite Program 2018-08-10 11:46:15 UTC
Upstream bug assigned to None

Comment 3 Satellite Program 2018-08-10 11:47:38 UTC
Moving this bug to POST for triage into Satellite 6 since the upstream issue https://projects.theforeman.org/issues/22090 has been resolved.

Comment 6 Jitendra Yejare 2019-01-29 13:28:51 UTC
Hi Marek,

I am trying to verify this bug but it seems to be not working. The DEV is from the community and hence I am not getting the help required.

I tried : (Update override, without override parameter id)

curl -u admin:changeme -X PUT -d '{"match":"os=RedHat 7.6","value":"overriden_hogaye_firse"}' --header "Content-Type:application/json" https://qeblade36.rhq.lab.eng.bos.redhat.com/api/v2/puppetclasses/1/smart_class_parameters/41/override_values

I am getting error : Wrong URL to PUT to.

Again I tried, (sc-param name instead of id)

curl -u admin:changeme -X PUT -d '{"match":"os=RedHat 7.6","value":"overriden_hogaye_firse"}' --header "Content-Type:application/json" https://qeblade36.rhq.lab.eng.bos.redhat.com/api/v2/puppetclasses/1/smart_class_parameters/content/override_values

Still, I am getting the same error, the Wrong URL to PUT to.


What am I doing wrong? Need Help

Comment 7 Marek Hulan 2019-01-29 14:46:43 UTC
replied via email meanwhile, the change is that matcher can be used instead of override id, please see the email for an example

Comment 8 Jitendra Yejare 2019-01-30 07:36:33 UTC
FailedQA!


Steps:

1. Attempt to update the override value by PUTing on satellite with overrides matcher instead of its id. e.g:
# curl -u admin:changeme -X PUT -d '{"value":"overridened3"}' --header "Content-Type:application/json" "https://qeblade36.rhq.lab.eng.bos.redhat.com/api/v2/puppetclasses/1/smart_class_parameters
/3/override_values/os=rhel7.6"


Observation and Logs:

PUT request fails if the matcher attribute name has space or dot(.) character.


# curl -X PUT -d '{"value":"overridened3"}' --header "Content-Type:application/json" "https://<server_url>/api/v2/puppetclasses/1/smart_class_parameters/3/override_values/os=rhel7.6"

{
  "error": {"message":"Resource override_value not found by id 'os=rhel7'"
}

# curl -X PUT -d '{"value":"overridened3"}' --header "Content-Type:application/json" "https://<server_url>/api/v2/puppetclasses/1/smart_class_parameters/3/override_values/os=rhel 7"
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>400 Bad Request</title>
</head><body>
<h1>Bad Request</h1>
<p>Your browser sent a request that this server could not understand.<br />
</p>
</body></html>

Comment 11 Bryan Kearney 2019-03-05 11:02:44 UTC
Upstream bug assigned to orabin

Comment 12 Bryan Kearney 2019-03-05 11:02:46 UTC
Upstream bug assigned to orabin

Comment 15 Jitendra Yejare 2019-03-18 11:46:33 UTC
Verified!

@Satellite 6.5 snap 20



Steps and Observation:


1. With Dot(.) character:
# curl -X PUT -d '{"value":"overridened"}' --header "Content-Type:application/json" "https://sat.url/api/v2/puppetclasses/1/smart_class_parameters/3/override_values/os=rhel7.6"
{"created_at":"2019-03-18 10:05:47 UTC","updated_at":"2019-03-18 10:08:09 UTC","id":21,"match":"os=rhel7.6","value":"overridened","omit":false,"use_puppet_default":false}

2. With Space Character:
# curl -X PUT -d '{"value":"overridened2"}' --header "Content-Type:application/json" https://sat.url/api/v2/puppetclasses/1/smart_class_parameters/3/override_values/os=rhel%207
{"created_at":"2019-03-18 10:05:47 UTC","updated_at":"2019-03-18 11:43:53 UTC","id":21,"match":"os=rhel 7","value":"overridened2","omit":false,"use_puppet_default":false}


Verified!

Comment 17 errata-xmlrpc 2019-05-14 12:37:41 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHSA-2019:1222