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_wait_for_instantiate_panic(self, ssh, mock_time): mock_ssh(ssh, exec_result=(1, "", "")) prox_approx_vnf = ProxApproxVnf(NAME, self.VNFD0) prox_approx_vnf._vnf_process = mock.MagicMock(**{"is_alive.return_value": True}) prox_approx_vnf._run_prox = mock.Mock(return_value=0) prox_approx_vnf.WAIT_TIME = 0 prox_approx_vnf.q_out.put("PANIC") with self.assertRaises(RuntimeError): prox_approx_vnf.wait_for_instantiate()
def test_run_prox(self, ssh, mock_time): mock_ssh(ssh) prox_approx_vnf = ProxApproxVnf(NAME, self.VNFD0) filewrapper = mock.MagicMock() config_path = self.SCENARIO_CFG['options']["vnf__1"]["prox_config"] prox_path = self.SCENARIO_CFG['options']["vnf__1"]["prox_path"] prox_args = self.SCENARIO_CFG['options']["vnf__1"]["prox_args"] prox_approx_vnf.WAIT_TIME = 0 prox_approx_vnf._run_prox(filewrapper, config_path, prox_path, prox_args) self.assertEqual(prox_approx_vnf.ssh_helper.run.call_args[0][0], "sudo bash -c 'cd /root/dppd-PROX-v035/build; " "/root/dppd-PROX-v035/build/prox -o cli -t -f configs/l3-swap-2.cfg '")