Skip to content

Commit

Permalink
Fixing sanity tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Valentin Yonev committed Oct 3, 2023
1 parent 615ac28 commit f91f5be
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions plugins/modules/vmware_content_library_item_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,12 @@
}
'''

from ansible.module_utils.basic import AnsibleModule
import traceback

from ansible.module_utils.basic import AnsibleModule, missing_required_lib
from ansible_collections.community.vmware.plugins.module_utils.vmware_rest_client import VmwareRestClient

VAUTOMATION_PYTHON_SDK_IMP_ERR = None
HAS_VAUTOMATION_PYTHON_SDK = False
try:
from com.vmware.content.library.item_client import DownloadSessionModel
Expand All @@ -72,6 +75,7 @@

import requests
except ImportError:
VAUTOMATION_PYTHON_SDK_IMP_ERR = traceback.format_exc()
pass

import uuid
Expand All @@ -91,6 +95,11 @@ def download(self):
"""
downloaded_files_map = {}
try:
if not HAS_VAUTOMATION_PYTHON_SDK:
self.module.fail_json(
msg=missing_required_lib('com.vmware'),
exception=VAUTOMATION_PYTHON_SDK_IMP_ERR)

download_session_id = self.content_service.content.library.item.DownloadSession.create(
create_spec=DownloadSessionModel(library_item_id=self.get_item_id()),
client_token=str(uuid.uuid4()))
Expand Down Expand Up @@ -140,13 +149,16 @@ def get_item_id(self):
return content_lib_item_ids[0]

def wait_for_prepare(self, session_id, file_name,
status_list=(DownloadSessionFile.PrepareStatus.PREPARED,),
status_list,
timeout=30, sleep_interval=1):
"""
Waits for a file to reach a status in the status list (default: prepared)
This method will either timeout or return the result of
downloadSessionFile.get(session_id, file_name)
"""
if HAS_VAUTOMATION_PYTHON_SDK:
status_list = (DownloadSessionFile.PrepareStatus.PREPARED,)

start_time = time.time()
while (time.time() - start_time) < timeout:
file_info = self.content_service.content.library.item.downloadsession.File.get(session_id, file_name)
Expand Down

0 comments on commit f91f5be

Please sign in to comment.