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 = Executor(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 + options.interval)
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 = Executor(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)
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 = Executor(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)
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 = Executor(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 + options.interval) self.assertEquals(len(virtwho.queued_reports), 0)