Shared filesystem management project for OpenStack.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

test_client_cmode.py 209KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761
  1. # Copyright (c) 2014 Alex Meade. All rights reserved.
  2. # Copyright (c) 2015 Clinton Knight. All rights reserved.
  3. # Copyright (c) 2015 Tom Barron. All rights reserved.
  4. #
  5. # Licensed under the Apache License, Version 2.0 (the "License"); you may
  6. # not use this file except in compliance with the License. You may obtain
  7. # a copy of the License at
  8. #
  9. # http://www.apache.org/licenses/LICENSE-2.0
  10. #
  11. # Unless required by applicable law or agreed to in writing, software
  12. # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  13. # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  14. # License for the specific language governing permissions and limitations
  15. # under the License.
  16. import copy
  17. import hashlib
  18. import time
  19. import ddt
  20. import mock
  21. from oslo_log import log
  22. import six
  23. from manila import exception
  24. from manila.share.drivers.netapp.dataontap.client import api as netapp_api
  25. from manila.share.drivers.netapp.dataontap.client import client_base
  26. from manila.share.drivers.netapp.dataontap.client import client_cmode
  27. from manila import test
  28. from manila.tests.share.drivers.netapp.dataontap.client import fakes as fake
  29. @ddt.ddt
  30. class NetAppClientCmodeTestCase(test.TestCase):
  31. def setUp(self):
  32. super(NetAppClientCmodeTestCase, self).setUp()
  33. # Mock loggers as themselves to allow logger arg validation
  34. mock_logger = log.getLogger('mock_logger')
  35. self.mock_object(client_cmode.LOG,
  36. 'error',
  37. mock.Mock(side_effect=mock_logger.error))
  38. self.mock_object(client_cmode.LOG,
  39. 'warning',
  40. mock.Mock(side_effect=mock_logger.warning))
  41. self.mock_object(client_cmode.LOG,
  42. 'debug',
  43. mock.Mock(side_effect=mock_logger.debug))
  44. self.mock_object(client_base.NetAppBaseClient,
  45. 'get_ontapi_version',
  46. mock.Mock(return_value=(1, 20)))
  47. self.client = client_cmode.NetAppCmodeClient(**fake.CONNECTION_INFO)
  48. self.client.connection = mock.MagicMock()
  49. self.vserver_client = client_cmode.NetAppCmodeClient(
  50. **fake.CONNECTION_INFO)
  51. self.vserver_client.set_vserver(fake.VSERVER_NAME)
  52. self.vserver_client.connection = mock.MagicMock()
  53. def _mock_api_error(self, code='fake', message='fake'):
  54. return mock.Mock(side_effect=netapp_api.NaApiError(code=code,
  55. message=message))
  56. def test_init_features_ontapi_1_21(self):
  57. self.mock_object(client_base.NetAppBaseClient,
  58. 'get_ontapi_version',
  59. mock.Mock(return_value=(1, 21)))
  60. self.client._init_features()
  61. self.assertFalse(self.client.features.BROADCAST_DOMAINS)
  62. self.assertFalse(self.client.features.IPSPACES)
  63. self.assertFalse(self.client.features.SUBNETS)
  64. @ddt.data((1, 30), (1, 40), (2, 0))
  65. def test_init_features_ontapi_1_30(self, ontapi_version):
  66. self.mock_object(client_base.NetAppBaseClient,
  67. 'get_ontapi_version',
  68. mock.Mock(return_value=ontapi_version))
  69. self.client._init_features()
  70. self.assertTrue(self.client.features.BROADCAST_DOMAINS)
  71. self.assertTrue(self.client.features.IPSPACES)
  72. self.assertTrue(self.client.features.SUBNETS)
  73. def test_invoke_vserver_api(self):
  74. self.client._invoke_vserver_api('fake-api', 'fake_vserver')
  75. self.client.connection.set_vserver.assert_has_calls(
  76. [mock.call('fake_vserver')])
  77. self.client.connection.invoke_successfully.assert_has_calls(
  78. [mock.call('fake-api', True)])
  79. def test_has_records(self):
  80. self.assertTrue(self.client._has_records(
  81. netapp_api.NaElement(fake.VSERVER_GET_ITER_RESPONSE)))
  82. def test_has_records_not_found(self):
  83. self.assertFalse(self.client._has_records(
  84. netapp_api.NaElement(fake.NO_RECORDS_RESPONSE)))
  85. @ddt.data((fake.VSERVER_GET_ITER_RESPONSE, 1),
  86. (fake.NO_RECORDS_RESPONSE, 0))
  87. @ddt.unpack
  88. def test_get_record_count(self, response, expected):
  89. api_response = netapp_api.NaElement(response)
  90. result = self.client._get_record_count(api_response)
  91. self.assertEqual(expected, result)
  92. def test_get_records_count_invalid(self):
  93. api_response = netapp_api.NaElement(
  94. fake.INVALID_GET_ITER_RESPONSE_NO_RECORDS)
  95. self.assertRaises(exception.NetAppException,
  96. self.client._get_record_count,
  97. api_response)
  98. def test_send_iter_request(self):
  99. api_responses = [
  100. netapp_api.NaElement(fake.STORAGE_DISK_GET_ITER_RESPONSE_PAGE_1),
  101. netapp_api.NaElement(fake.STORAGE_DISK_GET_ITER_RESPONSE_PAGE_2),
  102. netapp_api.NaElement(fake.STORAGE_DISK_GET_ITER_RESPONSE_PAGE_3),
  103. ]
  104. mock_send_request = self.mock_object(
  105. self.client, 'send_request',
  106. mock.Mock(side_effect=api_responses))
  107. storage_disk_get_iter_args = {
  108. 'desired-attributes': {
  109. 'storage-disk-info': {
  110. 'disk-name': None,
  111. }
  112. }
  113. }
  114. result = self.client.send_iter_request(
  115. 'storage-disk-get-iter', api_args=storage_disk_get_iter_args,
  116. max_page_length=10)
  117. num_records = result.get_child_content('num-records')
  118. self.assertEqual('28', num_records)
  119. next_tag = result.get_child_content('next-tag')
  120. self.assertEqual('', next_tag)
  121. args1 = copy.deepcopy(storage_disk_get_iter_args)
  122. args1['max-records'] = 10
  123. args2 = copy.deepcopy(storage_disk_get_iter_args)
  124. args2['max-records'] = 10
  125. args2['tag'] = 'next_tag_1'
  126. args3 = copy.deepcopy(storage_disk_get_iter_args)
  127. args3['max-records'] = 10
  128. args3['tag'] = 'next_tag_2'
  129. mock_send_request.assert_has_calls([
  130. mock.call('storage-disk-get-iter', args1),
  131. mock.call('storage-disk-get-iter', args2),
  132. mock.call('storage-disk-get-iter', args3),
  133. ])
  134. def test_send_iter_request_single_page(self):
  135. api_response = netapp_api.NaElement(
  136. fake.STORAGE_DISK_GET_ITER_RESPONSE)
  137. mock_send_request = self.mock_object(
  138. self.client, 'send_request',
  139. mock.Mock(return_value=api_response))
  140. storage_disk_get_iter_args = {
  141. 'desired-attributes': {
  142. 'storage-disk-info': {
  143. 'disk-name': None,
  144. }
  145. }
  146. }
  147. result = self.client.send_iter_request(
  148. 'storage-disk-get-iter', api_args=storage_disk_get_iter_args,
  149. max_page_length=10)
  150. num_records = result.get_child_content('num-records')
  151. self.assertEqual('4', num_records)
  152. args = copy.deepcopy(storage_disk_get_iter_args)
  153. args['max-records'] = 10
  154. mock_send_request.assert_has_calls([
  155. mock.call('storage-disk-get-iter', args),
  156. ])
  157. def test_send_iter_request_not_found(self):
  158. api_response = netapp_api.NaElement(fake.NO_RECORDS_RESPONSE)
  159. mock_send_request = self.mock_object(
  160. self.client, 'send_request',
  161. mock.Mock(return_value=api_response))
  162. result = self.client.send_iter_request('storage-disk-get-iter')
  163. num_records = result.get_child_content('num-records')
  164. self.assertEqual('0', num_records)
  165. args = {'max-records': client_cmode.DEFAULT_MAX_PAGE_LENGTH}
  166. mock_send_request.assert_has_calls([
  167. mock.call('storage-disk-get-iter', args),
  168. ])
  169. @ddt.data(fake.INVALID_GET_ITER_RESPONSE_NO_ATTRIBUTES,
  170. fake.INVALID_GET_ITER_RESPONSE_NO_RECORDS)
  171. def test_send_iter_request_invalid(self, fake_response):
  172. api_response = netapp_api.NaElement(fake_response)
  173. self.mock_object(self.client,
  174. 'send_request',
  175. mock.Mock(return_value=api_response))
  176. self.assertRaises(exception.NetAppException,
  177. self.client.send_iter_request,
  178. 'storage-disk-get-iter')
  179. def test_set_vserver(self):
  180. self.client.set_vserver(fake.VSERVER_NAME)
  181. self.client.connection.set_vserver.assert_has_calls(
  182. [mock.call('fake_vserver')])
  183. def test_vserver_exists(self):
  184. api_response = netapp_api.NaElement(fake.VSERVER_GET_ITER_RESPONSE)
  185. self.mock_object(self.client,
  186. 'send_iter_request',
  187. mock.Mock(return_value=api_response))
  188. vserver_get_args = {
  189. 'query': {'vserver-info': {'vserver-name': fake.VSERVER_NAME}},
  190. 'desired-attributes': {'vserver-info': {'vserver-name': None}}
  191. }
  192. result = self.client.vserver_exists(fake.VSERVER_NAME)
  193. self.client.send_iter_request.assert_has_calls([
  194. mock.call('vserver-get-iter', vserver_get_args)])
  195. self.assertTrue(result)
  196. def test_vserver_exists_not_found(self):
  197. api_response = netapp_api.NaElement(fake.NO_RECORDS_RESPONSE)
  198. self.mock_object(self.client,
  199. 'send_request',
  200. mock.Mock(return_value=api_response))
  201. result = self.client.vserver_exists(fake.VSERVER_NAME)
  202. self.assertFalse(result)
  203. def test_create_vserver_no_ipspace(self):
  204. self.mock_object(self.client, 'send_request')
  205. vserver_create_args = {
  206. 'vserver-name': fake.VSERVER_NAME,
  207. 'root-volume-security-style': 'unix',
  208. 'root-volume-aggregate': fake.ROOT_VOLUME_AGGREGATE_NAME,
  209. 'root-volume': fake.ROOT_VOLUME_NAME,
  210. 'name-server-switch': {'nsswitch': 'file'}
  211. }
  212. vserver_modify_args = {
  213. 'aggr-list': [{'aggr-name': aggr_name} for aggr_name
  214. in fake.SHARE_AGGREGATE_NAMES],
  215. 'vserver-name': fake.VSERVER_NAME
  216. }
  217. self.client.create_vserver(fake.VSERVER_NAME,
  218. fake.ROOT_VOLUME_AGGREGATE_NAME,
  219. fake.ROOT_VOLUME_NAME,
  220. fake.SHARE_AGGREGATE_NAMES,
  221. None)
  222. self.client.send_request.assert_has_calls([
  223. mock.call('vserver-create', vserver_create_args),
  224. mock.call('vserver-modify', vserver_modify_args)])
  225. def test_create_vserver_with_ipspace(self):
  226. self.client.features.add_feature('IPSPACES')
  227. self.mock_object(self.client, 'send_request')
  228. vserver_create_args = {
  229. 'vserver-name': fake.VSERVER_NAME,
  230. 'root-volume-security-style': 'unix',
  231. 'root-volume-aggregate': fake.ROOT_VOLUME_AGGREGATE_NAME,
  232. 'root-volume': fake.ROOT_VOLUME_NAME,
  233. 'name-server-switch': {'nsswitch': 'file'},
  234. 'ipspace': fake.IPSPACE_NAME,
  235. }
  236. vserver_modify_args = {
  237. 'aggr-list': [{'aggr-name': aggr_name} for aggr_name
  238. in fake.SHARE_AGGREGATE_NAMES],
  239. 'vserver-name': fake.VSERVER_NAME
  240. }
  241. self.client.create_vserver(fake.VSERVER_NAME,
  242. fake.ROOT_VOLUME_AGGREGATE_NAME,
  243. fake.ROOT_VOLUME_NAME,
  244. fake.SHARE_AGGREGATE_NAMES,
  245. fake.IPSPACE_NAME)
  246. self.client.send_request.assert_has_calls([
  247. mock.call('vserver-create', vserver_create_args),
  248. mock.call('vserver-modify', vserver_modify_args)])
  249. def test_create_vserver_ipspaces_not_supported(self):
  250. self.assertRaises(exception.NetAppException,
  251. self.client.create_vserver,
  252. fake.VSERVER_NAME,
  253. fake.ROOT_VOLUME_AGGREGATE_NAME,
  254. fake.ROOT_VOLUME_NAME,
  255. fake.SHARE_AGGREGATE_NAMES,
  256. fake.IPSPACE_NAME)
  257. def test_get_vserver_root_volume_name(self):
  258. api_response = netapp_api.NaElement(
  259. fake.VSERVER_GET_ROOT_VOLUME_NAME_RESPONSE)
  260. self.mock_object(self.client,
  261. 'send_iter_request',
  262. mock.Mock(return_value=api_response))
  263. vserver_get_args = {
  264. 'query': {'vserver-info': {'vserver-name': fake.VSERVER_NAME}},
  265. 'desired-attributes': {'vserver-info': {'root-volume': None}}
  266. }
  267. result = self.client.get_vserver_root_volume_name(fake.VSERVER_NAME)
  268. self.client.send_iter_request.assert_has_calls([
  269. mock.call('vserver-get-iter', vserver_get_args)])
  270. self.assertEqual(fake.ROOT_VOLUME_NAME, result)
  271. def test_get_vserver_root_volume_name_not_found(self):
  272. api_response = netapp_api.NaElement(fake.NO_RECORDS_RESPONSE)
  273. self.mock_object(self.client,
  274. 'send_iter_request',
  275. mock.Mock(return_value=api_response))
  276. self.assertRaises(exception.NetAppException,
  277. self.client.get_vserver_root_volume_name,
  278. fake.VSERVER_NAME)
  279. def test_get_vserver_ipspace(self):
  280. self.client.features.add_feature('IPSPACES')
  281. api_response = netapp_api.NaElement(
  282. fake.VSERVER_GET_IPSPACE_NAME_RESPONSE)
  283. self.mock_object(self.client,
  284. 'send_iter_request',
  285. mock.Mock(return_value=api_response))
  286. result = self.client.get_vserver_ipspace(fake.VSERVER_NAME)
  287. vserver_get_iter_args = {
  288. 'query': {
  289. 'vserver-info': {
  290. 'vserver-name': fake.VSERVER_NAME,
  291. },
  292. },
  293. 'desired-attributes': {
  294. 'vserver-info': {
  295. 'ipspace': None,
  296. },
  297. },
  298. }
  299. self.client.send_iter_request.assert_has_calls([
  300. mock.call('vserver-get-iter', vserver_get_iter_args)])
  301. self.assertEqual(fake.IPSPACE_NAME, result)
  302. def test_get_vserver_ipspace_not_supported(self):
  303. result = self.client.get_vserver_ipspace(fake.IPSPACE_NAME)
  304. self.assertIsNone(result)
  305. def test_get_vserver_ipspace_not_found(self):
  306. self.client.features.add_feature('IPSPACES')
  307. api_response = netapp_api.NaElement(fake.NO_RECORDS_RESPONSE)
  308. self.mock_object(self.client,
  309. 'send_iter_request',
  310. mock.Mock(return_value=api_response))
  311. self.assertRaises(exception.NetAppException,
  312. self.client.get_vserver_ipspace,
  313. fake.IPSPACE_NAME)
  314. def test_ipspace_has_data_vservers(self):
  315. self.client.features.add_feature('IPSPACES')
  316. api_response = netapp_api.NaElement(fake.VSERVER_GET_ITER_RESPONSE)
  317. self.mock_object(self.client,
  318. 'send_iter_request',
  319. mock.Mock(return_value=api_response))
  320. result = self.client.ipspace_has_data_vservers(fake.IPSPACE_NAME)
  321. vserver_get_iter_args = {
  322. 'query': {
  323. 'vserver-info': {
  324. 'ipspace': fake.IPSPACE_NAME,
  325. 'vserver-type': 'data'
  326. },
  327. },
  328. 'desired-attributes': {
  329. 'vserver-info': {
  330. 'vserver-name': None,
  331. },
  332. },
  333. }
  334. self.client.send_iter_request.assert_has_calls([
  335. mock.call('vserver-get-iter', vserver_get_iter_args)])
  336. self.assertTrue(result)
  337. def test_ipspace_has_data_vservers_not_supported(self):
  338. result = self.client.ipspace_has_data_vservers(fake.IPSPACE_NAME)
  339. self.assertFalse(result)
  340. def test_ipspace_has_data_vservers_not_found(self):
  341. self.client.features.add_feature('IPSPACES')
  342. api_response = netapp_api.NaElement(fake.NO_RECORDS_RESPONSE)
  343. self.mock_object(self.client,
  344. 'send_request',
  345. mock.Mock(return_value=api_response))
  346. result = self.client.ipspace_has_data_vservers(fake.IPSPACE_NAME)
  347. self.assertFalse(result)
  348. def test_list_vservers(self):
  349. api_response = netapp_api.NaElement(
  350. fake.VSERVER_DATA_LIST_RESPONSE)
  351. self.mock_object(self.client,
  352. 'send_iter_request',
  353. mock.Mock(return_value=api_response))
  354. result = self.client.list_vservers()
  355. vserver_get_iter_args = {
  356. 'query': {
  357. 'vserver-info': {
  358. 'vserver-type': 'data'
  359. }
  360. },
  361. 'desired-attributes': {
  362. 'vserver-info': {
  363. 'vserver-name': None
  364. }
  365. }
  366. }
  367. self.client.send_iter_request.assert_has_calls([
  368. mock.call('vserver-get-iter', vserver_get_iter_args)])
  369. self.assertListEqual([fake.VSERVER_NAME], result)
  370. def test_list_vservers_node_type(self):
  371. api_response = netapp_api.NaElement(
  372. fake.VSERVER_DATA_LIST_RESPONSE)
  373. self.mock_object(self.client,
  374. 'send_iter_request',
  375. mock.Mock(return_value=api_response))
  376. result = self.client.list_vservers(vserver_type='node')
  377. vserver_get_iter_args = {
  378. 'query': {
  379. 'vserver-info': {
  380. 'vserver-type': 'node'
  381. }
  382. },
  383. 'desired-attributes': {
  384. 'vserver-info': {
  385. 'vserver-name': None
  386. }
  387. }
  388. }
  389. self.client.send_iter_request.assert_has_calls([
  390. mock.call('vserver-get-iter', vserver_get_iter_args)])
  391. self.assertListEqual([fake.VSERVER_NAME], result)
  392. def test_list_vservers_not_found(self):
  393. api_response = netapp_api.NaElement(
  394. fake.NO_RECORDS_RESPONSE)
  395. self.mock_object(self.client,
  396. 'send_request',
  397. mock.Mock(return_value=api_response))
  398. result = self.client.list_vservers(vserver_type='data')
  399. self.assertListEqual([], result)
  400. def test_get_vserver_volume_count(self):
  401. api_response = netapp_api.NaElement(fake.VOLUME_COUNT_RESPONSE)
  402. self.mock_object(self.client,
  403. 'send_iter_request',
  404. mock.Mock(return_value=api_response))
  405. result = self.client.get_vserver_volume_count()
  406. self.assertEqual(2, result)
  407. def test_delete_vserver_no_volumes(self):
  408. self.mock_object(self.client,
  409. 'vserver_exists',
  410. mock.Mock(return_value=True))
  411. self.mock_object(self.client,
  412. 'get_vserver_root_volume_name',
  413. mock.Mock(return_value=fake.ROOT_VOLUME_NAME))
  414. self.mock_object(self.vserver_client,
  415. 'get_vserver_volume_count',
  416. mock.Mock(return_value=0))
  417. self.mock_object(self.client, '_terminate_vserver_services')
  418. self.mock_object(self.client, 'send_request')
  419. self.client.delete_vserver(
  420. fake.VSERVER_NAME,
  421. self.vserver_client,
  422. security_services=[fake.CIFS_SECURITY_SERVICE])
  423. self.client._terminate_vserver_services.assert_called_with(
  424. fake.VSERVER_NAME, self.vserver_client,
  425. [fake.CIFS_SECURITY_SERVICE])
  426. vserver_destroy_args = {'vserver-name': fake.VSERVER_NAME}
  427. self.client.send_request.assert_has_calls([
  428. mock.call('vserver-destroy', vserver_destroy_args)])
  429. def test_delete_vserver_one_volume(self):
  430. self.mock_object(self.client,
  431. 'vserver_exists',
  432. mock.Mock(return_value=True))
  433. self.mock_object(self.client,
  434. 'get_vserver_root_volume_name',
  435. mock.Mock(return_value=fake.ROOT_VOLUME_NAME))
  436. self.mock_object(self.vserver_client,
  437. 'get_vserver_volume_count',
  438. mock.Mock(return_value=1))
  439. self.mock_object(self.client, 'send_request')
  440. self.mock_object(self.vserver_client, 'offline_volume')
  441. self.mock_object(self.vserver_client, 'delete_volume')
  442. self.client.delete_vserver(fake.VSERVER_NAME,
  443. self.vserver_client)
  444. self.vserver_client.offline_volume.assert_called_with(
  445. fake.ROOT_VOLUME_NAME)
  446. self.vserver_client.delete_volume.assert_called_with(
  447. fake.ROOT_VOLUME_NAME)
  448. vserver_destroy_args = {'vserver-name': fake.VSERVER_NAME}
  449. self.client.send_request.assert_has_calls([
  450. mock.call('vserver-destroy', vserver_destroy_args)])
  451. def test_delete_vserver_one_volume_already_offline(self):
  452. self.mock_object(self.client,
  453. 'vserver_exists',
  454. mock.Mock(return_value=True))
  455. self.mock_object(self.client,
  456. 'get_vserver_root_volume_name',
  457. mock.Mock(return_value=fake.ROOT_VOLUME_NAME))
  458. self.mock_object(self.vserver_client,
  459. 'get_vserver_volume_count',
  460. mock.Mock(return_value=1))
  461. self.mock_object(self.client, 'send_request')
  462. self.mock_object(self.vserver_client,
  463. 'offline_volume',
  464. self._mock_api_error(code=netapp_api.EVOLUMEOFFLINE))
  465. self.mock_object(self.vserver_client, 'delete_volume')
  466. self.client.delete_vserver(fake.VSERVER_NAME,
  467. self.vserver_client)
  468. self.vserver_client.offline_volume.assert_called_with(
  469. fake.ROOT_VOLUME_NAME)
  470. self.vserver_client.delete_volume.assert_called_with(
  471. fake.ROOT_VOLUME_NAME)
  472. vserver_destroy_args = {'vserver-name': fake.VSERVER_NAME}
  473. self.client.send_request.assert_has_calls([
  474. mock.call('vserver-destroy', vserver_destroy_args)])
  475. self.assertEqual(1, client_cmode.LOG.error.call_count)
  476. def test_delete_vserver_one_volume_api_error(self):
  477. self.mock_object(self.client,
  478. 'vserver_exists',
  479. mock.Mock(return_value=True))
  480. self.mock_object(self.client,
  481. 'get_vserver_root_volume_name',
  482. mock.Mock(return_value=fake.ROOT_VOLUME_NAME))
  483. self.mock_object(self.vserver_client,
  484. 'get_vserver_volume_count',
  485. mock.Mock(return_value=1))
  486. self.mock_object(self.client, 'send_request')
  487. self.mock_object(self.vserver_client,
  488. 'offline_volume',
  489. self._mock_api_error())
  490. self.mock_object(self.vserver_client, 'delete_volume')
  491. self.assertRaises(netapp_api.NaApiError,
  492. self.client.delete_vserver,
  493. fake.VSERVER_NAME,
  494. self.vserver_client)
  495. def test_delete_vserver_multiple_volumes(self):
  496. self.mock_object(self.client,
  497. 'vserver_exists',
  498. mock.Mock(return_value=True))
  499. self.mock_object(self.client,
  500. 'get_vserver_root_volume_name',
  501. mock.Mock(return_value=fake.ROOT_VOLUME_NAME))
  502. self.mock_object(self.vserver_client,
  503. 'get_vserver_volume_count',
  504. mock.Mock(return_value=2))
  505. self.assertRaises(exception.NetAppException,
  506. self.client.delete_vserver,
  507. fake.VSERVER_NAME,
  508. self.vserver_client)
  509. def test_delete_vserver_not_found(self):
  510. self.mock_object(self.client,
  511. 'vserver_exists',
  512. mock.Mock(return_value=False))
  513. self.client.delete_vserver(fake.VSERVER_NAME,
  514. self.vserver_client)
  515. self.assertEqual(1, client_cmode.LOG.error.call_count)
  516. def test_terminate_vserver_services(self):
  517. self.mock_object(self.vserver_client, 'send_request')
  518. self.client._terminate_vserver_services(fake.VSERVER_NAME,
  519. self.vserver_client,
  520. [fake.CIFS_SECURITY_SERVICE])
  521. cifs_server_delete_args = {
  522. 'admin-password': fake.CIFS_SECURITY_SERVICE['password'],
  523. 'admin-username': fake.CIFS_SECURITY_SERVICE['user'],
  524. }
  525. self.vserver_client.send_request.assert_has_calls([
  526. mock.call('cifs-server-delete', cifs_server_delete_args)])
  527. def test_terminate_vserver_services_cifs_not_found(self):
  528. self.mock_object(self.vserver_client,
  529. 'send_request',
  530. self._mock_api_error(
  531. code=netapp_api.EOBJECTNOTFOUND))
  532. self.client._terminate_vserver_services(fake.VSERVER_NAME,
  533. self.vserver_client,
  534. [fake.CIFS_SECURITY_SERVICE])
  535. cifs_server_delete_args = {
  536. 'admin-password': fake.CIFS_SECURITY_SERVICE['password'],
  537. 'admin-username': fake.CIFS_SECURITY_SERVICE['user'],
  538. }
  539. self.vserver_client.send_request.assert_has_calls([
  540. mock.call('cifs-server-delete', cifs_server_delete_args)])
  541. self.assertEqual(1, client_cmode.LOG.error.call_count)
  542. def test_terminate_vserver_services_api_error(self):
  543. side_effects = [netapp_api.NaApiError(code='fake'), None]
  544. self.mock_object(self.vserver_client,
  545. 'send_request',
  546. mock.Mock(side_effect=side_effects))
  547. self.client._terminate_vserver_services(fake.VSERVER_NAME,
  548. self.vserver_client,
  549. [fake.CIFS_SECURITY_SERVICE])
  550. cifs_server_delete_args = {
  551. 'admin-password': fake.CIFS_SECURITY_SERVICE['password'],
  552. 'admin-username': fake.CIFS_SECURITY_SERVICE['user'],
  553. }
  554. self.vserver_client.send_request.assert_has_calls([
  555. mock.call('cifs-server-delete', cifs_server_delete_args),
  556. mock.call('cifs-server-delete')])
  557. self.assertEqual(0, client_cmode.LOG.error.call_count)
  558. def test_list_cluster_nodes(self):
  559. api_response = netapp_api.NaElement(
  560. fake.SYSTEM_NODE_GET_ITER_RESPONSE)
  561. self.mock_object(self.client,
  562. 'send_request',
  563. mock.Mock(return_value=api_response))
  564. result = self.client.list_cluster_nodes()
  565. self.assertListEqual([fake.NODE_NAME], result)
  566. def test_list_cluster_nodes_not_found(self):
  567. api_response = netapp_api.NaElement(fake.NO_RECORDS_RESPONSE)
  568. self.mock_object(self.client,
  569. 'send_request',
  570. mock.Mock(return_value=api_response))
  571. result = self.client.list_cluster_nodes()
  572. self.assertListEqual([], result)
  573. def test_list_node_data_ports(self):
  574. self.mock_object(self.client,
  575. 'get_node_data_ports',
  576. mock.Mock(return_value=fake.SPEED_SORTED_PORTS))
  577. result = self.client.list_node_data_ports(fake.NODE_NAME)
  578. self.assertSequenceEqual(fake.SPEED_SORTED_PORT_NAMES, result)
  579. def test_get_node_data_ports(self):
  580. api_response = netapp_api.NaElement(fake.NET_PORT_GET_ITER_RESPONSE)
  581. self.mock_object(self.client,
  582. 'send_iter_request',
  583. mock.Mock(return_value=api_response))
  584. result = self.client.get_node_data_ports(fake.NODE_NAME)
  585. net_port_get_iter_args = {
  586. 'query': {
  587. 'net-port-info': {
  588. 'node': fake.NODE_NAME,
  589. 'link-status': 'up',
  590. 'port-type': 'physical|if_group',
  591. 'role': 'data',
  592. },
  593. },
  594. 'desired-attributes': {
  595. 'net-port-info': {
  596. 'port': None,
  597. 'node': None,
  598. 'operational-speed': None,
  599. 'ifgrp-port': None,
  600. },
  601. },
  602. }
  603. self.assertSequenceEqual(fake.SPEED_SORTED_PORTS, result)
  604. self.client.send_iter_request.assert_has_calls([
  605. mock.call('net-port-get-iter', net_port_get_iter_args)])
  606. def test_get_node_data_ports_not_found(self):
  607. api_response = netapp_api.NaElement(fake.NO_RECORDS_RESPONSE)
  608. self.mock_object(self.client,
  609. 'send_iter_request',
  610. mock.Mock(return_value=api_response))
  611. result = self.client.get_node_data_ports(fake.NODE_NAME)
  612. self.assertSequenceEqual([], result)
  613. def test_sort_data_ports_by_speed(self):
  614. result = self.client._sort_data_ports_by_speed(
  615. fake.UNSORTED_PORTS_ALL_SPEEDS)
  616. self.assertSequenceEqual(fake.SORTED_PORTS_ALL_SPEEDS, result)
  617. def test_list_root_aggregates(self):
  618. api_response = netapp_api.NaElement(
  619. fake.AGGR_GET_ITER_ROOT_AGGR_RESPONSE)
  620. self.mock_object(self.client,
  621. 'send_iter_request',
  622. mock.Mock(return_value=api_response))
  623. result = self.client.list_root_aggregates()
  624. aggr_get_iter_args = {
  625. 'desired-attributes': {
  626. 'aggr-attributes': {
  627. 'aggregate-name': None,
  628. 'aggr-raid-attributes': {
  629. 'has-local-root': None,
  630. 'has-partner-root': None,
  631. },
  632. },
  633. }
  634. }
  635. self.assertSequenceEqual(fake.ROOT_AGGREGATE_NAMES, result)
  636. self.client.send_iter_request.assert_has_calls([
  637. mock.call('aggr-get-iter', aggr_get_iter_args)])
  638. def test_list_non_root_aggregates(self):
  639. api_response = netapp_api.NaElement(
  640. fake.AGGR_GET_ITER_NON_ROOT_AGGR_RESPONSE)
  641. self.mock_object(self.client,
  642. 'send_iter_request',
  643. mock.Mock(return_value=api_response))
  644. result = self.client.list_non_root_aggregates()
  645. aggr_get_iter_args = {
  646. 'query': {
  647. 'aggr-attributes': {
  648. 'aggr-raid-attributes': {
  649. 'has-local-root': 'false',
  650. 'has-partner-root': 'false',
  651. }
  652. },
  653. },
  654. 'desired-attributes': {
  655. 'aggr-attributes': {
  656. 'aggregate-name': None,
  657. },
  658. },
  659. }
  660. self.assertSequenceEqual(fake.SHARE_AGGREGATE_NAMES, result)
  661. self.client.send_iter_request.assert_has_calls([
  662. mock.call('aggr-get-iter', aggr_get_iter_args)])
  663. def test_list_aggregates(self):
  664. api_response = netapp_api.NaElement(fake.AGGR_GET_NAMES_RESPONSE)
  665. self.mock_object(self.client,
  666. 'send_iter_request',
  667. mock.Mock(return_value=api_response))
  668. result = self.client._list_aggregates()
  669. aggr_get_iter_args = {
  670. 'desired-attributes': {
  671. 'aggr-attributes': {
  672. 'aggregate-name': None,
  673. },
  674. },
  675. }
  676. self.assertSequenceEqual(
  677. fake.ROOT_AGGREGATE_NAMES + fake.SHARE_AGGREGATE_NAMES, result)
  678. self.client.send_iter_request.assert_has_calls([
  679. mock.call('aggr-get-iter', aggr_get_iter_args)])
  680. def test_list_aggregates_not_found(self):
  681. api_response = netapp_api.NaElement(fake.NO_RECORDS_RESPONSE)
  682. self.mock_object(self.client,
  683. 'send_request',
  684. mock.Mock(return_value=api_response))
  685. self.assertRaises(exception.NetAppException,
  686. self.client._list_aggregates)
  687. def test_list_vserver_aggregates(self):
  688. self.mock_object(self.vserver_client,
  689. 'get_vserver_aggregate_capacities',
  690. mock.Mock(return_value=fake.VSERVER_AGGREGATES))
  691. result = self.vserver_client.list_vserver_aggregates()
  692. self.assertListEqual(list(fake.VSERVER_AGGREGATES.keys()), result)
  693. def test_list_vserver_aggregates_none_found(self):
  694. self.mock_object(self.vserver_client,
  695. 'get_vserver_aggregate_capacities',
  696. mock.Mock(return_value={}))
  697. result = self.vserver_client.list_vserver_aggregates()
  698. self.assertListEqual([], result)
  699. @ddt.data((True, True), (True, False), (False, True), (False, False))
  700. @ddt.unpack
  701. def test_create_network_interface(self, broadcast_domains_supported,
  702. use_vlans):
  703. self.client.features.add_feature('BROADCAST_DOMAINS',
  704. broadcast_domains_supported)
  705. self.mock_object(self.client, '_ensure_broadcast_domain_for_port')
  706. self.mock_object(self.client, '_create_vlan')
  707. self.mock_object(self.client, 'send_request')
  708. lif_create_args = {
  709. 'address': fake.IP_ADDRESS,
  710. 'administrative-status': 'up',
  711. 'data-protocols': [
  712. {'data-protocol': 'nfs'},
  713. {'data-protocol': 'cifs'}
  714. ],
  715. 'home-node': fake.NODE_NAME,
  716. 'home-port': fake.VLAN_PORT if use_vlans else fake.PORT,
  717. 'netmask': fake.NETMASK,
  718. 'interface-name': fake.LIF_NAME,
  719. 'role': 'data',
  720. 'vserver': fake.VSERVER_NAME,
  721. }
  722. self.client.create_network_interface(fake.IP_ADDRESS,
  723. fake.NETMASK,
  724. fake.VLAN if use_vlans else None,
  725. fake.NODE_NAME,
  726. fake.PORT,
  727. fake.VSERVER_NAME,
  728. fake.LIF_NAME,
  729. fake.IPSPACE_NAME,
  730. fake.MTU)
  731. if use_vlans:
  732. self.client._create_vlan.assert_called_with(
  733. fake.NODE_NAME, fake.PORT, fake.VLAN)
  734. else:
  735. self.assertFalse(self.client._create_vlan.called)
  736. if broadcast_domains_supported:
  737. self.client._ensure_broadcast_domain_for_port.assert_called_with(
  738. fake.NODE_NAME, fake.VLAN_PORT if use_vlans else fake.PORT,
  739. fake.MTU, ipspace=fake.IPSPACE_NAME)
  740. else:
  741. self.assertFalse(
  742. self.client._ensure_broadcast_domain_for_port.called)
  743. self.client.send_request.assert_has_calls([
  744. mock.call('net-interface-create', lif_create_args)])
  745. def test_create_vlan(self):
  746. self.mock_object(self.client, 'send_request')
  747. vlan_create_args = {
  748. 'vlan-info': {
  749. 'parent-interface': fake.PORT,
  750. 'node': fake.NODE_NAME,
  751. 'vlanid': fake.VLAN
  752. }
  753. }
  754. self.client._create_vlan(fake.NODE_NAME, fake.PORT, fake.VLAN)
  755. self.client.send_request.assert_has_calls([
  756. mock.call('net-vlan-create', vlan_create_args)])
  757. def test_create_vlan_already_present(self):
  758. self.mock_object(self.client,
  759. 'send_request',
  760. self._mock_api_error(code=netapp_api.EDUPLICATEENTRY))
  761. vlan_create_args = {
  762. 'vlan-info': {
  763. 'parent-interface': fake.PORT,
  764. 'node': fake.NODE_NAME,
  765. 'vlanid': fake.VLAN
  766. }
  767. }
  768. self.client._create_vlan(fake.NODE_NAME, fake.PORT, fake.VLAN)
  769. self.client.send_request.assert_has_calls([
  770. mock.call('net-vlan-create', vlan_create_args)])
  771. self.assertEqual(1, client_cmode.LOG.debug.call_count)
  772. def test_create_vlan_api_error(self):
  773. self.mock_object(self.client, 'send_request', self._mock_api_error())
  774. self.assertRaises(exception.NetAppException,
  775. self.client._create_vlan,
  776. fake.NODE_NAME,
  777. fake.PORT,
  778. fake.VLAN)
  779. def test_delete_vlan(self):
  780. self.mock_object(self.client, 'send_request')
  781. vlan_delete_args = {
  782. 'vlan-info': {
  783. 'parent-interface': fake.PORT,
  784. 'node': fake.NODE_NAME,
  785. 'vlanid': fake.VLAN
  786. }
  787. }
  788. self.client.delete_vlan(fake.NODE_NAME, fake.PORT, fake.VLAN)
  789. self.client.send_request.assert_has_calls([
  790. mock.call('net-vlan-delete', vlan_delete_args)])
  791. def test_delete_vlan_still_used(self):
  792. self.mock_object(self.client,
  793. 'send_request',
  794. self._mock_api_error(code=netapp_api.EAPIERROR,
  795. message='Port already has a '
  796. 'lif bound. '))
  797. vlan_delete_args = {
  798. 'vlan-info': {
  799. 'parent-interface': fake.PORT,
  800. 'node': fake.NODE_NAME,
  801. 'vlanid': fake.VLAN
  802. }
  803. }
  804. self.client.delete_vlan(fake.NODE_NAME, fake.PORT, fake.VLAN)
  805. self.client.send_request.assert_has_calls([
  806. mock.call('net-vlan-delete', vlan_delete_args)])
  807. self.assertEqual(1, client_cmode.LOG.debug.call_count)
  808. def test_delete_vlan_api_error(self):
  809. self.mock_object(self.client, 'send_request', self._mock_api_error())
  810. self.assertRaises(exception.NetAppException,
  811. self.client.delete_vlan,
  812. fake.NODE_NAME,
  813. fake.PORT,
  814. fake.VLAN)
  815. def test_create_route(self):
  816. api_response = netapp_api.NaElement(
  817. fake.NET_ROUTES_CREATE_RESPONSE)
  818. expected_api_args = {
  819. 'destination': fake.SUBNET,
  820. 'gateway': fake.GATEWAY,
  821. 'return-record': 'true',
  822. }
  823. self.mock_object(
  824. self.client, 'send_request', mock.Mock(return_value=api_response))
  825. self.client.create_route(fake.GATEWAY, destination=fake.SUBNET)
  826. self.client.send_request.assert_called_once_with(
  827. 'net-routes-create', expected_api_args)
  828. def test_create_route_duplicate(self):
  829. self.mock_object(client_cmode.LOG, 'debug')
  830. expected_api_args = {
  831. 'destination': fake.SUBNET,
  832. 'gateway': fake.GATEWAY,
  833. 'return-record': 'true',
  834. }
  835. self.mock_object(
  836. self.client, 'send_request',
  837. mock.Mock(side_effect=self._mock_api_error(
  838. code=netapp_api.EAPIERROR, message='Duplicate route exists.')))
  839. self.client.create_route(fake.GATEWAY, destination=fake.SUBNET)
  840. self.client.send_request.assert_called_once_with(
  841. 'net-routes-create', expected_api_args)
  842. self.assertEqual(1, client_cmode.LOG.debug.call_count)
  843. def test_create_route_api_error(self):
  844. expected_api_args = {
  845. 'destination': fake.SUBNET,
  846. 'gateway': fake.GATEWAY,
  847. 'return-record': 'true',
  848. }
  849. self.mock_object(
  850. self.client, 'send_request',
  851. mock.Mock(side_effect=self._mock_api_error()))
  852. self.assertRaises(exception.NetAppException,
  853. self.client.create_route,
  854. fake.GATEWAY, destination=fake.SUBNET)
  855. self.client.send_request.assert_called_once_with(
  856. 'net-routes-create', expected_api_args)
  857. def test_ensure_broadcast_domain_for_port_domain_match(self):
  858. port_info = {
  859. 'ipspace': fake.IPSPACE_NAME,
  860. 'broadcast-domain': fake.BROADCAST_DOMAIN,
  861. }
  862. self.mock_object(self.client,
  863. '_get_broadcast_domain_for_port',
  864. mock.Mock(return_value=port_info))
  865. self.mock_object(self.client,
  866. '_broadcast_domain_exists',
  867. mock.Mock(return_value=True))
  868. self.mock_object(self.client, '_create_broadcast_domain')
  869. self.mock_object(self.client, '_modify_broadcast_domain')
  870. self.mock_object(self.client, '_add_port_to_broadcast_domain')
  871. self.client._ensure_broadcast_domain_for_port(
  872. fake.NODE_NAME, fake.PORT, fake.MTU, ipspace=fake.IPSPACE_NAME)
  873. self.client._get_broadcast_domain_for_port.assert_called_once_with(
  874. fake.NODE_NAME, fake.PORT)
  875. self.client._modify_broadcast_domain.assert_called_once_with(
  876. fake.BROADCAST_DOMAIN, fake.IPSPACE_NAME, fake.MTU)
  877. self.assertFalse(self.client._broadcast_domain_exists.called)
  878. self.assertFalse(self.client._create_broadcast_domain.called)
  879. self.assertFalse(self.client._add_port_to_broadcast_domain.called)
  880. @ddt.data(fake.IPSPACE_NAME, client_cmode.DEFAULT_IPSPACE)
  881. def test_ensure_broadcast_domain_for_port_other_domain(self, ipspace):
  882. port_info = {
  883. 'ipspace': ipspace,
  884. 'broadcast-domain': 'other_domain',
  885. }
  886. self.mock_object(self.client,
  887. '_get_broadcast_domain_for_port',
  888. mock.Mock(return_value=port_info))
  889. self.mock_object(self.client,
  890. '_broadcast_domain_exists',
  891. mock.Mock(return_value=True))
  892. self.mock_object(self.client, '_create_broadcast_domain')
  893. self.mock_object(self.client, '_modify_broadcast_domain')
  894. self.mock_object(self.client, '_remove_port_from_broadcast_domain')
  895. self.mock_object(self.client, '_add_port_to_broadcast_domain')
  896. self.client._ensure_broadcast_domain_for_port(
  897. fake.NODE_NAME, fake.PORT, ipspace=fake.IPSPACE_NAME, mtu=fake.MTU)
  898. self.client._get_broadcast_domain_for_port.assert_called_once_with(
  899. fake.NODE_NAME, fake.PORT)
  900. self.client._remove_port_from_broadcast_domain.assert_called_once_with(
  901. fake.NODE_NAME, fake.PORT, 'other_domain', ipspace)
  902. self.client._broadcast_domain_exists.assert_called_once_with(
  903. fake.BROADCAST_DOMAIN, fake.IPSPACE_NAME)
  904. self.assertFalse(self.client._create_broadcast_domain.called)
  905. self.client._modify_broadcast_domain.assert_called_once_with(
  906. fake.BROADCAST_DOMAIN, fake.IPSPACE_NAME, fake.MTU)
  907. self.client._add_port_to_broadcast_domain.assert_called_once_with(
  908. fake.NODE_NAME, fake.PORT, fake.BROADCAST_DOMAIN,
  909. fake.IPSPACE_NAME)
  910. def test_ensure_broadcast_domain_for_port_no_domain(self):
  911. port_info = {
  912. 'ipspace': fake.IPSPACE_NAME,
  913. 'broadcast-domain': None,
  914. }
  915. self.mock_object(self.client,
  916. '_get_broadcast_domain_for_port',
  917. mock.Mock(return_value=port_info))
  918. self.mock_object(self.client,
  919. '_broadcast_domain_exists',
  920. mock.Mock(return_value=False))
  921. self.mock_object(self.client, '_create_broadcast_domain')
  922. self.mock_object(self.client, '_modify_broadcast_domain')
  923. self.mock_object(self.client, '_remove_port_from_broadcast_domain')
  924. self.mock_object(self.client, '_add_port_to_broadcast_domain')
  925. self.client._ensure_broadcast_domain_for_port(
  926. fake.NODE_NAME, fake.PORT, ipspace=fake.IPSPACE_NAME, mtu=fake.MTU)
  927. self.client._get_broadcast_domain_for_port.assert_called_once_with(
  928. fake.NODE_NAME, fake.PORT)
  929. self.assertFalse(self.client._remove_port_from_broadcast_domain.called)
  930. self.client._broadcast_domain_exists.assert_called_once_with(
  931. fake.BROADCAST_DOMAIN, fake.IPSPACE_NAME)
  932. self.client._create_broadcast_domain.assert_called_once_with(
  933. fake.BROADCAST_DOMAIN, fake.IPSPACE_NAME, fake.MTU)
  934. self.assertFalse(self.client._modify_broadcast_domain.called)
  935. self.client._add_port_to_broadcast_domain.assert_called_once_with(
  936. fake.NODE_NAME, fake.PORT, fake.BROADCAST_DOMAIN,
  937. fake.IPSPACE_NAME)
  938. def test_get_broadcast_domain_for_port(self):
  939. api_response = netapp_api.NaElement(
  940. fake.NET_PORT_GET_ITER_BROADCAST_DOMAIN_RESPONSE)
  941. self.mock_object(self.client,
  942. 'send_iter_request',
  943. mock.Mock(return_value=api_response))
  944. net_port_get_iter_args = {
  945. 'query': {
  946. 'net-port-info': {
  947. 'node': fake.NODE_NAME,
  948. 'port': fake.PORT,
  949. },
  950. },
  951. 'desired-attributes': {
  952. 'net-port-info': {
  953. 'broadcast-domain': None,
  954. 'ipspace': None,
  955. },
  956. },
  957. }
  958. result = self.client._get_broadcast_domain_for_port(fake.NODE_NAME,
  959. fake.PORT)
  960. expected = {
  961. 'broadcast-domain': fake.BROADCAST_DOMAIN,
  962. 'ipspace': fake.IPSPACE_NAME,
  963. }
  964. self.client.send_iter_request.assert_has_calls([
  965. mock.call('net-port-get-iter', net_port_get_iter_args)])
  966. self.assertEqual(expected, result)
  967. def test_get_broadcast_domain_for_port_port_not_found(self):
  968. api_response = netapp_api.NaElement(
  969. fake.NO_RECORDS_RESPONSE)
  970. self.mock_object(self.client,
  971. 'send_iter_request',
  972. mock.Mock(return_value=api_response))
  973. self.assertRaises(exception.NetAppException,
  974. self.client._get_broadcast_domain_for_port,
  975. fake.NODE_NAME,
  976. fake.PORT)
  977. def test_get_broadcast_domain_for_port_domain_not_found(self):
  978. api_response = netapp_api.NaElement(
  979. fake.NET_PORT_GET_ITER_BROADCAST_DOMAIN_MISSING_RESPONSE)
  980. self.mock_object(self.client,
  981. 'send_iter_request',
  982. mock.Mock(return_value=api_response))
  983. result = self.client._get_broadcast_domain_for_port(fake.NODE_NAME,
  984. fake.PORT)
  985. expected = {
  986. 'broadcast-domain': None,
  987. 'ipspace': fake.IPSPACE_NAME,
  988. }
  989. self.assertEqual(expected, result)
  990. def test_broadcast_domain_exists(self):
  991. api_response = netapp_api.NaElement(
  992. fake.NET_PORT_BROADCAST_DOMAIN_GET_ITER_RESPONSE)
  993. self.mock_object(self.client,
  994. 'send_iter_request',
  995. mock.Mock(return_value=api_response))
  996. result = self.client._broadcast_domain_exists(fake.BROADCAST_DOMAIN,
  997. fake.IPSPACE_NAME)
  998. net_port_broadcast_domain_get_iter_args = {
  999. 'query': {
  1000. 'net-port-broadcast-domain-info': {
  1001. 'ipspace': fake.IPSPACE_NAME,
  1002. 'broadcast-domain': fake.BROADCAST_DOMAIN,
  1003. },
  1004. },
  1005. 'desired-attributes': {
  1006. 'net-port-broadcast-domain-info': None,
  1007. },
  1008. }
  1009. self.client.send_iter_request.assert_has_calls([
  1010. mock.call('net-port-broadcast-domain-get-iter',
  1011. net_port_broadcast_domain_get_iter_args)])
  1012. self.assertTrue(result)
  1013. def test_broadcast_domain_exists_not_found(self):
  1014. api_response = netapp_api.NaElement(
  1015. fake.NO_RECORDS_RESPONSE)
  1016. self.mock_object(self.client,
  1017. 'send_request',
  1018. mock.Mock(return_value=api_response))
  1019. result = self.client._broadcast_domain_exists(fake.BROADCAST_DOMAIN,
  1020. fake.IPSPACE_NAME)
  1021. self.assertFalse(result)
  1022. def test_create_broadcast_domain(self):
  1023. self.mock_object(self.client, 'send_request')
  1024. result = self.client._create_broadcast_domain(fake.BROADCAST_DOMAIN,
  1025. fake.IPSPACE_NAME,
  1026. fake.MTU)
  1027. net_port_broadcast_domain_create_args = {
  1028. 'ipspace': fake.IPSPACE_NAME,
  1029. 'broadcast-domain': fake.BROADCAST_DOMAIN,
  1030. 'mtu': fake.MTU,
  1031. }
  1032. self.assertIsNone(result)
  1033. self.client.send_request.assert_has_calls([
  1034. mock.call('net-port-broadcast-domain-create',
  1035. net_port_broadcast_domain_create_args)])
  1036. def test_modify_broadcast_domain(self):
  1037. self.mock_object(self.client, 'send_request')
  1038. result = self.client._modify_broadcast_domain(fake.BROADCAST_DOMAIN,
  1039. fake.IPSPACE_NAME,
  1040. fake.MTU)
  1041. net_port_broadcast_domain_modify_args = {
  1042. 'ipspace': fake.IPSPACE_NAME,
  1043. 'broadcast-domain': fake.BROADCAST_DOMAIN,
  1044. 'mtu': fake.MTU,
  1045. }
  1046. self.assertIsNone(result)
  1047. self.client.send_request.assert_called_once_with(
  1048. 'net-port-broadcast-domain-modify',
  1049. net_port_broadcast_domain_modify_args)
  1050. def test_delete_broadcast_domain(self):
  1051. self.mock_object(self.client, 'send_request')
  1052. result = self.client._delete_broadcast_domain(fake.BROADCAST_DOMAIN,
  1053. fake.IPSPACE_NAME)
  1054. net_port_broadcast_domain_delete_args = {
  1055. 'ipspace': fake.IPSPACE_NAME,
  1056. 'broadcast-domain': fake.BROADCAST_DOMAIN,
  1057. }
  1058. self.assertIsNone(result)
  1059. self.client.send_request.assert_has_calls([
  1060. mock.call('net-port-broadcast-domain-destroy',
  1061. net_port_broadcast_domain_delete_args)])
  1062. def test_delete_broadcast_domains_for_ipspace_not_found(self):
  1063. self.mock_object(self.client,
  1064. 'get_ipspaces',
  1065. mock.Mock(return_value=[]))
  1066. self.mock_object(self.client, '_delete_broadcast_domain')
  1067. self.client._delete_broadcast_domains_for_ipspace(fake.IPSPACE_NAME)
  1068. self.client.get_ipspaces.assert_called_once_with(
  1069. ipspace_name=fake.IPSPACE_NAME)
  1070. self.assertFalse(self.client._delete_broadcast_domain.called)
  1071. def test_delete_broadcast_domains_for_ipspace(self):
  1072. self.mock_object(self.client,
  1073. 'get_ipspaces',
  1074. mock.Mock(return_value=fake.IPSPACES))
  1075. self.mock_object(self.client, '_delete_broadcast_domain')
  1076. self.client._delete_broadcast_domains_for_ipspace(fake.IPSPACE_NAME)
  1077. self.client.get_ipspaces.assert_called_once_with(
  1078. ipspace_name=fake.IPSPACE_NAME)
  1079. self.client._delete_broadcast_domain.assert_called_once_with(
  1080. fake.IPSPACES[0]['broadcast-domains'][0], fake.IPSPACE_NAME)
  1081. def test_add_port_to_broadcast_domain(self):
  1082. self.mock_object(self.client, 'send_request')
  1083. add_port_to_broadcast_domain_args = {
  1084. 'ipspace': fake.IPSPACE_NAME,
  1085. 'broadcast-domain': fake.BROADCAST_DOMAIN,
  1086. 'ports': {
  1087. 'net-qualified-port-name': ':'.join([fake.NODE_NAME,
  1088. fake.VLAN_PORT])
  1089. }
  1090. }
  1091. result = self.client._add_port_to_broadcast_domain(
  1092. fake.NODE_NAME, fake.VLAN_PORT, fake.BROADCAST_DOMAIN,
  1093. fake.IPSPACE_NAME)
  1094. self.assertIsNone(result)
  1095. self.client.send_request.assert_has_calls([
  1096. mock.call('net-port-broadcast-domain-add-ports',
  1097. add_port_to_broadcast_domain_args)])
  1098. def test_add_port_to_broadcast_domain_already_present(self):
  1099. self.mock_object(self.client, 'send_request', self._mock_api_error(
  1100. code=netapp_api.
  1101. E_VIFMGR_PORT_ALREADY_ASSIGNED_TO_BROADCAST_DOMAIN))
  1102. result = self.client._add_port_to_broadcast_domain(
  1103. fake.NODE_NAME, fake.VLAN_PORT, fake.BROADCAST_DOMAIN,
  1104. fake.IPSPACE_NAME)
  1105. self.assertIsNone(result)
  1106. def test_add_port_to_broadcast_domain_api_error(self):
  1107. self.mock_object(self.client, 'send_request', self._mock_api_error())
  1108. self.assertRaises(exception.NetAppException,
  1109. self.client._add_port_to_broadcast_domain,
  1110. fake.NODE_NAME,
  1111. fake.VLAN_PORT,
  1112. fake.BROADCAST_DOMAIN,
  1113. fake.IPSPACE_NAME)
  1114. def test_remove_port_from_broadcast_domain(self):
  1115. self.mock_object(self.client, 'send_request')
  1116. result = self.client._remove_port_from_broadcast_domain(
  1117. fake.NODE_NAME, fake.VLAN_PORT, fake.BROADCAST_DOMAIN,
  1118. fake.IPSPACE_NAME)
  1119. net_port_broadcast_domain_remove_ports_args = {
  1120. 'ipspace': fake.IPSPACE_NAME,
  1121. 'broadcast-domain': fake.BROADCAST_DOMAIN,
  1122. 'ports': {
  1123. 'net-qualified-port-name': ':'.join([fake.NODE_NAME,
  1124. fake.VLAN_PORT])
  1125. }
  1126. }
  1127. self.assertIsNone(result)
  1128. self.client.send_request.assert_has_calls([
  1129. mock.call('net-port-broadcast-domain-remove-ports',
  1130. net_port_broadcast_domain_remove_ports_args)])
  1131. def test_network_interface_exists(self):
  1132. api_response = netapp_api.NaElement(
  1133. fake.NET_INTERFACE_GET_ONE_RESPONSE)
  1134. self.mock_object(self.client,
  1135. 'send_iter_request',
  1136. mock.Mock(return_value=api_response))
  1137. net_interface_get_args = {
  1138. 'query': {
  1139. 'net-interface-info': {
  1140. 'address': fake.IP_ADDRESS,
  1141. 'home-node': fake.NODE_NAME,
  1142. 'home-port': fake.VLAN_PORT,
  1143. 'netmask': fake.NETMASK,
  1144. 'vserver': fake.VSERVER_NAME}
  1145. },
  1146. 'desired-attributes': {
  1147. 'net-interface-info': {
  1148. 'interface-name': None,
  1149. }
  1150. }
  1151. }
  1152. result = self.client.network_interface_exists(
  1153. fake.VSERVER_NAME, fake.NODE_NAME, fake.PORT, fake.IP_ADDRESS,
  1154. fake.NETMASK, fake.VLAN)
  1155. self.client.send_iter_request.assert_has_calls([
  1156. mock.call('net-interface-get-iter', net_interface_get_args)])
  1157. self.assertTrue(result)
  1158. def test_network_interface_exists_not_found(self):
  1159. api_response = netapp_api.NaElement(fake.NO_RECORDS_RESPONSE)
  1160. self.mock_object(self.client,
  1161. 'send_iter_request',
  1162. mock.Mock(return_value=api_response))
  1163. net_interface_get_args = {
  1164. 'query': {
  1165. 'net-interface-info': {
  1166. 'address': fake.IP_ADDRESS,
  1167. 'home-node': fake.NODE_NAME,
  1168. 'home-port': fake.PORT,
  1169. 'netmask': fake.NETMASK,
  1170. 'vserver': fake.VSERVER_NAME}
  1171. },
  1172. 'desired-attributes': {
  1173. 'net-interface-info': {
  1174. 'interface-name': None,
  1175. }
  1176. }
  1177. }
  1178. result = self.client.network_interface_exists(
  1179. fake.VSERVER_NAME, fake.NODE_NAME, fake.PORT, fake.IP_ADDRESS,
  1180. fake.NETMASK, None)
  1181. self.client.send_iter_request.assert_has_calls([
  1182. mock.call('net-interface-get-iter', net_interface_get_args)])
  1183. self.assertFalse(result)
  1184. def test_list_network_interfaces(self):
  1185. api_response = netapp_api.NaElement(
  1186. fake.NET_INTERFACE_GET_ITER_RESPONSE)
  1187. self.mock_object(self.client,
  1188. 'send_iter_request',
  1189. mock.Mock(return_value=api_response))
  1190. net_interface_get_args = {
  1191. 'desired-attributes': {
  1192. 'net-interface-info': {
  1193. 'interface-name': None,
  1194. }
  1195. }
  1196. }
  1197. result = self.client.list_network_interfaces()
  1198. self.client.send_iter_request.assert_has_calls([
  1199. mock.call('net-interface-get-iter', net_interface_get_args)])
  1200. self.assertSequenceEqual(fake.LIF_NAMES, result)
  1201. def test_list_network_interfaces_not_found(self):
  1202. api_response = netapp_api.NaElement(fake.NO_RECORDS_RESPONSE)
  1203. self.mock_object(self.client,
  1204. 'send_request',
  1205. mock.Mock(return_value=api_response))
  1206. result = self.client.list_network_interfaces()
  1207. self.assertListEqual([], result)
  1208. def test_get_network_interfaces(self):
  1209. api_response = netapp_api.NaElement(
  1210. fake.NET_INTERFACE_GET_ITER_RESPONSE)
  1211. self.mock_object(self.client,
  1212. 'send_iter_request',
  1213. mock.Mock(return_value=api_response))
  1214. result = self.client.get_network_interfaces()
  1215. self.client.send_iter_request.assert_has_calls([
  1216. mock.call('net-interface-get-iter', None)])
  1217. self.assertSequenceEqual(fake.LIFS, result)
  1218. def test_get_network_interfaces_filtered_by_protocol(self):
  1219. api_response = netapp_api.NaElement(
  1220. fake.NET_INTERFACE_GET_ITER_RESPONSE_NFS)
  1221. self.mock_object(self.client,
  1222. 'send_iter_request',
  1223. mock.Mock(return_value=api_response))
  1224. result = self.client.get_network_interfaces(protocols=['NFS'])
  1225. net_interface_get_args = {
  1226. 'query': {
  1227. 'net-interface-info': {
  1228. 'data-protocols': {
  1229. 'data-protocol': 'nfs',
  1230. }
  1231. }
  1232. }
  1233. }
  1234. self.client.send_iter_request.assert_has_calls([
  1235. mock.call('net-interface-get-iter', net_interface_get_args)])
  1236. self.assertListEqual(fake.NFS_LIFS, result)
  1237. def test_get_network_interfaces_not_found(self):
  1238. api_response = netapp_api.NaElement(fake.NO_RECORDS_RESPONSE)
  1239. self.mock_object(self.client,
  1240. 'send_iter_request',
  1241. mock.Mock(return_value=api_response))
  1242. result = self.client.get_network_interfaces()
  1243. self.client.send_iter_request.assert_has_calls([
  1244. mock.call('net-interface-get-iter', None)])
  1245. self.assertListEqual([], result)
  1246. def test_get_ipspaces(self):
  1247. self.client.features.add_feature('IPSPACES')
  1248. api_response = netapp_api.NaElement(
  1249. fake.NET_IPSPACES_GET_ITER_RESPONSE)
  1250. self.mock_object(self.client,
  1251. 'send_iter_request',
  1252. mock.Mock(return_value=api_response))
  1253. result = self.client.get_ipspaces(ipspace_name=fake.IPSPACE_NAME)
  1254. net_ipspaces_get_iter_args = {
  1255. 'query': {
  1256. 'net-ipspaces-info': {
  1257. 'ipspace': fake.IPSPACE_NAME,
  1258. },
  1259. },
  1260. }
  1261. self.client.send_iter_request.assert_has_calls([
  1262. mock.call('net-ipspaces-get-iter', net_ipspaces_get_iter_args)])
  1263. self.assertEqual(fake.IPSPACES, result)
  1264. def test_get_ipspaces_not_found(self):
  1265. self.client.features.add_feature('IPSPACES')
  1266. api_response = netapp_api.NaElement(fake.NO_RECORDS_RESPONSE)
  1267. self.mock_object(self.client,
  1268. 'send_iter_request',
  1269. mock.Mock(return_value=api_response))
  1270. result = self.client.get_ipspaces()
  1271. net_ipspaces_get_iter_args = {}
  1272. self.client.send_iter_request.assert_has_calls([
  1273. mock.call('net-ipspaces-get-iter', net_ipspaces_get_iter_args)])
  1274. self.assertEqual([], result)
  1275. def test_get_ipspaces_not_supported(self):
  1276. self.mock_object(self.client, 'send_iter_request')
  1277. result = self.client.get_ipspaces()
  1278. self.assertFalse(self.client.send_iter_request.called)
  1279. self.assertEqual([], result)
  1280. @ddt.data((fake.NET_IPSPACES_GET_ITER_RESPONSE, True),
  1281. (fake.NO_RECORDS_RESPONSE, False))
  1282. @ddt.unpack
  1283. def test_ipspace_exists(self, api_response, expected):
  1284. self.client.features.add_feature('IPSPACES')
  1285. api_response = netapp_api.NaElement(api_response)
  1286. self.mock_object(self.client,
  1287. 'send_iter_request',
  1288. mock.Mock(return_value=api_response))
  1289. result = self.client.ipspace_exists(fake.IPSPACE_NAME)
  1290. net_ipspaces_get_iter_args = {
  1291. 'query': {
  1292. 'net-ipspaces-info': {
  1293. 'ipspace': fake.IPSPACE_NAME,
  1294. },
  1295. },
  1296. 'desired-attributes': {
  1297. 'net-ipspaces-info': {
  1298. 'ipspace': None,
  1299. },
  1300. },
  1301. }
  1302. self.client.send_iter_request.assert_has_calls([
  1303. mock.call('net-ipspaces-get-iter', net_ipspaces_get_iter_args)])
  1304. self.assertEqual(expected, result)
  1305. def test_ipspace_exists_not_supported(self):
  1306. result = self.client.ipspace_exists(fake.IPSPACE_NAME)
  1307. self.assertFalse(result)
  1308. def test_create_ipspace(self):
  1309. self.mock_object(self.client, 'send_request')
  1310. self.client.create_ipspace(fake.IPSPACE_NAME)
  1311. net_ipspaces_create_args = {'ipspace': fake.IPSPACE_NAME}
  1312. self.client.send_request.assert_has_calls([
  1313. mock.call('net-ipspaces-create', net_ipspaces_create_args)])
  1314. def test_delete_ipspace(self):
  1315. mock_delete_broadcast_domains_for_ipspace = self.mock_object(
  1316. self.client, '_delete_broadcast_domains_for_ipspace')
  1317. self.mock_object(self.client, 'send_request')
  1318. self.client.delete_ipspace(fake.IPSPACE_NAME)
  1319. net_ipspaces_destroy_args = {'ipspace': fake.IPSPACE_NAME}
  1320. mock_delete_broadcast_domains_for_ipspace.assert_called_once_with(
  1321. fake.IPSPACE_NAME)
  1322. self.client.send_request.assert_has_calls([
  1323. mock.call('net-ipspaces-destroy', net_ipspaces_destroy_args)])
  1324. def test_add_vserver_to_ipspace(self):
  1325. self.mock_object(self.client, 'send_request')
  1326. self.client.add_vserver_to_ipspace(fake.IPSPACE_NAME,
  1327. fake.VSERVER_NAME)
  1328. net_ipspaces_assign_vserver_args = {
  1329. 'ipspace': fake.IPSPACE_NAME,
  1330. 'vserver': fake.VSERVER_NAME
  1331. }
  1332. self.client.send_request.assert_has_calls([
  1333. mock.call('net-ipspaces-assign-vserver',
  1334. net_ipspaces_assign_vserver_args)])
  1335. def test_get_node_for_aggregate(self):
  1336. api_response = netapp_api.NaElement(
  1337. fake.AGGR_GET_NODE_RESPONSE).get_child_by_name(
  1338. 'attributes-list').get_children()
  1339. self.mock_object(self.client,
  1340. '_get_aggregates',
  1341. mock.Mock(return_value=api_response))
  1342. result = self.client.get_node_for_aggregate(fake.SHARE_AGGREGATE_NAME)
  1343. desired_attributes = {
  1344. 'aggr-attributes': {
  1345. 'aggregate-name': None,
  1346. 'aggr-ownership-attributes': {
  1347. 'home-name': None,
  1348. },
  1349. },
  1350. }
  1351. self.client._get_aggregates.assert_has_calls([
  1352. mock.call(
  1353. aggregate_names=[fake.SHARE_AGGREGATE_NAME],
  1354. desired_attributes=desired_attributes)])
  1355. self.assertEqual(fake.NODE_NAME, result)
  1356. def test_get_node_for_aggregate_none_requested(self):
  1357. result = self.client.get_node_for_aggregate(None)
  1358. self.assertIsNone(result)
  1359. def test_get_node_for_aggregate_api_not_found(self):
  1360. self.mock_object(self.client,
  1361. 'send_iter_request',
  1362. mock.Mock(side_effect=self._mock_api_error(
  1363. netapp_api.EAPINOTFOUND)))
  1364. result = self.client.get_node_for_aggregate(fake.SHARE_AGGREGATE_NAME)
  1365. self.assertIsNone(result)
  1366. def test_get_node_for_aggregate_api_error(self):
  1367. self.mock_object(self.client,
  1368. 'send_iter_request',
  1369. self._mock_api_error())
  1370. self.assertRaises(netapp_api.NaApiError,
  1371. self.client.get_node_for_aggregate,
  1372. fake.SHARE_AGGREGATE_NAME)
  1373. def test_get_node_for_aggregate_not_found(self):
  1374. api_response = netapp_api.NaElement(fake.NO_RECORDS_RESPONSE)
  1375. self.mock_object(self.client,
  1376. 'send_iter_request',
  1377. mock.Mock(return_value=api_response))
  1378. result = self.client.get_node_for_aggregate(fake.SHARE_AGGREGATE_NAME)
  1379. self.assertIsNone(result)
  1380. def test_get_cluster_aggregate_capacities(self):
  1381. api_response = netapp_api.NaElement(
  1382. fake.AGGR_GET_SPACE_RESPONSE).get_child_by_name(
  1383. 'attributes-list').get_children()
  1384. self.mock_object(self.client,
  1385. '_get_aggregates',
  1386. mock.Mock(return_value=api_response))
  1387. result = self.client.get_cluster_aggregate_capacities(
  1388. fake.SHARE_AGGREGATE_NAMES)
  1389. desired_attributes = {
  1390. 'aggr-attributes': {
  1391. 'aggregate-name': None,
  1392. 'aggr-space-attributes': {
  1393. 'size-available': None,
  1394. 'size-total': None,
  1395. 'size-used': None,
  1396. }
  1397. }
  1398. }
  1399. self.client._get_aggregates.assert_has_calls([
  1400. mock.call(
  1401. aggregate_names=fake.SHARE_AGGREGATE_NAMES,
  1402. desired_attributes=desired_attributes)])
  1403. expected = {
  1404. fake.SHARE_AGGREGATE_NAMES[0]: {
  1405. 'available': 45670400,
  1406. 'total': 943718400,
  1407. 'used': 898048000,
  1408. },
  1409. fake.SHARE_AGGREGATE_NAMES[1]: {
  1410. 'available': 4267659264,
  1411. 'total': 7549747200,
  1412. 'used': 3282087936,
  1413. },
  1414. }
  1415. self.assertDictEqual(expected, result)
  1416. def test_get_cluster_aggregate_capacities_not_found(self):
  1417. api_response = netapp_api.NaElement('none').get_children()
  1418. self.mock_object(self.client,
  1419. '_get_aggregates',
  1420. mock.Mock(return_value=api_response))
  1421. result = self.client.get_cluster_aggregate_capacities(
  1422. fake.SHARE_AGGREGATE_NAMES)
  1423. self.assertEqual({}, result)
  1424. def test_get_cluster_aggregate_capacities_none_requested(self):
  1425. result = self.client.get_cluster_aggregate_capacities([])
  1426. self.assertEqual({}, result)
  1427. def test_get_vserver_aggregate_capacities(self):
  1428. api_response = netapp_api.NaElement(fake.VSERVER_GET_RESPONSE)
  1429. self.mock_object(self.vserver_client,
  1430. 'send_request',
  1431. mock.Mock(return_value=api_response))
  1432. result = self.vserver_client.get_vserver_aggregate_capacities()
  1433. vserver_args = {
  1434. 'desired-attributes': {
  1435. 'vserver-info': {
  1436. 'vserver-name': None,
  1437. 'vserver-aggr-info-list': {
  1438. 'vserver-aggr-info': {
  1439. 'aggr-name': None,
  1440. 'aggr-availsize': None
  1441. }
  1442. }
  1443. }
  1444. }
  1445. }
  1446. self.vserver_client.send_request.assert_has_calls([
  1447. mock.call('vserver-get', vserver_args)])
  1448. self.assertDictEqual(fake.VSERVER_AGGREGATES, result)
  1449. def test_get_vserver_aggregate_capacities_partial_request(self):
  1450. api_response = netapp_api.NaElement(fake.VSERVER_GET_RESPONSE)
  1451. self.mock_object(self.vserver_client,
  1452. 'send_request',
  1453. mock.Mock(return_value=api_response))
  1454. result = self.vserver_client.get_vserver_aggregate_capacities(
  1455. fake.SHARE_AGGREGATE_NAMES[0])
  1456. expected = {fake.SHARE_AGGREGATE_NAMES[0]:
  1457. fake.VSERVER_AGGREGATES[fake.SHARE_AGGREGATE_NAMES[0]]}
  1458. self.assertDictEqual(expected, result)
  1459. def test_get_vserver_aggregate_capacities_aggregate_not_found(self):
  1460. api_response = netapp_api.NaElement(
  1461. fake.VSERVER_GET_RESPONSE_NO_AGGREGATES)
  1462. self.mock_object(self.vserver_client,
  1463. 'send_request',
  1464. mock.Mock(return_value=api_response))
  1465. result = self.vserver_client.get_vserver_aggregate_capacities()
  1466. self.assertDictEqual({}, result)
  1467. self.assertEqual(1, client_cmode.LOG.warning.call_count)
  1468. def test_get_vserver_aggregate_capacities_vserver_not_found(self):
  1469. api_response = netapp_api.NaElement(fake.NO_RECORDS_RESPONSE)
  1470. self.mock_object(self.vserver_client,
  1471. 'send_request',
  1472. mock.Mock(return_value=api_response))
  1473. self.assertRaises(exception.NetAppException,
  1474. self.vserver_client.get_vserver_aggregate_capacities)
  1475. def test_get_vserver_aggregate_capacities_none_requested(self):
  1476. result = self.client.get_vserver_aggregate_capacities([])
  1477. self.assertEqual({}, result)
  1478. def test_get_aggregates(self):
  1479. api_response = netapp_api.NaElement(fake.AGGR_GET_ITER_RESPONSE)
  1480. self.mock_object(self.client,
  1481. 'send_iter_request',
  1482. mock.Mock(return_value=api_response))
  1483. result = self.client._get_aggregates()
  1484. self.client.send_iter_request.assert_has_calls([
  1485. mock.call('aggr-get-iter', {})])
  1486. self.assertListEqual(
  1487. [aggr.to_string() for aggr in api_response.get_child_by_name(
  1488. 'attributes-list').get_children()],
  1489. [aggr.to_string() for aggr in result])
  1490. def test_get_aggregates_with_filters(self):
  1491. api_response = netapp_api.NaElement(fake.AGGR_GET_SPACE_RESPONSE)
  1492. self.mock_object(self.client,
  1493. 'send_iter_request',
  1494. mock.Mock(return_value=api_response))
  1495. desired_attributes = {
  1496. 'aggr-attributes': {
  1497. 'aggregate-name': None,
  1498. 'aggr-space-attributes': {
  1499. 'size-total': None,
  1500. 'size-available': None,
  1501. }
  1502. }
  1503. }
  1504. result = self.client._get_aggregates(
  1505. aggregate_names=fake.SHARE_AGGREGATE_NAMES,
  1506. desired_attributes=desired_attributes)
  1507. aggr_get_iter_args = {
  1508. 'query': {
  1509. 'aggr-attributes': {
  1510. 'aggregate-name': '|'.join(fake.SHARE_AGGREGATE_NAMES),
  1511. }
  1512. },
  1513. 'desired-attributes': desired_attributes
  1514. }
  1515. self.client.send_iter_request.assert_has_calls([
  1516. mock.call('aggr-get-iter', aggr_get_iter_args)])
  1517. self.assertListEqual(
  1518. [aggr.to_string() for aggr in api_response.get_child_by_name(
  1519. 'attributes-list').get_children()],
  1520. [aggr.to_string() for aggr in result])
  1521. def test_get_aggregates_not_found(self):
  1522. api_response = netapp_api.NaElement(fake.NO_RECORDS_RESPONSE)
  1523. self.mock_object(self.client,
  1524. 'send_iter_request',
  1525. mock.Mock(return_value=api_response))
  1526. result = self.client._get_aggregates()
  1527. self.client.send_iter_request.assert_has_calls([
  1528. mock.call('aggr-get-iter', {})])
  1529. self.assertListEqual([], result)
  1530. def test_get_performance_instance_uuids(self):
  1531. api_response = netapp_api.NaElement(
  1532. fake.PERF_OBJECT_INSTANCE_LIST_INFO_ITER_RESPONSE)
  1533. self.mock_object(self.client,
  1534. 'send_request',
  1535. mock.Mock(return_value=api_response))
  1536. result = self.client.get_performance_instance_uuids(
  1537. 'system', fake.NODE_NAME)
  1538. expected = [fake.NODE_NAME + ':kernel:system']
  1539. self.assertEqual(expected, result)
  1540. perf_object_instance_list_info_iter_args = {
  1541. 'objectname': 'system',
  1542. 'query': {
  1543. 'instance-info': {
  1544. 'uuid': fake.NODE_NAME + ':*',
  1545. }
  1546. }
  1547. }
  1548. self.client.send_request.assert_called_once_with(
  1549. 'perf-object-instance-list-info-iter',
  1550. perf_object_instance_list_info_iter_args)
  1551. def test_get_performance_counter_info(self):
  1552. api_response = netapp_api.NaElement(
  1553. fake.PERF_OBJECT_COUNTER_LIST_INFO_WAFL_RESPONSE)
  1554. self.mock_object(self.client,
  1555. 'send_request',
  1556. mock.Mock(return_value=api_response))
  1557. result = self.client.get_performance_counter_info('wafl',
  1558. 'cp_phase_times')
  1559. expected = {
  1560. 'name': 'cp_phase_times',
  1561. 'base-counter': 'total_cp_msecs',
  1562. 'labels': fake.PERF_OBJECT_COUNTER_TOTAL_CP_MSECS_LABELS,
  1563. }
  1564. self.assertEqual(expected, result)
  1565. perf_object_counter_list_info_args = {'objectname': 'wafl'}
  1566. self.client.send_request.assert_called_once_with(
  1567. 'perf-object-counter-list-info',
  1568. perf_object_counter_list_info_args)
  1569. def test_get_performance_counter_info_not_found(self):
  1570. api_response = netapp_api.NaElement(
  1571. fake.PERF_OBJECT_COUNTER_LIST_INFO_WAFL_RESPONSE)
  1572. self.mock_object(self.client,
  1573. 'send_request',
  1574. mock.Mock(return_value=api_response))
  1575. self.assertRaises(exception.NotFound,
  1576. self.client.get_performance_counter_info,
  1577. 'wafl',
  1578. 'invalid')
  1579. def test_get_performance_counters(self):
  1580. api_response = netapp_api.NaElement(
  1581. fake.PERF_OBJECT_GET_INSTANCES_SYSTEM_RESPONSE_CMODE)
  1582. self.mock_object(self.client,
  1583. 'send_request',
  1584. mock.Mock(return_value=api_response))
  1585. instance_uuids = [
  1586. fake.NODE_NAMES[0] + ':kernel:system',
  1587. fake.NODE_NAMES[1] + ':kernel:system',
  1588. ]
  1589. counter_names = ['avg_processor_busy']
  1590. result = self.client.get_performance_counters('system',
  1591. instance_uuids,
  1592. counter_names)
  1593. expected = [
  1594. {
  1595. 'avg_processor_busy': '5674745133134',
  1596. 'instance-name': 'system',
  1597. 'instance-uuid': instance_uuids[0],
  1598. 'node-name': fake.NODE_NAMES[0],
  1599. 'timestamp': '1453412013',
  1600. }, {
  1601. 'avg_processor_busy': '4077649009234',
  1602. 'instance-name': 'system',
  1603. 'instance-uuid': instance_uuids[1],
  1604. 'node-name': fake.NODE_NAMES[1],
  1605. 'timestamp': '1453412013'
  1606. },
  1607. ]
  1608. self.assertEqual(expected, result)
  1609. perf_object_get_instances_args = {
  1610. 'objectname': 'system',
  1611. 'instance-uuids': [
  1612. {'instance-uuid': instance_uuid}
  1613. for instance_uuid in instance_uuids
  1614. ],
  1615. 'counters': [
  1616. {'counter': counter} for counter in counter_names
  1617. ],
  1618. }
  1619. self.client.send_request.assert_called_once_with(
  1620. 'perf-object-get-instances', perf_object_get_instances_args)
  1621. def test_setup_security_services_ldap(self):
  1622. self.mock_object(self.client, 'send_request')
  1623. self.mock_object(self.vserver_client, 'configure_ldap')
  1624. self.client.setup_security_services([fake.LDAP_SECURITY_SERVICE],
  1625. self.vserver_client,
  1626. fake.VSERVER_NAME)
  1627. vserver_modify_args = {
  1628. 'name-mapping-switch': [
  1629. {'nmswitch': 'ldap'},
  1630. {'nmswitch': 'file'},
  1631. ],
  1632. 'name-server-switch': [
  1633. {'nsswitch': 'ldap'},
  1634. {'nsswitch': 'file'},
  1635. ],
  1636. 'vserver-name': fake.VSERVER_NAME
  1637. }
  1638. self.client.send_request.assert_has_calls([
  1639. mock.call('vserver-modify', vserver_modify_args)])
  1640. self.vserver_client.configure_ldap.assert_has_calls([
  1641. mock.call(fake.LDAP_SECURITY_SERVICE)])
  1642. def test_setup_security_services_active_directory(self):
  1643. self.mock_object(self.client, 'send_request')
  1644. self.mock_object(self.vserver_client, 'configure_active_directory')
  1645. self.client.setup_security_services([fake.CIFS_SECURITY_SERVICE],
  1646. self.vserver_client,
  1647. fake.VSERVER_NAME)
  1648. vserver_modify_args = {
  1649. 'name-mapping-switch': [
  1650. {'nmswitch': 'ldap'},
  1651. {'nmswitch': 'file'},
  1652. ],
  1653. 'name-server-switch': [
  1654. {'nsswitch': 'ldap'},
  1655. {'nsswitch': 'file'},
  1656. ],
  1657. 'vserver-name': fake.VSERVER_NAME
  1658. }
  1659. self.client.send_request.assert_has_calls([
  1660. mock.call('vserver-modify', vserver_modify_args)])
  1661. self.vserver_client.configure_active_directory.assert_has_calls([
  1662. mock.call(fake.CIFS_SECURITY_SERVICE, fake.VSERVER_NAME)])
  1663. def test_setup_security_services_kerberos(self):
  1664. self.mock_object(self.client, 'send_request')
  1665. self.mock_object(self.client, 'create_kerberos_realm')
  1666. self.mock_object(self.vserver_client, 'configure_kerberos')
  1667. self.client.setup_security_services([fake.KERBEROS_SECURITY_SERVICE],
  1668. self.vserver_client,
  1669. fake.VSERVER_NAME)
  1670. vserver_modify_args = {
  1671. 'name-mapping-switch': [
  1672. {'nmswitch': 'ldap'},
  1673. {'nmswitch': 'file'},
  1674. ],
  1675. 'name-server-switch': [
  1676. {'nsswitch': 'ldap'},
  1677. {'nsswitch': 'file'},
  1678. ],
  1679. 'vserver-name': fake.VSERVER_NAME
  1680. }
  1681. self.client.send_request.assert_has_calls([
  1682. mock.call('vserver-modify', vserver_modify_args)])
  1683. self.client.create_kerberos_realm.assert_has_calls([
  1684. mock.call(fake.KERBEROS_SECURITY_SERVICE)])
  1685. self.vserver_client.configure_kerberos.assert_has_calls([
  1686. mock.call(fake.KERBEROS_SECURITY_SERVICE, fake.VSERVER_NAME)])
  1687. def test_setup_security_services_invalid(self):
  1688. self.mock_object(self.client, 'send_request')
  1689. self.assertRaises(exception.NetAppException,
  1690. self.client.setup_security_services,
  1691. [fake.INVALID_SECURITY_SERVICE],
  1692. self.vserver_client,
  1693. fake.VSERVER_NAME)
  1694. vserver_modify_args = {
  1695. 'name-mapping-switch': [
  1696. {'nmswitch': 'ldap'},
  1697. {'nmswitch': 'file'},
  1698. ],
  1699. 'name-server-switch': [
  1700. {'nsswitch': 'ldap'},
  1701. {'nsswitch': 'file'},
  1702. ],
  1703. 'vserver-name': fake.VSERVER_NAME
  1704. }
  1705. self.client.send_request.assert_has_calls([
  1706. mock.call('vserver-modify', vserver_modify_args)])
  1707. def test_enable_nfs(self):
  1708. self.mock_object(self.client, 'send_request')
  1709. self.mock_object(self.client, '_enable_nfs_protocols')
  1710. self.mock_object(self.client, '_create_default_nfs_export_rule')
  1711. self.client.enable_nfs(fake.NFS_VERSIONS)
  1712. self.client.send_request.assert_called_once_with('nfs-enable')
  1713. self.client._enable_nfs_protocols.assert_called_once_with(
  1714. fake.NFS_VERSIONS)
  1715. self.client._create_default_nfs_export_rule.assert_called_once_with()
  1716. @ddt.data((True, True, True), (True, False, False), (False, True, True))
  1717. @ddt.unpack
  1718. def test_enable_nfs_protocols(self, v3, v40, v41):
  1719. self.mock_object(self.client, 'send_request')
  1720. versions = []
  1721. if v3:
  1722. versions.append('nfs3')
  1723. if v40:
  1724. versions.append('nfs4.0')
  1725. if v41:
  1726. versions.append('nfs4.1')
  1727. self.client._enable_nfs_protocols(versions)
  1728. nfs_service_modify_args = {
  1729. 'is-nfsv3-enabled': 'true' if v3 else 'false',
  1730. 'is-nfsv40-enabled': 'true' if v40 else 'false',
  1731. 'is-nfsv41-enabled': 'true' if v41 else 'false',
  1732. }
  1733. self.client.send_request.assert_called_once_with(
  1734. 'nfs-service-modify', nfs_service_modify_args)
  1735. def test_create_default_nfs_export_rule(self):
  1736. self.mock_object(self.client, 'send_request')
  1737. self.client._create_default_nfs_export_rule()
  1738. export_rule_create_args = {
  1739. 'client-match': '0.0.0.0/0',
  1740. 'policy-name': 'default',
  1741. 'ro-rule': {
  1742. 'security-flavor': 'any'
  1743. },
  1744. 'rw-rule': {
  1745. 'security-flavor': 'never'
  1746. }
  1747. }
  1748. self.client.send_request.assert_called_once_with(
  1749. 'export-rule-create', export_rule_create_args)
  1750. def test_configure_ldap(self):
  1751. self.mock_object(self.client, 'send_request')
  1752. self.client.configure_ldap(fake.LDAP_SECURITY_SERVICE)
  1753. config_name = hashlib.md5(
  1754. six.b(fake.LDAP_SECURITY_SERVICE['id'])).hexdigest()
  1755. ldap_client_create_args = {
  1756. 'ldap-client-config': config_name,
  1757. 'servers': {'ip-address': fake.LDAP_SECURITY_SERVICE['server']},
  1758. 'tcp-port': '389',
  1759. 'schema': 'RFC-2307',
  1760. 'bind-password': fake.LDAP_SECURITY_SERVICE['password']
  1761. }
  1762. ldap_config_create_args = {
  1763. 'client-config': config_name,
  1764. 'client-enabled': 'true'
  1765. }
  1766. self.client.send_request.assert_has_calls([
  1767. mock.call('ldap-client-create', ldap_client_create_args),
  1768. mock.call('ldap-config-create', ldap_config_create_args)])
  1769. def test_configure_active_directory(self):
  1770. self.mock_object(self.client, 'send_request')
  1771. self.mock_object(self.client, 'configure_dns')
  1772. self.client.configure_active_directory(fake.CIFS_SECURITY_SERVICE,
  1773. fake.VSERVER_NAME)
  1774. cifs_server = (
  1775. fake.VSERVER_NAME[0:7] + '..' + fake.VSERVER_NAME[-6:]).upper()
  1776. cifs_server_create_args = {
  1777. 'admin-username': fake.CIFS_SECURITY_SERVICE['user'],
  1778. 'admin-password': fake.CIFS_SECURITY_SERVICE['password'],
  1779. 'force-account-overwrite': 'true',
  1780. 'cifs-server': cifs_server,
  1781. 'domain': fake.CIFS_SECURITY_SERVICE['domain'],
  1782. }
  1783. self.client.configure_dns.assert_called_with(
  1784. fake.CIFS_SECURITY_SERVICE)
  1785. self.client.send_request.assert_has_calls([
  1786. mock.call('cifs-server-create', cifs_server_create_args)])
  1787. def test_configure_active_directory_api_error(self):
  1788. self.mock_object(self.client, 'send_request', self._mock_api_error())
  1789. self.mock_object(self.client, 'configure_dns')
  1790. self.assertRaises(exception.NetAppException,
  1791. self.client.configure_active_directory,
  1792. fake.CIFS_SECURITY_SERVICE,
  1793. fake.VSERVER_NAME)
  1794. def test_create_kerberos_realm(self):
  1795. self.mock_object(self.client, 'send_request')
  1796. self.client.create_kerberos_realm(fake.KERBEROS_SECURITY_SERVICE)
  1797. kerberos_realm_create_args = {
  1798. 'admin-server-ip': fake.KERBEROS_SECURITY_SERVICE['server'],
  1799. 'admin-server-port': '749',
  1800. 'clock-skew': '5',
  1801. 'comment': '',
  1802. 'config-name': fake.KERBEROS_SECURITY_SERVICE['id'],
  1803. 'kdc-ip': fake.KERBEROS_SECURITY_SERVICE['server'],
  1804. 'kdc-port': '88',
  1805. 'kdc-vendor': 'other',
  1806. 'password-server-ip': fake.KERBEROS_SECURITY_SERVICE['server'],
  1807. 'password-server-port': '464',
  1808. 'realm': fake.KERBEROS_SECURITY_SERVICE['domain'].upper()
  1809. }
  1810. self.client.send_request.assert_has_calls([
  1811. mock.call('kerberos-realm-create', kerberos_realm_create_args)])
  1812. def test_create_kerberos_realm_already_present(self):
  1813. self.mock_object(self.client,
  1814. 'send_request',
  1815. self._mock_api_error(code=netapp_api.EDUPLICATEENTRY))
  1816. self.client.create_kerberos_realm(fake.KERBEROS_SECURITY_SERVICE)
  1817. kerberos_realm_create_args = {
  1818. 'admin-server-ip': fake.KERBEROS_SECURITY_SERVICE['server'],
  1819. 'admin-server-port': '749',
  1820. 'clock-skew': '5',
  1821. 'comment': '',
  1822. 'config-name': fake.KERBEROS_SECURITY_SERVICE['id'],
  1823. 'kdc-ip': fake.KERBEROS_SECURITY_SERVICE['server'],
  1824. 'kdc-port': '88',
  1825. 'kdc-vendor': 'other',
  1826. 'password-server-ip': fake.KERBEROS_SECURITY_SERVICE['server'],
  1827. 'password-server-port': '464',
  1828. 'realm': fake.KERBEROS_SECURITY_SERVICE['domain'].upper()
  1829. }
  1830. self.client.send_request.assert_has_calls([
  1831. mock.call('kerberos-realm-create', kerberos_realm_create_args)])
  1832. self.assertEqual(1, client_cmode.LOG.debug.call_count)
  1833. def test_create_kerberos_realm_api_error(self):
  1834. self.mock_object(self.client, 'send_request', self._mock_api_error())
  1835. self.assertRaises(exception.NetAppException,
  1836. self.client.create_kerberos_realm,
  1837. fake.KERBEROS_SECURITY_SERVICE)
  1838. def test_configure_kerberos(self):
  1839. self.mock_object(self.client, 'send_request')
  1840. self.mock_object(self.client, 'configure_dns')
  1841. self.mock_object(self.client,
  1842. 'list_network_interfaces',
  1843. mock.Mock(return_value=['lif1', 'lif2']))
  1844. self.client.configure_kerberos(
  1845. fake.KERBEROS_SECURITY_SERVICE, fake.VSERVER_NAME)
  1846. spn = self.client._get_kerberos_service_principal_name(
  1847. fake.KERBEROS_SECURITY_SERVICE, fake.VSERVER_NAME)
  1848. kerberos_config_modify_args1 = {
  1849. 'admin-password': fake.KERBEROS_SECURITY_SERVICE['password'],
  1850. 'admin-user-name': fake.KERBEROS_SECURITY_SERVICE['user'],
  1851. 'interface-name': 'lif1',
  1852. 'is-kerberos-enabled': 'true',
  1853. 'service-principal-name': spn
  1854. }
  1855. kerberos_config_modify_args2 = {
  1856. 'admin-password': fake.KERBEROS_SECURITY_SERVICE['password'],
  1857. 'admin-user-name': fake.KERBEROS_SECURITY_SERVICE['user'],
  1858. 'interface-name': 'lif2',
  1859. 'is-kerberos-enabled': 'true',
  1860. 'service-principal-name': spn
  1861. }
  1862. self.client.configure_dns.assert_called_with(
  1863. fake.KERBEROS_SECURITY_SERVICE)
  1864. self.client.send_request.assert_has_calls([
  1865. mock.call('kerberos-config-modify',
  1866. kerberos_config_modify_args1),
  1867. mock.call('kerberos-config-modify',
  1868. kerberos_config_modify_args2)])
  1869. def test_configure_kerberos_no_network_interfaces(self):
  1870. self.mock_object(self.client, 'send_request')
  1871. self.mock_object(self.client, 'configure_dns')
  1872. self.mock_object(self.client,
  1873. 'list_network_interfaces',
  1874. mock.Mock(return_value=[]))
  1875. self.assertRaises(exception.NetAppException,
  1876. self.client.configure_kerberos,
  1877. fake.KERBEROS_SECURITY_SERVICE,
  1878. fake.VSERVER_NAME)
  1879. self.client.configure_dns.assert_called_with(
  1880. fake.KERBEROS_SECURITY_SERVICE)
  1881. def test_get_kerberos_service_principal_name(self):
  1882. spn = self.client._get_kerberos_service_principal_name(
  1883. fake.KERBEROS_SECURITY_SERVICE, fake.VSERVER_NAME
  1884. )
  1885. self.assertEqual(fake.KERBEROS_SERVICE_PRINCIPAL_NAME, spn)
  1886. def test_configure_dns_for_active_directory(self):
  1887. self.mock_object(self.client, 'send_request')
  1888. self.client.configure_dns(fake.CIFS_SECURITY_SERVICE)
  1889. net_dns_create_args = {
  1890. 'domains': {'string': fake.CIFS_SECURITY_SERVICE['domain']},
  1891. 'name-servers': {
  1892. 'ip-address': fake.CIFS_SECURITY_SERVICE['dns_ip']
  1893. },
  1894. 'dns-state': 'enabled'
  1895. }
  1896. self.client.send_request.assert_has_calls([
  1897. mock.call('net-dns-create', net_dns_create_args)])
  1898. def test_configure_dns_for_kerberos(self):
  1899. self.mock_object(self.client, 'send_request')
  1900. self.client.configure_dns(fake.KERBEROS_SECURITY_SERVICE)
  1901. net_dns_create_args = {
  1902. 'domains': {'string': fake.KERBEROS_SECURITY_SERVICE['domain']},
  1903. 'name-servers': {
  1904. 'ip-address': fake.KERBEROS_SECURITY_SERVICE['dns_ip']
  1905. },
  1906. 'dns-state': 'enabled'
  1907. }
  1908. self.client.send_request.assert_has_calls([
  1909. mock.call('net-dns-create', net_dns_create_args)])
  1910. def test_configure_dns_already_present(self):
  1911. self.mock_object(self.client,
  1912. 'send_request',
  1913. self._mock_api_error(code=netapp_api.EDUPLICATEENTRY))
  1914. self.client.configure_dns(fake.KERBEROS_SECURITY_SERVICE)
  1915. net_dns_create_args = {
  1916. 'domains': {'string': fake.KERBEROS_SECURITY_SERVICE['domain']},
  1917. 'name-servers': {
  1918. 'ip-address': fake.KERBEROS_SECURITY_SERVICE['dns_ip']
  1919. },
  1920. 'dns-state': 'enabled'
  1921. }
  1922. self.client.send_request.assert_has_calls([
  1923. mock.call('net-dns-create', net_dns_create_args)])
  1924. self.assertEqual(1, client_cmode.LOG.error.call_count)
  1925. def test_configure_dns_api_error(self):
  1926. self.mock_object(self.client, 'send_request', self._mock_api_error())
  1927. self.assertRaises(exception.NetAppException,
  1928. self.client.configure_dns,
  1929. fake.KERBEROS_SECURITY_SERVICE)
  1930. def test_create_volume(self):
  1931. self.mock_object(self.client, 'send_request')
  1932. self.client.create_volume(
  1933. fake.SHARE_AGGREGATE_NAME, fake.SHARE_NAME, 100)
  1934. volume_create_args = {
  1935. 'containing-aggr-name': fake.SHARE_AGGREGATE_NAME,
  1936. 'size': '100g',
  1937. 'volume': fake.SHARE_NAME,
  1938. 'volume-type': 'rw',
  1939. 'junction-path': '/%s' % fake.SHARE_NAME,
  1940. }
  1941. self.client.send_request.assert_called_once_with('volume-create',
  1942. volume_create_args)
  1943. def test_create_volume_with_extra_specs(self):
  1944. self.mock_object(self.client, 'set_volume_max_files')
  1945. self.mock_object(self.client, 'enable_dedup')
  1946. self.mock_object(self.client, 'enable_compression')
  1947. self.mock_object(self.client, 'send_request')
  1948. self.client.create_volume(
  1949. fake.SHARE_AGGREGATE_NAME, fake.SHARE_NAME, 100,
  1950. thin_provisioned=True, language='en-US',
  1951. snapshot_policy='default', dedup_enabled=True,
  1952. compression_enabled=True, max_files=5000, snapshot_reserve=15)
  1953. volume_create_args = {
  1954. 'containing-aggr-name': fake.SHARE_AGGREGATE_NAME,
  1955. 'size': '100g',
  1956. 'volume': fake.SHARE_NAME,
  1957. 'junction-path': '/%s' % fake.SHARE_NAME,
  1958. 'space-reserve': 'none',
  1959. 'language-code': 'en-US',
  1960. 'volume-type': 'rw',
  1961. 'snapshot-policy': 'default',
  1962. 'percentage-snapshot-reserve': '15',
  1963. }
  1964. self.client.send_request.assert_called_with('volume-create',
  1965. volume_create_args)
  1966. self.client.set_volume_max_files.assert_called_once_with(
  1967. fake.SHARE_NAME, fake.MAX_FILES)
  1968. self.client.enable_dedup.assert_called_once_with(fake.SHARE_NAME)
  1969. self.client.enable_compression.assert_called_once_with(fake.SHARE_NAME)
  1970. def test_enable_dedup(self):
  1971. self.mock_object(self.client, 'send_request')
  1972. self.client.enable_dedup(fake.SHARE_NAME)
  1973. sis_enable_args = {'path': '/vol/%s' % fake.SHARE_NAME}
  1974. self.client.send_request.assert_called_once_with('sis-enable',
  1975. sis_enable_args)
  1976. def test_disable_dedup(self):
  1977. self.mock_object(self.client, 'send_request')
  1978. self.client.disable_dedup(fake.SHARE_NAME)
  1979. sis_disable_args = {'path': '/vol/%s' % fake.SHARE_NAME}
  1980. self.client.send_request.assert_called_once_with('sis-disable',
  1981. sis_disable_args)
  1982. def test_enable_compression(self):
  1983. self.mock_object(self.client, 'send_request')
  1984. self.client.enable_compression(fake.SHARE_NAME)
  1985. sis_set_config_args = {
  1986. 'path': '/vol/%s' % fake.SHARE_NAME,
  1987. 'enable-compression': 'true'
  1988. }
  1989. self.client.send_request.assert_called_once_with('sis-set-config',
  1990. sis_set_config_args)
  1991. def test_disable_compression(self):
  1992. self.mock_object(self.client, 'send_request')
  1993. self.client.disable_compression(fake.SHARE_NAME)
  1994. sis_set_config_args = {
  1995. 'path': '/vol/%s' % fake.SHARE_NAME,
  1996. 'enable-compression': 'false'
  1997. }
  1998. self.client.send_request.assert_called_once_with('sis-set-config',
  1999. sis_set_config_args)
  2000. def test_get_volume_efficiency_status(self):
  2001. api_response = netapp_api.NaElement(fake.SIS_GET_ITER_RESPONSE)
  2002. self.mock_object(self.client,
  2003. 'send_iter_request',
  2004. mock.Mock(return_value=api_response))
  2005. result = self.client.get_volume_efficiency_status(fake.SHARE_NAME)
  2006. sis_get_iter_args = {
  2007. 'query': {
  2008. 'sis-status-info': {
  2009. 'path': '/vol/%s' % fake.SHARE_NAME,
  2010. },
  2011. },
  2012. 'desired-attributes': {
  2013. 'sis-status-info': {
  2014. 'state': None,
  2015. 'is-compression-enabled': None,
  2016. },
  2017. },
  2018. }
  2019. self.client.send_iter_request.assert_has_calls([
  2020. mock.call('sis-get-iter', sis_get_iter_args)])
  2021. expected = {'dedupe': True, 'compression': True}
  2022. self.assertDictEqual(expected, result)
  2023. def test_get_volume_efficiency_status_not_found(self):
  2024. api_response = netapp_api.NaElement(fake.NO_RECORDS_RESPONSE)
  2025. self.mock_object(self.client,
  2026. 'send_iter_request',
  2027. mock.Mock(return_value=api_response))
  2028. result = self.client.get_volume_efficiency_status(fake.SHARE_NAME)
  2029. expected = {'dedupe': False, 'compression': False}
  2030. self.assertDictEqual(expected, result)
  2031. def test_set_volume_max_files(self):
  2032. self.mock_object(self.client, 'send_request')
  2033. self.client.set_volume_max_files(fake.SHARE_NAME, fake.MAX_FILES)
  2034. volume_modify_iter_api_args = {
  2035. 'query': {
  2036. 'volume-attributes': {
  2037. 'volume-id-attributes': {
  2038. 'name': fake.SHARE_NAME,
  2039. },
  2040. },
  2041. },
  2042. 'attributes': {
  2043. 'volume-attributes': {
  2044. 'volume-inode-attributes': {
  2045. 'files-total': fake.MAX_FILES,
  2046. },
  2047. },
  2048. },
  2049. }
  2050. self.client.send_request.assert_called_once_with(
  2051. 'volume-modify-iter', volume_modify_iter_api_args)
  2052. def test_set_volume_name(self):
  2053. self.mock_object(self.client, 'send_request')
  2054. self.client.set_volume_name(fake.SHARE_NAME, 'new_name')
  2055. volume_rename_api_args = {
  2056. 'volume': fake.SHARE_NAME,
  2057. 'new-volume-name': 'new_name',
  2058. }
  2059. self.client.send_request.assert_called_once_with(
  2060. 'volume-rename', volume_rename_api_args)
  2061. def test_manage_volume_no_optional_args(self):
  2062. self.mock_object(self.client, 'send_request')
  2063. mock_update_volume_efficiency_attributes = self.mock_object(
  2064. self.client, 'update_volume_efficiency_attributes')
  2065. self.client.manage_volume(fake.SHARE_AGGREGATE_NAME, fake.SHARE_NAME)
  2066. volume_modify_iter_api_args = {
  2067. 'query': {
  2068. 'volume-attributes': {
  2069. 'volume-id-attributes': {
  2070. 'containing-aggregate-name': fake.SHARE_AGGREGATE_NAME,
  2071. 'name': fake.SHARE_NAME,
  2072. },
  2073. },
  2074. },
  2075. 'attributes': {
  2076. 'volume-attributes': {
  2077. 'volume-inode-attributes': {},
  2078. 'volume-language-attributes': {},
  2079. 'volume-snapshot-attributes': {},
  2080. 'volume-space-attributes': {
  2081. 'space-guarantee': 'volume',
  2082. },
  2083. },
  2084. },
  2085. }
  2086. self.client.send_request.assert_called_once_with(
  2087. 'volume-modify-iter', volume_modify_iter_api_args)
  2088. mock_update_volume_efficiency_attributes.assert_called_once_with(
  2089. fake.SHARE_NAME, False, False)
  2090. def test_manage_volume_all_optional_args(self):
  2091. self.mock_object(self.client, 'send_request')
  2092. mock_update_volume_efficiency_attributes = self.mock_object(
  2093. self.client, 'update_volume_efficiency_attributes')
  2094. self.client.manage_volume(fake.SHARE_AGGREGATE_NAME,
  2095. fake.SHARE_NAME,
  2096. thin_provisioned=True,
  2097. snapshot_policy=fake.SNAPSHOT_POLICY_NAME,
  2098. language=fake.LANGUAGE,
  2099. dedup_enabled=True,
  2100. compression_enabled=False,
  2101. max_files=fake.MAX_FILES)
  2102. volume_modify_iter_api_args = {
  2103. 'query': {
  2104. 'volume-attributes': {
  2105. 'volume-id-attributes': {
  2106. 'containing-aggregate-name': fake.SHARE_AGGREGATE_NAME,
  2107. 'name': fake.SHARE_NAME,
  2108. },
  2109. },
  2110. },
  2111. 'attributes': {
  2112. 'volume-attributes': {
  2113. 'volume-inode-attributes': {
  2114. 'files-total': fake.MAX_FILES,
  2115. },
  2116. 'volume-language-attributes': {
  2117. 'language': fake.LANGUAGE,
  2118. },
  2119. 'volume-snapshot-attributes': {
  2120. 'snapshot-policy': fake.SNAPSHOT_POLICY_NAME,
  2121. },
  2122. 'volume-space-attributes': {
  2123. 'space-guarantee': 'none',
  2124. },
  2125. },
  2126. },
  2127. }
  2128. self.client.send_request.assert_called_once_with(
  2129. 'volume-modify-iter', volume_modify_iter_api_args)
  2130. mock_update_volume_efficiency_attributes.assert_called_once_with(
  2131. fake.SHARE_NAME, True, False)
  2132. @ddt.data(
  2133. {'existing': (True, True), 'desired': (True, True)},
  2134. {'existing': (True, True), 'desired': (False, False)},
  2135. {'existing': (True, True), 'desired': (True, False)},
  2136. {'existing': (True, False), 'desired': (True, False)},
  2137. {'existing': (True, False), 'desired': (False, False)},
  2138. {'existing': (True, False), 'desired': (True, True)},
  2139. {'existing': (False, False), 'desired': (False, False)},
  2140. {'existing': (False, False), 'desired': (True, False)},
  2141. {'existing': (False, False), 'desired': (True, True)},
  2142. )
  2143. @ddt.unpack
  2144. def test_update_volume_efficiency_attributes(self, existing, desired):
  2145. existing_dedupe = existing[0]
  2146. existing_compression = existing[1]
  2147. desired_dedupe = desired[0]
  2148. desired_compression = desired[1]
  2149. self.mock_object(
  2150. self.client,
  2151. 'get_volume_efficiency_status',
  2152. mock.Mock(return_value={'dedupe': existing_dedupe,
  2153. 'compression': existing_compression}))
  2154. mock_enable_compression = self.mock_object(self.client,
  2155. 'enable_compression')
  2156. mock_disable_compression = self.mock_object(self.client,
  2157. 'disable_compression')
  2158. mock_enable_dedup = self.mock_object(self.client, 'enable_dedup')
  2159. mock_disable_dedup = self.mock_object(self.client, 'disable_dedup')
  2160. self.client.update_volume_efficiency_attributes(
  2161. fake.SHARE_NAME, desired_dedupe, desired_compression)
  2162. if existing_dedupe == desired_dedupe:
  2163. self.assertFalse(mock_enable_dedup.called)
  2164. self.assertFalse(mock_disable_dedup.called)
  2165. elif existing_dedupe and not desired_dedupe:
  2166. self.assertFalse(mock_enable_dedup.called)
  2167. self.assertTrue(mock_disable_dedup.called)
  2168. elif not existing_dedupe and desired_dedupe:
  2169. self.assertTrue(mock_enable_dedup.called)
  2170. self.assertFalse(mock_disable_dedup.called)
  2171. if existing_compression == desired_compression:
  2172. self.assertFalse(mock_enable_compression.called)
  2173. self.assertFalse(mock_disable_compression.called)
  2174. elif existing_compression and not desired_compression:
  2175. self.assertFalse(mock_enable_compression.called)
  2176. self.assertTrue(mock_disable_compression.called)
  2177. elif not existing_compression and desired_compression:
  2178. self.assertTrue(mock_enable_compression.called)
  2179. self.assertFalse(mock_disable_compression.called)
  2180. def test_set_volume_size(self):
  2181. api_response = netapp_api.NaElement(fake.VOLUME_MODIFY_ITER_RESPONSE)
  2182. self.mock_object(self.client,
  2183. 'send_request',
  2184. mock.Mock(return_value=api_response))
  2185. self.client.set_volume_size(fake.SHARE_NAME, 10)
  2186. volume_modify_iter_args = {
  2187. 'query': {
  2188. 'volume-attributes': {
  2189. 'volume-id-attributes': {
  2190. 'name': fake.SHARE_NAME
  2191. }
  2192. }
  2193. },
  2194. 'attributes': {
  2195. 'volume-attributes': {
  2196. 'volume-space-attributes': {
  2197. 'size': 10737418240,
  2198. },
  2199. },
  2200. },
  2201. }
  2202. self.client.send_request.assert_has_calls([
  2203. mock.call('volume-modify-iter', volume_modify_iter_args)])
  2204. def test_set_volume_size_api_error(self):
  2205. api_response = netapp_api.NaElement(
  2206. fake.VOLUME_MODIFY_ITER_ERROR_RESPONSE)
  2207. self.mock_object(self.client,
  2208. 'send_request',
  2209. mock.Mock(return_value=api_response))
  2210. self.assertRaises(netapp_api.NaApiError,
  2211. self.client.set_volume_size,
  2212. fake.SHARE_NAME,
  2213. 10)
  2214. def test_volume_exists(self):
  2215. api_response = netapp_api.NaElement(fake.VOLUME_GET_NAME_RESPONSE)
  2216. self.mock_object(self.client,
  2217. 'send_iter_request',
  2218. mock.Mock(return_value=api_response))
  2219. result = self.client.volume_exists(fake.SHARE_NAME)
  2220. volume_get_iter_args = {
  2221. 'query': {
  2222. 'volume-attributes': {
  2223. 'volume-id-attributes': {
  2224. 'name': fake.SHARE_NAME
  2225. }
  2226. }
  2227. },
  2228. 'desired-attributes': {
  2229. 'volume-attributes': {
  2230. 'volume-id-attributes': {
  2231. 'name': None
  2232. }
  2233. }
  2234. }
  2235. }
  2236. self.client.send_iter_request.assert_has_calls([
  2237. mock.call('volume-get-iter', volume_get_iter_args)])
  2238. self.assertTrue(result)
  2239. def test_volume_exists_not_found(self):
  2240. api_response = netapp_api.NaElement(fake.NO_RECORDS_RESPONSE)
  2241. self.mock_object(self.client,
  2242. 'send_request',
  2243. mock.Mock(return_value=api_response))
  2244. self.assertFalse(self.client.volume_exists(fake.SHARE_NAME))
  2245. def test_snapshot_exists(self):
  2246. api_response = netapp_api.NaElement(fake.VOLUME_GET_NAME_RESPONSE)
  2247. self.mock_object(self.client,
  2248. 'send_request',
  2249. mock.Mock(return_value=api_response))
  2250. result = self.client.snapshot_exists(fake.SNAPSHOT_NAME,
  2251. fake.SHARE_NAME)
  2252. snapshot_get_iter_args = {
  2253. 'query': {
  2254. 'snapshot-info': {
  2255. 'name': fake.SNAPSHOT_NAME,
  2256. 'volume': fake.SHARE_NAME,
  2257. }
  2258. },
  2259. 'desired-attributes': {
  2260. 'snapshot-info': {
  2261. 'name': None,
  2262. 'volume': None,
  2263. 'busy': None,
  2264. 'snapshot-owners-list': {
  2265. 'snapshot-owner': None,
  2266. }
  2267. }
  2268. }
  2269. }
  2270. self.client.send_request.assert_has_calls([
  2271. mock.call('snapshot-get-iter', snapshot_get_iter_args)])
  2272. self.assertTrue(result)
  2273. def test_snapshot_exists_not_found(self):
  2274. api_response = netapp_api.NaElement(fake.NO_RECORDS_RESPONSE)
  2275. self.mock_object(self.client,
  2276. 'send_request',
  2277. mock.Mock(return_value=api_response))
  2278. self.assertFalse(self.client.snapshot_exists(fake.SNAPSHOT_NAME,
  2279. fake.SHARE_NAME))
  2280. @ddt.data({
  2281. 'api_response_xml': fake.SNAPSHOT_GET_ITER_UNAVAILABLE_RESPONSE,
  2282. 'raised_exception': exception.SnapshotUnavailable,
  2283. }, {
  2284. 'api_response_xml': fake.SNAPSHOT_GET_ITER_OTHER_ERROR_RESPONSE,
  2285. 'raised_exception': exception.NetAppException,
  2286. })
  2287. @ddt.unpack
  2288. def test_snapshot_exists_error(self, api_response_xml, raised_exception):
  2289. api_response = netapp_api.NaElement(api_response_xml)
  2290. self.mock_object(self.client,
  2291. 'send_request',
  2292. mock.Mock(return_value=api_response))
  2293. self.assertRaises(raised_exception,
  2294. self.client.snapshot_exists,
  2295. fake.SNAPSHOT_NAME,
  2296. fake.SHARE_NAME)
  2297. def test_get_aggregate_for_volume(self):
  2298. api_response = netapp_api.NaElement(
  2299. fake.GET_AGGREGATE_FOR_VOLUME_RESPONSE)
  2300. self.mock_object(self.client,
  2301. 'send_iter_request',
  2302. mock.Mock(return_value=api_response))
  2303. result = self.client.get_aggregate_for_volume(fake.SHARE_NAME)
  2304. volume_get_iter_args = {
  2305. 'query': {
  2306. 'volume-attributes': {
  2307. 'volume-id-attributes': {
  2308. 'name': fake.SHARE_NAME
  2309. }
  2310. }
  2311. },
  2312. 'desired-attributes': {
  2313. 'volume-attributes': {
  2314. 'volume-id-attributes': {
  2315. 'containing-aggregate-name': None,
  2316. 'name': None
  2317. }
  2318. }
  2319. }
  2320. }
  2321. self.client.send_iter_request.assert_has_calls([
  2322. mock.call('volume-get-iter', volume_get_iter_args)])
  2323. self.assertEqual(fake.SHARE_AGGREGATE_NAME, result)
  2324. def test_get_aggregate_for_volume_not_found(self):
  2325. api_response = netapp_api.NaElement(fake.NO_RECORDS_RESPONSE)
  2326. self.mock_object(self.client,
  2327. 'send_iter_request',
  2328. mock.Mock(return_value=api_response))
  2329. self.assertRaises(exception.NetAppException,
  2330. self.client.get_aggregate_for_volume,
  2331. fake.SHARE_NAME)
  2332. def test_volume_has_luns(self):
  2333. api_response = netapp_api.NaElement(fake.LUN_GET_ITER_RESPONSE)
  2334. self.mock_object(self.client,
  2335. 'send_iter_request',
  2336. mock.Mock(return_value=api_response))
  2337. result = self.client.volume_has_luns(fake.SHARE_NAME)
  2338. lun_get_iter_args = {
  2339. 'query': {
  2340. 'lun-info': {
  2341. 'volume': fake.SHARE_NAME,
  2342. },
  2343. },
  2344. 'desired-attributes': {
  2345. 'lun-info': {
  2346. 'path': None,
  2347. },
  2348. },
  2349. }
  2350. self.client.send_iter_request.assert_has_calls([
  2351. mock.call('lun-get-iter', lun_get_iter_args)])
  2352. self.assertTrue(result)
  2353. def test_volume_has_luns_not_found(self):
  2354. api_response = netapp_api.NaElement(fake.NO_RECORDS_RESPONSE)
  2355. self.mock_object(self.client,
  2356. 'send_request',
  2357. mock.Mock(return_value=api_response))
  2358. result = self.client.volume_has_luns(fake.SHARE_NAME)
  2359. self.assertFalse(result)
  2360. def test_volume_has_junctioned_volumes(self):
  2361. api_response = netapp_api.NaElement(
  2362. fake.VOLUME_GET_ITER_JUNCTIONED_VOLUMES_RESPONSE)
  2363. self.mock_object(self.client,
  2364. 'send_iter_request',
  2365. mock.Mock(return_value=api_response))
  2366. fake_junction_path = '/%s' % fake.SHARE_NAME
  2367. self.mock_object(self.client,
  2368. 'get_volume_junction_path',
  2369. mock.Mock(return_value=fake_junction_path))
  2370. result = self.client.volume_has_junctioned_volumes(fake.SHARE_NAME)
  2371. volume_get_iter_args = {
  2372. 'query': {
  2373. 'volume-attributes': {
  2374. 'volume-id-attributes': {
  2375. 'junction-path': fake_junction_path + '/*',
  2376. },
  2377. },
  2378. },
  2379. 'desired-attributes': {
  2380. 'volume-attributes': {
  2381. 'volume-id-attributes': {
  2382. 'name': None,
  2383. },
  2384. },
  2385. },
  2386. }
  2387. self.client.send_iter_request.assert_has_calls([
  2388. mock.call('volume-get-iter', volume_get_iter_args)])
  2389. self.assertTrue(result)
  2390. def test_volume_has_junctioned_volumes_no_junction_path(self):
  2391. self.mock_object(self.client,
  2392. 'get_volume_junction_path',
  2393. mock.Mock(return_value=''))
  2394. result = self.client.volume_has_junctioned_volumes(fake.SHARE_NAME)
  2395. self.assertFalse(result)
  2396. def test_volume_has_junctioned_volumes_not_found(self):
  2397. api_response = netapp_api.NaElement(fake.NO_RECORDS_RESPONSE)
  2398. self.mock_object(self.client,
  2399. 'send_request',
  2400. mock.Mock(return_value=api_response))
  2401. fake_junction_path = '/%s' % fake.SHARE_NAME
  2402. self.mock_object(self.client,
  2403. 'get_volume_junction_path',
  2404. mock.Mock(return_value=fake_junction_path))
  2405. result = self.client.volume_has_junctioned_volumes(fake.SHARE_NAME)
  2406. self.assertFalse(result)
  2407. def test_get_volume(self):
  2408. api_response = netapp_api.NaElement(
  2409. fake.VOLUME_GET_ITER_VOLUME_TO_MANAGE_RESPONSE)
  2410. self.mock_object(self.client,
  2411. 'send_request',
  2412. mock.Mock(return_value=api_response))
  2413. result = self.client.get_volume(fake.SHARE_NAME)
  2414. volume_get_iter_args = {
  2415. 'query': {
  2416. 'volume-attributes': {
  2417. 'volume-id-attributes': {
  2418. 'name': fake.SHARE_NAME,
  2419. },
  2420. },
  2421. },
  2422. 'desired-attributes': {
  2423. 'volume-attributes': {
  2424. 'volume-id-attributes': {
  2425. 'containing-aggregate-name': None,
  2426. 'junction-path': None,
  2427. 'name': None,
  2428. 'owning-vserver-name': None,
  2429. 'type': None,
  2430. 'style': None,
  2431. },
  2432. 'volume-space-attributes': {
  2433. 'size': None,
  2434. }
  2435. },
  2436. },
  2437. }
  2438. expected = {
  2439. 'aggregate': fake.SHARE_AGGREGATE_NAME,
  2440. 'junction-path': '/%s' % fake.SHARE_NAME,
  2441. 'name': fake.SHARE_NAME,
  2442. 'type': 'rw',
  2443. 'style': 'flex',
  2444. 'size': fake.SHARE_SIZE,
  2445. 'owning-vserver-name': fake.VSERVER_NAME,
  2446. }
  2447. self.client.send_request.assert_has_calls([
  2448. mock.call('volume-get-iter', volume_get_iter_args)])
  2449. self.assertDictEqual(expected, result)
  2450. def test_get_volume_not_found(self):
  2451. api_response = netapp_api.NaElement(fake.NO_RECORDS_RESPONSE)
  2452. self.mock_object(self.client,
  2453. 'send_request',
  2454. mock.Mock(return_value=api_response))
  2455. self.assertRaises(exception.StorageResourceNotFound,
  2456. self.client.get_volume,
  2457. fake.SHARE_NAME)
  2458. def test_get_volume_not_unique(self):
  2459. api_response = netapp_api.NaElement(
  2460. fake.VOLUME_GET_ITER_NOT_UNIQUE_RESPONSE)
  2461. self.mock_object(self.client,
  2462. 'send_request',
  2463. mock.Mock(return_value=api_response))
  2464. self.assertRaises(exception.NetAppException,
  2465. self.client.get_volume,
  2466. fake.SHARE_NAME)
  2467. def test_get_volume_at_junction_path(self):
  2468. api_response = netapp_api.NaElement(
  2469. fake.VOLUME_GET_ITER_VOLUME_TO_MANAGE_RESPONSE)
  2470. self.mock_object(self.client,
  2471. 'send_iter_request',
  2472. mock.Mock(return_value=api_response))
  2473. fake_junction_path = '/%s' % fake.SHARE_NAME
  2474. result = self.client.get_volume_at_junction_path(fake_junction_path)
  2475. volume_get_iter_args = {
  2476. 'query': {
  2477. 'volume-attributes': {
  2478. 'volume-id-attributes': {
  2479. 'junction-path': fake_junction_path,
  2480. },
  2481. },
  2482. },
  2483. 'desired-attributes': {
  2484. 'volume-attributes': {
  2485. 'volume-id-attributes': {
  2486. 'containing-aggregate-name': None,
  2487. 'junction-path': None,
  2488. 'name': None,
  2489. 'type': None,
  2490. 'style': None,
  2491. },
  2492. 'volume-space-attributes': {
  2493. 'size': None,
  2494. }
  2495. },
  2496. },
  2497. }
  2498. expected = {
  2499. 'aggregate': fake.SHARE_AGGREGATE_NAME,
  2500. 'junction-path': fake_junction_path,
  2501. 'name': fake.SHARE_NAME,
  2502. 'type': 'rw',
  2503. 'style': 'flex',
  2504. 'size': fake.SHARE_SIZE,
  2505. }
  2506. self.client.send_iter_request.assert_has_calls([
  2507. mock.call('volume-get-iter', volume_get_iter_args)])
  2508. self.assertDictEqual(expected, result)
  2509. def test_get_volume_at_junction_path_not_specified(self):
  2510. result = self.client.get_volume_at_junction_path(None)
  2511. self.assertIsNone(result)
  2512. def test_get_volume_at_junction_path_not_found(self):
  2513. api_response = netapp_api.NaElement(fake.NO_RECORDS_RESPONSE)
  2514. self.mock_object(self.client,
  2515. 'send_iter_request',
  2516. mock.Mock(return_value=api_response))
  2517. fake_junction_path = '/%s' % fake.SHARE_NAME
  2518. result = self.client.get_volume_at_junction_path(fake_junction_path)
  2519. self.assertIsNone(result)
  2520. def test_get_volume_to_manage(self):
  2521. api_response = netapp_api.NaElement(
  2522. fake.VOLUME_GET_ITER_VOLUME_TO_MANAGE_RESPONSE)
  2523. self.mock_object(self.client,
  2524. 'send_iter_request',
  2525. mock.Mock(return_value=api_response))
  2526. result = self.client.get_volume_to_manage(fake.SHARE_AGGREGATE_NAME,
  2527. fake.SHARE_NAME)
  2528. volume_get_iter_args = {
  2529. 'query': {
  2530. 'volume-attributes': {
  2531. 'volume-id-attributes': {
  2532. 'containing-aggregate-name': fake.SHARE_AGGREGATE_NAME,
  2533. 'name': fake.SHARE_NAME,
  2534. },
  2535. },
  2536. },
  2537. 'desired-attributes': {
  2538. 'volume-attributes': {
  2539. 'volume-id-attributes': {
  2540. 'containing-aggregate-name': None,
  2541. 'junction-path': None,
  2542. 'name': None,
  2543. 'type': None,
  2544. 'style': None,
  2545. 'owning-vserver-name': None,
  2546. },
  2547. 'volume-space-attributes': {
  2548. 'size': None,
  2549. }
  2550. },
  2551. },
  2552. }
  2553. expected = {
  2554. 'aggregate': fake.SHARE_AGGREGATE_NAME,
  2555. 'junction-path': '/%s' % fake.SHARE_NAME,
  2556. 'name': fake.SHARE_NAME,
  2557. 'type': 'rw',
  2558. 'style': 'flex',
  2559. 'size': fake.SHARE_SIZE,
  2560. 'owning-vserver-name': fake.VSERVER_NAME
  2561. }
  2562. self.client.send_iter_request.assert_has_calls([
  2563. mock.call('volume-get-iter', volume_get_iter_args)])
  2564. self.assertDictEqual(expected, result)
  2565. def test_get_volume_to_manage_not_found(self):
  2566. api_response = netapp_api.NaElement(fake.NO_RECORDS_RESPONSE)
  2567. self.mock_object(self.client,
  2568. 'send_iter_request',
  2569. mock.Mock(return_value=api_response))
  2570. result = self.client.get_volume_to_manage(fake.SHARE_AGGREGATE_NAME,
  2571. fake.SHARE_NAME)
  2572. self.assertIsNone(result)
  2573. def test_create_volume_clone(self):
  2574. self.mock_object(self.client, 'send_request')
  2575. self.mock_object(self.client, 'split_volume_clone')
  2576. self.client.create_volume_clone(fake.SHARE_NAME,
  2577. fake.PARENT_SHARE_NAME,
  2578. fake.PARENT_SNAPSHOT_NAME)
  2579. volume_clone_create_args = {
  2580. 'volume': fake.SHARE_NAME,
  2581. 'parent-volume': fake.PARENT_SHARE_NAME,
  2582. 'parent-snapshot': fake.PARENT_SNAPSHOT_NAME,
  2583. 'junction-path': '/%s' % fake.SHARE_NAME
  2584. }
  2585. self.client.send_request.assert_has_calls([
  2586. mock.call('volume-clone-create', volume_clone_create_args)])
  2587. self.assertFalse(self.client.split_volume_clone.called)
  2588. @ddt.data(True, False)
  2589. def test_create_volume_clone_split(self, split):
  2590. self.mock_object(self.client, 'send_request')
  2591. self.mock_object(self.client, 'split_volume_clone')
  2592. self.client.create_volume_clone(fake.SHARE_NAME,
  2593. fake.PARENT_SHARE_NAME,
  2594. fake.PARENT_SNAPSHOT_NAME,
  2595. split=split)
  2596. volume_clone_create_args = {
  2597. 'volume': fake.SHARE_NAME,
  2598. 'parent-volume': fake.PARENT_SHARE_NAME,
  2599. 'parent-snapshot': fake.PARENT_SNAPSHOT_NAME,
  2600. 'junction-path': '/%s' % fake.SHARE_NAME
  2601. }
  2602. self.client.send_request.assert_has_calls([
  2603. mock.call('volume-clone-create', volume_clone_create_args)])
  2604. if split:
  2605. self.client.split_volume_clone.assert_called_once_with(
  2606. fake.SHARE_NAME)
  2607. else:
  2608. self.assertFalse(self.client.split_volume_clone.called)
  2609. @ddt.data(None,
  2610. mock.Mock(side_effect=netapp_api.NaApiError(
  2611. code=netapp_api.EVOL_CLONE_BEING_SPLIT)))
  2612. def test_split_volume_clone(self, side_effect):
  2613. self.mock_object(
  2614. self.client, 'send_request',
  2615. mock.Mock(side_effect=side_effect))
  2616. self.client.split_volume_clone(fake.SHARE_NAME)
  2617. volume_clone_split_args = {'volume': fake.SHARE_NAME}
  2618. self.client.send_request.assert_has_calls([
  2619. mock.call('volume-clone-split-start', volume_clone_split_args)])
  2620. def test_split_volume_clone_api_error(self):
  2621. self.mock_object(self.client,
  2622. 'send_request',
  2623. mock.Mock(side_effect=self._mock_api_error()))
  2624. self.assertRaises(netapp_api.NaApiError,
  2625. self.client.split_volume_clone,
  2626. fake.SHARE_NAME)
  2627. def test_get_clone_children_for_snapshot(self):
  2628. api_response = netapp_api.NaElement(
  2629. fake.VOLUME_GET_ITER_CLONE_CHILDREN_RESPONSE)
  2630. self.mock_object(self.client,
  2631. 'send_iter_request',
  2632. mock.Mock(return_value=api_response))
  2633. result = self.client.get_clone_children_for_snapshot(
  2634. fake.SHARE_NAME, fake.SNAPSHOT_NAME)
  2635. volume_get_iter_args = {
  2636. 'query': {
  2637. 'volume-attributes': {
  2638. 'volume-clone-attributes': {
  2639. 'volume-clone-parent-attributes': {
  2640. 'name': fake.SHARE_NAME,
  2641. 'snapshot-name': fake.SNAPSHOT_NAME,
  2642. },
  2643. },
  2644. },
  2645. },
  2646. 'desired-attributes': {
  2647. 'volume-attributes': {
  2648. 'volume-id-attributes': {
  2649. 'name': None,
  2650. },
  2651. },
  2652. },
  2653. }
  2654. self.client.send_iter_request.assert_has_calls([
  2655. mock.call('volume-get-iter', volume_get_iter_args)])
  2656. expected = [
  2657. {'name': fake.CLONE_CHILD_1},
  2658. {'name': fake.CLONE_CHILD_2},
  2659. ]
  2660. self.assertEqual(expected, result)
  2661. def test_get_clone_children_for_snapshot_not_found(self):
  2662. api_response = netapp_api.NaElement(fake.NO_RECORDS_RESPONSE)
  2663. self.mock_object(self.client,
  2664. 'send_iter_request',
  2665. mock.Mock(return_value=api_response))
  2666. result = self.client.get_clone_children_for_snapshot(
  2667. fake.SHARE_NAME, fake.SNAPSHOT_NAME)
  2668. self.assertEqual([], result)
  2669. def test_get_volume_junction_path(self):
  2670. api_response = netapp_api.NaElement(
  2671. fake.VOLUME_GET_VOLUME_PATH_RESPONSE)
  2672. self.mock_object(self.client,
  2673. 'send_request',
  2674. mock.Mock(return_value=api_response))
  2675. result = self.client.get_volume_junction_path(fake.SHARE_NAME)
  2676. volume_get_volume_path_args = {
  2677. 'volume': fake.SHARE_NAME,
  2678. 'is-style-cifs': 'false'
  2679. }
  2680. self.client.send_request.assert_has_calls([
  2681. mock.call('volume-get-volume-path', volume_get_volume_path_args)])
  2682. self.assertEqual(fake.VOLUME_JUNCTION_PATH, result)
  2683. def test_get_volume_junction_path_cifs(self):
  2684. api_response = netapp_api.NaElement(
  2685. fake.VOLUME_GET_VOLUME_PATH_CIFS_RESPONSE)
  2686. self.mock_object(self.client,
  2687. 'send_request',
  2688. mock.Mock(return_value=api_response))
  2689. result = self.client.get_volume_junction_path(fake.SHARE_NAME,
  2690. is_style_cifs=True)
  2691. volume_get_volume_path_args = {
  2692. 'volume': fake.SHARE_NAME,
  2693. 'is-style-cifs': 'true'
  2694. }
  2695. self.client.send_request.assert_has_calls([
  2696. mock.call('volume-get-volume-path', volume_get_volume_path_args)])
  2697. self.assertEqual(fake.VOLUME_JUNCTION_PATH_CIFS, result)
  2698. def test_mount_volume_default_junction_path(self):
  2699. self.mock_object(self.client, 'send_request')
  2700. self.client.mount_volume(fake.SHARE_NAME)
  2701. volume_mount_args = {
  2702. 'volume-name': fake.SHARE_NAME,
  2703. 'junction-path': '/%s' % fake.SHARE_NAME,
  2704. }
  2705. self.client.send_request.assert_has_calls([
  2706. mock.call('volume-mount', volume_mount_args)])
  2707. def test_mount_volume(self):
  2708. self.mock_object(self.client, 'send_request')
  2709. fake_path = '/fake_path'
  2710. self.client.mount_volume(fake.SHARE_NAME, junction_path=fake_path)
  2711. volume_mount_args = {
  2712. 'volume-name': fake.SHARE_NAME,
  2713. 'junction-path': fake_path,
  2714. }
  2715. self.client.send_request.assert_has_calls([
  2716. mock.call('volume-mount', volume_mount_args)])
  2717. def test_offline_volume(self):
  2718. self.mock_object(self.client, 'send_request')
  2719. self.client.offline_volume(fake.SHARE_NAME)
  2720. volume_offline_args = {'name': fake.SHARE_NAME}
  2721. self.client.send_request.assert_has_calls([
  2722. mock.call('volume-offline', volume_offline_args)])
  2723. def test_offline_volume_already_offline(self):
  2724. self.mock_object(self.client,
  2725. 'send_request',
  2726. mock.Mock(side_effect=self._mock_api_error(
  2727. netapp_api.EVOLUMEOFFLINE)))
  2728. self.client.offline_volume(fake.SHARE_NAME)
  2729. volume_offline_args = {'name': fake.SHARE_NAME}
  2730. self.client.send_request.assert_has_calls([
  2731. mock.call('volume-offline', volume_offline_args)])
  2732. def test_offline_volume_api_error(self):
  2733. self.mock_object(self.client,
  2734. 'send_request',
  2735. mock.Mock(side_effect=self._mock_api_error()))
  2736. self.assertRaises(netapp_api.NaApiError,
  2737. self.client.offline_volume,
  2738. fake.SHARE_NAME)
  2739. def test__unmount_volume(self):
  2740. self.mock_object(self.client, 'send_request')
  2741. self.client._unmount_volume(fake.SHARE_NAME)
  2742. volume_unmount_args = {
  2743. 'volume-name': fake.SHARE_NAME,
  2744. 'force': 'false'
  2745. }
  2746. self.client.send_request.assert_has_calls([
  2747. mock.call('volume-unmount', volume_unmount_args)])
  2748. def test__unmount_volume_force(self):
  2749. self.mock_object(self.client, 'send_request')
  2750. self.client._unmount_volume(fake.SHARE_NAME, force=True)
  2751. volume_unmount_args = {'volume-name': fake.SHARE_NAME, 'force': 'true'}
  2752. self.client.send_request.assert_has_calls([
  2753. mock.call('volume-unmount', volume_unmount_args)])
  2754. def test__unmount_volume_already_unmounted(self):
  2755. self.mock_object(self.client,
  2756. 'send_request',
  2757. mock.Mock(side_effect=self._mock_api_error(
  2758. netapp_api.EVOL_NOT_MOUNTED)))
  2759. self.client._unmount_volume(fake.SHARE_NAME, force=True)
  2760. volume_unmount_args = {'volume-name': fake.SHARE_NAME, 'force': 'true'}
  2761. self.client.send_request.assert_has_calls([
  2762. mock.call('volume-unmount', volume_unmount_args)])
  2763. def test__unmount_volume_api_error(self):
  2764. self.mock_object(self.client,
  2765. 'send_request',
  2766. mock.Mock(side_effect=self._mock_api_error()))
  2767. self.assertRaises(netapp_api.NaApiError,
  2768. self.client._unmount_volume,
  2769. fake.SHARE_NAME,
  2770. force=True)
  2771. def test_unmount_volume(self):
  2772. self.mock_object(self.client, '_unmount_volume')
  2773. self.client.unmount_volume(fake.SHARE_NAME)
  2774. self.client._unmount_volume.assert_called_once_with(fake.SHARE_NAME,
  2775. force=False)
  2776. self.assertEqual(1, client_cmode.LOG.debug.call_count)
  2777. self.assertEqual(0, client_cmode.LOG.warning.call_count)
  2778. def test_unmount_volume_api_error(self):
  2779. self.mock_object(self.client,
  2780. '_unmount_volume',
  2781. self._mock_api_error())
  2782. self.assertRaises(netapp_api.NaApiError,
  2783. self.client.unmount_volume,
  2784. fake.SHARE_NAME)
  2785. self.assertEqual(1, self.client._unmount_volume.call_count)
  2786. self.assertEqual(0, client_cmode.LOG.debug.call_count)
  2787. self.assertEqual(0, client_cmode.LOG.warning.call_count)
  2788. def test_unmount_volume_with_retries(self):
  2789. side_effect = [netapp_api.NaApiError(code=netapp_api.EAPIERROR,
  2790. message='...job ID...')] * 5
  2791. side_effect.append(None)
  2792. self.mock_object(self.client,
  2793. '_unmount_volume',
  2794. mock.Mock(side_effect=side_effect))
  2795. self.mock_object(time, 'sleep')
  2796. self.client.unmount_volume(fake.SHARE_NAME)
  2797. self.assertEqual(6, self.client._unmount_volume.call_count)
  2798. self.assertEqual(1, client_cmode.LOG.debug.call_count)
  2799. self.assertEqual(5, client_cmode.LOG.warning.call_count)
  2800. def test_unmount_volume_with_max_retries(self):
  2801. side_effect = [netapp_api.NaApiError(code=netapp_api.EAPIERROR,
  2802. message='...job ID...')] * 30
  2803. self.mock_object(self.client,
  2804. '_unmount_volume',
  2805. mock.Mock(side_effect=side_effect))
  2806. self.mock_object(time, 'sleep')
  2807. self.assertRaises(exception.NetAppException,
  2808. self.client.unmount_volume,
  2809. fake.SHARE_NAME)
  2810. self.assertEqual(10, self.client._unmount_volume.call_count)
  2811. self.assertEqual(0, client_cmode.LOG.debug.call_count)
  2812. self.assertEqual(10, client_cmode.LOG.warning.call_count)
  2813. def test_delete_volume(self):
  2814. self.mock_object(self.client, 'send_request')
  2815. self.client.delete_volume(fake.SHARE_NAME)
  2816. volume_destroy_args = {'name': fake.SHARE_NAME}
  2817. self.client.send_request.assert_has_calls([
  2818. mock.call('volume-destroy', volume_destroy_args)])
  2819. def test_create_snapshot(self):
  2820. self.mock_object(self.client, 'send_request')
  2821. self.client.create_snapshot(fake.SHARE_NAME, fake.SNAPSHOT_NAME)
  2822. snapshot_create_args = {
  2823. 'volume': fake.SHARE_NAME,
  2824. 'snapshot': fake.SNAPSHOT_NAME
  2825. }
  2826. self.client.send_request.assert_has_calls([
  2827. mock.call('snapshot-create', snapshot_create_args)])
  2828. @ddt.data({
  2829. 'mock_return': fake.SNAPSHOT_GET_ITER_NOT_BUSY_RESPONSE,
  2830. 'expected': {
  2831. 'access-time': fake.SNAPSHOT_ACCESS_TIME,
  2832. 'name': fake.SNAPSHOT_NAME,
  2833. 'volume': fake.SHARE_NAME,
  2834. 'busy': False,
  2835. 'owners': set(),
  2836. }
  2837. }, {
  2838. 'mock_return': fake.SNAPSHOT_GET_ITER_BUSY_RESPONSE,
  2839. 'expected': {
  2840. 'access-time': fake.SNAPSHOT_ACCESS_TIME,
  2841. 'name': fake.SNAPSHOT_NAME,
  2842. 'volume': fake.SHARE_NAME,
  2843. 'busy': True,
  2844. 'owners': {'volume clone'},
  2845. }
  2846. })
  2847. @ddt.unpack
  2848. def test_get_snapshot(self, mock_return, expected):
  2849. api_response = netapp_api.NaElement(mock_return)
  2850. self.mock_object(self.client,
  2851. 'send_request',
  2852. mock.Mock(return_value=api_response))
  2853. result = self.client.get_snapshot(fake.SHARE_NAME, fake.SNAPSHOT_NAME)
  2854. snapshot_get_iter_args = {
  2855. 'query': {
  2856. 'snapshot-info': {
  2857. 'name': fake.SNAPSHOT_NAME,
  2858. 'volume': fake.SHARE_NAME,
  2859. },
  2860. },
  2861. 'desired-attributes': {
  2862. 'snapshot-info': {
  2863. 'access-time': None,
  2864. 'name': None,
  2865. 'volume': None,
  2866. 'busy': None,
  2867. 'snapshot-owners-list': {
  2868. 'snapshot-owner': None,
  2869. }
  2870. },
  2871. },
  2872. }
  2873. self.client.send_request.assert_has_calls([
  2874. mock.call('snapshot-get-iter', snapshot_get_iter_args)])
  2875. self.assertDictEqual(expected, result)
  2876. @ddt.data({
  2877. 'api_response_xml': fake.NO_RECORDS_RESPONSE,
  2878. 'raised_exception': exception.SnapshotResourceNotFound,
  2879. }, {
  2880. 'api_response_xml': fake.SNAPSHOT_GET_ITER_NOT_UNIQUE_RESPONSE,
  2881. 'raised_exception': exception.NetAppException,
  2882. }, {
  2883. 'api_response_xml': fake.SNAPSHOT_GET_ITER_UNAVAILABLE_RESPONSE,
  2884. 'raised_exception': exception.SnapshotUnavailable,
  2885. }, {
  2886. 'api_response_xml': fake.SNAPSHOT_GET_ITER_OTHER_ERROR_RESPONSE,
  2887. 'raised_exception': exception.NetAppException,
  2888. })
  2889. @ddt.unpack
  2890. def test_get_snapshot_error(self, api_response_xml, raised_exception):
  2891. api_response = netapp_api.NaElement(api_response_xml)
  2892. self.mock_object(self.client,
  2893. 'send_request',
  2894. mock.Mock(return_value=api_response))
  2895. self.assertRaises(raised_exception,
  2896. self.client.get_snapshot,
  2897. fake.SHARE_NAME,
  2898. fake.SNAPSHOT_NAME)
  2899. def test_rename_snapshot(self):
  2900. self.mock_object(self.client, 'send_request')
  2901. self.client.rename_snapshot(fake.SHARE_NAME,
  2902. fake.SNAPSHOT_NAME,
  2903. 'new_snapshot_name')
  2904. snapshot_rename_args = {
  2905. 'volume': fake.SHARE_NAME,
  2906. 'current-name': fake.SNAPSHOT_NAME,
  2907. 'new-name': 'new_snapshot_name'
  2908. }
  2909. self.client.send_request.assert_has_calls([
  2910. mock.call('snapshot-rename', snapshot_rename_args)])
  2911. def test_restore_snapshot(self):
  2912. self.mock_object(self.client, 'send_request')
  2913. self.client.restore_snapshot(fake.SHARE_NAME,
  2914. fake.SNAPSHOT_NAME)
  2915. snapshot_restore_args = {
  2916. 'volume': fake.SHARE_NAME,
  2917. 'snapshot': fake.SNAPSHOT_NAME,
  2918. }
  2919. self.client.send_request.assert_has_calls([
  2920. mock.call('snapshot-restore-volume', snapshot_restore_args)])
  2921. @ddt.data(True, False)
  2922. def test_delete_snapshot(self, ignore_owners):
  2923. self.mock_object(self.client, 'send_request')
  2924. self.client.delete_snapshot(
  2925. fake.SHARE_NAME, fake.SNAPSHOT_NAME, ignore_owners=ignore_owners)
  2926. snapshot_delete_args = {
  2927. 'volume': fake.SHARE_NAME,
  2928. 'snapshot': fake.SNAPSHOT_NAME,
  2929. 'ignore-owners': 'true' if ignore_owners else 'false',
  2930. }
  2931. self.client.send_request.assert_has_calls([
  2932. mock.call('snapshot-delete', snapshot_delete_args)])
  2933. def test_soft_delete_snapshot(self):
  2934. mock_delete_snapshot = self.mock_object(self.client, 'delete_snapshot')
  2935. mock_rename_snapshot = self.mock_object(self.client, 'rename_snapshot')
  2936. self.client.soft_delete_snapshot(fake.SHARE_NAME, fake.SNAPSHOT_NAME)
  2937. mock_delete_snapshot.assert_called_once_with(
  2938. fake.SHARE_NAME, fake.SNAPSHOT_NAME)
  2939. self.assertFalse(mock_rename_snapshot.called)
  2940. def test_soft_delete_snapshot_api_error(self):
  2941. mock_delete_snapshot = self.mock_object(
  2942. self.client, 'delete_snapshot', self._mock_api_error())
  2943. mock_rename_snapshot = self.mock_object(self.client, 'rename_snapshot')
  2944. self.client.soft_delete_snapshot(fake.SHARE_NAME, fake.SNAPSHOT_NAME)
  2945. mock_delete_snapshot.assert_called_once_with(
  2946. fake.SHARE_NAME, fake.SNAPSHOT_NAME)
  2947. mock_rename_snapshot.assert_called_once_with(
  2948. fake.SHARE_NAME, fake.SNAPSHOT_NAME,
  2949. 'deleted_manila_' + fake.SNAPSHOT_NAME)
  2950. def test_prune_deleted_snapshots(self):
  2951. deleted_snapshots_map = {
  2952. 'vserver1': [{
  2953. 'name': 'deleted_snap_1',
  2954. 'volume': 'fake_volume_1',
  2955. 'vserver': 'vserver1',
  2956. }],
  2957. 'vserver2': [{
  2958. 'name': 'deleted_snap_2',
  2959. 'volume': 'fake_volume_2',
  2960. 'vserver': 'vserver2',
  2961. }],
  2962. }
  2963. mock_get_deleted_snapshots = self.mock_object(
  2964. self.client, '_get_deleted_snapshots',
  2965. mock.Mock(return_value=deleted_snapshots_map))
  2966. mock_delete_snapshot = self.mock_object(
  2967. self.client, 'delete_snapshot',
  2968. mock.Mock(side_effect=[None, netapp_api.NaApiError]))
  2969. self.mock_object(
  2970. copy, 'deepcopy', mock.Mock(return_value=self.client))
  2971. self.client.prune_deleted_snapshots()
  2972. mock_get_deleted_snapshots.assert_called_once_with()
  2973. mock_delete_snapshot.assert_has_calls([
  2974. mock.call('fake_volume_1', 'deleted_snap_1'),
  2975. mock.call('fake_volume_2', 'deleted_snap_2'),
  2976. ], any_order=True)
  2977. def test_get_deleted_snapshots(self):
  2978. api_response = netapp_api.NaElement(
  2979. fake.SNAPSHOT_GET_ITER_DELETED_RESPONSE)
  2980. self.mock_object(self.client,
  2981. 'send_iter_request',
  2982. mock.Mock(return_value=api_response))
  2983. result = self.client._get_deleted_snapshots()
  2984. snapshot_get_iter_args = {
  2985. 'query': {
  2986. 'snapshot-info': {
  2987. 'name': 'deleted_manila_*',
  2988. 'busy': 'false',
  2989. },
  2990. },
  2991. 'desired-attributes': {
  2992. 'snapshot-info': {
  2993. 'name': None,
  2994. 'vserver': None,
  2995. 'volume': None,
  2996. },
  2997. },
  2998. }
  2999. self.client.send_iter_request.assert_has_calls([
  3000. mock.call('snapshot-get-iter', snapshot_get_iter_args)])
  3001. expected = {
  3002. fake.VSERVER_NAME: [{
  3003. 'name': 'deleted_manila_' + fake.SNAPSHOT_NAME,
  3004. 'volume': fake.SHARE_NAME,
  3005. 'vserver': fake.VSERVER_NAME,
  3006. }],
  3007. }
  3008. self.assertDictEqual(expected, result)
  3009. def test_create_cg_snapshot(self):
  3010. mock_start_cg_snapshot = self.mock_object(
  3011. self.client, '_start_cg_snapshot',
  3012. mock.Mock(return_value=fake.CG_SNAPSHOT_ID))
  3013. mock_commit_cg_snapshot = self.mock_object(
  3014. self.client, '_commit_cg_snapshot')
  3015. self.client.create_cg_snapshot([fake.SHARE_NAME, fake.SHARE_NAME_2],
  3016. fake.SNAPSHOT_NAME)
  3017. mock_start_cg_snapshot.assert_called_once_with(
  3018. [fake.SHARE_NAME, fake.SHARE_NAME_2], fake.SNAPSHOT_NAME)
  3019. mock_commit_cg_snapshot.assert_called_once_with(fake.CG_SNAPSHOT_ID)
  3020. def test_create_cg_snapshot_no_id(self):
  3021. mock_start_cg_snapshot = self.mock_object(
  3022. self.client, '_start_cg_snapshot', mock.Mock(return_value=None))
  3023. mock_commit_cg_snapshot = self.mock_object(
  3024. self.client, '_commit_cg_snapshot')
  3025. self.assertRaises(exception.NetAppException,
  3026. self.client.create_cg_snapshot,
  3027. [fake.SHARE_NAME, fake.SHARE_NAME_2],
  3028. fake.SNAPSHOT_NAME)
  3029. mock_start_cg_snapshot.assert_called_once_with(
  3030. [fake.SHARE_NAME, fake.SHARE_NAME_2], fake.SNAPSHOT_NAME)
  3031. self.assertFalse(mock_commit_cg_snapshot.called)
  3032. def test_start_cg_snapshot(self):
  3033. self.mock_object(self.client, 'send_request')
  3034. self.client._start_cg_snapshot([fake.SHARE_NAME, fake.SHARE_NAME_2],
  3035. fake.SNAPSHOT_NAME)
  3036. cg_start_args = {
  3037. 'snapshot': fake.SNAPSHOT_NAME,
  3038. 'timeout': 'relaxed',
  3039. 'volumes': [
  3040. {'volume-name': fake.SHARE_NAME},
  3041. {'volume-name': fake.SHARE_NAME_2},
  3042. ],
  3043. }
  3044. self.client.send_request.assert_has_calls([
  3045. mock.call('cg-start', cg_start_args)])
  3046. def test_commit_cg_snapshot(self):
  3047. self.mock_object(self.client, 'send_request')
  3048. self.client._commit_cg_snapshot(fake.CG_SNAPSHOT_ID)
  3049. cg_commit_args = {'cg-id': fake.CG_SNAPSHOT_ID}
  3050. self.client.send_request.assert_has_calls([
  3051. mock.call('cg-commit', cg_commit_args)])
  3052. def test_create_cifs_share(self):
  3053. self.mock_object(self.client, 'send_request')
  3054. self.client.create_cifs_share(fake.SHARE_NAME)
  3055. cifs_share_create_args = {
  3056. 'path': '/%s' % fake.SHARE_NAME,
  3057. 'share-name': fake.SHARE_NAME
  3058. }
  3059. self.client.send_request.assert_has_calls([
  3060. mock.call('cifs-share-create', cifs_share_create_args)])
  3061. def test_get_cifs_share_access(self):
  3062. api_response = netapp_api.NaElement(
  3063. fake.CIFS_SHARE_ACCESS_CONTROL_GET_ITER)
  3064. self.mock_object(self.client,
  3065. 'send_iter_request',
  3066. mock.Mock(return_value=api_response))
  3067. result = self.client.get_cifs_share_access(fake.SHARE_NAME)
  3068. cifs_share_access_control_get_iter_args = {
  3069. 'query': {
  3070. 'cifs-share-access-control': {
  3071. 'share': fake.SHARE_NAME,
  3072. },
  3073. },
  3074. 'desired-attributes': {
  3075. 'cifs-share-access-control': {
  3076. 'user-or-group': None,
  3077. 'permission': None,
  3078. },
  3079. },
  3080. }
  3081. self.client.send_iter_request.assert_has_calls([
  3082. mock.call('cifs-share-access-control-get-iter',
  3083. cifs_share_access_control_get_iter_args)])
  3084. expected = {
  3085. 'Administrator': 'full_control',
  3086. 'Administrators': 'change',
  3087. 'Power Users': 'read',
  3088. 'Users': 'no_access',
  3089. }
  3090. self.assertDictEqual(expected, result)
  3091. def test_get_cifs_share_access_not_found(self):
  3092. api_response = netapp_api.NaElement(fake.NO_RECORDS_RESPONSE)
  3093. self.mock_object(self.client,
  3094. 'send_iter_request',
  3095. mock.Mock(return_value=api_response))
  3096. result = self.client.get_cifs_share_access(fake.SHARE_NAME)
  3097. self.assertEqual({}, result)
  3098. @ddt.data(True, False)
  3099. def test_add_cifs_share_access(self, readonly):
  3100. self.mock_object(self.client, 'send_request')
  3101. self.client.add_cifs_share_access(fake.SHARE_NAME,
  3102. fake.USER_NAME,
  3103. readonly)
  3104. cifs_share_access_control_create_args = {
  3105. 'permission': 'read' if readonly else 'full_control',
  3106. 'share': fake.SHARE_NAME,
  3107. 'user-or-group': fake.USER_NAME
  3108. }
  3109. self.client.send_request.assert_has_calls([
  3110. mock.call(
  3111. 'cifs-share-access-control-create',
  3112. cifs_share_access_control_create_args)])
  3113. @ddt.data(True, False)
  3114. def test_modify_cifs_share_access(self, readonly):
  3115. self.mock_object(self.client, 'send_request')
  3116. self.client.modify_cifs_share_access(fake.SHARE_NAME,
  3117. fake.USER_NAME,
  3118. readonly)
  3119. cifs_share_access_control_modify_args = {
  3120. 'permission': 'read' if readonly else 'full_control',
  3121. 'share': fake.SHARE_NAME,
  3122. 'user-or-group': fake.USER_NAME
  3123. }
  3124. self.client.send_request.assert_has_calls([
  3125. mock.call(
  3126. 'cifs-share-access-control-modify',
  3127. cifs_share_access_control_modify_args)])
  3128. def test_remove_cifs_share_access(self):
  3129. self.mock_object(self.client, 'send_request')
  3130. self.client.remove_cifs_share_access(fake.SHARE_NAME, fake.USER_NAME)
  3131. cifs_share_access_control_delete_args = {
  3132. 'user-or-group': fake.USER_NAME,
  3133. 'share': fake.SHARE_NAME
  3134. }
  3135. self.client.send_request.assert_has_calls([
  3136. mock.call(
  3137. 'cifs-share-access-control-delete',
  3138. cifs_share_access_control_delete_args)])
  3139. def test_remove_cifs_share(self):
  3140. self.mock_object(self.client, 'send_request')
  3141. self.client.remove_cifs_share(fake.SHARE_NAME)
  3142. cifs_share_delete_args = {'share-name': fake.SHARE_NAME}
  3143. self.client.send_request.assert_has_calls([
  3144. mock.call('cifs-share-delete', cifs_share_delete_args)])
  3145. def test_add_nfs_export_rule(self):
  3146. mock_get_nfs_export_rule_indices = self.mock_object(
  3147. self.client, '_get_nfs_export_rule_indices',
  3148. mock.Mock(return_value=[]))
  3149. mock_add_nfs_export_rule = self.mock_object(
  3150. self.client, '_add_nfs_export_rule')
  3151. mock_update_nfs_export_rule = self.mock_object(
  3152. self.client, '_update_nfs_export_rule')
  3153. self.client.add_nfs_export_rule(fake.EXPORT_POLICY_NAME,
  3154. fake.IP_ADDRESS,
  3155. False)
  3156. mock_get_nfs_export_rule_indices.assert_called_once_with(
  3157. fake.EXPORT_POLICY_NAME, fake.IP_ADDRESS)
  3158. mock_add_nfs_export_rule.assert_called_once_with(
  3159. fake.EXPORT_POLICY_NAME, fake.IP_ADDRESS, False)
  3160. self.assertFalse(mock_update_nfs_export_rule.called)
  3161. def test_add_nfs_export_rule_single_existing(self):
  3162. mock_get_nfs_export_rule_indices = self.mock_object(
  3163. self.client, '_get_nfs_export_rule_indices',
  3164. mock.Mock(return_value=['1']))
  3165. mock_add_nfs_export_rule = self.mock_object(
  3166. self.client, '_add_nfs_export_rule')
  3167. mock_update_nfs_export_rule = self.mock_object(
  3168. self.client, '_update_nfs_export_rule')
  3169. mock_remove_nfs_export_rules = self.mock_object(
  3170. self.client, '_remove_nfs_export_rules')
  3171. self.client.add_nfs_export_rule(fake.EXPORT_POLICY_NAME,
  3172. fake.IP_ADDRESS,
  3173. False)
  3174. mock_get_nfs_export_rule_indices.assert_called_once_with(
  3175. fake.EXPORT_POLICY_NAME, fake.IP_ADDRESS)
  3176. self.assertFalse(mock_add_nfs_export_rule.called)
  3177. mock_update_nfs_export_rule.assert_called_once_with(
  3178. fake.EXPORT_POLICY_NAME, fake.IP_ADDRESS, False, '1')
  3179. mock_remove_nfs_export_rules.assert_called_once_with(
  3180. fake.EXPORT_POLICY_NAME, [])
  3181. def test_add_nfs_export_rule_multiple_existing(self):
  3182. mock_get_nfs_export_rule_indices = self.mock_object(
  3183. self.client, '_get_nfs_export_rule_indices',
  3184. mock.Mock(return_value=['2', '4', '6']))
  3185. mock_add_nfs_export_rule = self.mock_object(
  3186. self.client, '_add_nfs_export_rule')
  3187. mock_update_nfs_export_rule = self.mock_object(
  3188. self.client, '_update_nfs_export_rule')
  3189. mock_remove_nfs_export_rules = self.mock_object(
  3190. self.client, '_remove_nfs_export_rules')
  3191. self.client.add_nfs_export_rule(fake.EXPORT_POLICY_NAME,
  3192. fake.IP_ADDRESS,
  3193. False)
  3194. mock_get_nfs_export_rule_indices.assert_called_once_with(
  3195. fake.EXPORT_POLICY_NAME, fake.IP_ADDRESS)
  3196. self.assertFalse(mock_add_nfs_export_rule.called)
  3197. mock_update_nfs_export_rule.assert_called_once_with(
  3198. fake.EXPORT_POLICY_NAME, fake.IP_ADDRESS, False, '2')
  3199. mock_remove_nfs_export_rules.assert_called_once_with(
  3200. fake.EXPORT_POLICY_NAME, ['4', '6'])
  3201. @ddt.data({'readonly': False, 'rw_security_flavor': 'sys'},
  3202. {'readonly': True, 'rw_security_flavor': 'never'})
  3203. @ddt.unpack
  3204. def test__add_nfs_export_rule(self, readonly, rw_security_flavor):
  3205. self.mock_object(self.client, 'send_request')
  3206. self.client._add_nfs_export_rule(fake.EXPORT_POLICY_NAME,
  3207. fake.IP_ADDRESS,
  3208. readonly)
  3209. export_rule_create_args = {
  3210. 'policy-name': fake.EXPORT_POLICY_NAME,
  3211. 'client-match': fake.IP_ADDRESS,
  3212. 'ro-rule': {
  3213. 'security-flavor': 'sys',
  3214. },
  3215. 'rw-rule': {
  3216. 'security-flavor': rw_security_flavor,
  3217. },
  3218. 'super-user-security': {
  3219. 'security-flavor': 'sys',
  3220. },
  3221. }
  3222. self.client.send_request.assert_has_calls(
  3223. [mock.call('export-rule-create', export_rule_create_args)])
  3224. @ddt.data({'readonly': False, 'rw_security_flavor': 'sys', 'index': '2'},
  3225. {'readonly': True, 'rw_security_flavor': 'never', 'index': '4'})
  3226. @ddt.unpack
  3227. def test_update_nfs_export_rule(self, readonly, rw_security_flavor, index):
  3228. self.mock_object(self.client, 'send_request')
  3229. self.client._update_nfs_export_rule(fake.EXPORT_POLICY_NAME,
  3230. fake.IP_ADDRESS,
  3231. readonly,
  3232. index)
  3233. export_rule_modify_args = {
  3234. 'policy-name': fake.EXPORT_POLICY_NAME,
  3235. 'rule-index': index,
  3236. 'client-match': fake.IP_ADDRESS,
  3237. 'ro-rule': {
  3238. 'security-flavor': 'sys',
  3239. },
  3240. 'rw-rule': {
  3241. 'security-flavor': rw_security_flavor,
  3242. },
  3243. 'super-user-security': {
  3244. 'security-flavor': 'sys',
  3245. },
  3246. }
  3247. self.client.send_request.assert_has_calls(
  3248. [mock.call('export-rule-modify', export_rule_modify_args)])
  3249. def test_get_nfs_export_rule_indices(self):
  3250. api_response = netapp_api.NaElement(fake.EXPORT_RULE_GET_ITER_RESPONSE)
  3251. self.mock_object(self.client,
  3252. 'send_iter_request',
  3253. mock.Mock(return_value=api_response))
  3254. result = self.client._get_nfs_export_rule_indices(
  3255. fake.EXPORT_POLICY_NAME, fake.IP_ADDRESS)
  3256. export_rule_get_iter_args = {
  3257. 'query': {
  3258. 'export-rule-info': {
  3259. 'policy-name': fake.EXPORT_POLICY_NAME,
  3260. 'client-match': fake.IP_ADDRESS,
  3261. },
  3262. },
  3263. 'desired-attributes': {
  3264. 'export-rule-info': {
  3265. 'vserver-name': None,
  3266. 'policy-name': None,
  3267. 'client-match': None,
  3268. 'rule-index': None,
  3269. },
  3270. },
  3271. }
  3272. self.assertListEqual(['1', '3'], result)
  3273. self.client.send_iter_request.assert_has_calls([
  3274. mock.call('export-rule-get-iter', export_rule_get_iter_args)])
  3275. def test_remove_nfs_export_rule(self):
  3276. fake_indices = ['1', '3', '4']
  3277. mock_get_nfs_export_rule_indices = self.mock_object(
  3278. self.client, '_get_nfs_export_rule_indices',
  3279. mock.Mock(return_value=fake_indices))
  3280. mock_remove_nfs_export_rules = self.mock_object(
  3281. self.client, '_remove_nfs_export_rules')
  3282. self.client.remove_nfs_export_rule(fake.EXPORT_POLICY_NAME,
  3283. fake.IP_ADDRESS)
  3284. mock_get_nfs_export_rule_indices.assert_called_once_with(
  3285. fake.EXPORT_POLICY_NAME, fake.IP_ADDRESS)
  3286. mock_remove_nfs_export_rules.assert_called_once_with(
  3287. fake.EXPORT_POLICY_NAME, fake_indices)
  3288. def test_remove_nfs_export_rules(self):
  3289. fake_indices = ['1', '3']
  3290. self.mock_object(self.client, 'send_request')
  3291. self.client._remove_nfs_export_rules(fake.EXPORT_POLICY_NAME,
  3292. fake_indices)
  3293. self.client.send_request.assert_has_calls([
  3294. mock.call(
  3295. 'export-rule-destroy',
  3296. {'policy-name': fake.EXPORT_POLICY_NAME, 'rule-index': '1'}),
  3297. mock.call(
  3298. 'export-rule-destroy',
  3299. {'policy-name': fake.EXPORT_POLICY_NAME, 'rule-index': '3'})])
  3300. def test_remove_nfs_export_rules_not_found(self):
  3301. self.mock_object(self.client,
  3302. 'send_request',
  3303. self._mock_api_error(code=netapp_api.EOBJECTNOTFOUND))
  3304. self.client._remove_nfs_export_rules(fake.EXPORT_POLICY_NAME, ['1'])
  3305. self.client.send_request.assert_has_calls([
  3306. mock.call(
  3307. 'export-rule-destroy',
  3308. {'policy-name': fake.EXPORT_POLICY_NAME, 'rule-index': '1'})])
  3309. def test_remove_nfs_export_rules_api_error(self):
  3310. self.mock_object(self.client, 'send_request', self._mock_api_error())
  3311. self.assertRaises(netapp_api.NaApiError,
  3312. self.client._remove_nfs_export_rules,
  3313. fake.EXPORT_POLICY_NAME,
  3314. ['1'])
  3315. def test_clear_nfs_export_policy_for_volume(self):
  3316. mock_set_nfs_export_policy_for_volume = self.mock_object(
  3317. self.client, 'set_nfs_export_policy_for_volume')
  3318. self.client.clear_nfs_export_policy_for_volume(fake.SHARE_NAME)
  3319. mock_set_nfs_export_policy_for_volume.assert_called_once_with(
  3320. fake.SHARE_NAME, 'default')
  3321. def test_set_nfs_export_policy_for_volume(self):
  3322. self.mock_object(self.client, 'send_request')
  3323. self.client.set_nfs_export_policy_for_volume(fake.SHARE_NAME,
  3324. fake.EXPORT_POLICY_NAME)
  3325. volume_modify_iter_args = {
  3326. 'query': {
  3327. 'volume-attributes': {
  3328. 'volume-id-attributes': {
  3329. 'name': fake.SHARE_NAME,
  3330. },
  3331. },
  3332. },
  3333. 'attributes': {
  3334. 'volume-attributes': {
  3335. 'volume-export-attributes': {
  3336. 'policy': fake.EXPORT_POLICY_NAME,
  3337. },
  3338. },
  3339. },
  3340. }
  3341. self.client.send_request.assert_has_calls([
  3342. mock.call('volume-modify-iter', volume_modify_iter_args)])
  3343. def test_get_nfs_export_policy_for_volume(self):
  3344. api_response = netapp_api.NaElement(
  3345. fake.VOLUME_GET_EXPORT_POLICY_RESPONSE)
  3346. self.mock_object(self.client,
  3347. 'send_iter_request',
  3348. mock.Mock(return_value=api_response))
  3349. result = self.client.get_nfs_export_policy_for_volume(fake.SHARE_NAME)
  3350. volume_get_iter_args = {
  3351. 'query': {
  3352. 'volume-attributes': {
  3353. 'volume-id-attributes': {
  3354. 'name': fake.SHARE_NAME,
  3355. },
  3356. },
  3357. },
  3358. 'desired-attributes': {
  3359. 'volume-attributes': {
  3360. 'volume-export-attributes': {
  3361. 'policy': None,
  3362. },
  3363. },
  3364. },
  3365. }
  3366. self.assertEqual(fake.EXPORT_POLICY_NAME, result)
  3367. self.client.send_iter_request.assert_has_calls([
  3368. mock.call('volume-get-iter', volume_get_iter_args)])
  3369. def test_get_nfs_export_policy_for_volume_not_found(self):
  3370. api_response = netapp_api.NaElement(fake.NO_RECORDS_RESPONSE)
  3371. self.mock_object(self.client,
  3372. 'send_iter_request',
  3373. mock.Mock(return_value=api_response))
  3374. self.assertRaises(exception.NetAppException,
  3375. self.client.get_nfs_export_policy_for_volume,
  3376. fake.SHARE_NAME)
  3377. def test_create_nfs_export_policy(self):
  3378. self.mock_object(self.client, 'send_request')
  3379. self.client.create_nfs_export_policy(fake.EXPORT_POLICY_NAME)
  3380. export_policy_create_args = {'policy-name': fake.EXPORT_POLICY_NAME}
  3381. self.client.send_request.assert_has_calls([
  3382. mock.call('export-policy-create', export_policy_create_args)])
  3383. def test_create_nfs_export_policy_already_present(self):
  3384. self.mock_object(self.client,
  3385. 'send_request',
  3386. self._mock_api_error(code=netapp_api.EDUPLICATEENTRY))
  3387. self.client.create_nfs_export_policy(fake.EXPORT_POLICY_NAME)
  3388. export_policy_create_args = {'policy-name': fake.EXPORT_POLICY_NAME}
  3389. self.client.send_request.assert_has_calls([
  3390. mock.call('export-policy-create', export_policy_create_args)])
  3391. def test_create_nfs_export_policy_api_error(self):
  3392. self.mock_object(self.client, 'send_request', self._mock_api_error())
  3393. self.assertRaises(netapp_api.NaApiError,
  3394. self.client.create_nfs_export_policy,
  3395. fake.EXPORT_POLICY_NAME)
  3396. def test_soft_delete_nfs_export_policy(self):
  3397. self.mock_object(self.client, 'delete_nfs_export_policy')
  3398. self.mock_object(self.client, 'rename_nfs_export_policy')
  3399. self.client.soft_delete_nfs_export_policy(fake.EXPORT_POLICY_NAME)
  3400. self.client.delete_nfs_export_policy.assert_has_calls([
  3401. mock.call(fake.EXPORT_POLICY_NAME)])
  3402. self.assertFalse(self.client.rename_nfs_export_policy.called)
  3403. def test_soft_delete_nfs_export_policy_api_error(self):
  3404. self.mock_object(self.client,
  3405. 'delete_nfs_export_policy',
  3406. self._mock_api_error())
  3407. self.mock_object(self.client, 'rename_nfs_export_policy')
  3408. self.client.soft_delete_nfs_export_policy(fake.EXPORT_POLICY_NAME)
  3409. self.client.delete_nfs_export_policy.assert_has_calls([
  3410. mock.call(fake.EXPORT_POLICY_NAME)])
  3411. self.assertTrue(self.client.rename_nfs_export_policy.called)
  3412. def test_delete_nfs_export_policy(self):
  3413. self.mock_object(self.client, 'send_request')
  3414. self.client.delete_nfs_export_policy(fake.EXPORT_POLICY_NAME)
  3415. export_policy_destroy_args = {'policy-name': fake.EXPORT_POLICY_NAME}
  3416. self.client.send_request.assert_has_calls([
  3417. mock.call('export-policy-destroy', export_policy_destroy_args)])
  3418. def test_delete_nfs_export_policy_not_found(self):
  3419. self.mock_object(self.client,
  3420. 'send_request',
  3421. self._mock_api_error(code=netapp_api.EOBJECTNOTFOUND))
  3422. self.client.delete_nfs_export_policy(fake.EXPORT_POLICY_NAME)
  3423. export_policy_destroy_args = {'policy-name': fake.EXPORT_POLICY_NAME}
  3424. self.client.send_request.assert_has_calls([
  3425. mock.call('export-policy-destroy', export_policy_destroy_args)])
  3426. def test_delete_nfs_export_policy_api_error(self):
  3427. self.mock_object(self.client, 'send_request', self._mock_api_error())
  3428. self.assertRaises(netapp_api.NaApiError,
  3429. self.client.delete_nfs_export_policy,
  3430. fake.EXPORT_POLICY_NAME)
  3431. def test_rename_nfs_export_policy(self):
  3432. self.mock_object(self.client, 'send_request')
  3433. self.client.rename_nfs_export_policy(fake.EXPORT_POLICY_NAME,
  3434. 'new_policy_name')
  3435. export_policy_rename_args = {
  3436. 'policy-name': fake.EXPORT_POLICY_NAME,
  3437. 'new-policy-name': 'new_policy_name'
  3438. }
  3439. self.client.send_request.assert_has_calls([
  3440. mock.call('export-policy-rename', export_policy_rename_args)])
  3441. def test_prune_deleted_nfs_export_policies(self):
  3442. # Mock client lest we not be able to see calls on its copy.
  3443. self.mock_object(copy,
  3444. 'deepcopy',
  3445. mock.Mock(return_value=self.client))
  3446. self.mock_object(self.client,
  3447. '_get_deleted_nfs_export_policies',
  3448. mock.Mock(return_value=fake.DELETED_EXPORT_POLICIES))
  3449. self.mock_object(self.client, 'delete_nfs_export_policy')
  3450. self.client.prune_deleted_nfs_export_policies()
  3451. self.assertTrue(self.client.delete_nfs_export_policy.called)
  3452. self.client.delete_nfs_export_policy.assert_has_calls(
  3453. [mock.call(policy) for policy in
  3454. fake.DELETED_EXPORT_POLICIES[fake.VSERVER_NAME]])
  3455. def test_prune_deleted_nfs_export_policies_api_error(self):
  3456. self.mock_object(copy,
  3457. 'deepcopy',
  3458. mock.Mock(return_value=self.client))
  3459. self.mock_object(self.client,
  3460. '_get_deleted_nfs_export_policies',
  3461. mock.Mock(return_value=fake.DELETED_EXPORT_POLICIES))
  3462. self.mock_object(self.client,
  3463. 'delete_nfs_export_policy',
  3464. self._mock_api_error())
  3465. self.client.prune_deleted_nfs_export_policies()
  3466. self.assertTrue(self.client.delete_nfs_export_policy.called)
  3467. self.client.delete_nfs_export_policy.assert_has_calls(
  3468. [mock.call(policy) for policy in
  3469. fake.DELETED_EXPORT_POLICIES[fake.VSERVER_NAME]])
  3470. def test_get_deleted_nfs_export_policies(self):
  3471. api_response = netapp_api.NaElement(
  3472. fake.DELETED_EXPORT_POLICY_GET_ITER_RESPONSE)
  3473. self.mock_object(self.client,
  3474. 'send_iter_request',
  3475. mock.Mock(return_value=api_response))
  3476. result = self.client._get_deleted_nfs_export_policies()
  3477. export_policy_get_iter_args = {
  3478. 'query': {
  3479. 'export-policy-info': {
  3480. 'policy-name': 'deleted_manila_*',
  3481. },
  3482. },
  3483. 'desired-attributes': {
  3484. 'export-policy-info': {
  3485. 'policy-name': None,
  3486. 'vserver': None,
  3487. },
  3488. },
  3489. }
  3490. self.assertSequenceEqual(fake.DELETED_EXPORT_POLICIES, result)
  3491. self.client.send_iter_request.assert_has_calls([
  3492. mock.call('export-policy-get-iter', export_policy_get_iter_args)])
  3493. def test_get_ems_log_destination_vserver(self):
  3494. self.mock_object(self.client,
  3495. 'get_ontapi_version',
  3496. mock.Mock(return_value=(1, 21)))
  3497. mock_list_vservers = self.mock_object(
  3498. self.client,
  3499. 'list_vservers',
  3500. mock.Mock(return_value=[fake.ADMIN_VSERVER_NAME]))
  3501. result = self.client._get_ems_log_destination_vserver()
  3502. mock_list_vservers.assert_called_once_with(vserver_type='admin')
  3503. self.assertEqual(fake.ADMIN_VSERVER_NAME, result)
  3504. def test_get_ems_log_destination_vserver_future(self):
  3505. self.mock_object(self.client,
  3506. 'get_ontapi_version',
  3507. mock.Mock(return_value=(2, 0)))
  3508. mock_list_vservers = self.mock_object(
  3509. self.client,
  3510. 'list_vservers',
  3511. mock.Mock(return_value=[fake.ADMIN_VSERVER_NAME]))
  3512. result = self.client._get_ems_log_destination_vserver()
  3513. mock_list_vservers.assert_called_once_with(vserver_type='admin')
  3514. self.assertEqual(fake.ADMIN_VSERVER_NAME, result)
  3515. def test_get_ems_log_destination_vserver_legacy(self):
  3516. self.mock_object(self.client,
  3517. 'get_ontapi_version',
  3518. mock.Mock(return_value=(1, 15)))
  3519. mock_list_vservers = self.mock_object(
  3520. self.client,
  3521. 'list_vservers',
  3522. mock.Mock(return_value=[fake.NODE_VSERVER_NAME]))
  3523. result = self.client._get_ems_log_destination_vserver()
  3524. mock_list_vservers.assert_called_once_with(vserver_type='node')
  3525. self.assertEqual(fake.NODE_VSERVER_NAME, result)
  3526. def test_get_ems_log_destination_no_cluster_creds(self):
  3527. self.mock_object(self.client,
  3528. 'get_ontapi_version',
  3529. mock.Mock(return_value=(1, 21)))
  3530. mock_list_vservers = self.mock_object(
  3531. self.client,
  3532. 'list_vservers',
  3533. mock.Mock(side_effect=[[], [fake.VSERVER_NAME]]))
  3534. result = self.client._get_ems_log_destination_vserver()
  3535. mock_list_vservers.assert_has_calls([
  3536. mock.call(vserver_type='admin'),
  3537. mock.call(vserver_type='data')])
  3538. self.assertEqual(fake.VSERVER_NAME, result)
  3539. def test_get_ems_log_destination_vserver_not_found(self):
  3540. self.mock_object(self.client,
  3541. 'get_ontapi_version',
  3542. mock.Mock(return_value=(1, 21)))
  3543. mock_list_vservers = self.mock_object(
  3544. self.client,
  3545. 'list_vservers',
  3546. mock.Mock(return_value=[]))
  3547. self.assertRaises(exception.NotFound,
  3548. self.client._get_ems_log_destination_vserver)
  3549. mock_list_vservers.assert_has_calls([
  3550. mock.call(vserver_type='admin'),
  3551. mock.call(vserver_type='data'),
  3552. mock.call(vserver_type='node')])
  3553. def test_send_ems_log_message(self):
  3554. # Mock client lest we not be able to see calls on its copy.
  3555. self.mock_object(
  3556. copy, 'copy',
  3557. mock.Mock(side_effect=[self.client, self.client.connection]))
  3558. self.mock_object(self.client,
  3559. '_get_ems_log_destination_vserver',
  3560. mock.Mock(return_value=fake.ADMIN_VSERVER_NAME))
  3561. self.mock_object(self.client, 'send_request')
  3562. self.client.send_ems_log_message(fake.EMS_MESSAGE)
  3563. self.client.send_request.assert_has_calls([
  3564. mock.call('ems-autosupport-log', fake.EMS_MESSAGE)])
  3565. self.assertEqual(1, client_cmode.LOG.debug.call_count)
  3566. def test_send_ems_log_message_api_error(self):
  3567. # Mock client lest we not be able to see calls on its copy.
  3568. self.mock_object(
  3569. copy, 'copy',
  3570. mock.Mock(side_effect=[self.client, self.client.connection]))
  3571. self.mock_object(self.client,
  3572. '_get_ems_log_destination_vserver',
  3573. mock.Mock(return_value=fake.ADMIN_VSERVER_NAME))
  3574. self.mock_object(self.client, 'send_request', self._mock_api_error())
  3575. self.client.send_ems_log_message(fake.EMS_MESSAGE)
  3576. self.client.send_request.assert_has_calls([
  3577. mock.call('ems-autosupport-log', fake.EMS_MESSAGE)])
  3578. self.assertEqual(1, client_cmode.LOG.warning.call_count)
  3579. def test_get_aggregate_none_specified(self):
  3580. result = self.client.get_aggregate('')
  3581. self.assertEqual({}, result)
  3582. def test_get_aggregate(self):
  3583. api_response = netapp_api.NaElement(
  3584. fake.AGGR_GET_ITER_SSC_RESPONSE).get_child_by_name(
  3585. 'attributes-list').get_children()
  3586. self.mock_object(self.client,
  3587. '_get_aggregates',
  3588. mock.Mock(return_value=api_response))
  3589. result = self.client.get_aggregate(fake.SHARE_AGGREGATE_NAME)
  3590. desired_attributes = {
  3591. 'aggr-attributes': {
  3592. 'aggregate-name': None,
  3593. 'aggr-raid-attributes': {
  3594. 'raid-type': None,
  3595. 'is-hybrid': None,
  3596. },
  3597. },
  3598. }
  3599. self.client._get_aggregates.assert_has_calls([
  3600. mock.call(
  3601. aggregate_names=[fake.SHARE_AGGREGATE_NAME],
  3602. desired_attributes=desired_attributes)])
  3603. expected = {
  3604. 'name': fake.SHARE_AGGREGATE_NAME,
  3605. 'raid-type': 'raid_dp',
  3606. 'is-hybrid': False,
  3607. }
  3608. self.assertEqual(expected, result)
  3609. def test_get_aggregate_not_found(self):
  3610. api_response = netapp_api.NaElement(fake.NO_RECORDS_RESPONSE)
  3611. self.mock_object(self.client,
  3612. 'send_request',
  3613. mock.Mock(return_value=api_response))
  3614. result = self.client.get_aggregate(fake.SHARE_AGGREGATE_NAME)
  3615. self.assertEqual({}, result)
  3616. def test_get_aggregate_api_error(self):
  3617. self.mock_object(self.client,
  3618. 'send_request',
  3619. mock.Mock(side_effect=self._mock_api_error()))
  3620. result = self.client.get_aggregate(fake.SHARE_AGGREGATE_NAME)
  3621. self.assertEqual({}, result)
  3622. @ddt.data({'types': {'FCAL'}, 'expected': ['FCAL']},
  3623. {'types': {'SATA', 'SSD'}, 'expected': ['SATA', 'SSD']},)
  3624. @ddt.unpack
  3625. def test_get_aggregate_disk_types(self, types, expected):
  3626. mock_get_aggregate_disk_types = self.mock_object(
  3627. self.client, '_get_aggregate_disk_types',
  3628. mock.Mock(return_value=types))
  3629. result = self.client.get_aggregate_disk_types(
  3630. fake.SHARE_AGGREGATE_NAME)
  3631. self.assertItemsEqual(expected, result)
  3632. mock_get_aggregate_disk_types.assert_called_once_with(
  3633. fake.SHARE_AGGREGATE_NAME)
  3634. def test_get_aggregate_disk_types_not_found(self):
  3635. mock_get_aggregate_disk_types = self.mock_object(
  3636. self.client, '_get_aggregate_disk_types',
  3637. mock.Mock(return_value=set()))
  3638. result = self.client.get_aggregate_disk_types(
  3639. fake.SHARE_AGGREGATE_NAME)
  3640. self.assertIsNone(result)
  3641. mock_get_aggregate_disk_types.assert_called_once_with(
  3642. fake.SHARE_AGGREGATE_NAME)
  3643. def test_get_aggregate_disk_types_shared(self):
  3644. self.client.features.add_feature('ADVANCED_DISK_PARTITIONING')
  3645. mock_get_aggregate_disk_types = self.mock_object(
  3646. self.client, '_get_aggregate_disk_types',
  3647. mock.Mock(side_effect=[set(['SSD']), set(['SATA'])]))
  3648. result = self.client.get_aggregate_disk_types(
  3649. fake.SHARE_AGGREGATE_NAME)
  3650. self.assertIsInstance(result, list)
  3651. self.assertItemsEqual(['SATA', 'SSD'], result)
  3652. mock_get_aggregate_disk_types.assert_has_calls([
  3653. mock.call(fake.SHARE_AGGREGATE_NAME),
  3654. mock.call(fake.SHARE_AGGREGATE_NAME, shared=True),
  3655. ])
  3656. @ddt.data({
  3657. 'shared': False,
  3658. 'query_disk_raid_info': {
  3659. 'disk-aggregate-info': {
  3660. 'aggregate-name': fake.SHARE_AGGREGATE_NAME,
  3661. },
  3662. },
  3663. }, {
  3664. 'shared': True,
  3665. 'query_disk_raid_info': {
  3666. 'disk-shared-info': {
  3667. 'aggregate-list': {
  3668. 'shared-aggregate-info': {
  3669. 'aggregate-name':
  3670. fake.SHARE_AGGREGATE_NAME,
  3671. },
  3672. },
  3673. },
  3674. },
  3675. })
  3676. @ddt.unpack
  3677. def test__get_aggregate_disk_types_ddt(self, shared, query_disk_raid_info):
  3678. api_response = netapp_api.NaElement(
  3679. fake.STORAGE_DISK_GET_ITER_RESPONSE)
  3680. self.mock_object(self.client,
  3681. 'send_iter_request',
  3682. mock.Mock(return_value=api_response))
  3683. result = self.client._get_aggregate_disk_types(
  3684. fake.SHARE_AGGREGATE_NAME, shared=shared)
  3685. storage_disk_get_iter_args = {
  3686. 'query': {
  3687. 'storage-disk-info': {
  3688. 'disk-raid-info': query_disk_raid_info,
  3689. },
  3690. },
  3691. 'desired-attributes': {
  3692. 'storage-disk-info': {
  3693. 'disk-raid-info': {
  3694. 'effective-disk-type': None,
  3695. },
  3696. },
  3697. },
  3698. }
  3699. self.client.send_iter_request.assert_called_once_with(
  3700. 'storage-disk-get-iter', storage_disk_get_iter_args)
  3701. expected = set(fake.SHARE_AGGREGATE_DISK_TYPES)
  3702. self.assertEqual(expected, result)
  3703. def test__get_aggregate_disk_types_not_found(self):
  3704. api_response = netapp_api.NaElement(fake.NO_RECORDS_RESPONSE)
  3705. self.mock_object(self.client,
  3706. 'send_iter_request',
  3707. mock.Mock(return_value=api_response))
  3708. result = self.client._get_aggregate_disk_types(
  3709. fake.SHARE_AGGREGATE_NAME)
  3710. self.assertEqual(set(), result)
  3711. def test__get_aggregate_disk_types_api_error(self):
  3712. self.mock_object(self.client,
  3713. 'send_iter_request',
  3714. mock.Mock(side_effect=self._mock_api_error()))
  3715. result = self.client._get_aggregate_disk_types(
  3716. fake.SHARE_AGGREGATE_NAME)
  3717. self.assertEqual(set([]), result)
  3718. def test_check_for_cluster_credentials(self):
  3719. api_response = netapp_api.NaElement(fake.SYSTEM_NODE_GET_ITER_RESPONSE)
  3720. self.mock_object(self.client,
  3721. 'send_iter_request',
  3722. mock.Mock(return_value=api_response))
  3723. result = self.client.check_for_cluster_credentials()
  3724. self.assertTrue(result)
  3725. def test_check_for_cluster_credentials_not_cluster(self):
  3726. self.mock_object(self.client,
  3727. 'send_iter_request',
  3728. mock.Mock(side_effect=self._mock_api_error(
  3729. netapp_api.EAPINOTFOUND)))
  3730. result = self.client.check_for_cluster_credentials()
  3731. self.assertFalse(result)
  3732. def test_check_for_cluster_credentials_api_error(self):
  3733. self.mock_object(self.client,
  3734. 'send_iter_request',
  3735. self._mock_api_error())
  3736. self.assertRaises(netapp_api.NaApiError,
  3737. self.client.check_for_cluster_credentials)
  3738. def test_create_cluster_peer(self):
  3739. self.mock_object(self.client, 'send_request')
  3740. self.client.create_cluster_peer(['fake_address_1', 'fake_address_2'],
  3741. 'fake_user', 'fake_password',
  3742. 'fake_passphrase')
  3743. cluster_peer_create_args = {
  3744. 'peer-addresses': [
  3745. {'remote-inet-address': 'fake_address_1'},
  3746. {'remote-inet-address': 'fake_address_2'},
  3747. ],
  3748. 'user-name': 'fake_user',
  3749. 'password': 'fake_password',
  3750. 'passphrase': 'fake_passphrase',
  3751. }
  3752. self.client.send_request.assert_has_calls([
  3753. mock.call('cluster-peer-create', cluster_peer_create_args)])
  3754. def test_get_cluster_peers(self):
  3755. api_response = netapp_api.NaElement(
  3756. fake.CLUSTER_PEER_GET_ITER_RESPONSE)
  3757. self.mock_object(self.client,
  3758. 'send_iter_request',
  3759. mock.Mock(return_value=api_response))
  3760. result = self.client.get_cluster_peers()
  3761. cluster_peer_get_iter_args = {}
  3762. self.client.send_iter_request.assert_has_calls([
  3763. mock.call('cluster-peer-get-iter', cluster_peer_get_iter_args)])
  3764. expected = [{
  3765. 'active-addresses': [
  3766. fake.CLUSTER_ADDRESS_1,
  3767. fake.CLUSTER_ADDRESS_2
  3768. ],
  3769. 'availability': 'available',
  3770. 'cluster-name': fake.CLUSTER_NAME,
  3771. 'cluster-uuid': 'fake_uuid',
  3772. 'peer-addresses': [fake.CLUSTER_ADDRESS_1],
  3773. 'remote-cluster-name': fake.REMOTE_CLUSTER_NAME,
  3774. 'serial-number': 'fake_serial_number',
  3775. 'timeout': '60',
  3776. }]
  3777. self.assertEqual(expected, result)
  3778. def test_get_cluster_peers_single(self):
  3779. api_response = netapp_api.NaElement(
  3780. fake.CLUSTER_PEER_GET_ITER_RESPONSE)
  3781. self.mock_object(self.client,
  3782. 'send_iter_request',
  3783. mock.Mock(return_value=api_response))
  3784. self.client.get_cluster_peers(remote_cluster_name=fake.CLUSTER_NAME)
  3785. cluster_peer_get_iter_args = {
  3786. 'query': {
  3787. 'cluster-peer-info': {
  3788. 'remote-cluster-name': fake.CLUSTER_NAME,
  3789. }
  3790. },
  3791. }
  3792. self.client.send_iter_request.assert_has_calls([
  3793. mock.call('cluster-peer-get-iter', cluster_peer_get_iter_args)])
  3794. def test_get_cluster_peers_not_found(self):
  3795. api_response = netapp_api.NaElement(fake.NO_RECORDS_RESPONSE)
  3796. self.mock_object(self.client,
  3797. 'send_iter_request',
  3798. mock.Mock(return_value=api_response))
  3799. result = self.client.get_cluster_peers(
  3800. remote_cluster_name=fake.CLUSTER_NAME)
  3801. self.assertEqual([], result)
  3802. self.assertTrue(self.client.send_iter_request.called)
  3803. def test_delete_cluster_peer(self):
  3804. self.mock_object(self.client, 'send_request')
  3805. self.client.delete_cluster_peer(fake.CLUSTER_NAME)
  3806. cluster_peer_delete_args = {'cluster-name': fake.CLUSTER_NAME}
  3807. self.client.send_request.assert_has_calls([
  3808. mock.call('cluster-peer-delete', cluster_peer_delete_args)])
  3809. def test_get_cluster_peer_policy(self):
  3810. self.client.features.add_feature('CLUSTER_PEER_POLICY')
  3811. api_response = netapp_api.NaElement(
  3812. fake.CLUSTER_PEER_POLICY_GET_RESPONSE)
  3813. self.mock_object(self.client,
  3814. 'send_request',
  3815. mock.Mock(return_value=api_response))
  3816. result = self.client.get_cluster_peer_policy()
  3817. expected = {
  3818. 'is-unauthenticated-access-permitted': False,
  3819. 'passphrase-minimum-length': 8
  3820. }
  3821. self.assertEqual(expected, result)
  3822. self.assertTrue(self.client.send_request.called)
  3823. def test_get_cluster_peer_policy_not_supported(self):
  3824. result = self.client.get_cluster_peer_policy()
  3825. self.assertEqual({}, result)
  3826. def test_set_cluster_peer_policy_not_supported(self):
  3827. self.mock_object(self.client, 'send_request')
  3828. self.client.set_cluster_peer_policy()
  3829. self.assertFalse(self.client.send_request.called)
  3830. def test_set_cluster_peer_policy_no_arguments(self):
  3831. self.client.features.add_feature('CLUSTER_PEER_POLICY')
  3832. self.mock_object(self.client, 'send_request')
  3833. self.client.set_cluster_peer_policy()
  3834. self.assertFalse(self.client.send_request.called)
  3835. def test_set_cluster_peer_policy(self):
  3836. self.client.features.add_feature('CLUSTER_PEER_POLICY')
  3837. self.mock_object(self.client, 'send_request')
  3838. self.client.set_cluster_peer_policy(
  3839. is_unauthenticated_access_permitted=True,
  3840. passphrase_minimum_length=12)
  3841. cluster_peer_policy_modify_args = {
  3842. 'is-unauthenticated-access-permitted': 'true',
  3843. 'passphrase-minlength': '12',
  3844. }
  3845. self.client.send_request.assert_has_calls([
  3846. mock.call('cluster-peer-policy-modify',
  3847. cluster_peer_policy_modify_args)])
  3848. def test_create_vserver_peer(self):
  3849. self.mock_object(self.client, 'send_request')
  3850. self.client.create_vserver_peer('fake_vserver', 'fake_vserver_peer')
  3851. vserver_peer_create_args = {
  3852. 'vserver': 'fake_vserver',
  3853. 'peer-vserver': 'fake_vserver_peer',
  3854. 'applications': [
  3855. {'vserver-peer-application': 'snapmirror'},
  3856. ],
  3857. }
  3858. self.client.send_request.assert_has_calls([
  3859. mock.call('vserver-peer-create', vserver_peer_create_args)])
  3860. def test_delete_vserver_peer(self):
  3861. self.mock_object(self.client, 'send_request')
  3862. self.client.delete_vserver_peer('fake_vserver', 'fake_vserver_peer')
  3863. vserver_peer_delete_args = {
  3864. 'vserver': 'fake_vserver',
  3865. 'peer-vserver': 'fake_vserver_peer',
  3866. }
  3867. self.client.send_request.assert_has_calls([
  3868. mock.call('vserver-peer-delete', vserver_peer_delete_args)])
  3869. def test_accept_vserver_peer(self):
  3870. self.mock_object(self.client, 'send_request')
  3871. self.client.accept_vserver_peer('fake_vserver', 'fake_vserver_peer')
  3872. vserver_peer_accept_args = {
  3873. 'vserver': 'fake_vserver',
  3874. 'peer-vserver': 'fake_vserver_peer',
  3875. }
  3876. self.client.send_request.assert_has_calls([
  3877. mock.call('vserver-peer-accept', vserver_peer_accept_args)])
  3878. def test_get_vserver_peers(self):
  3879. api_response = netapp_api.NaElement(
  3880. fake.VSERVER_PEER_GET_ITER_RESPONSE)
  3881. self.mock_object(self.client,
  3882. 'send_iter_request',
  3883. mock.Mock(return_value=api_response))
  3884. result = self.client.get_vserver_peers(
  3885. vserver_name=fake.VSERVER_NAME,
  3886. peer_vserver_name=fake.VSERVER_NAME_2)
  3887. vserver_peer_get_iter_args = {
  3888. 'query': {
  3889. 'vserver-peer-info': {
  3890. 'vserver': fake.VSERVER_NAME,
  3891. 'peer-vserver': fake.VSERVER_NAME_2,
  3892. }
  3893. },
  3894. }
  3895. self.client.send_iter_request.assert_has_calls([
  3896. mock.call('vserver-peer-get-iter', vserver_peer_get_iter_args)])
  3897. expected = [{
  3898. 'vserver': 'fake_vserver',
  3899. 'peer-vserver': 'fake_vserver_2',
  3900. 'peer-state': 'peered',
  3901. 'peer-cluster': 'fake_cluster'
  3902. }]
  3903. self.assertEqual(expected, result)
  3904. def test_get_vserver_peers_not_found(self):
  3905. api_response = netapp_api.NaElement(fake.NO_RECORDS_RESPONSE)
  3906. self.mock_object(self.client,
  3907. 'send_iter_request',
  3908. mock.Mock(return_value=api_response))
  3909. result = self.client.get_vserver_peers(
  3910. vserver_name=fake.VSERVER_NAME,
  3911. peer_vserver_name=fake.VSERVER_NAME_2)
  3912. self.assertEqual([], result)
  3913. self.assertTrue(self.client.send_iter_request.called)
  3914. def test_ensure_snapmirror_v2(self):
  3915. self.assertIsNone(self.client._ensure_snapmirror_v2())
  3916. def test_ensure_snapmirror_v2_not_supported(self):
  3917. self.client.features.add_feature('SNAPMIRROR_V2', supported=False)
  3918. self.assertRaises(exception.NetAppException,
  3919. self.client._ensure_snapmirror_v2)
  3920. @ddt.data({'schedule': 'fake_schedule', 'policy': 'fake_policy'},
  3921. {'schedule': None, 'policy': None})
  3922. @ddt.unpack
  3923. def test_create_snapmirror(self, schedule, policy):
  3924. self.mock_object(self.client, 'send_request')
  3925. self.client.create_snapmirror(
  3926. fake.SM_SOURCE_VSERVER, fake.SM_SOURCE_VOLUME,
  3927. fake.SM_DEST_VSERVER, fake.SM_DEST_VOLUME,
  3928. schedule=schedule, policy=policy)
  3929. snapmirror_create_args = {
  3930. 'source-vserver': fake.SM_SOURCE_VSERVER,
  3931. 'source-volume': fake.SM_SOURCE_VOLUME,
  3932. 'destination-vserver': fake.SM_DEST_VSERVER,
  3933. 'destination-volume': fake.SM_DEST_VOLUME,
  3934. 'relationship-type': 'data_protection',
  3935. }
  3936. if schedule:
  3937. snapmirror_create_args['schedule'] = schedule
  3938. if policy:
  3939. snapmirror_create_args['policy'] = policy
  3940. self.client.send_request.assert_has_calls([
  3941. mock.call('snapmirror-create', snapmirror_create_args)])
  3942. def test_create_snapmirror_already_exists(self):
  3943. mock_send_req = mock.Mock(side_effect=netapp_api.NaApiError(
  3944. code=netapp_api.ERELATION_EXISTS))
  3945. self.mock_object(self.client, 'send_request', mock_send_req)
  3946. self.client.create_snapmirror(
  3947. fake.SM_SOURCE_VSERVER, fake.SM_SOURCE_VOLUME,
  3948. fake.SM_DEST_VSERVER, fake.SM_DEST_VOLUME)
  3949. snapmirror_create_args = {
  3950. 'source-vserver': fake.SM_SOURCE_VSERVER,
  3951. 'source-volume': fake.SM_SOURCE_VOLUME,
  3952. 'destination-vserver': fake.SM_DEST_VSERVER,
  3953. 'destination-volume': fake.SM_DEST_VOLUME,
  3954. 'relationship-type': 'data_protection',
  3955. }
  3956. self.client.send_request.assert_has_calls([
  3957. mock.call('snapmirror-create', snapmirror_create_args)])
  3958. def test_create_snapmirror_error(self):
  3959. mock_send_req = mock.Mock(side_effect=netapp_api.NaApiError(
  3960. code=0))
  3961. self.mock_object(self.client, 'send_request', mock_send_req)
  3962. self.assertRaises(netapp_api.NaApiError, self.client.create_snapmirror,
  3963. fake.SM_SOURCE_VSERVER, fake.SM_SOURCE_VOLUME,
  3964. fake.SM_DEST_VSERVER, fake.SM_DEST_VOLUME)
  3965. self.assertTrue(self.client.send_request.called)
  3966. @ddt.data(
  3967. {
  3968. 'source_snapshot': 'fake_snapshot',
  3969. 'transfer_priority': 'fake_priority'
  3970. },
  3971. {
  3972. 'source_snapshot': None,
  3973. 'transfer_priority': None
  3974. }
  3975. )
  3976. @ddt.unpack
  3977. def test_initialize_snapmirror(self, source_snapshot, transfer_priority):
  3978. api_response = netapp_api.NaElement(fake.SNAPMIRROR_INITIALIZE_RESULT)
  3979. self.mock_object(self.client,
  3980. 'send_request',
  3981. mock.Mock(return_value=api_response))
  3982. result = self.client.initialize_snapmirror(
  3983. fake.SM_SOURCE_VSERVER, fake.SM_SOURCE_VOLUME,
  3984. fake.SM_DEST_VSERVER, fake.SM_DEST_VOLUME,
  3985. source_snapshot=source_snapshot,
  3986. transfer_priority=transfer_priority)
  3987. snapmirror_initialize_args = {
  3988. 'source-vserver': fake.SM_SOURCE_VSERVER,
  3989. 'source-volume': fake.SM_SOURCE_VOLUME,
  3990. 'destination-vserver': fake.SM_DEST_VSERVER,
  3991. 'destination-volume': fake.SM_DEST_VOLUME,
  3992. }
  3993. if source_snapshot:
  3994. snapmirror_initialize_args['source-snapshot'] = source_snapshot
  3995. if transfer_priority:
  3996. snapmirror_initialize_args['transfer-priority'] = transfer_priority
  3997. self.client.send_request.assert_has_calls([
  3998. mock.call('snapmirror-initialize', snapmirror_initialize_args)])
  3999. expected = {
  4000. 'operation-id': None,
  4001. 'status': 'succeeded',
  4002. 'jobid': None,
  4003. 'error-code': None,
  4004. 'error-message': None
  4005. }
  4006. self.assertEqual(expected, result)
  4007. @ddt.data(True, False)
  4008. def test_release_snapmirror(self, relationship_info_only):
  4009. self.mock_object(self.client, 'send_request')
  4010. self.client.release_snapmirror(
  4011. fake.SM_SOURCE_VSERVER, fake.SM_SOURCE_VOLUME,
  4012. fake.SM_DEST_VSERVER, fake.SM_DEST_VOLUME,
  4013. relationship_info_only=relationship_info_only)
  4014. snapmirror_release_args = {
  4015. 'query': {
  4016. 'snapmirror-destination-info': {
  4017. 'source-vserver': fake.SM_SOURCE_VSERVER,
  4018. 'source-volume': fake.SM_SOURCE_VOLUME,
  4019. 'destination-vserver': fake.SM_DEST_VSERVER,
  4020. 'destination-volume': fake.SM_DEST_VOLUME,
  4021. 'relationship-info-only': ('true' if relationship_info_only
  4022. else 'false'),
  4023. }
  4024. }
  4025. }
  4026. self.client.send_request.assert_has_calls([
  4027. mock.call('snapmirror-release-iter', snapmirror_release_args)])
  4028. def test_quiesce_snapmirror(self):
  4029. self.mock_object(self.client, 'send_request')
  4030. self.client.quiesce_snapmirror(
  4031. fake.SM_SOURCE_VSERVER, fake.SM_SOURCE_VOLUME,
  4032. fake.SM_DEST_VSERVER, fake.SM_DEST_VOLUME)
  4033. snapmirror_quiesce_args = {
  4034. 'source-vserver': fake.SM_SOURCE_VSERVER,
  4035. 'source-volume': fake.SM_SOURCE_VOLUME,
  4036. 'destination-vserver': fake.SM_DEST_VSERVER,
  4037. 'destination-volume': fake.SM_DEST_VOLUME,
  4038. }
  4039. self.client.send_request.assert_has_calls([
  4040. mock.call('snapmirror-quiesce', snapmirror_quiesce_args)])
  4041. @ddt.data(True, False)
  4042. def test_abort_snapmirror(self, clear_checkpoint):
  4043. self.mock_object(self.client, 'send_request')
  4044. self.client.abort_snapmirror(
  4045. fake.SM_SOURCE_VSERVER, fake.SM_SOURCE_VOLUME,
  4046. fake.SM_DEST_VSERVER, fake.SM_DEST_VOLUME,
  4047. clear_checkpoint=clear_checkpoint)
  4048. snapmirror_abort_args = {
  4049. 'source-vserver': fake.SM_SOURCE_VSERVER,
  4050. 'source-volume': fake.SM_SOURCE_VOLUME,
  4051. 'destination-vserver': fake.SM_DEST_VSERVER,
  4052. 'destination-volume': fake.SM_DEST_VOLUME,
  4053. 'clear-checkpoint': 'true' if clear_checkpoint else 'false',
  4054. }
  4055. self.client.send_request.assert_has_calls([
  4056. mock.call('snapmirror-abort', snapmirror_abort_args)])
  4057. def test_abort_snapmirror_no_transfer_in_progress(self):
  4058. mock_send_req = mock.Mock(side_effect=netapp_api.NaApiError(
  4059. code=netapp_api.ENOTRANSFER_IN_PROGRESS))
  4060. self.mock_object(self.client, 'send_request', mock_send_req)
  4061. self.client.abort_snapmirror(
  4062. fake.SM_SOURCE_VSERVER, fake.SM_SOURCE_VOLUME,
  4063. fake.SM_DEST_VSERVER, fake.SM_DEST_VOLUME)
  4064. snapmirror_abort_args = {
  4065. 'source-vserver': fake.SM_SOURCE_VSERVER,
  4066. 'source-volume': fake.SM_SOURCE_VOLUME,
  4067. 'destination-vserver': fake.SM_DEST_VSERVER,
  4068. 'destination-volume': fake.SM_DEST_VOLUME,
  4069. 'clear-checkpoint': 'false',
  4070. }
  4071. self.client.send_request.assert_has_calls([
  4072. mock.call('snapmirror-abort', snapmirror_abort_args)])
  4073. def test_abort_snapmirror_error(self):
  4074. mock_send_req = mock.Mock(side_effect=netapp_api.NaApiError(code=0))
  4075. self.mock_object(self.client, 'send_request', mock_send_req)
  4076. self.assertRaises(netapp_api.NaApiError, self.client.abort_snapmirror,
  4077. fake.SM_SOURCE_VSERVER, fake.SM_SOURCE_VOLUME,
  4078. fake.SM_DEST_VSERVER, fake.SM_DEST_VOLUME)
  4079. def test_break_snapmirror(self):
  4080. self.mock_object(self.client, 'send_request')
  4081. self.client.break_snapmirror(
  4082. fake.SM_SOURCE_VSERVER, fake.SM_SOURCE_VOLUME,
  4083. fake.SM_DEST_VSERVER, fake.SM_DEST_VOLUME)
  4084. snapmirror_break_args = {
  4085. 'source-vserver': fake.SM_SOURCE_VSERVER,
  4086. 'source-volume': fake.SM_SOURCE_VOLUME,
  4087. 'destination-vserver': fake.SM_DEST_VSERVER,
  4088. 'destination-volume': fake.SM_DEST_VOLUME,
  4089. }
  4090. self.client.send_request.assert_has_calls([
  4091. mock.call('snapmirror-break', snapmirror_break_args)])
  4092. @ddt.data(
  4093. {
  4094. 'schedule': 'fake_schedule',
  4095. 'policy': 'fake_policy',
  4096. 'tries': 5,
  4097. 'max_transfer_rate': 1024,
  4098. },
  4099. {
  4100. 'schedule': None,
  4101. 'policy': None,
  4102. 'tries': None,
  4103. 'max_transfer_rate': None,
  4104. }
  4105. )
  4106. @ddt.unpack
  4107. def test_modify_snapmirror(self, schedule, policy, tries,
  4108. max_transfer_rate):
  4109. self.mock_object(self.client, 'send_request')
  4110. self.client.modify_snapmirror(
  4111. fake.SM_SOURCE_VSERVER, fake.SM_SOURCE_VOLUME,
  4112. fake.SM_DEST_VSERVER, fake.SM_DEST_VOLUME,
  4113. schedule=schedule, policy=policy, tries=tries,
  4114. max_transfer_rate=max_transfer_rate)
  4115. snapmirror_modify_args = {
  4116. 'source-vserver': fake.SM_SOURCE_VSERVER,
  4117. 'source-volume': fake.SM_SOURCE_VOLUME,
  4118. 'destination-vserver': fake.SM_DEST_VSERVER,
  4119. 'destination-volume': fake.SM_DEST_VOLUME,
  4120. }
  4121. if schedule:
  4122. snapmirror_modify_args['schedule'] = schedule
  4123. if policy:
  4124. snapmirror_modify_args['policy'] = policy
  4125. if tries:
  4126. snapmirror_modify_args['tries'] = tries
  4127. if max_transfer_rate:
  4128. snapmirror_modify_args['max-transfer-rate'] = max_transfer_rate
  4129. self.client.send_request.assert_has_calls([
  4130. mock.call('snapmirror-modify', snapmirror_modify_args)])
  4131. def test_update_snapmirror(self):
  4132. self.mock_object(self.client, 'send_request')
  4133. self.client.update_snapmirror(
  4134. fake.SM_SOURCE_VSERVER, fake.SM_SOURCE_VOLUME,
  4135. fake.SM_DEST_VSERVER, fake.SM_DEST_VOLUME)
  4136. snapmirror_update_args = {
  4137. 'source-vserver': fake.SM_SOURCE_VSERVER,
  4138. 'source-volume': fake.SM_SOURCE_VOLUME,
  4139. 'destination-vserver': fake.SM_DEST_VSERVER,
  4140. 'destination-volume': fake.SM_DEST_VOLUME,
  4141. }
  4142. self.client.send_request.assert_has_calls([
  4143. mock.call('snapmirror-update', snapmirror_update_args)])
  4144. def test_update_snapmirror_already_transferring(self):
  4145. mock_send_req = mock.Mock(side_effect=netapp_api.NaApiError(
  4146. code=netapp_api.ETRANSFER_IN_PROGRESS))
  4147. self.mock_object(self.client, 'send_request', mock_send_req)
  4148. self.client.update_snapmirror(
  4149. fake.SM_SOURCE_VSERVER, fake.SM_SOURCE_VOLUME,
  4150. fake.SM_DEST_VSERVER, fake.SM_DEST_VOLUME)
  4151. snapmirror_update_args = {
  4152. 'source-vserver': fake.SM_SOURCE_VSERVER,
  4153. 'source-volume': fake.SM_SOURCE_VOLUME,
  4154. 'destination-vserver': fake.SM_DEST_VSERVER,
  4155. 'destination-volume': fake.SM_DEST_VOLUME,
  4156. }
  4157. self.client.send_request.assert_has_calls([
  4158. mock.call('snapmirror-update', snapmirror_update_args)])
  4159. def test_update_snapmirror_already_transferring_two(self):
  4160. mock_send_req = mock.Mock(side_effect=netapp_api.NaApiError(
  4161. code=netapp_api.EANOTHER_OP_ACTIVE))
  4162. self.mock_object(self.client, 'send_request', mock_send_req)
  4163. self.client.update_snapmirror(
  4164. fake.SM_SOURCE_VSERVER, fake.SM_SOURCE_VOLUME,
  4165. fake.SM_DEST_VSERVER, fake.SM_DEST_VOLUME)
  4166. snapmirror_update_args = {
  4167. 'source-vserver': fake.SM_SOURCE_VSERVER,
  4168. 'source-volume': fake.SM_SOURCE_VOLUME,
  4169. 'destination-vserver': fake.SM_DEST_VSERVER,
  4170. 'destination-volume': fake.SM_DEST_VOLUME,
  4171. }
  4172. self.client.send_request.assert_has_calls([
  4173. mock.call('snapmirror-update', snapmirror_update_args)])
  4174. def test_update_snapmirror_error(self):
  4175. mock_send_req = mock.Mock(side_effect=netapp_api.NaApiError(code=0))
  4176. self.mock_object(self.client, 'send_request', mock_send_req)
  4177. self.assertRaises(netapp_api.NaApiError, self.client.update_snapmirror,
  4178. fake.SM_SOURCE_VSERVER, fake.SM_SOURCE_VOLUME,
  4179. fake.SM_DEST_VSERVER, fake.SM_DEST_VOLUME)
  4180. def test_delete_snapmirror(self):
  4181. self.mock_object(self.client, 'send_request')
  4182. self.client.delete_snapmirror(
  4183. fake.SM_SOURCE_VSERVER, fake.SM_SOURCE_VOLUME,
  4184. fake.SM_DEST_VSERVER, fake.SM_DEST_VOLUME)
  4185. snapmirror_delete_args = {
  4186. 'query': {
  4187. 'snapmirror-info': {
  4188. 'source-vserver': fake.SM_SOURCE_VSERVER,
  4189. 'source-volume': fake.SM_SOURCE_VOLUME,
  4190. 'destination-vserver': fake.SM_DEST_VSERVER,
  4191. 'destination-volume': fake.SM_DEST_VOLUME,
  4192. }
  4193. }
  4194. }
  4195. self.client.send_request.assert_has_calls([
  4196. mock.call('snapmirror-destroy-iter', snapmirror_delete_args)])
  4197. def test__get_snapmirrors(self):
  4198. api_response = netapp_api.NaElement(fake.SNAPMIRROR_GET_ITER_RESPONSE)
  4199. self.mock_object(self.client,
  4200. 'send_iter_request',
  4201. mock.Mock(return_value=api_response))
  4202. desired_attributes = {
  4203. 'snapmirror-info': {
  4204. 'source-vserver': None,
  4205. 'source-volume': None,
  4206. 'destination-vserver': None,
  4207. 'destination-volume': None,
  4208. 'is-healthy': None,
  4209. }
  4210. }
  4211. result = self.client._get_snapmirrors(
  4212. fake.SM_SOURCE_VSERVER, fake.SM_SOURCE_VOLUME,
  4213. fake.SM_DEST_VSERVER, fake.SM_DEST_VOLUME,
  4214. desired_attributes=desired_attributes)
  4215. snapmirror_get_iter_args = {
  4216. 'query': {
  4217. 'snapmirror-info': {
  4218. 'source-vserver': fake.SM_SOURCE_VSERVER,
  4219. 'source-volume': fake.SM_SOURCE_VOLUME,
  4220. 'destination-vserver': fake.SM_DEST_VSERVER,
  4221. 'destination-volume': fake.SM_DEST_VOLUME,
  4222. },
  4223. },
  4224. 'desired-attributes': {
  4225. 'snapmirror-info': {
  4226. 'source-vserver': None,
  4227. 'source-volume': None,
  4228. 'destination-vserver': None,
  4229. 'destination-volume': None,
  4230. 'is-healthy': None,
  4231. },
  4232. },
  4233. }
  4234. self.client.send_iter_request.assert_has_calls([
  4235. mock.call('snapmirror-get-iter', snapmirror_get_iter_args)])
  4236. self.assertEqual(1, len(result))
  4237. def test__get_snapmirrors_not_found(self):
  4238. api_response = netapp_api.NaElement(fake.NO_RECORDS_RESPONSE)
  4239. self.mock_object(self.client,
  4240. 'send_iter_request',
  4241. mock.Mock(return_value=api_response))
  4242. result = self.client._get_snapmirrors()
  4243. self.client.send_iter_request.assert_has_calls([
  4244. mock.call('snapmirror-get-iter', {})])
  4245. self.assertEqual([], result)
  4246. def test_get_snapmirrors(self):
  4247. api_response = netapp_api.NaElement(
  4248. fake.SNAPMIRROR_GET_ITER_FILTERED_RESPONSE)
  4249. self.mock_object(self.client,
  4250. 'send_iter_request',
  4251. mock.Mock(return_value=api_response))
  4252. desired_attributes = ['source-vserver', 'source-volume',
  4253. 'destination-vserver', 'destination-volume',
  4254. 'is-healthy', 'mirror-state', 'schedule']
  4255. result = self.client.get_snapmirrors(
  4256. fake.SM_SOURCE_VSERVER, fake.SM_SOURCE_VOLUME,
  4257. fake.SM_DEST_VSERVER, fake.SM_DEST_VOLUME,
  4258. desired_attributes=desired_attributes)
  4259. snapmirror_get_iter_args = {
  4260. 'query': {
  4261. 'snapmirror-info': {
  4262. 'source-vserver': fake.SM_SOURCE_VSERVER,
  4263. 'source-volume': fake.SM_SOURCE_VOLUME,
  4264. 'destination-vserver': fake.SM_DEST_VSERVER,
  4265. 'destination-volume': fake.SM_DEST_VOLUME,
  4266. },
  4267. },
  4268. 'desired-attributes': {
  4269. 'snapmirror-info': {
  4270. 'source-vserver': None,
  4271. 'source-volume': None,
  4272. 'destination-vserver': None,
  4273. 'destination-volume': None,
  4274. 'is-healthy': None,
  4275. 'mirror-state': None,
  4276. 'schedule': None,
  4277. },
  4278. },
  4279. }
  4280. expected = [{
  4281. 'source-vserver': fake.SM_SOURCE_VSERVER,
  4282. 'source-volume': fake.SM_SOURCE_VOLUME,
  4283. 'destination-vserver': fake.SM_DEST_VSERVER,
  4284. 'destination-volume': fake.SM_DEST_VOLUME,
  4285. 'is-healthy': 'true',
  4286. 'mirror-state': 'snapmirrored',
  4287. 'schedule': 'daily',
  4288. }]
  4289. self.client.send_iter_request.assert_has_calls([
  4290. mock.call('snapmirror-get-iter', snapmirror_get_iter_args)])
  4291. self.assertEqual(expected, result)
  4292. def test_resume_snapmirror(self):
  4293. self.mock_object(self.client, 'send_request')
  4294. self.client.resume_snapmirror(
  4295. fake.SM_SOURCE_VSERVER, fake.SM_SOURCE_VOLUME,
  4296. fake.SM_DEST_VSERVER, fake.SM_DEST_VOLUME)
  4297. snapmirror_resume_args = {
  4298. 'source-vserver': fake.SM_SOURCE_VSERVER,
  4299. 'source-volume': fake.SM_SOURCE_VOLUME,
  4300. 'destination-vserver': fake.SM_DEST_VSERVER,
  4301. 'destination-volume': fake.SM_DEST_VOLUME,
  4302. }
  4303. self.client.send_request.assert_has_calls([
  4304. mock.call('snapmirror-resume', snapmirror_resume_args)])
  4305. def test_resume_snapmirror_not_quiesed(self):
  4306. mock_send_req = mock.Mock(side_effect=netapp_api.NaApiError(
  4307. code=netapp_api.ERELATION_NOT_QUIESCED))
  4308. self.mock_object(self.client, 'send_request', mock_send_req)
  4309. self.client.resume_snapmirror(
  4310. fake.SM_SOURCE_VSERVER, fake.SM_SOURCE_VOLUME,
  4311. fake.SM_DEST_VSERVER, fake.SM_DEST_VOLUME)
  4312. snapmirror_resume_args = {
  4313. 'source-vserver': fake.SM_SOURCE_VSERVER,
  4314. 'source-volume': fake.SM_SOURCE_VOLUME,
  4315. 'destination-vserver': fake.SM_DEST_VSERVER,
  4316. 'destination-volume': fake.SM_DEST_VOLUME,
  4317. }
  4318. self.client.send_request.assert_has_calls([
  4319. mock.call('snapmirror-resume', snapmirror_resume_args)])
  4320. def test_resume_snapmirror_error(self):
  4321. mock_send_req = mock.Mock(side_effect=netapp_api.NaApiError(code=0))
  4322. self.mock_object(self.client, 'send_request', mock_send_req)
  4323. self.assertRaises(netapp_api.NaApiError, self.client.resume_snapmirror,
  4324. fake.SM_SOURCE_VSERVER, fake.SM_SOURCE_VOLUME,
  4325. fake.SM_DEST_VSERVER, fake.SM_DEST_VOLUME)
  4326. def test_resync_snapmirror(self):
  4327. self.mock_object(self.client, 'send_request')
  4328. self.client.resync_snapmirror(
  4329. fake.SM_SOURCE_VSERVER, fake.SM_SOURCE_VOLUME,
  4330. fake.SM_DEST_VSERVER, fake.SM_DEST_VOLUME)
  4331. snapmirror_resync_args = {
  4332. 'source-vserver': fake.SM_SOURCE_VSERVER,
  4333. 'source-volume': fake.SM_SOURCE_VOLUME,
  4334. 'destination-vserver': fake.SM_DEST_VSERVER,
  4335. 'destination-volume': fake.SM_DEST_VOLUME,
  4336. }
  4337. self.client.send_request.assert_has_calls([
  4338. mock.call('snapmirror-resync', snapmirror_resync_args)])
  4339. @ddt.data('source', 'destination', None)
  4340. def test_volume_has_snapmirror_relationships(self, snapmirror_rel_type):
  4341. """Snapmirror relationships can be both ways."""
  4342. vol = fake.FAKE_MANAGE_VOLUME
  4343. snapmirror = {
  4344. 'source-vserver': fake.SM_SOURCE_VSERVER,
  4345. 'source-volume': fake.SM_SOURCE_VOLUME,
  4346. 'destination-vserver': fake.SM_DEST_VSERVER,
  4347. 'destination-volume': fake.SM_DEST_VOLUME,
  4348. 'is-healthy': 'true',
  4349. 'mirror-state': 'snapmirrored',
  4350. 'schedule': 'daily',
  4351. }
  4352. expected_get_snapmirrors_call_count = 2
  4353. expected_get_snapmirrors_calls = [
  4354. mock.call(vol['owning-vserver-name'], vol['name'], None, None),
  4355. mock.call(None, None, vol['owning-vserver-name'], vol['name']),
  4356. ]
  4357. if snapmirror_rel_type is None:
  4358. side_effect = ([], [])
  4359. elif snapmirror_rel_type == 'source':
  4360. snapmirror['source-vserver'] = vol['owning-vserver-name']
  4361. snapmirror['source-volume'] = vol['name']
  4362. side_effect = ([snapmirror], None)
  4363. expected_get_snapmirrors_call_count = 1
  4364. expected_get_snapmirrors_calls.pop()
  4365. else:
  4366. snapmirror['destination-vserver'] = vol['owning-vserver-name']
  4367. snapmirror['destination-volume'] = vol['name']
  4368. side_effect = (None, [snapmirror])
  4369. mock_get_snapmirrors_call = self.mock_object(
  4370. self.client, 'get_snapmirrors', mock.Mock(side_effect=side_effect))
  4371. mock_exc_log = self.mock_object(client_cmode.LOG, 'exception')
  4372. expected_retval = True if snapmirror_rel_type else False
  4373. retval = self.client.volume_has_snapmirror_relationships(vol)
  4374. self.assertEqual(expected_retval, retval)
  4375. self.assertEqual(expected_get_snapmirrors_call_count,
  4376. mock_get_snapmirrors_call.call_count)
  4377. mock_get_snapmirrors_call.assert_has_calls(
  4378. expected_get_snapmirrors_calls)
  4379. self.assertFalse(mock_exc_log.called)
  4380. def test_volume_has_snapmirror_relationships_api_error(self):
  4381. vol = fake.FAKE_MANAGE_VOLUME
  4382. expected_get_snapmirrors_calls = [
  4383. mock.call(vol['owning-vserver-name'], vol['name'], None, None),
  4384. ]
  4385. mock_get_snapmirrors_call = self.mock_object(
  4386. self.client, 'get_snapmirrors', mock.Mock(
  4387. side_effect=self._mock_api_error(netapp_api.EINTERNALERROR)))
  4388. mock_exc_log = self.mock_object(client_cmode.LOG, 'exception')
  4389. retval = self.client.volume_has_snapmirror_relationships(vol)
  4390. self.assertFalse(retval)
  4391. self.assertEqual(1, mock_get_snapmirrors_call.call_count)
  4392. mock_get_snapmirrors_call.assert_has_calls(
  4393. expected_get_snapmirrors_calls)
  4394. self.assertTrue(mock_exc_log.called)
  4395. @ddt.data(None, '12345')
  4396. def test_list_snapmirror_snapshots(self, newer_than):
  4397. api_response = netapp_api.NaElement(
  4398. fake.SNAPSHOT_GET_ITER_SNAPMIRROR_RESPONSE)
  4399. self.mock_object(self.client,
  4400. 'send_iter_request',
  4401. mock.Mock(return_value=api_response))
  4402. result = self.client.list_snapmirror_snapshots(fake.SHARE_NAME,
  4403. newer_than=newer_than)
  4404. snapshot_get_iter_args = {
  4405. 'query': {
  4406. 'snapshot-info': {
  4407. 'dependency': 'snapmirror',
  4408. 'volume': fake.SHARE_NAME,
  4409. },
  4410. },
  4411. }
  4412. if newer_than:
  4413. snapshot_get_iter_args['query']['snapshot-info']['access-time'] = (
  4414. '>' + newer_than)
  4415. self.client.send_iter_request.assert_has_calls([
  4416. mock.call('snapshot-get-iter', snapshot_get_iter_args)])
  4417. expected = [fake.SNAPSHOT_NAME]
  4418. self.assertEqual(expected, result)
  4419. @ddt.data('start_volume_move', 'check_volume_move')
  4420. def test_volume_move_method(self, method_name):
  4421. method = getattr(self.client, method_name)
  4422. self.mock_object(self.client, 'send_request')
  4423. retval = method(fake.SHARE_NAME, fake.VSERVER_NAME,
  4424. fake.SHARE_AGGREGATE_NAME)
  4425. expected_api_args = {
  4426. 'source-volume': fake.SHARE_NAME,
  4427. 'vserver': fake.VSERVER_NAME,
  4428. 'dest-aggr': fake.SHARE_AGGREGATE_NAME,
  4429. 'cutover-action': 'wait',
  4430. }
  4431. if method_name.startswith('check'):
  4432. expected_api_args['perform-validation-only'] = 'true'
  4433. self.assertIsNone(retval)
  4434. self.client.send_request.assert_called_once_with(
  4435. 'volume-move-start', expected_api_args)
  4436. def test_abort_volume_move(self):
  4437. self.mock_object(self.client, 'send_request')
  4438. retval = self.client.abort_volume_move(
  4439. fake.SHARE_NAME, fake.VSERVER_NAME)
  4440. expected_api_args = {
  4441. 'source-volume': fake.SHARE_NAME,
  4442. 'vserver': fake.VSERVER_NAME,
  4443. }
  4444. self.assertIsNone(retval)
  4445. self.client.send_request.assert_called_once_with(
  4446. 'volume-move-trigger-abort', expected_api_args)
  4447. @ddt.data(True, False)
  4448. def test_trigger_volume_move_cutover_force(self, forced):
  4449. self.mock_object(self.client, 'send_request')
  4450. retval = self.client.trigger_volume_move_cutover(
  4451. fake.SHARE_NAME, fake.VSERVER_NAME, force=forced)
  4452. expected_api_args = {
  4453. 'source-volume': fake.SHARE_NAME,
  4454. 'vserver': fake.VSERVER_NAME,
  4455. 'force': 'true' if forced else 'false',
  4456. }
  4457. self.assertIsNone(retval)
  4458. self.client.send_request.assert_called_once_with(
  4459. 'volume-move-trigger-cutover', expected_api_args)
  4460. def test_get_volume_move_status_no_records(self):
  4461. self.mock_object(self.client, 'send_iter_request')
  4462. self.mock_object(self.client, '_has_records',
  4463. mock.Mock(return_value=False))
  4464. self.assertRaises(exception.NetAppException,
  4465. self.client.get_volume_move_status,
  4466. fake.SHARE_NAME, fake.VSERVER_NAME)
  4467. expected_api_args = {
  4468. 'query': {
  4469. 'volume-move-info': {
  4470. 'volume': fake.SHARE_NAME,
  4471. 'vserver': fake.VSERVER_NAME,
  4472. },
  4473. },
  4474. 'desired-attributes': {
  4475. 'volume-move-info': {
  4476. 'percent-complete': None,
  4477. 'estimated-completion-time': None,
  4478. 'state': None,
  4479. 'details': None,
  4480. 'cutover-action': None,
  4481. 'phase': None,
  4482. },
  4483. },
  4484. }
  4485. self.client.send_iter_request.assert_called_once_with(
  4486. 'volume-move-get-iter', expected_api_args)
  4487. def test_get_volume_move_status(self):
  4488. move_status = netapp_api.NaElement(fake.VOLUME_MOVE_GET_ITER_RESULT)
  4489. self.mock_object(self.client, 'send_iter_request',
  4490. mock.Mock(return_value=move_status))
  4491. actual_status_info = self.client.get_volume_move_status(
  4492. fake.SHARE_NAME, fake.VSERVER_NAME)
  4493. expected_api_args = {
  4494. 'query': {
  4495. 'volume-move-info': {
  4496. 'volume': fake.SHARE_NAME,
  4497. 'vserver': fake.VSERVER_NAME,
  4498. },
  4499. },
  4500. 'desired-attributes': {
  4501. 'volume-move-info': {
  4502. 'percent-complete': None,
  4503. 'estimated-completion-time': None,
  4504. 'state': None,
  4505. 'details': None,
  4506. 'cutover-action': None,
  4507. 'phase': None,
  4508. },
  4509. },
  4510. }
  4511. expected_status_info = {
  4512. 'percent-complete': '82',
  4513. 'estimated-completion-time': '1481919246',
  4514. 'state': 'healthy',
  4515. 'details': 'Cutover Completed::Volume move job finishing move',
  4516. 'cutover-action': 'retry_on_failure',
  4517. 'phase': 'finishing',
  4518. }
  4519. self.assertDictMatch(expected_status_info, actual_status_info)
  4520. self.client.send_iter_request.assert_called_once_with(
  4521. 'volume-move-get-iter', expected_api_args)