1313# limitations under the License.
1414#
1515
16+ from distutils .version import LooseVersion
17+
1618import os
1719import pytest
1820
@@ -29,8 +31,33 @@ def upload_content():
2931
3032
3133@pytest .fixture (scope = 'function' )
32- def uploaded_file (mgmt_root , upload_content ):
33- fake_name = 'foo.txt'
34+ def uploaded_file_madm (mgmt_root , upload_content ):
35+ fake_name = 'fooMadm.txt'
36+ upath = '/var/config/rest/downloads'
37+ dpath = '/var/config/rest/madm'
38+ content = StringIO (upload_content )
39+
40+ ftu = mgmt_root .shared .file_transfer .uploads
41+ ftu .upload_stringio (content , fake_name , chunk_size = 20 )
42+
43+ mgmt_root .tm .util .unix_mv .exec_cmd (
44+ 'run' ,
45+ utilCmdArgs = '{0}/{2} {1}/{2}' .format (upath , dpath , fake_name )
46+ )
47+
48+ yield fake_name
49+ tpath_name = '{0}/{1}' .format (dpath , fake_name )
50+ mgmt_root .tm .util .unix_rm .exec_cmd ('run' , utilCmdArgs = tpath_name )
51+
52+
53+ @pytest .mark .skipif (
54+ LooseVersion (pytest .config .getoption ('--release' )) < LooseVersion (
55+ '13.0.0' ),
56+ reason = 'This fixture requires >= 13.0.0.'
57+ )
58+ @pytest .fixture (scope = 'function' )
59+ def uploaded_file_v13 (mgmt_root , upload_content ):
60+ fake_name = 'foo13.txt'
3461 upath = '/var/config/rest/downloads'
3562 dpath = '/var/config/rest/bulk'
3663 content = StringIO (upload_content )
@@ -47,11 +74,28 @@ def uploaded_file(mgmt_root, upload_content):
4774 mgmt_root .tm .util .unix_rm .exec_cmd ('run' , utilCmdArgs = tpath_name )
4875
4976
50- class TestSoftwareImage (object ):
51- def test_download (self , mgmt_root , uploaded_file , upload_content ):
52- dest = '/tmp/{0}' .format (uploaded_file )
77+ @pytest .mark .skipif (
78+ LooseVersion (pytest .config .getoption ('--release' )) < LooseVersion (
79+ '13.0.0' ),
80+ reason = 'This fixture requires >= 13.0.0.'
81+ )
82+ class TestFileTransferV13 (object ):
83+ def test_download_v13 (self , mgmt_root , uploaded_file_v13 , upload_content ):
84+ dest = '/tmp/{0}' .format (uploaded_file_v13 )
5385 bulk = mgmt_root .shared .file_transfer .bulk
54- bulk .download_file (uploaded_file , dest )
86+ bulk .download_file (uploaded_file_v13 , dest )
87+ assert os .path .exists (dest )
88+
89+ fh = open (dest , 'r' )
90+ content = fh .read ()
91+ assert content == upload_content
92+
93+
94+ class TestMadmFileTransfer (object ):
95+ def test_download (self , mgmt_root , uploaded_file_madm , upload_content ):
96+ dest = '/tmp/{0}' .format (uploaded_file_madm )
97+ madm = mgmt_root .shared .file_transfer .madm
98+ madm .download_file (uploaded_file_madm , dest )
5599 assert os .path .exists (dest )
56100
57101 fh = open (dest , 'r' )
0 commit comments