BB-804 - Clean up old MySQL instances as part of CI cleanup
Created by: jamestait
This PR adds an extra cleanup instance to the Integration Cleanup script, to remove MySQL databases that are older than three days.
Testing
You can test the cleanup function on a local OCIM instance:
$ vagrant ssh
(opencraft) vagrant@ubuntu-xenial:~$ cd opencraft
(opencraft) vagrant@ubuntu-xenial:~/opencraft$ mysql -u root -h localhost
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 20
Server version: 5.7.24-0ubuntu0.16.04.1 (Ubuntu)
Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> CREATE DATABASE f4ad7be3_integration_plebia_net_edxapp;
Query OK, 1 row affected (0.01 sec)
mysql> use f4ad7be3_integration_plebia_net_edxapp
Database changed
mysql> CREATE TABLE foo (id int);
Query OK, 0 rows affected (0.04 sec)
mysql> CREATE DATABASE unrelated)db;
Query OK, 1 row affected (0.01 sec)
mysql> use unrelated_db
Database changed
mysql> CREATE TABLE foo (id int);
Query OK, 0 rows affected (0.04 sec)
mysql> \q
Bye
(opencraft) vagrant@ubuntu-xenial:~/opencraft$ make shell
...
In [1]: from cleanup_utils import mysql_cleanup
In [2]: my_cleanup = mysql_cleanup.MySqlCleanupInstance(0, settings.DEFAULT_INSTANCE_MYSQL_URL, 'plebia.net', False)
In [3]: my_cleanup._get_old_databases()
Out[3]:
(('f4ad7be3_integration_plebia_net_edxapp',
datetime.datetime(2019, 1, 18, 11, 23, 58)),)
In [4]: my_cleanup.run_cleanup()
In [5]: my_cleanup._get_old_databases()
Out[5]: ()
In [6]: my_cleanup.cleaned_up_hashes
Out[6]: ['f4ad7be3']
In [7]:
Do you really want to exit ([y]/n)?
(opencraft) vagrant@ubuntu-xenial:~/opencraft$ mysql -u root -h localhost
mysql> show DATABASES;
+-------------------------------------------------+
| Database |
+-------------------------------------------------+
| information_schema |
| ... |
| mysql |
| performance_schema |
| sys |
| unrelated_db |
+-------------------------------------------------+
38 rows in set (0.00 sec)
mysql>