def test_get_flows_config_invalid_action(self, get_default_flows): """Check if incorrect ACL config fails to convert to ACL SampleVNF CLI commands""" ssh_helper = mock.Mock() setup_helper = AclApproxSetupEnvSetupEnvHelper(None, ssh_helper, None) get_default_flows.return_value = ({}, []) # duplicate config and add invald action acl_config = copy.deepcopy(self.ACL_CONFIG) acl_config['access-list-entries'][0]["actions"].append({"xnat": {}}) self.assertRaises(exceptions.AclUknownActionTemplate, setup_helper.get_flows_config, acl_config)
def test_get_flows_config_invalid_action_param(self, get_default_flows): """Check if ACL config with invalid action parameter fails to convert to ACL SampleVNF CLI commands""" ssh_helper = mock.Mock() setup_helper = AclApproxSetupEnvSetupEnvHelper(None, ssh_helper, None) get_default_flows.return_value = ({}, []) # duplicate config and add action with invalid parameter acl_config = copy.deepcopy(self.ACL_CONFIG) acl_config['access-list-entries'][0]["actions"].append( {"nat": {"xport": 0}}) self.assertRaises(exceptions.AclMissingActionArguments, setup_helper.get_flows_config, acl_config)
def test_get_flows_config(self, get_default_flows): """Check if provided ACL config can be converted to ACL SampleVNF CLI commands correctly""" ssh_helper = mock.Mock() setup_helper = AclApproxSetupEnvSetupEnvHelper(None, ssh_helper, None) get_default_flows.return_value = ({}, []) self.check_acl_commands(setup_helper.get_flows_config(self.ACL_CONFIG), [ # format: (<cli pattern>, <number of expected matches>) ("^p action add [0-9]+ count$", 1), ("^p action add [0-9]+ fwd 0$", 1), ("^p acl add 1 0.0.0.0 0 152.16.0.0 24 0 65535 0 65535 127 0 [0-9]+$", 1), ("^p acl applyruleset$", 1) ])
def test_get_default_flows(self): """Check if default ACL SampleVNF CLI commands are generated correctly""" ssh_helper = mock.Mock() vnfd_helper = VnfdHelper({ 'vdu': [{ 'external-interface': [{ 'virtual-interface': { 'local_ip': '152.16.100.19', 'netmask': '255.255.255.0', 'dpdk_port_num': 0, 'dst_ip': '152.16.100.20', 'vld_id': 'uplink_0', 'ifname': 'xe0', }, 'vnfd-connection-point-ref': 'xe0', 'name': 'xe0' }, { 'virtual-interface': { 'local_ip': '152.16.40.19', 'netmask': '255.255.255.0', 'dpdk_port_num': 1, 'dst_ip': '152.16.40.20', 'vld_id': 'downlink_0', 'ifname': 'xe1', }, 'vnfd-connection-point-ref': 'xe1', 'name': 'xe1' }] }] }) setup_helper = AclApproxSetupEnvSetupEnvHelper(vnfd_helper, ssh_helper, None) self.check_acl_commands( setup_helper.get_flows_config(), [ # format: (<cli pattern>, <number of expected matches>) ("^p action add [0-9]+ accept$", 2), ("^p action add [0-9]+ count$", 2), ("^p action add [0-9]+ fwd 1$", 1), ("^p action add [0-9]+ fwd 0$", 1), ("^p acl add 1 152.16.100.0 24 152.16.40.0 24 0 65535 0 65535 0 0 [0-9]+$", 1), ("^p acl add 1 152.16.40.0 24 152.16.100.0 24 0 65535 0 65535 0 0 [0-9]+$", 1), ("^p acl applyruleset$", 1) ])
def test_build_config(self, *args): vnfd_helper = mock.Mock() ssh_helper = mock.Mock() scenario_helper = mock.Mock() scenario_helper.vnf_cfg = {'lb_config': 'HW'} scenario_helper.options = {} scenario_helper.all_options = {} acl_approx_setup_helper = AclApproxSetupEnvSetupEnvHelper(vnfd_helper, ssh_helper, scenario_helper) acl_approx_setup_helper.get_flows_config = mock.Mock() acl_approx_setup_helper.ssh_helper.provision_tool = mock.Mock(return_value='tool_path') acl_approx_setup_helper.ssh_helper.all_ports = mock.Mock() acl_approx_setup_helper.vnfd_helper.port_nums = mock.Mock(return_value=[0, 1]) expected = 'sudo tool_path -p 0x3 -f /tmp/acl_config -s /tmp/acl_script --hwlb 3' self.assertEqual(acl_approx_setup_helper.build_config(), expected) acl_approx_setup_helper.get_flows_config.assert_called_once()