Bug 2058431

Summary: cloud_what is wrongly detecting hosts running on hyper-V (on-premise) as running on Azure
Product: Red Hat Enterprise Linux 8 Reporter: Joniel Pasqualetto <jpasqual>
Component: subscription-managerAssignee: candlepin-bugs
Status: CLOSED DUPLICATE QA Contact: Red Hat subscription-manager QE Team <rhsm-qe>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: 8.5CC: rcavalca
Target Milestone: rc   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2022-03-01 15:10:24 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 Joniel Pasqualetto 2022-02-24 22:18:46 UTC
Description of problem:

RHEL 8 running as VM on Hyper-V is being detected as running o Azure using heuristics.

The problem is that, using the current criteria, any host running on hyper-V will be detect as such.

The conditions being triggered are:

0.3 points here (virt.host_type is hyper-v) -> https://github.com/candlepin/subscription-manager/blob/8008cd771ae608e81af138b2273fdf0271755da1/src/cloud_what/providers/azure.py#L107-L110

~~~  
 # We know that Azure uses only HyperV
        if 'virt.host_type' in self.hw_info:
            if 'hyperv' in self.hw_info['virt.host_type']:
                probability += 0.3
~~~

More 0.3 points here (will find Microsoft on dmidecode if it runs on hyper-V) -> https://github.com/candlepin/subscription-manager/blob/8008cd771ae608e81af138b2273fdf0271755da1/src/cloud_what/providers/azure.py#L116-L129

~~~
        # Try to find "Azure" or "Microsoft" keywords in output of dmidecode
        found_microsoft = False
        found_azure = False
        for hw_item in self.hw_info.values():
            if type(hw_item) != str:
                continue
            if 'microsoft' in hw_item.lower():
                found_microsoft = True
            elif 'azure' in hw_item.lower():
                found_azure = True
        if found_microsoft is True:
            probability += 0.3
        if found_azure is True:
            probability += 0.1
~~~

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


How reproducible:
Always

Steps to Reproduce:
1. Install RHEL8 + subscription-manager-1.28.21-3.el8.x86_64 on a VM running over hyper-V
2. Enable debug logging on subscription-manager

subscription-manager config  --logging.default_log_level=DEBUG

3. Load facts:

subscription-manager facts


4. Look at /var/log/rhsm/rhsm.log 

2022-02-24 17:09:51,504 [DEBUG] subscription-manager:10827:MainThread @provider.py:83 - Trying to detect cloud provider
2022-02-24 17:09:51,504 [DEBUG] subscription-manager:10827:MainThread @provider.py:101 - No cloud provider detected using strong signs
2022-02-24 17:09:51,504 [DEBUG] subscription-manager:10827:MainThread @provider.py:116 - Cloud provider aws has probability: 0.3
2022-02-24 17:09:51,505 [DEBUG] subscription-manager:10827:MainThread @provider.py:116 - Cloud provider azure has probability: 0.6
2022-02-24 17:09:51,505 [DEBUG] subscription-manager:10827:MainThread @provider.py:116 - Cloud provider gcp has probability: 0.3
2022-02-24 17:09:51,505 [DEBUG] subscription-manager:10827:MainThread @provider.py:128 - Following cloud providers detected using heuristics: azure


Actual results:
cloud provider is detected and tries to query http://169.254.169.254, resulting in timeouts for the client:


~~~
2022-02-16 05:07:23,355 [ERROR] rhsmcertd-worker:333640:MainThread @base_action_client.py:73 - HTTPConnectionPool(host='169.254.169.254', port=80): Read timed out. (read timeout=10.0)
Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/urllib3/connectionpool.py", line 384, in _make_request
    six.raise_from(e, None)
  File "<string>", line 3, in raise_from
  File "/usr/lib/python3.6/site-packages/urllib3/connectionpool.py", line 380, in _make_request
    httplib_response = conn.getresponse()
  File "/usr/lib64/python3.6/http/client.py", line 1361, in getresponse
    response.begin()
  File "/usr/lib64/python3.6/http/client.py", line 311, in begin
    version, status, reason = self._read_status()
  File "/usr/lib64/python3.6/http/client.py", line 272, in _read_status
    line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
  File "/usr/lib64/python3.6/socket.py", line 586, in readinto
    return self._sock.recv_into(b)
socket.timeout: timed out

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/requests/adapters.py", line 449, in send
    timeout=timeout
  File "/usr/lib/python3.6/site-packages/urllib3/connectionpool.py", line 638, in urlopen
    _stacktrace=sys.exc_info()[2])
  File "/usr/lib/python3.6/site-packages/urllib3/util/retry.py", line 368, in increment
    raise six.reraise(type(error), error, _stacktrace)
  File "/usr/lib/python3.6/site-packages/urllib3/packages/six.py", line 693, in reraise
    raise value
  File "/usr/lib/python3.6/site-packages/urllib3/connectionpool.py", line 600, in urlopen
    chunked=chunked)
  File "/usr/lib/python3.6/site-packages/urllib3/connectionpool.py", line 386, in _make_request
    self._raise_timeout(err=e, url=url, timeout_value=read_timeout)
  File "/usr/lib/python3.6/site-packages/urllib3/connectionpool.py", line 306, in _raise_timeout
    raise ReadTimeoutError(self, url, "Read timed out. (read timeout=%s)" % timeout_value)
urllib3.exceptions.ReadTimeoutError: HTTPConnectionPool(host='169.254.169.254', port=80): Read timed out. (read timeout=10.0)
~~~

Expected results:

Host would not be detected as running on a cloud provider when it's not.

Additional info:

Comment 2 Pino Toscano 2022-03-01 15:10:24 UTC
Hi Joniel,

coincidentally, this was already reported as bz by Jiri Hnidek (of the sub-man team) that noticed the problem in other circumstances.
This is bug 2057053, so I'm closing this one as duplicate of it.

Thanks!

*** This bug has been marked as a duplicate of bug 2057053 ***