示例#1
0
 def test_get_data_ignore_same_reports(self):
     # Show that the data returned from _get_data does not include those
     # reports whose hash is identical to that of the last one sent for
     # the given source
     source_keys = ['source1', 'source2']
     report1 = Mock()
     report2 = Mock()
     report1.hash = "report1_hash"
     report2.hash = "report2_hash"
     datastore = {'source1': report1, 'source2': report2}
     last_report_for_source = {'source1': report1.hash}
     expected_data = {'source2': report2}
     manager = Mock()
     logger = Mock()
     config, d = self.create_fake_config('test', **self.default_config_args)
     terminate_event = Mock()
     interval = 10  # Arbitrary for this test
     options = Mock()
     options.print_ = False
     destination_thread = DestinationThread(logger,
                                            config,
                                            source_keys=source_keys,
                                            source=datastore,
                                            dest=manager,
                                            interval=interval,
                                            terminate_event=terminate_event,
                                            oneshot=True,
                                            options=self.options)
     destination_thread.is_initial_run = False
     destination_thread.last_report_for_source = last_report_for_source
     result_data = destination_thread._get_data()
     self.assertEqual(result_data, expected_data)
示例#2
0
 def test_get_data(self):
     # Show that get_data accesses the given source and tries to retrieve
     # the right source_keys
     source_keys = ['source1', 'source2']
     report1 = Mock()
     report2 = Mock()
     report1.hash = "report1_hash"
     report2.hash = "report2_hash"
     datastore = {'source1': report1, 'source2': report2}
     manager = Mock()
     logger = Mock()
     config, d = self.create_fake_config('test', **self.default_config_args)
     terminate_event = Mock()
     interval = 10  # Arbitrary for this test
     options = Mock()
     options.print_ = False
     destination_thread = DestinationThread(logger,
                                            config,
                                            source_keys=source_keys,
                                            source=datastore,
                                            dest=manager,
                                            interval=interval,
                                            terminate_event=terminate_event,
                                            oneshot=True,
                                            options=self.options)
     destination_thread.is_initial_run = False
     result_data = destination_thread._get_data()
     self.assertEqual(result_data, datastore)
示例#3
0
 def test_get_data_ignore_same_reports(self):
     # Show that the data returned from _get_data does not include those
     # reports whose hash is identical to that of the last one sent for
     # the given source
     source_keys = ['source1', 'source2']
     report1 = Mock()
     report2 = Mock()
     report1.hash = "report1_hash"
     report2.hash = "report2_hash"
     datastore = {'source1': report1, 'source2': report2}
     last_report_for_source = {
         'source1': report1.hash
     }
     expected_data = {
         'source2': report2
     }
     manager = Mock()
     logger = Mock()
     config, d = self.create_fake_config('test', **self.default_config_args)
     terminate_event = Mock()
     interval = 10  # Arbitrary for this test
     options = Mock()
     options.print_ = False
     destination_thread = DestinationThread(logger, config,
                                            source_keys=source_keys,
                                            source=datastore,
                                            dest=manager,
                                            interval=interval,
                                            terminate_event=terminate_event,
                                            oneshot=True,
                                            options=self.options)
     destination_thread.is_initial_run = False
     destination_thread.last_report_for_source = last_report_for_source
     result_data = destination_thread._get_data()
     self.assertEqual(result_data, expected_data)
示例#4
0
 def test_get_data(self):
     # Show that get_data accesses the given source and tries to retrieve
     # the right source_keys
     source_keys = ['source1', 'source2']
     report1 = Mock()
     report2 = Mock()
     report1.hash = "report1_hash"
     report2.hash = "report2_hash"
     datastore = {'source1': report1, 'source2': report2}
     manager = Mock()
     logger = Mock()
     config, d = self.create_fake_config('test', **self.default_config_args)
     terminate_event = Mock()
     interval = 10  # Arbitrary for this test
     options = Mock()
     options.print_ = False
     destination_thread = DestinationThread(logger, config,
                                            source_keys=source_keys,
                                            source=datastore,
                                            dest=manager,
                                            interval=interval,
                                            terminate_event=terminate_event,
                                            oneshot=True, options=self.options)
     destination_thread.is_initial_run = False
     result_data = destination_thread._get_data()
     self.assertEqual(result_data, datastore)
示例#5
0
    def test_duplicate_reports_are_ignored(self):
        """
        Test that duplicate reports are filtered out when retrieving items
        from the data store
        """
        source_keys = ['source1', 'source2']
        interval = 1
        terminate_event = Mock()
        options = Mock()
        options.print_ = False
        config1 = Config('source1', 'esx')
        virt1 = Mock()
        virt1.CONFIG_TYPE = 'esx'
        config = Mock()
        manager = Mock()

        guest1 = Guest('GUUID1', virt1, Guest.STATE_RUNNING)
        report1 = DomainListReport(config1, [guest1],
                                   hypervisor_id='hypervisor_id_1')
        report2 = DomainListReport(config1, [guest1],
                                   hypervisor_id='hypervisor_id_2')
        report3 = DomainListReport(config1, [guest1],
                                   hypervisor_id='hypervisor_id_3')
        datastore = {
            'source1': report1,  # Not changing, should be excluded later
            'source2': report2,  # Will change the report sent for source2
        }
        data_to_send = {
            'source1': report1,
            'source2': report2,
        }
        logger = Mock()
        destination_thread = DestinationThread(logger,
                                               config,
                                               source_keys=source_keys,
                                               source=datastore,
                                               dest=manager,
                                               interval=interval,
                                               terminate_event=terminate_event,
                                               oneshot=False,
                                               options=options)
        destination_thread._send_data(data_to_send=data_to_send)

        expected_hashes = {}
        for source_key, report in data_to_send.iteritems():
            expected_hashes[source_key] = report.hash

        self.assertEqual(destination_thread.last_report_for_source,
                         expected_hashes)
        # Pretend there were updates to the datastore from elsewhere
        destination_thread.source['source2'] = report3

        next_data_to_send = destination_thread._get_data()
        expected_next_data_to_send = {'source2': report3}
        self.assertEqual(next_data_to_send, expected_next_data_to_send)
示例#6
0
    def test_duplicate_reports_are_ignored(self):
        """
        Test that duplicate reports are filtered out when retrieving items
        from the data store
        """
        source_keys = ['source1', 'source2']
        interval = 1
        terminate_event = Mock()
        virt1 = Mock()
        virt1.CONFIG_TYPE = 'esx'
        config, d = self.create_fake_config('test', **self.default_config_args)
        manager = Mock()

        guest1 = Guest('GUUID1', virt1.CONFIG_TYPE, Guest.STATE_RUNNING)
        report1 = DomainListReport(config, [guest1],
                                   hypervisor_id='hypervisor_id_1')
        report2 = DomainListReport(config, [guest1],
                                   hypervisor_id='hypervisor_id_2')
        report3 = DomainListReport(config, [guest1],
                                   hypervisor_id='hypervisor_id_3')
        datastore = {
            'source1': report1,  # Not changing, should be excluded later
            'source2': report2,  # Will change the report sent for source2
        }
        data_to_send = {
            'source1': report1,
            'source2': report2,
        }
        logger = Mock()
        destination_thread = DestinationThread(logger, config,
                                               source_keys=source_keys,
                                               source=datastore,
                                               dest=manager,
                                               interval=interval,
                                               terminate_event=terminate_event,
                                               oneshot=False, options=self.options)
        destination_thread.is_initial_run = False
        destination_thread.is_terminated = Mock(return_value=False)
        destination_thread._send_data(data_to_send=data_to_send)

        expected_hashes = {}
        for source_key, report in data_to_send.items():
            expected_hashes[source_key] = report.hash

        self.assertEqual(destination_thread.last_report_for_source,
                         expected_hashes)
        # Pretend there were updates to the datastore from elsewhere
        destination_thread.source['source2'] = report3

        next_data_to_send = destination_thread._get_data()
        expected_next_data_to_send = {
            'source2': report3
        }
        self.assertEqual(next_data_to_send, expected_next_data_to_send)