mirror of
https://github.com/nextcloud/nextcloudpi.git
synced 2026-01-10 15:12:01 -03:30
system_tests.py: Add option to use pw-less sudo for commands
This commit is contained in:
parent
e1f76558fc
commit
af7d817519
2
.github/workflows/build-sd-images.yml
vendored
2
.github/workflows/build-sd-images.yml
vendored
@ -260,7 +260,7 @@ jobs:
|
|||||||
for attempt in {1..5}
|
for attempt in {1..5}
|
||||||
do
|
do
|
||||||
echo -e "${LOG_CICD} == System Tests (attempt $attempt/5) =="
|
echo -e "${LOG_CICD} == System Tests (attempt $attempt/5) =="
|
||||||
./.venv/bin/python tests/system_tests.py --non-interactive |& awk "{ print \"${LOG_TEST} \" \$0 }"
|
USE_SUDO=yes ./.venv/bin/python tests/system_tests.py --non-interactive |& awk "{ print \"${LOG_TEST} \" \$0 }"
|
||||||
[[ ${PIPESTATUS[0]} -eq 0 ]] || {
|
[[ ${PIPESTATUS[0]} -eq 0 ]] || {
|
||||||
echo -e "${LOG_CICD} System test failed!"
|
echo -e "${LOG_CICD} System test failed!"
|
||||||
sleep 12
|
sleep 12
|
||||||
|
|||||||
@ -252,6 +252,8 @@ def test_autoupdates():
|
|||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
||||||
|
sudo_prefix = ['sudo'] if os.environ.get('USE_SUDO', 'no') == 'yes' else []
|
||||||
|
|
||||||
signal.signal(signal.SIGINT, signal_handler)
|
signal.signal(signal.SIGINT, signal_handler)
|
||||||
|
|
||||||
# parse options
|
# parse options
|
||||||
@ -290,11 +292,12 @@ if __name__ == "__main__":
|
|||||||
|
|
||||||
# detect if we are running this in a NCP instance
|
# detect if we are running this in a NCP instance
|
||||||
try:
|
try:
|
||||||
dockers_running = run(['docker', 'ps', '--format', '{{.Names}}'], stdout=PIPE).stdout.decode('utf-8')
|
dockers_running = run(sudo_prefix + ['docker', 'ps', '--format', '{{.Names}}'], stdout=PIPE).stdout.decode('utf-8')
|
||||||
except:
|
except:
|
||||||
dockers_running = ''
|
dockers_running = ''
|
||||||
|
|
||||||
lxc_command = ['lxc'] if 'USE_INCUS' not in os.environ or os.environ['USE_INCUS'] != 'yes' else ['incus']
|
lxc_command = sudo_prefix
|
||||||
|
lxc_command += ['lxc'] if 'USE_INCUS' not in os.environ or os.environ['USE_INCUS'] != 'yes' else ['incus']
|
||||||
|
|
||||||
try:
|
try:
|
||||||
lxc_test = run(lxc_command + ['info'], stdout=PIPE, check=True)
|
lxc_test = run(lxc_command + ['info'], stdout=PIPE, check=True)
|
||||||
@ -316,7 +319,7 @@ if __name__ == "__main__":
|
|||||||
lxc_running = False
|
lxc_running = False
|
||||||
|
|
||||||
try:
|
try:
|
||||||
systemd_container_running = run(['machinectl', 'show', 'ncp'], stdout=PIPE, check = True)
|
systemd_container_running = run(sudo_prefix + ['machinectl', 'show', 'ncp'], stdout=PIPE, check = True)
|
||||||
except:
|
except:
|
||||||
systemd_container_running = False
|
systemd_container_running = False
|
||||||
|
|
||||||
@ -326,12 +329,12 @@ if __name__ == "__main__":
|
|||||||
print(tc.brown + "* local NCP instance detected" + tc.normal)
|
print(tc.brown + "* local NCP instance detected" + tc.normal)
|
||||||
if not is_lxc():
|
if not is_lxc():
|
||||||
binaries_must_be_installed = binaries_must_be_installed + binaries_no_docker
|
binaries_must_be_installed = binaries_must_be_installed + binaries_no_docker
|
||||||
pre_cmd = []
|
pre_cmd = sudo_prefix
|
||||||
|
|
||||||
# docker method
|
# docker method
|
||||||
elif 'nextcloudpi' in dockers_running:
|
elif 'nextcloudpi' in dockers_running:
|
||||||
print( tc.brown + "* local NCP docker instance detected" + tc.normal)
|
print( tc.brown + "* local NCP docker instance detected" + tc.normal)
|
||||||
pre_cmd = ['docker', 'exec']
|
pre_cmd = sudo_prefix + ['docker', 'exec']
|
||||||
if interactive:
|
if interactive:
|
||||||
pre_cmd.append('-ti')
|
pre_cmd.append('-ti')
|
||||||
pre_cmd.append('nextcloudpi')
|
pre_cmd.append('nextcloudpi')
|
||||||
@ -342,7 +345,7 @@ if __name__ == "__main__":
|
|||||||
pre_cmd = lxc_command + ['exec', 'ncp', '--']
|
pre_cmd = lxc_command + ['exec', 'ncp', '--']
|
||||||
|
|
||||||
elif systemd_container_running:
|
elif systemd_container_running:
|
||||||
pre_cmd = ['systemd-run', '--wait', '-P', '--machine=ncp']
|
pre_cmd = sudo_prefix + ['systemd-run', '--wait', '-P', '--machine=ncp']
|
||||||
|
|
||||||
# SSH method
|
# SSH method
|
||||||
else:
|
else:
|
||||||
@ -350,7 +353,7 @@ if __name__ == "__main__":
|
|||||||
print( tc.brown + "* No local NCP instance detected, trying SSH with " +
|
print( tc.brown + "* No local NCP instance detected, trying SSH with " +
|
||||||
tc.yellow + ssh_cmd + tc.normal + "...")
|
tc.yellow + ssh_cmd + tc.normal + "...")
|
||||||
binaries_must_be_installed = binaries_must_be_installed + binaries_no_docker
|
binaries_must_be_installed = binaries_must_be_installed + binaries_no_docker
|
||||||
pre_cmd = ['ssh', '-o UserKnownHostsFile=/dev/null' , '-o PasswordAuthentication=no',
|
pre_cmd = sudo_prefix + ['ssh', '-o UserKnownHostsFile=/dev/null' , '-o PasswordAuthentication=no',
|
||||||
'-o StrictHostKeyChecking=no', '-o ConnectTimeout=10', ssh_cmd[4:]]
|
'-o StrictHostKeyChecking=no', '-o ConnectTimeout=10', ssh_cmd[4:]]
|
||||||
|
|
||||||
if not skip_ping:
|
if not skip_ping:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user