New module: proxysql_query_rules_fast_routing (#26)

* added new module: proxysql_query_rules_fast_routing

* fixed sanity and integration test issues

* added changelog fragment

* fixed issue in main module func

* fixed syntax issues, typos

* fixed typi in integration test

* updated tests

* Update plugins/modules/proxysql_query_rules_fast_routing.py

Co-authored-by: Andrew Klychkov <aaklychkov@mail.ru>

* Update plugins/modules/proxysql_query_rules_fast_routing.py

Co-authored-by: Andrew Klychkov <aaklychkov@mail.ru>

* Update plugins/modules/proxysql_query_rules_fast_routing.py

Co-authored-by: Andrew Klychkov <aaklychkov@mail.ru>

* Update plugins/modules/proxysql_query_rules_fast_routing.py

Co-authored-by: Andrew Klychkov <aaklychkov@mail.ru>

* Update plugins/modules/proxysql_query_rules_fast_routing.py

Co-authored-by: Andrew Klychkov <aaklychkov@mail.ru>

* Update plugins/modules/proxysql_query_rules_fast_routing.py

Co-authored-by: Andrew Klychkov <aaklychkov@mail.ru>

* Update plugins/modules/proxysql_query_rules_fast_routing.py

Co-authored-by: Andrew Klychkov <aaklychkov@mail.ru>

* Update plugins/modules/proxysql_query_rules_fast_routing.py

Co-authored-by: Andrew Klychkov <aaklychkov@mail.ru>

* resolved issue

* removed changelog fragment

* Update plugins/modules/proxysql_query_rules_fast_routing.py

Co-authored-by: Andrew Klychkov <aaklychkov@mail.ru>

* Updates for query rules fast routing (#1)

fixed syntax, updated integration tests

* skipping previously ignored tests for ansible:devel

* Update plugins/modules/proxysql_query_rules_fast_routing.py

* Update plugins/modules/proxysql_query_rules_fast_routing.py

Co-authored-by: Andrew Klychkov <aaklychkov@mail.ru>

* Update plugins/modules/proxysql_query_rules_fast_routing.py

Co-authored-by: Andrew Klychkov <aaklychkov@mail.ru>

* Update plugins/modules/proxysql_query_rules_fast_routing.py

Co-authored-by: Andrew Klychkov <aaklychkov@mail.ru>

* Update plugins/modules/proxysql_query_rules_fast_routing.py

Co-authored-by: Andrew Klychkov <aaklychkov@mail.ru>

* Update plugins/modules/proxysql_query_rules_fast_routing.py

Co-authored-by: Andrew Klychkov <aaklychkov@mail.ru>

* Update plugins/modules/proxysql_query_rules_fast_routing.py

Co-authored-by: Andrew Klychkov <aaklychkov@mail.ru>

* resolved part of issues

* Update plugins/modules/proxysql_query_rules_fast_routing.py

Co-authored-by: Andrew Klychkov <aaklychkov@mail.ru>

* Update plugins/modules/proxysql_query_rules_fast_routing.py

Co-authored-by: Andrew Klychkov <aaklychkov@mail.ru>

* Update plugins/modules/proxysql_query_rules_fast_routing.py

Co-authored-by: Andrew Klychkov <aaklychkov@mail.ru>

* resolved a part of issues

* Update plugins/modules/proxysql_query_rules_fast_routing.py

Co-authored-by: Andrew Klychkov <aaklychkov@mail.ru>

* resolved a part of issues

* Update plugins/modules/proxysql_query_rules_fast_routing.py

Co-authored-by: Andrew Klychkov <aaklychkov@mail.ru>

* Update plugins/modules/proxysql_query_rules_fast_routing.py

Co-authored-by: Andrew Klychkov <aaklychkov@mail.ru>

* Update plugins/modules/proxysql_query_rules_fast_routing.py

Co-authored-by: Andrew Klychkov <aaklychkov@mail.ru>

* Update plugins/modules/proxysql_query_rules_fast_routing.py

Co-authored-by: Markus Bergholz <git@osuv.de>

Co-authored-by: Andrew Klychkov <aaklychkov@mail.ru>
Co-authored-by: Markus Bergholz <git@osuv.de>
local_integrationtest
Akim Lindberg 1 year ago committed by GitHub
parent 03ebf72763
commit 04db3bd8f7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 436
      plugins/modules/proxysql_query_rules_fast_routing.py
  2. 12
      tests/integration/targets/test_proxysql_query_rules_fast_routing/defaults/main.yml
  3. 3
      tests/integration/targets/test_proxysql_query_rules_fast_routing/meta/main.yml
  4. 61
      tests/integration/targets/test_proxysql_query_rules_fast_routing/tasks/base_test.yml
  5. 12
      tests/integration/targets/test_proxysql_query_rules_fast_routing/tasks/cleanup_test_query_rules_fast_routing.yml
  6. 88
      tests/integration/targets/test_proxysql_query_rules_fast_routing/tasks/main.yml
  7. 12
      tests/integration/targets/test_proxysql_query_rules_fast_routing/tasks/setup_test_query_rules_fast_routing.yml
  8. 6
      tests/integration/targets/test_proxysql_query_rules_fast_routing/tasks/teardown.yml
  9. 31
      tests/integration/targets/test_proxysql_query_rules_fast_routing/tasks/test_create_query_rule_fast_routing.yml
  10. 31
      tests/integration/targets/test_proxysql_query_rules_fast_routing/tasks/test_create_query_rule_fast_routing_in_memory_only.yml
  11. 31
      tests/integration/targets/test_proxysql_query_rules_fast_routing/tasks/test_create_query_rule_fast_routing_with_delayed_persist.yml
  12. 30
      tests/integration/targets/test_proxysql_query_rules_fast_routing/tasks/test_create_using_check_mode.yml
  13. 31
      tests/integration/targets/test_proxysql_query_rules_fast_routing/tasks/test_delete_query_rule_fast_routing.yml
  14. 30
      tests/integration/targets/test_proxysql_query_rules_fast_routing/tasks/test_delete_query_rule_fast_routing_in_memory_only.yml
  15. 31
      tests/integration/targets/test_proxysql_query_rules_fast_routing/tasks/test_delete_query_rule_fast_routing_with_delayed_persist.yml
  16. 30
      tests/integration/targets/test_proxysql_query_rules_fast_routing/tasks/test_delete_using_check_mode.yml
  17. 2
      tests/sanity/skip-2.12.txt

@ -0,0 +1,436 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
# Copyright: (c) 2017, Ansible Project
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import absolute_import, division, print_function
__metaclass__ = type
DOCUMENTATION = '''
---
module: proxysql_query_rules_fast_routing
author: "Akim Lindberg (@akimrx)"
short_description: Modifies query rules for fast routing policies using the proxysql admin interface
description:
- The M(community.proxysql.proxysql_query_rules_fast_routing) module modifies query rules for fast
routing policies and attributes using the proxysql admin interface.
options:
username:
description:
- Filtering criteria matching username, a query will match only if the connection is made with
the correct username.
type: str
required: True
schemaname:
description:
- Filtering criteria matching schemaname, a query will match only if the connection uses
schemaname as its default schema.
type: str
required: True
flagIN:
description:
- Evaluated in the same way as I(flagIN) is in B(mysql_query_rules) and correlates to the
I(flagOUT/apply) specified in the B(mysql_query_rules) table.
(see M(community.proxysql.proxysql_query_rules)).
type: int
default: 0
destination_hostgroup:
description:
- Route matched queries to this hostgroup. This happens unless there is a
started transaction and the logged in user has
I(transaction_persistent) set to C(True) (refer to M(community.proxysql.proxysql_mysql_users)).
type: int
required: True
comment:
description:
- Free form text field, usable for a descriptive comment of the query rule.
type: str
default: ''
state:
description:
- When C(present), adds the rule. When C(absent), removes the rule.
type: str
choices: [ "present", "absent" ]
default: present
force_delete:
description:
- By default, we avoid deleting more than one schedule in a single batch;
however, if you need this behaviour and you are not concerned about the
schedules deleted, you can set I(force_delete) to C(True).
type: bool
default: False
notes:
- Supports C(check_mode).
extends_documentation_fragment:
- community.proxysql.proxysql.managing_config
- community.proxysql.proxysql.connectivity
'''
EXAMPLES = '''
---
# This example adds a rule for fast routing
- name: Add a rule
community.proxysql.proxysql_query_rules_fast_routing:
login_user: admin
login_password: admin
username: 'user_ro'
schemaname: 'default'
destination_hostgroup: 1
comment: 'fast route user_ro to default schema'
state: present
save_to_disk: yes
load_to_runtime: yes
'''
RETURN = '''
stdout:
description: The mysql user modified or removed from proxysql.
returned: On create/update will return the newly modified rule, in all
other cases will return a list of rules that match the supplied
criteria.
type: dict
"sample": {
"changed": true,
"msg": "Added rule to mysql_query_rules_fast_routing",
"rules": [
{
"username": "user_ro",
"schemaname": "default",
"destination_hostgroup": 1,
"flagIN": "0",
"comment": ""
}
],
"state": "present"
}
'''
from ansible.module_utils.basic import AnsibleModule
from ansible_collections.community.proxysql.plugins.module_utils.mysql import mysql_connect, mysql_driver, mysql_driver_fail_msg
from ansible.module_utils.six import iteritems
from ansible.module_utils._text import to_native
# ===========================================
# proxysql module specific support methods.
#
def perform_checks(module):
if module.params["login_port"] < 0 or module.params["login_port"] > 65535:
module.fail_json(msg="login_port must be a valid unix port number (0-65535)")
if mysql_driver is None:
module.fail_json(msg=mysql_driver_fail_msg)
def save_config_to_disk(cursor):
cursor.execute("SAVE MYSQL QUERY RULES TO DISK")
return True
def load_config_to_runtime(cursor):
cursor.execute("LOAD MYSQL QUERY RULES TO RUNTIME")
return True
class ProxyQueryRuleFastRouting(object):
def __init__(self, module):
self.state = module.params["state"]
self.force_delete = module.params["force_delete"]
self.save_to_disk = module.params["save_to_disk"]
self.load_to_runtime = module.params["load_to_runtime"]
config_data_keys = [
"username",
"schemaname",
"flagIN",
"destination_hostgroup",
"comment"
]
self.config_data = dict(
(k, module.params[k])
for k in config_data_keys
)
def check_rule_pk_exists(self, cursor):
query_string = (
"SELECT count(*) AS `rule_count` "
"FROM mysql_query_rules_fast_routing "
"WHERE username = %s "
"AND schemaname = %s "
"AND flagIN = %s"
)
query_data = [
self.config_data["username"],
self.config_data["schemaname"],
self.config_data["flagIN"],
]
cursor.execute(query_string, query_data)
check_count = cursor.fetchone()
return (int(check_count['rule_count']) > 0)
def check_rule_cfg_exists(self, cursor):
query_string = "SELECT count(*) AS `rule_count` FROM mysql_query_rules_fast_routing"
cols = 0
query_data = []
for col, val in iteritems(self.config_data):
if val is not None:
cols += 1
query_data.append(val)
if cols == 1:
query_string += " WHERE " + col + " = %s"
else:
query_string += " AND " + col + " = %s"
if cols > 0:
cursor.execute(query_string, query_data)
else:
cursor.execute(query_string)
check_count = cursor.fetchone()
return int(check_count['rule_count'])
def get_rule_config(self, cursor):
query_string = (
"SELECT * "
"FROM mysql_query_rules_fast_routing "
"WHERE username = %s "
"AND schemaname = %s "
"AND flagIN = %s"
)
query_data = [
self.config_data["username"],
self.config_data["schemaname"],
self.config_data["flagIN"]
]
for col, val in iteritems(self.config_data):
if val is not None:
query_data.append(val)
query_string += " AND " + col + " = %s"
cursor.execute(query_string, query_data)
rule = cursor.fetchall()
return rule
def create_rule_config(self, cursor):
query_string = "INSERT INTO mysql_query_rules_fast_routing ("
cols = 0
query_data = []
for col, val in iteritems(self.config_data):
if val is not None:
cols += 1
query_data.append(val)
query_string += col + ","
query_string = query_string[:-1]
query_string += ") VALUES (" + "%s, " * cols
query_string = query_string[:-2]
query_string += ")"
cursor.execute(query_string, query_data)
return True
def update_rule_config(self, cursor):
query_string = "UPDATE mysql_query_rules_fast_routing"
cols = 0
query_data = [
self.config_data["username"],
self.config_data["schemaname"],
self.config_data["flagIN"]
]
for col, val in iteritems(self.config_data):
if val is not None and col not in ("username", "schemaname", "flagIN"):
cols += 1
query_data.append(val)
if cols == 1:
query_string += " SET " + col + "= %s,"
else:
query_string += " " + col + " = %s,"
query_string = query_string[:-1]
query_string += (
"WHERE username = %s "
"AND schemaname = %s "
"AND flagIN = %s"
)
cursor.execute(query_string, query_data)
return True
def delete_rule_config(self, cursor):
query_string = "DELETE FROM mysql_query_rules_fast_routing"
cols = 0
query_data = []
for col, val in iteritems(self.config_data):
if val is not None:
cols += 1
query_data.append(val)
if cols == 1:
query_string += " WHERE " + col + " = %s"
else:
query_string += " AND " + col + " = %s"
if cols > 0:
cursor.execute(query_string, query_data)
else:
cursor.execute(query_string)
check_count = cursor.rowcount
return True, int(check_count)
def manage_config(self, cursor, changed):
if not changed:
return
if self.save_to_disk:
save_config_to_disk(cursor)
if self.load_to_runtime:
load_config_to_runtime(cursor)
def create_rule(self, check_mode, result, cursor):
if not check_mode:
result['changed'] = self.create_rule_config(cursor)
result['msg'] = "Added rule to mysql_query_rules_fast_routing."
self.manage_config(cursor, result['changed'])
result['rules'] = self.get_rule_config(cursor)
else:
result['changed'] = True
result['msg'] = (
"Rule would have been added to "
"mysql_query_rules_fast_routing, "
"however check_mode is enabled."
)
def update_rule(self, check_mode, result, cursor):
if not check_mode:
result['changed'] = self.update_rule_config(cursor)
result['msg'] = "Updated rule in mysql_query_rules_fast_routing."
self.manage_config(cursor, result['changed'])
result['rules'] = self.get_rule_config(cursor)
else:
result['changed'] = True
result['msg'] = (
"Rule would have been updated in "
"mysql_query_rules_fast_routing, "
"however check_mode is enabled."
)
def delete_rule(self, check_mode, result, cursor):
if not check_mode:
result['rules'] = self.get_rule_config(cursor)
result['changed'], result['rows_affected'] = self.delete_rule_config(cursor)
result['msg'] = "Deleted rule from mysql_query_rules_fast_routing."
self.manage_config(cursor, result['changed'])
else:
result['changed'] = True
result['msg'] = (
"Rule would have been deleted from "
"mysql_query_rules_fast_routing, "
"however check_mode is enabled."
)
# ===========================================
# Module execution.
#
def main():
module = AnsibleModule(
argument_spec=dict(
login_user=dict(default=None, type='str'),
login_password=dict(default=None, no_log=True, type='str'),
login_host=dict(default="127.0.0.1"),
login_unix_socket=dict(default=None),
login_port=dict(default=6032, type='int'),
config_file=dict(default="", type='path'),
username=dict(required=True, type='str'),
schemaname=dict(required=True, type='str'),
destination_hostgroup=dict(required=True, type='int'),
flagIN=dict(default=0, type='int'),
comment=dict(default='', type='str'),
state=dict(default='present', choices=['present', 'absent']),
force_delete=dict(default=False, type='bool'),
save_to_disk=dict(default=True, type='bool'),
load_to_runtime=dict(default=True, type='bool')
),
supports_check_mode=True
)
perform_checks(module)
login_user = module.params["login_user"]
login_password = module.params["login_password"]
config_file = module.params["config_file"]
cursor = None
try:
cursor, db_conn = mysql_connect(
module,
login_user,
login_password,
config_file,
cursor_class='DictCursor'
)
except mysql_driver.Error as e:
module.fail_json(msg="unable to connect to ProxySQL Admin Module: %s" % to_native(e))
query_rule = ProxyQueryRuleFastRouting(module)
result = {}
result['state'] = query_rule.state
if query_rule.state == "present":
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.update_rule(module.check_mode, result, cursor)
else:
query_rule.create_rule(module.check_mode, result, cursor)
else:
result['changed'] = False
result['msg'] = (
"The rule already exists in "
"mysql_query_rules_fast_routing "
"and doesn't need to be updated."
)
result['rules'] = query_rule.get_rule_config(cursor)
except mysql_driver.Error as e:
module.fail_json(msg="unable to modify rule: %s" % to_native(e))
elif query_rule.state == "absent":
try:
existing_rules = query_rule.check_rule_cfg_exists(cursor)
if existing_rules > 0:
if existing_rules == 1 or query_rule.force_delete:
query_rule.delete_rule(module.check_mode, result, cursor)
else:
module.fail_json(msg=("Operation would delete multiple rules use force_delete to override this."))
else:
result['changed'] = False
result['msg'] = (
"The rule is already absent from the "
"mysql_query_rules_fast_routing memory "
"configuration"
)
except mysql_driver.Error as e:
module.fail_json(msg="unable to remove rule: %s" % to_native(e))
module.exit_json(**result)
if __name__ == '__main__':
main()

@ -0,0 +1,12 @@
---
test_user: 'user_ro'
test_schema: 'default'
test_flagin: 0
test_destination_hostgroup: 1
test_comment: 'testing fast route'
test_proxysql_query_rules_fast_routing_check_mode: false
test_proxysql_query_rules_fast_routing_in_memory_only: false
test_proxysql_query_rules_fast_routing_with_delayed_persist: false
test_proxysql_query_rules_fast_routing_check_idempotence: false
test_proxysql_query_rules_fast_routing_cleanup_after_test: true

@ -0,0 +1,61 @@
---
### prepare
- name: "{{ role_name }} | {{ current_test }} | are we performing a delete"
set_fact:
test_delete: "{{ current_test | regex_search('^test_delete') | ternary(true, false) }}"
- name: "{{ role_name }} | {{ current_test }} | ensure we're in a clean state when we start"
include_tasks: "{{ test_delete|ternary('setup_test_query_rules_fast_routing', 'cleanup_test_query_rules_fast_routing') }}.yml"
when: not test_proxysql_query_rules_fast_routing_check_idempotence
### when
- name: "{{ role_name }} | {{ current_test }} | {{ test_delete|ternary('delete','create') }} test query rules fast routing"
proxysql_query_rules_fast_routing:
login_user: admin
login_password: admin
username: '{{ test_user }}'
destination_hostgroup: '{{ test_destination_hostgroup }}'
schemaname: '{{ test_schema }}'
flagIN: '{{ test_flagin }}'
comment: '{{ test_comment }}'
state: "{{ test_delete|ternary('absent', 'present') }}"
save_to_disk: "{{ not test_proxysql_query_rules_fast_routing_in_memory_only }}"
load_to_runtime: "{{ not test_proxysql_query_rules_fast_routing_in_memory_only }}"
check_mode: "{{ test_proxysql_query_rules_fast_routing_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 fast routing 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 fast routing 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_fast_routing_with_delayed_persist
- name: "{{ role_name }} | {{ current_test }} | check if test query rule fast routing exists in memory"
shell: mysql -uadmin -padmin -h127.0.0.1 -P6032 -BNe"SELECT username || ',' || schemaname || ',' || destination_hostgroup || ',' || flagIN || ',' || comment FROM mysql_query_rules_fast_routing where username = '{{ test_user }}' and schemaname = '{{ test_schema }}' and destination_hostgroup = '{{ test_destination_hostgroup }}' and flagIN = '{{ test_flagin }}' and comment = '{{ test_comment }}'"
register: memory_result
- name: "{{ role_name }} | {{ current_test }} | check if test query rule fast routing exists on disk"
shell: mysql -uadmin -padmin -h127.0.0.1 -P6032 -BNe"SELECT username || ',' || schemaname || ',' || destination_hostgroup || ',' || flagIN || ',' || comment FROM disk.mysql_query_rules_fast_routing where username = '{{ test_user }}' and schemaname = '{{ test_schema }}' and destination_hostgroup = '{{ test_destination_hostgroup }}' and flagIN = '{{ test_flagin }}' and comment = '{{ test_comment }}'"
register: disk_result
- name: "{{ role_name }} | {{ current_test }} | check if test query rule fast routing exists in runtime"
shell: mysql -uadmin -padmin -h127.0.0.1 -P6032 -BNe"SELECT username || ',' || schemaname || ',' || destination_hostgroup || ',' || flagIN || ',' || comment FROM runtime_mysql_query_rules_fast_routing where username = '{{ test_user }}' and schemaname = '{{ test_schema }}' and destination_hostgroup = '{{ test_destination_hostgroup }}' and flagIN = '{{ test_flagin }}' and comment = '{{ test_comment }}'"
register: runtime_result

@ -0,0 +1,12 @@
---
- name: "{{ role_name }} | {{ current_test }} | ensure we're in a clean state when we start/finish"
block:
- name: "{{ role_name }} | {{ current_test }} | ensure no query rules fast routing are created"
shell: mysql -uadmin -padmin -h127.0.0.1 -P6032 -BNe"DELETE FROM mysql_query_rules_fast_routing"
- name: "{{ role_name }} | {{ current_test }} | ensure no query rules fast routing are saved on disk"
shell: mysql -uadmin -padmin -h127.0.0.1 -P6032 -BNe"SAVE MYSQL QUERY RULES TO DISK"
- name: "{{ role_name }} | {{ current_test }} | ensure no query rules fast routing are loaded to runtime"
shell: mysql -uadmin -padmin -h127.0.0.1 -P6032 -BNe"LOAD MYSQL QUERY RULES TO RUNTIME"

@ -0,0 +1,88 @@
---
####################################################################
# WARNING: These are designed specifically for Ansible tests #
# and should not be used as examples of how to write Ansible roles #
####################################################################
### tests
- name: "{{ role_name }} | test_create_using_check_mode | test create query rule fast routing using check mode"
import_tasks: test_create_using_check_mode.yml
vars:
test_proxysql_query_rules_fast_routing_check_mode: true
- name: "{{ role_name }} | test_delete_using_check_mode | test delete query rule fast routing using check mode"
import_tasks: test_delete_using_check_mode.yml
vars:
test_proxysql_query_rules_fast_routing_check_mode: true
- name: "{{ role_name }} | test_create_query_rule_fast_routing | test create query rule fast routing"
import_tasks: test_create_query_rule_fast_routing.yml
vars:
test_proxysql_query_rules_fast_routing_cleanup_after_test: false
- name: "{{ role_name }} | test_create_query_rule_fast_routing | test idempotence of create query rule fast routing"
import_tasks: test_create_query_rule_fast_routing.yml
vars:
test_proxysql_query_rules_fast_routing_check_idempotence: true
- name: "{{ role_name }} | test_delete_query_rule_fast_routing | test delete query rule fast routing"
import_tasks: test_delete_query_rule_fast_routing.yml
vars:
test_proxysql_query_rules_fast_routing_cleanup_after_test: false
- name: "{{ role_name }} | test_delete_query_rule_fast_routing | test idempotence of delete query rule fast routing"
import_tasks: test_delete_query_rule_fast_routing.yml
vars:
test_proxysql_query_rules_fast_routing_check_idempotence: true
- name: "{{ role_name }} | test_create_query_rule_fast_routing_in_memory_only | test create query rule fast routing in memory"
import_tasks: test_create_query_rule_fast_routing_in_memory_only.yml
vars:
test_proxysql_query_rules_fast_routing_in_memory_only: true
test_proxysql_query_rules_fast_routing_cleanup_after_test: false
- name: "{{ role_name }} | test_create_query_rule_fast_routing_in_memory_only | test idempotence of create query rule fast routing in memory"
import_tasks: test_create_query_rule_fast_routing_in_memory_only.yml
vars:
test_proxysql_query_rules_fast_routing_in_memory_only: true
test_proxysql_query_rules_fast_routing_check_idempotence: true
- name: "{{ role_name }} | test_delete_query_rule_fast_routing_in_memory_only | test delete query rule fast routing in memory"
import_tasks: test_delete_query_rule_fast_routing_in_memory_only.yml
vars:
test_proxysql_query_rules_fast_routing_in_memory_only: true
test_proxysql_query_rules_fast_routing_cleanup_after_test: false
- name: "{{ role_name }} | test_delete_query_rule_fast_routing_in_memory_only | test idempotence of delete query rule fast routing in memory"
import_tasks: test_delete_query_rule_fast_routing_in_memory_only.yml
vars:
test_proxysql_query_rules_fast_routing_in_memory_only: true
test_proxysql_query_rules_fast_routing_check_idempotence: true
- name: "{{ role_name }} | test_create_query_rule_fast_routing_with_delayed_persist | test create query rule fast routing with delayed save to disk/load to runtime"
import_tasks: test_create_query_rule_fast_routing_with_delayed_persist.yml
vars:
test_proxysql_query_rules_fast_routing_in_memory_only: true
test_proxysql_query_rules_fast_routing_with_delayed_persist: true
test_proxysql_query_rules_fast_routing_cleanup_after_test: false
- name: "{{ role_name }} | test_create_query_rule_fast_routing__with_delayed_persist | test idempotence of create query rule fast routing with delayed save to disk/load to runtime"
import_tasks: test_create_query_rule_fast_routing_with_delayed_persist.yml
vars:
test_proxysql_query_rules_fast_routing_in_memory_only: true
test_proxysql_query_rules_fast_routing_with_delayed_persist: true
test_proxysql_query_rules_fast_routing_check_idempotence: true
- name: "{{ role_name }} | test_delete_query_rule_fast_routing__with_delayed_persist | test delete query rule fast routing with delayed save to disk/load to runtime"
import_tasks: test_delete_query_rule_fast_routing_with_delayed_persist.yml
vars:
test_proxysql_query_rules_fast_routing_in_memory_only: true
test_proxysql_query_rules_fast_routing_with_delayed_persist: true
test_proxysql_query_rules_fast_routing_cleanup_after_test: false
- name: "{{ role_name }} | test_delete_query_rule_fast_routing_with_delayed_persist | test idempotence of delete query rule fast routing with delayed save to disk/load to runtime"
import_tasks: test_delete_query_rule_fast_routing_with_delayed_persist.yml
vars:
test_proxysql_query_rules_fast_routing_in_memory_only: true
test_proxysql_query_rules_fast_routing_with_delayed_persist: true
test_proxysql_query_rules_fast_routing_check_idempotence: true
### teardown
- name: "{{ role_name }} | teardown | perform teardown"
import_tasks: teardown.yml

@ -0,0 +1,12 @@
---
- name: "{{ role_name }} | {{ current_test }} | ensure test query rule fast routing is created when we start"
block:
- name: "{{ role_name }} | {{ current_test }} | ensure test query rule fast routing is created in memory"
shell: mysql -uadmin -padmin -h127.0.0.1 -P6032 -BNe"INSERT OR REPLACE INTO mysql_query_rules_fast_routing (username, schemaname, destination_hostgroup, flagIN, comment) VALUES ('{{ test_user }}', '{{ test_schema }}', '{{ test_destination_hostgroup }}', '{{ test_flagin }}', '{{ test_comment }}')"
- name: "{{ role_name }} | {{ current_test }} | ensure test query rule fast routing is created on disk"
shell: mysql -uadmin -padmin -h127.0.0.1 -P6032 -BNe"SAVE MYSQL QUERY RULES TO DISK"
- name: "{{ role_name }} | {{ current_test }} | ensure test query rule fast routing is created in runtime"
shell: mysql -uadmin -padmin -h127.0.0.1 -P6032 -BNe"LOAD MYSQL QUERY RULES TO RUNTIME"

@ -0,0 +1,6 @@
---
- name: "{{ role_name }} | teardown | uninstall proxysql"
apt:
name: proxysql
purge: true
state: absent

@ -0,0 +1,31 @@
---
- name: "{{ role_name }} | test_create_query_rule_fast_routing | set current test"
set_fact:
current_test: test_create_query_rule_fast_routing
- include_tasks: base_test.yml
### then
- name: "{{ role_name }} | {{ current_test }} | check if create query rule fast routing reported a change"
assert:
that:
- "status is {{ test_proxysql_query_rules_fast_routing_check_idempotence|ternary('not changed', 'changed') }}"
- name: "{{ role_name }} | {{ current_test }} | confirm create query rule fast routing did make a change in memory"
assert:
that: memory_result.stdout == '{{ test_user }},{{ test_schema }},{{ test_destination_hostgroup }},{{ test_flagin }},{{ test_comment }}'
- name: "{{ role_name }} | {{ current_test }} | confirm create query rule fast routing did make a change on disk"
assert:
that: disk_result.stdout == '{{ test_user }},{{ test_schema }},{{ test_destination_hostgroup }},{{ test_flagin }},{{ test_comment }}'
- name: "{{ role_name }} | {{ current_test }} | confirm create query rule fast routing did make a change to runtime"
assert:
that: runtime_result.stdout == '{{ test_user }},{{ test_schema }},{{ test_destination_hostgroup }},{{ test_flagin }},{{ test_comment }}'
### perform cleanup
- name: "{{ role_name }} | {{ current_test }} | ensure we're in a clean state when we finish"
import_tasks: cleanup_test_query_rules_fast_routing.yml
when: test_proxysql_query_rules_fast_routing_cleanup_after_test

@ -0,0 +1,31 @@
---
- name: "{{ role_name }} | test_create_query_rule_fast_routing_in_memory_only | set current test"
set_fact:
current_test: test_create_query_rule_fast_routing_in_memory_only
- include_tasks: base_test.yml
### then
- name: "{{ role_name }} | {{ current_test }} | check if create query rule fast routing reported a change"
assert:
that:
- "status is {{ test_proxysql_query_rules_fast_routing_check_idempotence|ternary('not changed', 'changed') }}"
- name: "{{ role_name }} | {{ current_test }} | confirm create query rule fast routing did make a change in memory"
assert:
that: memory_result.stdout == '{{ test_user }},{{ test_schema }},{{ test_destination_hostgroup }},{{ test_flagin }},{{ test_comment }}'
- name: "{{ role_name }} | {{ current_test }} | confirm create query rule fast routing didn't make a change on disk"
assert:
that: disk_result.stdout|length == 0
- name: "{{ role_name }} | {{ current_test }} | confirm create query rule fast routing didn't make a change to runtime"
assert:
that: runtime_result.stdout|length == 0
### perform cleanup
- name: "{{ role_name }} | {{ current_test }} | ensure we're in a clean state when we finish"
import_tasks: cleanup_test_query_rules_fast_routing.yml
when: test_proxysql_query_rules_fast_routing_cleanup_after_test

@ -0,0 +1,31 @@
---
- name: "{{ role_name }} | test_create_query_rule_fast_routing_with_delayed_persist | set current test"
set_fact:
current_test: test_create_query_rule_fast_routing_with_delayed_persist
- include_tasks: base_test.yml
### then
- name: "{{ role_name }} | {{ current_test }} | check if create query rule fast routing reported a change"
assert:
that:
- "status is {{ test_proxysql_query_rules_fast_routing_check_idempotence|ternary('not changed', 'changed') }}"
- name: "{{ role_name }} | {{ current_test }} | confirm create query rule fast routing did make a change in memory"
assert:
that: memory_result.stdout == '{{ test_user }},{{ test_schema }},{{ test_destination_hostgroup }},{{ test_flagin }},{{ test_comment }}'
- name: "{{ role_name }} | {{ current_test }} | confirm create query rule fast routing did make a change on disk"
assert:
that: disk_result.stdout == '{{ test_user }},{{ test_schema }},{{ test_destination_hostgroup }},{{ test_flagin }},{{ test_comment }}'
- name: "{{ role_name }} | {{ current_test }} | confirm create query rule fast routing did make a change to runtime"
assert:
that: runtime_result.stdout == '{{ test_user }},{{ test_schema }},{{ test_destination_hostgroup }},{{ test_flagin }},{{ test_comment }}'
### perform cleanup
- name: "{{ role_name }} | {{ current_test }} | ensure we're in a clean state when we finish"
import_tasks: cleanup_test_query_rules_fast_routing.yml
when: test_proxysql_query_rules_fast_routing_cleanup_after_test

@ -0,0 +1,30 @@
---
- name: "{{ role_name }} | test_create_using_check_mode | set current test"
set_fact:
current_test: test_create_using_check_mode
- include_tasks: base_test.yml
### then
- name: "{{ role_name }} | {{ current_test }} | check if create query rule fast routing in check mode reported a change"
assert:
that:
- status is changed
- name: "{{ role_name }} | {{ current_test }} | confirm create query rule fast routing 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 fast routing 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 fast routing in check mode didn't make a change to runtime"
assert:
that: runtime_result.stdout|length == 0
### perform cleanup
- name: "{{ role_name }} | {{ current_test }} | ensure we're in a clean state when we finish"
import_tasks: cleanup_test_query_rules_fast_routing.yml

@ -0,0 +1,31 @@
---
- name: "{{ role_name }} | test_delete_query_rule_fast_routing | set current test"
set_fact:
current_test: test_delete_query_rule_fast_routing
- include_tasks: base_test.yml
### then
- name: "{{ role_name }} | {{ current_test }} | check if delete query rule fast routing reported a change"
assert:
that:
- "status is {{ test_proxysql_query_rules_fast_routing_check_idempotence|ternary('not changed', 'changed') }}"
- name: "{{ role_name }} | {{ current_test }} | confirm delete query rule fast routing did make a change in memory"
assert:
that: memory_result.stdout|length == 0
- name: "{{ role_name }} | {{ current_test }} | confirm delete query rule fast routing did make a change on disk"
assert:
that: disk_result.stdout|length == 0
- name: "{{ role_name }} | {{ current_test }} | confirm delete query rule fast routing did make a change to runtime"
assert:
that: runtime_result.stdout|length == 0
### perform cleanup
- name: "{{ role_name }} | {{ current_test }} | ensure we're in a clean state when we finish"
import_tasks: cleanup_test_query_rules_fast_routing.yml
when: test_proxysql_query_rules_fast_routing_cleanup_after_test

@ -0,0 +1,30 @@
---
- name: "{{ role_name }} | test_delete_query_rule_fast_routing_in_memory_only | set current test"
set_fact:
current_test: test_delete_query_rule_fast_routing_in_memory_only
- include_tasks: base_test.yml
### then
- name: "{{ role_name }} | {{ current_test }} | check if delete query rule fast routing reported a change"
assert:
that:
- "status is {{ test_proxysql_query_rules_fast_routing_check_idempotence|ternary('not changed', 'changed') }}"
- name: "{{ role_name }} | {{ current_test }} | confirm delete query rule fast routing didn't make a change in memory"
assert:
that: memory_result.stdout|length == 0
- name: "{{ role_name }} | {{ current_test }} | confirm delete query rule fast routing fast routing did make a change on disk"
assert:
that: disk_result.stdout == '{{ test_user }},{{ test_schema }},{{ test_destination_hostgroup }},{{ test_flagin }},{{ test_comment }}'
- name: "{{ role_name }} | {{ current_test }} | confirm delete query rule fast routing did make a change to runtime"
assert:
that: runtime_result.stdout == '{{ test_user }},{{ test_schema }},{{ test_destination_hostgroup }},{{ test_flagin }},{{ test_comment }}'
### perform cleanup
- name: "{{ role_name }} | {{ current_test }} | ensure we're in a clean state when we finish"
import_tasks: cleanup_test_query_rules_fast_routing.yml
when: test_proxysql_query_rules_fast_routing_cleanup_after_test

@ -0,0 +1,31 @@
---
- name: "{{ role_name }} | test_delete_query_rule_fast_routing_with_delayed_persist | set current test"
set_fact:
current_test: test_delete_query_rule_fast_routing_with_delayed_persist
- include_tasks: base_test.yml
### then
- name: "{{ role_name }} | {{ current_test }} | check if delete query rule fast routing reported a change"
assert:
that:
- "status is {{ test_proxysql_query_rules_fast_routing_check_idempotence|ternary('not changed', 'changed') }}"
- name: "{{ role_name }} | {{ current_test }} | confirm delete query rule fast routing did make a change in memory"
assert:
that: memory_result.stdout|length == 0
- name: "{{ role_name }} | {{ current_test }} | confirm delete query rule fast routing did make a change on disk"
assert:
that: disk_result.stdout|length == 0
- name: "{{ role_name }} | {{ current_test }} | confirm delete query rule fast routing did make a change to runtime"
assert:
that: runtime_result.stdout|length == 0
### perform cleanup
- name: "{{ role_name }} | {{ current_test }} | ensure we're in a clean state when we finish"
import_tasks: cleanup_test_query_rules_fast_routing.yml
when: test_proxysql_query_rules_fast_routing_cleanup_after_test

@ -0,0 +1,30 @@
---
- name: "{{ role_name }} | test_delete_using_check_mode | set current test"
set_fact:
current_test: test_delete_using_check_mode
- include_tasks: base_test.yml
### then
- name: "{{ role_name }} | {{ current_test }} | check if delete query rule fast routing in check mode reported a change"
assert:
that:
- status is changed
- name: "{{ role_name }} | {{ current_test }} | confirm delete query rule fast routing in check mode didn't make a change in memory"
assert:
that: memory_result.stdout == '{{ test_user }},{{ test_schema }},{{ test_destination_hostgroup }},{{ test_flagin }},{{ test_comment }}'
- name: "{{ role_name }} | {{ current_test }} | confirm delete query rule fast routing in check mode didn't make a change on disk"
assert:
that: disk_result.stdout == '{{ test_user }},{{ test_schema }},{{ test_destination_hostgroup }},{{ test_flagin }},{{ test_comment }}'
- name: "{{ role_name }} | {{ current_test }} | confirm delete query rule fast routing in check mode didn't make a change to runtime"
assert:
that: runtime_result.stdout == '{{ test_user }},{{ test_schema }},{{ test_destination_hostgroup }},{{ test_flagin }},{{ test_comment }}'
### perform cleanup
- name: "{{ role_name }} | {{ current_test }} | ensure we're in a clean state when we finish"
import_tasks: cleanup_test_query_rules_fast_routing.yml

@ -0,0 +1,2 @@
roles/proxysql/molecule/default/tests/test_default.py future-import-boilerplate
roles/proxysql/molecule/default/tests/test_default.py metaclass-boilerplate
Loading…
Cancel
Save