opensvc / opensvc

The OpenSVC node agent
https://www.opensvc.com
GNU General Public License v2.0
35 stars 10 forks source link

XML Element call to invalid getiterator() method in opensvc/utilities/devtree/linux.py, line 406 #523

Closed alarbiere closed 2 years ago

alarbiere commented 2 years ago

Since the upgrade to python 3.9, any attempt to stop a service depending on a drbd disk resource fails with the following error being logged:

Traceback (most recent call last):
  File "/usr/share/opensvc/opensvc/core/objects/svc.py", line 1145, in do_action
    err = call_action(action)
  File "/usr/share/opensvc/opensvc/core/objects/svc.py", line 1134, in call_action
    err = getattr(self, action)()
  File "/usr/share/opensvc/opensvc/core/objects/svc.py", line 4512, in stop
    self.master_stop()
  File "/usr/share/opensvc/opensvc/core/objects/svc.py", line 492, in _func
    func(self)
  File "/usr/share/opensvc/opensvc/core/objects/svc.py", line 4516, in master_stop
    self.sub_set_action(STOP_GROUPS, "stop", xtags=set(["zone", "docker", "podman"]))
  File "/usr/share/opensvc/opensvc/core/objects/svc.py", line 3604, in sub_set_action
    self.set_action(rsets, _type=_type, action=action, tags=tags, xtags=xtags)
  File "/usr/share/opensvc/opensvc/core/objects/svc.py", line 3694, in set_action
    rset.action(action, types=_type, tags=tags, xtags=xtags, xtypes=aborted)
  File "/usr/share/opensvc/opensvc/core/resourceset.py", line 350, in action
    resource.action(action)
  File "/usr/share/opensvc/opensvc/core/resource.py", line 465, in action
    self.do_action(action)
  File "/usr/share/opensvc/opensvc/core/resource.py", line 369, in do_action
    self.action_main(action)
  File "/usr/share/opensvc/opensvc/core/resource.py", line 338, in action_main
    getattr(self, action)()
  File "/usr/share/opensvc/opensvc/drivers/resource/fs/linux.py", line 602, in stop
    self.remove_holders()
  File "/usr/share/opensvc/opensvc/drivers/resource/fs/linux.py", line 631, in remove_holders
    tree = self.svc.node.devtree
  File "/usr/share/opensvc/opensvc/utilities/lazy.py", line 32, in _lazyprop
    setattr(self, attr_name, fn(self))
  File "/usr/share/opensvc/opensvc/core/node/node.py", line 1919, in devtree
    tree.load()
  File "/usr/share/opensvc/opensvc/utilities/devtree/linux.py", line 624, in load
    self.add_drbd_relations()
  File "/usr/share/opensvc/opensvc/utilities/devtree/linux.py", line 408, in add_drbd_relations
    for res in tree.getiterator('resource'):
AttributeError: 'xml.etree.ElementTree.Element' object has no attribute 'getiterator'

I manually changed the relevant code at /usr/share/opensvc/opensvc/utilities/devtree/linux.py", line 404 from

...
        from xml.etree import ElementTree as etree
        tree = etree.fromstring(out.decode())
        for res in tree.getiterator('resource'):
            for host in res.findall('host'):
...

to the following, replacing the deprecated getiterator() method call by the new iter()

...
        from xml.etree import ElementTree as etree
        tree = etree.fromstring(out.decode())
        for res in tree.iter('resource'):
            for host in res.findall('host'):
...

which fixes the error for me.

cvaroqui commented 2 years ago

Thank you for reporting this issue. I added a search-and-replace patch to PR #522 ... pending QA testing in our lab.