-
Notifications
You must be signed in to change notification settings - Fork 931
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
lxd: add all-projects param to the operation API #12078
Conversation
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.
hi @roosterfish, thx for the review. I got it a bit more now. And I'm supposed to add |
Yes please. |
@AuruTus please sign-off all your commits ( |
309ff9c
to
15a2b77
Compare
@monstermunchkin hi master, all is done and signoffs are ok now. |
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 for this.
We should add a test for this though.
@monstermunchkin do you know of any precedent for testing operation listings that may help here?
We don't currently test operations, and we don't have a way of creating them via the API. What do you think about adding a new internal API endpoint called |
I'm not sure that is needed. It looks like the |
15a2b77
to
ba781d6
Compare
Signed-off-by: Aurutus <emslhy@hotmail.com>
Signed-off-by: Aurutus <emslhy@hotmail.com>
ba781d6
to
10a3102
Compare
Please can you rebase so your commits so they tell the final logical set of changes rather than the evolution over the PR review. Thanks |
@tomponline hi master, sorry I don't understand how to operate such things and those above are already generated by rebasing and force-pushing. Could give me some guides? |
Hey, so what I meant was that this latest commit f7a2c8d alters a commit earlier on your PR. Because we don't squash merge but instead pull all of your individual commits into the main branch we like that each commit within the pr represent the final version of it. Does that make sense? Thanks |
Oh I got it! 😄 . Will fix this later with the test sh script together. BTW, have a nice weekend. |
Signed-off-by: Aurutus <emslhy@hotmail.com>
Signed-off-by: Aurutus <emslhy@hotmail.com>
Signed-off-by: Aurutus <emslhy@hotmail.com>
@tomponline hi master, sorry I encounter some problems in local test env now, so I have to push the rebased commits first. The instance starting command has error as:
And this is the log print
I've been stuck here for a while, and didn't find a way to solve it. 😢 |
f7a2c8d
to
09ecaed
Compare
Does it run on the main branch, is is just your branch it does not run on? |
Yeah, tried both |
@AuruTus looks like a permission issue. Try granting execute permission for |
Cool! It works now. Thx master. I can continue my test. BTW, is there any guide on integration test result assertion? I noticed that there exists an expression like |
@AuruTus You can use |
d496f40
to
83850db
Compare
Hi masters, I think these test cases is enough for standalone mode query. (I cannot create a new network successfully on my Ubuntu 22.04 distro when creating a new project, so I directly test with the And there're still some issues for my cluster testing. I cannot mount And this the log printed when I wrote scripts
|
You're on WSL2, right? Perhaps this will fix your problem: microsoft/WSL#8840 If not, you could try setting up an Ubuntu VM and do your tests in there. |
got it! will try this after fixing static analysis. |
83850db
to
5282b4a
Compare
Signed-off-by: Aurutus <emslhy@hotmail.com>
Signed-off-by: Aurutus <emslhy@hotmail.com>
5282b4a
to
e58eeb7
Compare
set -e | ||
echo "==> get all-projects operations normally" | ||
result="$(lxc query "/1.0/operations?all-projects=true" | jq '.success[0]' | wc -l)" | ||
test "${result}" -eq 1 || false |
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.
You can drop the || false
.
Since this tests operations of all projects, limiting it to just one doesn't make sense. Instead you should have assert_get_all_operations
take an argument which represents the number of expected operations.
result="$(lxc query "/1.0/operations?recursion=1&all-projects=true" | jq '.success[0]' | grep -c 'status_code')" | ||
test "${result}" -eq 1 || false |
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.
You can drop the || false
.
Same as above, you should pass the expected number of operations as an argument.
( | ||
set -e | ||
echo "==> get all-projects operations normally" | ||
result="$(lxc query "/1.0/operations?all-projects=true" | jq '.success[0]' | wc -l)" |
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.
result="$(lxc query "/1.0/operations?all-projects=true" | jq '.success[0]' | wc -l)" | |
result="$(lxc query "/1.0/operations?all-projects=true" | jq '.success | length')" |
test "${result}" -eq 1 || false | ||
|
||
echo "==> get all-projects operations recursively" | ||
result="$(lxc query "/1.0/operations?recursion=1&all-projects=true" | jq '.success[0]' | grep -c 'status_code')" |
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.
result="$(lxc query "/1.0/operations?recursion=1&all-projects=true" | jq '.success[0]' | grep -c 'status_code')" | |
result="$(lxc query "/1.0/operations?recursion=1&all-projects=true" | jq '[.success[] | select(.status_code)] | length')" |
This will count the number of occurrences of status_code
.
ensure_import_testimage | ||
|
||
# create container | ||
name=x1 | ||
lxc launch testimage ${name} | ||
lxc list ${name} | grep RUNNING | ||
|
||
# get_all_operations | ||
lxc query -X POST -d '{\"command\":[\"touch\",\"/root/foo1\"],\"record-output\":false}' /1.0/instances/${name}/exec | ||
sleep 1 | ||
assert_get_all_operations | ||
|
||
lxc stop "${name}" --force | ||
lxc delete "${name}" |
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 this function you want to test if all operations of all projects are listed. However, you only create an operation in a single project.
Instead, you need to create a second project, and launch a container there as well. Then, you can run the exec commands for both containers, and count the number of operations.
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.
Got it. Will refactor this snippet with above ones later. I try to test these on VM. Too many constraints on my WSL.
lxc list ${name} | grep RUNNING | ||
|
||
# get_all_operations | ||
lxc query -X POST -d '{\"command\":[\"touch\",\"/root/foo1\"],\"record-output\":false}' /1.0/instances/${name}/exec |
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.
lxc query -X POST -d '{\"command\":[\"touch\",\"/root/foo1\"],\"record-output\":false}' /1.0/instances/${name}/exec | |
lxc exec -T --project=<whatever> "${name}" true |
test_operations_get_by_project() { | ||
assert_get_project_operations() { | ||
# $1: query param for project name | ||
( | ||
set -e | ||
echo "==> get $1 operations normally" | ||
result="$(lxc query "/1.0/operations?project=$1" | jq '.success[0]' | wc -l)" | ||
test "${result}" -eq 1 || false | ||
|
||
echo "==> get $1 operations recursively" | ||
result="$(lxc query "/1.0/operations?recursion=1&project=$1" | jq '.success[0]' | grep -c 'status_code')" | ||
test "${result}" -eq 1 || false | ||
) | ||
} | ||
|
||
ensure_import_testimage | ||
|
||
project="default" | ||
|
||
# create container | ||
name=x1 | ||
lxc launch testimage ${name} --project ${project} | ||
lxc list ${name} --project ${project} | grep RUNNING | ||
|
||
# get opetaions with project name | ||
lxc query -X POST -d '{\"command\":[\"touch\",\"/root/foo1\"],\"record-output\":false}' /1.0/instances/${name}/exec?project=${project} | ||
sleep 1 | ||
assert_get_project_operations ${project} | ||
|
||
lxc stop "${name}" --force --project ${project} | ||
lxc delete "${name}" --project ${project} | ||
} |
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.
The same comments as above apply here.
return nil, err | ||
} | ||
|
||
// Turn it into just a list of operations |
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.
Just a small nit, but can you end comments with a full stop? Thanks
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.
Will add this later too. 😄
@AuruTus hi, is this something you're still interested in progressing? Thanks |
sry, a bit busy recently. may have no enough free time to test it. Maybe can close this PR, for the code is really simple. |
@AuruTus Would you mind if I finish this? |
Oh that's great then. thx. |
Add
all-projects
query param support for operationsGet API and update its swagger doc (both1.0/operations
and1.0/operations?recursion=1
).Fix #11808