Fix how "--limit" is passed to the server for action executions
Change-Id: I4106c3c7cc52e41857fc588828dfc596fb91b4f5
(cherry picked from commit fd0b5de1c5)
			
			
This commit is contained in:
		@@ -7,9 +7,15 @@ wf:
 | 
			
		||||
  tasks:
 | 
			
		||||
    hello:
 | 
			
		||||
      action: std.echo output="Hello"
 | 
			
		||||
      wait-before: 5
 | 
			
		||||
      wait-before: 1
 | 
			
		||||
      publish:
 | 
			
		||||
        result: <% task(hello).result %>
 | 
			
		||||
        result: <% task().result %>
 | 
			
		||||
      on-success: bye
 | 
			
		||||
 | 
			
		||||
    bye:
 | 
			
		||||
      action: std.echo output="Bye"
 | 
			
		||||
      publish:
 | 
			
		||||
        result: <% $.result + ', ' + task().result %>
 | 
			
		||||
 | 
			
		||||
wf1:
 | 
			
		||||
  type: reverse
 | 
			
		||||
 
 | 
			
		||||
@@ -13,9 +13,12 @@
 | 
			
		||||
#    limitations under the License.
 | 
			
		||||
 | 
			
		||||
import json
 | 
			
		||||
import six
 | 
			
		||||
 | 
			
		||||
from mistralclient.api import base
 | 
			
		||||
 | 
			
		||||
urlparse = six.moves.urllib.parse
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class ActionExecution(base.Resource):
 | 
			
		||||
    resource_name = 'ActionExecution'
 | 
			
		||||
@@ -66,15 +69,20 @@ class ActionExecutionManager(base.ResourceManager):
 | 
			
		||||
    def list(self, task_execution_id=None, limit=None):
 | 
			
		||||
        url = '/action_executions'
 | 
			
		||||
 | 
			
		||||
        qparams = {}
 | 
			
		||||
 | 
			
		||||
        if task_execution_id:
 | 
			
		||||
            url = '/tasks/%s/action_executions' % task_execution_id
 | 
			
		||||
 | 
			
		||||
        url += "%s"
 | 
			
		||||
 | 
			
		||||
        qparams = {}
 | 
			
		||||
 | 
			
		||||
        if limit:
 | 
			
		||||
            qparams['limit'] = limit
 | 
			
		||||
 | 
			
		||||
        return self._list(url, response_key='action_executions')
 | 
			
		||||
        query_string = ("?%s" % urlparse.urlencode(list(qparams.items()))
 | 
			
		||||
                        if qparams else "")
 | 
			
		||||
 | 
			
		||||
        return self._list(url % query_string, response_key='action_executions')
 | 
			
		||||
 | 
			
		||||
    def get(self, id):
 | 
			
		||||
        self._ensure_not_empty(id=id)
 | 
			
		||||
 
 | 
			
		||||
@@ -154,6 +154,7 @@ class Create(command.ShowOne):
 | 
			
		||||
            action_input = utils.load_json(parsed_args.input)
 | 
			
		||||
 | 
			
		||||
        mistral_client = self.app.client_manager.workflow_engine
 | 
			
		||||
 | 
			
		||||
        action_ex = mistral_client.action_executions.create(
 | 
			
		||||
            parsed_args.name,
 | 
			
		||||
            action_input,
 | 
			
		||||
@@ -196,10 +197,14 @@ class List(base.MistralLister):
 | 
			
		||||
    def _get_resources(self, parsed_args):
 | 
			
		||||
        if parsed_args.limit is None:
 | 
			
		||||
            parsed_args.limit = base.DEFAULT_LIMIT
 | 
			
		||||
            LOG.info("limit is set to %s by default. Set "
 | 
			
		||||
 | 
			
		||||
            LOG.info(
 | 
			
		||||
                "limit is set to %s by default. Set "
 | 
			
		||||
                "the limit explicitly using \'--limit\', if required. "
 | 
			
		||||
                "Use \'--limit\' -1 to fetch the full result set.",
 | 
			
		||||
                     base.DEFAULT_LIMIT)
 | 
			
		||||
                base.DEFAULT_LIMIT
 | 
			
		||||
            )
 | 
			
		||||
 | 
			
		||||
        mistral_client = self.app.client_manager.workflow_engine
 | 
			
		||||
 | 
			
		||||
        return mistral_client.action_executions.list(
 | 
			
		||||
 
 | 
			
		||||
@@ -126,10 +126,14 @@ class List(base.MistralLister):
 | 
			
		||||
    def _get_resources(self, parsed_args):
 | 
			
		||||
        if parsed_args.limit is None:
 | 
			
		||||
            parsed_args.limit = base.DEFAULT_LIMIT
 | 
			
		||||
            LOG.info("limit is set to %s by default. Set "
 | 
			
		||||
 | 
			
		||||
            LOG.info(
 | 
			
		||||
                "limit is set to %s by default. Set "
 | 
			
		||||
                "the limit explicitly using \'--limit\', if required. "
 | 
			
		||||
                "Use \'--limit\' -1 to fetch the full result set.",
 | 
			
		||||
                     base.DEFAULT_LIMIT)
 | 
			
		||||
                base.DEFAULT_LIMIT
 | 
			
		||||
            )
 | 
			
		||||
 | 
			
		||||
        mistral_client = self.app.client_manager.workflow_engine
 | 
			
		||||
 | 
			
		||||
        return mistral_client.executions.list(
 | 
			
		||||
 
 | 
			
		||||
@@ -97,10 +97,14 @@ class List(base.MistralLister):
 | 
			
		||||
    def _get_resources(self, parsed_args):
 | 
			
		||||
        if parsed_args.limit is None:
 | 
			
		||||
            parsed_args.limit = base.DEFAULT_LIMIT
 | 
			
		||||
            LOG.info("limit is set to %s by default. Set "
 | 
			
		||||
 | 
			
		||||
            LOG.info(
 | 
			
		||||
                "limit is set to %s by default. Set "
 | 
			
		||||
                "the limit explicitly using \'--limit\', if required. "
 | 
			
		||||
                "Use \'--limit\' -1 to fetch the full result set.",
 | 
			
		||||
                     base.DEFAULT_LIMIT)
 | 
			
		||||
                base.DEFAULT_LIMIT
 | 
			
		||||
            )
 | 
			
		||||
 | 
			
		||||
        mistral_client = self.app.client_manager.workflow_engine
 | 
			
		||||
 | 
			
		||||
        return mistral_client.tasks.list(
 | 
			
		||||
 
 | 
			
		||||
@@ -1252,14 +1252,35 @@ class ActionExecutionCLITests(base_v2.MistralClientTestBase):
 | 
			
		||||
        )
 | 
			
		||||
 | 
			
		||||
        wf_name = self.get_field_value(act_ex, 'Workflow name')
 | 
			
		||||
        status = self.get_field_value(act_ex, 'State')
 | 
			
		||||
        state = self.get_field_value(act_ex, 'State')
 | 
			
		||||
 | 
			
		||||
        self.assertEqual(
 | 
			
		||||
            act_ex_from_list['ID'],
 | 
			
		||||
            self.get_field_value(act_ex, 'ID')
 | 
			
		||||
        )
 | 
			
		||||
        self.assertEqual(self.direct_wf['Name'], wf_name)
 | 
			
		||||
        self.assertEqual('SUCCESS', status)
 | 
			
		||||
        self.assertEqual('SUCCESS', state)
 | 
			
		||||
 | 
			
		||||
    def test_act_execution_list_with_limit(self):
 | 
			
		||||
        self.wait_execution_success(self.direct_ex_id)
 | 
			
		||||
 | 
			
		||||
        act_execs = self.mistral_admin('action-execution-list')
 | 
			
		||||
 | 
			
		||||
        # The workflow execution started in setUp()
 | 
			
		||||
        # generates 2 action executions.
 | 
			
		||||
        self.assertGreater(len(act_execs), 1)
 | 
			
		||||
 | 
			
		||||
        act_execs = self.mistral_admin(
 | 
			
		||||
            'action-execution-list',
 | 
			
		||||
            params="--limit 1"
 | 
			
		||||
        )
 | 
			
		||||
 | 
			
		||||
        self.assertEqual(len(act_execs), 1)
 | 
			
		||||
 | 
			
		||||
        act_ex = act_execs[0]
 | 
			
		||||
 | 
			
		||||
        self.assertEqual(self.direct_wf['Name'], act_ex['Workflow name'])
 | 
			
		||||
        self.assertEqual('SUCCESS', act_ex['State'])
 | 
			
		||||
 | 
			
		||||
    def test_act_execution_create_delete(self):
 | 
			
		||||
        action_ex = self.mistral_admin(
 | 
			
		||||
 
 | 
			
		||||
@@ -24,7 +24,6 @@ ACTION_EXEC = {
 | 
			
		||||
    'state': 'RUNNING',
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
URL_TEMPLATE = '/action_executions'
 | 
			
		||||
URL_TEMPLATE_ID = '/action_executions/%s'
 | 
			
		||||
 | 
			
		||||
@@ -94,6 +93,21 @@ class TestActionExecutions(base.BaseClientV2Test):
 | 
			
		||||
 | 
			
		||||
        self.assertEqual(expected, action_execution.to_dict())
 | 
			
		||||
 | 
			
		||||
    def test_list_with_limit(self):
 | 
			
		||||
        self.requests_mock.get(
 | 
			
		||||
            self.TEST_URL + URL_TEMPLATE,
 | 
			
		||||
            json={'action_executions': [ACTION_EXEC]}
 | 
			
		||||
        )
 | 
			
		||||
 | 
			
		||||
        action_execution_list = self.action_executions.list(limit=1)
 | 
			
		||||
 | 
			
		||||
        self.assertEqual(1, len(action_execution_list))
 | 
			
		||||
 | 
			
		||||
        last_request = self.requests_mock.last_request
 | 
			
		||||
 | 
			
		||||
        # Make sure that limit is passed to the server correctly.
 | 
			
		||||
        self.assertEqual(['1'], last_request.qs['limit'])
 | 
			
		||||
 | 
			
		||||
    def test_get(self):
 | 
			
		||||
        url = self.TEST_URL + URL_TEMPLATE_ID % ACTION_EXEC['id']
 | 
			
		||||
        self.requests_mock.get(url, json=ACTION_EXEC)
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user