Ejemplo n.º 1
0
    def test_send_current_report(self, fromConfig, fromOptions, getLogger, time):
        initial = 10
        time.side_effect = [initial, initial]

        fromOptions.return_value = Mock()
        options = Mock()
        options.interval = 6
        options.oneshot = True
        options.print_ = False
        options.log_dir = ''
        options.log_file = ''
        virtwho = VirtWho(Mock(), options, config_dir="/nonexistant")
        virtwho.oneshot_remaining = ['config_name']

        config = Mock()
        config.hash = "config_hash"
        config.name = "config_name"

        virtwho.send = Mock()
        virtwho.send.return_value = True
        report = HostGuestAssociationReport(config, {'hypervisors': {}})
        report.state = AbstractVirtReport.STATE_PROCESSING
        virtwho.queued_reports[config.name] = report

        virtwho.send_current_report()

        def check_report_state(report):
            report.state = AbstractVirtReport.STATE_FINISHED
        virtwho.check_report_state = Mock(side_effect=check_report_state)
        virtwho.check_reports_state()

        virtwho.send.assert_called_with(report)
        self.assertEquals(virtwho.send_after, initial + 60)
Ejemplo n.º 2
0
    def test_send_current_report_with_429(self, fromConfig, fromOptions, getLogger, time):
        initial = 10
        retry_after = 2
        time.return_value = initial

        fromOptions.return_value = Mock()
        options = Mock()
        options.interval = 6
        options.oneshot = True
        options.print_ = False
        options.log_dir = ''
        options.log_file = ''
        virtwho = VirtWho(Mock(), options, config_dir="/nonexistant")

        config = Mock()
        config.hash = "config_hash"
        config.name = "config_name"

        report = HostGuestAssociationReport(config, {'hypervisors': []})
        report.state = AbstractVirtReport.STATE_PROCESSING
        virtwho.queued_reports[config.name] = report

        virtwho.send = Mock()
        virtwho.send.return_value = False
        virtwho.send.side_effect = ManagerThrottleError(retry_after)

        virtwho.send_current_report()

        virtwho.send.assert_called_with(report)
        self.assertEquals(virtwho.send_after, initial + 60)
        self.assertEquals(len(virtwho.queued_reports), 1)

        retry_after = 120
        virtwho.send.side_effect = ManagerThrottleError(retry_after)
        virtwho.send_current_report()
        virtwho.send.assert_called_with(report)
        self.assertEquals(virtwho.send_after, initial + retry_after * 2)
        self.assertEquals(len(virtwho.queued_reports), 1)

        def finish(x):
            report.state = AbstractVirtReport.STATE_FINISHED
            return True
        virtwho.send.side_effect = finish
        virtwho.send_current_report()
        retry_after = 60
        self.assertEquals(virtwho.retry_after, retry_after)
        self.assertEquals(virtwho.send_after, initial + retry_after)
        self.assertEquals(len(virtwho.queued_reports), 0)
Ejemplo n.º 3
0
    def test_sending_guests(self, fromOptions, fromConfig, getLogger):
        options = Mock()
        options.oneshot = True
        options.interval = 0
        options.print_ = False
        fake_virt = Mock()
        fake_virt.CONFIG_TYPE = 'esx'
        test_hypervisor = Hypervisor('test',
                                     guestIds=[Guest('guest1', fake_virt, 1)])
        association = {'hypervisors': [test_hypervisor]}
        options.log_dir = ''
        options.log_file = ''
        getLogger.return_value = sentinel.logger
        fromConfig.return_value.config.name = 'test'
        virtwho = VirtWho(self.logger, options, config_dir="/nonexistant")
        config = Config("test",
                        "esx",
                        server="localhost",
                        username="******",
                        password="******",
                        owner="owner",
                        env="env")
        virtwho.configManager.addConfig(config)
        virtwho.queue = Queue()
        virtwho.queue.put(HostGuestAssociationReport(config, association))
        virtwho.run()

        fromConfig.assert_called_with(sentinel.logger, config)
        self.assertTrue(fromConfig.return_value.start.called)
        fromOptions.assert_called_with(self.logger, options)
Ejemplo n.º 4
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)
Ejemplo n.º 5
0
 def test_oneshot(self, mock_client):
     expected_assoc = '"well formed HostGuestMapping"'
     expected_report = HostGuestAssociationReport(self.esx.config,
                                                  expected_assoc)
     updateSet = Mock()
     updateSet.version = 'some_new_version_string'
     updateSet.truncated = False
     mock_client.return_value.service.WaitForUpdatesEx.return_value = updateSet
     queue = Queue()
     self.esx.applyUpdates = Mock()
     getHostGuestMappingMock = Mock()
     getHostGuestMappingMock.return_value = expected_assoc
     self.esx.getHostGuestMapping = getHostGuestMappingMock
     self.run_once(queue)
     self.assertEqual(queue.qsize(), 1)
     result_report = queue.get(block=True, timeout=1)
     self.assertEqual(expected_report.config.hash,
                      result_report.config.hash)
     self.assertEqual(expected_report._assoc, result_report._assoc)