Python SDK: Creating/Updating/Removing environment variables (from device itself)

Hi guys,

Maybe you can help with something:

My devices use the Python SDK to set the environment variables they need themselves. After downloading their individual configuration from our backend they use the “resin.models.environment_variables.device.create” function to create the needed variables.

Now, that works fine. But somehow, updating and removing env vars results in errors:

When updating a variable via “resin.models.environment_variables.device.update()” I get this:

15.03.18 21:57:55 (+0100) Now updating config_var 'RESIN_HOST_CONFIG_disable_splash' on device to value '0'
15.03.18 21:57:56 (+0100) Exception in thread Thread-3:
15.03.18 21:57:56 (+0100) Traceback (most recent call last):
15.03.18 21:57:56 (+0100)   File "/usr/local/lib/python2.7/threading.py", line 801, in __bootstrap_inner
15.03.18 21:57:56 (+0100)     self.run()
15.03.18 21:57:56 (+0100)   File "/usr/local/lib/python2.7/threading.py", line 754, in run
15.03.18 21:57:56 (+0100)     self.__target(*self.__args, **self.__kwargs)
15.03.18 21:57:56 (+0100)   File "ResinManager.py", line 142, in set_device_environment_variables_thread
15.03.18 21:57:56 (+0100)     config_var_dict[entry])
15.03.18 21:57:56 (+0100)   File "/usr/local/lib/python2.7/site-packages/resin/models/environment_variables.py", line 128, in update
15.03.18 21:57:56 (+0100)     endpoint=self.settings.get('pine_endpoint')
15.03.18 21:57:56 (+0100)   File "/usr/local/lib/python2.7/site-packages/resin/base_request.py", line 175, in request
15.03.18 21:57:56 (+0100)     raise exceptions.RequestError(response._content)
15.03.18 21:57:56 (+0100) RequestError

And when removing a variable via “resin.models.environment_variables.device.remove()” I get this:

15.03.18 22:04:06 (+0100) Now removing config_var 'RESIN_HOST_CONFIG_gpu_mem' on device with value '16' and id '131778'
15.03.18 22:04:07 (+0100) Exception in thread Thread-3:
15.03.18 22:04:07 (+0100) Traceback (most recent call last):
15.03.18 22:04:07 (+0100)   File "/usr/local/lib/python2.7/threading.py", line 801, in __bootstrap_inner
15.03.18 22:04:07 (+0100)     self.run()
15.03.18 22:04:07 (+0100)   File "/usr/local/lib/python2.7/threading.py", line 754, in run
15.03.18 22:04:07 (+0100)     self.__target(*self.__args, **self.__kwargs)
15.03.18 22:04:07 (+0100)   File "ResinManager.py", line 154, in set_device_environment_variables_thread
15.03.18 22:04:07 (+0100)     resin.models.environment_variables.device.remove(current_vars_on_device_dict[entry][0])
15.03.18 22:04:07 (+0100)   File "/usr/local/lib/python2.7/site-packages/resin/models/environment_variables.py", line 150, in remove
15.03.18 22:04:07 (+0100)     endpoint=self.settings.get('pine_endpoint')
15.03.18 22:04:07 (+0100)   File "/usr/local/lib/python2.7/site-packages/resin/base_request.py", line 175, in request
15.03.18 22:04:07 (+0100)     raise exceptions.RequestError(response._content)
15.03.18 22:04:07 (+0100) RequestError

This can’t be expected behaviour right?

Thanks!

Frans

Hi, We’ve recently released v3 of the python SDK which appears to fix the issues you’re seeing. Could you try the new version and see if that fixes your issue?

Thanks guys, I will try!

Hmm, I’m afraid with ‘remove’ I still get this:

21.03.18 17:13:39 (+0100)  main  Exception in thread Thread-3:
21.03.18 17:13:39 (+0100)  main  Traceback (most recent call last):
21.03.18 17:13:39 (+0100)  main    File "/usr/local/lib/python2.7/threading.py", line 801, in __bootstrap_inner
21.03.18 17:13:39 (+0100)  main      self.run()
21.03.18 17:13:39 (+0100)  main    File "/usr/local/lib/python2.7/threading.py", line 754, in run
21.03.18 17:13:39 (+0100)  main      self.__target(*self.__args, **self.__kwargs)
21.03.18 17:13:39 (+0100)  main    File "ResinManager.py", line 154, in set_device_environment_variables_thread
21.03.18 17:13:39 (+0100)  main      resin.models.environment_variables.device.remove(current_vars_on_device_dict[entry][0])
21.03.18 17:13:39 (+0100)  main    File "/usr/local/lib/python2.7/site-packages/resin/models/environment_variables.py", line 150, in remove
21.03.18 17:13:39 (+0100)  main      endpoint=self.settings.get('pine_endpoint')
21.03.18 17:13:39 (+0100)  main    File "/usr/local/lib/python2.7/site-packages/resin/base_request.py", line 175, in request
21.03.18 17:13:39 (+0100)  main      raise exceptions.RequestError(response._content)
21.03.18 17:13:39 (+0100)  main  RequestError

And with update I get this:

Exception in thread Thread-3:
21.03.18 17:16:39 (+0100)  main  Traceback (most recent call last):
21.03.18 17:16:39 (+0100)  main    File "/usr/local/lib/python2.7/threading.py", line 801, in __bootstrap_inner
21.03.18 17:16:39 (+0100)  main      self.run()
21.03.18 17:16:39 (+0100)  main    File "/usr/local/lib/python2.7/threading.py", line 754, in run
21.03.18 17:16:39 (+0100)  main      self.__target(*self.__args, **self.__kwargs)
21.03.18 17:16:39 (+0100)  main    File "ResinManager.py", line 142, in set_device_environment_variables_thread
21.03.18 17:16:39 (+0100)  main      config_var_dict[entry])
21.03.18 17:16:39 (+0100)  main    File "/usr/local/lib/python2.7/site-packages/resin/models/environment_variables.py", line 128, in update
21.03.18 17:16:39 (+0100)  main      endpoint=self.settings.get('pine_endpoint')
21.03.18 17:16:39 (+0100)  main    File "/usr/local/lib/python2.7/site-packages/resin/base_request.py", line 175, in request
21.03.18 17:16:39 (+0100)  main      raise exceptions.RequestError(response._content)
21.03.18 17:16:39 (+0100)  main  RequestError

So what would be needed to debug this? Shall I paste here the code that sets the env vars? Or would you care to login to one of the devices with this behaviour?

Is this a single container or multicontainer device? We’ve not supported multicontainer yet so it might now work properly. We will release Python SDK v4 which supports multicontainer really soon.

Single container!