internlm/SWE-Fixer-Train-110K huggingface dataset:
Repository: StackStorm/st2

Issue:
BUG: "'FabricRemoteAction' object has no attribute 'id'"
Fabric based actions are failing due to an incorrectly named attribute.

root@st2stage201:/tmp# st2 execution get 5493450cce36d2111eb26c79
STATUS: failed
RESULT: 
{
    "message": "'FabricRemoteAction' object has no attribute 'id'", 
    "traceback": "  File "/usr/lib/python2.7/dist-packages/st2actions/container/base.py", line 117, in _do_run
    run_result = runner.run(action_params)
  File "/usr/lib/python2.7/dist-packages/st2actions/runners/fabricrunner.py", line 106, in run
    result = self._run(remote_action)
  File "/usr/lib/python2.7/dist-packages/st2actions/runners/fabricrunner.py", line 120, in _run
    remote_action.name, remote_action.id, remote_action.get_command(),
"
}



Discussion:

Resolving patch:
diff --git a/st2actions/st2actions/runners/fabricrunner.py b/st2actions/st2actions/runners/fabricrunner.py
--- a/st2actions/st2actions/runners/fabricrunner.py
+++ b/st2actions/st2actions/runners/fabricrunner.py
@@ -117,7 +117,7 @@ def _run(self, remote_action):
                  self.runner_id, remote_action.get_on_behalf_user())
         LOG.info(('[Action info] name: %s, Id: %s, command: %s, on behalf user: %s, '
                   'actual user: %s, sudo: %s'),
-                 remote_action.name, remote_action.id, remote_action.get_command(),
+                 remote_action.name, remote_action.action_exec_id, remote_action.get_command(),
                  remote_action.get_on_behalf_user(), remote_action.get_user(),
                  remote_action.is_sudo())
         results = execute(remote_action.get_fabric_task(), hosts=remote_action.hosts)


Test patch:
Repository: StackStorm/st2

Issue:
st2 key set in CLI doesn't allow one to set a TTL. 
Reported by: psychopenguin on slack



Discussion:
https://stackstorm-community.slack.com/archives/community/p1451932987009989


Resolving patch:
diff --git a/st2client/st2client/commands/keyvalue.py b/st2client/st2client/commands/keyvalue.py
--- a/st2client/st2client/commands/keyvalue.py
+++ b/st2client/st2client/commands/keyvalue.py
@@ -82,11 +82,11 @@ def run_and_print(self, args, **kwargs):
 
 class KeyValuePairGetCommand(resource.ResourceGetCommand):
     pk_argument_name = 'name'
-    display_attributes = ['name', 'value']
+    display_attributes = ['name', 'value', 'expire_timestamp']
 
 
 class KeyValuePairSetCommand(resource.ResourceCommand):
-    display_attributes = ['name', 'value']
+    display_attributes = ['name', 'value', 'expire_timestamp']
 
     def __init__(self, resource, *args, **kwargs):
         super(KeyValuePairSetCommand, self).__init__(
@@ -99,6 +99,8 @@ def __init__(self, resource, *args, **kwargs):
                                  metavar='name',
                                  help='Name of the key value pair.')
         self.parser.add_argument('value', help='Value paired with the key.')
+        self.parser.add_argument('-l', '--ttl', dest='ttl', type=int, default=None,
+                                 help='TTL (in seconds) for this value.')
 
     @add_auth_token_to_kwargs_from_cli
     def run(self, args, **kwargs):
@@ -106,6 +108,10 @@ def run(self, args, **kwargs):
         instance.id = args.name  # TODO: refactor and get rid of id
         instance.name = args.name
         instance.value = args.value
+
+        if args.ttl:
+            instance.ttl = args.ttl
+
         return self.manager.update(instance, **kwargs)
 
     def run_and_print(self, args, **kwargs):


Test patch:
Repository: StackStorm/st2

Issue:
File content gets logged on GET to /packs/view/file
We need to blacklist the related endpoints in https://github.com/StackStorm/st2/blob/33320e2e06882e58b83b92a94140a7eb3c7072f6/st2common/st2common/hooks.py#L49.



Discussion:
Does this also happen under INFO log level or only under DEBUG?

Under INFO too, this is why I spotted it.


Resolving patch:
diff --git a/st2common/st2common/hooks.py b/st2common/st2common/hooks.py
--- a/st2common/st2common/hooks.py
+++ b/st2common/st2common/hooks.py
@@ -49,7 +49,9 @@
 RESPONSE_LOGGING_CONTROLLER_NAME_BLACKLIST = [
     'ActionExecutionChildrenController',  # action executions can be big
     'ActionExecutionAttributeController',  # result can be big
-    'ActionExecutionsController'  # action executions can be big
+    'ActionExecutionsController'  # action executions can be big,
+    'FilesController',  # files controller returns files content
+    'FileController'  # file controller returns binary file data
 ]
 
 


Test patch:
Repository: StackStorm/st2

Issue:
action alias regex fails to evaluate null optional arguments when type is not string
For example, something like:  `update {{hostname}}( {{count}} times)?` 
Works for `!update myhost 2 times`
Fails for `!update myhost`
Error: `(invalid literal for int() with base 10: '')`
So the workaround is to change the type of `count` from integer to string.
Or @emedvedev provides another workaround:

```
- update {{ hostname }} {{ count }} times
- update {{ hostname }}
```

Start from the most explicit.



Discussion:
I believe you could also specify a default value for the count parameter, so something like `{{count=1}}`. That is, if a default value makes sense in that case.

@emedvedev Please correct me if I'm wrong and we don't support default values anymore.


Resolving patch:
diff --git a/st2common/st2common/models/utils/action_alias_utils.py b/st2common/st2common/models/utils/action_alias_utils.py
--- a/st2common/st2common/models/utils/action_alias_utils.py
+++ b/st2common/st2common/models/utils/action_alias_utils.py
@@ -82,7 +82,9 @@ def get_extracted_param_value(self):
             values = matched_stream.groupdict()
         for param in params:
             matched_value = values[param[0]] if matched_stream else None
-            result[param[0]] = matched_value or param[1]
+            matched_result = matched_value or param[1]
+            if matched_result:
+                result[param[0]] = matched_result
         if extra:
             for pair in kv_pairs:
                 result[pair[0]] = ''.join(pair[2:])


Test patch:
diff --git a/st2common/tests/unit/test_action_alias_utils.py b/st2common/tests/unit/test_action_alias_utils.py
--- a/st2common/tests/unit/test_action_alias_utils.py
+++ b/st2common/tests/unit/test_action_alias_utils.py
@@ -107,7 +107,7 @@ def test_spacing(self):
         param_stream = 'acl123'
         parser = ActionAliasFormatParser(alias_format, param_stream)
         extracted_values = parser.get_extracted_param_value()
-        self.assertEqual(extracted_values, {'a': ''})
+        self.assertEqual(extracted_values, {})
 
     def test_json_parsing(self):
         alias_format = 'skip {{a}} more skip.'
Repository: StackStorm/st2

Issue:
linux.wait_for_ssh action improvements
Currently `linux.wait_for_ssh` action (https://github.com/StackStorm/st2/blob/master/contrib/linux/actions/wait_for_ssh.yaml) only supports authenticating with RSA SSH key.

There are multiple ways we can improve this action and make it more generic.
- Support for other key types
- Support for password based authentication
- Refactor the action to utilize the new Paramiko SSH client
- Default to using system user (stanley) username and key file. Ideally key file location should be read from the config



Discussion:

Resolving patch:
diff --git a/contrib/linux/actions/wait_for_ssh.py b/contrib/linux/actions/wait_for_ssh.py
--- a/contrib/linux/actions/wait_for_ssh.py
+++ b/contrib/linux/actions/wait_for_ssh.py
@@ -2,26 +2,36 @@
 
 import time
 
-import paramiko
+from oslo_config import cfg
 
 from st2actions.runners.pythonrunner import Action
+from st2actions.runners.ssh.paramiko_ssh import ParamikoSSHClient
 
 
 class BaseAction(Action):
-    def run(self, keyfile, username, hostname, ssh_timeout, retries):
-        key = paramiko.RSAKey.from_private_key_file(keyfile)
-        client = paramiko.SSHClient()
-        client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
+    def run(self, hostname, port, username, password=None, keyfile=None, ssh_timeout=5,
+            sleep_delay=20, retries=10):
+        # Note: If neither password nor key file is provided, we try to use system user
+        # key file
+        if not password and not keyfile:
+            keyfile = cfg.CONF.system_user.ssh_key_file
+            self.logger.info('Neither "password" nor "keyfile" parameter provided, '
+                             'defaulting to using "%s" key file' % (keyfile))
+
+        client = ParamikoSSHClient(hostname=hostname, port=port, username=username,
+                                   password=password, key_files=keyfile,
+                                   timeout=ssh_timeout)
 
         for index in range(retries):
             attempt = index + 1
 
             try:
                 self.logger.debug('SSH connection attempt: %s' % (attempt))
-                client.connect(hostname=hostname, username=username, pkey=key)
+                client.connect()
                 return True
             except Exception as e:
-                self.logger.info('Attempt %s failed (%s), sleeping...' % (attempt, str(e)))
-                time.sleep(ssh_timeout)
+                self.logger.info('Attempt %s failed (%s), sleeping for %s seconds...' %
+                                 (attempt, str(e), sleep_delay))
+                time.sleep(sleep_delay)
 
         raise Exception('Exceeded max retries (%s)' % (retries))


Test patch:
Repository: StackStorm/st2

Issue:
"st2 key delete" does not obey interface and populate user query params
st2 --debug  key delete  -s user -u stanley netdev_servicewrapper_address
2016-09-23 17:13:48,545  DEBUG - Using cached token from file "/home/vagrant/.st2/token-st2admin"

curl -X GET -H  'Connection: keep-alive' -H  'Accept-Encoding: gzip, deflate' -H  'Accept: _/_' -H  'User-Agent: python-requests/2.11.1' -H  'X-Auth-Token: 235ca028e8e545efbd28806090ca3bd6' 'http://127.0.0.1:9101/v1/keys/netdev_servicewrapper_address?scope=user'

{
    "faultstring": "KeyValuePair with name: st2admin:netdev_servicewrapper_address and scope: user not found in db."
}



Discussion:
Thanks for opening this issue, will look into it.

On a side note - do you use RBAC?


Resolving patch:
diff --git a/st2client/st2client/commands/keyvalue.py b/st2client/st2client/commands/keyvalue.py
--- a/st2client/st2client/commands/keyvalue.py
+++ b/st2client/st2client/commands/keyvalue.py
@@ -184,6 +184,7 @@ def run(self, args, **kwargs):
         scope = getattr(args, 'scope', DEFAULT_SCOPE)
         kwargs['params'] = {}
         kwargs['params']['scope'] = scope
+        kwargs['params']['user'] = args.user
         instance = self.get_resource(resource_id, **kwargs)
 
         if not instance:


Test patch:
Repository: StackStorm/st2

Issue:
Cache filters API response for web UI
As the number of actions, rules, etc has grown in our StackStorm cluster, the UI is becoming slower. In particular, the filters view (which we rely on heavily with this many executions) is very slow to become visible and usable. It might help to cache this `/api/v1/executions/views/filters` API response and asynchronously reload this value outside of the request thread, since this is slowly-changing data.

Our typical workflow is to
1. load the main execution page
2. wait for the filters to appear
3. apply some set of filters
4. wait for the next page to load

Here's a waterfall showing a 20s load time for the filters response. This is pretty common for us now.
![screen shot 2016-08-22 at 12 20 14 pm](https://cloud.githubusercontent.com/assets/44062/17864407/8c624f68-6863-11e6-8557-c5fbe4d23e9f.png)

For reference, we have 572 rules, 1200 actions, 143 triggers, 19 trigger types, and 600k+ executions.



Discussion:
This filters call is now timing out in the UI and thus the filters are never appearing. =(

This is super painful now. I'm hoping increasing the memory after-hours will help. Are there any ideas on the code front that could help?

This is still a big issue. I can't evangelize this through the team if they can't search through stuff. Help?

(To even find the rule names, I'm resorting to searching mongo and manually constructing URLs. Not exactly how I want to teach others to use StackStorm.)

Still slow, but purging the execution history helped a lot. Configuring auto-purge now.

@Kami any feedback on this issue? Still a problem here.

Just took 50 seconds to load the filters!
![screen shot 2016-11-08 at 7 40 51 am](https://cloud.githubusercontent.com/assets/44062/20101239/b9ec6062-a586-11e6-8c51-5697a7fbeb99.png)

@codyaray I'm very sorry it took us so long to get to that issue. Have you tried adding more indexes to mongo's action_execution_db? The `.explain()` shows most of the time is spent on "COLLSCAN". I'll share the actual numbers with you as soon as I get them and will create a PR. I believe that using indexes may end up being much more flexible solution for us rather than caching controller response. Quite frankly, the idea we've missed that part confuses the hell out of me. As I said, very sorry.

Resolving patch:
diff --git a/st2common/st2common/models/db/execution.py b/st2common/st2common/models/db/execution.py
--- a/st2common/st2common/models/db/execution.py
+++ b/st2common/st2common/models/db/execution.py
@@ -78,6 +78,11 @@ class ActionExecutionDB(stormbase.StormFoundationDB):
             {'fields': ['end_timestamp']},
             {'fields': ['status']},
             {'fields': ['parent']},
+            {'fields': ['rule.name']},
+            {'fields': ['runner.name']},
+            {'fields': ['trigger.name']},
+            {'fields': ['trigger_type.name']},
+            {'fields': ['context.user']},
             {'fields': ['-start_timestamp', 'action.ref', 'status']}
         ]
     }


Test patch:
Repository: StackStorm/st2

Issue:
st2 action-alias -h reports incorrect help
The output of `st2 action-alias -h` contains references to managing runners. Looks like something is a little bit messed up somewhere, maybe related to introduction of pluggable runners?

```
brocade@bwc-2:~$ st2 --version
st2 2.1.0
brocade@bwc-2:~$ st2 action-alias -h
usage: st2 action-alias [-h] {list,get,create,update,delete,match,execute} ...

Action aliases.

positional arguments:
  {list,get,create,update,delete,match,execute}
                        List of commands for managing runners.
    list                Get the list of runners.
    get                 Get individual action alias.
    create              Create a new action alias.
    update              Updating an existing action alias.
    delete              Delete an existing action alias.
    match               Get the list of runners that match the command text.
    execute             Execute the command text by finding a matching
                        ActionAlias.

optional arguments:
  -h, --help            show this help message and exit
brocade@bwc-2:~$
```


Discussion:
Good catch, this definitely looks like a typo or similar.

Resolving patch:
diff --git a/st2client/st2client/commands/action_alias.py b/st2client/st2client/commands/action_alias.py
--- a/st2client/st2client/commands/action_alias.py
+++ b/st2client/st2client/commands/action_alias.py
@@ -98,7 +98,8 @@ class ActionAliasExecuteCommand(resource.ResourceCommand):
     def __init__(self, resource, *args, **kwargs):
         super(ActionAliasExecuteCommand, self).__init__(
             resource, 'execute',
-            'Execute the command text by finding a matching ActionAlias.',
+            ('Execute the command text by finding a matching %s.' %
+            resource.get_display_name().lower()),
             *args, **kwargs)
 
         self.parser.add_argument('command_text',
diff --git a/st2client/st2client/models/action_alias.py b/st2client/st2client/models/action_alias.py
--- a/st2client/st2client/models/action_alias.py
+++ b/st2client/st2client/models/action_alias.py
@@ -25,7 +25,7 @@ class ActionAlias(core.Resource):
     _alias = 'Action-Alias'
     _display_name = 'Action Alias'
     _plural = 'ActionAliases'
-    _plural_display_name = 'Runners'
+    _plural_display_name = 'Action Aliases'
     _url_path = 'actionalias'
     _repr_attributes = ['name', 'pack', 'action_ref']
 


Test patch:
Repository: StackStorm/st2

Issue:
st2kv does not resolve in Jinja cast expression
In the rule: 
` {{ "2" | int }} - 2` Dah
`{{ trigger.count | int }} -> 2` OK
`{{ st2kv.system.count | int }} -> 0` Wrong.



Discussion:
Can confirm.

```
vagrant@st2packages-u16:~$ st2 key set count 2
+------------------+-------+
| Property         | Value |
+------------------+-------+
| name             | count |
| value            | 2     |
| expire_timestamp |       |
+------------------+-------+
vagrant@st2packages-u16:~$ st2 run core.local cmd="echo {{ st2kv.system.count | int }}"
.
id: 591541a63cb4275c92431e10
status: succeeded
parameters:
  cmd: echo {{ st2kv.system.count | int }}
result:
  failed: false
  return_code: 0
  stderr: ''
  stdout: 0
  succeeded: true
```

Resolving patch:
diff --git a/st2common/st2common/services/keyvalues.py b/st2common/st2common/services/keyvalues.py
--- a/st2common/st2common/services/keyvalues.py
+++ b/st2common/st2common/services/keyvalues.py
@@ -82,6 +82,12 @@ def __init__(self, prefix=None, key_prefix=None, cache=None, scope=FULL_SYSTEM_S
     def __str__(self):
         return self._value_cache[self._key_prefix]
 
+    def __int__(self):
+        return int(float(self))
+
+    def __float__(self):
+        return float(str(self))
+
     def __getitem__(self, key):
         return self._get(key)
 


Test patch:
diff --git a/st2common/tests/unit/test_keyvalue_lookup.py b/st2common/tests/unit/test_keyvalue_lookup.py
--- a/st2common/tests/unit/test_keyvalue_lookup.py
+++ b/st2common/tests/unit/test_keyvalue_lookup.py
@@ -145,3 +145,11 @@ def test_secret_lookup(self):
 
         user_lookup = UserKeyValueLookup(scope=FULL_USER_SCOPE, user='stanley')
         self.assertEquals(str(user_lookup.k3), k3.value)
+
+    def test_lookup_cast(self):
+        KeyValuePair.add_or_update(KeyValuePairDB(name='count', value='5.5'))
+
+        lookup = KeyValueLookup(scope=FULL_SYSTEM_SCOPE)
+        self.assertEqual(str(lookup.count), '5.5')
+        self.assertEqual(float(lookup.count), 5.5)
+        self.assertEqual(int(lookup.count), 5)
Repository: StackStorm/st2

Issue:
st2 execution run should display result for Mistral workflows on completion
We should display workflow result (result from the last completed task / action) on workflow completion when using `st2 execution run` command.

We already do that for action chain workflows and, IIRC, we also already did it for Mistral workflows.

Not displaying a result means user needs to type another command (`st2 execution get <last task execution id>`) which is rather annoying.

See https://gist.github.com/Kami/5b2f9bb7dd3b98cf46e5fddcecba9387




Discussion:
I agree, it would be helpfull

Resolving patch:
diff --git a/st2client/st2client/commands/action.py b/st2client/st2client/commands/action.py
--- a/st2client/st2client/commands/action.py
+++ b/st2client/st2client/commands/action.py
@@ -356,14 +356,15 @@ def _run_and_print_child_task_list(self, execution, args, **kwargs):
             # No child error, there might be a global error, include result in the output
             options['attributes'].append('result')
 
+        status_index = options['attributes'].index('status')
+
+        if isinstance(instance.result, dict):
+            tasks = instance.result.get('tasks', [])
+        else:
+            tasks = []
+
         # On failure we also want to include error message and traceback at the top level
         if instance.status == 'failed':
-            status_index = options['attributes'].index('status')
-            if isinstance(instance.result, dict):
-                tasks = instance.result.get('tasks', [])
-            else:
-                tasks = []
-
             top_level_error, top_level_traceback = self._get_top_level_error(live_action=instance)
 
             if len(tasks) >= 1:
@@ -388,6 +389,17 @@ def _run_and_print_child_task_list(self, execution, args, **kwargs):
                 options['attributes'].insert(status_index + 2, 'traceback')
                 options['attributes'].insert(status_index + 3, 'failed_on')
 
+        # Include result on the top-level object so user doesn't need to issue another command to
+        # see the result
+        if len(tasks) >= 1:
+            task_result = self._get_task_result(task=tasks[-1])
+
+            if task_result:
+                instance.result_task = tasks[-1].get('name', 'unknown')
+                options['attributes'].insert(status_index + 1, 'result_task')
+                options['attributes'].insert(status_index + 2, 'result')
+                instance.result = task_result
+
         # print root task
         self.print_output(instance, formatter, **options)
 
@@ -460,6 +472,12 @@ def _get_task_error(self, task):
 
         return error, traceback
 
+    def _get_task_result(self, task):
+        if not task:
+            return None
+
+        return task['result']
+
     def _get_action_parameters_from_args(self, action, runner, args):
         """
         Build a dictionary with parameters which will be passed to the action by


Test patch:
Repository: StackStorm/st2

Issue:
Don't publish messages to exporter exchange if exporter service is not enabled and running
While working on #3648 and I noticed `st2.exporter.work` queue grows indefinitely.

The reason for that is that exporter service is optional and doesn't run by default.

We should modify the code to only publish messages to that exchange if exporter service is enabled and running (otherwise this queue will keep growing indefinitely and this could eventually cause issues).


Discussion:

Resolving patch:
diff --git a/st2common/st2common/transport/bootstrap_utils.py b/st2common/st2common/transport/bootstrap_utils.py
--- a/st2common/st2common/transport/bootstrap_utils.py
+++ b/st2common/st2common/transport/bootstrap_utils.py
@@ -32,7 +32,6 @@
 from st2common.transport.queues import ACTIONSCHEDULER_REQUEST_QUEUE
 from st2common.transport.queues import ACTIONRUNNER_WORK_QUEUE
 from st2common.transport.queues import ACTIONRUNNER_CANCEL_QUEUE
-from st2common.transport.queues import EXPORTER_WORK_QUEUE
 from st2common.transport.queues import NOTIFIER_ACTIONUPDATE_WORK_QUEUE
 from st2common.transport.queues import RESULTSTRACKER_ACTIONSTATE_WORK_QUEUE
 from st2common.transport.queues import RULESENGINE_WORK_QUEUE
@@ -68,7 +67,6 @@
     ACTIONSCHEDULER_REQUEST_QUEUE,
     ACTIONRUNNER_WORK_QUEUE,
     ACTIONRUNNER_CANCEL_QUEUE,
-    EXPORTER_WORK_QUEUE,
     NOTIFIER_ACTIONUPDATE_WORK_QUEUE,
     RESULTSTRACKER_ACTIONSTATE_WORK_QUEUE,
     RULESENGINE_WORK_QUEUE,


Test patch: