Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openeuler
avocado
提交
104f19ad
A
avocado
项目概览
openeuler
/
avocado
通知
0
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
A
avocado
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
104f19ad
编写于
12月 04, 2018
作者:
C
Caio Carrara
浏览文件
操作
浏览文件
下载
差异文件
Merge remote-tracking branch 'clebergnu/partition_selftests'
Signed-off-by:
N
Caio Carrara
<
ccarrara@redhat.com
>
上级
fed4467c
dc235673
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
49 addition
and
37 deletion
+49
-37
selftests/unit/test_utils_partition.py
selftests/unit/test_utils_partition.py
+49
-37
未找到文件。
selftests/unit/test_utils_partition.py
浏览文件 @
104f19ad
...
@@ -6,6 +6,7 @@ avocado.utils.partition unittests
...
@@ -6,6 +6,7 @@ avocado.utils.partition unittests
import
os
import
os
import
shutil
import
shutil
import
sys
import
tempfile
import
tempfile
import
unittest
# pylint: disable=C0411
import
unittest
# pylint: disable=C0411
try
:
try
:
...
@@ -15,6 +16,7 @@ except ImportError:
...
@@ -15,6 +16,7 @@ except ImportError:
from
avocado.utils
import
partition
,
process
from
avocado.utils
import
partition
,
process
from
avocado.utils
import
path
as
utils_path
from
avocado.utils
import
path
as
utils_path
from
avocado.utils
import
wait
def
missing_binary
(
binary
):
def
missing_binary
(
binary
):
...
@@ -59,12 +61,12 @@ class TestPartition(Base):
...
@@ -59,12 +61,12 @@ class TestPartition(Base):
self
.
disk
.
mount
()
self
.
disk
.
mount
()
with
open
(
"/proc/mounts"
)
as
proc_mounts_file
:
with
open
(
"/proc/mounts"
)
as
proc_mounts_file
:
proc_mounts
=
proc_mounts_file
.
read
()
proc_mounts
=
proc_mounts_file
.
read
()
self
.
assertIn
(
self
.
mountpoint
,
proc_mounts
)
self
.
assertIn
(
self
.
mountpoint
,
proc_mounts
)
self
.
assertEqual
(
self
.
mountpoint
,
self
.
disk
.
get_mountpoint
())
self
.
assertEqual
(
self
.
mountpoint
,
self
.
disk
.
get_mountpoint
())
self
.
disk
.
unmount
()
self
.
disk
.
unmount
()
with
open
(
"/proc/mounts"
)
as
proc_mounts_file
:
with
open
(
"/proc/mounts"
)
as
proc_mounts_file
:
proc_mounts
=
proc_mounts_file
.
read
()
proc_mounts
=
proc_mounts_file
.
read
()
self
.
assertNotIn
(
self
.
mountpoint
,
proc_mounts
)
self
.
assertNotIn
(
self
.
mountpoint
,
proc_mounts
)
class
TestPartitionMkfsMount
(
Base
):
class
TestPartitionMkfsMount
(
Base
):
...
@@ -77,6 +79,18 @@ class TestPartitionMkfsMount(Base):
...
@@ -77,6 +79,18 @@ class TestPartitionMkfsMount(Base):
super
(
TestPartitionMkfsMount
,
self
).
setUp
()
super
(
TestPartitionMkfsMount
,
self
).
setUp
()
self
.
disk
.
mkfs
()
self
.
disk
.
mkfs
()
self
.
disk
.
mount
()
self
.
disk
.
mount
()
self
.
use_mnt_file
=
os
.
path
.
join
(
self
.
mountpoint
,
'file'
)
self
.
use_mnt_cmd
=
(
"%s -c 'import time; f = open(
\"
%s
\"
,
\"
w
\"
); "
"time.sleep(60)'"
%
(
sys
.
executable
,
self
.
use_mnt_file
))
def
run_process_to_use_mnt
(
self
):
proc
=
process
.
SubProcess
(
self
.
use_mnt_cmd
)
proc
.
start
()
self
.
assertTrue
(
wait
.
wait_for
(
lambda
:
os
.
path
.
exists
(
self
.
use_mnt_file
),
timeout
=
1
,
first
=
0.1
,
step
=
0.1
),
"File was not created within mountpoint"
)
return
proc
@
unittest
.
skipIf
(
missing_binary
(
'lsof'
),
"requires running lsof"
)
@
unittest
.
skipIf
(
missing_binary
(
'lsof'
),
"requires running lsof"
)
@
unittest
.
skipIf
(
not
process
.
can_sudo
(
'kill -l'
),
@
unittest
.
skipIf
(
not
process
.
can_sudo
(
'kill -l'
),
...
@@ -85,73 +99,71 @@ class TestPartitionMkfsMount(Base):
...
@@ -85,73 +99,71 @@ class TestPartitionMkfsMount(Base):
""" Test force-unmount feature """
""" Test force-unmount feature """
with
open
(
"/proc/mounts"
)
as
proc_mounts_file
:
with
open
(
"/proc/mounts"
)
as
proc_mounts_file
:
proc_mounts
=
proc_mounts_file
.
read
()
proc_mounts
=
proc_mounts_file
.
read
()
self
.
assertIn
(
self
.
mountpoint
,
proc_mounts
)
self
.
assertIn
(
self
.
mountpoint
,
proc_mounts
)
proc
=
process
.
SubProcess
(
"cd %s; while :; do echo a > a; rm a; done"
proc
=
self
.
run_process_to_use_mnt
()
%
self
.
mountpoint
,
shell
=
True
)
self
.
assertTrue
(
self
.
disk
.
unmount
())
proc
.
start
()
self
.
assertEqual
(
proc
.
poll
(),
-
9
)
# Process should be killed -9
self
.
assertTrue
(
self
.
disk
.
unmount
())
self
.
assertEqual
(
proc
.
poll
(),
-
9
)
# Process should be killed -9
with
open
(
"/proc/mounts"
)
as
proc_mounts_file
:
with
open
(
"/proc/mounts"
)
as
proc_mounts_file
:
proc_mounts
=
proc_mounts_file
.
read
()
proc_mounts
=
proc_mounts_file
.
read
()
self
.
assertNotIn
(
self
.
mountpoint
,
proc_mounts
)
self
.
assertNotIn
(
self
.
mountpoint
,
proc_mounts
)
@
unittest
.
skipUnless
(
missing_binary
(
'lsof'
),
"requires not having lsof"
)
@
unittest
.
skipUnless
(
missing_binary
(
'lsof'
),
"requires not having lsof"
)
def
test_force_unmount_no_lsof
(
self
):
def
test_force_unmount_no_lsof
(
self
):
""" Checks that a force-unmount will fail on systems without lsof """
""" Checks that a force-unmount will fail on systems without lsof """
with
open
(
"/proc/mounts"
)
as
proc_mounts_file
:
with
open
(
"/proc/mounts"
)
as
proc_mounts_file
:
proc_mounts
=
proc_mounts_file
.
read
()
proc_mounts
=
proc_mounts_file
.
read
()
self
.
assertIn
(
self
.
mountpoint
,
proc_mounts
)
self
.
assertIn
(
self
.
mountpoint
,
proc_mounts
)
proc
=
process
.
SubProcess
(
"cd %s; while :; do echo a > a; rm a; done"
proc
=
self
.
run_process_to_use_mnt
()
%
self
.
mountpoint
,
shell
=
True
)
self
.
assertRaises
(
partition
.
PartitionError
,
self
.
disk
.
unmount
)
proc
.
start
()
proc
.
terminate
()
self
.
assertRaises
(
partition
.
PartitionError
,
self
.
disk
.
unmount
)
proc
.
wait
()
proc
.
terminate
()
proc
.
wait
()
def
test_force_unmount_get_pids_fail
(
self
):
def
test_force_unmount_get_pids_fail
(
self
):
""" Checks PartitionError is raised if there's no lsof to get pids """
""" Checks PartitionError is raised if there's no lsof to get pids """
with
open
(
"/proc/mounts"
)
as
proc_mounts_file
:
with
open
(
"/proc/mounts"
)
as
proc_mounts_file
:
proc_mounts
=
proc_mounts_file
.
read
()
proc_mounts
=
proc_mounts_file
.
read
()
self
.
assertIn
(
self
.
mountpoint
,
proc_mounts
)
self
.
assertIn
(
self
.
mountpoint
,
proc_mounts
)
proc
=
process
.
SubProcess
(
"cd %s; while :; do echo a > a; rm a; done"
proc
=
self
.
run_process_to_use_mnt
()
%
self
.
mountpoint
,
shell
=
True
)
with
mock
.
patch
(
'avocado.utils.partition.process.run'
,
proc
.
start
()
side_effect
=
process
.
CmdError
):
with
mock
.
patch
(
'avocado.utils.partition.process.run'
,
with
mock
.
patch
(
'avocado.utils.partition.process.system_output'
,
side_effect
=
process
.
CmdError
):
side_effect
=
OSError
)
as
mocked_system_output
:
with
mock
.
patch
(
'avocado.utils.partition.process.system_output'
,
self
.
assertRaises
(
partition
.
PartitionError
,
self
.
disk
.
unmount
)
side_effect
=
OSError
)
as
mocked_system_output
:
mocked_system_output
.
assert_called_with
(
'lsof '
+
self
.
mountpoint
)
self
.
assertRaises
(
partition
.
PartitionError
,
self
.
disk
.
unmount
)
# TODO: process.terminate() should be enough, but currently isn't.
mocked_system_output
.
assert_called_with
(
'lsof '
+
self
.
mountpoint
)
# debug the root cause of why the process fails to terminate and the
proc
.
terminate
()
# test hangs on wait()
proc
.
wait
()
self
.
disk
.
unmount
()
proc
.
terminate
()
proc
.
wait
()
def
test_double_mount
(
self
):
def
test_double_mount
(
self
):
""" Check the attempt for second mount fails """
""" Check the attempt for second mount fails """
with
open
(
"/proc/mounts"
)
as
proc_mounts_file
:
with
open
(
"/proc/mounts"
)
as
proc_mounts_file
:
proc_mounts
=
proc_mounts_file
.
read
()
proc_mounts
=
proc_mounts_file
.
read
()
self
.
assertIn
(
self
.
mountpoint
,
proc_mounts
)
self
.
assertIn
(
self
.
mountpoint
,
proc_mounts
)
self
.
assertRaises
(
partition
.
PartitionError
,
self
.
disk
.
mount
)
self
.
assertRaises
(
partition
.
PartitionError
,
self
.
disk
.
mount
)
self
.
assertIn
(
self
.
mountpoint
,
proc_mounts
)
self
.
assertIn
(
self
.
mountpoint
,
proc_mounts
)
def
test_double_umount
(
self
):
def
test_double_umount
(
self
):
""" Check double unmount works well """
""" Check double unmount works well """
with
open
(
"/proc/mounts"
)
as
proc_mounts_file
:
with
open
(
"/proc/mounts"
)
as
proc_mounts_file
:
proc_mounts
=
proc_mounts_file
.
read
()
proc_mounts
=
proc_mounts_file
.
read
()
self
.
assertIn
(
self
.
mountpoint
,
proc_mounts
)
self
.
assertIn
(
self
.
mountpoint
,
proc_mounts
)
self
.
disk
.
unmount
()
self
.
disk
.
unmount
()
with
open
(
"/proc/mounts"
)
as
proc_mounts_file
:
with
open
(
"/proc/mounts"
)
as
proc_mounts_file
:
proc_mounts
=
proc_mounts_file
.
read
()
proc_mounts
=
proc_mounts_file
.
read
()
self
.
assertNotIn
(
self
.
mountpoint
,
proc_mounts
)
self
.
assertNotIn
(
self
.
mountpoint
,
proc_mounts
)
self
.
disk
.
unmount
()
self
.
disk
.
unmount
()
with
open
(
"/proc/mounts"
)
as
proc_mounts_file
:
with
open
(
"/proc/mounts"
)
as
proc_mounts_file
:
proc_mounts
=
proc_mounts_file
.
read
()
proc_mounts
=
proc_mounts_file
.
read
()
self
.
assertNotIn
(
self
.
mountpoint
,
proc_mounts
)
self
.
assertNotIn
(
self
.
mountpoint
,
proc_mounts
)
def
test_format_mounted
(
self
):
def
test_format_mounted
(
self
):
""" Check format on mounted device fails """
""" Check format on mounted device fails """
with
open
(
"/proc/mounts"
)
as
proc_mounts_file
:
with
open
(
"/proc/mounts"
)
as
proc_mounts_file
:
proc_mounts
=
proc_mounts_file
.
read
()
proc_mounts
=
proc_mounts_file
.
read
()
self
.
assertIn
(
self
.
mountpoint
,
proc_mounts
)
self
.
assertIn
(
self
.
mountpoint
,
proc_mounts
)
self
.
assertRaises
(
partition
.
PartitionError
,
self
.
disk
.
mkfs
)
self
.
assertRaises
(
partition
.
PartitionError
,
self
.
disk
.
mkfs
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录