Restructure simulate api to avoid passing query in uri

This patch restructures the simulate_action api to pass in the
query/sequence/action_policy via the body rather than the uri in
order to avoid a request URI to long error.

Note: one needs the corresponding server side change as well.
DocImpact
Closes-bug: 1410080

Change-Id: I35be50021d50b0a84bc57d63e09817a7485113f9
This commit is contained in:
Aaron Rosen 2015-01-14 16:39:16 -08:00
parent 5b45c490df
commit 69bdfe942f
3 changed files with 37 additions and 25 deletions

View File

@ -160,8 +160,17 @@ class SimulatePolicy(command.Command):
args['delta'] = parsed_args.delta
if parsed_args.trace:
args['trace'] = parsed_args.trace
body = {'query': parsed_args.query,
'sequence': parsed_args.sequence,
'action_policy': parsed_args.action_policy}
results = client.execute_policy_action(
parsed_args.policy, 'simulate', args)
policy_name=parsed_args.policy,
action="simulate",
trace=parsed_args.trace,
delta=parsed_args.delta,
body=body)
for result in results['result']:
print(result)
if 'trace' in results:

View File

@ -268,11 +268,14 @@ class TestSimulatePolicy(common.TestCongressBase):
parsed_args = self.check_parser(cmd, arglist, verifylist)
cmd.take_action(parsed_args)
args = {}
args['action_policy'] = action_name
args['sequence'] = sequence
args['query'] = query
lister.assert_called_with(policy_name, 'simulate', args)
body = {'action_policy': action_name,
'sequence': sequence,
'query': query}
lister.assert_called_with(policy_name=policy_name,
action='simulate',
trace=False,
delta=False,
body=body)
def test_simulate_policy_delta(self):
policy_name = 'classification'
@ -298,12 +301,14 @@ class TestSimulatePolicy(common.TestCongressBase):
parsed_args = self.check_parser(cmd, arglist, verifylist)
cmd.take_action(parsed_args)
args = {}
args['action_policy'] = action_name
args['sequence'] = sequence
args['query'] = query
args['delta'] = True
lister.assert_called_with(policy_name, 'simulate', args)
body = {'action_policy': action_name,
'sequence': sequence,
'query': query}
lister.assert_called_with(policy_name=policy_name,
action='simulate',
trace=False,
delta=True,
body=body)
def test_simulate_policy_trace(self):
policy_name = 'classification'
@ -329,12 +334,14 @@ class TestSimulatePolicy(common.TestCongressBase):
parsed_args = self.check_parser(cmd, arglist, verifylist)
cmd.take_action(parsed_args)
args = {}
args['action_policy'] = action_name
args['sequence'] = sequence
args['query'] = query
args['trace'] = True
lister.assert_called_with(policy_name, 'simulate', args)
body = {'action_policy': action_name,
'sequence': sequence,
'query': query}
lister.assert_called_with(policy_name=policy_name,
action='simulate',
trace=True,
delta=False,
body=body)
class TestGet(common.TestCongressBase):

View File

@ -12,8 +12,6 @@
# License for the specific language governing permissions and limitations
# under the License.
import urllib
from keystoneclient import adapter
@ -109,12 +107,10 @@ class Client(object):
resp, body = self.httpclient.get(self.policy_tables % (policy_name))
return body
def execute_policy_action(self, policy_name, action, args):
newargs = dict(args) # make a copy; then add action=<action>
newargs['action'] = action
actionurl = urllib.urlencode(newargs)
def execute_policy_action(self, policy_name, action, trace, delta, body):
uri = "?action=%s&trace=%s&delta=%s" % (action, trace, delta)
resp, body = self.httpclient.post(
self.policy_action % (policy_name, actionurl))
(self.policy_path % policy_name) + str(uri), body=body)
return body
def list_datasources(self):