Skip to content

Commit

Permalink
Nayduck cli - add cancel option (#10228)
Browse files Browse the repository at this point in the history
allows to cancel pending tests for given build ID

```
./scripts/nayduck.py --cancel 3288
Scheduling tests for: 
branch - remotes/origin/disable-store-validator-build 
commit hash - c221f8f
Sending request ...
Cancelled 1 tests
```

---------

Co-authored-by: nikurt <[email protected]>
  • Loading branch information
andrei-near and nikurt authored Nov 21, 2023
1 parent 2318c3a commit bf7ba11
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions scripts/nayduck.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ def _parse_args():
DEFAULT_TEST_FILE)

parser = argparse.ArgumentParser(description='Run tests.')
parser.add_argument(
'--cancel',
'-c',
help='Cancel scheduled run. In progress tests cannot be stopped.')
parser.add_argument('--branch',
'-b',
help='Branch to test. By default gets current one.')
Expand Down Expand Up @@ -278,7 +282,7 @@ def run_locally(args, tests):
subprocess.check_call(cmd, cwd=cwd, timeout=_parse_timeout(timeout))


def run_remotely(args, tests):
def run_command(args, tests):
import requests

try:
Expand Down Expand Up @@ -317,17 +321,27 @@ def run_remotely(args, tests):

while True:
print('Sending request ...')
res = requests.post(NAYDUCK_BASE_HREF + '/api/run/new',
json=post,
cookies={'nay-code': code})
if args.cancel:
res = requests.post(NAYDUCK_BASE_HREF +
f'/api/run/{args.cancel}/cancel',
cookies={'nay-code': code})
else:
res = requests.post(NAYDUCK_BASE_HREF + '/api/run/new',
json=post,
cookies={'nay-code': code})
if res.status_code != 401:
break
print(f'{styles[0]}Unauthorised.{styles[2]}\n')
code = github_auth(code_path)

if res.status_code == 200:
json_res = json.loads(res.text)
print(styles[json_res['code'] == 0] + json_res['response'] + styles[2])
if args.cancel:
print(styles[1] + 'Cancelled ' + str(json_res) + ' test(s)' +
styles[2])
else:
print(styles[json_res['code'] == 0] + json_res['response'] +
styles[2])
else:
print(f'{styles[0]}Got status code {res.status_code}:{styles[2]}\n')
print(res.text)
Expand All @@ -347,7 +361,7 @@ def main():
if args.run_locally:
run_locally(args, tests)
else:
run_remotely(args, tests)
run_command(args, tests)


if __name__ == "__main__":
Expand Down

0 comments on commit bf7ba11

Please sign in to comment.