Bug 1359653

Summary: Can't filter host when set two hosts in "filter_host_uuids" with same quotes
Product: Red Hat Enterprise Linux 7 Reporter: Liushihui <shihliu>
Component: virt-whoAssignee: Radek Novacek <rnovacek>
Status: CLOSED ERRATA QA Contact: Eko <hsun>
Severity: medium Docs Contact:
Priority: unspecified    
Version: 7.3CC: ldai, ovasik, sgao
Target Milestone: rc   
Target Release: ---   
Hardware: x86_64   
OS: Linux   
Whiteboard:
Fixed In Version: virt-who-0.17-7.el7 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2016-11-04 05:10:10 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 Liushihui 2016-07-25 08:51:17 UTC
Description of problem:
When two hosts in "filter_host_uuids" with same quotes('' or "") in /etc/virt-who.d/XXX, if one host is not exist, virt-who can't filter the other legal one.
if one host is set to null, virt-who will show error info and stop automatically.

Version-Release number of selected component (if applicable):
virt-who-0.17-6.el7.noarch
subscription-manager-1.17.9-1.el7.x86_64
python-rhsm-1.17.5-1.el7.x86_64

How reproducible:
Always

Steps to Reproduce:
1. Register system to satellite6.2
2. Set "filter_host_uuids" with same quotes '' or "",564D80F1-61F0-8510-87BF-57F9EC6122D7 is legal, "test" is illegal.
# cat /etc/virt-who.d/virt
[hyperv]
type=hyperv
server=10.73.5.212
username=administrator
password=Welcome1
owner=7970632
env=7970632
filter_host_uuids='564D80F1-61F0-8510-87BF-57F9EC6122D7','test'
or 
# cat /etc/virt-who.d/virt
[hyperv]
type=hyperv
server=10.73.5.212
username=administrator
password=Welcome1
owner=7970632
env=7970632
filter_host_uuids="564D80F1-61F0-8510-87BF-57F9EC6122D7","test"
3. Restart virt-who and check virt-who's log
4. Set "filter_host_uuids" with same quotes '' or "",564D80F1-61F0-8510-87BF-57F9EC6122D7 is legal, the other host is null.
[hyperv]
type=hyperv
server=10.73.5.212
username=administrator
password=Welcome1
owner=7970632
env=7970632
filter_host_uuids="564D80F1-61F0-8510-87BF-57F9EC6122D7",""
5. Restart virt-who and check virt-who's log

Actual results:
After step 3: Virt-who can't filter the legal host "564D80F1-61F0-8510-87BF-57F9EC6122D7", it will show null host.
"2016-07-25 04:38:56,550 [virtwho.main INFO] MainProcess(14047):MainThread @subscriptionmanager.py:hypervisorCheckIn:194 - Sending update in hosts-to-guests mapping for config "hyperv": 0 hypervisors and 0 guests found
2016-07-25 04:38:56,550 [virtwho.main DEBUG] MainProcess(14047):MainThread @subscriptionmanager.py:hypervisorCheckIn:195 - Host-to-guest mapping: {}
" 

After step5, it will show error info and virt-who will stop automatically
2016-07-25 04:43:10,874 [virtwho.main ERROR] MainProcess(14113):MainThread @__main__.py:main:16 - Fatal error:
Traceback (most recent call last):
  File "/usr/lib/python2.7/site-packages/virtwho/__main__.py", line 8, in main
    res = virtwho.main.main()
  File "/usr/lib/python2.7/site-packages/virtwho/main.py", line 178, in main
    return _main(executor)
  File "/usr/lib/python2.7/site-packages/virtwho/main.py", line 186, in _main
    result = executor.run()
  File "/usr/lib/python2.7/site-packages/virtwho/executor.py", line 249, in run
    if self.last_reports_hash.get(report.config.name, None) == report.hash:
  File "/usr/lib/python2.7/site-packages/virtwho/virt/virt.py", line 245, in hash
    return hashlib.sha256(json.dumps(self.serializedAssociation, sort_keys=True)).hexdigest()
  File "/usr/lib/python2.7/site-packages/virtwho/virt/virt.py", line 240, in serializedAssociation
    'hypervisors': sorted([h.toDict() for h in self.association['hypervisors']], key=itemgetter('hypervisorId'))
  File "/usr/lib/python2.7/site-packages/virtwho/virt/virt.py", line 231, in association
    if self._config.filter_hosts is not None and host.hypervisorId not in self._config.filter_hosts:
  File "/usr/lib/python2.7/site-packages/virtwho/config.py", line 123, in __getattr__
    return parse_list(value)
  File "/usr/lib/python2.7/site-packages/virtwho/config.py", line 75, in parse_list
    raise ValueError("Unterminated %s sign" % {"'": "single quote", '"': "double quote"}.get(read_to, read_to))
ValueError: Unterminated single quote sign

Expected results:
Virt-who should filter host correctly no matter with the same quotes or different quotes. it also shouldn't show error info but show correct host when filter a null host.

Additional info:
When two hosts with different quotes, virt-who can work normally.

Comment 1 Radek Novacek 2016-07-26 14:41:13 UTC
This issue is now addressed upstream.

https://github.com/virt-who/virt-who/commit/4054161b2bc259539ea72eeee7c15dda369654fe

Comment 3 Liushihui 2016-08-02 03:43:25 UTC
Verified it on virt-who-0.17-7.el7.noarch since virt-who can handle filter_host_uuids, excluded_host_uuids, filter_hosts,exclude_hosts with same quotes. Therefore, verify it.

Verified version:
virt-who-0.17-7.el7.noarch
subscription-manager-1.17.9-1.el7.x86_64
python-rhsm-1.17.5-1.el7.x86_64

Verified process:
1. Register system to satellite6.2
2. Set "filter_host_uuids" with same quotes '' or "",564D80F1-61F0-8510-87BF-57F9EC6122D7 is legal, "test" is illegal.
# cat /etc/virt-who.d/virt
[hyperv]
type=hyperv
server=10.73.5.212
username=administrator
password=Welcome1
owner=7970632
env=7970632
filter_host_uuids='564D80F1-61F0-8510-87BF-57F9EC6122D7','test'
or 
filter_host_uuids="564D80F1-61F0-8510-87BF-57F9EC6122D7","test"

3. Restart virt-who and check virt-who's log
2016-08-01 23:33:48,522 [virtwho.main DEBUG] MainProcess(108554):MainThread @subscriptionmanager.py:hypervisorCheckIn:195 - Host-to-guest mapping: {
    "564D80F1-61F0-8510-87BF-57F9EC6122D7": [
        {
            "guestId": "C877953C-A19E-5149-B614-D97873C4CBD2", 
            "state": 5, 
            "attributes": {
                "active": 0, 
                "virtWhoType": "hyperv"
            }
        }, 
        {
            "guestId": "8329390B-8359-F646-9176-27D738580E81", 
            "state": 1, 
            "attributes": {
                "active": 1, 
                "virtWhoType": "hyperv"
            }
        }, 
        {
            "guestId": "EB2C30F2-A847-3749-9828-20EBFB664490", 
            "state": 5, 
            "attributes": {
                "active": 0, 
                "virtWhoType": "hyperv"
            }
        }
    ]
}
2016-08-01 23:33:49,383 [virtwho.main DEBUG] MainProcess(108554):MainThread @executor.py:send_report:101 - Report for config "hyperv" sent

Result:
Virt-who should filter host correctly no matter with the same quotes or different quotes

Note:
When set as the following conditions, virt-who also can work normally.
filter_host_uuids="",""
exclude_host_uuids="",""
exclude_host_uuids='',''
exclude_hosts="test",""
exclude_host_uuids= "564D80F1-61F0-8510-87BF-57F9EC6122D7", "test"

Comment 5 errata-xmlrpc 2016-11-04 05:10:10 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://rhn.redhat.com/errata/RHBA-2016-2387.html