Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
ankur0101 opened this issue Oct 22, 2020 · 8 comments
Open

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

ankur0101 opened this issue Oct 22, 2020 · 8 comments

Comments

@ankur0101
Copy link

ankur0101 commented Oct 22, 2020

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
Copy link
Author

ankur0101 commented Oct 22, 2020

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

@bsrdjan bsrdjan changed the title libsapnwrfc.so: cannot open shared object file: No such file or directory How to build Cloud Foundry Python app (including SAP NW RFC SDK)? Oct 22, 2020
@bsrdjan
Copy link
Member

bsrdjan commented Oct 22, 2020

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: SAP/node-rfc#79

@ankur0101
Copy link
Author

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
Copy link
Member

bsrdjan commented Oct 22, 2020

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
Copy link
Author

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

@bsrdjan
Copy link
Member

bsrdjan commented Oct 28, 2020

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 bsrdjan added the cloud label Nov 3, 2020
@bsrdjan bsrdjan reopened this Nov 3, 2020
@bsrdjan
Copy link
Member

bsrdjan commented Feb 18, 2021

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

SAP/node-rfc#145 (comment)

@bsrdjan
Copy link
Member

bsrdjan commented Oct 29, 2023

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/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants