Sfoglia il codice sorgente

Fix (some) end-to-end tests (#721).

Dan Helfman 1 anno fa
parent
commit
ab351548d2

+ 2 - 2
borgmatic/hooks/cronhub.py

@@ -14,7 +14,7 @@ MONITOR_STATE_TO_CRONHUB = {
 
 
 
 
 def initialize_monitor(
 def initialize_monitor(
-    ping_url, config_filename, monitoring_log_level, dry_run
+    ping_url, config, config_filename, monitoring_log_level, dry_run
 ):  # pragma: no cover
 ):  # pragma: no cover
     '''
     '''
     No initialization is necessary for this monitor.
     No initialization is necessary for this monitor.
@@ -55,7 +55,7 @@ def ping_monitor(hook_config, config, config_filename, state, monitoring_log_lev
 
 
 
 
 def destroy_monitor(
 def destroy_monitor(
-    ping_url_or_uuid, config_filename, monitoring_log_level, dry_run
+    ping_url_or_uuid, config, config_filename, monitoring_log_level, dry_run
 ):  # pragma: no cover
 ):  # pragma: no cover
     '''
     '''
     No destruction is necessary for this monitor.
     No destruction is necessary for this monitor.

+ 2 - 2
borgmatic/hooks/cronitor.py

@@ -14,7 +14,7 @@ MONITOR_STATE_TO_CRONITOR = {
 
 
 
 
 def initialize_monitor(
 def initialize_monitor(
-    ping_url, config_filename, monitoring_log_level, dry_run
+    ping_url, config, config_filename, monitoring_log_level, dry_run
 ):  # pragma: no cover
 ):  # pragma: no cover
     '''
     '''
     No initialization is necessary for this monitor.
     No initialization is necessary for this monitor.
@@ -50,7 +50,7 @@ def ping_monitor(hook_config, config, config_filename, state, monitoring_log_lev
 
 
 
 
 def destroy_monitor(
 def destroy_monitor(
-    ping_url_or_uuid, config_filename, monitoring_log_level, dry_run
+    ping_url_or_uuid, config, config_filename, monitoring_log_level, dry_run
 ):  # pragma: no cover
 ):  # pragma: no cover
     '''
     '''
     No destruction is necessary for this monitor.
     No destruction is necessary for this monitor.

+ 2 - 2
borgmatic/hooks/healthchecks.py

@@ -70,7 +70,7 @@ def format_buffered_logs_for_payload():
     return payload
     return payload
 
 
 
 
-def initialize_monitor(hook_config, config_filename, monitoring_log_level, dry_run):
+def initialize_monitor(hook_config, config, config_filename, monitoring_log_level, dry_run):
     '''
     '''
     Add a handler to the root logger that stores in memory the most recent logs emitted. That way,
     Add a handler to the root logger that stores in memory the most recent logs emitted. That way,
     we can send them all to Healthchecks upon a finish or failure state. But skip this if the
     we can send them all to Healthchecks upon a finish or failure state. But skip this if the
@@ -133,7 +133,7 @@ def ping_monitor(hook_config, config, config_filename, state, monitoring_log_lev
             logger.warning(f'{config_filename}: Healthchecks error: {error}')
             logger.warning(f'{config_filename}: Healthchecks error: {error}')
 
 
 
 
-def destroy_monitor(hook_config, config_filename, monitoring_log_level, dry_run):
+def destroy_monitor(hook_config, config, config_filename, monitoring_log_level, dry_run):
     '''
     '''
     Remove the monitor handler that was added to the root logger. This prevents the handler from
     Remove the monitor handler that was added to the root logger. This prevents the handler from
     getting reused by other instances of this monitor.
     getting reused by other instances of this monitor.

+ 2 - 2
borgmatic/hooks/ntfy.py

@@ -6,7 +6,7 @@ logger = logging.getLogger(__name__)
 
 
 
 
 def initialize_monitor(
 def initialize_monitor(
-    ping_url, config_filename, monitoring_log_level, dry_run
+    ping_url, config, config_filename, monitoring_log_level, dry_run
 ):  # pragma: no cover
 ):  # pragma: no cover
     '''
     '''
     No initialization is necessary for this monitor.
     No initialization is necessary for this monitor.
@@ -75,7 +75,7 @@ def ping_monitor(hook_config, config, config_filename, state, monitoring_log_lev
 
 
 
 
 def destroy_monitor(
 def destroy_monitor(
-    ping_url_or_uuid, config_filename, monitoring_log_level, dry_run
+    ping_url_or_uuid, config, config_filename, monitoring_log_level, dry_run
 ):  # pragma: no cover
 ):  # pragma: no cover
     '''
     '''
     No destruction is necessary for this monitor.
     No destruction is necessary for this monitor.

+ 2 - 2
borgmatic/hooks/pagerduty.py

@@ -13,7 +13,7 @@ EVENTS_API_URL = 'https://events.pagerduty.com/v2/enqueue'
 
 
 
 
 def initialize_monitor(
 def initialize_monitor(
-    integration_key, config_filename, monitoring_log_level, dry_run
+    integration_key, config, config_filename, monitoring_log_level, dry_run
 ):  # pragma: no cover
 ):  # pragma: no cover
     '''
     '''
     No initialization is necessary for this monitor.
     No initialization is necessary for this monitor.
@@ -75,7 +75,7 @@ def ping_monitor(hook_config, config, config_filename, state, monitoring_log_lev
 
 
 
 
 def destroy_monitor(
 def destroy_monitor(
-    ping_url_or_uuid, config_filename, monitoring_log_level, dry_run
+    ping_url_or_uuid, config, config_filename, monitoring_log_level, dry_run
 ):  # pragma: no cover
 ):  # pragma: no cover
     '''
     '''
     No destruction is necessary for this monitor.
     No destruction is necessary for this monitor.

+ 107 - 116
tests/end-to-end/test_database.py

@@ -22,60 +22,57 @@ def write_configuration(
     storing database dumps, dump format (for PostgreSQL), and encryption passphrase.
     storing database dumps, dump format (for PostgreSQL), and encryption passphrase.
     '''
     '''
     config = f'''
     config = f'''
-location:
-    source_directories:
-        - {source_directory}
-    repositories:
-        - {repository_path}
-    borgmatic_source_directory: {borgmatic_source_directory}
-
-storage:
-    encryption_passphrase: "test"
-
-hooks:
-    postgresql_databases:
-        - name: test
-          hostname: postgresql
-          username: postgres
-          password: test
-          format: {postgresql_dump_format}
-        - name: all
-          hostname: postgresql
-          username: postgres
-          password: test
-        - name: all
-          format: custom
-          hostname: postgresql
-          username: postgres
-          password: test
-    mysql_databases:
-        - name: test
-          hostname: mysql
-          username: root
-          password: test
-        - name: all
-          hostname: mysql
-          username: root
-          password: test
-        - name: all
-          format: sql
-          hostname: mysql
-          username: root
-          password: test
-    mongodb_databases:
-        - name: test
-          hostname: mongodb
-          username: root
-          password: test
-          authentication_database: admin
-          format: {mongodb_dump_format}
-        - name: all
-          hostname: mongodb
-          username: root
-          password: test
-    sqlite_databases:
-        - name: sqlite_test
-          path: /tmp/sqlite_test.db
+source_directories:
+    - {source_directory}
+repositories:
+    - {repository_path}
+borgmatic_source_directory: {borgmatic_source_directory}
+
+encryption_passphrase: "test"
+
+postgresql_databases:
+    - name: test
+      hostname: postgresql
+      username: postgres
+      password: test
+      format: {postgresql_dump_format}
+    - name: all
+      hostname: postgresql
+      username: postgres
+      password: test
+    - name: all
+      format: custom
+      hostname: postgresql
+      username: postgres
+      password: test
+mysql_databases:
+    - name: test
+      hostname: mysql
+      username: root
+      password: test
+    - name: all
+      hostname: mysql
+      username: root
+      password: test
+    - name: all
+      format: sql
+      hostname: mysql
+      username: root
+      password: test
+mongodb_databases:
+    - name: test
+      hostname: mongodb
+      username: root
+      password: test
+      authentication_database: admin
+      format: {mongodb_dump_format}
+    - name: all
+      hostname: mongodb
+      username: root
+      password: test
+sqlite_databases:
+    - name: sqlite_test
+      path: /tmp/sqlite_test.db
 '''
 '''
 
 
     with open(config_path, 'w') as config_file:
     with open(config_path, 'w') as config_file:
@@ -96,51 +93,48 @@ def write_custom_restore_configuration(
     restore_username, restore_password and restore_path.
     restore_username, restore_password and restore_path.
     '''
     '''
     config = f'''
     config = f'''
-location:
-    source_directories:
-        - {source_directory}
-    repositories:
-        - {repository_path}
-    borgmatic_source_directory: {borgmatic_source_directory}
-
-storage:
-    encryption_passphrase: "test"
-
-hooks:
-    postgresql_databases:
-        - name: test
-          hostname: postgresql
-          username: postgres
-          password: test
-          format: {postgresql_dump_format}
-          restore_hostname: postgresql2
-          restore_port: 5433
-          restore_username: postgres2
-          restore_password: test2
-    mysql_databases:
-        - name: test
-          hostname: mysql
-          username: root
-          password: test
-          restore_hostname: mysql2
-          restore_port: 3307
-          restore_username: root
-          restore_password: test2
-    mongodb_databases:
-        - name: test
-          hostname: mongodb
-          username: root
-          password: test
-          authentication_database: admin
-          format: {mongodb_dump_format}
-          restore_hostname: mongodb2
-          restore_port: 27018
-          restore_username: root2
-          restore_password: test2
-    sqlite_databases:
-        - name: sqlite_test
-          path: /tmp/sqlite_test.db
-          restore_path: /tmp/sqlite_test2.db
+source_directories:
+    - {source_directory}
+repositories:
+    - {repository_path}
+borgmatic_source_directory: {borgmatic_source_directory}
+
+encryption_passphrase: "test"
+
+postgresql_databases:
+    - name: test
+      hostname: postgresql
+      username: postgres
+      password: test
+      format: {postgresql_dump_format}
+      restore_hostname: postgresql2
+      restore_port: 5433
+      restore_username: postgres2
+      restore_password: test2
+mysql_databases:
+    - name: test
+      hostname: mysql
+      username: root
+      password: test
+      restore_hostname: mysql2
+      restore_port: 3307
+      restore_username: root
+      restore_password: test2
+mongodb_databases:
+    - name: test
+      hostname: mongodb
+      username: root
+      password: test
+      authentication_database: admin
+      format: {mongodb_dump_format}
+      restore_hostname: mongodb2
+      restore_port: 27018
+      restore_username: root2
+      restore_password: test2
+sqlite_databases:
+    - name: sqlite_test
+      path: /tmp/sqlite_test.db
+      restore_path: /tmp/sqlite_test2.db
 '''
 '''
 
 
     with open(config_path, 'w') as config_file:
     with open(config_path, 'w') as config_file:
@@ -161,23 +155,20 @@ def write_simple_custom_restore_configuration(
     these options for PostgreSQL.
     these options for PostgreSQL.
     '''
     '''
     config = f'''
     config = f'''
-location:
-    source_directories:
-        - {source_directory}
-    repositories:
-        - {repository_path}
-    borgmatic_source_directory: {borgmatic_source_directory}
-
-storage:
-    encryption_passphrase: "test"
-
-hooks:
-    postgresql_databases:
-        - name: test
-          hostname: postgresql
-          username: postgres
-          password: test
-          format: {postgresql_dump_format}
+source_directories:
+    - {source_directory}
+repositories:
+    - {repository_path}
+borgmatic_source_directory: {borgmatic_source_directory}
+
+encryption_passphrase: "test"
+
+postgresql_databases:
+    - name: test
+      hostname: postgresql
+      username: postgres
+      password: test
+      format: {postgresql_dump_format}
 '''
 '''
 
 
     with open(config_path, 'w') as config_file:
     with open(config_path, 'w') as config_file:

+ 0 - 1
tests/end-to-end/test_validate_config.py

@@ -38,5 +38,4 @@ def test_validate_config_command_with_show_flag_displays_configuration():
             f'validate-borgmatic-config --config {config_path} --show'.split(' ')
             f'validate-borgmatic-config --config {config_path} --show'.split(' ')
         ).decode(sys.stdout.encoding)
         ).decode(sys.stdout.encoding)
 
 
-        assert 'location:' in output
         assert 'repositories:' in output
         assert 'repositories:' in output

+ 2 - 2
tests/integration/hooks/test_healthchecks.py

@@ -10,7 +10,7 @@ def test_destroy_monitor_removes_healthchecks_handler():
     original_handlers = list(logger.handlers)
     original_handlers = list(logger.handlers)
     logger.addHandler(module.Forgetful_buffering_handler(byte_capacity=100, log_level=1))
     logger.addHandler(module.Forgetful_buffering_handler(byte_capacity=100, log_level=1))
 
 
-    module.destroy_monitor(flexmock(), flexmock(), flexmock(), flexmock())
+    module.destroy_monitor(flexmock(), flexmock(), flexmock(), flexmock(), flexmock())
 
 
     assert logger.handlers == original_handlers
     assert logger.handlers == original_handlers
 
 
@@ -19,6 +19,6 @@ def test_destroy_monitor_without_healthchecks_handler_does_not_raise():
     logger = logging.getLogger()
     logger = logging.getLogger()
     original_handlers = list(logger.handlers)
     original_handlers = list(logger.handlers)
 
 
-    module.destroy_monitor(flexmock(), flexmock(), flexmock(), flexmock())
+    module.destroy_monitor(flexmock(), flexmock(), flexmock(), flexmock(), flexmock())
 
 
     assert logger.handlers == original_handlers
     assert logger.handlers == original_handlers

+ 5 - 5
tests/unit/hooks/test_healthchecks.py

@@ -86,7 +86,7 @@ def test_initialize_monitor_creates_log_handler_with_ping_body_limit():
     ).once()
     ).once()
 
 
     module.initialize_monitor(
     module.initialize_monitor(
-        {'ping_body_limit': ping_body_limit}, 'test.yaml', monitoring_log_level, dry_run=False
+        {'ping_body_limit': ping_body_limit}, {}, 'test.yaml', monitoring_log_level, dry_run=False
     )
     )
 
 
 
 
@@ -99,7 +99,7 @@ def test_initialize_monitor_creates_log_handler_with_default_ping_body_limit():
         monitoring_log_level,
         monitoring_log_level,
     ).once()
     ).once()
 
 
-    module.initialize_monitor({}, 'test.yaml', monitoring_log_level, dry_run=False)
+    module.initialize_monitor({}, {}, 'test.yaml', monitoring_log_level, dry_run=False)
 
 
 
 
 def test_initialize_monitor_creates_log_handler_with_zero_ping_body_limit():
 def test_initialize_monitor_creates_log_handler_with_zero_ping_body_limit():
@@ -112,7 +112,7 @@ def test_initialize_monitor_creates_log_handler_with_zero_ping_body_limit():
     ).once()
     ).once()
 
 
     module.initialize_monitor(
     module.initialize_monitor(
-        {'ping_body_limit': ping_body_limit}, 'test.yaml', monitoring_log_level, dry_run=False
+        {'ping_body_limit': ping_body_limit}, {}, 'test.yaml', monitoring_log_level, dry_run=False
     )
     )
 
 
 
 
@@ -121,7 +121,7 @@ def test_initialize_monitor_creates_log_handler_when_send_logs_true():
     flexmock(module).should_receive('Forgetful_buffering_handler').once()
     flexmock(module).should_receive('Forgetful_buffering_handler').once()
 
 
     module.initialize_monitor(
     module.initialize_monitor(
-        {'send_logs': True}, 'test.yaml', monitoring_log_level=1, dry_run=False
+        {'send_logs': True}, {}, 'test.yaml', monitoring_log_level=1, dry_run=False
     )
     )
 
 
 
 
@@ -130,7 +130,7 @@ def test_initialize_monitor_bails_when_send_logs_false():
     flexmock(module).should_receive('Forgetful_buffering_handler').never()
     flexmock(module).should_receive('Forgetful_buffering_handler').never()
 
 
     module.initialize_monitor(
     module.initialize_monitor(
-        {'send_logs': False}, 'test.yaml', monitoring_log_level=1, dry_run=False
+        {'send_logs': False}, {}, 'test.yaml', monitoring_log_level=1, dry_run=False
     )
     )