FWaaS UT: Fake rule should return value returned from API
In FWaaS UT, fwaas.fakes.FirewallRule is expected to return the same values returned from the API, but it returns 'any' for 'protocol'. In FWaaS API definition, JSON null (None in python) means 'any', so it should be None rather than 'any'. This commit fixes it and related codes in test_firewall.py. _generate_data() generates expected formatted data from API data. The same logic is also needed in _update_expect_response(). This commit introduces a common function _replace_display_columns to do this. Change-Id: If4fa6b26f72003b6c94020a762a5c19d17b338cd
This commit is contained in:
parent
4295dfb8de
commit
632671e4d9
|
@ -107,7 +107,7 @@ class FirewallRule(FakeFWaaS):
|
|||
('description', 'my-desc-' + uuid.uuid4().hex),
|
||||
('ip_version', 4),
|
||||
('action', 'deny'),
|
||||
('protocol', 'any'),
|
||||
('protocol', None),
|
||||
('source_ip_address', '192.168.1.0/24'),
|
||||
('source_port', '1:11111'),
|
||||
('destination_ip_address', '192.168.2.2'),
|
||||
|
|
|
@ -42,7 +42,18 @@ def _generate_data(ordered_dict=None, data=None):
|
|||
source = ordered_dict if ordered_dict else _fwr
|
||||
if data:
|
||||
source.update(data)
|
||||
return tuple(source[key] for key in source)
|
||||
return tuple(_replace_display_columns(key, source[key]) for key in source)
|
||||
|
||||
|
||||
def _replace_display_columns(key, val):
|
||||
# TODO(amotoki): This is required because of the logic of
|
||||
# osc_lib.utils.get_dict_properties().
|
||||
# It needs to be fixed in osc-lib first.
|
||||
if val is None:
|
||||
return val
|
||||
if key == 'protocol':
|
||||
return firewallrule.format_protocol(val)
|
||||
return val
|
||||
|
||||
|
||||
def _generate_req_and_res(verifylist):
|
||||
|
@ -133,7 +144,7 @@ class TestFirewallRule(test_fakes.TestNeutronClientOSCV2):
|
|||
_fwr['ip_version'],
|
||||
_fwr['name'],
|
||||
_fwr['tenant_id'],
|
||||
_fwr['protocol'],
|
||||
_replace_display_columns('protocol', _fwr['protocol']),
|
||||
_fwr['public'],
|
||||
_fwr['source_ip_address'],
|
||||
_fwr['source_port'],
|
||||
|
@ -179,7 +190,8 @@ class TestCreateFirewallRule(TestFirewallRule, common.TestCreateFWaaS):
|
|||
# Update response(finally returns 'data')
|
||||
self.data = _generate_data(ordered_dict=response)
|
||||
self.ordered_data = tuple(
|
||||
response[column] for column in self.ordered_columns
|
||||
_replace_display_columns(column, response[column])
|
||||
for column in self.ordered_columns
|
||||
)
|
||||
|
||||
def _set_all_params(self, args={}):
|
||||
|
@ -273,7 +285,7 @@ class TestCreateFirewallRule(TestFirewallRule, common.TestCreateFWaaS):
|
|||
class TestListFirewallRule(TestFirewallRule):
|
||||
|
||||
def _setup_summary(self, expect=None):
|
||||
protocol = _fwr['protocol'].upper()
|
||||
protocol = (_fwr['protocol'] or 'any').upper()
|
||||
src = 'source(port): 192.168.1.0/24(1:11111)'
|
||||
dst = 'dest(port): 192.168.2.2(2:22222)'
|
||||
action = 'deny'
|
||||
|
|
Loading…
Reference in New Issue