-
Notifications
You must be signed in to change notification settings - Fork 61
fix/ota-2183/Enable streaming of garage-push/deploy uploads #1305
fix/ota-2183/Enable streaming of garage-push/deploy uploads #1305
Conversation
9f3e6db
to
321413c
Compare
Codecov Report
@@ Coverage Diff @@
## master #1305 +/- ##
==========================================
- Coverage 79.72% 79.69% -0.03%
==========================================
Files 177 177
Lines 10475 10487 +12
==========================================
+ Hits 8351 8358 +7
- Misses 2124 2129 +5
Continue to review full report at Codecov.
|
I manually tested, using ‘t_deploy’,the output looks it didn’t work. Content_type is multipart and x-www-form-urlencoded.Maybe I was using the wrong test, or the code I added didn’t work somehow. |
It's possible that there is some other way you have to specify it, perhaps forcing the header value doesn't actually stick. However, I suspect a bigger problem is that you probably don't want to set that from the |
It will require updating treehub_server.py accordingly. |
Ah, I hadn't considered that. You might be right; the tests may need to get updated once we have it working correctly with the real backend.
To be clear, the "out of band upload" is out of scope for the current task that Liping is working on. But it's still worth understanding, and we may want to support it eventually, although I think it is somewhat more work. See https://saeljira.it.here.com/browse/OTA-1813 for some additional detail. Basically, the backend could tell us to upload directly to S3 and bypass treehub completely. The advantage is reduced load on our server and fewer points of failure. |
9cf5fa2
to
ac6abde
Compare
src/sota_tools/ostree_object.h
Outdated
@@ -111,6 +111,7 @@ class OSTreeObject { | |||
std::stringstream http_response_; | |||
CURL* curl_handle_; | |||
struct curl_httppost* form_post_; | |||
curl_slist* headers; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should initialize this to nullptr. Otherwise, it could be anything and will segfault in destructor. This should fix some of the failing tests in CI, I think.
src/sota_tools/ostree_object.cc
Outdated
@@ -241,6 +245,10 @@ void OSTreeObject::Upload(const TreehubServer &push_target, CURLM *curl_multi_ha | |||
|
|||
curlEasySetoptWrapper(curl_handle_, CURLOPT_PRIVATE, this); // Used by ostree_object_from_curl | |||
|
|||
headers = nullptr; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we call Upload() multiple times this will be a leak. Or is it not possible?
b4831ca
to
f9cfd21
Compare
@@ -79,6 +79,17 @@ def do_POST(self): | |||
self.send_response_only(200) | |||
self.end_headers() | |||
return | |||
elif ctype == 'application/octet-stream': |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In case of 'application/octet-stream' we can read the posted file/body just from the socket buffer, so something like that should work
elif ctype == 'application/octet-stream':
length = int(self.headers['content-length'])
body = self.rfile.read(length)
with open("body.dat", "wb") as f:
f.write(body)
self.send_response_only(200)
self.end_headers()
But, if the given implementation works then it's ok - this is just a test tool
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks Mike, I'll try your way. I was also just gonna try this:
import cgitb; cgitb.enable()
form = cgi.FieldStorage()
fileitem = form['filename']
if fileitem.filename:
with open("body.dat", "wb") as f:
f.write(fileitem.file.read())
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested Mike's way, t_deploy output:
diff: /tmp/aktualizr-951f-8561-2d1e-5c0a/d5ea-2beb-dir/objects/: No such file or directory
/home/liping/aktualizr/src/sota_tools/deploy_test.cc:32: Failure
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting, I've just checked and it works for me, I missed an ending return
statement at the end of the code snippet
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I added the return statement. maybe we can see how it work out In CI test?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I think, I understand where is a problem. It's not enough just set a header that indicates a type of transferring data, actual data should be transferred according to the declared way. In this particular case we set 'application/octet-stream' header but actually transfer data as 'multipart/form-data'
, see OSTreeObject::Upload() code below setting the headers.
src/sota_tools/ostree_object.cc
Outdated
@@ -241,6 +246,10 @@ void OSTreeObject::Upload(const TreehubServer &push_target, CURLM *curl_multi_ha | |||
|
|||
curlEasySetoptWrapper(curl_handle_, CURLOPT_PRIVATE, this); // Used by ostree_object_from_curl | |||
|
|||
assert(headers_ == nullptr); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If OSTreeObject::Upload
is called more than one for the same class instance then it won't work. I suppose, in our case it's called only once so it shouldn't be a problem, although, perhaps makes sense to set the headers in ctor ?
04a1608
to
50cd80b
Compare
All the tests passed except 'OstreeObject_test.UploadFail". II'll look into it tomorrow. |
70b8a8a
to
915e9cd
Compare
I closed the file after the reading is done, but somehow it will cause a failing of the test. Any suggestion where to close the file? |
abc53fc
to
12f26e1
Compare
See this PR: #1244 , looks there left an unsolved issue. |
12f26e1
to
10fa383
Compare
LOG_ERROR << "curl_formadd error: " << form_err; | ||
struct stat file_info {}; | ||
fd_ = fopen(file_path_.c_str(), "rb"); | ||
if (fd_ == nullptr) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Throwing an exception might be better.
@patrickvacek As far as I understand some of the tests triggered by the CI pipelines do use garag-push/deploy against the prod/SIT treehub ? |
Yes, that is correct. I don't think we actually push anything, though, I think it's just testing authentication. I might be misremembering. |
I suppose, it would be great to test this change against the real treehub, at least manually. |
Absolutely, this is a requirement. Manual confirmation is enough if we have tests that effectively simulate the real backend. |
06c1722
to
4523a85
Compare
Set header from ostree_object Fix headers initialize bug Uploade data as 'octet-stream' Fix bug fail ostree_object_test Close fd and not return right away Fix legacy issue of garage-deploy Recieve http/204 instead of http/200 Fix headers overwriting bug Signed-off-by: Zee314159 <[email protected]>
4523a85
to
ee671d5
Compare
@@ -42,7 +42,7 @@ class RequestPool { | |||
RateController rate_controller_; | |||
int running_requests_; | |||
int total_requests_made_{0}; | |||
const TreehubServer& server_; | |||
TreehubServer& server_; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's too bad we lose this const-ness. It doesn't seem so critical, though, and I don't have a better solution available yet, though, so maybe it's fine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I feel sorry for the loss too. I have tried.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested against SIT and it works! The const issue is pretty minor and we can always try to restore it another time.
Draft code.