Bug 1426424

Summary: Bootstrap fails to register systems with invalid hostnames or only have short names
Product: Red Hat Satellite Reporter: Satellite Program <pm-sat>
Component: BootstrapAssignee: Rich Jerrido <rjerrido>
Status: CLOSED ERRATA QA Contact: Lukáš Hellebrandt <lhellebr>
Severity: high Docs Contact:
Priority: high    
Version: 6.2.8CC: bbuckingham, bkearney, cdonnell, ehelms, jcallaha, lhellebr, rjerrido
Target Milestone: UnspecifiedKeywords: Triaged
Target Release: Unused   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: 1425606 Environment:
Last Closed: 2018-02-21 17:06:49 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:
Bug Depends On: 1425606    
Bug Blocks: 1122832    

Description Satellite Program 2017-02-23 20:49:20 UTC
+++ This bug was initially created as a clone of Bug #1425606 +++

Description of problem:

When running bootstrap, it fails to register a system that has an invalid hostname, (such as one with an underscore), or hostname that are short (hostname -f) doesn't return an FQDN, 


Version-Release number of selected component (if applicable):
katello-client-bootstrap-1.2.2

How reproducible:
100%

Steps to Reproduce:
1. Create a system with a 

short name (where hostname -f or "ython -c "import socket;print socket.getfqdn()"" returns a shortname

or an invalid name. (Such as a name with an underscore), such as foo_bar.example.com


2. Register with bootstrap. 
3.

Actual results:
bootstrap fails with an error similar to the following:

    [RUNNING], [2017-02-21 14:13:01], [Calling Foreman API to create a host entry associated with the group, domain, org & location]
    url: https://<capsule-fqdn>:8443/api/v2/hosts/
    method: POST
    data: {
      "host": {
        "managed": "true",
        "name": "<hostname>",
        "hostgroup_id": 22,
        "organization_id": 1,
        "mac": "00:50:56:90:11:D2",
        "architecture_id": 1,
        "location_id": 3,
        "domain_id": 6
      }
    }
    Error: The following error occured while talking to the API:
    url: https://<capsule-fqdn>:8443/api/v2/hosts/
    code: 422
    data: {
      "host": {
        "managed": "true",
        "name": "<hostname>",
        "hostgroup_id": 22,
        "organization_id": 1,
        "mac": "00:50:56:90:11:D2",
        "architecture_id": 1,
        "location_id": 3,
        "domain_id": 6
      }
    }
    error: {
      "error": {
        "errors": {
          "interfaces.name": [
            "is invalid"
          ],
          "name": [
            "is invalid"
          ]
        },
        "id": null,
        "full_messages": [
          "Name is invalid",
          "Name is invalid"
        ]
      }
    }

Expected results:

bootstrap successfully registers the system. 

Additional info:

--- Additional comment from rjerrido on 20170221T22:23:22

Also RFC 952 or 1123 covers hostname validation and Foreman appears to respect this (see lib/net/validations.rb). 

As we generally cannot ask the customer to change their hostnames (many have short names for 3rd party apps), it might be advisable to allow the customer to set an arbitrary hostname in bootstrap.py (for puppet and subscription-manager) that differs from what the system reports.

--- Additional comment from rjerrido on 20170223T19:29:43

Fixed in commit https://github.com/Katello/katello-client-bootstrap/commit/49ec1ae44a7463f5f615ad6d59fccd21d9da6bda

Comment 3 Lukáš Hellebrandt 2017-10-17 14:34:29 UTC
Verified with Sat6.3 snap 20.

Used reproducer from original BZ's comment 4:

# ./bootstrap.py -s <Satellite_FQDN> -o 'Default Organization' -a testak -g 'testhostgroup' -L 'Default Location' --fqdn <client_FQDN>

Note: When run without the --fqdn parameter, the following error text is shown:

"""
We could not determine the domain of this machine, most probably `hostname -f` does not return the FQDN.
This can lead to Puppet missbehaviour and thus the script will terminate now.
You can override this by passing one of the following
	--force - to disable all checking
	--skip-puppet - to omit installing the puppet agent
"""

As we solved this by using --fqdn parameter, this should also be mentioned in the error text.

Comment 4 Bryan Kearney 2018-02-21 17:06:49 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-2018:0336