Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openeuler
avocado
提交
d3a53445
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,发现更多精彩内容 >>
未验证
提交
d3a53445
编写于
4月 18, 2018
作者:
C
Cleber Rosa
浏览文件
操作
浏览文件
下载
差异文件
Merge remote-tracking branch 'abdhaleegit/memutils-blkstring'
Signed-off-by:
N
Cleber Rosa
<
crosa@redhat.com
>
上级
a847f3fd
62bebdd8
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
26 addition
and
10 deletion
+26
-10
avocado/utils/memory.py
avocado/utils/memory.py
+26
-10
未找到文件。
avocado/utils/memory.py
浏览文件 @
d3a53445
...
...
@@ -37,17 +37,31 @@ class MemError(Exception):
pass
def
get_blk_string
(
block
):
"""
Format the given block id to string
:param block: memory block id or block string.
:type string: like 198 or memory198
:return: returns string memory198 if id 198 is given
:rtype: string
"""
if
not
block
.
startswith
(
"memory"
):
return
"memory%s"
%
block
return
block
def
_check_memory_state
(
block
):
"""
Check the given memory block is online or offline
:param block: memory block id.
:type string: like 198
:type string: like 198
or memory198
:return: 'True' if online or 'False' if offline
:rtype: bool
"""
def
_is_online
():
path
=
'/sys/devices/system/memory/
memory%s/state'
%
block
path
=
'/sys/devices/system/memory/
%s/state'
%
get_blk_string
(
block
)
if
genio
.
read_file
(
path
)
==
'online
\n
'
:
return
True
return
False
...
...
@@ -72,11 +86,11 @@ def is_hot_pluggable(block):
Check if the given memory block is hotpluggable
:param block: memory block id.
:type string: like 198
:type string: like 198
or memory198
:return: True if hotpluggable, else False
:rtype: 'bool'
"""
path
=
'/sys/devices/system/memory/
memory%s/removable'
%
block
path
=
'/sys/devices/system/memory/
%s/removable'
%
get_blk_string
(
block
)
return
bool
(
int
(
genio
.
read_file
(
path
)))
...
...
@@ -84,14 +98,15 @@ def hotplug(block):
"""
Online the memory for the given block id.
:param block: memory block id
.
:param block: memory block id
or or memory198
:type string: like 198
"""
with
open
(
'/sys/devices/system/memory/memory%s/state'
%
block
,
'w'
)
as
state_file
:
block
=
get_blk_string
(
block
)
with
open
(
'/sys/devices/system/memory/%s/state'
%
block
,
'w'
)
as
state_file
:
state_file
.
write
(
'online'
)
if
not
_check_memory_state
(
block
):
raise
MemError
(
"unable to hot-plug
memory
%s block, not supported ?"
%
block
)
"unable to hot-plug %s block, not supported ?"
%
block
)
def
hotunplug
(
block
):
...
...
@@ -99,13 +114,14 @@ def hotunplug(block):
Offline the memory for the given block id.
:param block: memory block id.
:type string: like 198
:type string: like 198
or memory198
"""
with
open
(
'/sys/devices/system/memory/memory%s/state'
%
block
,
'w'
)
as
state_file
:
block
=
get_blk_string
(
block
)
with
open
(
'/sys/devices/system/memory/%s/state'
%
block
,
'w'
)
as
state_file
:
state_file
.
write
(
'offline'
)
if
_check_memory_state
(
block
):
raise
MemError
(
"unable to hot-unplug
memory
%s block. Device busy?"
%
block
)
"unable to hot-unplug %s block. Device busy?"
%
block
)
def
read_from_meminfo
(
key
):
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录