Skip to content

virt.get_graphics, virt.get_nics are broken, in turn breaking other things #20198

Closed

Description

@jcftang

Given

# salt --versions-report
           Salt: 2014.7.1
         Python: 2.7.6 (default, Mar 22 2014, 22:59:56)
         Jinja2: 2.7.2
       M2Crypto: 0.21.1
 msgpack-python: 0.4.5
   msgpack-pure: 0.1.3
       pycrypto: 2.6.1
        libnacl: Not Installed
         PyYAML: 3.10
          ioflo: Not Installed
          PyZMQ: 14.0.1
           RAET: Not Installed
            ZMQ: 4.0.4
           Mako: 0.9.1

When I try to get more info with virt.full_info

# salt x01 virt.full_info    
x01:
    The minion function caused an exception: Traceback (most recent call last):
      File "/usr/lib/python2.7/dist-packages/salt/minion.py", line 1022, in _thread_return
        return_data = func(*args, **kwargs)
      File "/usr/lib/python2.7/dist-packages/salt/modules/virt.py", line 1076, in full_info
        'vm_info': vm_info()}
      File "/usr/lib/python2.7/dist-packages/salt/modules/virt.py", line 720, in vm_info
        info[vm_] = _info(vm_)
      File "/usr/lib/python2.7/dist-packages/salt/modules/virt.py", line 710, in _info
        'graphics': get_graphics(vm_),
      File "/usr/lib/python2.7/dist-packages/salt/modules/virt.py", line 860, in get_graphics
        for key in g_node.attributes:
      File "/usr/lib/python2.7/xml/dom/minidom.py", line 522, in __getitem__
        return self._attrs[attname_or_tuple]
    KeyError: 0

And...

root@x01:/srv/scripts# salt x01 virt.get_graphics wheezy
x01:
    The minion function caused an exception: Traceback (most recent call last):
      File "/usr/lib/python2.7/dist-packages/salt/minion.py", line 1022, in _thread_return
        return_data = func(*args, **kwargs)
      File "/usr/lib/python2.7/dist-packages/salt/modules/virt.py", line 860, in get_graphics
        for key in g_node.attributes:
      File "/usr/lib/python2.7/xml/dom/minidom.py", line 522, in __getitem__
        return self._attrs[attname_or_tuple]
    KeyError: 0

Activity

  1. jcftang commented on Jan 29, 2015

    @jcftang
    Author

    Looking at https://github.com/saltstack/salt/blob/v2014.7.1/salt/modules/virt.py#L858, as I understand it, the idea was to set the video card or grab information about it.

    In my case the tag should be

    <!--
    WARNING: THIS IS AN AUTO-GENERATED FILE. CHANGES TO IT ARE LIKELY TO BE
    OVERWRITTEN AND LOST. Changes to this xml configuration should be made using:
      virsh edit wheezy
    or other application using the libvirt API.
    -->
    
    <domain type='kvm'>
      <name>wheezy</name>
      <uuid>ae207aa8-8da9-4fcf-9d17-04d05cae1099</uuid>
      <memory unit='KiB'>524288</memory>
      <currentMemory unit='KiB'>524288</currentMemory>
      <vcpu placement='static'>1</vcpu>
      <os>
        <type arch='x86_64' machine='pc-i440fx-trusty'>hvm</type>
        <boot dev='hd'/>
      </os>
      <features>
        <acpi/>
      </features>
      <clock offset='utc'/>
      <on_poweroff>destroy</on_poweroff>
      <on_reboot>restart</on_reboot>
      <on_crash>destroy</on_crash>
      <devices>
        <emulator>/usr/bin/kvm-spice</emulator>
        <disk type='file' device='disk'>
          <driver name='qemu' type='qcow2' cache='none' io='native'/>
          <source file='/srv/salt-images/wheezy/system.qcow2'/>
          <target dev='vda' bus='virtio'/>
          <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/>
        </disk>
        <controller type='usb' index='0'>
          <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/>
        </controller>
        <controller type='pci' index='0' model='pci-root'/>
        <interface type='bridge'>
          <mac address='ac:de:48:1c:d3:53'/>
          <source bridge='br0'/>
          <model type='virtio'/>
          <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
        </interface>
        <input type='mouse' bus='ps2'/>
        <input type='keyboard' bus='ps2'/>
        <graphics type='vnc' port='-1' autoport='yes' listen='0.0.0.0'>
          <listen type='address' address='0.0.0.0'/>
        </graphics>
        <video>
          <model type='cirrus' vram='9216' heads='1'/>
          <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/>
        </video>
        <memballoon model='virtio'>
          <address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0'/>
        </memballoon>
      </devices>
    </domain>
    
  2. added
    bug
    severity-low
    on Jan 30, 2015
  3. added this to the Approved milestone on Jan 30, 2015
  4. jfindlay commented on Jan 30, 2015

    @jfindlay
    Contributor

    @jcftang, thanks for reporting this.

  5. jcftang commented on Jan 30, 2015

    @jcftang
    Author

    I may be wrong about the intended behaviour but something is surely subtley broken somewhere.

  6. Galser commented on Feb 24, 2015

    @Galser

    Just a small note, for me this parsing function failing on 2 Hypervisors out of 24, running KVM, when graphics defined is not VNC but spice.
    E.g. this is okay , hypervisor 1:
    <graphics type='vnc' port='-1' autoport='yes'/>
    And this is failing , hypervisor 2:
    <graphics type='spice' autoport='yes'/>

    Both are absolutely identical machines in the terms of everything.
    Versions :

              Salt: 2014.7.1
             Python: 2.7.5 (default, May  5 2014, 09:13:10)
             Jinja2: 2.7.2
           M2Crypto: 0.21.1
     msgpack-python: 0.4.4
       msgpack-pure: Not Installed
           pycrypto: 2.6.1
            libnacl: Not Installed
             PyYAML: 3.10
              ioflo: Not Installed
              PyZMQ: 14.3.1
               RAET: Not Installed
                ZMQ: 3.2.4
               Mako: Not Installed
    
  7. thequailman commented on Feb 24, 2015

    @thequailman

    This is affecting me as well, I can't run any virt commands because of the get_graphics bug. Can I comment it out temporarily? Any workarounds?

  8. added
    severity-medium
    and removed
    severity-low
    on Feb 24, 2015
  9. jfindlay commented on Feb 24, 2015

    @jfindlay
    Contributor

    @thequailman, I haven't tested this but you could do

    diff --git a/salt/modules/virt.py b/salt/modules/virt.py
    index e6fc2d9..ef8eefb 100644
    --- a/salt/modules/virt.py
    +++ b/salt/modules/virt.py
    @@ -707,7 +707,7 @@ def vm_info(vm_=None):
             return {'cpu': raw[3],
                     'cputime': int(raw[4]),
                     'disks': get_disks(vm_),
    -                'graphics': get_graphics(vm_),
    +                'graphics': '' #get_graphics(vm_),
                     'nics': get_nics(vm_),
                     'maxMem': int(raw[1]),
                     'mem': int(raw[2]),
  10. cachedout commented on Feb 24, 2015

    @cachedout
    Contributor

    That looks like it is missing a comma. :]

    On Tue, Feb 24, 2015 at 11:41 AM, jfindlay [email protected] wrote:

    @thequailman https://github.com/thequailman, I haven't tested this but
    you could do

    diff --git a/salt/modules/virt.py b/salt/modules/virt.py
    index e6fc2d9..ef8eefb 100644--- a/salt/modules/virt.py+++ b/salt/modules/virt.py@@ -707,7 +707,7 @@ def vm_info(vm_=None):
    return {'cpu': raw[3],
    'cputime': int(raw[4]),
    'disks': get_disks(vm_),- 'graphics': get_graphics(vm_),+ 'graphics': '' #get_graphics(vm_),
    'nics': get_nics(vm_),
    'maxMem': int(raw[1]),
    'mem': int(raw[2]),

    —
    Reply to this email directly or view it on GitHub
    #20198 (comment).

  11. jfindlay commented on Feb 24, 2015

    @jfindlay
    Contributor

    @cachedout, tests my code for me.

    diff --git a/salt/modules/virt.py b/salt/modules/virt.py
    index e6fc2d9..ef8eefb 100644
    --- a/salt/modules/virt.py
    +++ b/salt/modules/virt.py
    @@ -707,7 +707,7 @@ def vm_info(vm_=None):
             return {'cpu': raw[3],
                     'cputime': int(raw[4]),
                     'disks': get_disks(vm_),
    -                'graphics': get_graphics(vm_),
    +                'graphics': '', #get_graphics(vm_),
                     'nics': get_nics(vm_),
                     'maxMem': int(raw[1]),
                     'mem': int(raw[2]),
  12. thequailman commented on Feb 24, 2015

    @thequailman

    That partially fixed it, I receive a new error now:

    Traceback (most recent call last):
      File "/bin/salt-call", line 11, in <module>
        salt_call()
      File "/usr/lib/python2.7/site-packages/salt/scripts.py", line 123, in salt_call
        client.run()
      File "/usr/lib/python2.7/site-packages/salt/cli/__init__.py", line 420, in run
        caller.run()
      File "/usr/lib/python2.7/site-packages/salt/cli/caller.py", line 225, in run
        ret = self.call()
      File "/usr/lib/python2.7/site-packages/salt/cli/caller.py", line 129, in call
        ret['return'] = func(*args, **kwargs)
      File "/usr/lib/python2.7/site-packages/salt/modules/virt.py", line 717, in vm_info
        info[vm_] = _info(vm_)
      File "/usr/lib/python2.7/site-packages/salt/modules/virt.py", line 711, in _info
        'nics': get_nics(vm_),
      File "/usr/lib/python2.7/site-packages/salt/modules/virt.py", line 802, in get_nics
        for key in v_node.attributes:
      File "/usr/lib64/python2.7/xml/dom/minidom.py", line 525, in __getitem__
        return self._attrs[attname_or_tuple]
    KeyError: 0
    

    If I follow the same suggestion for the get_nics function, the virt the commands work again.

  13. 3 remaining items

  14. jfindlay commented on Feb 24, 2015

    @jfindlay
    Contributor

    @Galser, no prob. I'm glad this haxor workaround is working.

  15. tjstansell commented on Mar 9, 2015

    @tjstansell
    Contributor

    I ran into this today and cranked up the python debugger and walked through this. It seems to be a type issue:

    > /usr/lib/python2.7/site-packages/salt/modules/virt.py(860)get_graphics()->None
    -> for key in g_node.attributes:
    (Pdb) key
    *** NameError: name 'key' is not defined
    (Pdb) g_node.attributes
    <xml.dom.minidom.NamedNodeMap object at 0x13046c8>
    (Pdb) g_node.attributes[0]
    *** KeyError: 0
    (Pdb) g_node.attributes[1]
    *** KeyError: 1
    (Pdb) g_node.attributes
    <xml.dom.minidom.NamedNodeMap object at 0x1304638>
    (Pdb) g_node.attributes.items
    <bound method NamedNodeMap.items of <xml.dom.minidom.NamedNodeMap object at 0x1304638>>
    (Pdb) g_node.attributes.items()
    [(u'autoport', u'yes'), (u'type', u'vnc'), (u'port', u'5904'), (u'listen', u'0.0.0.0')]
    (Pdb) g_node.attributes.keys()
    [u'autoport', u'type', u'port', u'listen']
    (Pdb)
    

    Notice how the code is trying to loop through the elements, but it needs to use the keys() or item() or items() methods to properly loop through the attributes.

    This is why we're getting KeyError: 0 since g_node.attributes is not a list, but a minidom object.

    The following code change fixed it for me:

    --- salt/modules/virt.py-       2014-12-02 20:45:58.000000000 +0000
    +++ salt/modules/virt.py        2015-03-09 18:50:54.564173154 +0000
    @@ -799,16 +799,16 @@
                     # driver, source, and match can all have optional attributes
                     if re.match('(driver|source|address)', v_node.tagName):
                         temp = {}
    -                    for key in v_node.attributes:
    -                        temp[key] = v_node.getAttribute(key)
    +                    for key,val in v_node.attributes.items():
    +                        temp[key] = val
                         nic[str(v_node.tagName)] = temp
                     # virtualport needs to be handled separately, to pick up the
                     # type attribute of the virtualport itself
                     if v_node.tagName == 'virtualport':
                         temp = {}
                         temp['type'] = v_node.getAttribute('type')
    -                    for key in v_node.attributes:
    -                        temp[key] = v_node.getAttribute(key)
    +                    for key,val in v_node.attributes.items():
    +                        temp[key] = val
                         nic['virtualport'] = temp
                 if 'mac' not in nic:
                     continue
    @@ -857,8 +857,8 @@
         for node in doc.getElementsByTagName('domain'):
             g_nodes = node.getElementsByTagName('graphics')
             for g_node in g_nodes:
    -            for key in g_node.attributes:
    -                out[key] = g_node.getAttribute(key)
    +            for key,val in g_node.attributes.items():
    +                out[key] = val
         return out

    This was hacked in place on my box running 2014.7.2.

  16. jfindlay commented on Mar 9, 2015

    @jfindlay
    Contributor

    @tjstansell, awesome, thanks. I will be glad to merge a pull request with these changes against the 2014.7 branch. If you don't have time to get back to this, I can make the changes.

  17. tjstansell commented on Mar 10, 2015

    @tjstansell
    Contributor
  18. added
    fixed-pls-verify
    on Mar 10, 2015
  19. rallytime commented on Mar 10, 2015

    @rallytime
    Contributor

    Awesome! Thanks for pulling that together @vdesjardins!

  20. added 2 commits that reference this issue on Mar 10, 2015
    827541e
    d529390
  21. removed
    needs-testcase
    on Mar 10, 2015
  22. rallytime commented on Mar 10, 2015

    @rallytime
    Contributor

    I've backported this fix in #21487 to the 2014.7 branch, so the fix will be available in the next release of salt.

  23. dsanader commented on May 16, 2015

    @dsanader

    The virtualport section of the get_nics function is still broken, the fix is missing the matching part of @tjstansell's suggestion :

    --- salt/modules/virt.py       2015-04-16 19:19:41.000000000 +0200
    +++ salt/modules/virt.py       2015-05-01 17:10:41.638418411 +0200
    @@ -808,8 +808,8 @@
                     if v_node.tagName == 'virtualport':
                         temp = {}
                         temp['type'] = v_node.getAttribute('type')
    -                    for key in v_node.attributes:
    -                        temp[key] = v_node.getAttribute(key)
    +                    for key, value in v_node.attributes.items():
    +                        temp[key] = value
                         nic['virtualport'] = temp
                 if 'mac' not in nic:
                     continue

    For example, the following xml block, still generates the same "KeyError: 0" in salt as mentioned above (looping over v_node.attributes is not possible).

    <interface type='bridge'>
      <mac address='00:16:3e:00:01:7c'/>
      <source bridge='br0'/>
      <vlan>
        <tag id='51'/>
      </vlan>
      <virtualport type='openvswitch'>
        <parameters interfaceid='673f21c0-f221-45c8-afcc-12885834c3f4'/>
      </virtualport>
      <target dev='nic0'/>
      <model type='virtio'/>
      <address type='pci' domain='0x0000' bus='0x01' slot='0x01' function='0x0'/>
    </interface>
  24. rallytime commented on May 16, 2015

    @rallytime
    Contributor

    Good catch @dsanader. I've fixed the virtualport loop in the pull request above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugfixed-pls-verifyseverity-medium

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions