def test_wait_for_instantiate(self, ssh): mock_ssh(ssh) mock_process = mock.Mock(autospec=Process) mock_process.is_alive.return_value = True mock_process.exitcode = 432 mock_q_out = mock.Mock(autospec=Queue) mock_q_out.get.side_effect = iter(["pipeline>"]) mock_q_out.qsize.side_effect = range(1, -1, -1) mock_resource = mock.MagicMock() vpe_approx_vnf = VpeApproxVnf(NAME, self.VNFD_0) vpe_approx_vnf._vnf_process = mock_process vpe_approx_vnf.q_out = mock_q_out vpe_approx_vnf.queue_wrapper = mock.Mock(autospec=QueueFileWrapper) vpe_approx_vnf.resource_helper.resource = mock_resource vpe_approx_vnf.q_out.put("pipeline>") self.assertEqual(vpe_approx_vnf.wait_for_instantiate(), 432)
def test_wait_for_instantiate_fragmented(self, ssh, _): mock_ssh(ssh) mock_process = mock.Mock(autospec=Process) mock_process.is_alive.return_value = True mock_process.exitcode = 432 # test that fragmented pipeline prompt is recognized mock_q_out = mock.Mock(autospec=Queue) mock_q_out.get.side_effect = iter(["wow pipel", "ine>"]) mock_q_out.qsize.side_effect = range(2, -1, -1) mock_resource = mock.MagicMock() vpe_approx_vnf = VpeApproxVnf(NAME, self.VNFD_0) vpe_approx_vnf._vnf_process = mock_process vpe_approx_vnf.q_out = mock_q_out vpe_approx_vnf.queue_wrapper = mock.Mock(autospec=QueueFileWrapper) vpe_approx_vnf.resource_helper.resource = mock_resource self.assertEqual(vpe_approx_vnf.wait_for_instantiate(), 432)
def test_wait_for_instantiate_panic_fragmented(self, ssh, _): mock_ssh(ssh, exec_result=(1, "", "")) mock_process = mock.Mock(autospec=Process) mock_process.is_alive.return_value = True mock_process.exitcode = 432 # test that fragmented PANIC is recognized mock_q_out = mock.Mock(autospec=Queue) mock_q_out.get.side_effect = iter(["omg PA", "NIC this is bad"]) mock_q_out.qsize.side_effect = range(2, -1, -1) mock_resource = mock.MagicMock() vpe_approx_vnf = VpeApproxVnf(NAME, self.VNFD_0) vpe_approx_vnf._vnf_process = mock_process vpe_approx_vnf.q_out = mock_q_out vpe_approx_vnf.resource_helper.resource = mock_resource with self.assertRaises(RuntimeError) as raised: vpe_approx_vnf.wait_for_instantiate() self.assertIn('Error starting', str(raised.exception))
def test_collect_kpi_sa_not_running(self, ssh, _): mock_ssh(ssh) resource = mock.Mock(autospec=ResourceProfile) resource.check_if_sa_running.return_value = False, 'error' resource.amqp_collect_nfvi_kpi.return_value = {'foo': 234} vpe_approx_vnf = VpeApproxVnf(NAME, self.VNFD_0) vpe_approx_vnf.q_in = mock.MagicMock() vpe_approx_vnf.q_out = mock.MagicMock() vpe_approx_vnf.q_out.qsize = mock.Mock(return_value=0) vpe_approx_vnf.resource_helper.resource = resource expected = { 'pkt_in_down_stream': 0, 'pkt_in_up_stream': 0, 'pkt_drop_down_stream': 0, 'pkt_drop_up_stream': 0, 'collect_stats': { 'core': {} }, } self.assertEqual(vpe_approx_vnf.collect_kpi(), expected)