def isRfcSdkAvailableForDownload(self, blobUrl: str, storageAccount: AzureStorageAccount) -> tuple: try: blobService = BlockBlobService(account_name=storageAccount.accountName, account_key=storageAccount.getAccessKey()) (accountName, containerName, blobName) = self._getBlobContainerAndName(blobUrl) if (not blobService.exists(container_name=containerName, blob_name=blobName)): # rfc sdk blob does not exist so we have no last modified time self.tracer.error("error validating rfc sdk blob: blob does not exist at url:%s", blobUrl) return (False, datetime.min) metadata = blobService.get_blob_properties(container_name=containerName, blob_name=blobName) lastModifiedTime = metadata.properties.last_modified self.tracer.info("found rfc sdk package blob at url:%s with last_modified:%s", blobUrl, lastModifiedTime) return (True, lastModifiedTime) except Exception as e: self.tracer.error("error validating rfc sdk blob: exception trying to access url:%s (%s)", blobUrl, e, exc_info=True) return (False, datetime.min)
def downloadAndInstallRfcSdk(self, blobUrl: str, storageAccount: AzureStorageAccount) -> bool: self.tracer.info("begin download and install of rfc sdk blob: %s", blobUrl) # start out with default since we can only persist sdk package # last modified date if we were able to fetch metadata for the blob lastModifiedTime = datetime.min wasSuccessful = False try: # create download folder self._createSdkInstallPathIfNotExists() blobService = BlockBlobService(account_name=storageAccount.accountName, account_key=storageAccount.getAccessKey()) (accountName, containerName, blobName) = self._getBlobContainerAndName(blobUrl) if (not blobService.exists(container_name=containerName, blob_name=blobName)): raise Exception("rfc sdk blob does noty exist! url:%s" % blobUrl) # extract metadata properties from blob so that we can attempt to download # to local file with same name as the blob itself, and also persist # the last modified time of the blob itself metadata = blobService.get_blob_properties(container_name=containerName, blob_name=blobName) lastModifiedTime = metadata.properties.last_modified downloadFilePath = os.path.join(self.installPath, blobName) # download sdk package to local install folder and unpack it self._downloadAndUnzip(blobService, containerName, blobName, downloadFilePath) # setup pyrfc environment variables and dynamic library loading configuration self.initRfcSdkEnvironment() # finally, verify that we can succesfully import the pyrfc module if (not self.isRfcSdkInstalled()): raise Exception("RFC SDK installation attempt failed!") self.tracer.info("RFC SDK installed successfully") wasSuccessful = True except Exception as e: wasSuccessful = False self.tracer.error("exception trying to download and install RFC SDK from url: %s, " + "installPath: %s, exception: (%s)", blobUrl, self.installPath, e, exc_info=True) try: # persist installation attempt timestamp and (if available) the last modified # time of the downloaded sdk blob so we only update installation in future if it changes self._writeSdkInstallationState(status='success' if wasSuccessful else 'failed', lastInstallAttemptTime=datetime.now(timezone.utc), packageLastModifiedTime=lastModifiedTime) except Exception as e: # failure to persist installation state file is treated as installation failure wasSuccessful = False return wasSuccessful