1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723 |
- # -*- coding: utf-8 -*-
- '''
- Tests for the zfs utils library
- :codeauthor: Jorge Schrauwen <sjorge@blackdot.be>
- :maintainer: Jorge Schrauwen <sjorge@blackdot.be>
- :maturity: new
- :platform: illumos,freebsd,linux
- .. versionadded:: 2018.3.1
- '''
- # Import Python libs
- from __future__ import absolute_import, unicode_literals, print_function
- # Import Salt Testing libs
- from tests.support.unit import skipIf, TestCase
- from tests.support.mock import (
- MagicMock,
- patch,
- NO_MOCK,
- NO_MOCK_REASON,
- )
- # Import Salt Execution module to test
- import salt.utils.zfs as zfs
- # Import Salt Utils
- import salt.loader
- from salt.utils.odict import OrderedDict
- # property_map mocks
- pmap_exec_zpool = {
- 'retcode': 2,
- 'stdout': '',
- 'stderr': "\n".join([
- 'missing property argument',
- 'usage:',
- ' get [-Hp] [-o "all" | field[,...]] <"all" | property[,...]> <pool> ...',
- '',
- 'the following properties are supported:',
- '',
- ' PROPERTY EDIT VALUES',
- '',
- ' allocated NO <size>',
- ' capacity NO <size>',
- ' dedupratio NO <1.00x or higher if deduped>',
- ' expandsize NO <size>',
- ' fragmentation NO <percent>',
- ' free NO <size>',
- ' freeing NO <size>',
- ' guid NO <guid>',
- ' health NO <state>',
- ' leaked NO <size>',
- ' size NO <size>',
- ' altroot YES <path>',
- ' autoexpand YES on | off',
- ' autoreplace YES on | off',
- ' bootfs YES <filesystem>',
- ' bootsize YES <size>',
- ' cachefile YES <file> | none',
- ' comment YES <comment-string>',
- ' dedupditto YES <threshold (min 100)>',
- ' delegation YES on | off',
- ' failmode YES wait | continue | panic',
- ' listsnapshots YES on | off',
- ' readonly YES on | off',
- ' version YES <version>',
- ' feature@... YES disabled | enabled | active',
- '',
- 'The feature@ properties must be appended with a feature name.',
- 'See zpool-features(5). ',
- ]),
- }
- pmap_zpool = {
- 'comment': {
- 'edit': True,
- 'type': 'str',
- 'values': '<comment-string>'
- },
- 'freeing': {
- 'edit': False,
- 'type': 'size',
- 'values': '<size>'
- },
- 'listsnapshots': {
- 'edit': True,
- 'type': 'bool',
- 'values': 'on | off'
- },
- 'leaked': {
- 'edit': False,
- 'type': 'size',
- 'values': '<size>'
- },
- 'version': {
- 'edit': True,
- 'type': 'numeric',
- 'values': '<version>'
- },
- 'write': {
- 'edit': False,
- 'type': 'size',
- 'values': '<size>'
- },
- 'replace': {
- 'edit': True,
- 'type': 'bool',
- 'values': 'on | off'
- },
- 'delegation': {
- 'edit': True,
- 'type': 'bool',
- 'values': 'on | off'
- },
- 'dedupditto': {
- 'edit': True,
- 'type': 'str',
- 'values': '<threshold (min 100)>'
- },
- 'autoexpand': {
- 'edit': True,
- 'type': 'bool',
- 'values': 'on | off'
- },
- 'alloc': {
- 'edit': False,
- 'type': 'size',
- 'values': '<size>'
- },
- 'allocated': {
- 'edit': False,
- 'type': 'size',
- 'values': '<size>'
- },
- 'guid': {
- 'edit': False,
- 'type': 'numeric',
- 'values': '<guid>'
- },
- 'size': {
- 'edit': False,
- 'type': 'size',
- 'values': '<size>'
- },
- 'cap': {
- 'edit': False,
- 'type': 'numeric',
- 'values': '<count>'
- },
- 'capacity': {
- 'edit': False,
- 'type': 'size',
- 'values': '<size>'
- },
- "capacity-alloc": {
- "edit": False,
- "type": "size",
- "values": "<size>"
- },
- "capacity-free": {
- "edit": False,
- "type": "size",
- "values": "<size>"
- },
- 'cachefile': {
- 'edit': True,
- 'type': 'str',
- 'values': '<file> | none'
- },
- "cksum": {
- "edit": False,
- "type": "numeric",
- "values": "<count>"
- },
- 'bootfs': {
- 'edit': True,
- 'type': 'str',
- 'values': '<filesystem>'
- },
- 'autoreplace': {
- 'edit': True,
- 'type': 'bool',
- 'values': 'on | off'
- },
- "bandwith-read": {
- "edit": False,
- "type": "size",
- "values": "<size>"
- },
- "bandwith-write": {
- "edit": False,
- "type": "size",
- "values": "<size>"
- },
- "operations-read": {
- "edit": False,
- "type": "size",
- "values": "<size>"
- },
- "operations-write": {
- "edit": False,
- "type": "size",
- "values": "<size>"
- },
- "read": {
- "edit": False,
- "type": "size",
- "values": "<size>"
- },
- 'readonly': {
- 'edit': True,
- 'type': 'bool',
- 'values': 'on | off'
- },
- 'dedupratio': {
- 'edit': False,
- 'type': 'str',
- 'values': '<1.00x or higher if deduped>'
- },
- 'health': {
- 'edit': False,
- 'type': 'str',
- 'values': '<state>'
- },
- 'feature@': {
- 'edit': True,
- 'type': 'str',
- 'values': 'disabled | enabled | active'
- },
- 'expandsize': {
- 'edit': False,
- 'type': 'size',
- 'values': '<size>'
- },
- 'listsnaps': {
- 'edit': True,
- 'type': 'bool',
- 'values': 'on | off'
- },
- 'bootsize': {
- 'edit': True,
- 'type': 'size',
- 'values': '<size>'
- },
- 'free': {
- 'edit': False,
- 'type': 'size',
- 'values': '<size>'
- },
- 'failmode': {
- 'edit': True,
- 'type': 'str',
- 'values': 'wait | continue | panic'
- },
- 'altroot': {
- 'edit': True,
- 'type': 'str',
- 'values': '<path>'
- },
- 'expand': {
- 'edit': True,
- 'type': 'bool',
- 'values': 'on | off'
- },
- 'frag': {
- 'edit': False,
- 'type': 'str',
- 'values': '<percent>'
- },
- 'fragmentation': {
- 'edit': False,
- 'type': 'str',
- 'values': '<percent>'
- }
- }
- pmap_exec_zfs = {
- 'retcode': 2,
- 'stdout': '',
- 'stderr': "\n".join([
- 'missing property argument',
- 'usage:',
- ' get [-crHp] [-d max] [-o "all" | field[,...]]',
- ' [-t type[,...]] [-s source[,...]]',
- ' <"all" | property[,...]> [filesystem|volume|snapshot|bookmark] ...',
- '',
- 'The following properties are supported:',
- '',
- ' PROPERTY EDIT INHERIT VALUES',
- '',
- ' available NO NO <size>',
- ' clones NO NO <dataset>[,...]',
- ' compressratio NO NO <1.00x or higher if compressed>',
- ' creation NO NO <date>',
- ' defer_destroy NO NO yes | no',
- ' filesystem_count NO NO <count>',
- ' logicalreferenced NO NO <size>',
- ' logicalused NO NO <size>',
- ' mounted NO NO yes | no',
- ' origin NO NO <snapshot>',
- ' receive_resume_token NO NO <string token>',
- ' refcompressratio NO NO <1.00x or higher if compressed>',
- ' referenced NO NO <size>',
- ' snapshot_count NO NO <count>',
- ' type NO NO filesystem | volume | snapshot | bookmark',
- ' used NO NO <size>',
- ' usedbychildren NO NO <size>',
- ' usedbydataset NO NO <size>',
- ' usedbyrefreservation NO NO <size>',
- ' usedbysnapshots NO NO <size>',
- ' userrefs NO NO <count>',
- ' written NO NO <size>',
- ' aclinherit YES YES discard | noallow | restricted | passthrough | passthrough-x',
- ' aclmode YES YES discard | groupmask | passthrough | restricted',
- ' atime YES YES on | off',
- ' canmount YES NO on | off | noauto',
- ' casesensitivity NO YES sensitive | insensitive | mixed',
- ' checksum YES YES on | off | fletcher2 | fletcher4 | sha256 | sha512 | skein | edonr',
- ' compression YES YES on | off | lzjb | gzip | gzip-[1-9] | zle | lz4',
- ' copies YES YES 1 | 2 | 3',
- ' dedup YES YES on | off | verify | sha256[,verify], sha512[,verify], skein[,verify], edonr,verify',
- ' devices YES YES on | off',
- ' exec YES YES on | off',
- ' filesystem_limit YES NO <count> | none',
- ' logbias YES YES latency | throughput',
- ' mlslabel YES YES <sensitivity label>',
- ' mountpoint YES YES <path> | legacy | none',
- ' nbmand YES YES on | off',
- ' normalization NO YES none | formC | formD | formKC | formKD',
- ' primarycache YES YES all | none | metadata',
- ' quota YES NO <size> | none',
- ' readonly YES YES on | off',
- ' recordsize YES YES 512 to 1M, power of 2',
- ' redundant_metadata YES YES all | most',
- ' refquota YES NO <size> | none',
- ' refreservation YES NO <size> | none',
- ' reservation YES NO <size> | none',
- ' secondarycache YES YES all | none | metadata',
- ' setuid YES YES on | off',
- ' sharenfs YES YES on | off | share(1M) options',
- ' sharesmb YES YES on | off | sharemgr(1M) options',
- ' snapdir YES YES hidden | visible',
- ' snapshot_limit YES NO <count> | none',
- ' sync YES YES standard | always | disabled',
- ' utf8only NO YES on | off',
- ' version YES NO 1 | 2 | 3 | 4 | 5 | current',
- ' volblocksize NO YES 512 to 128k, power of 2',
- ' volsize YES NO <size>',
- ' vscan YES YES on | off',
- ' xattr YES YES on | off',
- ' zoned YES YES on | off',
- ' userused@... NO NO <size>',
- ' groupused@... NO NO <size>',
- ' userquota@... YES NO <size> | none',
- ' groupquota@... YES NO <size> | none',
- ' written@<snap> NO NO <size>',
- '',
- 'Sizes are specified in bytes with standard units such as K, M, G, etc.',
- '',
- 'User-defined properties can be specified by using a name containing a colon (:).',
- '',
- 'The {user|group}{used|quota}@ properties must be appended with',
- 'a user or group specifier of one of these forms:',
- ' POSIX name (eg: "matt")',
- ' POSIX id (eg: "126829")',
- ' SMB name@domain (eg: "matt@sun")',
- ' SMB SID (eg: "S-1-234-567-89")',
- ]),
- }
- pmap_zfs = {
- "origin": {
- "edit": False,
- "inherit": False,
- "values": "<snapshot>",
- "type": "str"
- },
- "setuid": {
- "edit": True,
- "inherit": True,
- "values": "on | off",
- "type": "bool"
- },
- "referenced": {
- "edit": False,
- "inherit": False,
- "values": "<size>",
- "type": "size"
- },
- "vscan": {
- "edit": True,
- "inherit": True,
- "values": "on | off",
- "type": "bool"
- },
- "logicalused": {
- "edit": False,
- "inherit": False,
- "values": "<size>",
- "type": "size"
- },
- "userrefs": {
- "edit": False,
- "inherit": False,
- "values": "<count>",
- "type": "numeric"
- },
- "primarycache": {
- "edit": True,
- "inherit": True,
- "values": "all | none | metadata",
- "type": "str"
- },
- "logbias": {
- "edit": True,
- "inherit": True,
- "values": "latency | throughput",
- "type": "str"
- },
- "creation": {
- "edit": False,
- "inherit": False,
- "values": "<date>",
- "type": "str"
- },
- "sync": {
- "edit": True,
- "inherit": True,
- "values": "standard | always | disabled",
- "type": "str"
- },
- "dedup": {
- "edit": True,
- "inherit": True,
- "values": "on | off | verify | sha256[,verify], sha512[,verify], skein[,verify], edonr,verify",
- "type": "bool"
- },
- "sharenfs": {
- "edit": True,
- "inherit": True,
- "values": "on | off | share(1m) options",
- "type": "bool"
- },
- "receive_resume_token": {
- "edit": False,
- "inherit": False,
- "values": "<string token>",
- "type": "str"
- },
- "usedbyrefreservation": {
- "edit": False,
- "inherit": False,
- "values": "<size>",
- "type": "size"
- },
- "sharesmb": {
- "edit": True,
- "inherit": True,
- "values": "on | off | sharemgr(1m) options",
- "type": "bool"
- },
- "rdonly": {
- "edit": True,
- "inherit": True,
- "values": "on | off",
- "type": "bool"
- },
- "reservation": {
- "edit": True,
- "inherit": False,
- "values": "<size> | none",
- "type": "size"
- },
- "reserv": {
- "edit": True,
- "inherit": False,
- "values": "<size> | none",
- "type": "size"
- },
- "mountpoint": {
- "edit": True,
- "inherit": True,
- "values": "<path> | legacy | none",
- "type": "str"
- },
- "casesensitivity": {
- "edit": False,
- "inherit": True,
- "values": "sensitive | insensitive | mixed",
- "type": "str"
- },
- "utf8only": {
- "edit": False,
- "inherit": True,
- "values": "on | off",
- "type": "bool"
- },
- "usedbysnapshots": {
- "edit": False,
- "inherit": False,
- "values": "<size>",
- "type": "size"
- },
- "readonly": {
- "edit": True,
- "inherit": True,
- "values": "on | off",
- "type": "bool"
- },
- "written@": {
- "edit": False,
- "inherit": False,
- "values": "<size>",
- "type": "size"
- },
- "avail": {
- "edit": False,
- "inherit": False,
- "values": "<size>",
- "type": "size"
- },
- "recsize": {
- "edit": True,
- "inherit": True,
- "values": "512 to 1m, power of 2",
- "type": "str"
- },
- "atime": {
- "edit": True,
- "inherit": True,
- "values": "on | off",
- "type": "bool"
- },
- "compression": {
- "edit": True,
- "inherit": True,
- "values": "on | off | lzjb | gzip | gzip-[1-9] | zle | lz4",
- "type": "bool"
- },
- "snapdir": {
- "edit": True,
- "inherit": True,
- "values": "hidden | visible",
- "type": "str"
- },
- "aclmode": {
- "edit": True,
- "inherit": True,
- "values": "discard | groupmask | passthrough | restricted",
- "type": "str"
- },
- "zoned": {
- "edit": True,
- "inherit": True,
- "values": "on | off",
- "type": "bool"
- },
- "copies": {
- "edit": True,
- "inherit": True,
- "values": "1 | 2 | 3",
- "type": "numeric"
- },
- "snapshot_limit": {
- "edit": True,
- "inherit": False,
- "values": "<count> | none",
- "type": "numeric"
- },
- "aclinherit": {
- "edit": True,
- "inherit": True,
- "values": "discard | noallow | restricted | passthrough | passthrough-x",
- "type": "str"
- },
- "compressratio": {
- "edit": False,
- "inherit": False,
- "values": "<1.00x or higher if compressed>",
- "type": "str"
- },
- "xattr": {
- "edit": True,
- "inherit": True,
- "values": "on | off",
- "type": "bool"
- },
- "written": {
- "edit": False,
- "inherit": False,
- "values": "<size>",
- "type": "size"
- },
- "version": {
- "edit": True,
- "inherit": False,
- "values": "1 | 2 | 3 | 4 | 5 | current",
- "type": "numeric"
- },
- "recordsize": {
- "edit": True,
- "inherit": True,
- "values": "512 to 1m, power of 2",
- "type": "str"
- },
- "refquota": {
- "edit": True,
- "inherit": False,
- "values": "<size> | none",
- "type": "size"
- },
- "filesystem_limit": {
- "edit": True,
- "inherit": False,
- "values": "<count> | none",
- "type": "numeric"
- },
- "lrefer.": {
- "edit": False,
- "inherit": False,
- "values": "<size>",
- "type": "size"
- },
- "type": {
- "edit": False,
- "inherit": False,
- "values": "filesystem | volume | snapshot | bookmark",
- "type": "str"
- },
- "secondarycache": {
- "edit": True,
- "inherit": True,
- "values": "all | none | metadata",
- "type": "str"
- },
- "refer": {
- "edit": False,
- "inherit": False,
- "values": "<size>",
- "type": "size"
- },
- "available": {
- "edit": False,
- "inherit": False,
- "values": "<size>",
- "type": "size"
- },
- "used": {
- "edit": False,
- "inherit": False,
- "values": "<size>",
- "type": "size"
- },
- "exec": {
- "edit": True,
- "inherit": True,
- "values": "on | off",
- "type": "bool"
- },
- "compress": {
- "edit": True,
- "inherit": True,
- "values": "on | off | lzjb | gzip | gzip-[1-9] | zle | lz4",
- "type": "bool"
- },
- "volblock": {
- "edit": False,
- "inherit": True,
- "values": "512 to 128k, power of 2",
- "type": "str"
- },
- "refcompressratio": {
- "edit": False,
- "inherit": False,
- "values": "<1.00x or higher if compressed>",
- "type": "str"
- },
- "quota": {
- "edit": True,
- "inherit": False,
- "values": "<size> | none",
- "type": "size"
- },
- "groupquota@": {
- "edit": True,
- "inherit": False,
- "values": "<size> | none",
- "type": "size"
- },
- "userquota@": {
- "edit": True,
- "inherit": False,
- "values": "<size> | none",
- "type": "size"
- },
- "snapshot_count": {
- "edit": False,
- "inherit": False,
- "values": "<count>",
- "type": "numeric"
- },
- "volsize": {
- "edit": True,
- "inherit": False,
- "values": "<size>",
- "type": "size"
- },
- "clones": {
- "edit": False,
- "inherit": False,
- "values": "<dataset>[,...]",
- "type": "str"
- },
- "canmount": {
- "edit": True,
- "inherit": False,
- "values": "on | off | noauto",
- "type": "bool"
- },
- "mounted": {
- "edit": False,
- "inherit": False,
- "values": "yes | no",
- "type": "bool_alt"
- },
- "groupused@": {
- "edit": False,
- "inherit": False,
- "values": "<size>",
- "type": "size"
- },
- "normalization": {
- "edit": False,
- "inherit": True,
- "values": "none | formc | formd | formkc | formkd",
- "type": "str"
- },
- "usedbychildren": {
- "edit": False,
- "inherit": False,
- "values": "<size>",
- "type": "size"
- },
- "usedbydataset": {
- "edit": False,
- "inherit": False,
- "values": "<size>",
- "type": "size"
- },
- "mlslabel": {
- "edit": True,
- "inherit": True,
- "values": "<sensitivity label>",
- "type": "str"
- },
- "refreserv": {
- "edit": True,
- "inherit": False,
- "values": "<size> | none",
- "type": "size"
- },
- "defer_destroy": {
- "edit": False,
- "inherit": False,
- "values": "yes | no",
- "type": "bool_alt"
- },
- "volblocksize": {
- "edit": False,
- "inherit": True,
- "values": "512 to 128k, power of 2",
- "type": "str"
- },
- "lused.": {
- "edit": False,
- "inherit": False,
- "values": "<size>",
- "type": "size"
- },
- "redundant_metadata": {
- "edit": True,
- "inherit": True,
- "values": "all | most",
- "type": "str"
- },
- "filesystem_count": {
- "edit": False,
- "inherit": False,
- "values": "<count>",
- "type": "numeric"
- },
- "devices": {
- "edit": True,
- "inherit": True,
- "values": "on | off",
- "type": "bool"
- },
- "refreservation": {
- "edit": True,
- "inherit": False,
- "values": "<size> | none",
- "type": "size"
- },
- "userused@": {
- "edit": False,
- "inherit": False,
- "values": "<size>",
- "type": "size"
- },
- "logicalreferenced": {
- "edit": False,
- "inherit": False,
- "values": "<size>",
- "type": "size"
- },
- "checksum": {
- "edit": True,
- "inherit": True,
- "values": "on | off | fletcher2 | fletcher4 | sha256 | sha512 | skein | edonr",
- "type": "bool"
- },
- "nbmand": {
- "edit": True,
- "inherit": True,
- "values": "on | off",
- "type": "bool"
- }
- }
- def _from_auto(name, value, source='auto'):
- '''
- some more complex patching for zfs.from_auto
- '''
- with patch.object(salt.utils.zfs, 'property_data_zpool', MagicMock(return_value=pmap_zpool)), \
- patch.object(salt.utils.zfs, 'property_data_zfs', MagicMock(return_value=pmap_zfs)):
- return salt.utils.zfs.from_auto(name, value, source)
- def _from_auto_dict(values, source='auto'):
- '''
- some more complex patching for zfs.from_auto_dict
- '''
- with patch.object(salt.utils.zfs, 'property_data_zpool', MagicMock(return_value=pmap_zpool)), \
- patch.object(salt.utils.zfs, 'property_data_zfs', MagicMock(return_value=pmap_zfs)):
- return salt.utils.zfs.from_auto_dict(values, source)
- def _to_auto(name, value, source='auto', convert_to_human=True):
- '''
- some more complex patching for zfs.to_auto
- '''
- with patch.object(salt.utils.zfs, 'property_data_zpool', MagicMock(return_value=pmap_zpool)), \
- patch.object(salt.utils.zfs, 'property_data_zfs', MagicMock(return_value=pmap_zfs)):
- return salt.utils.zfs.to_auto(name, value, source, convert_to_human)
- def _to_auto_dict(values, source='auto', convert_to_human=True):
- '''
- some more complex patching for zfs.to_auto_dict
- '''
- with patch.object(salt.utils.zfs, 'property_data_zpool', MagicMock(return_value=pmap_zpool)), \
- patch.object(salt.utils.zfs, 'property_data_zfs', MagicMock(return_value=pmap_zfs)):
- return salt.utils.zfs.to_auto_dict(values, source, convert_to_human)
- utils_patch = {
- 'zfs.is_supported': MagicMock(return_value=True),
- 'zfs.has_feature_flags': MagicMock(return_value=True),
- 'zfs.property_data_zpool': MagicMock(return_value=pmap_zpool),
- 'zfs.property_data_zfs': MagicMock(return_value=pmap_zfs),
- # NOTE: we make zpool_command and zfs_command a NOOP
- # these are extensively tested in tests.unit.utils.test_zfs
- 'zfs.zpool_command': MagicMock(return_value='/bin/false'),
- 'zfs.zfs_command': MagicMock(return_value='/bin/false'),
- # NOTE: from_auto_dict is a special snowflake
- # internally it calls multiple calls from
- # salt.utils.zfs but we cannot patch those using
- # the common methode, __utils__ is not available
- # so they are direct calls, we do some voodoo here.
- 'zfs.from_auto_dict': _from_auto_dict,
- 'zfs.from_auto': _from_auto,
- 'zfs.to_auto_dict': _to_auto_dict,
- 'zfs.to_auto': _to_auto,
- }
- # Skip this test case if we don't have access to mock!
- @skipIf(NO_MOCK, NO_MOCK_REASON)
- class ZfsUtilsTestCase(TestCase):
- '''
- This class contains a set of functions that test salt.utils.zfs utils
- '''
- ## NOTE: test parameter parsing
- def test_is_supported(self):
- '''
- Test zfs.is_supported method
- '''
- for value in [False, True]:
- with patch('salt.utils.path.which',
- MagicMock(return_value=value)):
- with patch('salt.utils.platform.is_linux',
- MagicMock(return_value=value)):
- self.assertEqual(value, zfs.is_supported())
- def test_property_data_zpool(self):
- '''
- Test parsing of zpool get output
- '''
- with patch.object(zfs, '_zfs_cmd', MagicMock(return_value='/sbin/zfs')):
- with patch.object(zfs, '_zpool_cmd', MagicMock(return_value='/sbin/zpool')):
- with patch.object(zfs, '_exec', MagicMock(return_value=pmap_exec_zpool)):
- self.assertEqual(zfs.property_data_zpool(), pmap_zpool)
- def test_property_data_zfs(self):
- '''
- Test parsing of zfs get output
- '''
- with patch.object(zfs, '_zfs_cmd', MagicMock(return_value='/sbin/zfs')):
- with patch.object(zfs, '_zpool_cmd', MagicMock(return_value='/sbin/zpool')):
- with patch.object(zfs, '_exec', MagicMock(return_value=pmap_exec_zfs)):
- self.assertEqual(zfs.property_data_zfs(), pmap_zfs)
- ## NOTE: testing from_bool results
- def test_from_bool_on(self):
- '''
- Test from_bool with 'on'
- '''
- self.assertTrue(zfs.from_bool('on'))
- self.assertTrue(zfs.from_bool(zfs.from_bool('on')))
- def test_from_bool_off(self):
- '''
- Test from_bool with 'off'
- '''
- self.assertFalse(zfs.from_bool('off'))
- self.assertFalse(zfs.from_bool(zfs.from_bool('off')))
- def test_from_bool_none(self):
- '''
- Test from_bool with 'none'
- '''
- self.assertEqual(zfs.from_bool('none'), None)
- self.assertEqual(zfs.from_bool(zfs.from_bool('none')), None)
- def test_from_bool_passthrough(self):
- '''
- Test from_bool with 'passthrough'
- '''
- self.assertEqual(zfs.from_bool('passthrough'), 'passthrough')
- self.assertEqual(zfs.from_bool(zfs.from_bool('passthrough')), 'passthrough')
- def test_from_bool_alt_yes(self):
- '''
- Test from_bool_alt with 'yes'
- '''
- self.assertTrue(zfs.from_bool_alt('yes'))
- self.assertTrue(zfs.from_bool_alt(zfs.from_bool_alt('yes')))
- def test_from_bool_alt_no(self):
- '''
- Test from_bool_alt with 'no'
- '''
- self.assertFalse(zfs.from_bool_alt('no'))
- self.assertFalse(zfs.from_bool_alt(zfs.from_bool_alt('no')))
- def test_from_bool_alt_none(self):
- '''
- Test from_bool_alt with 'none'
- '''
- self.assertEqual(zfs.from_bool_alt('none'), None)
- self.assertEqual(zfs.from_bool_alt(zfs.from_bool_alt('none')), None)
- def test_from_bool_alt_passthrough(self):
- '''
- Test from_bool_alt with 'passthrough'
- '''
- self.assertEqual(zfs.from_bool_alt('passthrough'), 'passthrough')
- self.assertEqual(zfs.from_bool_alt(zfs.from_bool_alt('passthrough')), 'passthrough')
- ## NOTE: testing to_bool results
- def test_to_bool_true(self):
- '''
- Test to_bool with True
- '''
- self.assertEqual(zfs.to_bool(True), 'on')
- self.assertEqual(zfs.to_bool(zfs.to_bool(True)), 'on')
- def test_to_bool_false(self):
- '''
- Test to_bool with False
- '''
- self.assertEqual(zfs.to_bool(False), 'off')
- self.assertEqual(zfs.to_bool(zfs.to_bool(False)), 'off')
- def test_to_bool_none(self):
- '''
- Test to_bool with None
- '''
- self.assertEqual(zfs.to_bool(None), 'none')
- self.assertEqual(zfs.to_bool(zfs.to_bool(None)), 'none')
- def test_to_bool_passthrough(self):
- '''
- Test to_bool with 'passthrough'
- '''
- self.assertEqual(zfs.to_bool('passthrough'), 'passthrough')
- self.assertEqual(zfs.to_bool(zfs.to_bool('passthrough')), 'passthrough')
- def test_to_bool_alt_true(self):
- '''
- Test to_bool_alt with True
- '''
- self.assertEqual(zfs.to_bool_alt(True), 'yes')
- self.assertEqual(zfs.to_bool_alt(zfs.to_bool_alt(True)), 'yes')
- def test_to_bool_alt_false(self):
- '''
- Test to_bool_alt with False
- '''
- self.assertEqual(zfs.to_bool_alt(False), 'no')
- self.assertEqual(zfs.to_bool_alt(zfs.to_bool_alt(False)), 'no')
- def test_to_bool_alt_none(self):
- '''
- Test to_bool_alt with None
- '''
- self.assertEqual(zfs.to_bool_alt(None), 'none')
- self.assertEqual(zfs.to_bool_alt(zfs.to_bool_alt(None)), 'none')
- def test_to_bool_alt_passthrough(self):
- '''
- Test to_bool_alt with 'passthrough'
- '''
- self.assertEqual(zfs.to_bool_alt('passthrough'), 'passthrough')
- self.assertEqual(zfs.to_bool_alt(zfs.to_bool_alt('passthrough')), 'passthrough')
- ## NOTE: testing from_numeric results
- def test_from_numeric_str(self):
- '''
- Test from_numeric with '42'
- '''
- self.assertEqual(zfs.from_numeric('42'), 42)
- self.assertEqual(zfs.from_numeric(zfs.from_numeric('42')), 42)
- def test_from_numeric_int(self):
- '''
- Test from_numeric with 42
- '''
- self.assertEqual(zfs.from_numeric(42), 42)
- self.assertEqual(zfs.from_numeric(zfs.from_numeric(42)), 42)
- def test_from_numeric_none(self):
- '''
- Test from_numeric with 'none'
- '''
- self.assertEqual(zfs.from_numeric('none'), None)
- self.assertEqual(zfs.from_numeric(zfs.from_numeric('none')), None)
- def test_from_numeric_passthrough(self):
- '''
- Test from_numeric with 'passthrough'
- '''
- self.assertEqual(zfs.from_numeric('passthrough'), 'passthrough')
- self.assertEqual(zfs.from_numeric(zfs.from_numeric('passthrough')), 'passthrough')
- ## NOTE: testing to_numeric results
- def test_to_numeric_str(self):
- '''
- Test to_numeric with '42'
- '''
- self.assertEqual(zfs.to_numeric('42'), 42)
- self.assertEqual(zfs.to_numeric(zfs.to_numeric('42')), 42)
- def test_to_numeric_int(self):
- '''
- Test to_numeric with 42
- '''
- self.assertEqual(zfs.to_numeric(42), 42)
- self.assertEqual(zfs.to_numeric(zfs.to_numeric(42)), 42)
- def test_to_numeric_none(self):
- '''
- Test to_numeric with 'none'
- '''
- self.assertEqual(zfs.to_numeric(None), 'none')
- self.assertEqual(zfs.to_numeric(zfs.to_numeric(None)), 'none')
- def test_to_numeric_passthrough(self):
- '''
- Test to_numeric with 'passthrough'
- '''
- self.assertEqual(zfs.to_numeric('passthrough'), 'passthrough')
- self.assertEqual(zfs.to_numeric(zfs.to_numeric('passthrough')), 'passthrough')
- ## NOTE: testing from_size results
- def test_from_size_absolute(self):
- '''
- Test from_size with '5G'
- '''
- self.assertEqual(zfs.from_size('5G'), 5368709120)
- self.assertEqual(zfs.from_size(zfs.from_size('5G')), 5368709120)
- def test_from_size_decimal(self):
- '''
- Test from_size with '4.20M'
- '''
- self.assertEqual(zfs.from_size('4.20M'), 4404019)
- self.assertEqual(zfs.from_size(zfs.from_size('4.20M')), 4404019)
- def test_from_size_none(self):
- '''
- Test from_size with 'none'
- '''
- self.assertEqual(zfs.from_size('none'), None)
- self.assertEqual(zfs.from_size(zfs.from_size('none')), None)
- def test_from_size_passthrough(self):
- '''
- Test from_size with 'passthrough'
- '''
- self.assertEqual(zfs.from_size('passthrough'), 'passthrough')
- self.assertEqual(zfs.from_size(zfs.from_size('passthrough')), 'passthrough')
- ## NOTE: testing to_size results
- def test_to_size_str_absolute(self):
- '''
- Test to_size with '5368709120'
- '''
- self.assertEqual(zfs.to_size('5368709120'), '5G')
- self.assertEqual(zfs.to_size(zfs.to_size('5368709120')), '5G')
- def test_to_size_str_decimal(self):
- '''
- Test to_size with '4404019'
- '''
- self.assertEqual(zfs.to_size('4404019'), '4.20M')
- self.assertEqual(zfs.to_size(zfs.to_size('4404019')), '4.20M')
- def test_to_size_int_absolute(self):
- '''
- Test to_size with 5368709120
- '''
- self.assertEqual(zfs.to_size(5368709120), '5G')
- self.assertEqual(zfs.to_size(zfs.to_size(5368709120)), '5G')
- def test_to_size_int_decimal(self):
- '''
- Test to_size with 4404019
- '''
- self.assertEqual(zfs.to_size(4404019), '4.20M')
- self.assertEqual(zfs.to_size(zfs.to_size(4404019)), '4.20M')
- def test_to_size_none(self):
- '''
- Test to_size with 'none'
- '''
- self.assertEqual(zfs.to_size(None), 'none')
- self.assertEqual(zfs.to_size(zfs.to_size(None)), 'none')
- def test_to_size_passthrough(self):
- '''
- Test to_size with 'passthrough'
- '''
- self.assertEqual(zfs.to_size('passthrough'), 'passthrough')
- self.assertEqual(zfs.to_size(zfs.to_size('passthrough')), 'passthrough')
- ## NOTE: testing from_str results
- def test_from_str_space(self):
- '''
- Test from_str with "\"my pool/my dataset\"
- '''
- self.assertEqual(zfs.from_str('"my pool/my dataset"'), 'my pool/my dataset')
- self.assertEqual(zfs.from_str(zfs.from_str('"my pool/my dataset"')), 'my pool/my dataset')
- def test_from_str_squote_space(self):
- '''
- Test from_str with "my pool/jorge's dataset"
- '''
- self.assertEqual(zfs.from_str("my pool/jorge's dataset"), "my pool/jorge's dataset")
- self.assertEqual(zfs.from_str(zfs.from_str("my pool/jorge's dataset")), "my pool/jorge's dataset")
- def test_from_str_dquote_space(self):
- '''
- Test from_str with "my pool/the \"good\" stuff"
- '''
- self.assertEqual(zfs.from_str("my pool/the \"good\" stuff"), 'my pool/the "good" stuff')
- self.assertEqual(zfs.from_str(zfs.from_str("my pool/the \"good\" stuff")), 'my pool/the "good" stuff')
- def test_from_str_none(self):
- '''
- Test from_str with 'none'
- '''
- self.assertEqual(zfs.from_str('none'), None)
- self.assertEqual(zfs.from_str(zfs.from_str('none')), None)
- def test_from_str_passthrough(self):
- '''
- Test from_str with 'passthrough'
- '''
- self.assertEqual(zfs.from_str('passthrough'), 'passthrough')
- self.assertEqual(zfs.from_str(zfs.from_str('passthrough')), 'passthrough')
- ## NOTE: testing to_str results
- def test_to_str_space(self):
- '''
- Test to_str with 'my pool/my dataset'
- '''
- ## NOTE: for fun we use both the '"str"' and "\"str\"" way of getting the literal string: "str"
- self.assertEqual(zfs.to_str('my pool/my dataset'), '"my pool/my dataset"')
- self.assertEqual(zfs.to_str(zfs.to_str('my pool/my dataset')), "\"my pool/my dataset\"")
- def test_to_str_squote_space(self):
- '''
- Test to_str with "my pool/jorge's dataset"
- '''
- self.assertEqual(zfs.to_str("my pool/jorge's dataset"), "\"my pool/jorge's dataset\"")
- self.assertEqual(zfs.to_str(zfs.to_str("my pool/jorge's dataset")), "\"my pool/jorge's dataset\"")
- def test_to_str_none(self):
- '''
- Test to_str with 'none'
- '''
- self.assertEqual(zfs.to_str(None), 'none')
- self.assertEqual(zfs.to_str(zfs.to_str(None)), 'none')
- def test_to_str_passthrough(self):
- '''
- Test to_str with 'passthrough'
- '''
- self.assertEqual(zfs.to_str('passthrough'), 'passthrough')
- self.assertEqual(zfs.to_str(zfs.to_str('passthrough')), 'passthrough')
- ## NOTE: testing is_snapshot
- def test_is_snapshot_snapshot(self):
- '''
- Test is_snapshot with a valid snapshot name
- '''
- self.assertTrue(zfs.is_snapshot('zpool_name/dataset@backup'))
- def test_is_snapshot_bookmark(self):
- '''
- Test is_snapshot with a valid bookmark name
- '''
- self.assertFalse(zfs.is_snapshot('zpool_name/dataset#backup'))
- def test_is_snapshot_filesystem(self):
- '''
- Test is_snapshot with a valid filesystem name
- '''
- self.assertFalse(zfs.is_snapshot('zpool_name/dataset'))
- ## NOTE: testing is_bookmark
- def test_is_bookmark_snapshot(self):
- '''
- Test is_bookmark with a valid snapshot name
- '''
- self.assertFalse(zfs.is_bookmark('zpool_name/dataset@backup'))
- def test_is_bookmark_bookmark(self):
- '''
- Test is_bookmark with a valid bookmark name
- '''
- self.assertTrue(zfs.is_bookmark('zpool_name/dataset#backup'))
- def test_is_bookmark_filesystem(self):
- '''
- Test is_bookmark with a valid filesystem name
- '''
- self.assertFalse(zfs.is_bookmark('zpool_name/dataset'))
- ## NOTE: testing is_dataset
- def test_is_dataset_snapshot(self):
- '''
- Test is_dataset with a valid snapshot name
- '''
- self.assertFalse(zfs.is_dataset('zpool_name/dataset@backup'))
- def test_is_dataset_bookmark(self):
- '''
- Test is_dataset with a valid bookmark name
- '''
- self.assertFalse(zfs.is_dataset('zpool_name/dataset#backup'))
- def test_is_dataset_filesystem(self):
- '''
- Test is_dataset with a valid filesystem/volume name
- '''
- self.assertTrue(zfs.is_dataset('zpool_name/dataset'))
- ## NOTE: testing zfs_command
- def test_zfs_command_simple(self):
- '''
- Test if zfs_command builds the correct string
- '''
- with patch.object(zfs, '_zfs_cmd', MagicMock(return_value='/sbin/zfs')):
- with patch.object(zfs, '_zpool_cmd', MagicMock(return_value='/sbin/zpool')):
- with patch.object(zfs, 'property_data_zfs', MagicMock(return_value=pmap_zfs)):
- with patch.object(zfs, 'property_data_zpool', MagicMock(return_value=pmap_zpool)):
- self.assertEqual(
- zfs.zfs_command('list'),
- "/sbin/zfs list"
- )
- def test_zfs_command_none_target(self):
- '''
- Test if zfs_command builds the correct string with a target of None
- '''
- with patch.object(zfs, '_zfs_cmd', MagicMock(return_value='/sbin/zfs')):
- with patch.object(zfs, '_zpool_cmd', MagicMock(return_value='/sbin/zpool')):
- with patch.object(zfs, 'property_data_zfs', MagicMock(return_value=pmap_zfs)):
- with patch.object(zfs, 'property_data_zpool', MagicMock(return_value=pmap_zpool)):
- self.assertEqual(
- zfs.zfs_command('list', target=[None, 'mypool', None]),
- "/sbin/zfs list mypool"
- )
- def test_zfs_command_flag(self):
- '''
- Test if zfs_command builds the correct string
- '''
- with patch.object(zfs, '_zfs_cmd', MagicMock(return_value='/sbin/zfs')):
- with patch.object(zfs, '_zpool_cmd', MagicMock(return_value='/sbin/zpool')):
- with patch.object(zfs, 'property_data_zfs', MagicMock(return_value=pmap_zfs)):
- with patch.object(zfs, 'property_data_zpool', MagicMock(return_value=pmap_zpool)):
- my_flags = [
- '-r', # recursive
- ]
- self.assertEqual(
- zfs.zfs_command('list', flags=my_flags),
- "/sbin/zfs list -r"
- )
- def test_zfs_command_opt(self):
- '''
- Test if zfs_command builds the correct string
- '''
- with patch.object(zfs, '_zfs_cmd', MagicMock(return_value='/sbin/zfs')):
- with patch.object(zfs, '_zpool_cmd', MagicMock(return_value='/sbin/zpool')):
- with patch.object(zfs, 'property_data_zfs', MagicMock(return_value=pmap_zfs)):
- with patch.object(zfs, 'property_data_zpool', MagicMock(return_value=pmap_zpool)):
- my_opts = {
- '-t': 'snap', # only list snapshots
- }
- self.assertEqual(
- zfs.zfs_command('list', opts=my_opts),
- "/sbin/zfs list -t snap"
- )
- def test_zfs_command_flag_opt(self):
- '''
- Test if zfs_command builds the correct string
- '''
- with patch.object(zfs, '_zfs_cmd', MagicMock(return_value='/sbin/zfs')):
- with patch.object(zfs, '_zpool_cmd', MagicMock(return_value='/sbin/zpool')):
- with patch.object(zfs, 'property_data_zfs', MagicMock(return_value=pmap_zfs)):
- with patch.object(zfs, 'property_data_zpool', MagicMock(return_value=pmap_zpool)):
- my_flags = [
- '-r', # recursive
- ]
- my_opts = {
- '-t': 'snap', # only list snapshots
- }
- self.assertEqual(
- zfs.zfs_command('list', flags=my_flags, opts=my_opts),
- "/sbin/zfs list -r -t snap"
- )
- def test_zfs_command_target(self):
- '''
- Test if zfs_command builds the correct string
- '''
- with patch.object(zfs, '_zfs_cmd', MagicMock(return_value='/sbin/zfs')):
- with patch.object(zfs, '_zpool_cmd', MagicMock(return_value='/sbin/zpool')):
- with patch.object(zfs, 'property_data_zfs', MagicMock(return_value=pmap_zfs)):
- with patch.object(zfs, 'property_data_zpool', MagicMock(return_value=pmap_zpool)):
- my_flags = [
- '-r', # recursive
- ]
- my_opts = {
- '-t': 'snap', # only list snapshots
- }
- self.assertEqual(
- zfs.zfs_command('list', flags=my_flags, opts=my_opts, target='mypool'),
- "/sbin/zfs list -r -t snap mypool"
- )
- def test_zfs_command_target_with_space(self):
- '''
- Test if zfs_command builds the correct string
- '''
- with patch.object(zfs, '_zfs_cmd', MagicMock(return_value='/sbin/zfs')):
- with patch.object(zfs, '_zpool_cmd', MagicMock(return_value='/sbin/zpool')):
- with patch.object(zfs, 'property_data_zfs', MagicMock(return_value=pmap_zfs)):
- with patch.object(zfs, 'property_data_zpool', MagicMock(return_value=pmap_zpool)):
- my_flags = [
- '-r', # recursive
- ]
- my_opts = {
- '-t': 'snap', # only list snapshots
- }
- self.assertEqual(
- zfs.zfs_command('list', flags=my_flags, opts=my_opts, target='my pool'),
- '/sbin/zfs list -r -t snap "my pool"'
- )
- def test_zfs_command_property(self):
- '''
- Test if zfs_command builds the correct string
- '''
- with patch.object(zfs, '_zfs_cmd', MagicMock(return_value='/sbin/zfs')):
- with patch.object(zfs, '_zpool_cmd', MagicMock(return_value='/sbin/zpool')):
- with patch.object(zfs, 'property_data_zfs', MagicMock(return_value=pmap_zfs)):
- with patch.object(zfs, 'property_data_zpool', MagicMock(return_value=pmap_zpool)):
- self.assertEqual(
- zfs.zfs_command('get', property_name='quota', target='mypool'),
- "/sbin/zfs get quota mypool"
- )
- def test_zfs_command_property_value(self):
- '''
- Test if zfs_command builds the correct string
- '''
- with patch.object(zfs, '_zfs_cmd', MagicMock(return_value='/sbin/zfs')):
- with patch.object(zfs, '_zpool_cmd', MagicMock(return_value='/sbin/zpool')):
- with patch.object(zfs, 'property_data_zfs', MagicMock(return_value=pmap_zfs)):
- with patch.object(zfs, 'property_data_zpool', MagicMock(return_value=pmap_zpool)):
- my_flags = [
- '-r', # recursive
- ]
- self.assertEqual(
- zfs.zfs_command('set', flags=my_flags, property_name='quota', property_value='5G', target='mypool'),
- "/sbin/zfs set -r quota=5368709120 mypool"
- )
- def test_zfs_command_multi_property_value(self):
- '''
- Test if zfs_command builds the correct string
- '''
- with patch.object(zfs, '_zfs_cmd', MagicMock(return_value='/sbin/zfs')):
- with patch.object(zfs, '_zpool_cmd', MagicMock(return_value='/sbin/zpool')):
- with patch.object(zfs, 'property_data_zfs', MagicMock(return_value=pmap_zfs)):
- with patch.object(zfs, 'property_data_zpool', MagicMock(return_value=pmap_zpool)):
- property_name = ['quota', 'readonly']
- property_value = ['5G', 'no']
- self.assertEqual(
- zfs.zfs_command('set', property_name=property_name, property_value=property_value, target='mypool'),
- "/sbin/zfs set quota=5368709120 readonly=off mypool"
- )
- def test_zfs_command_fs_props(self):
- '''
- Test if zfs_command builds the correct string
- '''
- with patch.object(zfs, '_zfs_cmd', MagicMock(return_value='/sbin/zfs')):
- with patch.object(zfs, '_zpool_cmd', MagicMock(return_value='/sbin/zpool')):
- with patch.object(zfs, 'property_data_zfs', MagicMock(return_value=pmap_zfs)):
- with patch.object(zfs, 'property_data_zpool', MagicMock(return_value=pmap_zpool)):
- my_flags = [
- '-p', # create parent
- ]
- my_props = {
- 'quota': '1G',
- 'compression': 'lz4',
- }
- self.assertEqual(
- zfs.zfs_command('create', flags=my_flags, filesystem_properties=my_props, target='mypool/dataset'),
- "/sbin/zfs create -p -o compression=lz4 -o quota=1073741824 mypool/dataset"
- )
- def test_zfs_command_fs_props_with_space(self):
- '''
- Test if zfs_command builds the correct string
- '''
- with patch.object(zfs, '_zfs_cmd', MagicMock(return_value='/sbin/zfs')):
- with patch.object(zfs, '_zpool_cmd', MagicMock(return_value='/sbin/zpool')):
- with patch.object(zfs, 'property_data_zfs', MagicMock(return_value=pmap_zfs)):
- with patch.object(zfs, 'property_data_zpool', MagicMock(return_value=pmap_zpool)):
- my_props = {
- 'quota': '4.2M',
- 'compression': 'lz4',
- }
- self.assertEqual(
- zfs.zfs_command('create', filesystem_properties=my_props, target="my pool/jorge's dataset"),
- '/sbin/zfs create -o compression=lz4 -o quota=4404019 "my pool/jorge\'s dataset"'
- )
- ## NOTE: testing zpool_command
- def test_zpool_command_simple(self):
- '''
- Test if zfs_command builds the correct string
- '''
- with patch.object(zfs, '_zfs_cmd', MagicMock(return_value='/sbin/zfs')):
- with patch.object(zfs, '_zpool_cmd', MagicMock(return_value='/sbin/zpool')):
- with patch.object(zfs, 'property_data_zfs', MagicMock(return_value=pmap_zfs)):
- with patch.object(zfs, 'property_data_zpool', MagicMock(return_value=pmap_zpool)):
- self.assertEqual(
- zfs.zpool_command('list'),
- "/sbin/zpool list"
- )
- def test_zpool_command_opt(self):
- '''
- Test if zpool_command builds the correct string
- '''
- with patch.object(zfs, '_zfs_cmd', MagicMock(return_value='/sbin/zfs')):
- with patch.object(zfs, '_zpool_cmd', MagicMock(return_value='/sbin/zpool')):
- with patch.object(zfs, 'property_data_zfs', MagicMock(return_value=pmap_zfs)):
- with patch.object(zfs, 'property_data_zpool', MagicMock(return_value=pmap_zpool)):
- my_opts = {
- '-o': 'name,size', # show only name and size
- }
- self.assertEqual(
- zfs.zpool_command('list', opts=my_opts),
- "/sbin/zpool list -o name,size"
- )
- def test_zpool_command_opt_list(self):
- '''
- Test if zpool_command builds the correct string
- '''
- with patch.object(zfs, '_zfs_cmd', MagicMock(return_value='/sbin/zfs')):
- with patch.object(zfs, '_zpool_cmd', MagicMock(return_value='/sbin/zpool')):
- with patch.object(zfs, 'property_data_zfs', MagicMock(return_value=pmap_zfs)):
- with patch.object(zfs, 'property_data_zpool', MagicMock(return_value=pmap_zpool)):
- my_opts = {
- '-d': ['/tmp', '/zvol'],
- }
- self.assertEqual(
- zfs.zpool_command('import', opts=my_opts, target='mypool'),
- "/sbin/zpool import -d /tmp -d /zvol mypool"
- )
- def test_zpool_command_flag_opt(self):
- '''
- Test if zpool_command builds the correct string
- '''
- with patch.object(zfs, '_zfs_cmd', MagicMock(return_value='/sbin/zfs')):
- with patch.object(zfs, '_zpool_cmd', MagicMock(return_value='/sbin/zpool')):
- with patch.object(zfs, 'property_data_zfs', MagicMock(return_value=pmap_zfs)):
- with patch.object(zfs, 'property_data_zpool', MagicMock(return_value=pmap_zpool)):
- my_opts = {
- '-o': 'name,size', # show only name and size
- }
- self.assertEqual(
- zfs.zpool_command('list', opts=my_opts),
- "/sbin/zpool list -o name,size"
- )
- def test_zpool_command_target(self):
- '''
- Test if zpool_command builds the correct string
- '''
- with patch.object(zfs, '_zfs_cmd', MagicMock(return_value='/sbin/zfs')):
- with patch.object(zfs, '_zpool_cmd', MagicMock(return_value='/sbin/zpool')):
- with patch.object(zfs, 'property_data_zfs', MagicMock(return_value=pmap_zfs)):
- with patch.object(zfs, 'property_data_zpool', MagicMock(return_value=pmap_zpool)):
- my_opts = {
- '-o': 'name,size', # show only name and size
- }
- self.assertEqual(
- zfs.zpool_command('list', opts=my_opts, target='mypool'),
- "/sbin/zpool list -o name,size mypool"
- )
- def test_zpool_command_target_with_space(self):
- '''
- Test if zpool_command builds the correct string
- '''
- with patch.object(zfs, '_zfs_cmd', MagicMock(return_value='/sbin/zfs')):
- with patch.object(zfs, '_zpool_cmd', MagicMock(return_value='/sbin/zpool')):
- with patch.object(zfs, 'property_data_zfs', MagicMock(return_value=pmap_zfs)):
- with patch.object(zfs, 'property_data_zpool', MagicMock(return_value=pmap_zpool)):
- fs_props = {
- 'quota': '100G',
- }
- pool_props = {
- 'comment': "jorge's comment has a space",
- }
- self.assertEqual(
- zfs.zpool_command('create', pool_properties=pool_props, filesystem_properties=fs_props, target='my pool'),
- "/sbin/zpool create -O quota=107374182400 -o comment=\"jorge's comment has a space\" \"my pool\""
- )
- def test_zpool_command_property(self):
- '''
- Test if zpool_command builds the correct string
- '''
- with patch.object(zfs, '_zfs_cmd', MagicMock(return_value='/sbin/zfs')):
- with patch.object(zfs, '_zpool_cmd', MagicMock(return_value='/sbin/zpool')):
- with patch.object(zfs, 'property_data_zfs', MagicMock(return_value=pmap_zfs)):
- with patch.object(zfs, 'property_data_zpool', MagicMock(return_value=pmap_zpool)):
- self.assertEqual(
- zfs.zpool_command('get', property_name='comment', target='mypool'),
- "/sbin/zpool get comment mypool"
- )
- def test_zpool_command_property_value(self):
- '''
- Test if zpool_command builds the correct string
- '''
- with patch.object(zfs, '_zfs_cmd', MagicMock(return_value='/sbin/zfs')):
- with patch.object(zfs, '_zpool_cmd', MagicMock(return_value='/sbin/zpool')):
- with patch.object(zfs, 'property_data_zfs', MagicMock(return_value=pmap_zfs)):
- with patch.object(zfs, 'property_data_zpool', MagicMock(return_value=pmap_zpool)):
- my_flags = [
- '-v', # verbose
- ]
- self.assertEqual(
- zfs.zpool_command('iostat', flags=my_flags, target=['mypool', 60, 1]),
- "/sbin/zpool iostat -v mypool 60 1"
- )
- def test_parse_command_result_success(self):
- '''
- Test if parse_command_result returns the expected result
- '''
- with patch.object(zfs, '_zfs_cmd', MagicMock(return_value='/sbin/zfs')):
- with patch.object(zfs, '_zpool_cmd', MagicMock(return_value='/sbin/zpool')):
- with patch.object(zfs, 'property_data_zfs', MagicMock(return_value=pmap_zfs)):
- with patch.object(zfs, 'property_data_zpool', MagicMock(return_value=pmap_zpool)):
- res = {}
- res['retcode'] = 0
- res['stderr'] = ''
- res['stdout'] = ''
- self.assertEqual(
- zfs.parse_command_result(res, 'tested'),
- OrderedDict([('tested', True)]),
- )
- def test_parse_command_result_success_nolabel(self):
- '''
- Test if parse_command_result returns the expected result
- '''
- with patch.object(zfs, '_zfs_cmd', MagicMock(return_value='/sbin/zfs')):
- with patch.object(zfs, '_zpool_cmd', MagicMock(return_value='/sbin/zpool')):
- with patch.object(zfs, 'property_data_zfs', MagicMock(return_value=pmap_zfs)):
- with patch.object(zfs, 'property_data_zpool', MagicMock(return_value=pmap_zpool)):
- res = {}
- res['retcode'] = 0
- res['stderr'] = ''
- res['stdout'] = ''
- self.assertEqual(
- zfs.parse_command_result(res),
- OrderedDict(),
- )
- def test_parse_command_result_fail(self):
- '''
- Test if parse_command_result returns the expected result on failure
- '''
- with patch.object(zfs, '_zfs_cmd', MagicMock(return_value='/sbin/zfs')):
- with patch.object(zfs, '_zpool_cmd', MagicMock(return_value='/sbin/zpool')):
- with patch.object(zfs, 'property_data_zfs', MagicMock(return_value=pmap_zfs)):
- with patch.object(zfs, 'property_data_zpool', MagicMock(return_value=pmap_zpool)):
- res = {}
- res['retcode'] = 1
- res['stderr'] = ''
- res['stdout'] = ''
- self.assertEqual(
- zfs.parse_command_result(res, 'tested'),
- OrderedDict([('tested', False)]),
- )
- def test_parse_command_result_nolabel(self):
- '''
- Test if parse_command_result returns the expected result on failure
- '''
- with patch.object(zfs, '_zfs_cmd', MagicMock(return_value='/sbin/zfs')):
- with patch.object(zfs, '_zpool_cmd', MagicMock(return_value='/sbin/zpool')):
- with patch.object(zfs, 'property_data_zfs', MagicMock(return_value=pmap_zfs)):
- with patch.object(zfs, 'property_data_zpool', MagicMock(return_value=pmap_zpool)):
- res = {}
- res['retcode'] = 1
- res['stderr'] = ''
- res['stdout'] = ''
- self.assertEqual(
- zfs.parse_command_result(res),
- OrderedDict(),
- )
- def test_parse_command_result_fail_message(self):
- '''
- Test if parse_command_result returns the expected result on failure with stderr
- '''
- with patch.object(zfs, '_zfs_cmd', MagicMock(return_value='/sbin/zfs')):
- with patch.object(zfs, '_zpool_cmd', MagicMock(return_value='/sbin/zpool')):
- with patch.object(zfs, 'property_data_zfs', MagicMock(return_value=pmap_zfs)):
- with patch.object(zfs, 'property_data_zpool', MagicMock(return_value=pmap_zpool)):
- res = {}
- res['retcode'] = 1
- res['stderr'] = "\n".join([
- 'ice is not hot',
- 'usage:',
- 'this should not be printed',
- ])
- res['stdout'] = ''
- self.assertEqual(
- zfs.parse_command_result(res, 'tested'),
- OrderedDict([('tested', False), ('error', 'ice is not hot')]),
- )
- def test_parse_command_result_fail_message_nolabel(self):
- '''
- Test if parse_command_result returns the expected result on failure with stderr
- '''
- with patch.object(zfs, '_zfs_cmd', MagicMock(return_value='/sbin/zfs')):
- with patch.object(zfs, '_zpool_cmd', MagicMock(return_value='/sbin/zpool')):
- with patch.object(zfs, 'property_data_zfs', MagicMock(return_value=pmap_zfs)):
- with patch.object(zfs, 'property_data_zpool', MagicMock(return_value=pmap_zpool)):
- res = {}
- res['retcode'] = 1
- res['stderr'] = "\n".join([
- 'ice is not hot',
- 'usage:',
- 'this should not be printed',
- ])
- res['stdout'] = ''
- self.assertEqual(
- zfs.parse_command_result(res),
- OrderedDict([('error', 'ice is not hot')]),
- )
- # vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4
|