diff options
Diffstat (limited to 'tests/protocol/test_wire.py')
-rw-r--r-- | tests/protocol/test_wire.py | 53 |
1 files changed, 28 insertions, 25 deletions
diff --git a/tests/protocol/test_wire.py b/tests/protocol/test_wire.py index dda7a2b..ba9fc7d 100644 --- a/tests/protocol/test_wire.py +++ b/tests/protocol/test_wire.py @@ -152,11 +152,12 @@ class TestWireProtocolGetters(AgentTestCase): wire_protocol_client = WireProtocol(wireserver_url).client wire_protocol_client.ext_conf = ExtensionsConfig(None) wire_protocol_client.ext_conf.status_upload_blob = testurl + wire_protocol_client.ext_conf.status_upload_blob_type = testtype wire_protocol_client.status_blob.vm_status = vmstatus with patch.object(WireClient, "get_goal_state") as patch_get_goal_state: with patch.object(HostPluginProtocol, "put_vm_status") as patch_host_ga_plugin_upload: - with patch.object(StatusBlob, "upload", return_value=True) as patch_default_upload: + with patch.object(StatusBlob, "upload") as patch_default_upload: HostPluginProtocol.set_default_channel(False) wire_protocol_client.upload_status_blob() @@ -190,7 +191,25 @@ class TestWireProtocolGetters(AgentTestCase): self.assertTrue(HostPluginProtocol.is_default_channel()) HostPluginProtocol.set_default_channel(False) - def test_upload_status_blob_error_reporting(self, *args): + def test_upload_status_blob_unknown_type_assumes_block(self, *args): + vmstatus = VMStatus(message="Ready", status="Ready") + wire_protocol_client = WireProtocol(wireserver_url).client + wire_protocol_client.ext_conf = ExtensionsConfig(None) + wire_protocol_client.ext_conf.status_upload_blob = testurl + wire_protocol_client.ext_conf.status_upload_blob_type = "NotALegalType" + wire_protocol_client.status_blob.vm_status = vmstatus + + with patch.object(WireClient, "get_goal_state") as patch_get_goal_state: + with patch.object(StatusBlob, "prepare") as patch_prepare: + with patch.object(StatusBlob, "upload") as patch_default_upload: + HostPluginProtocol.set_default_channel(False) + wire_protocol_client.upload_status_blob() + + patch_prepare.assert_called_once_with("BlockBlob") + patch_default_upload.assert_called_once_with(testurl) + patch_get_goal_state.assert_not_called() + + def test_upload_status_blob_reports_prepare_error(self, *args): vmstatus = VMStatus(message="Ready", status="Ready") wire_protocol_client = WireProtocol(wireserver_url).client wire_protocol_client.ext_conf = ExtensionsConfig(None) @@ -199,29 +218,13 @@ class TestWireProtocolGetters(AgentTestCase): wire_protocol_client.status_blob.vm_status = vmstatus goal_state = GoalState(WireProtocolData(DATA_FILE).goal_state) - with patch.object(HostPluginProtocol, - "ensure_initialized", - return_value=True): - with patch.object(StatusBlob, - "put_block_blob", - side_effect=HttpError("error")): - with patch.object(StatusBlob, - "get_blob_type", - return_value='BlockBlob'): - with patch.object(HostPluginProtocol, - "put_vm_status"): - with patch.object(WireClient, - "report_blob_type", - side_effect=MagicMock()): - with patch.object(event, - "add_event") as patch_add_event: - HostPluginProtocol.set_default_channel(False) - wire_protocol_client.get_goal_state = Mock(return_value=goal_state) - wire_protocol_client.upload_status_blob() - wire_protocol_client.get_goal_state.assert_called_once() - self.assertTrue(patch_add_event.call_count == 1) - self.assertTrue(patch_add_event.call_args_list[0][1]['op'] == 'ReportStatus') - self.assertFalse(HostPluginProtocol.is_default_channel()) + with patch.object(StatusBlob, "prepare", + side_effect=Exception) as mock_prepare: + with patch.object(WireClient, "report_status_event") as mock_event: + wire_protocol_client.upload_status_blob() + + mock_prepare.assert_called_once() + mock_event.assert_called_once() def test_get_in_vm_artifacts_profile_blob_not_available(self, *args): wire_protocol_client = WireProtocol(wireserver_url).client |