StackStorm / StackStorm/st2

Shell script runners don't correctly serialize "False" value for boolean parameters

Open
#4,649 2 comments 0 reactions 1 assignee View on GitHub

@Kami is already working on this.

Since Apr 26, 2019.

bug
Dominant language
Python
Stars
6.5k
Forks
787
PR merge metrics
No merged PRs in 30d

Description

I found out this issue while working on the release.

Currently, the script runner doesn't include "False" values for boolean parameter (https://github.com/StackStorm/st2/blob/master/st2common/st2common/models/system/action.py#L277) which means it won't work correctly in scenarios where boolean script parameter is not the last parameter.

For example, from one of our actions:

Script file:

Action metadata file:

---
name: st2_chg_ver_for_st2
description: Change the version for the st2 repo
enabled: true
runner_type: remote-shell-script
entry_point: st2_chg_ver_for_st2.sh
parameters:
    project:
        type: string
        description: Project name for st2
        default: st2
        position: 0
    version:
        type: string
        description: Version to update to. Should include the patch e.g. 0.1.0
        required: true
        position: 1
    fork:
        type: string
        description: Fork to use
        default: StackStorm
        position: 2
    branch:
        type: string
        description: Branch to update
        default: master
        position: 3
    update_mistral:
        type: boolean
        description: If true, update mistralclient version in requirements.txt.
        default: false
        position: 4
    update_changelog:
        type: boolean
        description: If true, update version in changelog.
        default: false
        position: 5
    local_repo:
        type: string
        description: Location where to clone the repo. Programmatically determined if not provided.
        position: 6
    dir:
        immutable: true
        default: /home/stanley/
    sudo:
        immutable: true
        default: false
    cmd:
        immutable: true
        default: ""
    kwarg_op:
        immutable: true
        default: "--"
...
#!/bin/bash
set -e

PROJECT=$1
VERSION=$2
FORK=$3
BRANCH=$4
UPDATE_MISTRAL=$5
UPDATE_CHANGELOG=$6
LOCAL_REPO=$7
GIT_REPO="git@github.com:${FORK}/${PROJECT}.git"
CWD=`pwd`
PUSH=0
....

In this case, if update_mistral and update_changelog parameters default to False, script will get incorrectly called with the following arguments st2_chg_ver_for_st2.sh st2 3.1dev StackStorm master st2_1556296602_602 which is incorrect since argument number 4 will now be local_repo instead of update_mistral.

Actual command line should look like this: st2_chg_ver_for_st2.sh st2 3.1dev StackStorm master 0 0 st2_1556296602_602. In short, False should get serialized as 0 (and we need to document this).

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.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.