Skip to content

Commit

Permalink
Merge pull request #75 from patrickmogul/main
Browse files Browse the repository at this point in the history
v1.3.1 - Test Cases
  • Loading branch information
patrickmogul authored Sep 24, 2023
2 parents ecfc210 + 9cf828c commit ffbcab9
Show file tree
Hide file tree
Showing 14 changed files with 314 additions and 123 deletions.
39 changes: 39 additions & 0 deletions .github/workflows/python-app.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# This workflow will install Python dependencies, run tests and lint with a single version of Python
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python

name: Python application

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

permissions:
contents: read

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Set up Python 3.10
uses: actions/setup-python@v3
with:
python-version: "3.10"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install flake8 pytest
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Test with pytest
run: |
pytest
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ pycryptodome==3.16.0
pyhmy==0.1.0
PyJWT==2.6.0
pyperclip==1.8.2
pytest>=7.4.2
python-dotenv==0.21.0
requests>=2.28.1
rlp==3.0.0
Expand Down
3 changes: 0 additions & 3 deletions src/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +0,0 @@
from .library import load_var_file, ask_yes_no, set_var

__all__ = ['load_var_file', 'ask_yes_no', 'set_var']
20 changes: 12 additions & 8 deletions src/app.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os, argparse
import os
import argparse
from toolbox import (
run_findora_menu,
menu_install_findora,
Expand All @@ -9,25 +10,28 @@
container_running,
run_troubleshooting_process,
parse_flags,
check_preflight_setup
check_preflight_setup,
)
from config import findora_env
from shared import findora_env


def main() -> None:
# Intro w/ stars below
loader_intro()
print_stars()

# Load Vars / Set Network & Region
network, region = check_preflight_setup(findora_env.dotenv_file, findora_env.user_home_dir, findora_env.active_user_name)

network, region = check_preflight_setup(
findora_env.dotenv_file, findora_env.user_home_dir, findora_env.active_user_name
)

# Can this user access docker?
docker_check()

# Init parser for extra flags:
parser = argparse.ArgumentParser(description="Findora Validator Toolbox - Help Menu")
parse_flags(parser, region, network)

# If `fn` isn't installed, run full installer.
if not os.path.exists("/usr/local/bin/fn"):
# It does not, let's ask to install!
Expand Down
29 changes: 0 additions & 29 deletions src/config.py

This file was deleted.

8 changes: 5 additions & 3 deletions src/installer.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import subprocess
from config import findora_env
from shared import (
create_directory_with_permissions,
install_fn_app,
Expand All @@ -8,6 +7,7 @@
load_server_data,
start_local_validator,
get_live_version,
findora_env
)


Expand Down Expand Up @@ -36,7 +36,7 @@ def run_full_installer(network, region):

# Make Directories & Set Permissions
create_directory_with_permissions("/data/findora", USERNAME)

# Create backup directory
subprocess.run(
["mkdir", "-p", f"/home/{USERNAME}/findora_backup"],
Expand Down Expand Up @@ -72,4 +72,6 @@ def run_full_installer(network, region):
)

# Start findorad
start_local_validator(ROOT_DIR, FINDORAD_IMG, "installer", network, CONTAINER_NAME, ENDPOINT_STATUS_URL, RETRY_INTERVAL)
start_local_validator(
ROOT_DIR, FINDORAD_IMG, "installer", network, CONTAINER_NAME, ENDPOINT_STATUS_URL, RETRY_INTERVAL
)
20 changes: 0 additions & 20 deletions src/messages/framenu.txt

This file was deleted.

19 changes: 14 additions & 5 deletions src/safety_clean.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import subprocess
import os
from config import findora_env
from shared import (
stop_and_remove_container,
chown_dir,
get_live_version,
start_local_validator,
load_server_data,
findora_env,
)


def run_safety_clean(network = os.environ.get("FRA_NETWORK"), region = os.environ.get("FRA_REGION")):
def run_safety_clean(network=os.environ.get("FRA_NETWORK"), region=os.environ.get("FRA_REGION")):
USERNAME = findora_env.active_user_name
ENV = "prod"
server_url = f"https://{ENV}-{network}.{ENV}.findora.org"
Expand All @@ -30,9 +30,18 @@ def run_safety_clean(network = os.environ.get("FRA_NETWORK"), region = os.enviro

# get checkpoint on testnet
if network == "testnet":
CHECKPOINT_URL = f"https://{ENV}-{network}-us-west-2-ec2-instance.s3.us-west-2.amazonaws.com/{network}/checkpoint"
CHECKPOINT_URL = (
f"https://{ENV}-{network}-us-west-2-ec2-instance.s3.us-west-2.amazonaws.com/{network}/checkpoint"
)
subprocess.run(["sudo", "rm", "-rf", f"{ROOT_DIR}/checkpoint.toml"], check=True)
subprocess.run(["wget", "-O", f"{ROOT_DIR}/checkpoint.toml", f"{CHECKPOINT_URL}"], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, check=True)
subprocess.run(
["wget", "-O", f"{ROOT_DIR}/checkpoint.toml", f"{CHECKPOINT_URL}"],
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL,
check=True,
)

# Start findorad
start_local_validator(ROOT_DIR, FINDORAD_IMG, "safety_clean", network, CONTAINER_NAME, ENDPOINT_STATUS_URL, RETRY_INTERVAL)
start_local_validator(
ROOT_DIR, FINDORAD_IMG, "safety_clean", network, CONTAINER_NAME, ENDPOINT_STATUS_URL, RETRY_INTERVAL
)
45 changes: 41 additions & 4 deletions src/shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,44 @@
import urllib.request
import tarfile
import docker
from colorama import Fore
from config import findora_env
import socket


def get_url(timeout=5) -> str:
try:
response = requests.get("https://api.ipify.org?format=json", timeout=timeout)
response.raise_for_status() # Raises a HTTPError if the response was unsuccessful

# Parse the JSON response
ip_data = response.json()
result = ip_data["ip"]
except requests.exceptions.RequestException as x:
try:
response = requests.get("https://ident.me", timeout=timeout)
response.raise_for_status() # Raises a HTTPError if the response was unsuccessful
result = response.text
except requests.exceptions.RequestException as x:
print(type(x), x)
result = "0.0.0.0"
return result


class findora_env:
toolbox_version = "1.3.1"
server_host_name = socket.gethostname()
user_home_dir = os.path.expanduser("~")
dotenv_file = f"{user_home_dir}/.findora.env"
active_user_name = os.path.split(user_home_dir)[-1]
findora_root = "/data/findora"
findora_root_mainnet = f"{findora_root}/mainnet"
findora_root_testnet = f"{findora_root}/testnet"
toolbox_location = os.path.join(user_home_dir, "findora-toolbox")
staker_memo_path = os.path.join(user_home_dir, "staker_memo")
our_external_ip = get_url()
container_name = "findorad"
migrate_dir = os.path.join(user_home_dir, "migrate")
fra_env = "prod"
findora_backup = os.path.join(user_home_dir, "findora_backup")


def execute_command(command):
Expand Down Expand Up @@ -247,7 +283,8 @@ def load_server_data(ENV, network, ROOT_DIR, region):

# Check available disk space
required_space = snapshot_size * 2.5
available_space = get_available_space(SNAPSHOT_DIR)
available_space = get_available_space(ROOT_DIR)
final_size = available_space - required_space + snapshot_size
if available_space < required_space:
print(
f"Error: Not enough disk space available. Minimum Required: {format_size(required_space)}+, Available: {format_size(available_space)}."
Expand All @@ -257,7 +294,7 @@ def load_server_data(ENV, network, ROOT_DIR, region):
exit(1)
else:
print(
f"* Available disk space: {format_size(available_space)} - Estimated required space: {format_size(required_space)} - Estimated available space after unpacking: {format_size(available_space - required_space - snapshot_size)} "
f"* Available disk space: {format_size(available_space)} - Estimated required space: {format_size(required_space)} - Estimated available space after unpacking: {format_size(final_size)} "
)

# Extract the tar archive and check the exit status
Expand Down
Loading

0 comments on commit ffbcab9

Please sign in to comment.