munki/munki-facts

monterey_upgrade_supported not returning device ID under Python 3

ericholtam opened this issue · 2 comments

When running monterey_upgrade_supported.py with the Munki embedded Python 3 framework I'm not getting a deviceID returned. This is causing a false negative on the Munki fact where the Mac (Apple Silicon in this case) doesn't match up to a supported model or board id, and therefore not meeting the condition to get Monterey offered to install. When running the same code on the same machine but using a Python 2 framework, the values are returned properly.

Example runs below. Disregard the actual returned value as the machine I'm running it on is already running a newer OS. This is just to show that the value of the get_device_id function is not returning the proper value. I'm not sure how to address this myself.

$ /usr/local/munki/munki-python /usr/local/munki/conditions/facts/monterey_upgrade_supported.py 
is_virtual_machine:          False
get_current_model:           Mac14,2
is_supported_model:          False
get_minor_system_version:    18
is_supported_system_version: False
get_board_id:                
is_supported_board_id:       False
get_device_id:               
is_supported_device_id:       False
{'monterey_upgrade_supported': False}

$ /Library/MunkiReport/Python.framework/Versions/Current/bin/python /usr/local/munki/conditions/facts/monterey_upgrade_supported.py
is_virtual_machine:          False
get_current_model:           Mac14,2
is_supported_model:          False
get_minor_system_version:    18
is_supported_system_version: False
get_board_id:                
is_supported_board_id:       False
get_device_id:               j413ap
is_supported_device_id:       False
{'monterey_upgrade_supported': False}

I found a conversation about a similar issue at https://gist.github.com/pudquick/581a71425439f2cf8f09?permalink_comment_id=4324622#gistcomment-4324622

The workaround is to add a b to the call deviceid = sysctl(b"hw.target")

Testing locally with that change the values returned are correct using both Python 2 and Python 3:

$ /Library/MunkiReport/Python.framework/Versions/Current/bin/python /usr/local/munki/conditions/facts/monterey_upgrade_supported.py
is_virtual_machine:          False
get_current_model:           Mac14,2
is_supported_model:          False
get_minor_system_version:    18
is_supported_system_version: False
get_board_id:                
is_supported_board_id:       False
get_device_id:               j413ap
is_supported_device_id:       False
{'monterey_upgrade_supported': False}


$ /usr/local/munki/munki-python /usr/local/munki/conditions/facts/monterey_upgrade_supported.py                               
is_virtual_machine:          False
get_current_model:           Mac14,2
is_supported_model:          False
get_minor_system_version:    18
is_supported_system_version: False
get_board_id:                
is_supported_board_id:       False
get_device_id:               j413ap
is_supported_device_id:       False
{'monterey_upgrade_supported': False}

I'll submit a PR for this change.

....and in looking into creating the PR, I see that this was already addressed with adding an encoding to the name in the function.

if isinstance(name, str):
    name = name.encode('utf-8')

Disregard this.