bug: fix ssh commands not working properly because of error handling inside inner functions.

This commit is contained in:
UpstreamData
2023-05-12 08:23:29 -06:00
parent 8e430b149b
commit 827834a119
5 changed files with 60 additions and 86 deletions

View File

@@ -71,7 +71,7 @@ class BMMiner(BaseMiner):
try:
conn = await self._get_ssh_connection()
except (asyncssh.Error, OSError):
except ConnectionError:
return None
# open an ssh connection
@@ -106,11 +106,11 @@ class BMMiner(BaseMiner):
async def reboot(self) -> bool:
logging.debug(f"{self}: Sending reboot command.")
_ret = await self.send_ssh_command("reboot")
ret = await self.send_ssh_command("reboot")
logging.debug(f"{self}: Reboot command completed.")
if isinstance(_ret, str):
return True
return False
if ret is None:
return False
return True
async def send_config(self, config: MinerConfig, user_suffix: str = None) -> None:
return None
@@ -193,8 +193,7 @@ class BMMiner(BaseMiner):
async def get_hostname(self) -> Optional[str]:
hn = await self.send_ssh_command("cat /proc/sys/kernel/hostname")
if hn:
return hn
return hn
async def get_hashrate(self, api_summary: dict = None) -> Optional[float]:
# get hr from API

View File

@@ -194,7 +194,7 @@ class BOSMiner(BaseMiner):
try:
conn = await self._get_ssh_connection()
except (asyncssh.Error, OSError):
except ConnectionError:
return None
# open an ssh connection
@@ -224,9 +224,9 @@ class BOSMiner(BaseMiner):
async def fault_light_on(self) -> bool:
"""Sends command to turn on fault light on the miner."""
logging.debug(f"{self}: Sending fault_light on command.")
_ret = await self.send_ssh_command("miner fault_light on")
ret = await self.send_ssh_command("miner fault_light on")
logging.debug(f"{self}: fault_light on command completed.")
if isinstance(_ret, str):
if isinstance(ret, str):
self.light = True
return self.light
return False
@@ -235,9 +235,9 @@ class BOSMiner(BaseMiner):
"""Sends command to turn off fault light on the miner."""
logging.debug(f"{self}: Sending fault_light off command.")
self.light = False
_ret = await self.send_ssh_command("miner fault_light off")
ret = await self.send_ssh_command("miner fault_light off")
logging.debug(f"{self}: fault_light off command completed.")
if isinstance(_ret, str):
if isinstance(ret, str):
self.light = False
return True
return False
@@ -249,9 +249,9 @@ class BOSMiner(BaseMiner):
async def restart_bosminer(self) -> bool:
"""Restart bosminer hashing process."""
logging.debug(f"{self}: Sending bosminer restart command.")
_ret = await self.send_ssh_command("/etc/init.d/bosminer restart")
ret = await self.send_ssh_command("/etc/init.d/bosminer restart")
logging.debug(f"{self}: bosminer restart command completed.")
if isinstance(_ret, str):
if isinstance(ret, str):
return True
return False
@@ -278,9 +278,9 @@ class BOSMiner(BaseMiner):
async def reboot(self) -> bool:
"""Reboots power to the physical miner."""
logging.debug(f"{self}: Sending reboot command.")
_ret = await self.send_ssh_command("/sbin/reboot")
ret = await self.send_ssh_command("/sbin/reboot")
logging.debug(f"{self}: Reboot command completed.")
if isinstance(_ret, str):
if isinstance(ret, str):
return True
return False
@@ -294,7 +294,7 @@ class BOSMiner(BaseMiner):
conn = None
try:
conn = await self._get_ssh_connection()
except (asyncssh.Error, OSError):
except ConnectionError:
try:
pools = await self.api.pools()
except APIError:
@@ -322,7 +322,7 @@ class BOSMiner(BaseMiner):
)
try:
conn = await self._get_ssh_connection()
except (asyncssh.Error, OSError):
except ConnectionError:
return None
async with conn:
# BBB check because bitmain suxx
@@ -366,12 +366,9 @@ class BOSMiner(BaseMiner):
##################################################
async def get_mac(self) -> Optional[str]:
try:
result = await self.send_ssh_command("cat /sys/class/net/eth0/address")
if result:
return result.upper().strip()
except (asyncssh.Error, OSError):
pass
result = await self.send_ssh_command("cat /sys/class/net/eth0/address")
if result:
return result.upper().strip()
async def get_model(self) -> Optional[str]:
return self.model + " (BOS)"
@@ -425,7 +422,7 @@ class BOSMiner(BaseMiner):
fw_ver = await self.send_ssh_command("cat /etc/bos_version")
# if we get the version data, parse it
if fw_ver:
if fw_ver is not None:
ver = fw_ver.split("-")[5]
if "." in ver:
self.fw_ver = ver
@@ -954,15 +951,12 @@ class BOSMiner(BaseMiner):
pass
# get light via ssh if that fails (10x slower)
try:
data = (
await self.send_ssh_command("cat /sys/class/leds/'Red LED'/delay_off")
).strip()
self.light = False
if data == "50":
self.light = True
except Exception as e:
logging.debug(f"SSH command failed - Fault Light - {e}")
data = (
await self.send_ssh_command("cat /sys/class/leds/'Red LED'/delay_off")
).strip()
self.light = False
if data == "50":
self.light = True
return self.light
async def get_nominal_hashrate(self, api_devs: dict = None) -> Optional[float]:

View File

@@ -34,7 +34,7 @@ class BOSMinerOld(BOSMiner):
try:
conn = await self._get_ssh_connection()
except (asyncssh.Error, OSError):
except ConnectionError:
return None
# open an ssh connection

View File

@@ -69,7 +69,7 @@ class CGMiner(BaseMiner):
try:
conn = await self._get_ssh_connection()
except (asyncssh.Error, OSError):
except ConnectionError:
return None
# open an ssh connection
@@ -100,57 +100,44 @@ class CGMiner(BaseMiner):
"""Restart cgminer hashing process."""
commands = ["cgminer-api restart", "/usr/bin/cgminer-monitor >/dev/null 2>&1"]
commands = ";".join(commands)
try:
_ret = await self.send_ssh_command(commands)
except (asyncssh.Error, OSError):
ret = await self.send_ssh_command(commands)
if ret is None:
return False
else:
if isinstance(_ret, str):
return True
return False
return True
async def reboot(self) -> bool:
"""Reboots power to the physical miner."""
logging.debug(f"{self}: Sending reboot command.")
try:
_ret = await self.send_ssh_command("reboot")
except (asyncssh.Error, OSError):
ret = await self.send_ssh_command("reboot")
if ret is None:
return False
else:
logging.debug(f"{self}: Reboot command completed.")
if isinstance(_ret, str):
return True
return False
return True
async def resume_mining(self) -> bool:
try:
commands = [
"mkdir -p /etc/tmp/",
'echo "*/3 * * * * /usr/bin/cgminer-monitor" > /etc/tmp/root',
"crontab -u root /etc/tmp/root",
"/usr/bin/cgminer-monitor >/dev/null 2>&1",
]
commands = ";".join(commands)
await self.send_ssh_command(commands)
except (asyncssh.Error, OSError):
commands = [
"mkdir -p /etc/tmp/",
'echo "*/3 * * * * /usr/bin/cgminer-monitor" > /etc/tmp/root',
"crontab -u root /etc/tmp/root",
"/usr/bin/cgminer-monitor >/dev/null 2>&1",
]
commands = ";".join(commands)
ret = await self.send_ssh_command(commands)
if ret is None:
return False
else:
return True
return True
async def stop_mining(self) -> bool:
try:
commands = [
"mkdir -p /etc/tmp/",
'echo "" > /etc/tmp/root',
"crontab -u root /etc/tmp/root",
"killall cgminer",
]
commands = ";".join(commands)
await self.send_ssh_command(commands)
except (asyncssh.Error, OSError):
commands = [
"mkdir -p /etc/tmp/",
'echo "" > /etc/tmp/root',
"crontab -u root /etc/tmp/root",
"killall cgminer",
]
commands = ";".join(commands)
ret = await self.send_ssh_command(commands)
if ret is None:
return False
else:
return True
return True
async def get_config(self) -> MinerConfig:
api_pools = await self.api.pools()
@@ -224,12 +211,8 @@ class CGMiner(BaseMiner):
return self.fw_ver
async def get_hostname(self) -> Optional[str]:
try:
hn = await self.send_ssh_command("cat /proc/sys/kernel/hostname")
except (asyncssh.Error, OSError):
return None
if hn:
return hn
hn = await self.send_ssh_command("cat /proc/sys/kernel/hostname")
return hn
async def get_hashrate(self, api_summary: dict = None) -> Optional[float]:
# get hr from API

View File

@@ -14,7 +14,6 @@
# limitations under the License. -
# ------------------------------------------------------------------------------
import inspect
import ipaddress
import logging
from abc import ABC, abstractmethod
@@ -25,7 +24,6 @@ import asyncssh
from pyasic.config import MinerConfig
from pyasic.data import Fan, HashBoard, MinerData
from pyasic.data.error_codes import MinerErrorData
from pyasic.errors import APIError
class BaseMiner(ABC):
@@ -95,12 +93,12 @@ class BaseMiner(ABC):
)
return conn
except Exception as e:
raise e
raise ConnectionError from e
except OSError as e:
logging.warning(f"Connection refused: {self}")
raise e
raise ConnectionError from e
except Exception as e:
raise e
raise ConnectionError from e
async def check_light(self) -> bool:
return await self.get_fault_light()