예제 #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()
    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