Skip to content

Commit

Permalink
Add read and write connections for this module and update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rhysmeister committed Oct 11, 2024
1 parent 87ac04d commit cfabb59
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
22 changes: 15 additions & 7 deletions plugins/modules/cassandra_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -503,19 +503,27 @@ def main():
if ssl_cert_reqs in ('CERT_REQUIRED', 'CERT_OPTIONAL'):
ssl_context.load_verify_locations(module.params['ssl_ca_certs'])
profile = ExecutionProfile(consistency_level=ConsistencyLevel.name_to_value[consistency_level])
cluster = Cluster(login_host,
port=login_port,
auth_provider=auth_provider,
ssl_context=ssl_context,
execution_profiles={EXEC_PROFILE_DEFAULT: profile})
session = cluster.connect()

# read connection - not all consistency levels work on reads
cluster_r = Cluster(login_host,
port=login_port,
auth_provider=auth_provider,
ssl_context=ssl_context)

cluster_w = Cluster(login_host,
port=login_port,
auth_provider=auth_provider,
ssl_context=ssl_context,
execution_profiles={EXEC_PROFILE_DEFAULT: profile})
session_r = cluster_r.connect()
session = cluster_r.connect()
except AuthenticationFailed as excep:
module.fail_json(msg="Authentication failed: {0}".format(excep))
except Exception as excep:
module.fail_json(msg="Error connecting to cluster: {0}".format(excep))

try:
if table_exists(session, keyspace_name, table_name):
if table_exists(session_r, keyspace_name, table_name):
if state == "present":
result['changed'] = False
else:
Expand Down
4 changes: 1 addition & 3 deletions tests/integration/targets/cassandra_table/tasks/284.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,11 @@
consistency_level: "ANY"
login_user: "{{ cassandra_admin_user }}"
login_password: "{{ cassandra_admin_pwd }}"
ignore_errors: true
register: any

- assert:
that:
- any.failed
- "'ANY ConsistencyLevel is only supported for writes' in any.msg"
- any.changed

- name: Create a test keyspace - QUORUM consistency
community.cassandra.cassandra_table:
Expand Down

0 comments on commit cfabb59

Please sign in to comment.