trove版本
git show HEAD commit f644fdcdb5695de53422ea27bce19f4262413d9e Merge: 7d219aa 9f17051 Author: Jenkins <jenkins@review.openstack.org> Date: Thu Jan 19 02:10:02 2017 +0000 Merge "Add i18n translation to others 1/3"
源代码
# trove/guestagent/datastore/mysql_common/service.py 1084行 def disable_root(self): """Reset the root password to an unknown value. """ self.enable_root(root_password=None)
disable_root调用enable_root设置root密码为随机密码
源代码
# trove/guestagent/datastore/mysql_common/service.py 1051行 def enable_root(self, root_password=None): """Enable the root user global access and/or reset the root password. """ user = models.MySQLUser.root(password=root_password) ...
models.MySQLUser代码
# trove/common/db/mysql/models.py 121行 class MySQLUser(models.DatastoreUser): """Represents a MySQL User and its associated properties.""" not_supported_chars = re.compile("^\s|\s$|‘|\"|;|`|,|/|\\\\") def _is_valid_string(self, value): ...
models.MySQLUser.root继承自models.DatastoreUser
models.DatastoreUser.root代码
# trove/common/db/models.py 229行 class DatastoreUser(DatastoreModelsBase): """Represents a datastore user.""" _HOSTNAME_WILDCARD = ‘%‘ root_username = ‘root‘ ... @classmethod def root(cls, name=None, password=None, *args, **kwargs): if not name: name = cls.root_username if not password: password = utils.generate_random_password() user = cls(name, password, *args, **kwargs) user.make_root() return user
从代码上可以看到当password为None时会为password随机生成一个密码,因此在trove root-disable后,trove root-show依然会显示root是enable.
本文出自 “武陵荒草” 博客,请务必保留此出处http://penguintux.blog.51cto.com/3021117/1893196
原文地址:http://penguintux.blog.51cto.com/3021117/1893196