def mysqldump_from_env(env, role_name, dbs, fname): node = env_util.get_one_node_of(env, role_name) cmd = [ 'bash', '-c', 'set -o pipefail; ' + # We want to fail if mysqldump fails 'mysqldump --add-drop-database --lock-all-tables ' '--databases {0}'.format(' '.join(dbs)) + ' | gzip', ] with ssh.popen(cmd, stdout=ssh.PIPE, node=node) as proc: with open(fname, 'wb') as local_file: shutil.copyfileobj(proc.stdout, local_file)
def test_get_one_node_of(mocker): get_nodes = mocker.patch("octane.util.env.get_nodes") get_nodes.return_value = iter(["node1", "node2"]) node = env_util.get_one_node_of(mock.Mock(), "controller") assert node == "node1"
def test_get_one_node_of(mocker): get_nodes = mocker.patch('octane.util.env.get_nodes') get_nodes.return_value = iter(['node1', 'node2']) node = env_util.get_one_node_of(mock.Mock(), 'controller') assert node == 'node1'
def mysqldump_restore_to_env(env, role_name, fname): node = env_util.get_one_node_of(env, role_name) with open(fname, 'rb') as local_file: with ssh.popen(['sh', '-c', 'zcat | mysql'], stdin=ssh.PIPE, node=node) as proc: shutil.copyfileobj(local_file, proc.stdin)