instance.run_command not working + Client.execute problem
Hello,
while testing singularity-cli I encountered a problem with instance.run_command method.
see:
from spython.main import Client
a = Client.instance('/my/image.sif', name='foo')
a.run_command(['ls'])
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/opt/gensoft/adm/share/gensoft/spython/utils/terminal.py", line 186, in run_command
cmd = _process_sudo_cmd(cmd, sudo, sudo_options)
File "/opt/gensoft/adm/share/gensoft/spython/utils/terminal.py", line 30, in _process_sudo_cmd
cmd = ["sudo"] + cmd
TypeError: can only concatenate list (not "Instance") to list
I tested instance.run_command method as I have a problem with Client.execute method
I have a singularity image that I need to test if it have nv support at runtime. from a different process than the one that instanciated it.
remember instance a was instanciated WITHOUT nv support in process1 but...
in process2
NB as expected instance.option is not available from different process
from spython.main import Client
foo = Client.instances('foo')
Client.execute(foo, ['nvidia-smi'], return_result=True)['return_code']
0
```
I was expecting anything but 0 ;-)
## Context
[provide more detailed introduction to the issue itself . This is for make a reproducible issue.]
* Operating System:
```
cat /etc/os-release
NAME="Red Hat Enterprise Linux"
VERSION="8.8 (Ootpa)"
ID="rhel"
ID_LIKE="fedora"
VERSION_ID="8.8"
PLATFORM_ID="platform:el8"
PRETTY_NAME="Red Hat Enterprise Linux 8.8 (Ootpa)"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:redhat:enterprise_linux:8::baseos"
HOME_URL="https://www.redhat.com/"
DOCUMENTATION_URL="https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/8"
BUG_REPORT_URL="https://bugzilla.redhat.com/"
REDHAT_BUGZILLA_PRODUCT="Red Hat Enterprise Linux 8"
REDHAT_BUGZILLA_PRODUCT_VERSION=8.8
REDHAT_SUPPORT_PRODUCT="Red Hat Enterprise Linux"
REDHAT_SUPPORT_PRODUCT_VERSION="8.8"
```
* singularity version:
singularity --version apptainer version 1.2.4-1.el8
* spython version: 0.3.11
* python version:
python3 --version Python 3.8.1
Let's start with the first issue posted above, which is fixed here https://github.com/singularityhub/singularity-cli/pull/214 (pending your testing and approval) then (from that branch) let's update the thread here (or open a new issue) with a specific way to reproduce your second. Thanks!
#214 tested and it ran smoothly.
thanks for the fix.
eric
Merged! If you want to install the master branch, and test again and update the issue for the second item, I'll have some time tomorrow or this weekend to work on it (going to bed now). Thanks!
great.
I'm currently playing some tests in order to check the second problem.
PS have a good night ;-)
Eric
I guess I miss-use or at least does not understand the diffrences beetween Client.execute(instance, [cmd]) and `instance.run_command([cmd])
see:
>>> from spython.main import Client
>>> a = Client.instance('/my/image.sif', name='foo', options=['--hostname', 'bar'])
>>> a.run_command(['hostname'])
'maestro-builder\n'
>>> Client.execute(a, ['hostname'])
'bar\n'
NB of course: from the shell using the instance satrted from spython
singularity exec instance://foo hostname
bar
does it looks accurate for you ?
in my mind as run_command is an instance method, I was expecting the command to be run from the instance
and finally problem 2 is not a problem... it was on my side.
adding --contain to the instance solved the pb.
sorry for the noise
eric
No worries! So execute is supposed to minic singularity exec. And run_command was previously a more hidden helper command to (one off) run a random command, but not inside the container (to the system). I do think it would be more intuitive if this current run_command was an exec to the instance, and then the current was moved back to be a helper (hidden) function. I am happy to test this out and open another PR if you agree.
yep agree. seems more logical