def test_returns_vip_host_if_mysqldump_node_is_not_set(self): config = mock.MagicMock() expected = "db_vip" config.mysql.db_host = expected config.migrate.mysqldump_host = None self.assertEqual(expected, mysql_connector.get_db_host(config))
def run(self, *args, **kwargs): db_host = mysql_connector.get_db_host(self.cloud.cloud_config) # dump mysql to file # probably, we have to choose what databases we have to dump # by default we dump all databases command = ("mysqldump " "--user={user} " "--password={password} " "--opt " "--all-databases > {path}").format( user=self.cloud.cloud_config.mysql.db_user, password=self.cloud.cloud_config.mysql.db_password, path=self.cloud.cloud_config.snapshot.snapshot_path) LOG.info("dumping database with command '%s'", command) self.cloud.ssh_util.execute(command, host_exec=db_host) # copy dump file to host with cloudferry (for now just in case) # in future we will store snapshot for every step of migration key_string = ' -i '.join(self.cloud.config.migrate.key_filename) context = { 'host_src': db_host, 'path_src': self.cloud.cloud_config.snapshot.snapshot_path, 'user_src': self.cloud.cloud_config.cloud.ssh_user, 'key': key_string, 'path_dst': self.cloud.cloud_config.snapshot.snapshot_path} command = ( "scp -o StrictHostKeyChecking=no -i {key} " "{user_src}@{host_src}:{path_src} {path_dst}".format(**context)) LOG.info("EXECUTING {command} local".format(command=command)) local(command) return {}
def test_returns_mysqldump_host_if_set(self): config = mock.MagicMock() config.mysql.db_host = "db_vip" expected = "mysql_node" config.migrate.mysqldump_host = expected self.assertEqual(expected, mysql_connector.get_db_host(config))
def run(self, *args, **kwargs): db_host = mysql_connector.get_db_host(self.cloud.cloud_config) # dump mysql to file # probably, we have to choose what databases we have to dump # by default we dump all databases options = ["--user={user}", "--opt", "--all-databases"] if self.cloud.cloud_config.mysql.db_password: options.append("--password={password}") options = " ".join(options).format( user=self.cloud.cloud_config.mysql.db_user, password=self.cloud.cloud_config.mysql.db_password) command = "mysqldump {options} > {path}".format( options=options, path=self.cloud.cloud_config.snapshot.snapshot_path) LOG.info("dumping database with command '%s'", command) self.cloud.ssh_util.execute(command, host_exec=db_host) # copy dump file to host with cloudferry (for now just in case) # in future we will store snapshot for every step of migration key_string = ' -i '.join(self.cloud.config.migrate.key_filename) context = { 'host_src': db_host, 'path_src': self.cloud.cloud_config.snapshot.snapshot_path, 'user_src': self.cloud.cloud_config.cloud.ssh_user, 'key': key_string, 'path_dst': self.cloud.cloud_config.snapshot.snapshot_path, 'cipher': ssh_util.get_cipher_option(), } command = ("scp {cipher} -o StrictHostKeyChecking=no -i {key} " "{user_src}@{host_src}:{path_src} {path_dst}".format( **context)) LOG.info("EXECUTING {command} local".format(command=command)) local(command) return {}
def run(self, *args, **kwargs): db_host = mysql_connector.get_db_host(self.cloud.cloud_config) # apply sqldump from file to mysql command = ("mysql " "--user={user} " "--password={password} " "< {path}").format( user=self.cloud.cloud_config.mysql.db_user, password=self.cloud.cloud_config.mysql.db_password, path=self.cloud.cloud_config.snapshot.snapshot_path, ) LOG.info("restoring database with command '%s'", command) self.cloud.ssh_util.execute(command, host_exec=db_host) return {}
def run(self, *args, **kwargs): db_host = mysql_connector.get_db_host(self.cloud.cloud_config) # apply sqldump from file to mysql command = ("mysql " "--user={user} " "--password={password} " "< {path}").format( user=self.cloud.cloud_config.mysql.db_user, password=self.cloud.cloud_config.mysql.db_password, path=self.cloud.cloud_config.snapshot.snapshot_path) LOG.info("restoring database with command '%s'", command) self.cloud.ssh_util.execute(command, host_exec=db_host) return {}
def run(self, *args, **kwargs): db_host = mysql_connector.get_db_host(self.cloud.cloud_config) # apply sqldump from file to mysql options = ["--user={user}"] if self.cloud.cloud_config.mysql.db_password: options.append("--password={password}") options = " ".join(options).format( user=self.cloud.cloud_config.mysql.db_user, password=self.cloud.cloud_config.mysql.db_password) command = "mysql {options} < {path}".format( options=options, path=self.cloud.cloud_config.snapshot.snapshot_path) LOG.info("restoring database with command '%s'", command) self.cloud.ssh_util.execute(command, host_exec=db_host) return {}
def run(self, *args, **kwargs): db_host = mysql_connector.get_db_host(self.cloud.cloud_config) # apply sqldump from file to mysql options = ["--user={user}"] if self.cloud.cloud_config.mysql.db_password: options.append("--password={password}") options = " ".join(options).format( user=self.cloud.cloud_config.mysql.db_user, password=self.cloud.cloud_config.mysql.db_password ) command = "mysql {options} < {path}".format( options=options, path=self.cloud.cloud_config.snapshot.snapshot_path ) LOG.info("restoring database with command '%s'", command) self.cloud.ssh_util.execute(command, host_exec=db_host) return {}