provision.py 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. from ... import exc
  2. from ...testing.provision import configure_follower
  3. from ...testing.provision import create_db
  4. from ...testing.provision import drop_db
  5. from ...testing.provision import generate_driver_url
  6. from ...testing.provision import temp_table_keyword_args
  7. @generate_driver_url.for_db("mysql", "mariadb")
  8. def generate_driver_url(url, driver, query_str):
  9. backend = url.get_backend_name()
  10. # NOTE: at the moment, tests are running mariadbconnector
  11. # against both mariadb and mysql backends. if we want this to be
  12. # limited, do the decision making here to reject a "mysql+mariadbconnector"
  13. # URL. Optionally also re-enable the module level
  14. # MySQLDialect_mariadbconnector.is_mysql flag as well, which must include
  15. # a unit and/or functional test.
  16. # all the Jenkins tests have been running mysqlclient Python library
  17. # built against mariadb client drivers for years against all MySQL /
  18. # MariaDB versions going back to MySQL 5.6, currently they can talk
  19. # to MySQL databases without problems.
  20. if backend == "mysql":
  21. dialect_cls = url.get_dialect()
  22. if dialect_cls._is_mariadb_from_url(url):
  23. backend = "mariadb"
  24. new_url = url.set(
  25. drivername="%s+%s" % (backend, driver)
  26. ).update_query_string(query_str)
  27. try:
  28. new_url.get_dialect()
  29. except exc.NoSuchModuleError:
  30. return None
  31. else:
  32. return new_url
  33. @create_db.for_db("mysql", "mariadb")
  34. def _mysql_create_db(cfg, eng, ident):
  35. with eng.begin() as conn:
  36. try:
  37. _mysql_drop_db(cfg, conn, ident)
  38. except Exception:
  39. pass
  40. with eng.begin() as conn:
  41. conn.exec_driver_sql(
  42. "CREATE DATABASE %s CHARACTER SET utf8mb4" % ident
  43. )
  44. conn.exec_driver_sql(
  45. "CREATE DATABASE %s_test_schema CHARACTER SET utf8mb4" % ident
  46. )
  47. conn.exec_driver_sql(
  48. "CREATE DATABASE %s_test_schema_2 CHARACTER SET utf8mb4" % ident
  49. )
  50. @configure_follower.for_db("mysql", "mariadb")
  51. def _mysql_configure_follower(config, ident):
  52. config.test_schema = "%s_test_schema" % ident
  53. config.test_schema_2 = "%s_test_schema_2" % ident
  54. @drop_db.for_db("mysql", "mariadb")
  55. def _mysql_drop_db(cfg, eng, ident):
  56. with eng.begin() as conn:
  57. conn.exec_driver_sql("DROP DATABASE %s_test_schema" % ident)
  58. conn.exec_driver_sql("DROP DATABASE %s_test_schema_2" % ident)
  59. conn.exec_driver_sql("DROP DATABASE %s" % ident)
  60. @temp_table_keyword_args.for_db("mysql", "mariadb")
  61. def _mysql_temp_table_keyword_args(cfg, eng):
  62. return {"prefixes": ["TEMPORARY"]}