PyRFC icon indicating copy to clipboard operation
PyRFC copied to clipboard

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

Open ankur0101 opened this issue 5 years ago • 8 comments

Hello,

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

  • Downloaded nwrfcsdk from sap marketplace for Linux On 64-bit and saved in in /root as /root/nwrfcsdk
  • Ran command export SAPNWRFC_HOME=/root/nwrfcsdk
  • Ran command pip3 install cython
  • Ran command pip3 install pynwrfc
  • Ran command python3
  • Ran from pyrfc import Connection

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 avatar Oct 22 '20 06:10 ankur0101

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

  • Moved nwrfcsdk from /root/nwrfcsdk to /usr/local/sap/nwrfcsdk
  • Created nwrfcsdk.conf file in /etc/ld.so.conf.d/ and added content as /usr/local/sap/nwrfcsdk/lib
  • Ran command ldconfig
  • Ran command ldconfig -p | grep sap which showed loaded library

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

ankur0101 avatar Oct 22 '20 07:10 ankur0101

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

bsrdjan avatar Oct 22 '20 09:10 bsrdjan

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?

ankur0101 avatar Oct 22 '20 13:10 ankur0101

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 ?

bsrdjan avatar Oct 22 '20 13:10 bsrdjan

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

ankur0101 avatar Oct 23 '20 13:10 ankur0101

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 avatar Oct 28 '20 11:10 bsrdjan

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 avatar Feb 18 '21 14:02 bsrdjan

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/

bsrdjan avatar Oct 29 '23 08:10 bsrdjan