~guillaume-simon/mysql-utilities/mysql-utilities

« back to all changes in this revision

Viewing changes to mysql-test/t/clone_server_errors.py

  • Committer: chuck.bell at oracle
  • Date: 2013-11-05 20:59:06 UTC
  • Revision ID: chuck.bell@oracle.com-20131105205906-lrnsi8wq5r01uwb9
BUG#13773247 : mysqlserverclone wrongly states it can only clone local server

The mysqlserverclone does not check to see if a server specified with
--server is local to the machine where mysqlserverclone is running. This
patch adds that check to ensure only local servers can be cloned.

Test cases added and changed. Documentation changes are done in a
separate pass.

v3

Show diffs side-by-side

added added

removed removed

Lines of Context:
37
37
        self.res_fname = "result.txt"
38
38
        s0_conn = self.build_connection_string(self.servers.get_server(0))
39
39
        cmd_str = "mysqlserverclone.py --server=%s " % s0_conn
 
40
        tnum = 1
40
41
 
41
42
        port1 = int(self.servers.get_next_port())
42
43
        newport = "--new-port=%d " % port1
43
 
        comment = "Test case 1 - error: no --new-data option"
 
44
        comment = "Test case {0} - error: no --new-data option".format(tnum)
44
45
        res = self.run_test_case(2, cmd_str, comment)
45
46
        if not res:
46
 
            raise MUTLibError("%s: failed" % comment)
47
 
 
48
 
        comment = "Test case 2 - error: no login"
49
 
        res = self.run_test_case(1, "mysqlserverclone.py " +
50
 
                                 "--server=root:root@nothere --new-data=/nada "
51
 
                                 "--new-id=7 " + newport, comment)
52
 
        if not res:
53
 
            raise MUTLibError("%s: failed" % comment)
54
 
 
55
 
        comment = "Test case 3 - error: cannot connect"
56
 
        res = self.run_test_case(1, "mysqlserverclone.py --server=root:nope@" +
57
 
                                 "nothere --new-data=/nada --new-id=7 " +
58
 
                                 "--root-password=nope " + newport,
59
 
                                 comment)
60
 
        if not res:
61
 
            raise MUTLibError("%s: failed" % comment)
62
 
 
63
 
        cmd_str += "--new-id=%d " % self.servers.get_next_id() + newport + \
64
 
                   " --root-password=root "
65
 
        comment = "Test case 4 - cannot create directory"
66
 
        res = self.run_test_case(1, cmd_str + "--new-data=/not/there/yes",
67
 
                                 comment)
68
 
        if not res:
69
 
            raise MUTLibError("%s: failed" % comment)
 
47
            raise MUTLibError("{0}: failed".format(comment))
 
48
        tnum += 1
 
49
 
 
50
        comment = "Test case {0} - error: clone remote server".format(tnum)
 
51
        res = self.run_test_case(2, "mysqlserverclone.py "
 
52
                                 "--server=root:root@notme:90125 "
 
53
                                 "--new-data=/nada "
 
54
                                 "--new-id=7 {0} ".format(newport), comment)
 
55
        if not res:
 
56
            raise MUTLibError("{0}: failed".format(comment))
 
57
        tnum += 1
 
58
 
 
59
        comment = "Test case {0} - error: no login".format(tnum)
 
60
        res = self.run_test_case(1, "mysqlserverclone.py "
 
61
                                 "--server=root:root@localhost:90125 "
 
62
                                 "--new-data=/nada "
 
63
                                 "--new-id=7 {0} ".format(newport), comment)
 
64
        if not res:
 
65
            raise MUTLibError("{0}: failed".format(comment))
 
66
        tnum += 1
 
67
 
 
68
        comment = "Test case {0} - error: cannot connect".format(tnum)
 
69
        res = self.run_test_case(1, "mysqlserverclone.py --server=nope@"
 
70
                                 "localhost:3310 --new-data=/nada --new-id=7 "
 
71
                                 "--root-password=nope {0}".format(newport),
 
72
                                 comment)
 
73
        if not res:
 
74
            raise MUTLibError("{0}: failed".format(comment))
 
75
        tnum += 1
 
76
 
 
77
        cmd_str = "{0} --new-id={1} {2} {3} {4}".format(
 
78
            cmd_str, self.servers.get_next_id(), newport,
 
79
            "--root-password=root ", "--new-data=/not/there/yes")
 
80
        comment = "Test case {0} - cannot create directory".format(tnum)
 
81
        res = self.run_test_case(1, cmd_str, comment)
 
82
        if not res:
 
83
            raise MUTLibError("{0}: failed".format(comment))
 
84
        tnum += 1
70
85
 
71
86
        # Make the directory and put a file in it
72
87
        new_dir = os.path.join(os.getcwd(), "test123")
75
90
        f_out = open(os.path.join(new_dir, "temp123"), "w")
76
91
        f_out.write("test")
77
92
        f_out.close()
78
 
        comment = "Test case 5 - error: --new-data exists"
79
 
        res = self.run_test_case(2, "mysqlserverclone.py --server=root:nope@" +
80
 
                                 "nothere --new-data=%s " % new_dir +
81
 
                                 "--new-id=7 --root-password=nope " + newport,
82
 
                                 comment)
 
93
        cmd_str = ("mysqlserverclone.py --server=root:nope@nothere "
 
94
                   "--new-data={0} --new-id=7 --root-password=nope "
 
95
                   "{1}".format(new_dir, newport))
 
96
        comment = "Test case {0} - error: --new-data exists".format(tnum)
 
97
        res = self.run_test_case(2, cmd_str, comment)
83
98
        if not res:
84
 
            raise MUTLibError("%s: failed" % comment)
 
99
            raise MUTLibError("{0}: failed".format(comment))
 
100
        tnum += 1
85
101
 
86
102
        shutil.rmtree(new_dir, True)
87
103
 
88
 
        comment = "Test case 6 - --new-data does not exist (but cannot connect)"
89
 
        res = self.run_test_case(1, "mysqlserverclone.py --server=root:nope@" +
90
 
                                 "nothere --new-data=%s " % new_dir +
91
 
                                 "--new-id=7 --root-password=nope " + newport,
92
 
                                 comment)
 
104
        cmd_str = ("mysqlserverclone.py --server=root:nope@localhost "
 
105
                   "--new-data={0} --new-id=7 --root-password=nope "
 
106
                   "{1}".format(new_dir, newport))
 
107
        comment = ("Test case {0} - --new-data does not exist (but cannot "
 
108
                   "connect)".format(tnum))
 
109
        res = self.run_test_case(1, cmd_str, comment)
93
110
        if not res:
94
 
            raise MUTLibError("%s: failed" % comment)
 
111
            raise MUTLibError("{0}: failed".format(comment))
 
112
        tnum += 1
95
113
 
96
114
        cmd_str = " ".join(["mysqlserverclone.py", "--server=%s" % s0_conn,
97
 
                            "--new-port=%s" %  self.servers.get_server(0).port,
 
115
                            "--new-port=%s" % self.servers.get_server(0).port,
98
116
                            "--new-data=%s" % new_dir, "--root=root"])
99
117
 
100
 
        comment = "Test case 7 - attempt to use existing port"
 
118
        comment = "Test case {0} - attempt to use existing port".format(tnum)
101
119
        res = self.run_test_case(1, cmd_str, comment)
102
120
        if not res:
103
 
            raise MUTLibError("%s: failed" % comment)
 
121
            raise MUTLibError("{0}: failed".format(comment))
104
122
 
105
123
        # Mask known platform-dependent lines
106
124
        self.mask_result("Error 2003:", "2003", "####")
 
125
        self.mask_result("Error 1045", "1045", "####:")
107
126
        self.replace_result("Error ####: Can't connect to MySQL server",
108
127
                            "Error ####: Can't connect to MySQL server"
109
128
                            " on 'nothere:####'\n")