SAP / PyRFC

Asynchronous, non-blocking SAP NW RFC SDK bindings for Python
http://sap.github.io/PyRFC
Apache License 2.0
494 stars 132 forks source link

How to build Cloud Foundry Python app (including SAP NW RFC SDK)? #205

Open ankur0101 opened 3 years ago

ankur0101 commented 3 years ago

Hello,

I am using Ubuntu based environment to run PyRFC. I took following steps:

This immediately gave following error message:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.8/dist-packages/pyrfc/__init__.py", line 29, in <module>
    from .pyrfc import (
ImportError: libsapnwrfc.so: cannot open shared object file: No such file or directory

If I look inside init.py, I see it is trying to load SO (shared object) file as module using os.add_dll_directory(os.path.join(os.environ["SAPNWRFC_HOME"], "lib")) Which can be found here https://github.com/SAP/PyRFC/blob/master/src/pyrfc/init.py I am not sure this is the correct approach to load Shared object files in linux since method add_dll_directory is being called after checking OS type as nt, I could not see any check mechanism to detect unix OS type.

Also please find the screenshot below for the structure of /root/nwrfcsdk

image

What exactly needs to be done here to get this thing working? Thanks

EDIT: I see no code for unix os types is written in this library.

image

I will try to push unix adaptation but I think it would be better that someone managing this repo can take care of it.

ankur0101 commented 3 years ago

The temporary workaround is to install shared object files via ldconfig. I took following steps and now error has disappeared.

image

I think this could get addressed into library since currently I am trying to use pyrfc in SAP Cloud foundry where root access to container could not be gained and unsure how to create nwrfcsdk.conf in /etc/ld.so.conf.d/ and run command ldconfig via cf push.

Credits: https://medium.com/codingtown/install-sap-nw-rfc-sdk-in-ubuntu-18-04-3-lts-50e42b4dfe66

bsrdjan commented 3 years ago

If you look only 4 lines above the os.add_dll_directory() statement in init.py, there is a comment why this statement is added and relevant for Windows only.

Your main questions I think are how to deploy SAP NWRFC SDK to Cloud Foundry and how to use the PyRFC from Cloud Foundry.

Technically, SAP NWRFC SDK can be deployed using CF Pre-Runtime Hooks and PyRFC can be also deployed the standard way. The challenge is RFC channel from SAP Cloud Platform to ABAP backend, currently supported only for Java runtimes in Neo and the SAP Java Buildpack in Cloud Foundry.

For Python (and/or NodeJS) you can create the feature request for SAP Secure Cloud Connector, to enable SAP NWRFC SDK usage within SAP Cloud Platform Connectivity context and be able to use the Cloud Connector also from Python.

Please see the same question for NodeJS: https://github.com/SAP/node-rfc/issues/79

ankur0101 commented 3 years ago

Thanks @bsrdjan for changing title 👍

To run ldconfig via cf push using .profile, it requires root level permissions since it returns Permission Denied error. I am not experienced in cloud foundry but as per my observation, I see CF installs dependencies from requirements.txt first and then triggers .profile Hence this results error saying "Environment variable SAPNWRFC_HOME not defined" even though it has been mentioned in manifest.yml as

env:
    SAPNWRFC_HOME: /home/vcap/app/nwrfcsdk

Is there any way to get Shared object files uploaded before running requirments.txt?

bsrdjan commented 3 years ago

Sorry that I can't help further with PyRFC and NWRFC SDK packaging on Cloud Foundry, without SAP NWRFC SDK being supported on Cloud Foundry. Would you mind to create a feature request for that on influence.sap.com ?

ankur0101 commented 3 years ago

I was able to push pyrfc with NWRFC's shared object into sap cloud foundry via docker image. Thanks for your assistance @bsrdjan

bsrdjan commented 3 years ago

The feature request to enable SAP NWRFC SDK usage on Cloud Foundry, in Connectivity context, can be created for:

Security Services category of the SAP Cloud Platform – Platform Foundation

bsrdjan commented 3 years ago

Here the feature request for node-rfc cloud connectivity. You may comment or vote or create similar request for PyRFC

https://github.com/SAP/node-rfc/issues/145#issuecomment-781209573

bsrdjan commented 9 months ago

Here the current status and how to build Cloud Foundry Node.JS app with SAP NW RFC SDK:

ABAP RFC connectivity from Kyma and BTP Node.JS buildpack

It works the same way with Python: https://blogs.sap.com/2023/10/30/abap-rfc-connectivity-from-btp-python-buildpack/