Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openeuler
avocado
提交
0a62d937
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,发现更多精彩内容 >>
未验证
提交
0a62d937
编写于
10月 19, 2016
作者:
C
Cleber Rosa
浏览文件
操作
浏览文件
下载
差异文件
Merge remote-tracking branch 'ldoktor/test_utils_partition4'
上级
7d461155
62ba96e5
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
22 addition
and
21 deletion
+22
-21
avocado/utils/process.py
avocado/utils/process.py
+11
-3
selftests/functional/test_lv_utils.py
selftests/functional/test_lv_utils.py
+2
-0
selftests/unit/test_utils_iso9660.py
selftests/unit/test_utils_iso9660.py
+3
-3
selftests/unit/test_utils_partition.py
selftests/unit/test_utils_partition.py
+6
-15
未找到文件。
avocado/utils/process.py
浏览文件 @
0a62d937
...
...
@@ -99,12 +99,20 @@ class CmdError(Exception):
return
"CmdError"
def
can_sudo
():
def
can_sudo
(
cmd
=
None
):
"""
:return: True when sudo is available (or i
s root)
Check whether sudo is available (or running a
s root)
"""
if
os
.
getuid
()
==
0
:
if
os
.
getuid
()
==
0
:
# Root
return
True
try
:
# Does sudo binary exists?
path
.
find_command
(
'sudo'
)
except
path
.
CmdNotFoundError
:
return
False
if
cmd
:
# Am I able to run the cmd or plain sudo id?
return
not
system
(
cmd
,
ignore_status
=
True
,
sudo
=
True
)
elif
system_output
(
"id -u"
,
ignore_status
=
True
,
sudo
=
True
).
strip
()
==
"0"
:
return
True
else
:
...
...
selftests/functional/test_lv_utils.py
浏览文件 @
0a62d937
...
...
@@ -26,6 +26,8 @@ class LVUtilsTest(unittest.TestCase):
@
unittest
.
skipIf
(
process
.
system
(
"which vgs"
,
ignore_status
=
True
),
"LVM utils not installed (command vgs is missing)"
)
@
unittest
.
skipIf
(
not
process
.
can_sudo
(),
"This test requires root or "
"passwordless sudo configured."
)
def
setUp
(
self
):
try
:
process
.
system
(
"/bin/true"
,
sudo
=
True
)
...
...
selftests/unit/test_utils_iso9660.py
浏览文件 @
0a62d937
...
...
@@ -43,8 +43,8 @@ class BaseIso9660(unittest.TestCase):
self
.
iso
.
close
()
self
.
iso
.
close
()
# check that double-close won't fail
@
unittest
.
skipIf
(
not
process
.
can_sudo
(),
"This test requires sudo or root"
)
@
unittest
.
skipIf
(
not
process
.
can_sudo
(
"mount"
),
"This test requires
mount to run under
sudo or root"
)
def
mnt_dir_workflow
(
self
):
"""
Check the mnt_dir functionality
...
...
@@ -116,7 +116,7 @@ class IsoMount(BaseIso9660):
Mount-based check
"""
@
unittest
.
skipIf
(
not
process
.
can_sudo
(),
@
unittest
.
skipIf
(
not
process
.
can_sudo
(
"mount"
),
"This test requires sudo or root"
)
def
setUp
(
self
):
super
(
IsoMount
,
self
).
setUp
()
...
...
selftests/unit/test_utils_partition.py
浏览文件 @
0a62d937
...
...
@@ -29,28 +29,17 @@ def missing_binary(binary):
return
True
def
cannot_sudo
(
command
):
try
:
process
.
run
(
command
,
sudo
=
True
)
False
except
(
process
.
CmdError
,
OSError
):
return
True
class
TestPartition
(
unittest
.
TestCase
):
"""
Unit tests for avocado.utils.partition
"""
@
unittest
.
skipIf
(
missing_binary
(
'mkfs.ext2'
),
"mkfs.ext2 is required for these tests to run."
)
@
unittest
.
skipIf
(
missing_binary
(
'sudo'
),
"sudo is required for these tests to run."
)
@
unittest
.
skipIf
(
cannot_sudo
(
'mount'
),
@
unittest
.
skipIf
(
not
process
.
can_sudo
(
'mount'
),
'current user must be allowed to run "mount" under sudo'
)
@
unittest
.
skipIf
(
cannot_sudo
(
'mkfs.ext2 -V'
),
'current user must be allowed to run "mkfs.ext2" under sudo'
)
@
unittest
.
skipIf
(
not
process
.
can_sudo
(
'mkfs.ext2 -V'
),
'current user must be allowed to run "mkfs.ext2" under '
'sudo'
)
def
setUp
(
self
):
self
.
tmpdir
=
tempfile
.
mkdtemp
(
prefix
=
"avocado_"
+
__name__
)
self
.
mountpoint
=
os
.
path
.
join
(
self
.
tmpdir
,
"disk"
)
...
...
@@ -68,6 +57,8 @@ class TestPartition(unittest.TestCase):
self
.
disk
.
unmount
()
self
.
assertNotIn
(
self
.
mountpoint
,
open
(
"/proc/mounts"
).
read
())
@
unittest
.
skipIf
(
not
process
.
can_sudo
(
'kill -l'
),
"requires running kill as a privileged user"
)
def
test_force_unmount
(
self
):
""" Test force-unmount feature """
self
.
disk
.
mkfs
()
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录