diff options
author | wangyao <wangyao@cmss.chinamobile.com> | 2017-04-17 13:08:37 +0800 |
---|---|---|
committer | wangyao <wangyao@cmss.chinamobile.com> | 2017-05-31 09:00:22 +0800 |
commit | 4bfe5b58a1b4709e5df4d4c1b325ddddf6f4f2d9 (patch) | |
tree | ed322069a8317b42ecfb8f7d767f93d951330471 | |
parent | 00fde782be276698a5372066bb3fec74509e0fa8 (diff) | |
download | trove-4bfe5b58a1b4709e5df4d4c1b325ddddf6f4f2d9.tar.gz |
Fix user-list failed if host uses host_ip/netmask
According bug exception trace this problem cause by host name validate .
The origin code use netaddr.IPAddress to validate host name, it just fit ip address,
so the ip/netmask style do not match this rule.To solve this problem,
I changed this method to netaddr.IPNetwork, which support ip and
ip/netmask. Also provide a test case to validate the method.
Change-Id: I8dad9d1496d09372698821b832d1baa4f0c35a0d
Closes-Bug: #1673874
-rw-r--r-- | trove/common/db/mysql/models.py | 4 | ||||
-rw-r--r-- | trove/tests/unittests/guestagent/test_mysql_manager.py | 10 |
2 files changed, 12 insertions, 2 deletions
diff --git a/trove/common/db/mysql/models.py b/trove/common/db/mysql/models.py index cf9d0fbf..50700b10 100644 --- a/trove/common/db/mysql/models.py +++ b/trove/common/db/mysql/models.py @@ -145,8 +145,8 @@ class MySQLUser(models.DatastoreUser): if CONF.hostname_require_valid_ip: try: # '%' works as a MySQL wildcard, but it is not a valid - # part of an IPAddress - netaddr.IPAddress(value.replace('%', '1')) + # part of an IPNetwork + netaddr.IPNetwork(value.replace('%', '1')) except (ValueError, netaddr.AddrFormatError): return False else: diff --git a/trove/tests/unittests/guestagent/test_mysql_manager.py b/trove/tests/unittests/guestagent/test_mysql_manager.py index 2f60dd05..1355420a 100644 --- a/trove/tests/unittests/guestagent/test_mysql_manager.py +++ b/trove/tests/unittests/guestagent/test_mysql_manager.py @@ -20,6 +20,7 @@ from mock import patch from proboscis.asserts import assert_equal from testtools.matchers import Is, Equals, Not +from trove.common.db.mysql import models from trove.common.exception import InsufficientSpaceForReplica from trove.common.exception import ProcessExecutionError from trove.common import instance as rd_instance @@ -103,6 +104,15 @@ class GuestAgentManagerTest(DatastoreManagerTest): dbaas.MySqlAppStatus.get.assert_any_call() mock_status.update.assert_any_call() + def _empty_user(self): + return models.MySQLUser(deserializing=True) + + def test_valid_host_name(self): + test_host = "192.58.197.0/255.255.255.0" + user = self._empty_user() + user.host = test_host + self.assertEqual(test_host, user.host) + @patch.object(dbaas.MySqlAdmin, 'create_database') def test_create_database(self, create_db_mock): self.manager.create_database(self.context, ['db1']) |