Ejemplo n.º 1
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)
Ejemplo n.º 2
0
 def _get_report(self):
     if self.isHypervisor():
         return HostGuestAssociationReport(self.config,
                                           self._getHostGuestMapping())
     else:
         return DomainListReport(self.config, self._listDomains(),
                                 self._remote_host_id())
Ejemplo n.º 3
0
 def setUp(self):
     self.config = Config('config',
                          'esx',
                          server='localhost',
                          username='******',
                          password='******',
                          owner='owner',
                          env='env',
                          log_dir='',
                          log_file='')
     self.second_config = Config('second_config',
                                 'esx',
                                 server='localhost',
                                 username='******',
                                 password='******',
                                 owner='owner',
                                 env='env',
                                 log_dir='',
                                 log_file='')
     fake_virt = Mock()
     fake_virt.CONFIG_TYPE = 'esx'
     guests = [Guest('guest1', fake_virt, 1)]
     test_hypervisor = Hypervisor('test',
                                  guestIds=[Guest('guest1', fake_virt, 1)])
     assoc = {'hypervisors': [test_hypervisor]}
     self.fake_domain_list = DomainListReport(self.second_config, guests)
     self.fake_report = HostGuestAssociationReport(self.config, assoc)
 def test_sendVirtGuests(self):
     config = VirtConfigSection.from_dict({'type': 'libvirt'}, 'test', None)
     report = DomainListReport(config, self.guestList, self.hypervisor_id)
     self.sm.sendVirtGuests(report)
     self.sm.connection.updateConsumer.assert_called_with(
         123,
         guest_uuids=[g.toDict() for g in self.guestList],
         hypervisor_id=self.hypervisor_id)
Ejemplo n.º 5
0
 def test_sendVirtGuests(self, rhsmconnection):
     config = Config('test', 'libvirt')
     report = DomainListReport(config, self.guestList, self.hypervisor_id)
     self.sm.sendVirtGuests(report)
     self.sm.connection.updateConsumer.assert_called_with(
         123,
         guest_uuids=[g.toDict() for g in self.guestList],
         hypervisor_id=self.hypervisor_id)
Ejemplo n.º 6
0
 def test_exit_after_unregister(self, fromConfig, getLogger):
     virtwho = self.mock_virtwho()
     report = DomainListReport(virtwho.configManager.configs[0], [])
     # Send two reports and then 'exit'
     virtwho.queue.get.side_effect = [report, Empty, report, Empty, 'exit']
     # First report will be successful, second one will throw ManagerFatalError
     virtwho.send.side_effect = [True, ManagerFatalError]
     # _main should exit normally
     _main(virtwho)
     self.assertStartStop(fromConfig)
Ejemplo n.º 7
0
 def _get_report(self):
     if self.status:
         # this will make the authentication happen
         # a failure will get picked up in the _run method
         self.statusConfirmConnection()
         return StatusReport(self.config)
     if self.isHypervisor():
         return HostGuestAssociationReport(self.config,
                                           self._getHostGuestMapping())
     else:
         return DomainListReport(self.config, self._listDomains(),
                                 self._remote_host_id())
Ejemplo n.º 8
0
 def test_reload_after_unregister(self, fromConfig, getLogger):
     virtwho = self.mock_virtwho()
     report = DomainListReport(virtwho.configManager.configs[0], [])
     # Send two reports and then 'reload'
     virtwho.queue.get.side_effect = [
         report, Empty, report, Empty, 'reload'
     ]
     # First report will be successful, second one will throw ManagerFatalError
     virtwho.send.side_effect = [True, ManagerFatalError]
     # _main should throw ReloadRequest
     self.assertRaises(ReloadRequest, _main, virtwho)
     self.assertStartStop(fromConfig)
Ejemplo n.º 9
0
    def test_reload_after_register(self, fromConfig, getLogger):
        virtwho = self.mock_virtwho()
        report = DomainListReport(virtwho.configManager.configs[0], [])
        # Send report and then 'reload'
        virtwho.queue.get.side_effect = [report, Empty, 'reload']
        # First report will be successful, second one will throw ManagerFatalError
        virtwho.send.side_effect = [ManagerFatalError, True]
        # _main should throw ReloadRequest
        self.assertRaises(ReloadRequest, _main, virtwho)

        self.assertEqual(virtwho.queue.get.call_count, 3)
        # It should wait blocking for the reload
        virtwho.queue.get.assert_has_calls([call(block=True)])
        self.assertStartStop(fromConfig)
Ejemplo n.º 10
0
class TestManager(TestBase):
    """ Test of all available subscription managers. """
    guest1 = Guest('9c927368-e888-43b4-9cdb-91b10431b258', xvirt, Guest.STATE_RUNNING)
    guest2 = Guest('d5ffceb5-f79d-41be-a4c1-204f836e144a', xvirt, Guest.STATE_SHUTOFF)
    guestInfo = [guest1]
    hypervisor_id = "HYPERVISOR_ID"

    config = Config('test', 'libvirt', owner='OWNER', env='ENV')
    host_guest_report = HostGuestAssociationReport(config, {
        'hypervisors': [
            Hypervisor('9c927368-e888-43b4-9cdb-91b10431b258', []),
            Hypervisor('ad58b739-5288-4cbc-a984-bd771612d670', [guest1, guest2])
        ]
    })
    domain_report = DomainListReport(config, [guest1], hypervisor_id)
Ejemplo n.º 11
0
 def test_start_unregistered(self, fromConfig, getLogger):
     virtwho = self.mock_virtwho()
     virtwho.queue.get.side_effect = [
         DomainListReport(virtwho.configManager.configs[0], []), Empty,
         'reload'
     ]
     virtwho.send.side_effect = ManagerFatalError
     # When not registered, it should throw ReloadRequest
     self.assertRaises(ReloadRequest, _main, virtwho)
     # queue.get should be called 3 times: report, nonblocking reading
     # of remaining reports and after ManagerFatalError wait indefinately
     self.assertEqual(virtwho.queue.get.call_count, 3)
     # It should wait blocking for the reload
     virtwho.queue.get.assert_has_calls([call(block=True)])
     self.assertStartStop(fromConfig)
Ejemplo n.º 12
0
    def test_send_data_429_during_send_virt_guests(self):
        # Show that when a 429 is encountered during the sending of a
        # DomainListReport that we retry after waiting the appropriate
        # amount of time
        source_keys = ['source1']
        config1 = Config('source1', 'esx')
        virt1 = Mock()
        virt1.CONFIG_TYPE = 'esx'

        guest1 = Guest('GUUID1', virt1, Guest.STATE_RUNNING)
        report1 = DomainListReport(config1, [guest1],
                                   hypervisor_id='hypervisor_id_1')

        datastore = {'source1': report1}
        data_to_send = {'source1': report1}

        config = Mock()
        config.polling_interval = 10
        logger = Mock()

        error_to_throw = ManagerThrottleError(retry_after=21)

        manager = Mock()
        manager.sendVirtGuests = Mock(side_effect=[error_to_throw, report1])
        terminate_event = Mock()
        interval = 10
        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=options)
        destination_thread.wait = Mock()
        destination_thread._send_data(data_to_send)
        manager.sendVirtGuests.assert_has_calls([
            call(report1, options=destination_thread.options),
            call(report1, options=destination_thread.options)
        ])
        destination_thread.wait.assert_has_calls(
            [call(wait_time=error_to_throw.retry_after)])
Ejemplo n.º 13
0
    def test_send_data_429_during_send_virt_guests(self):
        # Show that when a 429 is encountered during the sending of a
        # DomainListReport that we retry after waiting the appropriate
        # amount of time
        config, d = self.create_fake_config('test', **self.default_config_args)
        source_keys = ['source1']
        virt1 = Mock()
        virt1.CONFIG_TYPE = 'esx'

        guest1 = Guest('GUUID1', virt1.CONFIG_TYPE, Guest.STATE_RUNNING)
        report1 = DomainListReport(config, [guest1],
                                   hypervisor_id='hypervisor_id_1')

        datastore = {'source1': report1}
        data_to_send = {'source1': report1}

        logger = Mock()

        error_to_throw = ManagerThrottleError(retry_after=62)

        manager = Mock()
        manager.sendVirtGuests = Mock(side_effect=[error_to_throw, report1])
        terminate_event = Mock()
        interval = 10
        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=False,
                                               options=self.options)
        destination_thread.wait = Mock()
        destination_thread.record_status = Mock()
        destination_thread.is_terminated = Mock(return_value=False)
        destination_thread._send_data(data_to_send)
        manager.sendVirtGuests.assert_has_calls(
            [call(report1, options=destination_thread.options)])
        destination_thread.wait.assert_has_calls(
            [call(wait_time=error_to_throw.retry_after)])
Ejemplo n.º 14
0
    def test_send_data_domain_list_reports(self):
        # Show that DomainListReports are sent using the sendVirtGuests
        # method of the destination

        source_keys = ['source1']
        config1, d1 = self.create_fake_config('source1',
                                              **self.default_config_args)
        virt1 = Mock()
        virt1.CONFIG_TYPE = 'esx'

        guest1 = Guest('GUUID1', virt1.CONFIG_TYPE, Guest.STATE_RUNNING)
        report1 = DomainListReport(config1, [guest1],
                                   hypervisor_id='hypervisor_id_1')

        datastore = {'source1': report1}
        data_to_send = {'source1': report1}

        config, d = self.create_fake_config('test', **self.default_config_args)
        logger = Mock()

        manager = Mock()
        terminate_event = Mock()
        interval = 10
        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.wait = Mock()
        destination_thread.is_terminated = Mock(return_value=False)
        destination_thread.record_status = Mock()
        destination_thread._send_data(data_to_send)
        manager.sendVirtGuests.assert_has_calls(
            [call(report1, options=destination_thread.options)])
Ejemplo n.º 15
0
    def test_send_data_domain_list_reports(self):
        # Show that DomainListReports are sent using the sendVirtGuests
        # method of the destination

        source_keys = ['source1']
        config1 = Config('source1', 'esx')
        virt1 = Mock()
        virt1.CONFIG_TYPE = 'esx'

        guest1 = Guest('GUUID1', virt1, Guest.STATE_RUNNING)
        report1 = DomainListReport(config1, [guest1],
                                   hypervisor_id='hypervisor_id_1')

        datastore = {'source1': report1}
        data_to_send = {'source1': report1}

        config = Mock()
        config.polling_interval = 10
        logger = Mock()

        manager = Mock()
        terminate_event = Mock()
        interval = 10
        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=options)
        destination_thread.wait = Mock()
        destination_thread._send_data(data_to_send)
        manager.sendVirtGuests.assert_has_calls(
            [call(report1, options=destination_thread.options)])