Exemple #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_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()
Exemple #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_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()
Exemple #3
0
 def __init__(self, options):
     self._upload_age_limit = options.age_to_upload
     self._delete_age_limit = options.age_to_delete
     if options.delete_only:
         self._gs_offloader = FakeGSOffloader()
     else:
         self.gs_uri = utils.get_offload_gsuri()
         logging.debug('Offloading to: %s', self.gs_uri)
         multiprocessing = False
         if options.multiprocessing:
             multiprocessing = True
         elif options.multiprocessing is None:
             multiprocessing = GS_OFFLOADER_MULTIPROCESSING
         logging.info('Offloader multiprocessing is set to:%r',
                      multiprocessing)
         console_client = None
         if (cloud_console_client
                 and cloud_console_client.is_cloud_notification_enabled()):
             console_client = cloud_console_client.PubSubBasedClient()
         self._gs_offloader = GSOffloader(self.gs_uri, multiprocessing,
                                          self._delete_age_limit,
                                          console_client)
     classlist = [
         job_directories.SwarmingJobDirectory,
     ]
     if options.process_hosts_only or options.process_all:
         classlist.append(job_directories.SpecialJobDirectory)
     if not options.process_hosts_only:
         classlist.append(job_directories.RegularJobDirectory)
     self._jobdir_classes = classlist
     assert self._jobdir_classes
     self._processes = options.parallelism
     self._open_jobs = {}
     self._pusub_topic = None
     self._offload_count_limit = 3
Exemple #4
0
    def test_send_test_job_offloaded_message(self):
        """Tests send job offloaded notification."""
        console_client = cloud_console_client.PubSubBasedClient(
                pubsub_topic='test topic')

        # self.mox.ResetAll()
        message = {'data': 'dummy data', 'attributes' : {'key' : 'value'}}
        self.mox.StubOutWithMock(cloud_console_client.PubSubBasedClient,
                '_create_test_result_notification')
        console_client._create_test_result_notification(
                'gs://test_bucket/123-moblab').AndReturn(message)

        msg_ids = ['1']
        self._pubsub_client_mock.publish_notifications(
                'test topic', [message]).AndReturn(msg_ids)

        self.mox.ReplayAll()
        console_client.send_test_job_offloaded_message(
                'gs://test_bucket/123-moblab')
        self.mox.VerifyAll()
Exemple #5
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()
Exemple #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()