added more logging for bosminer models.

This commit is contained in:
UpstreamData
2022-03-15 09:07:07 -06:00
parent 07a8b00a93
commit 9edcd866bb
4 changed files with 51 additions and 16 deletions

View File

@@ -39,7 +39,7 @@ class BMMiner(BaseMiner):
else: else:
logging.warning(f"Failed to get hostname for miner: {self}") logging.warning(f"Failed to get hostname for miner: {self}")
return "?" return "?"
except Exception: except Exception as e:
logging.warning(f"Failed to get hostname for miner: {self}") logging.warning(f"Failed to get hostname for miner: {self}")
return "?" return "?"
@@ -85,3 +85,4 @@ class BMMiner(BaseMiner):
async def reboot(self) -> None: async def reboot(self) -> None:
logging.debug(f"{self}: Sending reboot command.") logging.debug(f"{self}: Sending reboot command.")
await self.send_ssh_command("reboot") await self.send_ssh_command("reboot")
logging.debug(f"{self}: Reboot command completed.")

View File

@@ -3,7 +3,7 @@ from API.bosminer import BOSMinerAPI
import asyncssh import asyncssh
import toml import toml
from config.bos import bos_config_convert, general_config_convert_bos from config.bos import bos_config_convert, general_config_convert_bos
import logging
class BOSMiner(BaseMiner): class BOSMiner(BaseMiner):
def __init__(self, ip: str) -> None: def __init__(self, ip: str) -> None:
@@ -23,8 +23,11 @@ class BOSMiner(BaseMiner):
try: try:
conn = await asyncssh.connect(str(self.ip), known_hosts=None, username=self.uname, password=self.pwd, conn = await asyncssh.connect(str(self.ip), known_hosts=None, username=self.uname, password=self.pwd,
server_host_key_algs=['ssh-rsa']) server_host_key_algs=['ssh-rsa'])
except OSError:
logging.warning(f"Connection refused: {self} ")
return None
except Exception as e: except Exception as e:
print("Exception raised:", self.ip) logging.warning(f"{self} raised an exception: {e}")
raise e raise e
# return created connection # return created connection
return conn return conn
@@ -42,7 +45,7 @@ class BOSMiner(BaseMiner):
# save result of the command # save result of the command
result = await conn.run(cmd) result = await conn.run(cmd)
except Exception as e: except Exception as e:
print(f"{cmd} error: {e}") logging.warning(f"{self} command {cmd} error: {e}")
if i == 3: if i == 3:
return return
continue continue
@@ -51,28 +54,40 @@ class BOSMiner(BaseMiner):
async def fault_light_on(self) -> None: async def fault_light_on(self) -> None:
"""Sends command to turn on fault light on the miner.""" """Sends command to turn on fault light on the miner."""
logging.debug(f"{self}: Sending fault_light on command.")
await self.send_ssh_command('miner fault_light on') await self.send_ssh_command('miner fault_light on')
logging.debug(f"{self}: fault_light on command completed.")
async def fault_light_off(self) -> None: async def fault_light_off(self) -> None:
"""Sends command to turn off fault light on the miner.""" """Sends command to turn off fault light on the miner."""
logging.debug(f"{self}: Sending fault_light off command.")
await self.send_ssh_command('miner fault_light off') await self.send_ssh_command('miner fault_light off')
logging.debug(f"{self}: fault_light off command completed.")
async def restart_backend(self): async def restart_backend(self):
await self.restart_bosminer() await self.restart_bosminer()
async def restart_bosminer(self) -> None: async def restart_bosminer(self) -> None:
"""Restart bosminer hashing process.""" """Restart bosminer hashing process."""
logging.debug(f"{self}: Sending bosminer restart command.")
await self.send_ssh_command('/etc/init.d/bosminer restart') await self.send_ssh_command('/etc/init.d/bosminer restart')
logging.debug(f"{self}: bosminer restart command completed.")
async def reboot(self) -> None: async def reboot(self) -> None:
"""Reboots power to the physical miner.""" """Reboots power to the physical miner."""
await self.send_ssh_command('/sbin/reboot') logging.debug(f"{self}: Sending reboot command.")
await self.send_ssh_command("/sbin/reboot")
logging.debug(f"{self}: Reboot command completed.")
async def get_config(self) -> None: async def get_config(self) -> None:
logging.debug(f"{self}: Getting config.")
async with (await self._get_ssh_connection()) as conn: async with (await self._get_ssh_connection()) as conn:
logging.debug(f"{self}: Opening SFTP connection.")
async with conn.start_sftp_client() as sftp: async with conn.start_sftp_client() as sftp:
logging.debug(f"{self}: Reading config file.")
async with sftp.open('/etc/bosminer.toml') as file: async with sftp.open('/etc/bosminer.toml') as file:
toml_data = toml.loads(await file.read()) toml_data = toml.loads(await file.read())
logging.debug(f"{self}: Converting config file.")
cfg = await bos_config_convert(toml_data) cfg = await bos_config_convert(toml_data)
self.config = cfg self.config = cfg
@@ -80,33 +95,47 @@ class BOSMiner(BaseMiner):
"""Attempts to get hostname from miner.""" """Attempts to get hostname from miner."""
try: try:
async with (await self._get_ssh_connection()) as conn: async with (await self._get_ssh_connection()) as conn:
data = await conn.run('cat /proc/sys/kernel/hostname') if conn is not None:
return data.stdout.strip() data = await conn.run('cat /proc/sys/kernel/hostname')
host = data.stdout.strip()
logging.debug(f"Found hostname for {self.ip}: {host}")
return host
else:
logging.warning(f"Failed to get hostname for miner: {self}")
return "?"
except Exception as e: except Exception as e:
print(self.ip, e) logging.warning(f"Failed to get hostname for miner: {self}")
return "BOSMiner Unknown" return "?"
async def get_model(self): async def get_model(self):
if self.model: if self.model:
logging.debug(f"Found model for {self.ip}: {self.model} (BOS)")
return self.model + " (BOS)" return self.model + " (BOS)"
version_data = await self.api.devdetails() version_data = await self.api.devdetails()
if version_data: if version_data:
if not version_data["DEVDETAILS"] == []: if not version_data["DEVDETAILS"] == []:
self.model = version_data["DEVDETAILS"][0]["Model"].replace("Antminer ", "") self.model = version_data["DEVDETAILS"][0]["Model"].replace("Antminer ", "")
logging.debug(f"Found model for {self.ip}: {self.model} (BOS)")
return self.model + " (BOS)" return self.model + " (BOS)"
logging.warning(f"Failed to get model for miner: {self}")
return None return None
async def send_config(self, yaml_config) -> None: async def send_config(self, yaml_config) -> None:
"""Configures miner with yaml config.""" """Configures miner with yaml config."""
logging.debug(f"{self}: Sending config.")
toml_conf = await general_config_convert_bos(yaml_config) toml_conf = await general_config_convert_bos(yaml_config)
async with (await self._get_ssh_connection()) as conn: async with (await self._get_ssh_connection()) as conn:
logging.debug(f"{self}: Opening SFTP connection.")
async with conn.start_sftp_client() as sftp: async with conn.start_sftp_client() as sftp:
logging.debug(f"{self}: Opening config file.")
async with sftp.open('/etc/bosminer.toml', 'w+') as file: async with sftp.open('/etc/bosminer.toml', 'w+') as file:
await file.write(toml_conf) await file.write(toml_conf)
logging.debug(f"{self}: Restarting BOSMiner")
await conn.run("/etc/init.d/bosminer restart") await conn.run("/etc/init.d/bosminer restart")
async def get_board_info(self) -> dict: async def get_board_info(self) -> dict:
"""Gets data on each board and chain in the miner.""" """Gets data on each board and chain in the miner."""
logging.debug(f"{self}: Getting board info.")
devdetails = await self.api.devdetails() devdetails = await self.api.devdetails()
if not devdetails.get("DEVDETAILS"): if not devdetails.get("DEVDETAILS"):
print("devdetails error", devdetails) print("devdetails error", devdetails)
@@ -126,6 +155,7 @@ class BOSMiner(BaseMiner):
"chip_status": "o" * board['Chips'], "chip_status": "o" * board['Chips'],
"nominal": nominal "nominal": nominal
}) })
logging.debug(f"Found board data for {self}: {boards}")
return boards return boards
async def get_bad_boards(self) -> dict: async def get_bad_boards(self) -> dict:

View File

@@ -1,17 +1,15 @@
# TODO: Add Logging # TODO: Add Logging
# TODO: Add debug mode to settings?
# TODO: Add an option to append the last octet of the IP
# address to the workername when configuring
from tools.bad_board_util.miner_factory import miner_factory from tools.bad_board_util.miner_factory import miner_factory
from tools.bad_board_util.ui import ui from tools.bad_board_util.ui import ui
import asyncio import asyncio
import sys import sys
import logging
from logger import logger
logger.info("Initializing logger for CFG Util.")
# Fix bug with some whatsminers and asyncio because of a socket not being shut down: # Fix bug with some whatsminers and asyncio because of a socket not being shut down:
if sys.version_info[0] == 3 and sys.version_info[1] >= 8 and sys.platform.startswith('win'): if sys.version_info[0] == 3 and sys.version_info[1] >= 8 and sys.platform.startswith('win'):
@@ -19,8 +17,10 @@ if sys.version_info[0] == 3 and sys.version_info[1] >= 8 and sys.platform.starts
def main(): def main():
logging.info("Starting Board Util.")
loop = asyncio.new_event_loop() loop = asyncio.new_event_loop()
loop.run_until_complete(ui()) loop.run_until_complete(ui())
logging.info("Closing Board Util.")
if __name__ == '__main__': if __name__ == '__main__':

View File

@@ -1,5 +1,9 @@
# TODO: Add Logging # TODO: Add Logging
# TODO: Add an option to append the last octet of the IP
# address to the workername when configuring
import asyncio import asyncio
import sys import sys
import logging import logging