Ejemplo n.º 1
0
 def test_create_test_result_notification(self):
     """Tests the test result notification message."""
     self._console_client = cloud_console_client.PubSubBasedClient()
     self.mox.StubOutWithMock(utils,
                              'get_moblab_serial_number')
     utils.get_moblab_serial_number().AndReturn(
         'PV120BB8JAC01E')
     self.mox.StubOutWithMock(utils, 'get_moblab_id')
     utils.get_moblab_id().AndReturn(
         'c8386d92-9ad1-11e6-80f5-111111111111')
     self.mox.ReplayAll()
     console_client = cloud_console_client.PubSubBasedClient()
     msg = console_client._create_test_job_offloaded_message(
             'gs://test_bucket/123-moblab')
     self.assertEquals(base64.b64encode(
         cloud_console_client.LEGACY_TEST_OFFLOAD_MESSAGE), msg['data'])
     self.assertEquals(
         cloud_console_client.CURRENT_MESSAGE_VERSION,
         msg['attributes'][cloud_console_client.LEGACY_ATTR_VERSION])
     self.assertEquals(
         '1c:dc:d1:11:01:e1',
         msg['attributes'][cloud_console_client.LEGACY_ATTR_MOBLAB_MAC]
         )
     self.assertEquals(
         'c8386d92-9ad1-11e6-80f5-111111111111',
         msg['attributes'][cloud_console_client.LEGACY_ATTR_MOBLAB_ID])
     self.assertEquals(
         'gs://test_bucket/123-moblab',
         msg['attributes'][cloud_console_client.LEGACY_ATTR_GCS_URI])
     self.mox.VerifyAll()
Ejemplo n.º 2
0
 def test_create_test_result_notification(self):
     """Tests the test result notification message."""
     self._console_client = cloud_console_client.PubSubBasedClient()
     self.mox.StubOutWithMock(utils, 'get_moblab_id')
     self.mox.StubOutWithMock(utils,
                              'get_default_interface_mac_address')
     utils.get_default_interface_mac_address().AndReturn(
         '1c:dc:d1:11:01:e1')
     utils.get_moblab_id().AndReturn(
         'c8386d92-9ad1-11e6-80f5-111111111111')
     self.mox.ReplayAll()
     console_client = cloud_console_client.PubSubBasedClient()
     msg = console_client._create_test_result_notification(
             'gs://test_bucket/123-moblab')
     self.assertEquals(base64.b64encode(
         cloud_console_client.NEW_TEST_RESULT_MESSAGE), msg['data'])
     self.assertEquals(
         cloud_console_client.NOTIFICATION_VERSION,
         msg['attributes'][cloud_console_client.NOTIFICATION_ATTR_VERSION])
     self.assertEquals(
         '1c:dc:d1:11:01:e1',
         msg['attributes'][cloud_console_client.NOTIFICATION_ATTR_MOBLAB_MAC]
         )
     self.assertEquals(
         'c8386d92-9ad1-11e6-80f5-111111111111',
         msg['attributes'][cloud_console_client.NOTIFICATION_ATTR_MOBLAB_ID])
     self.assertEquals(
         'gs://test_bucket/123-moblab',
         msg['attributes'][cloud_console_client.NOTIFICATION_ATTR_GCS_URI])
     self.mox.VerifyAll()
Ejemplo n.º 3
0
    def test_send_heartbeat(self):
        """Tests send heartbeat."""
        console_client = cloud_console_client.PubSubBasedClient(
                pubsub_topic='test topic')
        self.mox.StubOutWithMock(utils, 'get_moblab_id')
        utils.get_moblab_id().AndReturn(
            'c8386d92-9ad1-11e6-80f5-111111111111')

        message = {
                'attributes' : {
                    'ATTR_MOBLAB_ID': 'c8386d92-9ad1-11e6-80f5-111111111111',
                    'ATTR_MESSAGE_VERSION': '1',
                    'ATTR_MESSAGE_TYPE': 'MSG_MOBLAB_HEARTBEAT',
                    'ATTR_MOBLAB_MAC_ADDRESS': '8c:dc:d4:56:06:e7'}}
        msg_ids = ['1']
        self._pubsub_client_mock.publish_notifications(
                'test topic', [message]).AndReturn(msg_ids)
        self.mox.ReplayAll()
        console_client.send_heartbeat()
        self.mox.VerifyAll()
Ejemplo n.º 4
0
def get_version_info():
    """ RPC handler to get informaiton about the version of the moblab.

    @return: A serialized JSON RPC object.
    """
    lines = open(_ETC_LSB_RELEASE).readlines()
    version_response = {
        x.split('=')[0]: x.split('=')[1]
        for x in lines if '=' in x
    }
    version_response['MOBLAB_ID'] = utils.get_moblab_id()
    version_response['MOBLAB_MAC_ADDRESS'] = (
        utils.get_default_interface_mac_address())
    return rpc_utils.prepare_for_serialization(version_response)
Ejemplo n.º 5
0
    def _create_notification_attributes(self):
        """Creates a cloud pubsub notification message attribute map.

        Fills in the version, moblab mac address, and moblab id information
        as attributes.

        @returns: A pubsub messsage attribute map.
        """
        msg_attributes = {}
        msg_attributes[NOTIFICATION_ATTR_VERSION] = NOTIFICATION_VERSION
        msg_attributes[NOTIFICATION_ATTR_MOBLAB_MAC] = (
            utils.get_default_interface_mac_address())
        msg_attributes[NOTIFICATION_ATTR_MOBLAB_ID] = utils.get_moblab_id()
        return msg_attributes
Ejemplo n.º 6
0
    def test_send_event(self):
        """Tests send heartbeat."""
        console_client = cloud_console_client.PubSubBasedClient(
                pubsub_topic='test topic')
        self.mox.StubOutWithMock(utils, 'get_moblab_id')
        utils.get_moblab_id().AndReturn(
            'c8386d92-9ad1-11e6-80f5-111111111111')

        message = {
                'data': '\x08\x01\x12\x0ethis is a test',
                'attributes' : {
                    'ATTR_MOBLAB_ID': 'c8386d92-9ad1-11e6-80f5-111111111111',
                    'ATTR_MESSAGE_VERSION': '1',
                    'ATTR_MESSAGE_TYPE': 'MSG_MOBLAB_REMOTE_EVENT',
                    'ATTR_MOBLAB_MAC_ADDRESS': '8c:dc:d4:56:06:e7'}}
        msg_ids = ['1']
        self._pubsub_client_mock.publish_notifications(
                'test topic', [message]).AndReturn(msg_ids)
        self.mox.ReplayAll()
        console_client.send_event(
                cpcon.RemoteEventMessage.EVENT_MOBLAB_BOOT_COMPLETE,
                'this is a test')
        self.mox.VerifyAll()
    def _create_test_job_offloaded_message(self, gcs_uri):
        """Construct a test result notification.

        TODO(ntang): switch LEGACY to new message format.
        @param gcs_uri: The test result Google Cloud Storage URI.

        @returns The notification message.
        """
        data = base64.b64encode(LEGACY_TEST_OFFLOAD_MESSAGE)
        msg_attributes = {}
        msg_attributes[LEGACY_ATTR_VERSION] = CURRENT_MESSAGE_VERSION
        msg_attributes[LEGACY_ATTR_MOBLAB_MAC] = (
            utils.get_moblab_serial_number())
        msg_attributes[LEGACY_ATTR_MOBLAB_ID] = utils.get_moblab_id()
        msg_attributes[LEGACY_ATTR_GCS_URI] = gcs_uri

        return self._create_message(data, msg_attributes)
def get_version_info():
    """ RPC handler to get informaiton about the version of the moblab.

    @return: A serialized JSON RPC object.
    """
    lines = open(_ETC_LSB_RELEASE).readlines()
    version_response = {
        x.split('=')[0]: x.split('=')[1]
        for x in lines if '=' in x
    }
    version_response['MOBLAB_ID'] = utils.get_moblab_id()
    version_response['MOBLAB_SERIAL_NUMBER'] = (
        utils.get_moblab_serial_number())
    _check_for_system_update()
    update_status = _get_system_update_status()
    version_response['MOBLAB_UPDATE_VERSION'] = update_status['NEW_VERSION']
    version_response['MOBLAB_UPDATE_STATUS'] = update_status['CURRENT_OP']
    version_response['MOBLAB_UPDATE_PROGRESS'] = update_status['PROGRESS']
    return rpc_utils.prepare_for_serialization(version_response)
    def _create_message_attributes(self, message_type_enum):
        """Creates a cloud pubsub notification message attribute map.

        Fills in the version, moblab mac address, and moblab id information
        as attributes.

        @param message_type_enum The message type enum.

        @returns: A pubsub messsage attribute map.
        """
        msg_attributes = {}
        msg_attributes[_get_attribute_name(cpcon.ATTR_MESSAGE_TYPE)] = (
            _get_message_type_name(message_type_enum))
        msg_attributes[_get_attribute_name(
            cpcon.ATTR_MESSAGE_VERSION)] = (CURRENT_MESSAGE_VERSION)
        msg_attributes[_get_attribute_name(cpcon.ATTR_MOBLAB_MAC_ADDRESS)] = (
            utils.get_moblab_serial_number())
        msg_attributes[_get_attribute_name(
            cpcon.ATTR_MOBLAB_ID)] = (utils.get_moblab_id())
        return msg_attributes