def convert_to_master(slave, args_array, **kwargs): """Function: convert_to_master Description: Creates MasterRep instance from a SlaveRep instance. Arguments: (input) slaves -> Slave instance array. (input) args_array -> Array of command line options and values. (output) master -> MasterRep instance. """ slv_array = cmds_gen.create_cfg_array(args_array["-s"], cfg_path=args_array["-d"]) for entry in slv_array: if slave.name == entry["name"] and slave.port == int(entry["port"]): rep_user = entry["rep_user"] rep_japd = entry["rep_japd"] break master = mysql_class.MasterRep(slave.name, slave.server_id, slave.sql_user, slave.sql_pass, slave.machine, host=slave.host, port=slave.port, defaults_file=slave.defaults_file, extra_def_file=slave.extra_def_file, rep_user=rep_user, rep_japd=rep_japd) master.connect() return master
def test_create_slv_array(self): """Function: test_create_slv_array Description: Test create_slv_array function. Arguments: """ slaves = cmds_gen.create_cfg_array(self.config_name, cfg_path=self.config_dir) srv = mysql_libs.create_slv_array(slaves) self.assertTrue(isinstance(srv, list))
def test_not_found(self): """Function: test_not_found Description: Test with slave not found. Arguments: """ slaves = cmds_gen.create_cfg_array(self.config_name, cfg_path=self.config_dir) servers = mysql_libs.create_slv_array(slaves) slv, _, _ = mysql_libs.fetch_slv(servers, self.name) self.assertFalse(slv)
def test_not_found2(self): """Function: test_not_found2 Description: Test with slave not found. Arguments: """ slaves = cmds_gen.create_cfg_array(self.config_name, cfg_path=self.config_dir) servers = mysql_libs.create_slv_array(slaves) _, err_flag, err_msg = mysql_libs.fetch_slv(servers, self.name) self.assertEqual((err_flag, err_msg), (True, self.err_msg))
def test_found2(self): """Function: test_found2 Description: Test with slave found. Arguments: """ slaves = cmds_gen.create_cfg_array(self.config_name, cfg_path=self.config_dir) name = slaves[0]["name"] servers = mysql_libs.create_slv_array(slaves) _, err_flag, err_msg = mysql_libs.fetch_slv(servers, name) self.assertEqual((err_flag, err_msg), (False, None))
def test_found(self): """Function: test_found Description: Test with slave found. Arguments: """ slaves = cmds_gen.create_cfg_array(self.config_name, cfg_path=self.config_dir) name = slaves[0]["name"] servers = mysql_libs.create_slv_array(slaves) slv, _, _ = mysql_libs.fetch_slv(servers, name) self.assertTrue(isinstance(slv, mysql_class.SlaveRep))
def create_instances(args_array, **kwargs): """Function: create_instances Description: Create SlaveRep instances for the slaves. The slave instances will be appended to an array. Arguments: (input) args_array -> Array of command line options and values. (output) slaves -> List of slave instances. """ args_array = dict(args_array) slaves = [] # Parse the slave config file. slv_array = cmds_gen.create_cfg_array(args_array["-s"], cfg_path=args_array["-d"]) slaves = mysql_libs.create_slv_array(slv_array) return slaves
def run_program(args_array, func_dict, **kwargs): """Function: run_program Description: Creates class instance(s) and controls flow of the program. Arguments: (input) args_array -> Array of command line options and values. (input) func_dict -> Dictionary list of functions and options. """ args_array = dict(args_array) func_dict = dict(func_dict) master = None if "-c" in args_array: mst_cfg = gen_libs.load_module(args_array["-c"], args_array["-d"]) master = mysql_class.MasterRep( mst_cfg.name, mst_cfg.sid, mst_cfg.user, mst_cfg.passwd, machine=getattr(machine, mst_cfg.serv_os)(), host=mst_cfg.host, port=mst_cfg.port, defaults_file=mst_cfg.cfg_file) master.connect() slaves = [] if "-s" in args_array: slv_cfg = cmds_gen.create_cfg_array(args_array["-s"], cfg_path=args_array["-d"]) slaves = mysql_libs.create_slv_array(slv_cfg) call_run_chk(args_array, func_dict, master, slaves) if master: cmds_gen.disconnect(master, slaves) else: cmds_gen.disconnect(slaves)