Fixed upgrade_firmware for auradine miner

This commit is contained in:
1e9abhi1e10
2024-06-07 02:58:09 +05:30
parent 9c41a6b28f
commit eefb055a3f

View File

@@ -16,9 +16,6 @@
import logging
from enum import Enum
from typing import List, Optional
import aiofiles
import base64
from pathlib import Path
from pyasic.config import MinerConfig
from pyasic.data import AlgoHashRate, Fan, HashBoard, HashUnit
@@ -390,51 +387,26 @@ class Auradine(StockFirmware):
except LookupError:
pass
async def upgrade_firmware(self, file: Path):
async def upgrade_firmware(self, url: str = None, version: str = "latest") -> dict:
"""
Upgrade the firmware of the Auradine miner device.
Upgrade the firmware of the Auradine miner.
Args:
file (Path): The local file path of the firmware to be uploaded.
url (str, optional): The URL to download the firmware from.
version (str, optional): The version of the firmware to upgrade to, defaults to 'latest'.
Returns:
str: Confirmation message after upgrading the firmware.
dict: A dictionary indicating the result of the firmware upgrade.
"""
try:
logging.info("Starting firmware upgrade process for Auradine miner.")
if not file:
raise ValueError("File location must be provided for firmware upgrade.")
# Read the firmware file contents
async with aiofiles.open(file, "rb") as f:
upgrade_contents = await f.read()
# Encode the firmware contents in base64
encoded_contents = base64.b64encode(upgrade_contents).decode("utf-8")
# Upload the firmware file to the Auradine miner device
logging.info(f"Uploading firmware file from {file} to the device.")
await self.ssh.send_command(
f"echo {encoded_contents} | base64 -d > /tmp/firmware.tar && sysupgrade /tmp/firmware.tar"
)
logging.info("Firmware upgrade process completed successfully for Auradine miner.")
return "Firmware upgrade completed successfully."
except FileNotFoundError as e:
logging.error(f"File not found during the firmware upgrade process: {e}")
raise
except ValueError as e:
logging.error(
f"Validation error occurred during the firmware upgrade process: {e}"
)
raise
except OSError as e:
logging.error(f"OS error occurred during the firmware upgrade process: {e}")
raise
if url is not None:
return await self.web.firmware_upgrade(url=url)
return await self.web.firmware_upgrade(version=version)
except Exception as e:
logging.error(
f"An unexpected error occurred during the firmware upgrade process: {e}",
exc_info=True,
)
raise
raise