Nix compatibility fixes
This commit is contained in:
parent
4e8e027785
commit
353a4a1f4e
9 changed files with 63 additions and 21 deletions
|
|
@ -81,7 +81,13 @@ class SwapMgrBase:
|
||||||
class SwapMgrLinux(SwapMgrBase):
|
class SwapMgrLinux(SwapMgrBase):
|
||||||
|
|
||||||
def get_active(self):
|
def get_active(self):
|
||||||
cp = run(['/sbin/swapon', '--show=NAME', '--noheadings'], stdout=PIPE, text=True, check=True)
|
for cmd in ('/sbin/swapon', 'swapon'):
|
||||||
|
try:
|
||||||
|
cp = run([cmd, '--show=NAME', '--noheadings'], stdout=PIPE, text=True, check=True)
|
||||||
|
break
|
||||||
|
except Exception:
|
||||||
|
if cmd == 'swapon':
|
||||||
|
raise
|
||||||
res = cp.stdout.splitlines()
|
res = cp.stdout.splitlines()
|
||||||
return [e for e in res if not e.startswith('/dev/zram')] if self.ignore_zram else res
|
return [e for e in res if not e.startswith('/dev/zram')] if self.ignore_zram else res
|
||||||
|
|
||||||
|
|
@ -418,7 +424,7 @@ class Autosign:
|
||||||
linux_mount_subdir = 'mmgen_autosign'
|
linux_mount_subdir = 'mmgen_autosign'
|
||||||
macOS_ramdisk_name = 'AutosignRamDisk'
|
macOS_ramdisk_name = 'AutosignRamDisk'
|
||||||
wallet_subdir = 'autosign'
|
wallet_subdir = 'autosign'
|
||||||
linux_blkid_cmd = '/sbin/blkid -s LABEL -o value'
|
linux_blkid_cmd = 'sudo blkid -s LABEL -o value'
|
||||||
|
|
||||||
cmds = ('setup', 'xmr_setup', 'sign', 'wait')
|
cmds = ('setup', 'xmr_setup', 'sign', 'wait')
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -488,10 +488,7 @@ class CoinDaemon(Daemon):
|
||||||
"remove the network's datadir"
|
"remove the network's datadir"
|
||||||
assert self.test_suite, 'datadir removal restricted to test suite'
|
assert self.test_suite, 'datadir removal restricted to test suite'
|
||||||
if self.state == 'stopped':
|
if self.state == 'stopped':
|
||||||
run([
|
run(['rm', '-rf', self.datadir])
|
||||||
('rm' if self.platform == 'win32' else '/bin/rm'),
|
|
||||||
'-rf',
|
|
||||||
self.datadir])
|
|
||||||
set_vt100()
|
set_vt100()
|
||||||
else:
|
else:
|
||||||
msg(f'Cannot remove {self.network_datadir!r} - daemon is not stopped')
|
msg(f'Cannot remove {self.network_datadir!r} - daemon is not stopped')
|
||||||
|
|
|
||||||
|
|
@ -42,10 +42,7 @@ def check_or_create_dir(path):
|
||||||
if os.getenv('MMGEN_TEST_SUITE'):
|
if os.getenv('MMGEN_TEST_SUITE'):
|
||||||
if os.path.exists(path): # path is a link or regular file
|
if os.path.exists(path): # path is a link or regular file
|
||||||
from subprocess import run
|
from subprocess import run
|
||||||
run([
|
run(['rm', '-rf', str(path)])
|
||||||
('rm' if sys.platform == 'win32' else '/bin/rm'),
|
|
||||||
'-rf',
|
|
||||||
str(path)])
|
|
||||||
set_vt100()
|
set_vt100()
|
||||||
try:
|
try:
|
||||||
os.makedirs(path, 0o700)
|
os.makedirs(path, 0o700)
|
||||||
|
|
|
||||||
|
|
@ -134,19 +134,30 @@ class CmdTestAutosignBase(CmdTestBase):
|
||||||
|
|
||||||
def _set_e2label(self, label):
|
def _set_e2label(self, label):
|
||||||
imsg(f'Setting label to {label}')
|
imsg(f'Setting label to {label}')
|
||||||
run(['/sbin/e2label', str(self.txdev.img_path), label], check=True)
|
for cmd in ('/sbin/e2label', 'e2label'):
|
||||||
|
try:
|
||||||
|
run([cmd, str(self.txdev.img_path), label], check=True)
|
||||||
|
break
|
||||||
|
except:
|
||||||
|
if cmd == 'e2label':
|
||||||
|
raise
|
||||||
|
|
||||||
def _create_removable_device(self):
|
def _create_removable_device(self):
|
||||||
if sys.platform == 'linux':
|
if sys.platform == 'linux':
|
||||||
self.txdev.create()
|
self.txdev.create()
|
||||||
self.txdev.attach(silent=True)
|
self.txdev.attach(silent=True)
|
||||||
cmd = [
|
args = [
|
||||||
'/sbin/mkfs.ext2',
|
|
||||||
'-E', 'root_owner={}:{}'.format(os.getuid(), os.getgid()),
|
'-E', 'root_owner={}:{}'.format(os.getuid(), os.getgid()),
|
||||||
'-L', self.asi.dev_label,
|
'-L', self.asi.dev_label,
|
||||||
str(self.txdev.img_path)]
|
str(self.txdev.img_path)]
|
||||||
redir = DEVNULL
|
redir = DEVNULL
|
||||||
run(cmd, stdout=redir, stderr=redir, check=True)
|
for cmd in ('/sbin/mkfs.ext2', 'mkfs.ext2'):
|
||||||
|
try:
|
||||||
|
run([cmd] + args, stdout=redir, stderr=redir, check=True)
|
||||||
|
break
|
||||||
|
except:
|
||||||
|
if cmd == 'mkfs.ext2':
|
||||||
|
raise
|
||||||
self.txdev.detach(silent=True)
|
self.txdev.detach(silent=True)
|
||||||
elif sys.platform == 'darwin':
|
elif sys.platform == 'darwin':
|
||||||
cmd = [
|
cmd = [
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ from mmgen.daemon import CoinDaemon
|
||||||
from mmgen.proto.xmr.rpc import MoneroRPCClient, MoneroWalletRPCClient
|
from mmgen.proto.xmr.rpc import MoneroRPCClient, MoneroWalletRPCClient
|
||||||
from mmgen.proto.xmr.daemon import MoneroWalletDaemon
|
from mmgen.proto.xmr.daemon import MoneroWalletDaemon
|
||||||
|
|
||||||
from ..include.common import cfg, qmsg, vmsg
|
from ..include.common import cfg, qmsg, vmsg, in_nix_environment, test_exec
|
||||||
|
|
||||||
async def cfg_file_auth_test(cfg, d, bad_auth=False):
|
async def cfg_file_auth_test(cfg, d, bad_auth=False):
|
||||||
m = 'missing credentials' if bad_auth else f'credentials from {d.cfg_file}'
|
m = 'missing credentials' if bad_auth else f'credentials from {d.cfg_file}'
|
||||||
|
|
@ -181,6 +181,9 @@ class unit_tests:
|
||||||
return await run_test(['eth', 'eth_tn', 'eth_rt'], daemon_ids=['erigon'])
|
return await run_test(['eth', 'eth_tn', 'eth_rt'], daemon_ids=['erigon'])
|
||||||
|
|
||||||
async def parity(self, name, ut):
|
async def parity(self, name, ut):
|
||||||
|
if in_nix_environment() and not test_exec('parity --help'):
|
||||||
|
ut.skip_msg('Nix environment')
|
||||||
|
return True
|
||||||
return await run_test(['etc'])
|
return await run_test(['etc'])
|
||||||
|
|
||||||
async def xmrwallet(self, name, ut):
|
async def xmrwallet(self, name, ut):
|
||||||
|
|
|
||||||
|
|
@ -337,6 +337,19 @@ def check_solc_ver():
|
||||||
def do_run(cmd, check=True):
|
def do_run(cmd, check=True):
|
||||||
return run(cmd, stdout=PIPE, stderr=DEVNULL, check=check)
|
return run(cmd, stdout=PIPE, stderr=DEVNULL, check=check)
|
||||||
|
|
||||||
|
def test_exec(cmd):
|
||||||
|
try:
|
||||||
|
do_run(cmd.split())
|
||||||
|
return True
|
||||||
|
except Exception:
|
||||||
|
return False
|
||||||
|
|
||||||
|
def in_nix_environment():
|
||||||
|
for path in os.getenv('PATH').split(':'):
|
||||||
|
if os.path.realpath(path).startswith('/nix/store'):
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
def VirtBlockDevice(img_path, size):
|
def VirtBlockDevice(img_path, size):
|
||||||
if sys.platform == 'linux':
|
if sys.platform == 'linux':
|
||||||
return VirtBlockDeviceLinux(img_path, size)
|
return VirtBlockDeviceLinux(img_path, size)
|
||||||
|
|
@ -407,20 +420,20 @@ class VirtBlockDeviceLinux(VirtBlockDeviceBase):
|
||||||
self.size = size
|
self.size = size
|
||||||
|
|
||||||
def _get_associations(self):
|
def _get_associations(self):
|
||||||
cmd = ['/sbin/losetup', '-n', '-O', 'NAME', '-j', str(self.img_path)]
|
cmd = ['sudo', 'losetup', '-n', '-O', 'NAME', '-j', str(self.img_path)]
|
||||||
return do_run(cmd).stdout.decode().splitlines()
|
return do_run(cmd).stdout.decode().splitlines()
|
||||||
|
|
||||||
def get_new_dev(self):
|
def get_new_dev(self):
|
||||||
return do_run(['sudo', '/sbin/losetup', '-f']).stdout.decode().strip()
|
return do_run(['sudo', 'losetup', '-f']).stdout.decode().strip()
|
||||||
|
|
||||||
def do_create(self, size, path):
|
def do_create(self, size, path):
|
||||||
do_run(['truncate', f'--size={size}', str(path)])
|
do_run(['truncate', f'--size={size}', str(path)])
|
||||||
|
|
||||||
def do_attach(self, path, dev):
|
def do_attach(self, path, dev):
|
||||||
do_run(['sudo', '/sbin/losetup', dev, str(path)])
|
do_run(['sudo', 'losetup', dev, str(path)])
|
||||||
|
|
||||||
def do_detach(self, dev, check=True):
|
def do_detach(self, dev, check=True):
|
||||||
do_run(['sudo', '/sbin/losetup', '-d', dev], check=check)
|
do_run(['sudo', 'losetup', '-d', dev], check=check)
|
||||||
|
|
||||||
class VirtBlockDeviceMacOS(VirtBlockDeviceBase):
|
class VirtBlockDeviceMacOS(VirtBlockDeviceBase):
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,13 @@ class unit_tests:
|
||||||
|
|
||||||
def losetup(self, name, ut):
|
def losetup(self, name, ut):
|
||||||
os.stat('/dev/loop0')
|
os.stat('/dev/loop0')
|
||||||
run(['/sbin/losetup', '-f'], check=True, stdout=DEVNULL)
|
for cmd in ('/sbin/losetup', '/usr/sbin/losetup', 'losetup'):
|
||||||
|
try:
|
||||||
|
run([cmd, '-f'], check=True, stdout=DEVNULL)
|
||||||
|
break
|
||||||
|
except:
|
||||||
|
if cmd == 'losetup':
|
||||||
|
raise
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def pycoin(self, name, ut):
|
def pycoin(self, name, ut):
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@ init_groups() {
|
||||||
noalt_ok_tests='lint'
|
noalt_ok_tests='lint'
|
||||||
|
|
||||||
[ "$MSYS2" ] && SKIP_LIST='autosign autosign_live'
|
[ "$MSYS2" ] && SKIP_LIST='autosign autosign_live'
|
||||||
[ "$ARM32" -o "$ARM64" ] && SKIP_LIST+=' etc'
|
[ "$ARM32" -o "$ARM64" -o "$SKIP_PARITY" ] && SKIP_LIST+=' etc'
|
||||||
|
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
@ -239,6 +239,7 @@ init_tests() {
|
||||||
|
|
||||||
d_etc="operations for Ethereum Classic using devnet"
|
d_etc="operations for Ethereum Classic using devnet"
|
||||||
t_etc="parity $cmdtest_py --coin=etc ethdev"
|
t_etc="parity $cmdtest_py --coin=etc ethdev"
|
||||||
|
[ "$SKIP_PARITY" ] && t_etc_skip='parity'
|
||||||
|
|
||||||
d_xmr="Monero xmrwallet operations"
|
d_xmr="Monero xmrwallet operations"
|
||||||
t_xmr="
|
t_xmr="
|
||||||
|
|
|
||||||
|
|
@ -217,6 +217,12 @@ do_reexec() {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
in_nix_environment() {
|
||||||
|
for path in ${PATH//:/ }; do
|
||||||
|
realpath -q $path | grep -q '^/nix/store/' && break
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
# start execution
|
# start execution
|
||||||
|
|
||||||
set -e
|
set -e
|
||||||
|
|
@ -368,6 +374,8 @@ do
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
|
in_nix_environment && parity --help >/dev/null 2>&1 || SKIP_PARITY=1
|
||||||
|
|
||||||
[ "$MMGEN_DISABLE_COLOR" ] || {
|
[ "$MMGEN_DISABLE_COLOR" ] || {
|
||||||
RED="\e[31;1m" GREEN="\e[32;1m" YELLOW="\e[33;1m" BLUE="\e[34;1m" MAGENTA="\e[35;1m" CYAN="\e[36;1m"
|
RED="\e[31;1m" GREEN="\e[32;1m" YELLOW="\e[33;1m" BLUE="\e[34;1m" MAGENTA="\e[35;1m" CYAN="\e[36;1m"
|
||||||
RESET="\e[0m"
|
RESET="\e[0m"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue