Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openeuler
avocado
提交
830e0c86
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,发现更多精彩内容 >>
未验证
提交
830e0c86
编写于
10月 08, 2018
作者:
C
Cleber Rosa
浏览文件
操作
浏览文件
下载
差异文件
Merge remote-tracking branch 'cacarrara/opensuse-vmimage-provider'
Signed-off-by:
N
Cleber Rosa
<
crosa@redhat.com
>
上级
ea3f2823
37e7a3ea
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
87 addition
and
2 deletion
+87
-2
avocado/utils/vmimage.py
avocado/utils/vmimage.py
+37
-2
selftests/unit/test_utils_vmimage.py
selftests/unit/test_utils_vmimage.py
+50
-0
未找到文件。
avocado/utils/vmimage.py
浏览文件 @
830e0c86
...
...
@@ -83,6 +83,10 @@ class ImageProviderBase(object):
def
version
(
self
):
return
self
.
_best_version
or
self
.
get_version
()
@
property
def
version_pattern
(
self
):
return
'^%s/$'
%
self
.
_version
def
_feed_html_parser
(
self
,
url
,
parser
):
try
:
data
=
urlopen
(
url
).
read
()
...
...
@@ -97,8 +101,7 @@ class ImageProviderBase(object):
"""
Probes the higher version available for the current parameters.
"""
pattern
=
'^%s/$'
%
self
.
_version
parser
=
VMImageHtmlParser
(
pattern
)
parser
=
VMImageHtmlParser
(
self
.
version_pattern
)
self
.
_feed_html_parser
(
self
.
url_versions
,
parser
)
...
...
@@ -275,6 +278,38 @@ class JeosImageProvider(ImageProviderBase):
self
.
image_pattern
=
'jeos-{version}-{arch}.qcow2.xz$'
class
OpenSUSEImageProvider
(
ImageProviderBase
):
"""
OpenSUSE Image Provider
"""
HTML_ENCODING
=
'iso-8859-1'
name
=
'OpenSUSE'
def
__init__
(
self
,
version
=
'[0-9]{2}.[0-9]{1}'
,
build
=
None
,
arch
=
os
.
uname
()[
4
]):
super
(
OpenSUSEImageProvider
,
self
).
__init__
(
version
,
build
,
arch
)
self
.
url_versions
=
'https://download.opensuse.org/repositories/Cloud:/Images:/'
self
.
url_images
=
self
.
url_versions
+
'Leap_{version}/images/'
if
not
build
:
self
.
image_pattern
=
'openSUSE-Leap-{version}-OpenStack.{arch}-((.)*).qcow2$'
else
:
self
.
image_pattern
=
'openSUSE-Leap-{version}-OpenStack.{arch}-{build}.qcow2$'
@
property
def
version_pattern
(
self
):
return
'^Leap_%s'
%
self
.
_version
def
get_best_version
(
self
,
versions
):
# versions pattern equals Leap_15.0, Leap_42.0, Leap_XY.Z
version_numbers
=
[
float
(
v
.
split
(
'_'
)[
1
])
for
v
in
versions
]
if
self
.
_version
.
startswith
(
'4'
):
version_numbers
=
[
v
for
v
in
version_numbers
if
v
>=
40.0
]
else
:
version_numbers
=
[
v
for
v
in
version_numbers
if
v
<
40.0
]
return
max
(
version_numbers
)
class
Image
(
object
):
def
__init__
(
self
,
name
,
url
,
version
,
arch
,
checksum
,
algorithm
,
cache_dir
,
snapshot_dir
=
None
):
...
...
selftests/unit/test_utils_vmimage.py
浏览文件 @
830e0c86
...
...
@@ -113,5 +113,55 @@ class ImageProviderBase(unittest.TestCase):
self
.
assertIn
(
'attributes are required to get image url'
,
exc
.
exception
.
args
[
0
])
class
OpenSUSEImageProvider
(
unittest
.
TestCase
):
def
setUp
(
self
):
self
.
suse_available_versions
=
[
'Leap_15.0'
,
'Leap_42.1'
,
'Leap_42.2'
,
'Leap_42.3'
]
self
.
base_images_url
=
'https://download.opensuse.org/repositories/Cloud:/Images:/Leap_15.0/images/'
@
staticmethod
def
get_html_with_image_link
(
image_link
):
return
'''
<a href="openSUSE-Leap-15.0-OpenStack.x86_64-0.0.4-Buildlp150.12.30.packages"></a>
<a href="%s"></a>
<a href="openSUSE-Leap-15.0-OpenStack.x86_64-0.0.4-Buildlp150.12.30.qcow2.sha256"></a>
'''
%
image_link
def
test_get_best_version_default
(
self
):
suse_latest_version
=
15.0
suse_provider
=
vmimage
.
OpenSUSEImageProvider
()
self
.
assertEqual
(
suse_provider
.
get_best_version
(
self
.
suse_available_versions
),
suse_latest_version
)
def
test_get_best_version_leap_4_series
(
self
):
suse_latest_version
=
42.3
suse_provider
=
vmimage
.
OpenSUSEImageProvider
(
version
=
'4(.)*'
)
self
.
assertEqual
(
suse_provider
.
get_best_version
(
self
.
suse_available_versions
),
suse_latest_version
)
@
mock
.
patch
(
'avocado.utils.vmimage.urlopen'
)
def
test_get_image_url
(
self
,
urlopen_mock
):
image
=
'openSUSE-Leap-15.0-OpenStack.x86_64-0.0.4-Buildlp150.12.30.qcow2'
html_fixture
=
self
.
get_html_with_image_link
(
image
)
urlread_mocked
=
mock
.
Mock
(
return_value
=
html_fixture
)
urlopen_mock
.
return_value
=
mock
.
Mock
(
read
=
urlread_mocked
)
expected_image_url
=
self
.
base_images_url
+
image
suse_provider
=
vmimage
.
OpenSUSEImageProvider
()
suse_provider
.
get_version
=
mock
.
Mock
(
return_value
=
'15.0'
)
self
.
assertEqual
(
suse_provider
.
get_image_url
(),
expected_image_url
)
@
mock
.
patch
(
'avocado.utils.vmimage.urlopen'
)
def
test_get_image_url_defining_build
(
self
,
urlopen_mock
):
image
=
'openSUSE-Leap-15.0-OpenStack.x86_64-1.1.1-Buildlp111.11.11.qcow2'
html_fixture
=
self
.
get_html_with_image_link
(
image
)
urlread_mocked
=
mock
.
Mock
(
return_value
=
html_fixture
)
urlopen_mock
.
return_value
=
mock
.
Mock
(
read
=
urlread_mocked
)
expected_image_url
=
self
.
base_images_url
+
image
suse_provider
=
vmimage
.
OpenSUSEImageProvider
(
build
=
'1.1.1-Buildlp111.11.11'
)
suse_provider
.
get_version
=
mock
.
Mock
(
return_value
=
'15.0'
)
self
.
assertEqual
(
suse_provider
.
get_image_url
(),
expected_image_url
)
if
__name__
==
'__main__'
:
unittest
.
main
()
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录