This site is in read only mode. Please continue to browse, but replying, likes, and other actions are disabled for now.

⚠️ We've moved!

Hi there!

To reduce project dependency on 3rd party paid services the StackStorm TSC has decided to move the Q/A from this forum to Github Discussions. This will make user experience better integrated with the native Github flow, as well as the questions closer to the community where they can provide answers.

Use 🔗 Github Discussions to ask your questions.

Action Setup to use Intellij for development and debugging

I have struggled with this for EVER. The development side normally I have a sanbox setup somewhere on the network OR a vagrant image that I use the sftp features in Intellij to directly connect to the sandbox. Edit code, run action via st2 run. This is ok for the most part but since we decided to re-write a lot of packs it was a perfect time to figure this out. So, the following is a rough action frame work that will allow the same behavior but instead of running the action via st2 you can simply run from intellij as well as st2. THEN you can also run debug from intellij as well using the remote sandbox’s python3 virt environment for that action. Ok, on the the code

import sys
import yaml
import json
from pathlib import Path
from lib.actions import BaseAction


class DoThingsAction(BaseAction):
    def run(self, fname, lname):
        hello = "hey there {} {}".format(fname, lname)        
        return hello


def runme(fname, lname):
    """
    This function is here for only debugging and developement purposes.
    :param fname: First name
    :param lname: Last name
    :return: Output from action
    """
    results = DoThingsAction(config).run(fname, lname)
    print(results)


if __name__ == '__main__':
    """
    This is here ONLY for debugging and developement.
    """
    fname = sys.argv[1:][0]
    lname = sys.argv[1:][1]
    """
    The file in Path, is a different yaml file then the normal main yaml.
    DO NOT store this file ANYWHERE except in your intellij.  The reason is
    from st2common.runners.base_action import Action
    decrypts everything in that file, and for debugging we read this file and
    use it for the self.conf instead.
    """
    p = Path('foreman_lab')
    if p.exists():
        with p.open() as f:
            config = yaml.safe_load(f)
            config = json.loads(json.dumps(config, default=str))
        runme(fname, lname)

Start by going to Project Settings> Project Settings> SDKs and Add a new Python SDK. Select SSH Interpreter file in the details for the host to attach to and specify the path to the remote virtual-env python3. For pure remote debugging needs don’t check the upload part. IF your developing, check this and make sure your Sync folder goes to /opt/stackstorm/packs/

Back in the project, right click on the action and “run” it. That will fail (as expected). Then go to configs and edit the config for that action. Change the Python Interpreter to the one you just created.

Next, in the parameters section. Place the params you want in order to how they will be read into the action. This is purely positional. In the example above it would be something like
John Smith

Now, you should be able to run/debug your action.
@blag gets credit for getting me here.

If you find typos or the directions are off… not a technical writer so … sorry.