Bug #78439 mysqldbcompare attribute error with same servers connection with --all option
Submitted: 15 Sep 2015 8:21 Modified: 20 Jan 2016 0:37
Reporter: Shahriyar Rzayev Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Utilities Severity:S2 (Serious)
Version:1.5.5 OS:Linux (Any)
Assigned to: CPU Architecture:Any

[15 Sep 2015 8:21] Shahriyar Rzayev
Description:
If we try to specify same connection information both for source[server1] and destination[server2] servers and appen --all option it will raise an error:

sh@sh--home:~$ mysqldbcompare  --server1=root:12345@localhost:3306 --server2=root:12345@localhost:3306 --all
# WARNING: Using a password on the command line interface can be insecure.
# server1 on localhost: ... connected.
# server2 on localhost: ... connected.
Traceback (most recent call last):
  File "/usr/bin/mysqldbcompare", line 336, in <module>
    exclude_list, options)
  File "/usr/lib/python2.7/dist-packages/mysql/utilities/command/dbcompare.py", line 520, in compare_all_databases
    if server1.port == server2.port and server1.is_alias(server2.host):
AttributeError: 'NoneType' object has no attribute 'port'

in dbcompare.py at line 520 there is a function named compare_all_databases.
Inside function there is a check for similarity off specified connections:

# Check if the specified servers are the same.
     if server1.port == server2.port and server1.is_alias(server2.host):
         raise UtilError(
             "Specified servers are the same (server1={host1}:{port1} and "
             "server2={host2}:{port2}). Cannot compare all databases on the "
             "same server.".format(host1=server1.host, port1=server1.port,
                                   host2=server2.host, port2=server2.port))

But in fact this check is unnecessary and buggy because, above there is a call to connect_servers() function.
server1, server2 = connect_servers(server1_val, server2_val, conn_options)

connect_servers() function is in /common/server.py and if you read comments of this function:

"""If the source and destination are the
same server and the unique parameter is False, destination is set to None."""

The check if specified connections are same already done inside this function.
That's why we get None type error, because connections are same and server2 is set to None by  connect_servers() function.
That's why it is sufficient just to check server2 is None inside compare_all_databases() function.
Will upload a patch.
After fix:

sh@sh--home:~/mysql_utilities/bin$ /home/sh/mysql_utilities/bin/mysqldbcompare --server1=root:12345@localhost:3306 --server2=root:12345@localhost:3306 --all
sh: 0: getcwd() failed: No such file or directory
# WARNING: Using a password on the command line interface can be insecure.
# server1 on localhost: ... connected.
# server2 on localhost: ... connected.
ERROR: Specified servers are the same (server1=localhost:3306 and server2=localhost:3306). Cannot compare all databases on the same server.

 

How to repeat:
Try to run server1 and server2 with same connection information with --all parameter.

Suggested fix:
Checking if server2 is "None" inside compare_all_databases() function.
If "None" it will indicate that server1 is same as server2
[15 Sep 2015 8:22] Shahriyar Rzayev
diff_patch for dbcompare.py

Attachment: dbcompare_patch_bug_78439.txt (text/plain), 1.23 KiB.

[15 Sep 2015 9:52] MySQL Verification Team
Hello Shahriyar Rzayev,

Thank you for the report.

Thanks,
Umesh
[15 Sep 2015 9:54] MySQL Verification Team
//

[root@cluster-repo ~]# rpm -qa|grep mysql-utilities
mysql-utilities-1.5.4-1.el6.noarch
mysql-utilities-extra-1.5.4-1.el6.noarch

[root@cluster-repo ~]# mysqldbcompare  --server1=root@localhost:3306 --server2=root@localhost:3306 --all
# WARNING: Using a password on the command line interface can be insecure.
# server1 on localhost: ... connected.
# server2 on localhost: ... connected.
Traceback (most recent call last):
  File "/usr/bin/mysqldbcompare", line 336, in <module>
    exclude_list, options)
  File "/usr/lib/python2.6/site-packages/mysql/utilities/command/dbcompare.py", line 520, in compare_all_databases
    if server1.port == server2.port and server1.is_alias(server2.host):
AttributeError: 'NoneType' object has no attribute 'port'

// 1.5.5

[root@cluster-repo ~]# rpm -qa|grep mysql-utilities
mysql-utilities-1.5.5-1.el6.noarch
mysql-utilities-extra-1.5.5-1.el6.noarch
[root@cluster-repo ~]# mysqldbcompare  --server1=root@localhost:3306 --server2=root@localhost:3306 --all
# WARNING: Using a password on the command line interface can be insecure.
# server1 on localhost: ... connected.
# server2 on localhost: ... connected.
Traceback (most recent call last):
  File "/usr/bin/mysqldbcompare", line 336, in <module>
    exclude_list, options)
  File "/usr/lib/python2.6/site-packages/mysql/utilities/command/dbcompare.py", line 520, in compare_all_databases
    if server1.port == server2.port and server1.is_alias(server2.host):
AttributeError: 'NoneType' object has no attribute 'port'
[root@cluster-repo ~]#
[20 Jan 2016 0:37] Philip Olson
Posted by developer:
 
Fixed as of the upcoming MySQL Utilities 1.6.3 release, and here's the changelog entry:

With the mysqldbcompare utility, using the same connection information for
both --server1 and --server2 with the --all option would raise an
AttributeError.

Thank you for the bug report.