Merge "Don't sort the fw_rule order in OSC"

This commit is contained in:
Jenkins
2017-03-10 07:08:37 +00:00
committed by Gerrit Code Review
2 changed files with 16 additions and 16 deletions

View File

@@ -54,20 +54,20 @@ def _get_common_attrs(client_manager, parsed_args, is_create=True):
).id ).id
if parsed_args.firewall_rule and parsed_args.no_firewall_rule: if parsed_args.firewall_rule and parsed_args.no_firewall_rule:
_firewall_rules = [] _firewall_rules = []
for f in set(parsed_args.firewall_rule): for f in parsed_args.firewall_rule:
_firewall_rules.append(client.find_resource( _firewall_rules.append(client.find_resource(
const.FWR, f, cmd_resource=const.CMD_FWR)['id']) const.FWR, f, cmd_resource=const.CMD_FWR)['id'])
attrs[const.FWRS] = sorted(_firewall_rules) attrs[const.FWRS] = _firewall_rules
elif parsed_args.firewall_rule: elif parsed_args.firewall_rule:
rules = [] rules = []
for f in set(parsed_args.firewall_rule):
rules.append(client.find_resource(
const.FWR, f, cmd_resource=const.CMD_FWR)['id'])
if not is_create: if not is_create:
rules += client.find_resource( rules += client.find_resource(
const.FWP, parsed_args.firewall_policy, const.FWP, parsed_args.firewall_policy,
cmd_resource=const.CMD_FWP)[const.FWRS] cmd_resource=const.CMD_FWP)[const.FWRS]
attrs[const.FWRS] = sorted(set(rules)) for f in parsed_args.firewall_rule:
rules.append(client.find_resource(
const.FWR, f, cmd_resource=const.CMD_FWR)['id'])
attrs[const.FWRS] = rules
elif parsed_args.no_firewall_rule: elif parsed_args.no_firewall_rule:
attrs[const.FWRS] = [] attrs[const.FWRS] = []
if parsed_args.audited: if parsed_args.audited:
@@ -395,14 +395,14 @@ class UnsetFirewallPolicy(command.Command):
client = client_manager.neutronclient client = client_manager.neutronclient
if parsed_args.firewall_rule: if parsed_args.firewall_rule:
old = client.find_resource( current = client.find_resource(
const.FWP, parsed_args.firewall_policy, const.FWP, parsed_args.firewall_policy,
cmd_resource=const.CMD_FWP)[const.FWRS] cmd_resource=const.CMD_FWP)[const.FWRS]
new = [] removed = []
for f in set(parsed_args.firewall_rule): for f in set(parsed_args.firewall_rule):
new.append(client.find_resource( removed.append(client.find_resource(
const.FWR, f, cmd_resource=const.CMD_FWR)['id']) const.FWR, f, cmd_resource=const.CMD_FWR)['id'])
attrs[const.FWRS] = sorted(list(set(old) - set(new))) attrs[const.FWRS] = [r for r in current if r not in removed]
if parsed_args.all_firewall_rule: if parsed_args.all_firewall_rule:
attrs[const.FWRS] = [] attrs[const.FWRS] = []
if parsed_args.audited: if parsed_args.audited:

View File

@@ -343,19 +343,19 @@ class TestSetFirewallPolicy(TestFirewallPolicy, common.TestSetFWaaS):
if self.neutronclient.find_resource.call_count == 1: if self.neutronclient.find_resource.call_count == 1:
self.neutronclient.find_resource.assert_called_with( self.neutronclient.find_resource.assert_called_with(
self.res, target, cmd_resource=const.CMD_FWP) self.res, target, cmd_resource=const.CMD_FWP)
# 2. Find specified firewall_rule # 2. Find specified firewall_policy's 'firewall_rules' attribute
if self.neutronclient.find_resource.call_count == 2: if self.neutronclient.find_resource.call_count == 2:
self.neutronclient.find_resource.assert_called_with( self.neutronclient.find_resource.assert_called_with(
'firewall_rule', args[1], cmd_resource=const.CMD_FWR) self.res, args[1], cmd_resource=const.CMD_FWP)
return {'firewall_rules': _fwp['firewall_rules']}
# 3. Find specified firewall_rule # 3. Find specified firewall_rule
if self.neutronclient.find_resource.call_count == 3: if self.neutronclient.find_resource.call_count == 3:
self.neutronclient.find_resource.assert_called_with( self.neutronclient.find_resource.assert_called_with(
'firewall_rule', args[1], cmd_resource=const.CMD_FWR) 'firewall_rule', args[1], cmd_resource=const.CMD_FWR)
# 4. Find specified firewall_policy's 'firewall_rules' attribute # 4. Find specified firewall_rule
if self.neutronclient.find_resource.call_count == 4: if self.neutronclient.find_resource.call_count == 4:
self.neutronclient.find_resource.assert_called_with( self.neutronclient.find_resource.assert_called_with(
self.res, target, cmd_resource=const.CMD_FWP) 'firewall_rule', args[1], cmd_resource=const.CMD_FWR)
return {'firewall_rules': _fwp['firewall_rules']}
return {'id': args[1]} return {'id': args[1]}
self.neutronclient.find_resource.side_effect = _mock_policy self.neutronclient.find_resource.side_effect = _mock_policy
@@ -372,7 +372,7 @@ class TestSetFirewallPolicy(TestFirewallPolicy, common.TestSetFWaaS):
parsed_args = self.check_parser(self.cmd, arglist, verifylist) parsed_args = self.check_parser(self.cmd, arglist, verifylist)
result = self.cmd.take_action(parsed_args) result = self.cmd.take_action(parsed_args)
expect = sorted(set(_fwp['firewall_rules'] + [rule1, rule2])) expect = _fwp['firewall_rules'] + [rule1, rule2]
body = {self.res: {'firewall_rules': expect}} body = {self.res: {'firewall_rules': expect}}
self.mocked.assert_called_once_with(target, body) self.mocked.assert_called_once_with(target, body)
self.assertEqual(4, self.neutronclient.find_resource.call_count) self.assertEqual(4, self.neutronclient.find_resource.call_count)