def test_instantiate(self, ssh, mock_find, mock_cpu_sys_cores, mock_time): mock_ssh(ssh) mock_cpu_sys_cores.get_core_socket.return_value = {'0': '01234'} prox_approx_vnf = ProxApproxVnf(NAME, self.VNFD0) prox_approx_vnf.ssh_helper = mock.MagicMock( **{"execute.return_value": (0, "", ""), "bin_path": ""}) prox_approx_vnf.setup_helper._setup_resources = mock.MagicMock() prox_approx_vnf.setup_helper._find_used_drivers = mock.MagicMock() prox_approx_vnf.setup_helper.used_drivers = {} prox_approx_vnf.setup_helper.bound_pci = [] prox_approx_vnf._run_prox = mock.MagicMock(return_value=0) prox_approx_vnf.resource_helper = mock.MagicMock() prox_approx_vnf.resource_helper.get_process_args.return_value = { '-e': '', '-t': '', }, 'configs/l3-gen-2.cfg', '/root/dppd-PROX-v035/build/prox' prox_approx_vnf.copy_to_target = mock.MagicMock() prox_approx_vnf.upload_prox_config = mock.MagicMock() prox_approx_vnf.generate_prox_config_file = mock.MagicMock() prox_approx_vnf.q_out.put("PROX started") prox_approx_vnf.WAIT_TIME = 0 # if process it still running exitcode will be None expected = 0, None result = prox_approx_vnf.instantiate(self.SCENARIO_CFG, self.CONTEXT_CFG) self.assertIn(result, expected)
def test_collect_kpi(self, ssh, mock_time): mock_ssh(ssh) resource_helper = mock.MagicMock() resource_helper.execute.return_value = list(range(12)) resource_helper.collect_collectd_kpi.return_value = { 'core': { 'result': 234 } } prox_approx_vnf = ProxApproxVnf(NAME, self.VNFD0) prox_approx_vnf.resource_helper = resource_helper expected = { 'packets_in': 7, 'packets_dropped': 1, 'packets_fwd': 6, 'collect_stats': { 'core': { 'result': 234 } }, } result = prox_approx_vnf.collect_kpi() self.assertEqual(result, expected)
def test_terminate(self, ssh, mock_socket, mock_time): mock_ssh(ssh) prox_approx_vnf = ProxApproxVnf(NAME, self.VNFD0) prox_approx_vnf._vnf_process = mock.MagicMock() prox_approx_vnf._vnf_process.terminate = mock.Mock() prox_approx_vnf.ssh_helper = mock.MagicMock() prox_approx_vnf.setup_helper = mock.Mock() prox_approx_vnf.resource_helper = mock.MagicMock() self.assertIsNone(prox_approx_vnf.terminate())
def test_collect_kpi_error(self, ssh, mock_time): mock_ssh(ssh) resource_helper = mock.MagicMock() prox_approx_vnf = ProxApproxVnf(NAME, deepcopy(self.VNFD0)) prox_approx_vnf.resource_helper = resource_helper prox_approx_vnf.vnfd_helper['vdu'][0]['external-interface'] = [] with self.assertRaises(RuntimeError): prox_approx_vnf.collect_kpi()
def test_collect_kpi_no_client(self, ssh, mock_time): mock_ssh(ssh) prox_approx_vnf = ProxApproxVnf(NAME, self.VNFD0) prox_approx_vnf.resource_helper = None expected = { 'packets_in': 0, 'packets_dropped': 0, 'packets_fwd': 0, 'collect_stats': {'core': {}}, } result = prox_approx_vnf.collect_kpi() self.assertEqual(result, expected)