Bug 1399619 - Duplicate host getting created every time during upload facts with API "POST /api/hosts/facts"
Summary: Duplicate host getting created every time during upload facts with API "POST ...
Keywords:
Status: CLOSED WONTFIX
Alias: None
Product: Red Hat Satellite
Classification: Red Hat
Component: Puppet
Version: 6.2.2
Hardware: Unspecified
OS: Unspecified
medium
medium vote
Target Milestone: Unspecified
Assignee: satellite6-bugs
QA Contact: Katello QA List
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2016-11-29 12:36 UTC by vijsingh
Modified: 2020-09-10 10:00 UTC (History)
5 users (show)

Fixed In Version:
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2018-09-04 17:58:19 UTC
Target Upstream Version:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Red Hat Bugzilla 1404968 0 medium CLOSED Restricted user to upload facts and reports via api 2021-02-22 00:41:40 UTC

Internal Links: 1404968

Description vijsingh 2016-11-29 12:36:10 UTC
Description of problem:
Duplicate host getting created each time during upload facts with using API "POST /api/hosts/facts" 

#curl -H "Accept:application/json,version=2" -H "Content-Type:application/json" -X POST -u user:password -d @/var/tmp/myhost.json https://satellite.example.com/api/hosts/facts 


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

How reproducible:
each time 


Steps to Reproduce:
1. Run the below API two to three times ..

#curl -H "Accept:application/json,version=2" -H "Content-Type:application/json" -X POST -u user:password -d @/var/tmp/myhost.json https://satellite.example.com/api/hosts/facts 

2. Check the hosts under hosts tab on Satellite GUI.


Actual results:
Getting the multiple hosts entries for same host with same name.

Expected results:
It should check the host name before make the new entry and entry should not be duplicate.

Additional info:

Comment 1 Philipp Gassmann 2016-11-29 14:27:19 UTC
Duplicated hosts are only created, when uploading the facts for a new host using a restricted user with only upload_facts permissions.

When uploading the facts with with the admin user, it will correctly update the existing host.

When uploading facts to an existing host with the restricted user, it will throw the following error:

~~~
# curl -H "Accept:application/json,version=2"      -H "Content-Type:application/json"      -X POST -u reporter:Password        -d @/tmp/upload_facts.json      https://satellite/api/hosts/facts
{
  "error": {"message":"Resource host not found by id ''"}
}

~~~

It looks like there's an implicitly required permission to upload facts correctly.

Comment 3 Marek Hulan 2016-12-01 07:44:04 UTC
What permissions does the user with login "user" has? Can you reproduce it with admin user? What's the value of "Use short name for VMs" setting?

Comment 4 vijsingh 2016-12-01 09:27:44 UTC
(In reply to Marek Hulan from comment #3)
> What permissions does the user with login "user" has? Can you reproduce it
> with admin user?

Permission for restricted user is `upload_facts` and same is reproduce by restricted user only not by admin user.

> What's the value of "Use short name for VMs" setting?

Would you please provide some brief on above question.

Comment 5 Marek Hulan 2016-12-01 09:42:07 UTC
Could you please also retry if you give the user view_hosts permission? You can find out the value of "Use short name for VMs" setting by navigating to Administer -> Settings -> Provisioning tab. See the value column for this setting.

Comment 6 vijsingh 2016-12-01 10:41:04 UTC
(In reply to Marek Hulan from comment #5)
> Could you please also retry if you give the user view_hosts permission? You

Tried with `view_hosts` permission however still getting the duplicate entries with restricted user.

> can find out the value of "Use short name for VMs" setting by navigating to
> Administer -> Settings -> Provisioning tab. See the value column for this
> setting.

It's  `value = false`.

Comment 7 Marek Hulan 2016-12-23 14:37:56 UTC
Thanks for update. Could you please check what organization and location the newly created host is assigned to? Is the user also assigned to some of these? Could you please get the production.log with debug log level so we could see actual SQL queries? Also please upload your /var/tmp/myhost.json. It would greatly help if you had a reproducing environment.

Strange thing is that it worked fine for me while I worked on BZ 1404968 which might be something that you might also hit.

Comment 8 Philipp Gassmann 2017-01-03 08:57:04 UTC
Hi Marek,

I'm the customer who opened the originating case (01744905) for these issues. I give you the full context of these issues. 

Here are the steps that cover all issues:
1. register the host with new domain (myhost.foo.com) using activation key.
2. upload facts with restricted upload_facts user: Result:
 - fact upload is correctly associated with registered host
 - no Domain is created and no domain is shown in the host details
3. upload facts with admin user. Results:
 - Domain foo.com is created
 - host is associated with foo.com in the host details
4. upload facts with restricted user no longer works: Result: Resource host not found by id ''
5. Open Domain in GUI and Submit to save domain correctly
6. upload facts with restricted user works again
7. subscription-manager unregister 
8. delete the host in Satellite
9. uploading facts with restricted user leads to duplicate entries.


Details for the Domain part
We never defined the domains manually. I just reproduced the implicit creation of the domain when uploading fact with the admin user.

Steps to reproduce:
1. replace domain in upload_facts.json
  # sed -i 's/yourdomain.com/newdomain.ch/' /var/tmp/myhost.json
2. upload the json with admin user. curl -H "Accept:application/json,version=2" -H "Content-Type:application/json" -X POST -u admin:Password -d @/var/tmp/myhost.json https://localhost/api/hosts/facts --insecure
3. newdomain.ch is shown in GUI Infrastructure > Domains in context "Any Organization"
  - When editing the domain, the Location and Organization are displayed as selected.
  - The domain is not displayed when in context of the organisation.
4. After clicking submit without any changes, the domain is available in the Organisation context.

Comment 12 Marek Hulan 2017-03-06 17:16:10 UTC
Hello Philipp, thank you very much for more information. I'm sorry I could not get to this BZ earlier. I think I start to understand what's going on. It actually confirms my comment https://bugzilla.redhat.com/show_bug.cgi?id=1404968#c3

Let's move the discussion there, I'll keep this open to investigate if we could do something about duplicated records, but the cause is tracked under BZ 1404968 and should be fixed there as well.

Comment 13 Bryan Kearney 2018-09-04 17:58:19 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.


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