cancel
Showing results for 
Search instead for 
Did you mean: 

How to connect Hana DB with API tests?

0 Kudos

Hello colleagues,


I'm developing a multitenancy application in nodeJS and I want to run my integration tests against a real hana database instead of a in-memory (current configuration).

I saw in this blog https://blogs.sap.com/2021/02/15/the-hidden-life-of-servicemanager-handled-containers/ how to fetch the hana credentials for a specific tenant which I aim to connect to run the tests. Also I'm able to test the connection against the HANA SQL console and I can to query in the DB

.But whenever I set the configuration in the `.cdsrc.json` the application fails with the following error messages:

[hana] - Could not establish connection for tenant "anonymous". Existing pool will be drained.[hana] - Error: Could not establish connection for tenant "anonymous" due to error: Could not connect to any host: [ my-host-prod-us10.hanacloud.ondemand.com:443 - unable to get local issuer certificate ]<br>[...]<br>TimeoutError: Acquiring client from pool timed out. Please review your system setup, transaction handling, and pool configuration.


I saw that this tenant issue could be related to my mocked users not having it set properly, so I did the following (without success)

{ "admin": { "password": "xxxxxxx", "tenant": "my-tenant" }}
Regarding the `unable to get local issuer certificate` I tried with both sslValidateCertificate false and true but the issue kept the same

In my `.cdsrc.json` I have the following configuration:

"dbtesthana": {<br>        "kind": "hana",<br>        "schema": "xxxx",<br>        "credentials": {<br>          "host": "xxxx",<br>          "port": 443,<br>          "user": "xxx", <br>          "password": "xxxx",<br>          "initializationTimeout": "60000",<br>          "sslValidateCertificate": false,<br>          "certificate": "-----BEGIN CERTIFICATE-----xxxxxx----END CERTIFICATE-----"<br>        }      <br>}<br>}

Am I missing something?Changing the configuration to `default-env.json` always results in malformated authentication error.

Thanks a ton for your help!

[Edit1]: formatting issues

[Edit 2]: Hana is already configured to accept all incoming requests as described in SAP Hana Cloud Central: https://help.sap.com/viewer/9ae9104a46f74a6583ce5182e7fb20cb/hanacloud/en-US/770d34deb86d4eb49dc944c...

david_kunz2
Advisor
Advisor
0 Kudos

Hi igor.lauxen ,

Did you enable multitenancy in your app?

See here fore more info:

https://cap.cloud.sap/docs/guides/deployment/as-saas

Thanks for clarification and best regards,
David
0 Kudos

hi david.kunz2

Yes, currently the app uses multitenancy. This is already up and running and I'm able to subscribe to new instanaces in BTP where each instace, using service manager, creates a new HDI container to isolate the data.

Thanks for the reply!
Igor

david_kunz2
Advisor
Advisor

Hi igor.lauxen ,

Then I'm a bit confused, shouldn't your HANA service be bound to the service-manager? In your `.cdsrc.json` you referenced the HANA database directly.

Best regards,
David

0 Kudos

hi david.kunz2 this is something that I'm not sure as well.

Since during my test I want to access a specific database instead of dynamically find a database, I'm trying now to connect directly so I don't add new layers of potential errors.

Do you think this is a potential problem? Do you have an example where it was used the service-manager to access a database in .cdsrc?

Thanks!
Igor

david_kunz2
Advisor
Advisor
0 Kudos

Hi igor.lauxen ,

Our CAP layer already does the necessary things to retrieve the correct database based on tenant information, so it would be easiest to just do that and not connect manually.

Best regards,
David

0 Kudos

hi david.kunz2

do you have a documentation that I can use to support in this setup?

Thanks!
Igor

Accepted Solutions (0)

Answers (1)

Answers (1)

david_kunz2
Advisor
Advisor
0 Kudos

Hi igor.lauxen ,

You just need to make sure that the correct tenant is set and that multitenancy is enabled. The rest is done automatically.

https://cap.cloud.sap/docs/guides/deployment/as-saas

Best regards,
David

0 Kudos

Based on this comment I reverted my changes in cdsrc.json and connected to my services hosted in BTP by authenticating using OAuth during test execution.
I'm following this process in the tests because it's how I "define" in which tenant I'm going to access when testing against postman for instance.
The challenge with this approach is that it will only work for previous created entities, if I create a new table called XYZ and and add automation tests for it, it will break in the pipeline because the services for this entity are not yet deployed.
david.kunz2 do you trigger the deployment of the tenant prior the testing/static code checks when testing against a real hana db?

david_kunz2
Advisor
Advisor
0 Kudos

Hi igor.lauxen ,

Yes, the relevant artifacts need to be deployed first.

Best regards,
David