StackStorm / StackStorm/st2

Fix unit tests to not require the `stanley` system_user?

Open
#6,203 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug infrastructure: ci/cd proposal tests
Dominant language
Python
Stars
6.5k
Forks
787
PR merge metrics
No merged PRs in 30d

Description

I'm working on getting pants to run our unit tests via pytest (I figure we can deal with integration tests later once all unit tests are running). I've got most of the st2common unit tests passing, but I've run into an assumption in our test suite that I would like to get rid of. The question is how.

Problematic assumption: That the system running our tests has the system_user (typically stanley).

For GHA, we had to add setup tasks that modify the conf files to use runner instead of stanley... But then we also create the stanley user "for ssh".
For vagrant, adding a user is not a big ask. Similar for docker containers.
But for local development (eg with vim, or with PyCharm, or whatever people prefer), I want to be able to at least run the unit tests without creating that user.

What's worse, the tests fail without indicating that the reason they failed was because the stanley user is not present.
I noticed in the log output that the core.echo action was triggering the command: sudo -E -H -u stanley -- bash -c 'echo "<% ctx().msg1 %>"' which was weird because the sudo parameter was false in the test's sample workflow. Apparently, the local-command-runner will use sudo -u <system_user> if the current user is not the same as system_user.

How can we make the default system_user match the current user, at least for unit tests?
Maybe whatever solution we come up with will lead to removing those GHA user setup tasks for the unit tests (requiring the user for integration tests doesn't bother me).

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the st2common unit tests through pytest and inspect the core.echo action and local-command-runner behavior described in the issue. Trace how the test configuration selects system_user and how the GHA setup tasks modify the conf files. Done means unit tests run locally without creating the stanley user and failures clearly identify unrelated causes.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
devops, testing
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.