salopensource / sal-scripts

Apache License 2.0
23 stars 31 forks source link

machine_checkin.py reads wrong os_version for older macOS systems #62

Closed octomike closed 4 years ago

octomike commented 4 years ago

Commit f1e43ddad1f20b72b6e95b7711ffc4a79ce47085 introduced a regression for the operatingsystem plugin in SAL.

(I know they are officially unsupported..), but older clients have this os_version value:

<key>os_version</key>
<string>OS X 10.11.6 (15G22010)</string>

while the "new" naming scheme is:

<key>os_version</key>
<string>macOS 10.15 (19A583)</string>

This results in a TypeError in SAL within the operatingsystem plugin, because it tries to compare (sort) X with 10.15.

ERROR [django.request:228] Internal Server Error: /load_plugin/OperatingSystem/machine_group/1/
Traceback (most recent call last):
  File "/home/sal/.virtualenvs/sal/lib/python3.7/site-packages/django/core/handlers/exception.py", line 34, in inner
    response = get_response(request)
  File "/home/sal/.virtualenvs/sal/lib/python3.7/site-packages/django/core/handlers/base.py", line 126, in _get_response
    response = self.process_exception_by_middleware(e, request)
  File "/home/sal/.virtualenvs/sal/lib/python3.7/site-packages/django/core/handlers/base.py", line 124, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/home/sal/.virtualenvs/sal/lib/python3.7/site-packages/django/contrib/auth/decorators.py", line 21, in _wrapped_view
    return view_func(request, *args, **kwargs)
  File "./server/non_ui_views.py", line 123, in plugin_load
    plugin_object.widget_content(request, group_type=group_type, group_id=group_id))
  File "./sal/plugin.py", line 241, in widget_content
    context = self.get_context(queryset, **kwargs)
  File "/home/sal/sal/server/plugins/operatingsystem/operatingsystem.py", line 69, in get_context
    (key, sorted(grouped[key], key=os_key, reverse=True)) for key in OS_TABLE.values()]
  File "/home/sal/sal/server/plugins/operatingsystem/operatingsystem.py", line 69, in <listcomp>
    (key, sorted(grouped[key], key=os_key, reverse=True)) for key in OS_TABLE.values()]
  File "/usr/lib/python3.7/distutils/version.py", line 52, in __lt__
    c = self._cmp(other)
  File "/usr/lib/python3.7/distutils/version.py", line 337, in _cmp
    if self.version < other.version:
TypeError: '<' not supported between instances of 'int' and 'str'

I can create a PR, but I'm not sure where to catch this issue. It's probably best to catch this here and return 10.11.6 instead of X, but it could also be handled (ignored) in the sal plugin.

sheagcraig commented 4 years ago

This has been handled by #64.