コード例 #1
0
 def test_put_status_error_reporting(self):
     """
     Validate the telemetry when uploading status fails
     """
     test_goal_state = wire.GoalState(WireProtocolData(DATA_FILE).goal_state)
     status = restapi.VMStatus(status="Ready",
                               message="Guest Agent is running")
     wire.HostPluginProtocol.set_default_channel(False)
     with patch.object(wire.StatusBlob,
                       "upload",
                       return_value=False):
         wire_protocol_client = wire.WireProtocol(wireserver_url).client
         wire_protocol_client.get_goal_state = Mock(return_value=test_goal_state)
         wire_protocol_client.ext_conf = wire.ExtensionsConfig(None)
         wire_protocol_client.ext_conf.status_upload_blob = sas_url
         wire_protocol_client.status_blob.set_vm_status(status)
         put_error = wire.HttpError("put status http error")
         with patch.object(event,
                           "add_event") as patch_add_event:
             with patch.object(restutil,
                               "http_put",
                               side_effect=put_error) as patch_http_put:
                 with patch.object(wire.HostPluginProtocol,
                                   "ensure_initialized", return_value=True):
                     wire_protocol_client.upload_status_blob()
                     self.assertFalse(wire.HostPluginProtocol.is_default_channel())
                     self.assertTrue(patch_add_event.call_count == 1)
コード例 #2
0
    def test_put_status_error_reporting(self, patch_add_event):
        """
        Validate the telemetry when uploading status fails
        """
        wire.HostPluginProtocol.is_default_channel = False
        with patch.object(wire.StatusBlob, "upload", return_value=False):
            with self.create_mock_protocol() as wire_protocol:
                wire_protocol_client = wire_protocol.client

                put_error = wire.HttpError("put status http error")
                with patch.object(restutil, "http_put", side_effect=put_error):
                    with patch.object(wire.HostPluginProtocol,
                                      "ensure_initialized", return_value=True):
                        self.assertRaises(wire.ProtocolError, wire_protocol_client.upload_status_blob)

                        # The agent tries to upload via HostPlugin and that fails due to
                        # http_put having a side effect of "put_error"
                        #
                        # The agent tries to upload using a direct connection, and that succeeds.
                        self.assertEqual(1, wire_protocol_client.status_blob.upload.call_count)  # pylint: disable=no-member
                        # The agent never touches the default protocol is this code path, so no change.
                        self.assertFalse(wire.HostPluginProtocol.is_default_channel)
                        # The agent never logs telemetry event for direct fallback
                        self.assertEqual(1, patch_add_event.call_count)
                        self.assertEqual('ReportStatus', patch_add_event.call_args[1]['op'])
                        self.assertTrue('Falling back to direct' in patch_add_event.call_args[1]['message'])
                        self.assertEqual(True, patch_add_event.call_args[1]['is_success'])
コード例 #3
0
 def test_fallback_failure(self):
     """
     Validate that when host plugin fails, the default channel is reset
     """
     test_goal_state = wire.GoalState(WireProtocolData(DATA_FILE).goal_state)
     status = restapi.VMStatus(status="Ready",
                               message="Guest Agent is running")
     wire.HostPluginProtocol.set_default_channel(False)
     with patch.object(wire.HostPluginProtocol,
                       "ensure_initialized",
                       return_value=True):
         with patch.object(wire.StatusBlob,
                           "upload",
                           return_value=False):
             with patch.object(wire.HostPluginProtocol,
                               "_put_page_blob_status",
                               side_effect=wire.HttpError("put failure")) as patch_put:
                 client = wire.WireProtocol(wireserver_url).client
                 client.get_goal_state = Mock(return_value=test_goal_state)
                 client.ext_conf = wire.ExtensionsConfig(None)
                 client.ext_conf.status_upload_blob = sas_url
                 client.ext_conf.status_upload_blob_type = page_blob_type
                 client.status_blob.set_vm_status(status)
                 client.upload_status_blob()
                 self.assertTrue(patch_put.call_count == 1,
                                 "Fallback was not engaged")
                 self.assertFalse(wire.HostPluginProtocol.is_default_channel())
コード例 #4
0
    def test_put_status_error_reporting(self, patch_add_event):
        """
        Validate the telemetry when uploading status fails
        """
        test_goal_state = wire.GoalState(
            WireProtocolData(DATA_FILE).goal_state)
        status = restapi.VMStatus(status="Ready",
                                  message="Guest Agent is running")
        wire.HostPluginProtocol.set_default_channel(False)
        with patch.object(wire.StatusBlob, "upload", return_value=False):
            wire_protocol_client = wire.WireProtocol(wireserver_url).client
            wire_protocol_client.get_goal_state = Mock(
                return_value=test_goal_state)
            wire_protocol_client.ext_conf = wire.ExtensionsConfig(None)
            wire_protocol_client.ext_conf.status_upload_blob = sas_url
            wire_protocol_client.status_blob.set_vm_status(status)
            put_error = wire.HttpError("put status http error")
            with patch.object(restutil, "http_put",
                              side_effect=put_error) as patch_http_put:
                with patch.object(wire.HostPluginProtocol,
                                  "ensure_initialized",
                                  return_value=True):
                    wire_protocol_client.upload_status_blob()

                    # The agent tries to upload via HostPlugin and that fails due to
                    # http_put having a side effect of "put_error"
                    #
                    # The agent tries to upload using a direct connection, and that succeeds.
                    self.assertEqual(
                        1, wire_protocol_client.status_blob.upload.call_count)
                    # The agent never touches the default protocol is this code path, so no change.
                    self.assertFalse(
                        wire.HostPluginProtocol.is_default_channel())
                    # The agent never logs a telemetry event for a bad HTTP call
                    self.assertEqual(patch_add_event.call_count, 0)