|
@@ -479,7 +479,17 @@ def test_restore_database_dump_runs_pg_restore():
|
|
).once()
|
|
).once()
|
|
|
|
|
|
module.restore_database_dump(
|
|
module.restore_database_dump(
|
|
- database_config, 'test.yaml', {}, dry_run=False, extract_process=extract_process
|
|
|
|
|
|
+ database_config,
|
|
|
|
+ 'test.yaml',
|
|
|
|
+ {},
|
|
|
|
+ dry_run=False,
|
|
|
|
+ extract_process=extract_process,
|
|
|
|
+ connection_params={
|
|
|
|
+ 'hostname': None,
|
|
|
|
+ 'port': None,
|
|
|
|
+ 'username': None,
|
|
|
|
+ 'password': None,
|
|
|
|
+ },
|
|
)
|
|
)
|
|
|
|
|
|
|
|
|
|
@@ -494,7 +504,17 @@ def test_restore_database_dump_errors_on_multiple_database_config():
|
|
|
|
|
|
with pytest.raises(ValueError):
|
|
with pytest.raises(ValueError):
|
|
module.restore_database_dump(
|
|
module.restore_database_dump(
|
|
- database_config, 'test.yaml', {}, dry_run=False, extract_process=flexmock()
|
|
|
|
|
|
+ database_config,
|
|
|
|
+ 'test.yaml',
|
|
|
|
+ {},
|
|
|
|
+ dry_run=False,
|
|
|
|
+ extract_process=flexmock(),
|
|
|
|
+ connection_params={
|
|
|
|
+ 'restore_hostname': None,
|
|
|
|
+ 'restore_port': None,
|
|
|
|
+ 'restore_username': None,
|
|
|
|
+ 'restore_password': None,
|
|
|
|
+ },
|
|
)
|
|
)
|
|
|
|
|
|
|
|
|
|
@@ -545,7 +565,17 @@ def test_restore_database_dump_runs_pg_restore_with_hostname_and_port():
|
|
).once()
|
|
).once()
|
|
|
|
|
|
module.restore_database_dump(
|
|
module.restore_database_dump(
|
|
- database_config, 'test.yaml', {}, dry_run=False, extract_process=extract_process
|
|
|
|
|
|
+ database_config,
|
|
|
|
+ 'test.yaml',
|
|
|
|
+ {},
|
|
|
|
+ dry_run=False,
|
|
|
|
+ extract_process=extract_process,
|
|
|
|
+ connection_params={
|
|
|
|
+ 'hostname': None,
|
|
|
|
+ 'port': None,
|
|
|
|
+ 'username': None,
|
|
|
|
+ 'password': None,
|
|
|
|
+ },
|
|
)
|
|
)
|
|
|
|
|
|
|
|
|
|
@@ -594,7 +624,183 @@ def test_restore_database_dump_runs_pg_restore_with_username_and_password():
|
|
).once()
|
|
).once()
|
|
|
|
|
|
module.restore_database_dump(
|
|
module.restore_database_dump(
|
|
- database_config, 'test.yaml', {}, dry_run=False, extract_process=extract_process
|
|
|
|
|
|
+ database_config,
|
|
|
|
+ 'test.yaml',
|
|
|
|
+ {},
|
|
|
|
+ dry_run=False,
|
|
|
|
+ extract_process=extract_process,
|
|
|
|
+ connection_params={
|
|
|
|
+ 'hostname': None,
|
|
|
|
+ 'port': None,
|
|
|
|
+ 'username': None,
|
|
|
|
+ 'password': None,
|
|
|
|
+ },
|
|
|
|
+ )
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+def test_make_extra_environment_with_cli_password_sets_correct_password():
|
|
|
|
+ database = {'name': 'foo', 'restore_password': 'trustsome1', 'password': 'anotherpassword'}
|
|
|
|
+
|
|
|
|
+ extra = module.make_extra_environment(
|
|
|
|
+ database, restore_connection_params={'password': 'clipassword'}
|
|
|
|
+ )
|
|
|
|
+
|
|
|
|
+ assert extra['PGPASSWORD'] == 'clipassword'
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+def test_restore_database_dump_with_connection_params_uses_connection_params_for_restore():
|
|
|
|
+ database_config = [
|
|
|
|
+ {
|
|
|
|
+ 'name': 'foo',
|
|
|
|
+ 'hostname': 'database.example.org',
|
|
|
|
+ 'port': 5433,
|
|
|
|
+ 'username': 'postgres',
|
|
|
|
+ 'password': 'trustsome1',
|
|
|
|
+ 'restore_hostname': 'restorehost',
|
|
|
|
+ 'restore_port': 'restoreport',
|
|
|
|
+ 'restore_username': 'restoreusername',
|
|
|
|
+ 'restore_password': 'restorepassword',
|
|
|
|
+ 'schemas': None,
|
|
|
|
+ }
|
|
|
|
+ ]
|
|
|
|
+ extract_process = flexmock(stdout=flexmock())
|
|
|
|
+
|
|
|
|
+ flexmock(module).should_receive('make_extra_environment').and_return(
|
|
|
|
+ {'PGPASSWORD': 'clipassword', 'PGSSLMODE': 'disable'}
|
|
|
|
+ )
|
|
|
|
+ flexmock(module).should_receive('make_dump_path')
|
|
|
|
+ flexmock(module.dump).should_receive('make_database_dump_filename')
|
|
|
|
+ flexmock(module).should_receive('execute_command_with_processes').with_args(
|
|
|
|
+ (
|
|
|
|
+ 'pg_restore',
|
|
|
|
+ '--no-password',
|
|
|
|
+ '--if-exists',
|
|
|
|
+ '--exit-on-error',
|
|
|
|
+ '--clean',
|
|
|
|
+ '--dbname',
|
|
|
|
+ 'foo',
|
|
|
|
+ '--host',
|
|
|
|
+ 'clihost',
|
|
|
|
+ '--port',
|
|
|
|
+ 'cliport',
|
|
|
|
+ '--username',
|
|
|
|
+ 'cliusername',
|
|
|
|
+ ),
|
|
|
|
+ processes=[extract_process],
|
|
|
|
+ output_log_level=logging.DEBUG,
|
|
|
|
+ input_file=extract_process.stdout,
|
|
|
|
+ extra_environment={'PGPASSWORD': 'clipassword', 'PGSSLMODE': 'disable'},
|
|
|
|
+ ).once()
|
|
|
|
+ flexmock(module).should_receive('execute_command').with_args(
|
|
|
|
+ (
|
|
|
|
+ 'psql',
|
|
|
|
+ '--no-password',
|
|
|
|
+ '--no-psqlrc',
|
|
|
|
+ '--quiet',
|
|
|
|
+ '--host',
|
|
|
|
+ 'clihost',
|
|
|
|
+ '--port',
|
|
|
|
+ 'cliport',
|
|
|
|
+ '--username',
|
|
|
|
+ 'cliusername',
|
|
|
|
+ '--dbname',
|
|
|
|
+ 'foo',
|
|
|
|
+ '--command',
|
|
|
|
+ 'ANALYZE',
|
|
|
|
+ ),
|
|
|
|
+ extra_environment={'PGPASSWORD': 'clipassword', 'PGSSLMODE': 'disable'},
|
|
|
|
+ ).once()
|
|
|
|
+
|
|
|
|
+ module.restore_database_dump(
|
|
|
|
+ database_config,
|
|
|
|
+ 'test.yaml',
|
|
|
|
+ {},
|
|
|
|
+ dry_run=False,
|
|
|
|
+ extract_process=extract_process,
|
|
|
|
+ connection_params={
|
|
|
|
+ 'hostname': 'clihost',
|
|
|
|
+ 'port': 'cliport',
|
|
|
|
+ 'username': 'cliusername',
|
|
|
|
+ 'password': 'clipassword',
|
|
|
|
+ },
|
|
|
|
+ )
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+def test_restore_database_dump_without_connection_params_uses_restore_params_in_config_for_restore():
|
|
|
|
+ database_config = [
|
|
|
|
+ {
|
|
|
|
+ 'name': 'foo',
|
|
|
|
+ 'hostname': 'database.example.org',
|
|
|
|
+ 'port': 5433,
|
|
|
|
+ 'username': 'postgres',
|
|
|
|
+ 'password': 'trustsome1',
|
|
|
|
+ 'schemas': None,
|
|
|
|
+ 'restore_hostname': 'restorehost',
|
|
|
|
+ 'restore_port': 'restoreport',
|
|
|
|
+ 'restore_username': 'restoreusername',
|
|
|
|
+ 'restore_password': 'restorepassword',
|
|
|
|
+ }
|
|
|
|
+ ]
|
|
|
|
+ extract_process = flexmock(stdout=flexmock())
|
|
|
|
+
|
|
|
|
+ flexmock(module).should_receive('make_extra_environment').and_return(
|
|
|
|
+ {'PGPASSWORD': 'restorepassword', 'PGSSLMODE': 'disable'}
|
|
|
|
+ )
|
|
|
|
+ flexmock(module).should_receive('make_dump_path')
|
|
|
|
+ flexmock(module.dump).should_receive('make_database_dump_filename')
|
|
|
|
+ flexmock(module).should_receive('execute_command_with_processes').with_args(
|
|
|
|
+ (
|
|
|
|
+ 'pg_restore',
|
|
|
|
+ '--no-password',
|
|
|
|
+ '--if-exists',
|
|
|
|
+ '--exit-on-error',
|
|
|
|
+ '--clean',
|
|
|
|
+ '--dbname',
|
|
|
|
+ 'foo',
|
|
|
|
+ '--host',
|
|
|
|
+ 'restorehost',
|
|
|
|
+ '--port',
|
|
|
|
+ 'restoreport',
|
|
|
|
+ '--username',
|
|
|
|
+ 'restoreusername',
|
|
|
|
+ ),
|
|
|
|
+ processes=[extract_process],
|
|
|
|
+ output_log_level=logging.DEBUG,
|
|
|
|
+ input_file=extract_process.stdout,
|
|
|
|
+ extra_environment={'PGPASSWORD': 'restorepassword', 'PGSSLMODE': 'disable'},
|
|
|
|
+ ).once()
|
|
|
|
+ flexmock(module).should_receive('execute_command').with_args(
|
|
|
|
+ (
|
|
|
|
+ 'psql',
|
|
|
|
+ '--no-password',
|
|
|
|
+ '--no-psqlrc',
|
|
|
|
+ '--quiet',
|
|
|
|
+ '--host',
|
|
|
|
+ 'restorehost',
|
|
|
|
+ '--port',
|
|
|
|
+ 'restoreport',
|
|
|
|
+ '--username',
|
|
|
|
+ 'restoreusername',
|
|
|
|
+ '--dbname',
|
|
|
|
+ 'foo',
|
|
|
|
+ '--command',
|
|
|
|
+ 'ANALYZE',
|
|
|
|
+ ),
|
|
|
|
+ extra_environment={'PGPASSWORD': 'restorepassword', 'PGSSLMODE': 'disable'},
|
|
|
|
+ ).once()
|
|
|
|
+
|
|
|
|
+ module.restore_database_dump(
|
|
|
|
+ database_config,
|
|
|
|
+ 'test.yaml',
|
|
|
|
+ {},
|
|
|
|
+ dry_run=False,
|
|
|
|
+ extract_process=extract_process,
|
|
|
|
+ connection_params={
|
|
|
|
+ 'hostname': None,
|
|
|
|
+ 'port': None,
|
|
|
|
+ 'username': None,
|
|
|
|
+ 'password': None,
|
|
|
|
+ },
|
|
)
|
|
)
|
|
|
|
|
|
|
|
|
|
@@ -644,7 +850,17 @@ def test_restore_database_dump_runs_pg_restore_with_options():
|
|
).once()
|
|
).once()
|
|
|
|
|
|
module.restore_database_dump(
|
|
module.restore_database_dump(
|
|
- database_config, 'test.yaml', {}, dry_run=False, extract_process=extract_process
|
|
|
|
|
|
+ database_config,
|
|
|
|
+ 'test.yaml',
|
|
|
|
+ {},
|
|
|
|
+ dry_run=False,
|
|
|
|
+ extract_process=extract_process,
|
|
|
|
+ connection_params={
|
|
|
|
+ 'hostname': None,
|
|
|
|
+ 'port': None,
|
|
|
|
+ 'username': None,
|
|
|
|
+ 'password': None,
|
|
|
|
+ },
|
|
)
|
|
)
|
|
|
|
|
|
|
|
|
|
@@ -672,7 +888,17 @@ def test_restore_database_dump_runs_psql_for_all_database_dump():
|
|
).once()
|
|
).once()
|
|
|
|
|
|
module.restore_database_dump(
|
|
module.restore_database_dump(
|
|
- database_config, 'test.yaml', {}, dry_run=False, extract_process=extract_process
|
|
|
|
|
|
+ database_config,
|
|
|
|
+ 'test.yaml',
|
|
|
|
+ {},
|
|
|
|
+ dry_run=False,
|
|
|
|
+ extract_process=extract_process,
|
|
|
|
+ connection_params={
|
|
|
|
+ 'hostname': None,
|
|
|
|
+ 'port': None,
|
|
|
|
+ 'username': None,
|
|
|
|
+ 'password': None,
|
|
|
|
+ },
|
|
)
|
|
)
|
|
|
|
|
|
|
|
|
|
@@ -705,7 +931,17 @@ def test_restore_database_dump_runs_psql_for_plain_database_dump():
|
|
).once()
|
|
).once()
|
|
|
|
|
|
module.restore_database_dump(
|
|
module.restore_database_dump(
|
|
- database_config, 'test.yaml', {}, dry_run=False, extract_process=extract_process
|
|
|
|
|
|
+ database_config,
|
|
|
|
+ 'test.yaml',
|
|
|
|
+ {},
|
|
|
|
+ dry_run=False,
|
|
|
|
+ extract_process=extract_process,
|
|
|
|
+ connection_params={
|
|
|
|
+ 'hostname': None,
|
|
|
|
+ 'port': None,
|
|
|
|
+ 'username': None,
|
|
|
|
+ 'password': None,
|
|
|
|
+ },
|
|
)
|
|
)
|
|
|
|
|
|
|
|
|
|
@@ -759,7 +995,17 @@ def test_restore_database_dump_runs_non_default_pg_restore_and_psql():
|
|
).once()
|
|
).once()
|
|
|
|
|
|
module.restore_database_dump(
|
|
module.restore_database_dump(
|
|
- database_config, 'test.yaml', {}, dry_run=False, extract_process=extract_process
|
|
|
|
|
|
+ database_config,
|
|
|
|
+ 'test.yaml',
|
|
|
|
+ {},
|
|
|
|
+ dry_run=False,
|
|
|
|
+ extract_process=extract_process,
|
|
|
|
+ connection_params={
|
|
|
|
+ 'hostname': None,
|
|
|
|
+ 'port': None,
|
|
|
|
+ 'username': None,
|
|
|
|
+ 'password': None,
|
|
|
|
+ },
|
|
)
|
|
)
|
|
|
|
|
|
|
|
|
|
@@ -772,7 +1018,17 @@ def test_restore_database_dump_with_dry_run_skips_restore():
|
|
flexmock(module).should_receive('execute_command_with_processes').never()
|
|
flexmock(module).should_receive('execute_command_with_processes').never()
|
|
|
|
|
|
module.restore_database_dump(
|
|
module.restore_database_dump(
|
|
- database_config, 'test.yaml', {}, dry_run=True, extract_process=flexmock()
|
|
|
|
|
|
+ database_config,
|
|
|
|
+ 'test.yaml',
|
|
|
|
+ {},
|
|
|
|
+ dry_run=True,
|
|
|
|
+ extract_process=flexmock(),
|
|
|
|
+ connection_params={
|
|
|
|
+ 'hostname': None,
|
|
|
|
+ 'port': None,
|
|
|
|
+ 'username': None,
|
|
|
|
+ 'password': None,
|
|
|
|
+ },
|
|
)
|
|
)
|
|
|
|
|
|
|
|
|
|
@@ -813,7 +1069,17 @@ def test_restore_database_dump_without_extract_process_restores_from_disk():
|
|
).once()
|
|
).once()
|
|
|
|
|
|
module.restore_database_dump(
|
|
module.restore_database_dump(
|
|
- database_config, 'test.yaml', {}, dry_run=False, extract_process=None
|
|
|
|
|
|
+ database_config,
|
|
|
|
+ 'test.yaml',
|
|
|
|
+ {},
|
|
|
|
+ dry_run=False,
|
|
|
|
+ extract_process=None,
|
|
|
|
+ connection_params={
|
|
|
|
+ 'hostname': None,
|
|
|
|
+ 'port': None,
|
|
|
|
+ 'username': None,
|
|
|
|
+ 'password': None,
|
|
|
|
+ },
|
|
)
|
|
)
|
|
|
|
|
|
|
|
|
|
@@ -858,5 +1124,15 @@ def test_restore_database_dump_with_schemas_restores_schemas():
|
|
).once()
|
|
).once()
|
|
|
|
|
|
module.restore_database_dump(
|
|
module.restore_database_dump(
|
|
- database_config, 'test.yaml', {}, dry_run=False, extract_process=None
|
|
|
|
|
|
+ database_config,
|
|
|
|
+ 'test.yaml',
|
|
|
|
+ {},
|
|
|
|
+ dry_run=False,
|
|
|
|
+ extract_process=None,
|
|
|
|
+ connection_params={
|
|
|
|
+ 'hostname': None,
|
|
|
|
+ 'port': None,
|
|
|
|
+ 'username': None,
|
|
|
|
+ 'password': None,
|
|
|
|
+ },
|
|
)
|
|
)
|