From 7b7c5eb84e916c4aa8a25f558a680fd4469ec12e Mon Sep 17 00:00:00 2001 From: Markus Bergholz Date: Tue, 28 Sep 2021 12:02:09 +0200 Subject: [PATCH] Fix query rules 2 (#77) * fix query rule * prepare integration test to run against proxysql < 2 and >= 2 * dafuq * Update tests/integration/targets/test_proxysql_query_rules/tasks/setup_test_query_rule.yml Co-authored-by: Andrew Klychkov * add changelog fragment Co-authored-by: Andrew Klychkov --- changelogs/fragments/77-fix-query-rules.yml | 2 + plugins/modules/proxysql_query_rules.py | 8 +- .../tasks/base_test.yml | 152 ++++++++++++------ .../test_proxysql_query_rules/tasks/main.yml | 10 ++ .../tasks/setup_test_query_rule.yml | 7 +- .../tasks/test_create_query_rule.yml | 56 +++++-- .../test_create_query_rule_in_memory_only.yml | 57 ++++--- ...create_query_rule_with_delayed_persist.yml | 55 +++++-- .../tasks/test_create_using_check_mode.yml | 55 +++++-- .../tasks/test_delete_query_rule.yml | 56 +++++-- .../test_delete_query_rule_in_memory_only.yml | 56 +++++-- ...delete_query_rule_with_delayed_persist.yml | 57 ++++--- .../tasks/test_delete_using_check_mode.yml | 55 +++++-- 13 files changed, 444 insertions(+), 182 deletions(-) create mode 100644 changelogs/fragments/77-fix-query-rules.yml diff --git a/changelogs/fragments/77-fix-query-rules.yml b/changelogs/fragments/77-fix-query-rules.yml new file mode 100644 index 0000000..abc16ad --- /dev/null +++ b/changelogs/fragments/77-fix-query-rules.yml @@ -0,0 +1,2 @@ +bugfixes: +- proxysql_query_rules - fix backwards compatibility. Proxysql > 2 does not support parameter ``cache_empty_result`` (https://github.com/ansible-collections/community.proxysql/pull/77). \ No newline at end of file diff --git a/plugins/modules/proxysql_query_rules.py b/plugins/modules/proxysql_query_rules.py index 12926d7..5d91785 100644 --- a/plugins/modules/proxysql_query_rules.py +++ b/plugins/modules/proxysql_query_rules.py @@ -380,7 +380,7 @@ def load_config_to_runtime(cursor): class ProxyQueryRule(object): - def __init__(self, module): + def __init__(self, module, version): self.state = module.params["state"] self.force_delete = module.params["force_delete"] self.save_to_disk = module.params["save_to_disk"] @@ -403,7 +403,6 @@ def __init__(self, module): "replace_pattern", "destination_hostgroup", "cache_ttl", - "cache_empty_result", "multiplex", "timeout", "retries", @@ -418,6 +417,9 @@ def __init__(self, module): "apply", "comment"] + if version.get('major') >= 2: + config_data_keys.append("cache_empty_result") + self.config_data = dict((k, module.params[k]) for k in config_data_keys) @@ -681,7 +683,7 @@ def main(): msg="unable to connect to ProxySQL Admin Module.. %s" % to_native(e) ) - proxysql_query_rule = ProxyQueryRule(module) + proxysql_query_rule = ProxyQueryRule(module, version) result = {} result['state'] = proxysql_query_rule.state diff --git a/tests/integration/targets/test_proxysql_query_rules/tasks/base_test.yml b/tests/integration/targets/test_proxysql_query_rules/tasks/base_test.yml index e435f47..1b2c634 100644 --- a/tests/integration/targets/test_proxysql_query_rules/tasks/base_test.yml +++ b/tests/integration/targets/test_proxysql_query_rules/tasks/base_test.yml @@ -8,58 +8,120 @@ include_tasks: "{{ test_delete|ternary('setup_test_query_rule', 'cleanup_test_query_rules') }}.yml" when: not test_proxysql_query_rules_check_idempotence -### when - -- name: "{{ role_name }} | {{ current_test }} | {{ test_delete|ternary('delete','create') }} test query rule" - proxysql_query_rules: - login_user: admin - login_password: admin - username: '{{ test_user }}' - match_pattern: '{{ test_match_pattern }}' - destination_hostgroup: '{{ test_destination_hostgroup }}' - active: '{{ test_active }}' - retries: '{{ test_retries }}' - cache_ttl: '{{ test_cache_ttl }}' - cache_empty_result: '{{ test_cache_empty_result }}' - multiplex: '{{ test_multiplex }}' - next_query_flagIN: '{{ test_next_query_flagin }}' - state: "{{ test_delete|ternary('absent', 'present') }}" - save_to_disk: "{{ not test_proxysql_query_rules_in_memory_only }}" - load_to_runtime: "{{ not test_proxysql_query_rules_in_memory_only }}" - check_mode: "{{ test_proxysql_query_rules_check_mode }}" - register: status - -- name: "{{ role_name }} | {{ current_test }} | persist the changes to disk, and load to runtime" - block: +### when proxysql >= 2 - - name: "{{ role_name }} | {{ current_test }} | save the query rules config from memory to disk" - proxysql_manage_config: +- name: test against proxysql >= 2 + when: PROXYSQL2 + block: + - name: "{{ role_name }} | {{ current_test }} | {{ test_delete|ternary('delete','create') }} test query rule" + proxysql_query_rules: login_user: admin login_password: admin - action: SAVE - config_settings: MYSQL QUERY RULES - direction: TO - config_layer: DISK + username: '{{ test_user }}' + match_pattern: '{{ test_match_pattern }}' + destination_hostgroup: '{{ test_destination_hostgroup }}' + active: '{{ test_active }}' + retries: '{{ test_retries }}' + cache_ttl: '{{ test_cache_ttl }}' + cache_empty_result: '{{ test_cache_empty_result }}' + multiplex: '{{ test_multiplex }}' + next_query_flagIN: '{{ test_next_query_flagin }}' + state: "{{ test_delete|ternary('absent', 'present') }}" + save_to_disk: "{{ not test_proxysql_query_rules_in_memory_only }}" + load_to_runtime: "{{ not test_proxysql_query_rules_in_memory_only }}" + check_mode: "{{ test_proxysql_query_rules_check_mode }}" + register: status + + - name: "{{ role_name }} | {{ current_test }} | persist the changes to disk, and load to runtime" + block: + + - name: "{{ role_name }} | {{ current_test }} | save the query rules config from memory to disk" + proxysql_manage_config: + login_user: admin + login_password: admin + action: SAVE + config_settings: MYSQL QUERY RULES + direction: TO + config_layer: DISK + + - name: "{{ role_name }} | {{ current_test }} | load the query rules config from memory to runtime" + proxysql_manage_config: + login_user: admin + login_password: admin + action: LOAD + config_settings: MYSQL QUERY RULES + direction: TO + config_layer: RUNTIME + + when: test_proxysql_query_rules_with_delayed_persist + + - name: "{{ role_name }} | {{ current_test }} | check if test query rule exists in memory" + shell: mysql -uadmin -padmin -h127.0.0.1 -P6032 -BNe"SELECT username || ',' || match_pattern || ',' || destination_hostgroup || ',' || active || ',' || retries || ',' || cache_ttl || ',' || cache_empty_result || ',' || multiplex || ',' || next_query_flagIN FROM mysql_query_rules where username = '{{ test_user }}' and match_pattern = '{{ test_match_pattern }}' and destination_hostgroup and '{{ test_destination_hostgroup }}' and active = '{{ test_active }}' and retries = '{{ test_retries }}' and cache_ttl = '{{ test_cache_ttl }}' and cache_empty_result = '{{ test_cache_empty_result }}' and multiplex = '{{ test_multiplex }}' and next_query_flagIN = '{{ test_next_query_flagin }}'" + register: memory_result + + - name: "{{ role_name }} | {{ current_test }} | check if test query rule exists on disk" + shell: mysql -uadmin -padmin -h127.0.0.1 -P6032 -BNe"SELECT username || ',' || match_pattern || ',' || destination_hostgroup || ',' || active || ',' || retries || ',' || cache_ttl || ',' || cache_empty_result || ',' || multiplex || ',' || next_query_flagIN FROM disk.mysql_query_rules where username = '{{ test_user }}' and match_pattern = '{{ test_match_pattern }}' and destination_hostgroup and '{{ test_destination_hostgroup }}' and active = '{{ test_active }}' and retries = '{{ test_retries }}' and cache_ttl = '{{ test_cache_ttl }}' and cache_empty_result = '{{ test_cache_empty_result }}' and multiplex = '{{ test_multiplex }}' and next_query_flagIN = '{{ test_next_query_flagin }}'" + register: disk_result - - name: "{{ role_name }} | {{ current_test }} | load the query rules config from memory to runtime" - proxysql_manage_config: + - name: "{{ role_name }} | {{ current_test }} | check if test query rule exists in runtime" + shell: mysql -uadmin -padmin -h127.0.0.1 -P6032 -BNe"SELECT username || ',' || match_pattern || ',' || destination_hostgroup || ',' || active || ',' || retries || ',' || cache_ttl || ',' || cache_empty_result || ',' || multiplex || ',' || next_query_flagIN FROM runtime_mysql_query_rules where username = '{{ test_user }}' and match_pattern = '{{ test_match_pattern }}' and destination_hostgroup and '{{ test_destination_hostgroup }}' and active = '{{ test_active }}' and retries = '{{ test_retries }}' and cache_ttl = '{{ test_cache_ttl }}' and cache_empty_result = '{{ test_cache_empty_result }}' and multiplex = '{{ test_multiplex }}' and next_query_flagIN = '{{ test_next_query_flagin }}'" + register: runtime_result + + +### when proxysql < 2 + +- name: test against proxysql < 2 + when: not PROXYSQL2 + block: + - name: "{{ role_name }} | {{ current_test }} | {{ test_delete|ternary('delete','create') }} test query rule" + proxysql_query_rules: login_user: admin login_password: admin - action: LOAD - config_settings: MYSQL QUERY RULES - direction: TO - config_layer: RUNTIME + username: '{{ test_user }}' + match_pattern: '{{ test_match_pattern }}' + destination_hostgroup: '{{ test_destination_hostgroup }}' + active: '{{ test_active }}' + retries: '{{ test_retries }}' + cache_ttl: '{{ test_cache_ttl }}' + multiplex: '{{ test_multiplex }}' + next_query_flagIN: '{{ test_next_query_flagin }}' + state: "{{ test_delete|ternary('absent', 'present') }}" + save_to_disk: "{{ not test_proxysql_query_rules_in_memory_only }}" + load_to_runtime: "{{ not test_proxysql_query_rules_in_memory_only }}" + check_mode: "{{ test_proxysql_query_rules_check_mode }}" + register: status1 + + - name: "{{ role_name }} | {{ current_test }} | persist the changes to disk, and load to runtime" + block: + + - name: "{{ role_name }} | {{ current_test }} | save the query rules config from memory to disk" + proxysql_manage_config: + login_user: admin + login_password: admin + action: SAVE + config_settings: MYSQL QUERY RULES + direction: TO + config_layer: DISK + + - name: "{{ role_name }} | {{ current_test }} | load the query rules config from memory to runtime" + proxysql_manage_config: + login_user: admin + login_password: admin + action: LOAD + config_settings: MYSQL QUERY RULES + direction: TO + config_layer: RUNTIME - when: test_proxysql_query_rules_with_delayed_persist + when: test_proxysql_query_rules_with_delayed_persist -- name: "{{ role_name }} | {{ current_test }} | check if test query rule exists in memory" - shell: mysql -uadmin -padmin -h127.0.0.1 -P6032 -BNe"SELECT username || ',' || match_pattern || ',' || destination_hostgroup || ',' || active || ',' || retries || ',' || cache_ttl || ',' || cache_empty_result || ',' || multiplex || ',' || next_query_flagIN FROM mysql_query_rules where username = '{{ test_user }}' and match_pattern = '{{ test_match_pattern }}' and destination_hostgroup and '{{ test_destination_hostgroup }}' and active = '{{ test_active }}' and retries = '{{ test_retries }}' and cache_ttl = '{{ test_cache_ttl }}' and cache_empty_result = '{{ test_cache_empty_result }}' and multiplex = '{{ test_multiplex }}' and next_query_flagIN = '{{ test_next_query_flagin }}'" - register: memory_result + - name: "{{ role_name }} | {{ current_test }} | check if test query rule exists in memory" + shell: mysql -uadmin -padmin -h127.0.0.1 -P6032 -BNe"SELECT username || ',' || match_pattern || ',' || destination_hostgroup || ',' || active || ',' || retries || ',' || cache_ttl || ',' || multiplex || ',' || next_query_flagIN FROM mysql_query_rules where username = '{{ test_user }}' and match_pattern = '{{ test_match_pattern }}' and destination_hostgroup and '{{ test_destination_hostgroup }}' and active = '{{ test_active }}' and retries = '{{ test_retries }}' and cache_ttl = '{{ test_cache_ttl }}' and multiplex = '{{ test_multiplex }}' and next_query_flagIN = '{{ test_next_query_flagin }}'" + register: memory_result1 -- name: "{{ role_name }} | {{ current_test }} | check if test query rule exists on disk" - shell: mysql -uadmin -padmin -h127.0.0.1 -P6032 -BNe"SELECT username || ',' || match_pattern || ',' || destination_hostgroup || ',' || active || ',' || retries || ',' || cache_ttl || ',' || cache_empty_result || ',' || multiplex || ',' || next_query_flagIN FROM disk.mysql_query_rules where username = '{{ test_user }}' and match_pattern = '{{ test_match_pattern }}' and destination_hostgroup and '{{ test_destination_hostgroup }}' and active = '{{ test_active }}' and retries = '{{ test_retries }}' and cache_ttl = '{{ test_cache_ttl }}' and cache_empty_result = '{{ test_cache_empty_result }}' and multiplex = '{{ test_multiplex }}' and next_query_flagIN = '{{ test_next_query_flagin }}'" - register: disk_result + - name: "{{ role_name }} | {{ current_test }} | check if test query rule exists on disk" + shell: mysql -uadmin -padmin -h127.0.0.1 -P6032 -BNe"SELECT username || ',' || match_pattern || ',' || destination_hostgroup || ',' || active || ',' || retries || ',' || cache_ttl || ',' || multiplex || ',' || next_query_flagIN FROM disk.mysql_query_rules where username = '{{ test_user }}' and match_pattern = '{{ test_match_pattern }}' and destination_hostgroup and '{{ test_destination_hostgroup }}' and active = '{{ test_active }}' and retries = '{{ test_retries }}' and cache_ttl = '{{ test_cache_ttl }}' and multiplex = '{{ test_multiplex }}' and next_query_flagIN = '{{ test_next_query_flagin }}'" + register: disk_result1 -- name: "{{ role_name }} | {{ current_test }} | check if test query rule exists in runtime" - shell: mysql -uadmin -padmin -h127.0.0.1 -P6032 -BNe"SELECT username || ',' || match_pattern || ',' || destination_hostgroup || ',' || active || ',' || retries || ',' || cache_ttl || ',' || cache_empty_result || ',' || multiplex || ',' || next_query_flagIN FROM runtime_mysql_query_rules where username = '{{ test_user }}' and match_pattern = '{{ test_match_pattern }}' and destination_hostgroup and '{{ test_destination_hostgroup }}' and active = '{{ test_active }}' and retries = '{{ test_retries }}' and cache_ttl = '{{ test_cache_ttl }}' and cache_empty_result = '{{ test_cache_empty_result }}' and multiplex = '{{ test_multiplex }}' and next_query_flagIN = '{{ test_next_query_flagin }}'" - register: runtime_result + - name: "{{ role_name }} | {{ current_test }} | check if test query rule exists in runtime" + shell: mysql -uadmin -padmin -h127.0.0.1 -P6032 -BNe"SELECT username || ',' || match_pattern || ',' || destination_hostgroup || ',' || active || ',' || retries || ',' || cache_ttl || ',' || multiplex || ',' || next_query_flagIN FROM runtime_mysql_query_rules where username = '{{ test_user }}' and match_pattern = '{{ test_match_pattern }}' and destination_hostgroup and '{{ test_destination_hostgroup }}' and active = '{{ test_active }}' and retries = '{{ test_retries }}' and cache_ttl = '{{ test_cache_ttl }}' and multiplex = '{{ test_multiplex }}' and next_query_flagIN = '{{ test_next_query_flagin }}'" + register: runtime_result1 diff --git a/tests/integration/targets/test_proxysql_query_rules/tasks/main.yml b/tests/integration/targets/test_proxysql_query_rules/tasks/main.yml index 3e09a62..f0638d0 100644 --- a/tests/integration/targets/test_proxysql_query_rules/tasks/main.yml +++ b/tests/integration/targets/test_proxysql_query_rules/tasks/main.yml @@ -5,6 +5,16 @@ #################################################################### ### tests +- name: "{{ role_name }} | proxysql_info" + check_mode: yes + community.proxysql.proxysql_info: + login_user: admin + login_password: admin + register: proxysql_information + +- name: set proxysql version fact + set_fact: + PROXYSQL2: "{{ proxysql_information.version.major >= 2 }}" - name: "{{ role_name }} | test_create_using_check_mode | test create query rule using check mode" import_tasks: test_create_using_check_mode.yml diff --git a/tests/integration/targets/test_proxysql_query_rules/tasks/setup_test_query_rule.yml b/tests/integration/targets/test_proxysql_query_rules/tasks/setup_test_query_rule.yml index 051c40f..7638b91 100644 --- a/tests/integration/targets/test_proxysql_query_rules/tasks/setup_test_query_rule.yml +++ b/tests/integration/targets/test_proxysql_query_rules/tasks/setup_test_query_rule.yml @@ -2,9 +2,14 @@ - name: "{{ role_name }} | {{ current_test }} | ensure test query rule is created when we start" block: - - name: "{{ role_name }} | {{ current_test }} | ensure test query rule is created in memory" + - name: "{{ role_name }} | {{ current_test }} | ensure test query rule is created in memory proxysql >= 2" + when: PROXYSQL2 shell: mysql -uadmin -padmin -h127.0.0.1 -P6032 -BNe"INSERT OR REPLACE INTO mysql_query_rules (username, match_pattern, destination_hostgroup, active, retries, cache_ttl, cache_empty_result, multiplex, next_query_flagIN) VALUES ('{{ test_user }}', '{{ test_match_pattern}}', '{{ test_destination_hostgroup }}', '{{ test_active }}', '{{ test_retries }}', '{{ test_cache_ttl }}', '{{ test_cache_empty_result }}', '{{ test_multiplex }}', '{{ test_next_query_flagin }}')" + - name: "{{ role_name }} | {{ current_test }} | ensure test query rule is created in memory proxysql < 2" + when: not PROXYSQL2 + shell: mysql -uadmin -padmin -h127.0.0.1 -P6032 -BNe"INSERT OR REPLACE INTO mysql_query_rules (username, match_pattern, destination_hostgroup, active, retries, cache_ttl, multiplex, next_query_flagIN) VALUES ('{{ test_user }}', '{{ test_match_pattern}}', '{{ test_destination_hostgroup }}', '{{ test_active }}', '{{ test_retries }}', '{{ test_cache_ttl }}', '{{ test_multiplex }}', '{{ test_next_query_flagin }}')" + - name: "{{ role_name }} | {{ current_test }} | ensure test query rule is created on disk" shell: mysql -uadmin -padmin -h127.0.0.1 -P6032 -BNe"SAVE MYSQL QUERY RULES TO DISK" diff --git a/tests/integration/targets/test_proxysql_query_rules/tasks/test_create_query_rule.yml b/tests/integration/targets/test_proxysql_query_rules/tasks/test_create_query_rule.yml index 20d824b..f1c9bfc 100644 --- a/tests/integration/targets/test_proxysql_query_rules/tasks/test_create_query_rule.yml +++ b/tests/integration/targets/test_proxysql_query_rules/tasks/test_create_query_rule.yml @@ -7,22 +7,46 @@ ### then -- name: "{{ role_name }} | {{ current_test }} | check if create query rule reported a change" - assert: - that: - - "status is {{ test_proxysql_query_rules_check_idempotence|ternary('not changed', 'changed') }}" - -- name: "{{ role_name }} | {{ current_test }} | confirm create query rule did make a change in memory" - assert: - that: memory_result.stdout == '{{ test_user }},{{ test_match_pattern }},{{ test_destination_hostgroup }},{{ test_active }},{{ test_retries }},{{ test_cache_ttl }},{{ test_cache_empty_result }},{{ test_multiplex }},{{ test_next_query_flagin }}' - -- name: "{{ role_name }} | {{ current_test }} | confirm create query rule did make a change on disk" - assert: - that: disk_result.stdout == '{{ test_user }},{{ test_match_pattern }},{{ test_destination_hostgroup }},{{ test_active }},{{ test_retries }},{{ test_cache_ttl }},{{ test_cache_empty_result }},{{ test_multiplex }},{{ test_next_query_flagin }}' - -- name: "{{ role_name }} | {{ current_test }} | confirm create query rule did make a change to runtime" - assert: - that: runtime_result.stdout == '{{ test_user }},{{ test_match_pattern }},{{ test_destination_hostgroup }},{{ test_active }},{{ test_retries }},{{ test_cache_ttl }},{{ test_cache_empty_result }},{{ test_multiplex }},{{ test_next_query_flagin }}' +- name: verify test against proxysql >= 2 + when: PROXYSQL2 + block: + - name: "{{ role_name }} | {{ current_test }} | check if create query rule reported a change" + assert: + that: + - "status is {{ test_proxysql_query_rules_check_idempotence|ternary('not changed', 'changed') }}" + + - name: "{{ role_name }} | {{ current_test }} | confirm create query rule did make a change in memory" + assert: + that: memory_result.stdout == '{{ test_user }},{{ test_match_pattern }},{{ test_destination_hostgroup }},{{ test_active }},{{ test_retries }},{{ test_cache_ttl }},{{ test_cache_empty_result }},{{ test_multiplex }},{{ test_next_query_flagin }}' + + - name: "{{ role_name }} | {{ current_test }} | confirm create query rule did make a change on disk" + assert: + that: disk_result.stdout == '{{ test_user }},{{ test_match_pattern }},{{ test_destination_hostgroup }},{{ test_active }},{{ test_retries }},{{ test_cache_ttl }},{{ test_cache_empty_result }},{{ test_multiplex }},{{ test_next_query_flagin }}' + + - name: "{{ role_name }} | {{ current_test }} | confirm create query rule did make a change to runtime" + assert: + that: runtime_result.stdout == '{{ test_user }},{{ test_match_pattern }},{{ test_destination_hostgroup }},{{ test_active }},{{ test_retries }},{{ test_cache_ttl }},{{ test_cache_empty_result }},{{ test_multiplex }},{{ test_next_query_flagin }}' + +- name: verify test against proxysql < 2 + when: not PROXYSQL2 + block: + - name: "{{ role_name }} | {{ current_test }} | check if create query rule reported a change" + assert: + that: + - "status1 is {{ test_proxysql_query_rules_check_idempotence|ternary('not changed', 'changed') }}" + + - name: "{{ role_name }} | {{ current_test }} | confirm create query rule did make a change in memory" + assert: + that: memory_result1.stdout == '{{ test_user }},{{ test_match_pattern }},{{ test_destination_hostgroup }},{{ test_active }},{{ test_retries }},{{ test_cache_ttl }},{{ test_multiplex }},{{ test_next_query_flagin }}' + + - name: "{{ role_name }} | {{ current_test }} | confirm create query rule did make a change on disk" + assert: + that: disk_result1.stdout == '{{ test_user }},{{ test_match_pattern }},{{ test_destination_hostgroup }},{{ test_active }},{{ test_retries }},{{ test_cache_ttl }},{{ test_multiplex }},{{ test_next_query_flagin }}' + + - name: "{{ role_name }} | {{ current_test }} | confirm create query rule did make a change to runtime" + assert: + that: runtime_result1.stdout == '{{ test_user }},{{ test_match_pattern }},{{ test_destination_hostgroup }},{{ test_active }},{{ test_retries }},{{ test_cache_ttl }},{{ test_multiplex }},{{ test_next_query_flagin }}' + ### perform cleanup diff --git a/tests/integration/targets/test_proxysql_query_rules/tasks/test_create_query_rule_in_memory_only.yml b/tests/integration/targets/test_proxysql_query_rules/tasks/test_create_query_rule_in_memory_only.yml index 99653bb..a096035 100644 --- a/tests/integration/targets/test_proxysql_query_rules/tasks/test_create_query_rule_in_memory_only.yml +++ b/tests/integration/targets/test_proxysql_query_rules/tasks/test_create_query_rule_in_memory_only.yml @@ -6,24 +6,45 @@ - include_tasks: base_test.yml ### then - -- name: "{{ role_name }} | {{ current_test }} | check if create query rule reported a change" - assert: - that: - - "status is {{ test_proxysql_query_rules_check_idempotence|ternary('not changed', 'changed') }}" - -- name: "{{ role_name }} | {{ current_test }} | confirm create query rule did make a change in memory" - assert: - that: memory_result.stdout == '{{ test_user }},{{ test_match_pattern }},{{ test_destination_hostgroup }},{{ test_active }},{{ test_retries }},{{ test_cache_ttl }},{{ test_cache_empty_result }},{{ test_multiplex }},{{ test_next_query_flagin }}' - -- name: "{{ role_name }} | {{ current_test }} | confirm create query rule didn't make a change on disk" - assert: - that: disk_result.stdout|length == 0 - -- name: "{{ role_name }} | {{ current_test }} | confirm create query rule didn't make a change to runtime" - assert: - that: runtime_result.stdout|length == 0 - +- name: verify test against proxysql >= 2 + when: PROXYSQL2 + block: + - name: "{{ role_name }} | {{ current_test }} | check if create query rule reported a change" + assert: + that: + - "status is {{ test_proxysql_query_rules_check_idempotence|ternary('not changed', 'changed') }}" + + - name: "{{ role_name }} | {{ current_test }} | confirm create query rule did make a change in memory" + assert: + that: memory_result.stdout == '{{ test_user }},{{ test_match_pattern }},{{ test_destination_hostgroup }},{{ test_active }},{{ test_retries }},{{ test_cache_ttl }},{{ test_cache_empty_result }},{{ test_multiplex }},{{ test_next_query_flagin }}' + + - name: "{{ role_name }} | {{ current_test }} | confirm create query rule didn't make a change on disk" + assert: + that: disk_result.stdout|length == 0 + + - name: "{{ role_name }} | {{ current_test }} | confirm create query rule didn't make a change to runtime" + assert: + that: runtime_result.stdout|length == 0 + +- name: verify test against proxysql < 2 + when: not PROXYSQL2 + block: + - name: "{{ role_name }} | {{ current_test }} | check if create query rule reported a change" + assert: + that: + - "status1 is {{ test_proxysql_query_rules_check_idempotence|ternary('not changed', 'changed') }}" + + - name: "{{ role_name }} | {{ current_test }} | confirm create query rule did make a change in memory" + assert: + that: memory_result1.stdout == '{{ test_user }},{{ test_match_pattern }},{{ test_destination_hostgroup }},{{ test_active }},{{ test_retries }},{{ test_cache_ttl }},{{ test_multiplex }},{{ test_next_query_flagin }}' + + - name: "{{ role_name }} | {{ current_test }} | confirm create query rule didn't make a change on disk" + assert: + that: disk_result1.stdout|length == 0 + + - name: "{{ role_name }} | {{ current_test }} | confirm create query rule didn't make a change to runtime" + assert: + that: runtime_result1.stdout|length == 0 ### perform cleanup - name: "{{ role_name }} | {{ current_test }} | ensure we're in a clean state when we finish" diff --git a/tests/integration/targets/test_proxysql_query_rules/tasks/test_create_query_rule_with_delayed_persist.yml b/tests/integration/targets/test_proxysql_query_rules/tasks/test_create_query_rule_with_delayed_persist.yml index 102305c..2c5c7f9 100644 --- a/tests/integration/targets/test_proxysql_query_rules/tasks/test_create_query_rule_with_delayed_persist.yml +++ b/tests/integration/targets/test_proxysql_query_rules/tasks/test_create_query_rule_with_delayed_persist.yml @@ -7,22 +7,45 @@ ### then -- name: "{{ role_name }} | {{ current_test }} | check if create query rule reported a change" - assert: - that: - - "status is {{ test_proxysql_query_rules_check_idempotence|ternary('not changed', 'changed') }}" - -- name: "{{ role_name }} | {{ current_test }} | confirm create query rule did make a change in memory" - assert: - that: memory_result.stdout == '{{ test_user }},{{ test_match_pattern }},{{ test_destination_hostgroup }},{{ test_active }},{{ test_retries }},{{ test_cache_ttl }},{{ test_cache_empty_result }},{{ test_multiplex }},{{ test_next_query_flagin }}' - -- name: "{{ role_name }} | {{ current_test }} | confirm create query rule did make a change on disk" - assert: - that: disk_result.stdout == '{{ test_user }},{{ test_match_pattern }},{{ test_destination_hostgroup }},{{ test_active }},{{ test_retries }},{{ test_cache_ttl }},{{ test_cache_empty_result }},{{ test_multiplex }},{{ test_next_query_flagin }}' - -- name: "{{ role_name }} | {{ current_test }} | confirm create query rule did make a change to runtime" - assert: - that: runtime_result.stdout == '{{ test_user }},{{ test_match_pattern }},{{ test_destination_hostgroup }},{{ test_active }},{{ test_retries }},{{ test_cache_ttl }},{{ test_cache_empty_result }},{{ test_multiplex }},{{ test_next_query_flagin }}' +- name: verify test against proxysql >= 2 + when: PROXYSQL2 + block: + - name: "{{ role_name }} | {{ current_test }} | check if create query rule reported a change" + assert: + that: + - "status is {{ test_proxysql_query_rules_check_idempotence|ternary('not changed', 'changed') }}" + + - name: "{{ role_name }} | {{ current_test }} | confirm create query rule did make a change in memory" + assert: + that: memory_result.stdout == '{{ test_user }},{{ test_match_pattern }},{{ test_destination_hostgroup }},{{ test_active }},{{ test_retries }},{{ test_cache_ttl }},{{ test_cache_empty_result }},{{ test_multiplex }},{{ test_next_query_flagin }}' + + - name: "{{ role_name }} | {{ current_test }} | confirm create query rule did make a change on disk" + assert: + that: disk_result.stdout == '{{ test_user }},{{ test_match_pattern }},{{ test_destination_hostgroup }},{{ test_active }},{{ test_retries }},{{ test_cache_ttl }},{{ test_cache_empty_result }},{{ test_multiplex }},{{ test_next_query_flagin }}' + + - name: "{{ role_name }} | {{ current_test }} | confirm create query rule did make a change to runtime" + assert: + that: runtime_result.stdout == '{{ test_user }},{{ test_match_pattern }},{{ test_destination_hostgroup }},{{ test_active }},{{ test_retries }},{{ test_cache_ttl }},{{ test_cache_empty_result }},{{ test_multiplex }},{{ test_next_query_flagin }}' + +- name: verify test against proxysql < 2 + when: not PROXYSQL2 + block: + - name: "{{ role_name }} | {{ current_test }} | check if create query rule reported a change" + assert: + that: + - "status1 is {{ test_proxysql_query_rules_check_idempotence|ternary('not changed', 'changed') }}" + + - name: "{{ role_name }} | {{ current_test }} | confirm create query rule did make a change in memory" + assert: + that: memory_result1.stdout == '{{ test_user }},{{ test_match_pattern }},{{ test_destination_hostgroup }},{{ test_active }},{{ test_retries }},{{ test_cache_ttl }},{{ test_multiplex }},{{ test_next_query_flagin }}' + + - name: "{{ role_name }} | {{ current_test }} | confirm create query rule did make a change on disk" + assert: + that: disk_result1.stdout == '{{ test_user }},{{ test_match_pattern }},{{ test_destination_hostgroup }},{{ test_active }},{{ test_retries }},{{ test_cache_ttl }},{{ test_multiplex }},{{ test_next_query_flagin }}' + + - name: "{{ role_name }} | {{ current_test }} | confirm create query rule did make a change to runtime" + assert: + that: runtime_result1.stdout == '{{ test_user }},{{ test_match_pattern }},{{ test_destination_hostgroup }},{{ test_active }},{{ test_retries }},{{ test_cache_ttl }},{{ test_multiplex }},{{ test_next_query_flagin }}' ### perform cleanup diff --git a/tests/integration/targets/test_proxysql_query_rules/tasks/test_create_using_check_mode.yml b/tests/integration/targets/test_proxysql_query_rules/tasks/test_create_using_check_mode.yml index 6e217bc..4cc47fd 100644 --- a/tests/integration/targets/test_proxysql_query_rules/tasks/test_create_using_check_mode.yml +++ b/tests/integration/targets/test_proxysql_query_rules/tasks/test_create_using_check_mode.yml @@ -7,22 +7,45 @@ ### then -- name: "{{ role_name }} | {{ current_test }} | check if create query rule in check mode reported a change" - assert: - that: - - status is changed - -- name: "{{ role_name }} | {{ current_test }} | confirm create query rule in check mode didn't make a change in memory" - assert: - that: memory_result.stdout|length == 0 - -- name: "{{ role_name }} | {{ current_test }} | confirm create query rule in check mode didn't make a change on disk" - assert: - that: disk_result.stdout|length == 0 - -- name: "{{ role_name }} | {{ current_test }} | confirm create query rule in check mode didn't make a change to runtime" - assert: - that: runtime_result.stdout|length == 0 +- name: test against proxysql >= 2 + when: PROXYSQL2 + block: + - name: "{{ role_name }} | {{ current_test }} | check if create query rule in check mode reported a change" + assert: + that: + - status is changed + + - name: "{{ role_name }} | {{ current_test }} | confirm create query rule in check mode didn't make a change in memory" + assert: + that: memory_result.stdout|length == 0 + + - name: "{{ role_name }} | {{ current_test }} | confirm create query rule in check mode didn't make a change on disk" + assert: + that: disk_result.stdout|length == 0 + + - name: "{{ role_name }} | {{ current_test }} | confirm create query rule in check mode didn't make a change to runtime" + assert: + that: runtime_result.stdout|length == 0 + +- name: test against proxysql < 2 + when: not PROXYSQL2 + block: + - name: "{{ role_name }} | {{ current_test }} | check if create query rule in check mode reported a change" + assert: + that: + - status1 is changed + + - name: "{{ role_name }} | {{ current_test }} | confirm create query rule in check mode didn't make a change in memory" + assert: + that: memory_result1.stdout|length == 0 + + - name: "{{ role_name }} | {{ current_test }} | confirm create query rule in check mode didn't make a change on disk" + assert: + that: disk_result1.stdout|length == 0 + + - name: "{{ role_name }} | {{ current_test }} | confirm create query rule in check mode didn't make a change to runtime" + assert: + that: runtime_result1.stdout|length == 0 ### perform cleanup diff --git a/tests/integration/targets/test_proxysql_query_rules/tasks/test_delete_query_rule.yml b/tests/integration/targets/test_proxysql_query_rules/tasks/test_delete_query_rule.yml index c17cb99..c563c86 100644 --- a/tests/integration/targets/test_proxysql_query_rules/tasks/test_delete_query_rule.yml +++ b/tests/integration/targets/test_proxysql_query_rules/tasks/test_delete_query_rule.yml @@ -7,23 +7,45 @@ ### then -- name: "{{ role_name }} | {{ current_test }} | check if delete query rule reported a change" - assert: - that: - - "status is {{ test_proxysql_query_rules_check_idempotence|ternary('not changed', 'changed') }}" - -- name: "{{ role_name }} | {{ current_test }} | confirm delete query rule did make a change in memory" - assert: - that: memory_result.stdout|length == 0 - -- name: "{{ role_name }} | {{ current_test }} | confirm delete query rule did make a change on disk" - assert: - that: disk_result.stdout|length == 0 - -- name: "{{ role_name }} | {{ current_test }} | confirm delete query rule did make a change to runtime" - assert: - that: runtime_result.stdout|length == 0 - +- name: verify test against proxysql >= 2 + when: PROXYSQL2 + block: + - name: "{{ role_name }} | {{ current_test }} | check if delete query rule reported a change" + assert: + that: + - "status is {{ test_proxysql_query_rules_check_idempotence|ternary('not changed', 'changed') }}" + + - name: "{{ role_name }} | {{ current_test }} | confirm delete query rule did make a change in memory" + assert: + that: memory_result.stdout|length == 0 + + - name: "{{ role_name }} | {{ current_test }} | confirm delete query rule did make a change on disk" + assert: + that: disk_result.stdout|length == 0 + + - name: "{{ role_name }} | {{ current_test }} | confirm delete query rule did make a change to runtime" + assert: + that: runtime_result.stdout|length == 0 + +- name: verify test against proxysql < 2 + when: not PROXYSQL2 + block: + - name: "{{ role_name }} | {{ current_test }} | check if delete query rule reported a change" + assert: + that: + - "status1 is {{ test_proxysql_query_rules_check_idempotence|ternary('not changed', 'changed') }}" + + - name: "{{ role_name }} | {{ current_test }} | confirm delete query rule did make a change in memory" + assert: + that: memory_result1.stdout|length == 0 + + - name: "{{ role_name }} | {{ current_test }} | confirm delete query rule did make a change on disk" + assert: + that: disk_result1.stdout|length == 0 + + - name: "{{ role_name }} | {{ current_test }} | confirm delete query rule did make a change to runtime" + assert: + that: runtime_result1.stdout|length == 0 ### perform cleanup - name: "{{ role_name }} | {{ current_test }} | ensure we're in a clean state when we finish" diff --git a/tests/integration/targets/test_proxysql_query_rules/tasks/test_delete_query_rule_in_memory_only.yml b/tests/integration/targets/test_proxysql_query_rules/tasks/test_delete_query_rule_in_memory_only.yml index a6be23e..a5f32db 100644 --- a/tests/integration/targets/test_proxysql_query_rules/tasks/test_delete_query_rule_in_memory_only.yml +++ b/tests/integration/targets/test_proxysql_query_rules/tasks/test_delete_query_rule_in_memory_only.yml @@ -7,22 +7,46 @@ ### then -- name: "{{ role_name }} | {{ current_test }} | check if delete query rule reported a change" - assert: - that: - - "status is {{ test_proxysql_query_rules_check_idempotence|ternary('not changed', 'changed') }}" - -- name: "{{ role_name }} | {{ current_test }} | confirm delete query rule didn't make a change in memory" - assert: - that: memory_result.stdout|length == 0 - -- name: "{{ role_name }} | {{ current_test }} | confirm delete query rule did make a change on disk" - assert: - that: disk_result.stdout == '{{ test_user }},{{ test_match_pattern }},{{ test_destination_hostgroup }},{{ test_active }},{{ test_retries }},{{ test_cache_ttl }},{{ test_cache_empty_result }},{{ test_multiplex }},{{ test_next_query_flagin }}' - -- name: "{{ role_name }} | {{ current_test }} | confirm delete query rule did make a change to runtime" - assert: - that: runtime_result.stdout == '{{ test_user }},{{ test_match_pattern }},{{ test_destination_hostgroup }},{{ test_active }},{{ test_retries }},{{ test_cache_ttl }},{{ test_cache_empty_result }},{{ test_multiplex }},{{ test_next_query_flagin }}' +- name: verify test against proxysql >= 2 + when: PROXYSQL2 + block: + - name: "{{ role_name }} | {{ current_test }} | check if delete query rule reported a change" + assert: + that: + - "status is {{ test_proxysql_query_rules_check_idempotence|ternary('not changed', 'changed') }}" + + - name: "{{ role_name }} | {{ current_test }} | confirm delete query rule didn't make a change in memory" + assert: + that: memory_result.stdout|length == 0 + + - name: "{{ role_name }} | {{ current_test }} | confirm delete query rule did make a change on disk" + assert: + that: disk_result.stdout == '{{ test_user }},{{ test_match_pattern }},{{ test_destination_hostgroup }},{{ test_active }},{{ test_retries }},{{ test_cache_ttl }},{{ test_cache_empty_result }},{{ test_multiplex }},{{ test_next_query_flagin }}' + + - name: "{{ role_name }} | {{ current_test }} | confirm delete query rule did make a change to runtime" + assert: + that: runtime_result.stdout == '{{ test_user }},{{ test_match_pattern }},{{ test_destination_hostgroup }},{{ test_active }},{{ test_retries }},{{ test_cache_ttl }},{{ test_cache_empty_result }},{{ test_multiplex }},{{ test_next_query_flagin }}' + +- name: verify test against proxysql < 2 + when: not PROXYSQL2 + block: + - name: "{{ role_name }} | {{ current_test }} | check if delete query rule reported a change" + assert: + that: + - "status1 is {{ test_proxysql_query_rules_check_idempotence|ternary('not changed', 'changed') }}" + + - name: "{{ role_name }} | {{ current_test }} | confirm delete query rule didn't make a change in memory" + assert: + that: memory_result1.stdout|length == 0 + + - name: "{{ role_name }} | {{ current_test }} | confirm delete query rule did make a change on disk" + assert: + that: disk_result1.stdout == '{{ test_user }},{{ test_match_pattern }},{{ test_destination_hostgroup }},{{ test_active }},{{ test_retries }},{{ test_cache_ttl }},{{ test_multiplex }},{{ test_next_query_flagin }}' + + - name: "{{ role_name }} | {{ current_test }} | confirm delete query rule did make a change to runtime" + assert: + that: runtime_result1.stdout == '{{ test_user }},{{ test_match_pattern }},{{ test_destination_hostgroup }},{{ test_active }},{{ test_retries }},{{ test_cache_ttl }},{{ test_multiplex }},{{ test_next_query_flagin }}' + ### perform cleanup - name: "{{ role_name }} | {{ current_test }} | ensure we're in a clean state when we finish" diff --git a/tests/integration/targets/test_proxysql_query_rules/tasks/test_delete_query_rule_with_delayed_persist.yml b/tests/integration/targets/test_proxysql_query_rules/tasks/test_delete_query_rule_with_delayed_persist.yml index 5ef8c47..397d76d 100644 --- a/tests/integration/targets/test_proxysql_query_rules/tasks/test_delete_query_rule_with_delayed_persist.yml +++ b/tests/integration/targets/test_proxysql_query_rules/tasks/test_delete_query_rule_with_delayed_persist.yml @@ -6,24 +6,45 @@ - include_tasks: base_test.yml ### then - -- name: "{{ role_name }} | {{ current_test }} | check if delete query rule reported a change" - assert: - that: - - "status is {{ test_proxysql_query_rules_check_idempotence|ternary('not changed', 'changed') }}" - -- name: "{{ role_name }} | {{ current_test }} | confirm delete query rule did make a change in memory" - assert: - that: memory_result.stdout|length == 0 - -- name: "{{ role_name }} | {{ current_test }} | confirm delete query rule did make a change on disk" - assert: - that: disk_result.stdout|length == 0 - -- name: "{{ role_name }} | {{ current_test }} | confirm delete query rule did make a change to runtime" - assert: - that: runtime_result.stdout|length == 0 - +- name: verify test against proxysql >= 2 + when: PROXYSQL2 + block: + - name: "{{ role_name }} | {{ current_test }} | check if delete query rule reported a change" + assert: + that: + - "status is {{ test_proxysql_query_rules_check_idempotence|ternary('not changed', 'changed') }}" + + - name: "{{ role_name }} | {{ current_test }} | confirm delete query rule did make a change in memory" + assert: + that: memory_result.stdout|length == 0 + + - name: "{{ role_name }} | {{ current_test }} | confirm delete query rule did make a change on disk" + assert: + that: disk_result.stdout|length == 0 + + - name: "{{ role_name }} | {{ current_test }} | confirm delete query rule did make a change to runtime" + assert: + that: runtime_result.stdout|length == 0 + +- name: verify test against proxysql < 2 + when: not PROXYSQL2 + block: + - name: "{{ role_name }} | {{ current_test }} | check if delete query rule reported a change" + assert: + that: + - "status1 is {{ test_proxysql_query_rules_check_idempotence|ternary('not changed', 'changed') }}" + + - name: "{{ role_name }} | {{ current_test }} | confirm delete query rule did make a change in memory" + assert: + that: memory_result1.stdout|length == 0 + + - name: "{{ role_name }} | {{ current_test }} | confirm delete query rule did make a change on disk" + assert: + that: disk_result1.stdout|length == 0 + + - name: "{{ role_name }} | {{ current_test }} | confirm delete query rule did make a change to runtime" + assert: + that: runtime_result1.stdout|length == 0 ### perform cleanup - name: "{{ role_name }} | {{ current_test }} | ensure we're in a clean state when we finish" diff --git a/tests/integration/targets/test_proxysql_query_rules/tasks/test_delete_using_check_mode.yml b/tests/integration/targets/test_proxysql_query_rules/tasks/test_delete_using_check_mode.yml index ceed1e9..17b8f2c 100644 --- a/tests/integration/targets/test_proxysql_query_rules/tasks/test_delete_using_check_mode.yml +++ b/tests/integration/targets/test_proxysql_query_rules/tasks/test_delete_using_check_mode.yml @@ -7,22 +7,45 @@ ### then -- name: "{{ role_name }} | {{ current_test }} | check if delete query rule in check mode reported a change" - assert: - that: - - status is changed - -- name: "{{ role_name }} | {{ current_test }} | confirm delete query rule in check mode didn't make a change in memory" - assert: - that: memory_result.stdout == '{{ test_user }},{{ test_match_pattern }},{{ test_destination_hostgroup }},{{ test_active }},{{ test_retries }},{{ test_cache_ttl }},{{ test_cache_empty_result }},{{ test_multiplex }},{{ test_next_query_flagin }}' - -- name: "{{ role_name }} | {{ current_test }} | confirm delete query rule in check mode didn't make a change on disk" - assert: - that: disk_result.stdout == '{{ test_user }},{{ test_match_pattern }},{{ test_destination_hostgroup }},{{ test_active }},{{ test_retries }},{{ test_cache_ttl }},{{ test_cache_empty_result }},{{ test_multiplex }},{{ test_next_query_flagin }}' - -- name: "{{ role_name }} | {{ current_test }} | confirm delete query rule in check mode didn't make a change to runtime" - assert: - that: runtime_result.stdout == '{{ test_user }},{{ test_match_pattern }},{{ test_destination_hostgroup }},{{ test_active }},{{ test_retries }},{{ test_cache_ttl }},{{ test_cache_empty_result }},{{ test_multiplex }},{{ test_next_query_flagin }}' +- name: verify test against proxysql >= 2 + when: PROXYSQL2 + block: + - name: "{{ role_name }} | {{ current_test }} | check if delete query rule in check mode reported a change" + assert: + that: + - status is changed + + - name: "{{ role_name }} | {{ current_test }} | confirm delete query rule in check mode didn't make a change in memory" + assert: + that: memory_result.stdout == '{{ test_user }},{{ test_match_pattern }},{{ test_destination_hostgroup }},{{ test_active }},{{ test_retries }},{{ test_cache_ttl }},{{ test_cache_empty_result }},{{ test_multiplex }},{{ test_next_query_flagin }}' + + - name: "{{ role_name }} | {{ current_test }} | confirm delete query rule in check mode didn't make a change on disk" + assert: + that: disk_result.stdout == '{{ test_user }},{{ test_match_pattern }},{{ test_destination_hostgroup }},{{ test_active }},{{ test_retries }},{{ test_cache_ttl }},{{ test_cache_empty_result }},{{ test_multiplex }},{{ test_next_query_flagin }}' + + - name: "{{ role_name }} | {{ current_test }} | confirm delete query rule in check mode didn't make a change to runtime" + assert: + that: runtime_result.stdout == '{{ test_user }},{{ test_match_pattern }},{{ test_destination_hostgroup }},{{ test_active }},{{ test_retries }},{{ test_cache_ttl }},{{ test_cache_empty_result }},{{ test_multiplex }},{{ test_next_query_flagin }}' + +- name: verify test against proxysql < 2 + when: not PROXYSQL2 + block: + - name: "{{ role_name }} | {{ current_test }} | check if delete query rule in check mode reported a change" + assert: + that: + - status1 is changed + + - name: "{{ role_name }} | {{ current_test }} | confirm delete query rule in check mode didn't make a change in memory" + assert: + that: memory_result1.stdout == '{{ test_user }},{{ test_match_pattern }},{{ test_destination_hostgroup }},{{ test_active }},{{ test_retries }},{{ test_cache_ttl }},{{ test_multiplex }},{{ test_next_query_flagin }}' + + - name: "{{ role_name }} | {{ current_test }} | confirm delete query rule in check mode didn't make a change on disk" + assert: + that: disk_result1.stdout == '{{ test_user }},{{ test_match_pattern }},{{ test_destination_hostgroup }},{{ test_active }},{{ test_retries }},{{ test_cache_ttl }},{{ test_multiplex }},{{ test_next_query_flagin }}' + + - name: "{{ role_name }} | {{ current_test }} | confirm delete query rule in check mode didn't make a change to runtime" + assert: + that: runtime_result1.stdout == '{{ test_user }},{{ test_match_pattern }},{{ test_destination_hostgroup }},{{ test_active }},{{ test_retries }},{{ test_cache_ttl }},{{ test_multiplex }},{{ test_next_query_flagin }}' ### perform cleanup