Skip to content

Commit 3fab44f

Browse files
authored
Merge pull request #1089 from caphrim007/feature.add-madm-downloads
Adds madm download endpoint
2 parents d2775f8 + e5e7ffd commit 3fab44f

2 files changed

Lines changed: 63 additions & 6 deletions

File tree

f5/bigip/shared/file_transfer.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ def __init__(self, shared):
3434
super(File_Transfer, self).__init__(shared)
3535
self._meta_data['allowed_lazy_attributes'] = [
3636
Bulk,
37+
Madm,
3738
Uploads
3839
]
3940

@@ -63,6 +64,18 @@ class Bulk(PathElement, FileUploadMixin, FileDownloadMixin):
6364
"""A file upload resource."""
6465
def __init__(self, file_transfer):
6566
super(Bulk, self).__init__(file_transfer)
67+
self._meta_data['minimum_version'] = '13.0.0'
68+
69+
def download_file(self, src, dest, **kwargs):
70+
filename = os.path.basename(src)
71+
self.file_bound_uri = self._meta_data['uri'] + filename
72+
self._download_file(src, dest, **kwargs)
73+
74+
75+
class Madm(PathElement, FileDownloadMixin):
76+
"""A file upload resource."""
77+
def __init__(self, file_transfer):
78+
super(Madm, self).__init__(file_transfer)
6679

6780
def download_file(self, src, dest, **kwargs):
6881
filename = os.path.basename(src)

f5/bigip/shared/test/functional/test_file_transfer.py

Lines changed: 50 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
# limitations under the License.
1414
#
1515

16+
from distutils.version import LooseVersion
17+
1618
import os
1719
import 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

Comments
 (0)