Cleanup after MySQL integration tests (#63641)

Add handlers to setup_mysql_db and setup_mysql8 to remove installed packages.
This commit is contained in:
Sam Doran 2019-10-23 11:11:02 -04:00 committed by GitHub
parent 68de182555
commit 3e4ae42256
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 151 additions and 32 deletions

View file

@ -1,4 +1,14 @@
repo_link: https://repo.mysql.com/mysql80-community-release-el7-3.noarch.rpm
repo_name: mysql-community
mysql_package_name: mysql-community-server
my_cnf: /etc/my.cnf
mysql_packages:
- mysql-community-server
- MySQL-python
mysql_cleanup_packages:
- mysql-community-client
- mysql-community-common
- mysql-community-libs
- mysql-community-libs-compat
- mysql-community-server
- mysql80-community-release

View file

@ -0,0 +1,24 @@
- name: stop mysql service
service:
name: mysqld
state: stopped
listen: cleanup mysql8
- name: remove repo
yum:
name: mysql80-community-release
state: absent
listen: cleanup mysql8
- name: remove mysql packages
yum:
name: '{{ mysql_packages | union(mysql_cleanup_packages) }}'
state: absent
listen: cleanup mysql8
- name: remove mysql data
file:
path: "{{ item }}"
state: absent
loop: "{{ mysql_data_dirs }}"
listen: cleanup mysql8

View file

@ -2,5 +2,17 @@
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
# Setup MySQL 8:
- name: Include distribution specific variables
include_vars: "{{ lookup('first_found', params) }}"
vars:
params:
files:
- '{{ ansible_facts.distribution }}-{{ ansible_facts.distribution_major_version }}.yml'
- '{{ ansible_facts.os_family }}.yml'
- 'default.yml'
paths: vars
- import_tasks: setup_mysql8.yml
when: ansible_distribution == 'CentOS' and ansible_distribution_major_version >= '7'
when:
- ansible_facts.distribution == 'CentOS'
- ansible_facts.distribution_major_version is version_compare('7', '>=')

View file

@ -1,13 +1,15 @@
# Copyright: (c) 2019, Andrew Klychkov (@Andersson007) <aaklychkov@mail.ru>
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
- name: Install Repo
- name: Install MySQL repo
yum:
name: '{{ repo_link }}'
notify: cleanup mysql8
- name: Install MySQL community server
yum:
name: '{{ mysql_package_name }}'
name: '{{ mysql_packages }}'
notify: cleanup mysql8
- name: Copy my.cnf
copy:
@ -31,8 +33,7 @@
shell: "echo \"SHOW VARIABLES LIKE '%version%';\" | mysql"
- name: Detect socket path
shell: >
echo "show variables like 'socket'\G" | mysql | grep 'Value: ' | sed 's/[ ]\+Value: //'
shell: 'echo "show variables like ''socket''\G" | mysql | grep ''Value: '' | sed ''s/[ ]\+Value: //'''
register: _socket_path
- name: Set socket path
@ -44,8 +45,7 @@
root_pass: "dlsafjlkjdsaK1#"
- name: Set root password
shell: >
echo "flush privileges; ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '{{ root_pass }}';" | mysql
shell: 'echo "flush privileges; ALTER USER ''root''@''localhost'' IDENTIFIED WITH mysql_native_password BY ''{{ root_pass }}'';" | mysql'
- name: Change configuration
lineinfile:

View file

@ -0,0 +1,3 @@
mysql_data_dirs:
- /var/lib/mysql
- /usr/share/mysql

View file

@ -0,0 +1,3 @@
mysql_data_dirs:
- /var/lib/mysql
- /usr/mysql

View file

@ -4,3 +4,15 @@ mysql_packages:
- mysql-server
- MySQL-python
- bzip2
mysql_cleanup_packages:
- mysql-community-client
- mysql-community-common
- mysql-community-libs
- mysql-community-libs-compat
- mysql-community-server
- mysql80-community-release
mysql_data_dirs:
- /var/lib/mysql
- /usr/mysql

View file

@ -0,0 +1,25 @@
- name: stop mysql service
service:
name: "{{ mysql_service }}"
state: stopped
listen: cleanup mysql
- name: remove mysql packages
action: '{{ ansible_pkg_mgr }}'
args:
name: "{{ item }}"
state: absent
loop: "{{ mysql_packages | union(mysql_cleanup_packages) }}"
listen: cleanup mysql
- name: remove mysql data
file:
path: "{{ item }}"
state: absent
loop: "{{ mysql_data_dirs }}"
listen: cleanup mysql
- name: remove pip packages
pip:
name: mysql-python
state: absent

View file

@ -27,47 +27,56 @@
python_suffix: "-py3"
when: ansible_python_version is version('3', '>=')
- include_vars: '{{ item }}'
with_first_found:
- files:
- '{{ ansible_distribution }}-{{ ansible_distribution_major_version }}{{ python_suffix }}.yml'
- '{{ ansible_distribution }}-{{ ansible_distribution_major_version }}.yml'
- '{{ ansible_os_family }}-{{ ansible_distribution_major_version }}{{ python_suffix }}.yml'
- '{{ ansible_distribution }}{{ python_suffix }}.yml'
- '{{ ansible_os_family }}{{ python_suffix }}.yml'
- name: Include distribution specific variables
include_vars: "{{ lookup('first_found', params) }}"
vars:
params:
files:
- '{{ ansible_facts.distribution }}-{{ ansible_facts.distribution_major_version }}{{ python_suffix }}.yml'
- '{{ ansible_facts.distribution }}-{{ ansible_facts.distribution_major_version }}.yml'
- '{{ ansible_facts.os_family }}-{{ ansible_facts.distribution_major_version }}{{ python_suffix }}.yml'
- '{{ ansible_facts.distribution }}{{ python_suffix }}.yml'
- '{{ ansible_facts.os_family }}{{ python_suffix }}.yml'
- 'default{{ python_suffix }}.yml'
paths: '../vars'
paths: vars
- name: install mysqldb_test rpm dependencies
yum: name={{ item }} state=latest
with_items: "{{mysql_packages}}"
when: ansible_pkg_mgr == 'yum'
yum:
name: "{{ mysql_packages }}"
state: latest
when: ansible_pkg_mgr == 'yum'
notify: cleanup mysql
- name: install mysqldb_test rpm dependencies
dnf:
name: '{{ item }}'
name: '{{ mysql_packages }}'
state: latest
install_weak_deps: False # mariadb-server has a weak dep on python2 which break Python 3 test environments
with_items: "{{mysql_packages}}"
when: ansible_pkg_mgr == 'dnf'
when: ansible_pkg_mgr == 'dnf'
notify: cleanup mysql
- name: install mysqldb_test debian dependencies
apt: name={{ item }} state=latest
with_items: "{{mysql_packages}}"
when: ansible_pkg_mgr == 'apt'
apt:
name: "{{ mysql_packages }}"
state: latest
when: ansible_pkg_mgr == 'apt'
notify: cleanup mysql
- name: install mysqldb_test FreeBSD dependencies
pkgng:
name: "{{ item }}"
name: "{{ mysql_packages }}"
state: present
with_items: "{{mysql_packages}}"
when: ansible_os_family == "FreeBSD"
notify: cleanup mysql
- name: install mysql-python package via pip (FreeBSD)
pip:
name: mysql-python
state: present
when: ansible_os_family == "FreeBSD"
notify:
- cleanup mysql
- remove pip packages
- name: enable mysql-server service (FreeBSD)
lineinfile:
@ -77,16 +86,17 @@
- name: apply work-around for OverlayFS issue
# https://github.com/docker/for-linux/issues/72#issuecomment-319904698
command: find /var/lib/mysql -type f -exec touch {} ;
command: find {{ mysql_data_dirs[0] }} -type f -exec touch {} ;
# find will fail if mysql has never been started, as the directory won't exist
ignore_errors: yes
- name: restart mysql_db service
service: name={{ mysql_service }} state=restarted
service:
name: "{{ mysql_service }}"
state: restarted
- name: Detect socket path
shell: >
echo "show variables like 'socket'\G" | mysql | grep 'Value: ' | sed 's/[ ]\+Value: //'
shell: 'echo "show variables like ''socket''\G" | mysql | grep ''Value: '' | sed ''s/[ ]\+Value: //'''
register: _socket_path
- name: Set socket path

View file

@ -4,3 +4,13 @@ mysql_packages:
- mysql-server
- python-mysqldb
- bzip2
mysql_cleanup_packages:
- mysql-client*
- mysql-server*
- mysql-common
- mysql-sandbox
mysql_data_dirs:
- /var/lib/mysql
- /usr/share/mysql

View file

@ -4,3 +4,13 @@ mysql_packages:
- mysql-server
- python3-pymysql
- bzip2
mysql_cleanup_packages:
- mysql-client*
- mysql-server*
- mysql-common
- mysql-sandbox
mysql_data_dirs:
- /var/lib/mysql
- /usr/share/mysql