Skip to content

Commit 3bad25a

Browse files
authored
Merge pull request #79 from arctix625/feat/properties-param
sap_hdbsql: Add new parameter named properties
2 parents a9a08f2 + 3b12b16 commit 3bad25a

2 files changed

Lines changed: 42 additions & 0 deletions

File tree

plugins/modules/sap_hdbsql.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,13 @@
6262
description: Use encrypted connection.
6363
type: bool
6464
default: false
65+
properties:
66+
description:
67+
- Sets SQLDBC connect options e.g. sqlMode=SAPR3
68+
- Must be a string or list containing strings.
69+
- See SAP HANA documentation for list of available options.
70+
type: list
71+
elements: str
6572
filepath:
6673
description:
6774
- One or more files each containing one SQL query to run.
@@ -142,6 +149,16 @@
142149
- select user_name from users
143150
- select * from users
144151
autocommit: False
152+
153+
- name: Run query with SQLDBC connect options
154+
community.sap_libs.sap_hdbsql:
155+
sid: "hdb"
156+
instance: "01"
157+
password: "Test123"
158+
query: select user_name from users
159+
properties:
160+
- "sqlMode=SAPR3"
161+
- "sslHostNameInCertificate=hana.example.com"
145162
'''
146163

147164
RETURN = r'''
@@ -205,6 +222,7 @@ def main():
205222
query=dict(type='list', elements='str', required=False),
206223
filepath=dict(type='list', elements='path', required=False),
207224
autocommit=dict(type='bool', default=True),
225+
properties=dict(type='list', elements='str', required=False),
208226
),
209227
required_one_of=[('query', 'filepath')],
210228
required_if=[('userstore', False, ['password'])],
@@ -260,6 +278,10 @@ def main():
260278
if params['database']:
261279
command.extend(['-d', params['database']])
262280

281+
if params['properties']:
282+
for prop in params['properties']:
283+
command.extend(['-Z', prop])
284+
263285
if params['userstore']:
264286
command.extend(['-x', '-U', params['user']])
265287

tests/unit/plugins/modules/test_sap_hdbsql.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,3 +184,23 @@ def test_encrypted_connection_flags(self):
184184
self.assertIn('-e', executed_cmd)
185185
self.assertIn('-ssltrustcert', executed_cmd)
186186
self.assertIn('-sslcreatecert', executed_cmd)
187+
188+
def test_properties_command_args(self):
189+
"""Verify that properties are correctly added to the command"""
190+
args = {
191+
'sid': "HDB",
192+
'instance': "01",
193+
'password': "pwd",
194+
'properties': ["key1=value1", "key2=value2"],
195+
'query': ["SELECT 1 FROM DUMMY;"]
196+
}
197+
with patch.object(basic.AnsibleModule, 'run_command') as run_command:
198+
run_command.return_value = 0, '1', ''
199+
with self.assertRaises(AnsibleExitJson):
200+
with set_module_args(args):
201+
self.module.main()
202+
203+
executed_cmd = run_command.call_args[0][0]
204+
self.assertIn('-Z', executed_cmd)
205+
self.assertIn('key1=value1', executed_cmd)
206+
self.assertIn('key2=value2', executed_cmd)

0 commit comments

Comments
 (0)