Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion contrib/packs/actions/install.meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@
default: "master"
register:
type: "string"
default: "actions"
default: "actions,aliases,sensors"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is misusing string parameter type (it should really be array), but I assume you have done it because you can't really specify arrays via chatops now, right?

If so, that's fine for now. As a future improvement, we could look into re-using CLI logic for specifying arrays and objects as strings, but this might require more work since aliases are not aware of the parameter types.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aliases work with array like the Cli. Also there is some type awareness

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, they do? Cool, I didn't know that.

(I do see the CAST_OVERRIDES code now...)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried with array first, but it's converted into string. See: #1231 (comment)

Also, as I understand array type won't be preserved here in install workflow

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried with array first, but it's converted into string. See: #1231 (comment)

Most likely due to the specific jinja template being used. Have not tried it out myself so can't say what works and what does not.

Also, as I understand array type won't be preserved here in install workflow

It will if load.yaml say it expect input as an array. The output type is not preserved since we lack type information. However, input to an action is cast, as much as possible, into the correct types.

I will agree that all this is very confusing and how the translations happens and types are preserved/not preserved during transitions is quite unclear.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For now if you have figured out a way we should go with that since we know that it works.

description: "Possible options are all, sensors, actions, rules, aliases."
4 changes: 2 additions & 2 deletions contrib/packs/actions/load.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
immutable: true
cmd:
immutable: true
default: "st2ctl reload --register-{{register}}"
default: "st2ctl reload{% for item in register.split(',') %} --register-{{ item|trim }}{% endfor %}"
register:
type: "string"
default: "actions"
default: "actions,aliases,sensors"
description: "Possible options are all, sensors, actions, rules, aliases."
kwarg_op:
immutable: true
41 changes: 24 additions & 17 deletions tools/st2ctl
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ function print_usage() {
echo
echo "usage: st2ctl {reload, clean}"
echo "optional arguments:"
echo " --register-all Register all sensors, rules, and actions."
echo " --register-sensors Register all sensors only."
echo " --register-rules Register all rules only."
echo " --register-actions Register all actions only."
echo " --register-aliases Register all aliases only."
echo " --register-policies Register all policies only."
echo " --register-all Register all."
echo " --register-sensors Register all sensors."
echo " --register-rules Register all rules."
echo " --register-actions Register all actions."
echo " --register-aliases Register all aliases."
echo " --register-policies Register all policies."
echo " --verbose Output additional debug and informational messages."
}

Expand Down Expand Up @@ -93,19 +93,26 @@ then
fi

# Note: Scripts already call reload with "--register-<content>"
# TODO: Update packs. actions to only pass in a resource name excluding # --register prefix
if [ ${1} == "reload" -o ${1} == "clean" ]; then
ALLOWED_REGISTER_FLAGS=(--register-all --register-actions --register-aliases --register-policies --register-rules --register-sensors --verbose)
DEFAULT_REGISTER_FLAGS='--register-actions --register-aliases --register-sensors'

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, this is a lot better. Hated this monstrosity :P

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm just slightly worried, since I don't remember if we have any end to end tests for st2ctl.

If we don't, now it would be a good time to add some to st2tests repo.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

st2tests looks like some kind of acceptance tests, pretty cool thing. I'll do it a bit later.

@Kami StackStorm/st2tests#16

if [ ! -z ${2} ]; then
for arg in ${@:2}; do
if [[ " ${ALLOWED_REGISTER_FLAGS[*]} " != *" $arg "* ]]; then # argument not allowed
echo -e "\e[31mError: Invalid argument provided: ${arg} \e[0m\n"
print_usage
exit 1
fi
done
fi

if [ -z ${2} ]; then
REGISTER_FLAGS="--register-sensors --register-actions --register-aliases"
elif [ ! -z ${2} ] && [ ${2} == "--register-all" -o ${2} == "--register-sensors" -o ${2} == "--register-rules" -o ${2} == "--register-actions" -o ${2} == "--register-aliases" -o ${2} == "--register-policies" ]; then
REGISTER_FLAGS=${2}
if [ ! -z ${3} ] && [ ${3} == "--verbose" ]; then
REGISTER_FLAGS="${REGISTER_FLAGS} ${3}"
fi
elif [ ${2} == "--verbose" ] && [ -z ${3} ]; then
REGISTER_FLAGS="--register-sensors --register-actions --register-aliases ${2}"
elif [ ${2} == "--verbose" ] && [ ${3} == "--register-all" -o ${3} == "--register-sensors" -o ${3} == "--register-rules" -o ${3} == "--register-actions" -o ${3} == "--register-aliases" -o ${3} == "--register-policies" ]; then
REGISTER_FLAGS="${3} ${2}"
REGISTER_FLAGS=${DEFAULT_REGISTER_FLAGS}
elif [ ${2} == '--verbose' ] && [ -z ${3} ]; then
REGISTER_FLAGS="$DEFAULT_REGISTER_FLAGS ${2}"
elif [ ! -z ${2} ]; then
REGISTER_FLAGS=${@:2}
else
print_usage
exit 1
Expand Down