test_mount.py 7.3 KB

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