def gather_broken_rules(savedminer, minerstats): broken = [] for ruleparms in RULES.app.ruleparameters(): rule = MinerStatisticsRule(savedminer, minerstats, ruleparms) if rule.isbroken(): broken += rule.brokenrules return broken
def test_lowhash(self): '''test low hash condition''' params = RuleParameters(self.miner.minerinfo.miner_type, 10000, 40, 55, 60*10) rules = MinerStatisticsRule(self.miner, self.minerstats, params) isbroken = rules.isbroken() self.assertTrue(isbroken) self.assertTrue(len(rules.brokenrules) > 0)
def test_hardware_errors_alert(self): '''test when hardware errors exceeced''' self.minerstats.hardware_errors = 100 params = RuleParameters(self.miner.minerinfo.miner_type, 13500, 40, 55, 60*10, None, 99, '10s') rules = MinerStatisticsRule(self.miner, self.minerstats, params) isbroken = rules.isbroken() self.assertTrue(isbroken) self.assertTrue(len(rules.brokenrules) > 0)
def test_low_temp(self): '''test when temp is low on miner''' self.minerstats.controllertemp = 101 params = RuleParameters(self.miner.minerinfo.miner_type, 10000, 40, 55, 60*10) rules = MinerStatisticsRule(self.miner, self.minerstats, params) isbroken = rules.isbroken() self.assertTrue(isbroken) self.assertTrue(len(rules.brokenrules) > 0)
def test_high_temp_reset_null(self): '''test when controller temp is high on miner. no reset''' self.minerstats.controllertemp = 101 params = RuleParameters(self.miner.minerinfo.miner_type, 10000, 40, 55, 60*10, maxtempreset=None) rules = MinerStatisticsRule(self.miner, self.minerstats, params) isbroken = rules.isbroken() self.assertTrue(isbroken) self.assertFalse(rules.has_reboot_rule())
def test_board_high_temp_reset(self): '''test when controller temp is high on miner''' self.minerstats.tempboard1 = 150 self.minerstats.elapsed = (60 * 10) + 1 params = RuleParameters(self.miner.minerinfo.miner_type, 10000, 40, 55, 60*10, maxtempreset=120) rules = MinerStatisticsRule(self.miner, self.minerstats, params) isbroken = rules.isbroken() self.assertTrue(isbroken) self.assertTrue(rules.has_reboot_rule())
def rules(miner, minerstats, minerpool): '''this runs the rules''' entries = QueueEntries() if miner is None or minerstats is None: return entries savedminer = RULES.app.getminer(miner) cmd_restart = MinerCommand('restart', '') broken = [] for ruleparms in RULES.app.ruleparameters(): rule = MinerStatisticsRule(savedminer, minerstats, ruleparms) if rule.isbroken(): broken += rule.brokenrules if broken: #TODO: could raise broken rule event??? for rule in broken: log = MinerLog() log.createdate = datetime.datetime.utcnow() log.minerid = rule.miner.key() log.minername = rule.miner.name log.action = rule.parameter RULES.app.log_mineractivity(log) if rule.action == 'alert': entries.addalert( RULES.addalert(RULES.app.stamp(rule.parameter))) elif rule.action == 'restart': entries.add( QueueName.Q_RESTART, RULES.app.createmessagecommand(rule.miner, cmd_restart)) entries.addalert( RULES.addalert( RULES.app.stamp('Restarted {0}'.format( rule.miner.name)))) else: RULES.app.logerror('did not process broken rule {0}'.format( rule.parameter)) return entries
def test_string_has_reading(self): params = RuleParameters(self.miner.minerinfo.miner_type, 10000, '', 55, 60 * 10) rules = MinerStatisticsRule(self.miner, self.minerstats, params) self.assertFalse(rules.hasreading_num(params.controllertemplimit))
def test_reset_leaves_reboot(self): rules = MinerStatisticsRule(self.miner, None, None) rules.addbrokenrule(BrokenRule(self.miner, 'restart', 'reboot')) rules.addbrokenrule(BrokenRule(self.miner, 'restart', '')) self.assertTrue(len(rules.brokenrules) == 1) self.assertTrue(rules.brokenrules[0].parameter == 'reboot')
def test_only_one_reboot(self): rules = MinerStatisticsRule(self.miner, None, None) rules.addbrokenrule(BrokenRule(self.miner, 'restart', 'reboot')) rules.addbrokenrule(BrokenRule(self.miner, 'restart', 'reboot')) self.assertTrue(len(rules.brokenrules) == 1)
def test_hasreading(self): self.assertFalse(MinerStatisticsRule.hasreading(None)) self.assertTrue(MinerStatisticsRule.hasreading(1)) self.assertFalse(MinerStatisticsRule.hasreading(0)) self.assertFalse(MinerStatisticsRule.hasreading_num(None))
def test_incompatable_minertype(self): params = RuleParameters('notthesameminertype', 10000, 40, 55, 60*10) rules = MinerStatisticsRule(self.miner, self.minerstats, params) isbroken = rules.isbroken() self.assertFalse(isbroken)
def test_float_has_reading(self): params = RuleParameters(self.miner.minerinfo.miner_type, 10000, 49.9, 55, 60*10) self.assertTrue(MinerStatisticsRule.hasreading_num(params.controllertemplimit))