1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346
|
import option
import wb_admin_config_file_be
from wb_common import Users
#===============================================================================
#
#===============================================================================
class DummyPwdHandler:
def get_password_for(self, name):
return ""
def reset_password_for(self, name):
pass
#===============================================================================
#
#===============================================================================
class HelperDummy:
content = None
def __init__(self, content):
content = self.content
def get_file_content(file_name, as_user=Users.CURRENT, user_password=None, skip_lines=0):
return self.content
#===============================================================================
#
#===============================================================================
class CtrlBEDummy:
def __init__(self):
self.helper = HelperDummy([])
self.password_handler = DummyPwdHandler()
#===============================================================================
#
#===============================================================================
class DummyProfile:
@property
def target_is_windows(self):
return False
@property
def config_file_section(self):
return "mysqld"
@property
def admin_enabled(self):
return True
@property
def config_file_section(self):
return "mysqld"
profile = DummyProfile()
#===============================================================================
#
#===============================================================================
def unit_test_1():
ctrl_be = CtrlBEDummy()
ctrl_be.helper.content = ["#Start\n", "[mysqld]\n", "ansi\n"]
cfg = wb_admin_config_file_be.ConfigFileSource((5,1,8), ctrl_be, profile)
cfg.file_name = "dummy_name"
cfg.parse_file_contents(ctrl_be.helper.content)
ret = False
for name, opt in cfg.options.iteritems():
values = opt.get_values()
default = opt.default_value()
if len(values) > 0:
if default is not True:
if name == 'ansi' and values[0].enabled == True:
ret = True
return (ret, "Reading simple config")
#-------------------------------------------------------------------------------
def unit_test_2():
ctrl_be = CtrlBEDummy()
ctrl_be.helper.content = ["#Start\n", "[mysqld]\n", "binlog-do-db=db1\n", "binlog-do-db=db2\n"]
cfg = wb_admin_config_file_be.ConfigFileSource((5,1,8), ctrl_be, profile)
cfg.file_name = "dummy_name"
cfg.parse_file_contents(ctrl_be.helper.content)
ret = False
cfg_opts = {}
for name, opt in cfg.options.iteritems():
values = opt.get_values()
default = opt.default_value()
if len(values) == 2:
cfg_opts[id(opt)] = opt
ret = len(cfg_opts) == 1 and len(cfg_opts.values()[0].get_values()) == 2
values = cfg_opts.values()[0].get_values()
ret = ret and values[0].value == "db1" and values[1].value == "db2"
return (ret, "Reading simple config with multiline option")
#-------------------------------------------------------------------------------
def unit_test_3():
ctrl_be = CtrlBEDummy()
ctrl_be.helper.content = ["#Start\n", "[mysqld]\n", "ansi\n"]
cfg = wb_admin_config_file_be.ConfigFileSource((5,1,8), ctrl_be, profile)
cfg.file_name = "dummy_name"
cfg.parse_file_contents(ctrl_be.helper.content)
ret = False
opt = cfg.get_option("chroot")
values = opt.get_values()
values.append(option.Value("/var/ww/mydir", True))
opt.set_values(values)
new_lines = cfg.generate_file_content()
cfg = wb_admin_config_file_be.ConfigFileSource((5,1,8), ctrl_be, profile)
cfg.file_name = "dummy_name"
cfg.parse_file_contents(new_lines)
opt = cfg.get_option("chroot")
ret = opt.get_values()[0].value == '"/var/ww/mydir"'
return (ret, "Adding dirname/filename option")
#-------------------------------------------------------------------------------
def unit_test_4():
ctrl_be = CtrlBEDummy()
ctrl_be.helper.content = []
cfg = wb_admin_config_file_be.ConfigFileSource((5,1,8), ctrl_be, profile)
cfg.file_name = "dummy_name"
cfg.parse_file_contents(ctrl_be.helper.content)
ret = False
new_lines = cfg.generate_file_content()
ret = '[mysqld]' in new_lines
return (ret, "Parsing empty config")
#-------------------------------------------------------------------------------
def unit_test_5():
ctrl_be = CtrlBEDummy()
ctrl_be.helper.content = ["#Start\n", "[mysqld]\n"]
cfg = wb_admin_config_file_be.ConfigFileSource((5,1,8), ctrl_be, profile)
cfg.file_name = "dummy_name"
cfg.parse_file_contents(ctrl_be.helper.content)
ret = False
opt = cfg.get_option("binlog-do-db")
values = opt.get_values()
values.append(option.Value("db1", True))
values.append(option.Value("db2", True))
opt.set_values(values)
new_lines = cfg.generate_file_content()
cfg = wb_admin_config_file_be.ConfigFileSource((5,1,8), ctrl_be, profile)
cfg.file_name = "dummy_name"
cfg.parse_file_contents(new_lines)
ret = 'binlog-do-db = db2' in new_lines and 'binlog-do-db = db1' in new_lines
new_lines = cfg.generate_file_content()
ret = ret and 'binlog-do-db = db2' in new_lines and 'binlog-do-db = db1' in new_lines
return (ret, "Adding multi-line option")
#-------------------------------------------------------------------------------
def unit_test_6():
ctrl_be = CtrlBEDummy()
ctrl_be.helper.content = ["#Start", "[mysql]", "port=3306"]
cfg = wb_admin_config_file_be.ConfigFileSource((5,1,8), ctrl_be, profile)
cfg.file_name = "dummy_name"
cfg.parse_file_contents(ctrl_be.helper.content)
ret = False
opt = cfg.get_option("binlog-do-db")
values = opt.get_values()
values.append(option.Value("db1", True))
values.append(option.Value("db2", True))
opt.set_values(values)
new_lines = cfg.generate_file_content()
cfg = wb_admin_config_file_be.ConfigFileSource((5,1,8), ctrl_be, profile)
cfg.file_name = "dummy_name"
cfg.parse_file_contents(new_lines)
ret = 'binlog-do-db = db2' in new_lines and 'binlog-do-db = db1' in new_lines
new_lines = cfg.generate_file_content()
ret = ret and 'binlog-do-db = db2' in new_lines and 'binlog-do-db = db1' in new_lines
return (ret, "Adding multi-line option to non-empty file with missing [mysqld]")
#-------------------------------------------------------------------------------
def unit_test_7():
ctrl_be = CtrlBEDummy()
ctrl_be.helper.content = ["#Start", "[mysql]", "port=3306", "[mysqld]", 'binlog-do-db = db1', 'binlog-do-db = db2']
cfg = wb_admin_config_file_be.ConfigFileSource((5,1,8), ctrl_be, profile)
cfg.file_name = "dummy_name"
cfg.parse_file_contents(ctrl_be.helper.content)
ret = False
opt = cfg.get_option("binlog-do-db")
values = opt.get_values()
values[1].value = "db3"
new_lines = cfg.generate_file_content()
ret = 'binlog-do-db = db3' in new_lines and 'binlog-do-db = db1' in new_lines
return (ret, "Changing multi-line option")
#-------------------------------------------------------------------------------
def unit_test_8():
ctrl_be = CtrlBEDummy()
ctrl_be.helper.content = ["#Start", "[mysql]", "port=3306", "[mysqld]", 'binlog-do-db = db1', 'binlog-do-db = db2']
cfg = wb_admin_config_file_be.ConfigFileSource((5,1,8), ctrl_be, profile)
cfg.file_name = "dummy_name"
cfg.parse_file_contents(ctrl_be.helper.content)
ret = False
opt = cfg.get_option("binlog-do-db")
values = opt.get_values()
values[1].enabled = False
new_lines = cfg.generate_file_content()
ret = 'binlog-do-db = db2' not in new_lines and 'binlog-do-db = db1' in new_lines
return (ret, "Deleting one value from a multi-line option")
#-------------------------------------------------------------------------------
def unit_test_9():
ctrl_be = CtrlBEDummy()
ctrl_be.helper.content = ["[mysqld]","local-infile = 0",'general-log-file="sdf1"','#general_log_file="sdf2"',"replicate-ignore-db='data1'","replicate-ignore-db='data2'",
"replicate-ignore-db='data3'","port=3306","port=3307"]
cfg = wb_admin_config_file_be.ConfigFileSource((5,1,8), ctrl_be, profile)
cfg.file_name = "dummy_name"
cfg.parse_file_contents(ctrl_be.helper.content)
ret = False
opt = cfg.get_option("replicate-ignore-db")
values = opt.get_values()
ret = len(values) == 3
return (ret, "Testing cfg")
#-------------------------------------------------------------------------------
def unit_test_10():
ctrl_be = CtrlBEDummy()
ctrl_be.helper.content = ["[mysqld]","local-infile = 0",'general-log-file="sdf1"','#general_log_file="sdf2"',"replicate-ignore-db='data1'","replicate-ignore-db='data2'",
"replicate-ignore-db='data3'","port=3306","port=3307"]
cfg = wb_admin_config_file_be.ConfigFileSource((5,1,8), ctrl_be, profile)
cfg.file_name = "dummy_name"
cfg.parse_file_contents(ctrl_be.helper.content)
ret = False
opt = cfg.get_option("local-infile")
(c,r,a) = opt.get_changeset()
ret = len(c) == len(r) == len(a) == 0
opt = cfg.get_option("tmpdir")
values = opt.get_values()
values.append(option.Value("", True))
opt.set_values(values)
#print cfg.generate_file_content()
return (ret, "Testing cfg")
#-------------------------------------------------------------------------------
def unit_test_11():
ctrl_be = CtrlBEDummy()
ctrl_be.helper.content = ["[mysqld]","local-infile = 0",'general-log-file="sdf1"','#general_log_file="sdf2"',"replicate-ignore-db='data1'","replicate-ignore-db='data2'",
"replicate-ignore-db='data3'","port=3306","port=3307"]
cfg = wb_admin_config_file_be.ConfigFileSource((5,1,8), ctrl_be, profile)
cfg.file_name = "dummy_name"
cfg.parse_file_contents(ctrl_be.helper.content)
ret = False
opt = cfg.get_option("skip-networking")
opt.set_values([option.Value(None, True)])
opt.set_values([option.Value(None, False)])
(c, r, a) = opt.get_changeset()
cont = cfg.generate_file_content()
return (ret, "Testing cfg")
#-------------------------------------------------------------------------------
def unit_test_12():
ctrl_be = CtrlBEDummy()
ctrl_be.helper.content = ["[mysqld]","local-infile = 0",'general-log-file="sdf1"','#general_log_file="sdf2"',"replicate-ignore-db='data1'","replicate-ignore-db='data2'",
"replicate-ignore-db='data3'","port=3306","port=3307","skip-networking"]
cfg = wb_admin_config_file_be.ConfigFileSource((5,1,8), ctrl_be, profile)
cfg.file_name = "dummy_name"
cfg.parse_file_contents(ctrl_be.helper.content)
ret = False
opt = cfg.get_option("skip-networking")
values = opt.get_values()
opt.set_values([option.Value(None, False)])
(c, r, a) = opt.get_changeset()
cont = cfg.generate_file_content()
print cont
return (ret, "Testing cfg")
#-------------------------------------------------------------------------------
results = []
tests = sorted(filter(lambda x: "unit_test" in x, dir()))
tests_numbers = sorted(map(lambda x: int(x[10:]), tests))
for testnr in tests_numbers:
test = "unit_test_%i" % testnr
print "--------------------------------------------------------------------"
print "-- %s starting" % test
ret = eval(test + "()")
print "-- %s %s: %s\n" % (test, str(ret[0]), ret[1])
results.append((ret[0], ret[1], test))
print "============================== SUMMARY ==================================="
for res in results:
ch = "+" if res[0] else "-"
print "%s %s - %s" % (ch, res[2], res[1])
|