Testing console-conf

Thanks for helping on it, but why is ssh needed? We should be able to create ptys without requiring ssh.

Yeah, sorry but I haven’t found any reference about how to create an interactive raw pty with non null height and width (the dimensions seem to be critical for console-conf and in general any urwid based application) from a noniteractive session. Opening an ssh session allows us to request our desired terminal, send a command to it and get the result easily, it also works fine with console-conf (sergio’s tests are working with very small modifications) but if there’s a simpler way of doing things any ideas are more than welcome :slight_smile:

Well, I found another way to fix it avoiding the ssh

The idea is to use the python pty module to make possible to use the stty command to setup the current tty. Previously it was not possible because the stty command was giving the following output

+ stty -a
stty: 'standard input': Inappropriate ioctl for device

Then, the idea is to spawn a script which will have the stty command avalable to configure the tty.

python3 -c "import pty; pty.spawn('./run')"

run script:

#!/bin/bash
save_state=$(stty -g)
stty raw
stty -echo
stty cols 240 rows 60
expect -d -f task.exp
stty "$save_state"
1 Like

We don’t even need the python call nor the additional script, just configuring expect with set stty_init "raw cols 240 rows 60" before spawning console-conf is enough:

# tests/main/console-conf/task.yaml
summary: console-conf
execute: |
    snap install --devmode expect

    expect -f console-conf.exp

and

# tests/main/console-conf/console-conf.exp
set stty_init "raw cols 240 rows 60"

spawn sudo /usr/bin/console-conf

expect {
    "Ubuntu Core" {
      exit 0
    } timeout {
      exit 1
    }
}

@cachio let me know if this works for you

Yes, it works perfect :grinning:

I’ll push the changes now

Thanks

@cachio just for making sure we have this sorted, is all good with the proposed solution? Does configuring the tty that expect spawns with set stty_init "raw cols x rows y" solve the issue without changing anything else?

Thanks,

@fgimenez, the configuration that made all the tests work is:

set stty_init “raw speed 38400 rows 30 columns 100”