Skip to content

add test cases for exec command#1133

Merged
cyphar merged 1 commit into
opencontainers:masterfrom
datawolf:add-integration-test-for-exec
Nov 4, 2016
Merged

add test cases for exec command#1133
cyphar merged 1 commit into
opencontainers:masterfrom
datawolf:add-integration-test-for-exec

Conversation

@datawolf
Copy link
Copy Markdown
Contributor

This patch add test --cwd, --env, --user option for exec command.

Signed-off-by: Wang Long long.wanglong@huawei.com

Comment thread tests/integration/exec.bats Outdated

wait_for_container 15 1 test_busybox

runc exec --cwd /bin test_busybox ls -la
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why not make this test use /bin/pwd instead -- so we can actually check that --cwd does what it says?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

ok, good idea.

update done.


wait_for_container 15 1 test_busybox

runc exec --user 1000:1000 test_busybox id
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I kinda want to also add a test for --user username:groupname. Busybox contains a passwd file:

root:x:0:0:root:/root:/bin/ash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
adm:x:3:4:adm:/var/adm:/sbin/nologin
lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
sync:x:5:0:sync:/sbin:/bin/sync
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
halt:x:7:0:halt:/sbin:/sbin/halt
mail:x:8:12:mail:/var/spool/mail:/sbin/nologin
news:x:9:13:news:/usr/lib/news:/sbin/nologin
uucp:x:10:14:uucp:/var/spool/uucppublic:/sbin/nologin
operator:x:11:0:operator:/root:/bin/sh
man:x:13:15:man:/usr/man:/sbin/nologin
postmaster:x:14:12:postmaster:/var/spool/mail:/sbin/nologin
cron:x:16:16:cron:/var/spool/cron:/sbin/nologin
ftp:x:21:21::/var/lib/ftp:/sbin/nologin
sshd:x:22:22:sshd:/dev/null:/sbin/nologin
at:x:25:25:at:/var/spool/cron/atjobs:/sbin/nologin
squid:x:31:31:Squid:/var/cache/squid:/sbin/nologin
xfs:x:33:33:X Font Server:/etc/X11/fs:/sbin/nologin
games:x:35:35:games:/usr/games:/sbin/nologin
postgres:x:70:70::/var/lib/postgresql:/bin/sh
nut:x:84:84:nut:/var/state/nut:/sbin/nologin
cyrus:x:85:12::/usr/cyrus:/sbin/nologin
vpopmail:x:89:89::/var/vpopmail:/sbin/nologin
ntp:x:123:123:NTP:/var/empty:/sbin/nologin
smmsp:x:209:209:smmsp:/var/spool/mqueue:/sbin/nologin
guest:x:405:100:guest:/dev/null:/sbin/nologin
nobody:x:65534:65534:nobody:/:/sbin/nologin

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

but the current implementation of runc exec command only support --user value, -u value UID(format:<uid>[:gid])

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

That's right, I completely forgot that libcontainer/user isn't actually used by us "properly".

@cyphar
Copy link
Copy Markdown
Member

cyphar commented Oct 20, 2016

In future, if you're going to create a series of "add test case" patch sets or something like that, feel free to group them in a single PR. Please take a look at my nits.

@datawolf datawolf force-pushed the add-integration-test-for-exec branch from 5be97af to 72b1f8a Compare October 20, 2016 09:15
@datawolf
Copy link
Copy Markdown
Contributor Author

In future, if you're going to create a series of "add test case" patch sets or something like that, feel free to group them in a single PR. Please take a look at my nits.

@cyphar , got it, thanks.

Comment thread tests/integration/exec.bats Outdated
runc exec --cwd /bin test_busybox pwd
[ "$status" -eq 0 ]

[[ ${output} == *"/bin"* ]]
Copy link
Copy Markdown
Member

@cyphar cyphar Oct 20, 2016

Choose a reason for hiding this comment

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

My main concern with this is that

% [[ "a" == *"a"* ]]; echo $?
0
% [[ "ab" == *"a"* ]]; echo $?
0

Can't we do something like:

[[ $(echo "${output}" | tr -d ' \n') == "/bin" ]]

Though there's probably a simpler way of doing it than that.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Actually you can just do [[ ${line[0]} == "/bin" ]]

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

thanks for your review.

but [[ $(echo "${output}" | tr -d ' \n') == "/bin" ]] and [[ ${lines[0]} == "/bin" ]] do not works. the same as [[ ${output} == "/bin" ]].

and I write a simple test bats scripts, it test ok

#!/usr/bin/env bats

@test "pwd test" {
   run runc exec --cwd /bin test_busybox pwd
   [[ ${output} == "/bin" ]]
}

So I don't know why they all do not work in tests/integration/*.bats?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@cyphar do you have any ideas?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@datawolf [[ $(echo "${output}" | tr -d '\r') == "/bin" ]] will work.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

thanks @hqhq . why the output has a '\r' at the end? If we have no way to delete this character. A simpler way of doing it may be:

[[ ${output} == $(echo -e "/bin\r") ]]

Update patch done.

Copy link
Copy Markdown
Member

@cyphar cyphar Oct 24, 2016

Choose a reason for hiding this comment

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

It also happens with other commands! What!

% sudo ./runc exec test echo lol | cat -v
lol^M

And it happens with the container cmd set to echo lol!

% sudo ./runc run test | cat -v
lol^M

.. wat.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@datawolf

If we have no way to delete this character. A simpler way of doing it may be:

I prefer using `tr -d '\r'. Or just using the variable regex replacement used in the linked bats issue.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

update done. @cyphar

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I've opened #1145 to track this. I have no clue what's going on, but I have a suspicion it's related to creating ptys...

@datawolf datawolf force-pushed the add-integration-test-for-exec branch 4 times, most recently from c22a5ec to 6b2c2b7 Compare October 24, 2016 09:41
@cyphar
Copy link
Copy Markdown
Member

cyphar commented Oct 24, 2016

My testing shows that #1146 fixes the issue with \r.

@datawolf
Copy link
Copy Markdown
Contributor Author

OK, after #1146 merged, I will update this pr.

@datawolf datawolf force-pushed the add-integration-test-for-exec branch 3 times, most recently from 557339f to 48bed6f Compare November 1, 2016 08:32
@datawolf datawolf force-pushed the add-integration-test-for-exec branch from 48bed6f to 9af2668 Compare November 4, 2016 01:45
@datawolf
Copy link
Copy Markdown
Contributor Author

datawolf commented Nov 4, 2016

As the #1146 has been merged. I update this pr and rebased.

@hqhq
Copy link
Copy Markdown
Contributor

hqhq commented Nov 4, 2016

I don't see the updates, you are still tr -d '\r'.

This patch add test `--cwd`, `--env`, `--user` option for exec command.

Signed-off-by: Wang Long <long.wanglong@huawei.com>
@datawolf datawolf force-pushed the add-integration-test-for-exec branch from 9af2668 to d5525cc Compare November 4, 2016 06:16
@datawolf
Copy link
Copy Markdown
Contributor Author

datawolf commented Nov 4, 2016

@hqhq, Sorry for that. I just forgot to git add the update. Now is updated

@hqhq
Copy link
Copy Markdown
Contributor

hqhq commented Nov 4, 2016

LGTM

Approved with PullApprove

1 similar comment
@cyphar
Copy link
Copy Markdown
Member

cyphar commented Nov 4, 2016

LGTM

Approved with PullApprove

@cyphar cyphar merged commit d5525cc into opencontainers:master Nov 4, 2016
cyphar added a commit that referenced this pull request Nov 4, 2016
@datawolf datawolf deleted the add-integration-test-for-exec branch November 8, 2016 01:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants