test_mount.py 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. import logging
  2. from flexmock import flexmock
  3. from borgmatic.borg import mount as module
  4. from ..test_verbosity import insert_logging_mock
  5. def insert_execute_command_mock(command):
  6. flexmock(module.environment).should_receive('make_environment')
  7. flexmock(module).should_receive('execute_command').with_args(
  8. command, borg_local_path='borg', extra_environment=None,
  9. ).once()
  10. def test_mount_archive_calls_borg_with_required_parameters():
  11. flexmock(module.feature).should_receive('available').and_return(False)
  12. flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
  13. ('repo::archive',)
  14. )
  15. insert_execute_command_mock(('borg', 'mount', 'repo::archive', '/mnt'))
  16. module.mount_archive(
  17. repository='repo',
  18. archive='archive',
  19. mount_point='/mnt',
  20. paths=None,
  21. foreground=False,
  22. options=None,
  23. storage_config={},
  24. local_borg_version='1.2.3',
  25. )
  26. def test_mount_archive_with_borg_features_calls_borg_with_repository_and_glob_archives_flags():
  27. flexmock(module.feature).should_receive('available').and_return(True)
  28. flexmock(module.flags).should_receive('make_repository_flags').and_return(('--repo', 'repo',))
  29. insert_execute_command_mock(
  30. ('borg', 'mount', '--repo', 'repo', '--glob-archives', 'archive', '/mnt')
  31. )
  32. module.mount_archive(
  33. repository='repo',
  34. archive='archive',
  35. mount_point='/mnt',
  36. paths=None,
  37. foreground=False,
  38. options=None,
  39. storage_config={},
  40. local_borg_version='1.2.3',
  41. )
  42. def test_mount_archive_calls_borg_with_path_parameters():
  43. flexmock(module.feature).should_receive('available').and_return(False)
  44. flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
  45. ('repo::archive',)
  46. )
  47. insert_execute_command_mock(('borg', 'mount', 'repo::archive', '/mnt', 'path1', 'path2'))
  48. module.mount_archive(
  49. repository='repo',
  50. archive='archive',
  51. mount_point='/mnt',
  52. paths=['path1', 'path2'],
  53. foreground=False,
  54. options=None,
  55. storage_config={},
  56. local_borg_version='1.2.3',
  57. )
  58. def test_mount_archive_calls_borg_with_remote_path_parameters():
  59. flexmock(module.feature).should_receive('available').and_return(False)
  60. flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
  61. ('repo::archive',)
  62. )
  63. insert_execute_command_mock(
  64. ('borg', 'mount', '--remote-path', 'borg1', 'repo::archive', '/mnt')
  65. )
  66. module.mount_archive(
  67. repository='repo',
  68. archive='archive',
  69. mount_point='/mnt',
  70. paths=None,
  71. foreground=False,
  72. options=None,
  73. storage_config={},
  74. local_borg_version='1.2.3',
  75. remote_path='borg1',
  76. )
  77. def test_mount_archive_calls_borg_with_umask_parameters():
  78. flexmock(module.feature).should_receive('available').and_return(False)
  79. flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
  80. ('repo::archive',)
  81. )
  82. insert_execute_command_mock(('borg', 'mount', '--umask', '0770', 'repo::archive', '/mnt'))
  83. module.mount_archive(
  84. repository='repo',
  85. archive='archive',
  86. mount_point='/mnt',
  87. paths=None,
  88. foreground=False,
  89. options=None,
  90. storage_config={'umask': '0770'},
  91. local_borg_version='1.2.3',
  92. )
  93. def test_mount_archive_calls_borg_with_lock_wait_parameters():
  94. flexmock(module.feature).should_receive('available').and_return(False)
  95. flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
  96. ('repo::archive',)
  97. )
  98. insert_execute_command_mock(('borg', 'mount', '--lock-wait', '5', 'repo::archive', '/mnt'))
  99. module.mount_archive(
  100. repository='repo',
  101. archive='archive',
  102. mount_point='/mnt',
  103. paths=None,
  104. foreground=False,
  105. options=None,
  106. storage_config={'lock_wait': '5'},
  107. local_borg_version='1.2.3',
  108. )
  109. def test_mount_archive_with_log_info_calls_borg_with_info_parameter():
  110. flexmock(module.feature).should_receive('available').and_return(False)
  111. flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
  112. ('repo::archive',)
  113. )
  114. insert_execute_command_mock(('borg', 'mount', '--info', 'repo::archive', '/mnt'))
  115. insert_logging_mock(logging.INFO)
  116. module.mount_archive(
  117. repository='repo',
  118. archive='archive',
  119. mount_point='/mnt',
  120. paths=None,
  121. foreground=False,
  122. options=None,
  123. storage_config={},
  124. local_borg_version='1.2.3',
  125. )
  126. def test_mount_archive_with_log_debug_calls_borg_with_debug_parameters():
  127. flexmock(module.feature).should_receive('available').and_return(False)
  128. flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
  129. ('repo::archive',)
  130. )
  131. insert_execute_command_mock(('borg', 'mount', '--debug', '--show-rc', 'repo::archive', '/mnt'))
  132. insert_logging_mock(logging.DEBUG)
  133. module.mount_archive(
  134. repository='repo',
  135. archive='archive',
  136. mount_point='/mnt',
  137. paths=None,
  138. foreground=False,
  139. options=None,
  140. storage_config={},
  141. local_borg_version='1.2.3',
  142. )
  143. def test_mount_archive_calls_borg_with_foreground_parameter():
  144. flexmock(module.feature).should_receive('available').and_return(False)
  145. flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
  146. ('repo::archive',)
  147. )
  148. flexmock(module.environment).should_receive('make_environment')
  149. flexmock(module).should_receive('execute_command').with_args(
  150. ('borg', 'mount', '--foreground', 'repo::archive', '/mnt'),
  151. output_file=module.DO_NOT_CAPTURE,
  152. borg_local_path='borg',
  153. extra_environment=None,
  154. ).once()
  155. module.mount_archive(
  156. repository='repo',
  157. archive='archive',
  158. mount_point='/mnt',
  159. paths=None,
  160. foreground=True,
  161. options=None,
  162. storage_config={},
  163. local_borg_version='1.2.3',
  164. )
  165. def test_mount_archive_calls_borg_with_options_parameters():
  166. flexmock(module.feature).should_receive('available').and_return(False)
  167. flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
  168. ('repo::archive',)
  169. )
  170. insert_execute_command_mock(('borg', 'mount', '-o', 'super_mount', 'repo::archive', '/mnt'))
  171. module.mount_archive(
  172. repository='repo',
  173. archive='archive',
  174. mount_point='/mnt',
  175. paths=None,
  176. foreground=False,
  177. options='super_mount',
  178. storage_config={},
  179. local_borg_version='1.2.3',
  180. )