Skip to content

Commit

Permalink
Backport: Skip checking flagIN value before inserting rules (#108) #126
Browse files Browse the repository at this point in the history
#120 (#130)

* Skip checking flagIN value before inserting rules (#108)

* Skip checking flagIN value before inserting rules

* Add changelogs fragments

* Update changelogs/fragments/107-update_destination_hostgroup.yml

* include integration test

* fix typo

* more debug outputs

* more checks

* fix query_data order

* append changelog

Co-authored-by: Markus Bergholz <[email protected]>

* too many blank lines (#120)

Co-authored-by: Squirrel <[email protected]>
  • Loading branch information
markuman and squirrel532 authored Jan 3, 2023
1 parent 68286cb commit a781c12
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 2 deletions.
3 changes: 3 additions & 0 deletions changelogs/fragments/107-update_destination_hostgroup.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
bugfixes:
- proxysql_query_rules_fast_routing - remove unnecessary ``flagIN`` check, that makes it impossible to update the ``destination_hostgroup`` parameter (https://github.com/ansible-collections/community.proxysql/pull/108).
- proxysql_query_rules_fast_routing - fix query parameter order, that prevents updating ``destination_hostgroup`` parameter (https://github.com/ansible-collections/community.proxysql/pull/108).
4 changes: 2 additions & 2 deletions plugins/modules/proxysql_query_rules_fast_routing.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,8 @@ def update_rule_config(self, cursor):

for col, val in iteritems(self.config_data):
if val is not None and col not in ("username", "schemaname", "flagIN"):
query_data.insert(cols, val)
cols += 1
query_data.append(val)
if cols == 1:
query_string += " SET " + col + "= %s,"
else:
Expand Down Expand Up @@ -379,7 +379,7 @@ def main():
try:
if not query_rule.check_rule_cfg_exists(cursor):
if query_rule.config_data["username"] and query_rule.config_data["schemaname"] and \
query_rule.config_data["flagIN"] and query_rule.check_rule_pk_exists(cursor):
query_rule.check_rule_pk_exists(cursor):
query_rule.update_rule(module.check_mode, result, cursor)
else:
query_rule.create_rule(module.check_mode, result, cursor)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
- name: Create fast routing rules
community.proxysql.proxysql_query_rules_fast_routing:
# rule args
username: user
schemaname: test_database
destination_hostgroup: 1
# auth args
login_user: admin
login_password: admin
state: present
register: out

- debug:
var: out

- name: verify create
assert:
that:
- out is changed
- out.rules[0].destination_hostgroup == "1"

- name: Update destination hostgroup of previous fast routing rule
community.proxysql.proxysql_query_rules_fast_routing:
# rule args
username: user
schemaname: test_database
destination_hostgroup: 2
# auth args
login_user: admin
login_password: admin
state: present
register: out

- debug:
var: out

- name: verify change
assert:
that:
- out is changed
- out.rules[0].destination_hostgroup == "2"

- name: Update destination hostgroup of previous fast routing rule (idempotent)
community.proxysql.proxysql_query_rules_fast_routing:
# rule args
username: user
schemaname: test_database
destination_hostgroup: 2
# auth args
login_user: admin
login_password: admin
state: present
register: out

- debug:
var: out

- name: verify no change
assert:
that:
- out is not changed
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@
test_proxysql_query_rules_fast_routing_with_delayed_persist: true
test_proxysql_query_rules_fast_routing_check_idempotence: true


### other checks
- name: test change destination hostgroup
include_tasks: 107-update_destination_hostgroup.yml

### teardown

- name: "{{ role_name }} | teardown | perform teardown"
Expand Down

0 comments on commit a781c12

Please sign in to comment.