Esempio n. 1
0
    def setUp(self):
        '''create test miner'''
        self.minerinfo = MinerInfo('Antminer S9', '')
        self.miner = Miner('Test',
                           'Online',
                           'Antminer S9',
                           '',
                           '',
                           '',
                           '',
                           '',
                           '',
                           '',
                           lastmonitor=None,
                           offlinecount=0,
                           defaultpool='',
                           minerinfo=self.minerinfo)

        self.minerstats = MinerStatistics(self.miner,
                                          datetime.datetime.utcnow(),
                                          3,
                                          currenthash=9999,
                                          controllertemp=0,
                                          tempboard1=0,
                                          tempboard2=0,
                                          tempboard3=0)
Esempio n. 2
0
def getminerinfo(miner: Miner):
    minerid = 'unknown'
    minertype = 'unknown'
    if not miner.can_monitor():
        raise MinerMonitorException(
            'miner {0} cannot be monitored. ip={1} port={2}'.format(
                miner.name, miner.ipaddress, miner.port))
    api = MinerApi(host=miner.ipaddress, port=int(miner.port), timeout=1)
    jstats = api.stats()
    #if there was an error then the return is STATUS not STATS!
    toplevelstatus = jstats['STATUS'][0]
    if toplevelstatus['STATUS'] == 'error':
        if not miner.is_disabled():
            raise MinerMonitorException(toplevelstatus['description'])
    else:
        status = jstats['STATS'][0]
        details = jstats['STATS'][1]
        if 'Type' in status:
            minertype = status['Type']
        else:
            if toplevelstatus['Description'].startswith('cgminer'):
                minertype = toplevelstatus['Description']
        if minertype == 'Antminer S9':
            minerid = details['miner_id']
    minerinfo = MinerInfo(minertype, minerid)
    return minerinfo
    def test_minerserialization(self):
        sch = MinerSchema()
        miner = Miner('test')
        miner.status = MinerStatus.Offline
        miner.status = MinerStatus.Online
        miner.minerinfo = MinerInfo('Antminer S9', '123')
        miner.minerpool = MinerCurrentPool(miner,
                                           'test pool',
                                           'test worker',
                                           allpools={})
        miner.minerpool.poolname = 'unittest'
        miner.minerstats = MinerStatistics(miner, datetime.datetime.utcnow(),
                                           0, 1, 0, 99, 98, 97, 123, '', '',
                                           '')
        miner.minerstats.boardstatus1 = 'o'
        miner.minerstats.boardstatus2 = 'oo'
        miner.minerstats.boardstatus3 = 'ooo'
        jminer = sch.dumps(miner).data

        #rehydrate miner
        reminer = MinerSchema().loads(jminer).data
        self.assertTrue(isinstance(reminer.minerinfo, MinerInfo))
        self.assertTrue(isinstance(reminer.minerpool, MinerCurrentPool))
        self.assertTrue(reminer.minerpool.poolname == 'unittest')
        self.assertTrue(isinstance(reminer.minerstats, MinerStatistics))
        self.assertTrue(reminer.laststatuschanged)
        self.assertTrue(reminer.minerstats.boardstatus1 == 'o')
        self.assertTrue(reminer.minerstats.boardstatus2 == 'oo')
        self.assertTrue(reminer.minerstats.boardstatus3 == 'ooo')
Esempio n. 4
0
def parse_minerinfo(status):
    #build MinerInfo from stats
    minerid = 'unknown'
    minertype = 'unknown'
    if 'Type' in status:
        minertype = status['Type']
    else:
        if status['Description'].startswith('cgminer'):
            minertype = status['Description']
    if 'miner_id' in status:
        minerid = status['miner_id']
    minerinfo = MinerInfo(minertype, minerid)
    return minerinfo
Esempio n. 5
0
    def test_minerserialization(self):
        sch = messaging.messages.MinerSchema()
        miner = self.make_miner()
        miner.status = MinerStatus.Offline
        miner.status = MinerStatus.Online
        miner.minerinfo = MinerInfo('Antminer S9', '123')
        miner.minerpool = MinerCurrentPool(miner,
                                           'test pool',
                                           'test worker',
                                           allpools={})
        miner.minerpool.poolname = 'unittest'
        miner.minerstats = domain.minerstatistics.MinerStatistics(
            miner, datetime.datetime.utcnow(), 0, 1, 0, 99, 98, 97, 123, '',
            '', '')
        miner.minerstats.boardstatus1 = 'o'
        miner.minerstats.boardstatus2 = 'oo'
        miner.minerstats.boardstatus3 = 'ooo'
        miner.minerstats.hardware_errors = 123
        miner.minerstats.hash_avg = 13000
        miner.location = 'unittest'
        miner.in_service_date = datetime.datetime.today().replace(
            microsecond=0)
        jminer = sch.dumps(miner).data

        #rehydrate miner
        reminer = messaging.messages.MinerSchema().loads(jminer).data
        self.assertTrue(reminer.customerid == miner.customerid)
        self.assertTrue(isinstance(reminer.minerinfo, MinerInfo))
        self.assertTrue(isinstance(reminer.minerpool, MinerCurrentPool))
        self.assertTrue(reminer.minerpool.poolname == 'unittest')
        self.assertTrue(
            isinstance(reminer.minerstats,
                       domain.minerstatistics.MinerStatistics))
        self.assertTrue(reminer.laststatuschanged)
        self.assertTrue(reminer.minerstats.boardstatus1 == 'o')
        self.assertTrue(reminer.minerstats.boardstatus2 == 'oo')
        self.assertTrue(reminer.minerstats.boardstatus3 == 'ooo')
        self.assertTrue(reminer.minerstats.hardware_errors == 123)
        self.assertTrue(reminer.minerstats.hash_avg == 13000)
        self.assertTrue(reminer.location == miner.location)
        self.assertTrue(reminer.in_service_date == miner.in_service_date)
Esempio n. 6
0
 def make(self, data):
     return MinerInfo(**data)
Esempio n. 7
0
 def test_miner_setminerinfo(self):
     miner = Miner('test')
     minerinfo = MinerInfo('testminertype', miner.minerid)
     miner.setminerinfo(minerinfo)
     self.assertTrue(miner.miner_type == minerinfo.miner_type)