summaryrefslogtreecommitdiff
path: root/trove/guestagent/datastore/mysql_common/service.py
diff options
context:
space:
mode:
authorLingxian Kong <anlin.kong@gmail.com>2020-01-10 18:37:58 +1300
committerLingxian Kong <anlin.kong@gmail.com>2020-01-28 14:27:52 +1300
commit602c4d42de77d1be0397185b04f2790f4bae87b7 (patch)
tree57a91b0024c9ed917571e411df27a111e1341f44 /trove/guestagent/datastore/mysql_common/service.py
parent54987b60a738abfbe8171b889da1658468dcf9ca (diff)
downloadtrove-602c4d42de77d1be0397185b04f2790f4bae87b7.tar.gz
Improve the function tests
- Execute test groups in serial to make sure no more than 2 database instance are created at the same time. - Remove some unneccesary tests - Remove unneeded datastore, e.g. 'Test_Datastore_1' - Remove unsupported trovestack subcommands - Move unsupported DIB elements to the 'deprecated-elements' folder - Decrease default value of 'agent_call_high_timeout' to 5min - Add initial_deplay for pooling task - Use socket file to connect with database instead of using localhost IP Change-Id: Ie5030a671fbeb453eafa6cbe04e08da7b52e33c9
Diffstat (limited to 'trove/guestagent/datastore/mysql_common/service.py')
-rw-r--r--trove/guestagent/datastore/mysql_common/service.py50
1 files changed, 26 insertions, 24 deletions
diff --git a/trove/guestagent/datastore/mysql_common/service.py b/trove/guestagent/datastore/mysql_common/service.py
index de5f1a2b..c562775e 100644
--- a/trove/guestagent/datastore/mysql_common/service.py
+++ b/trove/guestagent/datastore/mysql_common/service.py
@@ -50,7 +50,8 @@ from trove.guestagent.datastore import service
from trove.guestagent import pkg
ADMIN_USER_NAME = "os_admin"
-CONNECTION_STR_FORMAT = "mysql+pymysql://%s:%s@127.0.0.1:3306"
+CONNECTION_STR_FORMAT = ("mysql+pymysql://%s:%s@localhost/?"
+ "unix_socket=/var/run/mysqld/mysqld.sock")
LOG = logging.getLogger(__name__)
FLUSH = text(sql_query.FLUSH)
ENGINE = None
@@ -157,26 +158,14 @@ class BaseMySqlAppStatus(service.BaseDbStatus):
The checks which don't need service app can be put here.
"""
try:
- utils.execute_with_timeout(
- "/usr/bin/mysqladmin",
- "ping", run_as_root=True, root_helper="sudo",
- log_output_on_error=True)
-
- LOG.debug("Database service check: mysqld is alive")
- return rd_instance.ServiceStatuses.RUNNING
- except exception.ProcessExecutionError:
- LOG.warning("Database service check: Failed to get database "
- "service status by mysqladmin, fall back to use ps.")
-
- try:
out, _ = utils.execute_with_timeout(
"/bin/ps", "-C", "mysqld", "h",
log_output_on_error=True
)
pid = out.split()[0]
- LOG.debug('Database service check: service PID exists', pid)
- return rd_instance.ServiceStatuses.BLOCKED
+ LOG.debug('Database service check: service PID exists: %s', pid)
+ return rd_instance.ServiceStatuses.RUNNING
except exception.ProcessExecutionError:
LOG.warning("Database service check: Failed to get database "
"service status by ps, fall back to check PID file.")
@@ -629,20 +618,28 @@ class BaseMySqlApp(object):
override_strategy=ImportOverrideStrategy(CNF_INCLUDE_DIR, CNF_EXT))
def get_engine(self):
- """Create the default engine with the updated admin user."""
- # TODO(rnirmal):Based on permission issues being resolved we may revert
- # url = URL(drivername='mysql', host='localhost',
- # query={'read_default_file': '/etc/mysql/my.cnf'})
+ """Create the default engine with the updated admin user.
+
+ If admin user not created yet, use root instead.
+ """
global ENGINE
if ENGINE:
return ENGINE
- pwd = self.get_auth_password()
+ user = ADMIN_USER_NAME
+ password = ""
+ try:
+ password = self.get_auth_password()
+ except exception.UnprocessableEntity:
+ # os_admin user not created yet
+ user = 'root'
+
ENGINE = sqlalchemy.create_engine(
- CONNECTION_STR_FORMAT % (ADMIN_USER_NAME,
- urllib.parse.quote(pwd.strip())),
+ CONNECTION_STR_FORMAT % (user,
+ urllib.parse.quote(password.strip())),
pool_recycle=120, echo=CONF.sql_query_logging,
listeners=[self.keep_alive_connection_cls()])
+
return ENGINE
@classmethod
@@ -678,7 +675,7 @@ class BaseMySqlApp(object):
with all privileges similar to the root user.
"""
LOG.debug("Creating Trove admin user '%s'.", ADMIN_USER_NAME)
- host = "127.0.0.1"
+ host = "localhost"
try:
cu = sql_query.CreateUser(ADMIN_USER_NAME, host=host,
clear=password)
@@ -742,6 +739,9 @@ class BaseMySqlApp(object):
LOG.debug("Generating admin password.")
admin_password = utils.generate_random_password()
+
+ # By default, MySQL does not require a password at all for connecting
+ # as root
engine = sqlalchemy.create_engine(
CONNECTION_STR_FORMAT % ('root', ''), echo=True)
with self.local_sql_client(engine, use_flush=False) as client:
@@ -771,9 +771,11 @@ class BaseMySqlApp(object):
self.wipe_ib_logfiles()
def _save_authentication_properties(self, admin_password):
+ # Use localhost to connect with mysql using unix socket instead of ip
+ # and port.
client_sect = {'client': {'user': ADMIN_USER_NAME,
'password': admin_password,
- 'host': '127.0.0.1'}}
+ 'host': 'localhost'}}
operating_system.write_file(self.get_client_auth_file(),
client_sect, codec=self.CFG_CODEC)