NORDUnet / opennsa

Open-source implementation of the NSI protocol with support for different backends
BSD 3-Clause "New" or "Revised" License
13 stars 19 forks source link

Running opennsa on debian 12 fails due to error on twistar library: re.error global flags not at the start #48

Open italovalcy opened 4 months ago

italovalcy commented 4 months ago

Hi,

After fixing other building errors like the one reported in #44, the following error happens after starting opennsa in Debian 12 I get the following error:

2024-05-08 20:57:30Z [-] Unhandled error in Deferred:
2024-05-08 20:57:30Z [-] Unhandled Error
    Traceback (most recent call last):
      File "/usr/local/lib/python3.11/dist-packages/twisted/internet/defer.py", line 662, in _runCallbacks
        current.result = callback(current.result, *args, **kw)
      File "/usr/local/lib/python3.11/dist-packages/twisted/internet/base.py", line 515, in _continueFiring
        callable(*args, **kwargs)
      File "/usr/local/lib/python3.11/dist-packages/twisted/internet/defer.py", line 1656, in unwindGenerator
        return _cancellableInlineCallbacks(gen)
      File "/usr/local/lib/python3.11/dist-packages/twisted/internet/defer.py", line 1571, in _cancellableInlineCallbacks
        _inlineCallbacks(None, g, status)
    --- <exception caught here> ---
      File "/usr/local/lib/python3.11/dist-packages/twisted/internet/defer.py", line 1445, in _inlineCallbacks
        result = current_context.run(g.send, result)
      File "/home/opennsa/opennsa/opennsa/backends/common/genericbackend.py", line 89, in buildSchedule
        conns = yield GenericBackendConnections.find(where=['source_network = ? AND dest_network = ? AND lifecycle_state <> ?', self.network, self.network, state.TERMINATED])
      File "/usr/local/lib/python3.11/dist-packages/twistar/dbobject.py", line 427, in find
        d = config.select(klass.tablename(), id, where, group, limit, orderby)
      File "/usr/local/lib/python3.11/dist-packages/twistar/dbobject.py", line 364, in tablename
        klass.TABLENAME = inf.tableize(klass.__name__)
      File "/usr/local/lib/python3.11/dist-packages/BermiInflector/Inflector.py", line 78, in tableize
        return self.Inflector.tableize(class_name)
      File "/usr/local/lib/python3.11/dist-packages/BermiInflector/Rules/Base.py", line 80, in tableize
        return self.pluralize(self.underscore(class_name))
      File "/usr/local/lib/python3.11/dist-packages/BermiInflector/Rules/English.py", line 66, in pluralize
        match = re.search(rules[rule][0], word, re.IGNORECASE)
      File "/usr/lib/python3.11/re/__init__.py", line 176, in search
        return _compile(pattern, flags).search(string)
      File "/usr/lib/python3.11/re/__init__.py", line 294, in _compile
        p = _compiler.compile(pattern, flags)
      File "/usr/lib/python3.11/re/_compiler.py", line 743, in compile
        p = _parser.parse(p, flags)
      File "/usr/lib/python3.11/re/_parser.py", line 980, in parse
        p = _parse_sub(source, state, flags & SRE_FLAG_VERBOSE, 0)
      File "/usr/lib/python3.11/re/_parser.py", line 455, in _parse_sub
        itemsappend(_parse(source, state, verbose, nested + 1,
      File "/usr/lib/python3.11/re/_parser.py", line 841, in _parse
        raise source.error('global flags not at the start '
    re.error: global flags not at the start of the expression at position 1
Joshua-M-CANARIE commented 4 months ago

Having delved further into this. Here's the source of the error: Debian image stable-slim has moved to Bookworm which uses python version 3.11, whereas the original OpenNSA build used Bullseye, using python version 3.9, and the package twistar does not support version 3.11

In python 3.11, they require using a tag at the beginning of regex, like (?s) or (?i), which the twistar library does not do.

As it stands, the latest version of twistar is version 2.0.0, which is the version used by OpenNSA, and it was released back in 2018 and the git hub repo has been archived by the owner back in 2021. It appears very, very unlikely that Twistar will be updated to use Python 3.11 on its own, so there's 3 options at this point.

In my development, migrating back to Bullseye has proven successful, however this solution won't support all requirements, particularly once Bullseye reaches EOL in 2026.

italovalcy commented 4 months ago

Hi @Joshua-M-CANARIE thanks a lot for checking this. I've a running version of opennsa and BerlinInflector lib running on debian 12 with the following change:

sed -i 's/\^(?i)(ox)/(?i)^(ox)/g' /usr/local/lib/python3.11/dist-packages/BermiInflector/Rules/English.py

I think the best option would be Refactor the OpenNSA library to not make use of Twistar. However, since I this. seems to be a long path, maybe maintaining a fork of BermiInflector or Twistar. I can help on that if you guys are interested.