zfs.py 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749
  1. # -*- coding: utf-8 -*-
  2. """
  3. tests.support.zfs
  4. ~~~~~~~~~~~~~~~~~
  5. ZFS related unit test data structures
  6. """
  7. # Import Python libs
  8. from __future__ import absolute_import, print_function, unicode_literals
  9. # Import salt libs
  10. import salt.utils.zfs
  11. # Import Salt tests libs
  12. from tests.support.mock import MagicMock, patch
  13. class ZFSMockData(object):
  14. def __init__(self):
  15. # property_map mocks
  16. self.pmap_exec_zpool = {
  17. "retcode": 2,
  18. "stdout": "",
  19. "stderr": "\n".join(
  20. [
  21. "missing property argument",
  22. "usage:",
  23. ' get [-Hp] [-o "all" | field[,...]] <"all" | property[,...]> <pool> ...',
  24. "",
  25. "the following properties are supported:",
  26. "",
  27. " PROPERTY EDIT VALUES",
  28. "",
  29. " allocated NO <size>",
  30. " capacity NO <size>",
  31. " dedupratio NO <1.00x or higher if deduped>",
  32. " expandsize NO <size>",
  33. " fragmentation NO <percent>",
  34. " free NO <size>",
  35. " freeing NO <size>",
  36. " guid NO <guid>",
  37. " health NO <state>",
  38. " leaked NO <size>",
  39. " size NO <size>",
  40. " altroot YES <path>",
  41. " autoexpand YES on | off",
  42. " autoreplace YES on | off",
  43. " bootfs YES <filesystem>",
  44. " bootsize YES <size>",
  45. " cachefile YES <file> | none",
  46. " comment YES <comment-string>",
  47. " dedupditto YES <threshold (min 100)>",
  48. " delegation YES on | off",
  49. " failmode YES wait | continue | panic",
  50. " listsnapshots YES on | off",
  51. " readonly YES on | off",
  52. " version YES <version>",
  53. " feature@... YES disabled | enabled | active",
  54. "",
  55. "The feature@ properties must be appended with a feature name.",
  56. "See zpool-features(5). ",
  57. ]
  58. ),
  59. }
  60. self.pmap_zpool = {
  61. "comment": {"edit": True, "type": "str", "values": "<comment-string>"},
  62. "freeing": {"edit": False, "type": "size", "values": "<size>"},
  63. "listsnapshots": {"edit": True, "type": "bool", "values": "on | off"},
  64. "leaked": {"edit": False, "type": "size", "values": "<size>"},
  65. "version": {"edit": True, "type": "numeric", "values": "<version>"},
  66. "write": {"edit": False, "type": "size", "values": "<size>"},
  67. "replace": {"edit": True, "type": "bool", "values": "on | off"},
  68. "delegation": {"edit": True, "type": "bool", "values": "on | off"},
  69. "dedupditto": {
  70. "edit": True,
  71. "type": "str",
  72. "values": "<threshold (min 100)>",
  73. },
  74. "autoexpand": {"edit": True, "type": "bool", "values": "on | off"},
  75. "alloc": {"edit": False, "type": "size", "values": "<size>"},
  76. "allocated": {"edit": False, "type": "size", "values": "<size>"},
  77. "guid": {"edit": False, "type": "numeric", "values": "<guid>"},
  78. "size": {"edit": False, "type": "size", "values": "<size>"},
  79. "cap": {"edit": False, "type": "numeric", "values": "<count>"},
  80. "capacity": {"edit": False, "type": "size", "values": "<size>"},
  81. "capacity-alloc": {"edit": False, "type": "size", "values": "<size>"},
  82. "capacity-free": {"edit": False, "type": "size", "values": "<size>"},
  83. "cachefile": {"edit": True, "type": "str", "values": "<file> | none"},
  84. "cksum": {"edit": False, "type": "numeric", "values": "<count>"},
  85. "bootfs": {"edit": True, "type": "str", "values": "<filesystem>"},
  86. "autoreplace": {"edit": True, "type": "bool", "values": "on | off"},
  87. "bandwidth-read": {"edit": False, "type": "size", "values": "<size>"},
  88. "bandwidth-write": {"edit": False, "type": "size", "values": "<size>"},
  89. "operations-read": {"edit": False, "type": "size", "values": "<size>"},
  90. "operations-write": {"edit": False, "type": "size", "values": "<size>"},
  91. "read": {"edit": False, "type": "size", "values": "<size>"},
  92. "readonly": {"edit": True, "type": "bool", "values": "on | off"},
  93. "dedupratio": {
  94. "edit": False,
  95. "type": "str",
  96. "values": "<1.00x or higher if deduped>",
  97. },
  98. "health": {"edit": False, "type": "str", "values": "<state>"},
  99. "feature@": {
  100. "edit": True,
  101. "type": "str",
  102. "values": "disabled | enabled | active",
  103. },
  104. "expandsize": {"edit": False, "type": "size", "values": "<size>"},
  105. "listsnaps": {"edit": True, "type": "bool", "values": "on | off"},
  106. "bootsize": {"edit": True, "type": "size", "values": "<size>"},
  107. "free": {"edit": False, "type": "size", "values": "<size>"},
  108. "failmode": {
  109. "edit": True,
  110. "type": "str",
  111. "values": "wait | continue | panic",
  112. },
  113. "altroot": {"edit": True, "type": "str", "values": "<path>"},
  114. "expand": {"edit": True, "type": "bool", "values": "on | off"},
  115. "frag": {"edit": False, "type": "str", "values": "<percent>"},
  116. "fragmentation": {"edit": False, "type": "str", "values": "<percent>"},
  117. }
  118. self.pmap_exec_zfs = {
  119. "retcode": 2,
  120. "stdout": "",
  121. "stderr": "\n".join(
  122. [
  123. "missing property argument",
  124. "usage:",
  125. ' get [-crHp] [-d max] [-o "all" | field[,...]]',
  126. " [-t type[,...]] [-s source[,...]]",
  127. ' <"all" | property[,...]> [filesystem|volume|snapshot|bookmark] ...',
  128. "",
  129. "The following properties are supported:",
  130. "",
  131. " PROPERTY EDIT INHERIT VALUES",
  132. "",
  133. " available NO NO <size>",
  134. " clones NO NO <dataset>[,...]",
  135. " compressratio NO NO <1.00x or higher if compressed>",
  136. " creation NO NO <date>",
  137. " defer_destroy NO NO yes | no",
  138. " filesystem_count NO NO <count>",
  139. " logicalreferenced NO NO <size>",
  140. " logicalused NO NO <size>",
  141. " mounted NO NO yes | no",
  142. " origin NO NO <snapshot>",
  143. " receive_resume_token NO NO <string token>",
  144. " refcompressratio NO NO <1.00x or higher if compressed>",
  145. " referenced NO NO <size>",
  146. " snapshot_count NO NO <count>",
  147. " type NO NO filesystem | volume | snapshot | bookmark",
  148. " used NO NO <size>",
  149. " usedbychildren NO NO <size>",
  150. " usedbydataset NO NO <size>",
  151. " usedbyrefreservation NO NO <size>",
  152. " usedbysnapshots NO NO <size>",
  153. " userrefs NO NO <count>",
  154. " written NO NO <size>",
  155. " aclinherit YES YES discard | noallow | restricted | passthrough | passthrough-x",
  156. " aclmode YES YES discard | groupmask | passthrough | restricted",
  157. " atime YES YES on | off",
  158. " canmount YES NO on | off | noauto",
  159. " casesensitivity NO YES sensitive | insensitive | mixed",
  160. " checksum YES YES on | off | fletcher2 | fletcher4 | sha256 | sha512 | skein | edonr",
  161. " compression YES YES on | off | lzjb | gzip | gzip-[1-9] | zle | lz4",
  162. " copies YES YES 1 | 2 | 3",
  163. " dedup YES YES on | off | verify | sha256[,verify], sha512[,verify], skein[,verify], edonr,verify",
  164. " devices YES YES on | off",
  165. " exec YES YES on | off",
  166. " filesystem_limit YES NO <count> | none",
  167. " logbias YES YES latency | throughput",
  168. " mlslabel YES YES <sensitivity label>",
  169. " mountpoint YES YES <path> | legacy | none",
  170. " nbmand YES YES on | off",
  171. " normalization NO YES none | formC | formD | formKC | formKD",
  172. " primarycache YES YES all | none | metadata",
  173. " quota YES NO <size> | none",
  174. " readonly YES YES on | off",
  175. " recordsize YES YES 512 to 1M, power of 2",
  176. " redundant_metadata YES YES all | most",
  177. " refquota YES NO <size> | none",
  178. " refreservation YES NO <size> | none",
  179. " reservation YES NO <size> | none",
  180. " secondarycache YES YES all | none | metadata",
  181. " setuid YES YES on | off",
  182. " sharenfs YES YES on | off | share(1M) options",
  183. " sharesmb YES YES on | off | sharemgr(1M) options",
  184. " snapdir YES YES hidden | visible",
  185. " snapshot_limit YES NO <count> | none",
  186. " sync YES YES standard | always | disabled",
  187. " utf8only NO YES on | off",
  188. " version YES NO 1 | 2 | 3 | 4 | 5 | current",
  189. " volblocksize NO YES 512 to 128k, power of 2",
  190. " volsize YES NO <size>",
  191. " vscan YES YES on | off",
  192. " xattr YES YES on | off",
  193. " zoned YES YES on | off",
  194. " userused@... NO NO <size>",
  195. " groupused@... NO NO <size>",
  196. " userquota@... YES NO <size> | none",
  197. " groupquota@... YES NO <size> | none",
  198. " written@<snap> NO NO <size>",
  199. "",
  200. "Sizes are specified in bytes with standard units such as K, M, G, etc.",
  201. "",
  202. "User-defined properties can be specified by using a name containing a colon (:).",
  203. "",
  204. "The {user|group}{used|quota}@ properties must be appended with",
  205. "a user or group specifier of one of these forms:",
  206. ' POSIX name (eg: "matt")',
  207. ' POSIX id (eg: "126829")',
  208. ' SMB name@domain (eg: "matt@sun")',
  209. ' SMB SID (eg: "S-1-234-567-89")',
  210. ]
  211. ),
  212. }
  213. self.pmap_zfs = {
  214. "origin": {
  215. "edit": False,
  216. "inherit": False,
  217. "values": "<snapshot>",
  218. "type": "str",
  219. },
  220. "setuid": {
  221. "edit": True,
  222. "inherit": True,
  223. "values": "on | off",
  224. "type": "bool",
  225. },
  226. "referenced": {
  227. "edit": False,
  228. "inherit": False,
  229. "values": "<size>",
  230. "type": "size",
  231. },
  232. "vscan": {
  233. "edit": True,
  234. "inherit": True,
  235. "values": "on | off",
  236. "type": "bool",
  237. },
  238. "logicalused": {
  239. "edit": False,
  240. "inherit": False,
  241. "values": "<size>",
  242. "type": "size",
  243. },
  244. "userrefs": {
  245. "edit": False,
  246. "inherit": False,
  247. "values": "<count>",
  248. "type": "numeric",
  249. },
  250. "primarycache": {
  251. "edit": True,
  252. "inherit": True,
  253. "values": "all | none | metadata",
  254. "type": "str",
  255. },
  256. "logbias": {
  257. "edit": True,
  258. "inherit": True,
  259. "values": "latency | throughput",
  260. "type": "str",
  261. },
  262. "creation": {
  263. "edit": False,
  264. "inherit": False,
  265. "values": "<date>",
  266. "type": "str",
  267. },
  268. "sync": {
  269. "edit": True,
  270. "inherit": True,
  271. "values": "standard | always | disabled",
  272. "type": "str",
  273. },
  274. "dedup": {
  275. "edit": True,
  276. "inherit": True,
  277. "values": "on | off | verify | sha256[,verify], sha512[,verify], skein[,verify], edonr,verify",
  278. "type": "bool",
  279. },
  280. "sharenfs": {
  281. "edit": True,
  282. "inherit": True,
  283. "values": "on | off | share(1m) options",
  284. "type": "bool",
  285. },
  286. "receive_resume_token": {
  287. "edit": False,
  288. "inherit": False,
  289. "values": "<string token>",
  290. "type": "str",
  291. },
  292. "usedbyrefreservation": {
  293. "edit": False,
  294. "inherit": False,
  295. "values": "<size>",
  296. "type": "size",
  297. },
  298. "sharesmb": {
  299. "edit": True,
  300. "inherit": True,
  301. "values": "on | off | sharemgr(1m) options",
  302. "type": "bool",
  303. },
  304. "rdonly": {
  305. "edit": True,
  306. "inherit": True,
  307. "values": "on | off",
  308. "type": "bool",
  309. },
  310. "reservation": {
  311. "edit": True,
  312. "inherit": False,
  313. "values": "<size> | none",
  314. "type": "size",
  315. },
  316. "reserv": {
  317. "edit": True,
  318. "inherit": False,
  319. "values": "<size> | none",
  320. "type": "size",
  321. },
  322. "mountpoint": {
  323. "edit": True,
  324. "inherit": True,
  325. "values": "<path> | legacy | none",
  326. "type": "str",
  327. },
  328. "casesensitivity": {
  329. "edit": False,
  330. "inherit": True,
  331. "values": "sensitive | insensitive | mixed",
  332. "type": "str",
  333. },
  334. "utf8only": {
  335. "edit": False,
  336. "inherit": True,
  337. "values": "on | off",
  338. "type": "bool",
  339. },
  340. "usedbysnapshots": {
  341. "edit": False,
  342. "inherit": False,
  343. "values": "<size>",
  344. "type": "size",
  345. },
  346. "readonly": {
  347. "edit": True,
  348. "inherit": True,
  349. "values": "on | off",
  350. "type": "bool",
  351. },
  352. "written@": {
  353. "edit": False,
  354. "inherit": False,
  355. "values": "<size>",
  356. "type": "size",
  357. },
  358. "avail": {
  359. "edit": False,
  360. "inherit": False,
  361. "values": "<size>",
  362. "type": "size",
  363. },
  364. "recsize": {
  365. "edit": True,
  366. "inherit": True,
  367. "values": "512 to 1m, power of 2",
  368. "type": "str",
  369. },
  370. "atime": {
  371. "edit": True,
  372. "inherit": True,
  373. "values": "on | off",
  374. "type": "bool",
  375. },
  376. "compression": {
  377. "edit": True,
  378. "inherit": True,
  379. "values": "on | off | lzjb | gzip | gzip-[1-9] | zle | lz4",
  380. "type": "bool",
  381. },
  382. "snapdir": {
  383. "edit": True,
  384. "inherit": True,
  385. "values": "hidden | visible",
  386. "type": "str",
  387. },
  388. "aclmode": {
  389. "edit": True,
  390. "inherit": True,
  391. "values": "discard | groupmask | passthrough | restricted",
  392. "type": "str",
  393. },
  394. "zoned": {
  395. "edit": True,
  396. "inherit": True,
  397. "values": "on | off",
  398. "type": "bool",
  399. },
  400. "copies": {
  401. "edit": True,
  402. "inherit": True,
  403. "values": "1 | 2 | 3",
  404. "type": "numeric",
  405. },
  406. "snapshot_limit": {
  407. "edit": True,
  408. "inherit": False,
  409. "values": "<count> | none",
  410. "type": "numeric",
  411. },
  412. "aclinherit": {
  413. "edit": True,
  414. "inherit": True,
  415. "values": "discard | noallow | restricted | passthrough | passthrough-x",
  416. "type": "str",
  417. },
  418. "compressratio": {
  419. "edit": False,
  420. "inherit": False,
  421. "values": "<1.00x or higher if compressed>",
  422. "type": "str",
  423. },
  424. "xattr": {
  425. "edit": True,
  426. "inherit": True,
  427. "values": "on | off",
  428. "type": "bool",
  429. },
  430. "written": {
  431. "edit": False,
  432. "inherit": False,
  433. "values": "<size>",
  434. "type": "size",
  435. },
  436. "version": {
  437. "edit": True,
  438. "inherit": False,
  439. "values": "1 | 2 | 3 | 4 | 5 | current",
  440. "type": "numeric",
  441. },
  442. "recordsize": {
  443. "edit": True,
  444. "inherit": True,
  445. "values": "512 to 1m, power of 2",
  446. "type": "str",
  447. },
  448. "refquota": {
  449. "edit": True,
  450. "inherit": False,
  451. "values": "<size> | none",
  452. "type": "size",
  453. },
  454. "filesystem_limit": {
  455. "edit": True,
  456. "inherit": False,
  457. "values": "<count> | none",
  458. "type": "numeric",
  459. },
  460. "lrefer.": {
  461. "edit": False,
  462. "inherit": False,
  463. "values": "<size>",
  464. "type": "size",
  465. },
  466. "type": {
  467. "edit": False,
  468. "inherit": False,
  469. "values": "filesystem | volume | snapshot | bookmark",
  470. "type": "str",
  471. },
  472. "secondarycache": {
  473. "edit": True,
  474. "inherit": True,
  475. "values": "all | none | metadata",
  476. "type": "str",
  477. },
  478. "refer": {
  479. "edit": False,
  480. "inherit": False,
  481. "values": "<size>",
  482. "type": "size",
  483. },
  484. "available": {
  485. "edit": False,
  486. "inherit": False,
  487. "values": "<size>",
  488. "type": "size",
  489. },
  490. "used": {
  491. "edit": False,
  492. "inherit": False,
  493. "values": "<size>",
  494. "type": "size",
  495. },
  496. "exec": {
  497. "edit": True,
  498. "inherit": True,
  499. "values": "on | off",
  500. "type": "bool",
  501. },
  502. "compress": {
  503. "edit": True,
  504. "inherit": True,
  505. "values": "on | off | lzjb | gzip | gzip-[1-9] | zle | lz4",
  506. "type": "bool",
  507. },
  508. "volblock": {
  509. "edit": False,
  510. "inherit": True,
  511. "values": "512 to 128k, power of 2",
  512. "type": "str",
  513. },
  514. "refcompressratio": {
  515. "edit": False,
  516. "inherit": False,
  517. "values": "<1.00x or higher if compressed>",
  518. "type": "str",
  519. },
  520. "quota": {
  521. "edit": True,
  522. "inherit": False,
  523. "values": "<size> | none",
  524. "type": "size",
  525. },
  526. "groupquota@": {
  527. "edit": True,
  528. "inherit": False,
  529. "values": "<size> | none",
  530. "type": "size",
  531. },
  532. "userquota@": {
  533. "edit": True,
  534. "inherit": False,
  535. "values": "<size> | none",
  536. "type": "size",
  537. },
  538. "snapshot_count": {
  539. "edit": False,
  540. "inherit": False,
  541. "values": "<count>",
  542. "type": "numeric",
  543. },
  544. "volsize": {
  545. "edit": True,
  546. "inherit": False,
  547. "values": "<size>",
  548. "type": "size",
  549. },
  550. "clones": {
  551. "edit": False,
  552. "inherit": False,
  553. "values": "<dataset>[,...]",
  554. "type": "str",
  555. },
  556. "canmount": {
  557. "edit": True,
  558. "inherit": False,
  559. "values": "on | off | noauto",
  560. "type": "bool",
  561. },
  562. "mounted": {
  563. "edit": False,
  564. "inherit": False,
  565. "values": "yes | no",
  566. "type": "bool_alt",
  567. },
  568. "groupused@": {
  569. "edit": False,
  570. "inherit": False,
  571. "values": "<size>",
  572. "type": "size",
  573. },
  574. "normalization": {
  575. "edit": False,
  576. "inherit": True,
  577. "values": "none | formc | formd | formkc | formkd",
  578. "type": "str",
  579. },
  580. "usedbychildren": {
  581. "edit": False,
  582. "inherit": False,
  583. "values": "<size>",
  584. "type": "size",
  585. },
  586. "usedbydataset": {
  587. "edit": False,
  588. "inherit": False,
  589. "values": "<size>",
  590. "type": "size",
  591. },
  592. "mlslabel": {
  593. "edit": True,
  594. "inherit": True,
  595. "values": "<sensitivity label>",
  596. "type": "str",
  597. },
  598. "refreserv": {
  599. "edit": True,
  600. "inherit": False,
  601. "values": "<size> | none",
  602. "type": "size",
  603. },
  604. "defer_destroy": {
  605. "edit": False,
  606. "inherit": False,
  607. "values": "yes | no",
  608. "type": "bool_alt",
  609. },
  610. "volblocksize": {
  611. "edit": False,
  612. "inherit": True,
  613. "values": "512 to 128k, power of 2",
  614. "type": "str",
  615. },
  616. "lused.": {
  617. "edit": False,
  618. "inherit": False,
  619. "values": "<size>",
  620. "type": "size",
  621. },
  622. "redundant_metadata": {
  623. "edit": True,
  624. "inherit": True,
  625. "values": "all | most",
  626. "type": "str",
  627. },
  628. "filesystem_count": {
  629. "edit": False,
  630. "inherit": False,
  631. "values": "<count>",
  632. "type": "numeric",
  633. },
  634. "devices": {
  635. "edit": True,
  636. "inherit": True,
  637. "values": "on | off",
  638. "type": "bool",
  639. },
  640. "refreservation": {
  641. "edit": True,
  642. "inherit": False,
  643. "values": "<size> | none",
  644. "type": "size",
  645. },
  646. "userused@": {
  647. "edit": False,
  648. "inherit": False,
  649. "values": "<size>",
  650. "type": "size",
  651. },
  652. "logicalreferenced": {
  653. "edit": False,
  654. "inherit": False,
  655. "values": "<size>",
  656. "type": "size",
  657. },
  658. "checksum": {
  659. "edit": True,
  660. "inherit": True,
  661. "values": "on | off | fletcher2 | fletcher4 | sha256 | sha512 | skein | edonr",
  662. "type": "bool",
  663. },
  664. "nbmand": {
  665. "edit": True,
  666. "inherit": True,
  667. "values": "on | off",
  668. "type": "bool",
  669. },
  670. }
  671. def _from_auto(self, name, value, source="auto"):
  672. """
  673. some more complex patching for zfs.from_auto
  674. """
  675. with patch.object(
  676. salt.utils.zfs,
  677. "property_data_zpool",
  678. MagicMock(return_value=self.pmap_zpool),
  679. ), patch.object(
  680. salt.utils.zfs, "property_data_zfs", MagicMock(return_value=self.pmap_zfs)
  681. ):
  682. return salt.utils.zfs.from_auto(name, value, source)
  683. def _from_auto_dict(self, values, source="auto"):
  684. """
  685. some more complex patching for zfs.from_auto_dict
  686. """
  687. with patch.object(
  688. salt.utils.zfs,
  689. "property_data_zpool",
  690. MagicMock(return_value=self.pmap_zpool),
  691. ), patch.object(
  692. salt.utils.zfs, "property_data_zfs", MagicMock(return_value=self.pmap_zfs)
  693. ):
  694. return salt.utils.zfs.from_auto_dict(values, source)
  695. def _to_auto(self, name, value, source="auto", convert_to_human=True):
  696. """
  697. some more complex patching for zfs.to_auto
  698. """
  699. with patch.object(
  700. salt.utils.zfs,
  701. "property_data_zpool",
  702. MagicMock(return_value=self.pmap_zpool),
  703. ), patch.object(
  704. salt.utils.zfs, "property_data_zfs", MagicMock(return_value=self.pmap_zfs)
  705. ):
  706. return salt.utils.zfs.to_auto(name, value, source, convert_to_human)
  707. def _to_auto_dict(self, values, source="auto", convert_to_human=True):
  708. """
  709. some more complex patching for zfs.to_auto_dict
  710. """
  711. with patch.object(
  712. salt.utils.zfs,
  713. "property_data_zpool",
  714. MagicMock(return_value=self.pmap_zpool),
  715. ), patch.object(
  716. salt.utils.zfs, "property_data_zfs", MagicMock(return_value=self.pmap_zfs)
  717. ):
  718. return salt.utils.zfs.to_auto_dict(values, source, convert_to_human)
  719. def get_patched_utils(self):
  720. return {
  721. "zfs.is_supported": MagicMock(return_value=True),
  722. "zfs.has_feature_flags": MagicMock(return_value=True),
  723. "zfs.property_data_zpool": MagicMock(return_value=self.pmap_zpool),
  724. "zfs.property_data_zfs": MagicMock(return_value=self.pmap_zfs),
  725. # NOTE: we make zpool_command and zfs_command a NOOP
  726. # these are extensively tested in tests.unit.utils.test_zfs
  727. "zfs.zpool_command": MagicMock(return_value="/bin/false"),
  728. "zfs.zfs_command": MagicMock(return_value="/bin/false"),
  729. # NOTE: from_auto_dict is a special snowflake
  730. # internally it calls multiple calls from
  731. # salt.utils.zfs but we cannot patch those using
  732. # the common methode, __utils__ is not available
  733. # so they are direct calls, we do some voodoo here.
  734. "zfs.from_auto_dict": self._from_auto_dict,
  735. "zfs.from_auto": self._from_auto,
  736. "zfs.to_auto_dict": self._to_auto_dict,
  737. "zfs.to_auto": self._to_auto,
  738. }