I am using socketCAN to interface to a CAN bus in Ubuntu 16.04. The interface works fine on my machine. However, when I kick off our CI, it executes on a remote agent (also Ubuntu 16.04) and I am receiving a permission error when the socket is creation is attempted:
Traceback (most recent call last):
File "main.py", line 20, in <module>
from tests_smoke import SmokeTests
File ".../tests_smoke.py", line 9, in <module>
from tests.validate_can import ValidateCAN
File ".../tests/validate_can.py", line 16, in <module>
bus = can.interface.Bus(bustype='socketcan', channel='can0', bitrate=250000)
File "/usr/local/lib/python3.5/dist-packages/can/interface.py", line 128, in __new__
return cls(channel, *args, **config)
File "/usr/local/lib/python3.5/dist-packages/can/interfaces/socketcan/socketcan.py", line 459, in __init__
self.socket = create_socket()
File "/usr/local/lib/python3.5/dist-packages/can/interfaces/socketcan/socketcan.py", line 330, in create_socket
sock = socket.socket(PF_CAN, socket.SOCK_RAW, CAN_RAW)
File "/usr/lib/python3.5/socket.py", line 134, in __init__
_socket.socket.__init__(self, family, type, proto, fileno)
PermissionError: [Errno 1] Operation not permitted
Being a novice in both Linux and Python, I'm not positive how to address this. I read in a few places that this may be a file creation permission issue which is inherited from the calling process so I have placed a "os.umask(0)" at the beginning of the script and that had no impact.
I've also read that it may be necessary to run the script as root. This seems quite risky.
What is the best way to fix this?