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
import
os
import
shutil
import
sys
import
tempfile
import
unittest
# pylint: disable=C0411
try
:
...
...
@@ -15,6 +16,7 @@ except ImportError:
from
avocado.utils
import
partition
,
process
from
avocado.utils
import
path
as
utils_path
from
avocado.utils
import
wait
def
missing_binary
(
binary
):
...
...
@@ -77,6 +79,18 @@ class TestPartitionMkfsMount(Base):
super
(
TestPartitionMkfsMount
,
self
).
setUp
()
self
.
disk
.
mkfs
()
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
(
not
process
.
can_sudo
(
'kill -l'
),
...
...
@@ -86,9 +100,7 @@ class TestPartitionMkfsMount(Base):
with
open
(
"/proc/mounts"
)
as
proc_mounts_file
:
proc_mounts
=
proc_mounts_file
.
read
()
self
.
assertIn
(
self
.
mountpoint
,
proc_mounts
)
proc
=
process
.
SubProcess
(
"cd %s; while :; do echo a > a; rm a; done"
%
self
.
mountpoint
,
shell
=
True
)
proc
.
start
()
proc
=
self
.
run_process_to_use_mnt
()
self
.
assertTrue
(
self
.
disk
.
unmount
())
self
.
assertEqual
(
proc
.
poll
(),
-
9
)
# Process should be killed -9
with
open
(
"/proc/mounts"
)
as
proc_mounts_file
:
...
...
@@ -101,9 +113,7 @@ class TestPartitionMkfsMount(Base):
with
open
(
"/proc/mounts"
)
as
proc_mounts_file
:
proc_mounts
=
proc_mounts_file
.
read
()
self
.
assertIn
(
self
.
mountpoint
,
proc_mounts
)
proc
=
process
.
SubProcess
(
"cd %s; while :; do echo a > a; rm a; done"
%
self
.
mountpoint
,
shell
=
True
)
proc
.
start
()
proc
=
self
.
run_process_to_use_mnt
()
self
.
assertRaises
(
partition
.
PartitionError
,
self
.
disk
.
unmount
)
proc
.
terminate
()
proc
.
wait
()
...
...
@@ -113,15 +123,17 @@ class TestPartitionMkfsMount(Base):
with
open
(
"/proc/mounts"
)
as
proc_mounts_file
:
proc_mounts
=
proc_mounts_file
.
read
()
self
.
assertIn
(
self
.
mountpoint
,
proc_mounts
)
proc
=
process
.
SubProcess
(
"cd %s; while :; do echo a > a; rm a; done"
%
self
.
mountpoint
,
shell
=
True
)
proc
.
start
()
proc
=
self
.
run_process_to_use_mnt
()
with
mock
.
patch
(
'avocado.utils.partition.process.run'
,
side_effect
=
process
.
CmdError
):
with
mock
.
patch
(
'avocado.utils.partition.process.system_output'
,
side_effect
=
OSError
)
as
mocked_system_output
:
self
.
assertRaises
(
partition
.
PartitionError
,
self
.
disk
.
unmount
)
mocked_system_output
.
assert_called_with
(
'lsof '
+
self
.
mountpoint
)
# TODO: process.terminate() should be enough, but currently isn't.
# debug the root cause of why the process fails to terminate and the
# test hangs on wait()
self
.
disk
.
unmount
()
proc
.
terminate
()
proc
.
wait
()
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录