Project

General

Profile

Actions

Bug #30760

open

Weird behaviour when Importing the report template to Foreman via API

Added by Dominik Matoulek over 3 years ago. Updated over 3 years ago.

Status:
New
Priority:
Normal
Category:
Reporting
Target version:
-
Difficulty:
Triaged:
Yes
Fixed in Releases:
Found in Releases:

Description

Cloned from https://bugzilla.redhat.com/show_bug.cgi?id=1778402

Description of problem:
Once we have already the exported report template, we would like to import it to Satellite. Via API, after imported the code will work, however, when editing the code we will see a single long line, instead of our indented code.

How reproducible:
100%

Steps to Reproduce:
1. Export the report template (can be via webUI) and save the file
2. Create a small json to import and the content will be like below
---
$ cat new.json {
"name": "Hosts - complete list",
"template": "
<% load_hosts(search: input('host')).each_record do |host| >
<
#
name: Hosts - complete list
snippet: false
template_inputs:
name: host
required: false
input_type: user
advanced: false
value_type: plain
resource_type: Katello::ActivationKey
model: ReportTemplate
>
<

report_row(
'Server FQND': host.name
)
>
<
end ->
<
= report_render %>
"
}
--

3. Importing it.
---
[user@terminal ~]$ curl -s -u admin:foreman -d @new.json --header "Content-Type:application/json" -X POST -k HOST/api/report_templates {"template":"<% load_hosts(search: input('host')).each_record do |host| ><#name: Hosts - complete listsnippet: falsetemplate_inputs: name: host required: false input_type: user advanced: false value_type: plain resource_type: Katello::ActivationKeymodel: ReportTemplate%><% report_row( 'Server FQND': host.name )-%><% end ><= report_render %>","default":false,"snippet":false,"locked":false,"created_at":"2019-11-30 17:21:35 UTC","updated_at":"2019-11-30 17:21:35 UTC","name":"Hosts - complete list","id":165,"locations":[],"organizations":[]}[wpinheir@ironman ~]$
--

At this moment we can see the report template was imported, in order to run this, will be necessary to create an input but after that, the report output is fine.

Actual results:

Report is ok BUT the code is in a single line. Let's check the curl output
---
[user@terminal ~]$ curl -s -u admin:foreman -X GET -k HOST/api/report_templates/165 | json_reformat {
"template": "<% load_hosts(search: input('host')).each_record do |host| ><#name: Hosts - complete listsnippet: falsetemplate_inputs: name: host required: false input_type: user advanced: false value_type: plain resource_type: Katello::ActivationKeymodel: ReportTemplate%><% report_row( 'Server FQND': host.name )-%><% end -><= report_render %>",
"default": false,
"snippet": false,
"locked": false,
"created_at": "2019-11-30 17:21:35 UTC",
"updated_at": "2019-11-30 17:21:35 UTC",
"name": "Hosts - complete list",
"id": 165,
"locations": [

],
"organizations": [
]
}
[user@terminal ~]$
---

Expected results:

At this time, I just updated the code with the correct one (new lines, indentations, etc) and rerun the curl
---
[user@terminal ~]$ curl -s -u admin:foreman -X GET -k HOST/api/report_templates/165 | json_reformat {
"template": "<% load_hosts(search: input('host')).each_record do |host| >\n<#\nname: Hosts - complete list\nsnippet: false\ntemplate_inputs:\n name: host\n required: false\n input_type: user\n advanced: false\n value_type: plain\n resource_type: Katello::ActivationKey\nmodel: ReportTemplate\n%>\n<%\n report_row(\n 'Server FQND': host.name\n )\n-%>\n<% end ->\n<= report_render %>",
"default": false,
"snippet": false,
"locked": false,
"created_at": "2019-11-30 17:21:35 UTC",
"updated_at": "2019-11-30 17:25:56 UTC",
"name": "Hosts - complete list",
"id": 165,
"locations": [

],
"organizations": [
]
}
[user@terminal ~]$
---

We can see a bunch of "\n" that represent new lines. I was expecting to the API handle this automatically without the necessity of manual or additional intervantion.

Actions #1

Updated by Dominik Matoulek over 3 years ago

  • Subject changed from Weird behaviour when Importing the report template to Foreman via API to Weird behaviour when Importing the report template to Foreman via API
  • Description updated (diff)
  • Category changed from Statistics to Reporting
  • Triaged changed from No to Yes
Actions #2

Updated by Dominik Matoulek over 3 years ago

  • Assignee set to Dominik Matoulek
Actions #3

Updated by Marek Hulán over 3 years ago

This is most likely fixed by #28768

Actions

Also available in: Atom PDF