Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
L
lxc
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Chen Yisong
lxc
Commits
0e17b9c6
Commit
0e17b9c6
authored
Jan 23, 2014
by
Stéphane Graber
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tests: Rework lxc-test-usernic
Signed-off-by:
Stéphane Graber
<
stgraber@ubuntu.com
>
Acked-by:
Serge E. Hallyn
<
serge.hallyn@ubuntu.com
>
parent
7059802c
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
71 additions
and
59 deletions
+71
-59
lxc-test-usernic
src/tests/lxc-test-usernic
+71
-59
No files found.
src/tests/lxc-test-usernic
View file @
0e17b9c6
...
@@ -21,123 +21,135 @@
...
@@ -21,123 +21,135 @@
# License along with this library; if not, write to the Free Software
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
DONE
=
0
cleanup
()
{
cleanup
()
{
(
set
+e
lxc-stop
-n
usernic-c1
lxc-destroy
-n
usernic-c1
sed
-i
'/usernic-user/d'
/var/run/lxc/nics /etc/lxc/lxc-usernet
sed
-i
'/usernic-user/d'
/var/run/lxc/nics /etc/lxc/lxc-usernet
ifconfig usernic-br0 down
ifconfig usernic-br0 down
ifconfig usernic-br1 down
ifconfig usernic-br1 down
sudo
brctl delbr usernic-br0
brctl delbr usernic-br0
sudo
brctl delbr usernic-br1
brctl delbr usernic-br1
sudo
deluser usernic-user
su
-l
usernic-user
-c
"lxc-stop -P /tmp/usernic-test/lxcbase -n b1"
run_cmd
"lxc-stop -n b1"
rm
-rf
/tmp/usernic-test
pkill
-u
$(
id
-u
usernic-user
)
-9
exit
$1
rm
-rf
/tmp/usernic-test /home/usernic-user /run/user/
$(
id
-u
usernic-user
)
deluser usernic-user
)
>
/dev/null 2>&1
if
[
"
$DONE
"
=
"1"
]
;
then
echo
"PASS"
exit
0
fi
echo
"FAIL"
exit
1
}
run_cmd
()
{
sudo
-i
-u
usernic-user
env
XDG_RUNTIME_DIR
=
/run/user/
$(
id
-u
usernic-user
)
$*
}
}
set
-eu
trap
cleanup EXIT SIGHUP SIGINT SIGTERM
# create a test user
# create a test user
deluser usernic-user
||
true
deluser usernic-user
||
true
useradd usernic-user
useradd usernic-user
sudo mkdir
-p
/home/usernic-user
sudo mkdir
-p
/home/usernic-user
sudo chown
usernic-user /home/usernic-user
sudo chown
usernic-user /home/usernic-user
usermod
-v
910000-919999
-w
910000-919999 usernic-user
usermod
-v
910000-919999
-w
910000-919999 usernic-user
mkdir
-p
/tmp/usernic-test/lxcbase
chown
usernic-user /tmp/usernic-test/lxcbase
uid
=
$(
id
-u
usernic-user
)
cat
>
/home/usernic-user/.bashrc
<<
EOF
export XDG_RUNTIME_DIR=/run/user/
$uid
EOF
XDG_RUNTIME_DIR
=
/run/user/
$uid
export
XDG_RUNTIME_DIR
=
/run/user/
$uid
mkdir
-p
/run/user/
$uid
chown
usernic-user /run/user/
$uid
env
echo
XXX[
su
-l
usernic-user
-c
"env"
sleep
20
#
mkdir
-p
/home/usernic-user/.config/lxc/
cat
>
/
tmp/lxc-usernic
.conf
<<
EOF
cat
>
/
home/usernic-user/.config/lxc/default
.conf
<<
EOF
lxc.network.type = empty
lxc.network.type = empty
lxc.id_map = u 0 91
1
000 10000
lxc.id_map = u 0 91
0
000 10000
lxc.id_map = g 0 91
1
000 10000
lxc.id_map = g 0 91
0
000 10000
EOF
EOF
# Create two test bridges
for
d
in
/sys/fs/cgroup/
*
;
do
[
!
-d
$d
/lxctest
]
&&
mkdir
$d
/lxctest
chown
-R
usernic-user
$d
/lxctest
echo
$$
>
$d
/lxctest/tasks
done
mkdir
-p
/run/user/
$(
id
-u
usernic-user
)
chown
-R
usernic-user /run/user/
$(
id
-u
usernic-user
)
/home/usernic-user
# Create two test bridges
brctl addbr usernic-br0
brctl addbr usernic-br0
brctl addbr usernic-br1
brctl addbr usernic-br1
ifconfig usernic-br0 0.0.0.0 up
ifconfig usernic-br0 0.0.0.0 up
ifconfig usernic-br1 0.0.0.0 up
ifconfig usernic-br1 0.0.0.0 up
LXC_USERNIC_PATH
=
$(
ls
-1
/usr/lib/
*
/lxc/lxc-user-nic |
head
-1
)
# Create three containers
# Create three containers
su
-l
usernic-user
-c
"lxc-create -P /tmp/usernic-test/lxcbase -t busybox -n b1 -f /tmp/lxc-usernic.conf
"
run_cmd
"lxc-create -t download -n b1 -- -d ubuntu -r trusty -a i386
"
su
-l
usernic-user
-c
"lxc-start -P /tmp/usernic-test/lxcbase
-n b1 -d"
run_cmd
"lxc-start
-n b1 -d"
p1
=
`
lxc-info
-P
/tmp/usernic-test/lxcbase
-n
b1
-p
|
awk
-F
:
'{ print $2 }'
`
p1
=
$(
run_cmd
"lxc-info -n b1 -p -H"
)
# Assign one veth, should fail as no allowed entries yet
# Assign one veth, should fail as no allowed entries yet
su
-l
usernic-user
-c
"
$LXC_USERNIC_PATH
$p1
veth usernic-br0 xx1"
if
run_cmd
"lxc-user-nic
$p1
veth usernic-br0 xx1"
;
then
if
[
$?
-eq
0
]
;
then
echo
"FAIL: able to create nic with no entries"
echo
"FAIL: able to create nic with no entries"
cleanup
1
exit
1
fi
fi
# Give him a quota of two
# Give him a quota of two
touch
/etc/lxc/lxc-usernet
touch
/etc/lxc/lxc-usernet
sed
-i
'/^
lxc-usernet
/d'
/etc/lxc/lxc-usernet
sed
-i
'/^
usernic-user
/d'
/etc/lxc/lxc-usernet
echo
"
lxc-usernet
veth usernic-br0 2"
>>
/etc/lxc/lxc-usernet
echo
"
usernic-user
veth usernic-br0 2"
>>
/etc/lxc/lxc-usernet
# Assign one veth to second bridge, should fail
# Assign one veth to second bridge, should fail
su
-l
usernic-user
-c
"
$LXC_USERNIC_PATH
$p1
veth usernic-br1 xx1"
if
run_cmd
"lxc-user-nic
$p1
veth usernic-br1 xx1"
;
then
if
[
$?
-eq
0
]
;
then
echo
"FAIL: able to create nic with no entries"
echo
"FAIL: able to create nic with no entries"
cleanup
1
exit
1
fi
fi
# Assign two veths, should succeed
# Assign two veths, should succeed
su
-l
usernic-user
-c
"
$LXC_USERNIC_PATH
$p1
veth usernic-br0 xx2"
if
!
run_cmd
"lxc-user-nic
$p1
veth usernic-br0 xx2"
;
then
if
[
$?
-ne
0
]
;
then
echo
"FAIL: unable to create first nic"
echo
"FAIL: unable to create first nic"
cleanup
1
exit
1
fi
fi
su
-l
usernic-user
-c
"
$LXC_USERNIC_PATH
$p1
veth usernic-br0 xx3"
if
[
$?
-ne
0
]
;
then
if
!
run_cmd
"lxc-user-nic
$p1
veth usernic-br0 xx3"
;
then
echo
"FAIL: unable to create second nic"
echo
"FAIL: unable to create second nic"
cleanup
1
exit
1
fi
fi
# Assign one more veth, should fail.
# Assign one more veth, should fail.
su
-l
usernic-user
-c
"
$LXC_USERNIC_PATH
$p1
veth usernic-br0 xx4"
if
run_cmd
"lxc-user-nic
$p1
veth usernic-br0 xx4"
;
then
if
[
$?
-eq
0
]
;
then
echo
"FAIL: able to create third nic"
echo
"FAIL: able to create third nic"
cleanup
1
exit
1
fi
fi
# Shut down and restart the container, should be able to assign more nics
# Shut down and restart the container, should be able to assign more nics
su
-l
usernic-user
-c
"lxc-stop -P /tmp/usernic-test/lxcbase
-n b1"
run_cmd
"lxc-stop
-n b1"
su
-l
usernic-user
-c
"lxc-start -P /tmp/usernic-test/lxcbase
-n b1 -d"
run_cmd
"lxc-start
-n b1 -d"
p1
=
`
lxc-info
-P
/tmp/usernic-test/lxcbase
-n
b1
-p
|
awk
-F
:
'{ print $2 }'
`
p1
=
$(
run_cmd
"lxc-info -n b1 -p -H"
)
su
-l
usernic-user
-c
"
$LXC_USERNIC_PATH
$p1
veth usernic-br0 xx5"
if
[
$?
-ne
0
]
;
then
if
!
run_cmd
"lxc-user-nic
$p1
veth usernic-br0 xx5"
;
then
echo
"FAIL: unable to create nic after destroying the old"
echo
"FAIL: unable to create nic after destroying the old"
cleanup 1
cleanup 1
fi
fi
su
-l
usernic-user
-c
"lxc-stop -P /tmp/usernic-test/lxcbase
-n b1"
run_cmd
"lxc-stop
-n b1"
# Create a root-owned ns
# Create a root-owned ns
lxc-create
-t
busybox
-n
usernic-c1
lxc-create
-t
busybox
-n
usernic-c1
lxc-start
-n
usernic-c1
-d
lxc-start
-n
usernic-c1
-d
p2
=
`
lxc-info
-n
usernic-c1
-p
|
awk
-F
:
'{ print $2}'
`
p2
=
$(
lxc-info
-n
usernic-c1
-p
-H
)
# assign veth to it - should fail
# assign veth to it - should fail
su
-l
usernic-user
-c
"
$LXC_USERNIC_PATH
$p2
veth usernic-br0 xx6"
if
run_cmd
"lxc-user-nic
$p2
veth usernic-br0 xx6"
;
then
ret
=
$?
lxc-stop
-n
usernic-c1
lxc-destroy
-n
usernic-c1
if
[
$ret
-eq
0
]
;
then
echo
"FAIL: able to attach nic to root-owned container"
echo
"FAIL: able to attach nic to root-owned container"
cleanup 1
cleanup 1
fi
fi
echo
"All tests passed"
echo
"All tests passed"
DONE
=
1
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment