zfs.py 29 KB

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