Skip to content
This repository has been archived by the owner on Sep 21, 2023. It is now read-only.

Commit

Permalink
feat(localnet): added automatic rc release download in localnet if bi…
Browse files Browse the repository at this point in the history
…nary path not provided

```
sandi@sandi-ThinkPad-X1-Carbon-7th ~/w/n/nearup (master)> nearup run localnet
2021-05-17 16:03:48.689 INFO nearup - run: Home directory is /home/sandi/.near/localnet...
2021-05-17 16:03:50.417 INFO util - download_binaries: Downloading latest deployed version for localnet
2021-05-17 16:03:50.418 INFO util - download_binaries: Downloading neard to /home/sandi/.nearup/near/localnet/neard from nearcore/Linux/1.19.0/daf13ddfa7341883f4c8eb00b063a98757dc59c8/neard...
2021-05-17 16:03:54.132 INFO util - download_binaries: Downloaded neard to /home/sandi/.nearup/near/localnet/neard...
2021-05-17 16:03:54.132 INFO util - download_binaries: Making the neard executable...
2021-05-17 16:03:54.174 INFO localnet - run: Localnet was spawned successfully...
2021-05-17 16:03:54.175 INFO localnet - run: Localnet logs written in: /home/sandi/.nearup/logs/localnet
2021-05-17 16:03:54.175 INFO localnet - run: Check localnet status at http://127.0.0.1:3030/status
sandi@sandi-ThinkPad-X1-Carbon-7th ~/w/n/nearup (master)> nearup stop
2021-05-17 16:04:04.349 WARNING nodelib - stop_nearup: Stopping the near daemon...
2021-05-17 16:04:04.350 INFO nodelib - stop_native: Near procces is neard with pid: 107196...
2021-05-17 16:04:04.350 INFO nodelib - stop_native: Stopping process neard with pid 107196...
2021-05-17 16:04:06.696 INFO nodelib - stop_native: Near procces is neard with pid: 107197...
2021-05-17 16:04:06.697 INFO nodelib - stop_native: Stopping process neard with pid 107197...
2021-05-17 16:04:07.032 INFO nodelib - stop_native: Near procces is neard with pid: 107198...
2021-05-17 16:04:07.033 INFO nodelib - stop_native: Stopping process neard with pid 107198...
2021-05-17 16:04:07.368 INFO nodelib - stop_native: Near procces is neard with pid: 107234...
2021-05-17 16:04:07.369 INFO nodelib - stop_native: Stopping process neard with pid 107234...
2021-05-17 16:04:07.704 WARNING nodelib - stop_nearup: Stopping the nearup watcher...
2021-05-17 16:04:07.705 ERROR watcher - stop_watcher: There was an error while stopping watcher: psutil.NoSuchProcess no process found with pid 7068
```
  • Loading branch information
chefsale committed May 18, 2021
1 parent e148397 commit 30e6483
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 7 deletions.
2 changes: 1 addition & 1 deletion nearuplib/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.9.0
0.9.1
1 change: 1 addition & 0 deletions nearuplib/constants.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os

LOCALNET_FOLDER = os.path.expanduser("~/.nearup/near/localnet")
LOGS_FOLDER = os.path.expanduser('~/.nearup/logs')
LOCALNET_LOGS_FOLDER = os.path.expanduser("~/.nearup/logs/localnet")
NODE_PID_FILE = os.path.expanduser('~/.nearup/node.pid')
Expand Down
2 changes: 2 additions & 0 deletions nearuplib/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ class NetworkError(Exception):

def capture_as(exception):
"""Capture any exception raised by the wrapped function and re-raise as the given exception."""

def wrap(func):

@functools.wraps(func)
def wrapped(*args, **kwargs):
try:
Expand Down
9 changes: 8 additions & 1 deletion nearuplib/localnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@

from shutil import rmtree

from nearuplib.constants import NODE_PID_FILE, LOCALNET_LOGS_FOLDER
from nearuplib.constants import NODE_PID_FILE, LOCALNET_FOLDER, LOCALNET_LOGS_FOLDER
from nearuplib.nodelib import run_binary, proc_name_from_pid, is_neard_running
from nearuplib.util import download_binaries


def run(binary_path, home, num_nodes, num_shards, override, verbose=True):
Expand Down Expand Up @@ -65,6 +66,12 @@ def run(binary_path, home, num_nodes, num_shards, override, verbose=True):
def entry(binary_path, home, num_nodes, num_shards, override, verbose):
if binary_path:
binary_path = os.path.join(binary_path, 'neard')
else:
uname = os.uname()[0]
binary_path = os.path.join(LOCALNET_FOLDER, "neard")
if not os.path.exists(LOCALNET_FOLDER):
os.makedirs(LOCALNET_FOLDER)
download_binaries('localnet', uname)

if is_neard_running():
sys.exit(1)
Expand Down
8 changes: 6 additions & 2 deletions nearuplib/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,12 @@ def download_genesis(net, home_dir):


def download_binaries(net, uname, nightly=False):
commit = latest_deployed_release_commit(net)
branch = latest_deployed_release_branch(net)
if net != "localnet":
commit = latest_deployed_release_commit(net)
branch = latest_deployed_release_branch(net)
else:
commit = latest_deployed_release_commit("testnet")
branch = latest_deployed_release_branch("testnet")

if commit:
logging.info(f'Downloading latest deployed version for {net}')
Expand Down
7 changes: 5 additions & 2 deletions nearuplib/watcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,13 @@ def check_watcher_file():
try:
pid = int(pid_file.readline().strip())
except Exception:
logging.error(f"Nearup watcher PID file {WATCHER_PID_FILE} has unexpected content.")
logging.error(
f"Nearup watcher PID file {WATCHER_PID_FILE} has unexpected content."
)
return True

logging.warning(f"Old Nearup watcher PID file {WATCHER_PID_FILE} found.")
logging.warning(
f"Old Nearup watcher PID file {WATCHER_PID_FILE} found.")

try:
os.kill(pid, 0)
Expand Down
3 changes: 2 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ commands = bash ./scripts/pylint.sh
# W0703 broad-except
# R0801 duplicate-code
# R0913 too-many-arguments
disable=C0114,C0116,W1202,W1203,W0511,W0703,R0801,R0913
# R1732 consider-using-with
disable=C0114,C0116,W1202,W1203,W0511,W0703,R0801,R0913,R1732

[DESIGN]
# Maximum number of arguments for function / method
Expand Down

0 comments on commit 30e6483

Please sign in to comment.