test_mount.py 7.2 KB

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