Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sheep compatiability #21

Merged
merged 35 commits into from
Aug 28, 2022
Merged

Sheep compatiability #21

merged 35 commits into from
Aug 28, 2022

Conversation

shardros
Copy link
Member

@shardros shardros commented Aug 17, 2022

This PR will be merged when there is all of the parts which sheep needs to run working.

This was referenced Aug 17, 2022
@fenjalien fenjalien added this to the Shepherd-1 Feature parity milestone Aug 19, 2022
This was linked to issues Aug 19, 2022
@shardros shardros marked this pull request as ready for review August 19, 2022 16:42
@fenjalien
Copy link
Collaborator

Running this branch on my pi produces this error when the start button is pressed in the editor:

INFO:     127.0.0.1:44546 - "POST /upload/upload HTTP/1.1" 500 Internal Server Error
ERROR:    Exception in ASGI application
Traceback (most recent call last):
  File "/home/pi/.cache/pypoetry/virtualenvs/shepherd-2-TGIJcPDa-py3.10/lib/python3.10/site-packages/uvicorn/protocols/http/h11_impl.py", line 394, in run_asgi
    result = await app(self.scope, self.receive, self.send)
  File "/home/pi/.cache/pypoetry/virtualenvs/shepherd-2-TGIJcPDa-py3.10/lib/python3.10/site-packages/uvicorn/middleware/proxy_headers.py", line 45, in __call__
    return await self.app(scope, receive, send)
  File "/home/pi/.cache/pypoetry/virtualenvs/shepherd-2-TGIJcPDa-py3.10/lib/python3.10/site-packages/fastapi/applications.py", line 199, in __call__
    await super().__call__(scope, receive, send)
  File "/home/pi/.cache/pypoetry/virtualenvs/shepherd-2-TGIJcPDa-py3.10/lib/python3.10/site-packages/starlette/applications.py", line 112, in __call__
    await self.middleware_stack(scope, receive, send)
  File "/home/pi/.cache/pypoetry/virtualenvs/shepherd-2-TGIJcPDa-py3.10/lib/python3.10/site-packages/starlette/middleware/errors.py", line 181, in __call__
    raise exc from None
  File "/home/pi/.cache/pypoetry/virtualenvs/shepherd-2-TGIJcPDa-py3.10/lib/python3.10/site-packages/starlette/middleware/errors.py", line 159, in __call__
    await self.app(scope, receive, _send)
  File "/home/pi/.cache/pypoetry/virtualenvs/shepherd-2-TGIJcPDa-py3.10/lib/python3.10/site-packages/starlette/exceptions.py", line 82, in __call__
    raise exc from None
  File "/home/pi/.cache/pypoetry/virtualenvs/shepherd-2-TGIJcPDa-py3.10/lib/python3.10/site-packages/starlette/exceptions.py", line 71, in __call__
    await self.app(scope, receive, sender)
  File "/home/pi/.cache/pypoetry/virtualenvs/shepherd-2-TGIJcPDa-py3.10/lib/python3.10/site-packages/starlette/routing.py", line 580, in __call__
    await route.handle(scope, receive, send)
  File "/home/pi/.cache/pypoetry/virtualenvs/shepherd-2-TGIJcPDa-py3.10/lib/python3.10/site-packages/starlette/routing.py", line 241, in handle
    await self.app(scope, receive, send)
  File "/home/pi/.cache/pypoetry/virtualenvs/shepherd-2-TGIJcPDa-py3.10/lib/python3.10/site-packages/starlette/routing.py", line 52, in app
    response = await func(request)
  File "/home/pi/.cache/pypoetry/virtualenvs/shepherd-2-TGIJcPDa-py3.10/lib/python3.10/site-packages/fastapi/routing.py", line 216, in app
    raw_response = await run_endpoint_function(
  File "/home/pi/.cache/pypoetry/virtualenvs/shepherd-2-TGIJcPDa-py3.10/lib/python3.10/site-packages/fastapi/routing.py", line 151, in run_endpoint_function
    return await run_in_threadpool(dependant.call, **values)
  File "/home/pi/.cache/pypoetry/virtualenvs/shepherd-2-TGIJcPDa-py3.10/lib/python3.10/site-packages/starlette/concurrency.py", line 40, in run_in_threadpool
    return await loop.run_in_executor(None, func, *args)
  File "/home/pi/.pyenv/versions/3.10.6/lib/python3.10/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/home/pi/shepherd-2/./app/routers.py", line 55, in upload_file
    app.upload.process_uploaded_file(uploaded_file)
  File "/home/pi/shepherd-2/./app/upload.py", line 110, in process_uploaded_file
    shutil.rmtree(config.round_path)
  File "/home/pi/.pyenv/versions/3.10.6/lib/python3.10/shutil.py", line 714, in rmtree
    onerror(os.lstat, path, sys.exc_info())
  File "/home/pi/.pyenv/versions/3.10.6/lib/python3.10/shutil.py", line 712, in rmtree
    orig_st = os.lstat(path)
FileNotFoundError: [Errno 2] No such file or directory: '/home/pi/shepherd-2/usercode/round'

The later run request gives a 409

INFO:     127.0.0.1:49338 - "POST /run/start HTTP/1.1" 409 Conflict

The output of running pytest is

test/test_editor.py ..                                                             [ 20%]
test/test_home.py .                                                                [ 30%]
test/test_runner.py x..F                                                           [ 70%]
test/test_upload.py FFF                                                            [100%]

It looks like the failures are also due to the directory usercode/round not exsisting, what is the purpose of this folder @shardros ?

@shardros
Copy link
Member Author

Fixed and tested on fresh install

@shardros
Copy link
Member Author

It looks like the failures are also due to the directory usercode/round not exsisting, what is the purpose of this folder @shardros ?

This is correct. This is the folder where the usercode which is to be run in the next round is uploaded to. It is now automatically created by shepherd. Logs aren't done in this pr but you can see that the code works by looking logs.txt

@fenjalien
Copy link
Collaborator

This is the folder where the usercode which is to be run in the next round is uploaded to.

Ah so usercode/ is all the code that has been written by the user and usercode/round/ is the code that will be run when /run/start is hit?

@shardros
Copy link
Member Author

This is the folder where the usercode which is to be run in the next round is uploaded to.

Ah so usercode/ is all the code that has been written by the user and usercode/round/ is the code that will be run when /run/start is hit?

Correct :)

Copy link
Collaborator

@fenjalien fenjalien left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From running the tests:

test/test_editor.py ..        [ 20%]
test/test_home.py .         [ 30%]
test/test_runner.py xF..   [ 70%]
test/test_upload.py .FF    [100%]

test_start fails at line 20 due to a timeout. Looks like it comes from this line:

type(runner).state.__set__(runner, States.RUNNING)

Why is it like this? In fact all of the rest of the tests fail due to this.

app/editor.py Outdated Show resolved Hide resolved
app/config.py Outdated Show resolved Hide resolved
app/config.py Outdated Show resolved Hide resolved
app/config.py Outdated Show resolved Hide resolved
app/config.py Outdated Show resolved Hide resolved
app/routers.py Outdated Show resolved Hide resolved
app/routers.py Show resolved Hide resolved
app/routers.py Show resolved Hide resolved
install.sh Show resolved Hide resolved
install.sh Show resolved Hide resolved
@fenjalien
Copy link
Collaborator

I've just tried changing this:

type(runner).state.__set__(runner, States.RUNNING)

to this:

runner.state = States.RUNNING

and all tests pass apart from larg_zip_upload by timeout. I'm assuming this is due to the shear size its timeout will need to be much longer.

shardros and others added 18 commits August 23, 2022 17:41
This test looks at the logs and checks they are as they should be. However if shepherd crashes in this test then the usercode continues running and continues writing to the logs.
This commit uses context managers to harden against this but does not completely solve the problem
This test looks at the logs and checks they are as they should be. However if shepherd crashes in this test then the usercode continues running and continues writing to the logs.
This commit uses context managers to harden against this but does not completely solve the problem
@shardros
Copy link
Member Author

@fenjalien ready for another round of review

@shardros shardros merged commit 8491081 into master Aug 28, 2022
@shardros
Copy link
Member Author

You can still retroactively do the code review but we need to move fast

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Run parity with shepherd-1 Upload parity with shepherd-1
2 participants