def test_check_health_pubsub_publish_error(self, mc_ans_runner, mc_grc): mc_conn = MagicMock() mc_ans_runner.return_value = mc_conn mc_conn.run.return_value = {"contacted": [self.vm_ip]} mc_grc.side_effect = ConnectionError() # didn't raise exception check_health(self.opts, self.vm_name, self.vm_ip) assert mc_conn.run.called assert mc_grc.called
def test_check_health_runner_ok(self, mc_ans_runner, mc_grc): mc_conn = MagicMock() mc_ans_runner.return_value = mc_conn mc_conn.run.return_value = {"contacted": [self.vm_ip]} mc_rc = MagicMock() mc_grc.return_value = mc_rc # didn't raise exception check_health(self.opts, self.vm_name, self.vm_ip) assert mc_rc.publish.call_args[0][0] == PUBSUB_MB dict_result = json.loads(mc_rc.publish.call_args[0][1]) assert dict_result["result"] == "OK"
def test_check_health_runner_no_response(self, mc_ans_runner, mc_grc): mc_runner = MagicMock() mc_ans_runner.return_value = mc_runner # mc_runner.connection.side_effect = IOError() mc_rc = MagicMock() mc_grc.return_value = mc_rc # didn't raise exception check_health(self.opts, self.vm_name, self.vm_ip) assert mc_rc.publish.call_args[0][0] == PUBSUB_MB dict_result = json.loads(mc_rc.publish.call_args[0][1]) assert dict_result["result"] == "failed" assert "VM is not responding to the testing playbook." in dict_result["msg"]
def test_check_health_runner_exception(self, mc_ans_runner, mc_grc): mc_conn = MagicMock() mc_ans_runner.return_value = mc_conn mc_conn.run.side_effect = IOError() mc_rc = MagicMock() mc_grc.return_value = mc_rc # didn't raise exception check_health(self.opts, self.vm_name, self.vm_ip) assert mc_rc.publish.call_args[0][0] == PUBSUB_MB dict_result = json.loads(mc_rc.publish.call_args[0][1]) assert dict_result["result"] == "failed" assert "Failed to check VM" in dict_result["msg"] assert "due to ansible error:" in dict_result["msg"]
def test_check_health_runner_no_response(self, mc_ans_runner, mc_grc): mc_runner = MagicMock() mc_ans_runner.return_value = mc_runner # mc_runner.connection.side_effect = IOError() mc_rc = MagicMock() mc_grc.return_value = mc_rc # didn't raise exception check_health(self.opts, self.vm_name, self.vm_ip) assert mc_rc.publish.call_args[0][0] == PUBSUB_MB dict_result = json.loads(mc_rc.publish.call_args[0][1]) assert dict_result["result"] == "failed" assert "VM is not responding to the testing playbook." in dict_result[ "msg"]