stack_and_upgrade_controller_test.js 91 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023
  1. /**
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. var App = require('app');
  19. require('controllers/main/admin/stack_and_upgrade_controller');
  20. require('utils/string_utils');
  21. var testHelpers = require('test/helpers');
  22. describe('App.MainAdminStackAndUpgradeController', function() {
  23. var controller = App.MainAdminStackAndUpgradeController.create({
  24. getDBProperty: Em.K,
  25. setDBProperty: Em.K,
  26. setDBProperties: Em.K,
  27. getDBProperties: Em.K
  28. });
  29. controller.removeObserver('App.upgradeState', controller, 'finish');
  30. describe("#realRepoUrl", function() {
  31. before(function () {
  32. this.mock = sinon.stub(App, 'get');
  33. this.mock.withArgs('apiPrefix').returns('apiPrefix')
  34. .withArgs('stackVersionURL').returns('stackVersionURL');
  35. });
  36. after(function () {
  37. this.mock.restore();
  38. });
  39. it("should be valid", function() {
  40. controller.propertyDidChange('realRepoUrl');
  41. expect(controller.get('realRepoUrl')).to.equal('apiPrefixstackVersionURL/compatible_repository_versions?fields=*,operating_systems/*,operating_systems/repositories/*');
  42. });
  43. });
  44. describe("#realStackUrl", function() {
  45. before(function () {
  46. this.mock = sinon.stub(App, 'get');
  47. this.mock.withArgs('apiPrefix').returns('apiPrefix')
  48. .withArgs('clusterName').returns('clusterName');
  49. });
  50. after(function () {
  51. this.mock.restore();
  52. });
  53. it("should be valid", function() {
  54. controller.propertyDidChange('realStackUrl');
  55. expect(controller.get('realStackUrl')).to.equal('apiPrefix/clusters/clusterName/stack_versions?fields=*,repository_versions/*,repository_versions/operating_systems/OperatingSystems/*,repository_versions/operating_systems/repositories/*');
  56. });
  57. });
  58. describe("#realUpdateUrl", function() {
  59. before(function () {
  60. this.mock = sinon.stub(App, 'get');
  61. this.mock.withArgs('apiPrefix').returns('apiPrefix')
  62. .withArgs('clusterName').returns('clusterName');
  63. });
  64. after(function () {
  65. this.mock.restore();
  66. });
  67. it("realUpdateUrl is valid", function() {
  68. controller.propertyDidChange('realUpdateUrl');
  69. expect(controller.get('realUpdateUrl')).to.equal('apiPrefix/clusters/clusterName/stack_versions?fields=ClusterStackVersions/*');
  70. });
  71. });
  72. describe("#requestStatus", function() {
  73. beforeEach(function() {
  74. this.mock = sinon.stub(App, 'get');
  75. });
  76. afterEach(function() {
  77. this.mock.restore();
  78. });
  79. it("App.upgradeSuspended is true", function() {
  80. this.mock.returns(true);
  81. controller.set('upgradeData', { Upgrade: {request_status: 'ABORTED'}});
  82. controller.propertyDidChange('requestStatus');
  83. expect(controller.get('requestStatus')).to.equal('SUSPENDED');
  84. });
  85. it("state not ABORTED", function() {
  86. this.mock.returns(false);
  87. controller.set('upgradeData', { Upgrade: {request_status: 'INIT'}});
  88. controller.propertyDidChange('requestStatus');
  89. expect(controller.get('requestStatus')).to.equal('INIT');
  90. });
  91. it("upgradeData is null", function() {
  92. this.mock.returns(false);
  93. controller.set('upgradeData', null);
  94. controller.propertyDidChange('requestStatus');
  95. expect(controller.get('requestStatus')).to.be.empty;
  96. });
  97. });
  98. describe("#load()", function() {
  99. beforeEach(function(){
  100. sinon.stub(controller, 'loadUpgradeData').returns({
  101. done: Em.clb
  102. });
  103. sinon.stub(controller, 'loadStackVersionsToModel').returns({
  104. done: Em.clb
  105. });
  106. sinon.stub(controller, 'loadRepoVersionsToModel').returns({
  107. done: Em.clb
  108. });
  109. sinon.stub(App.StackVersion, 'find').returns([Em.Object.create({
  110. state: 'CURRENT',
  111. repositoryVersion: {
  112. repositoryVersion: '2.2',
  113. displayName: 'HDP-2.2'
  114. }
  115. })]);
  116. controller.load();
  117. });
  118. afterEach(function(){
  119. controller.loadUpgradeData.restore();
  120. controller.loadStackVersionsToModel.restore();
  121. controller.loadRepoVersionsToModel.restore();
  122. App.StackVersion.find.restore();
  123. });
  124. it("loadUpgradeData called with valid arguments", function() {
  125. expect(controller.loadUpgradeData.calledWith(true)).to.be.true;
  126. });
  127. it('loadStackVersionsToModel called with valid arguments', function () {
  128. expect(controller.loadStackVersionsToModel.calledWith(true)).to.be.true;
  129. });
  130. it('loadRepoVersionsToModel called once', function () {
  131. expect(controller.loadRepoVersionsToModel.calledOnce).to.be.true;
  132. });
  133. it('currentVersion is corrent', function () {
  134. expect(controller.get('currentVersion')).to.eql({
  135. "repository_version": "2.2",
  136. "repository_name": "HDP-2.2"
  137. });
  138. });
  139. });
  140. describe("#loadUpgradeData()", function() {
  141. it("get entire data", function() {
  142. controller.set('upgradeId', 1);
  143. controller.loadUpgradeData();
  144. var args = testHelpers.findAjaxRequest('name', 'admin.upgrade.data');
  145. expect(args[0]).to.exists;
  146. expect(args[0].sender).to.be.eql(controller);
  147. expect(args[0].data).to.be.eql({
  148. id: 1
  149. });
  150. });
  151. it("get only state", function() {
  152. controller.set('upgradeId', 1);
  153. controller.loadUpgradeData(true);
  154. var args = testHelpers.findAjaxRequest('name', 'admin.upgrade.state');
  155. expect(args[0]).to.exists;
  156. expect(args[0].sender).to.be.eql(controller);
  157. expect(args[0].data).to.be.eql({
  158. id: 1
  159. });
  160. });
  161. it("upgrade id is null", function() {
  162. controller.set('upgradeId', null);
  163. controller.loadUpgradeData();
  164. var args = testHelpers.findAjaxRequest('name', 'admin.upgrade.state');
  165. var args2 = testHelpers.findAjaxRequest('name', 'admin.upgrade.data');
  166. expect(args).to.not.exists;
  167. expect(args2).to.not.exists;
  168. });
  169. });
  170. describe("#loadUpgradeDataSuccessCallback()", function() {
  171. var retryCases = [
  172. {
  173. isRetryPendingInitial: true,
  174. status: 'ABORTED',
  175. isRetryPending: true,
  176. requestInProgress: true,
  177. title: 'retry request not yet applied'
  178. },
  179. {
  180. isRetryPendingInitial: true,
  181. status: 'UPGRADING',
  182. isRetryPending: false,
  183. requestInProgress: false,
  184. title: 'retry request applied'
  185. },
  186. {
  187. isRetryPendingInitial: false,
  188. status: 'ABORTED',
  189. isRetryPending: false,
  190. requestInProgress: true,
  191. title: 'no retry request sent'
  192. },
  193. {
  194. isRetryPendingInitial: false,
  195. status: 'UPGRADING',
  196. isRetryPending: false,
  197. requestInProgress: true,
  198. title: 'upgrade wasn\'t aborted'
  199. }
  200. ];
  201. beforeEach(function () {
  202. sinon.stub(controller, 'updateUpgradeData', Em.K);
  203. sinon.stub(controller, 'setDBProperty', Em.K);
  204. });
  205. afterEach(function () {
  206. controller.updateUpgradeData.restore();
  207. controller.setDBProperty.restore();
  208. });
  209. it("correct data", function() {
  210. var data = {
  211. "Upgrade": {
  212. "request_status": "UPGRADED"
  213. },
  214. "upgrade_groups": [
  215. {
  216. "UpgradeGroup": {
  217. "id": 1
  218. },
  219. "upgrade_items": []
  220. }
  221. ]};
  222. controller.loadUpgradeDataSuccessCallback(data);
  223. expect(App.get('upgradeState')).to.equal('UPGRADED');
  224. expect(controller.updateUpgradeData.calledOnce).to.be.true;
  225. expect(controller.setDBProperty.calledWith('upgradeState', 'UPGRADED')).to.be.true;
  226. });
  227. it("data is null", function() {
  228. var data = null;
  229. controller.loadUpgradeDataSuccessCallback(data);
  230. expect(controller.updateUpgradeData.called).to.be.false;
  231. expect(controller.setDBProperty.called).to.be.false;
  232. });
  233. retryCases.forEach(function (item) {
  234. it(item.title, function () {
  235. var data = {
  236. "Upgrade": {
  237. "request_status": item.status
  238. }
  239. };
  240. controller.setProperties({
  241. isRetryPending: item.isRetryPendingInitial,
  242. requestInProgress: true
  243. });
  244. controller.loadUpgradeDataSuccessCallback(data);
  245. expect(controller.getProperties(['isRetryPending', 'requestInProgress'])).to.eql({
  246. isRetryPending: item.isRetryPending,
  247. requestInProgress: item.requestInProgress
  248. });
  249. });
  250. });
  251. });
  252. describe("#getUpgradeItem()", function() {
  253. it("default callback", function() {
  254. var item = Em.Object.create({
  255. request_id: 1,
  256. group_id: 2,
  257. stage_id: 3
  258. });
  259. controller.getUpgradeItem(item);
  260. var args = testHelpers.findAjaxRequest('name', 'admin.upgrade.upgrade_item');
  261. expect(args[0]).to.exists;
  262. expect(args[0].sender).to.be.eql(controller);
  263. expect(args[0].success).to.be.equal('getUpgradeItemSuccessCallback');
  264. expect(args[0].data).to.be.eql({
  265. upgradeId: 1,
  266. groupId: 2,
  267. stageId: 3
  268. });
  269. });
  270. it("custom callback", function() {
  271. var item = Em.Object.create({
  272. request_id: 1,
  273. group_id: 2,
  274. stage_id: 3
  275. });
  276. controller.getUpgradeItem(item, 'customCallback');
  277. var args = testHelpers.findAjaxRequest('name', 'admin.upgrade.upgrade_item');
  278. expect(args[0]).to.exists;
  279. expect(args[0].sender).to.be.eql(controller);
  280. expect(args[0].success).to.be.equal('customCallback');
  281. expect(args[0].data).to.be.eql({
  282. upgradeId: 1,
  283. groupId: 2,
  284. stageId: 3
  285. });
  286. });
  287. });
  288. describe("#openUpgradeDialog()", function () {
  289. before(function () {
  290. sinon.stub(App.router, 'transitionTo', Em.K);
  291. });
  292. after(function () {
  293. App.router.transitionTo.restore();
  294. });
  295. it("should open dialog", function () {
  296. controller.openUpgradeDialog();
  297. expect(App.router.transitionTo.calledWith('admin.stackUpgrade')).to.be.true;
  298. });
  299. });
  300. describe("#runPreUpgradeCheck()", function() {
  301. it("make ajax call", function() {
  302. controller.runPreUpgradeCheck(Em.Object.create({
  303. repositoryVersion: '2.2',
  304. displayName: 'HDP-2.2',
  305. upgradeType: 'ROLLING',
  306. skipComponentFailures: false,
  307. skipSCFailures: false
  308. }));
  309. var args = testHelpers.findAjaxRequest('name', 'admin.upgrade.pre_upgrade_check');
  310. expect(args[0]).to.exists;
  311. expect(args[0].sender).to.be.eql(controller);
  312. expect(args[0].data).to.be.eql({
  313. value: '2.2',
  314. label: 'HDP-2.2',
  315. type: 'ROLLING',
  316. skipComponentFailures: 'false',
  317. skipSCFailures: 'false'
  318. });
  319. });
  320. });
  321. describe("#runPreUpgradeCheckSuccess()", function () {
  322. var cases = [
  323. {
  324. check: {
  325. "check": "Work-preserving RM/NM restart is enabled in YARN configs",
  326. "status": "FAIL",
  327. "reason": "FAIL",
  328. "failed_on": [],
  329. "check_type": "SERVICE"
  330. },
  331. showClusterCheckPopupCalledCount: 1,
  332. upgradeCalledCount: 0,
  333. title: 'popup is displayed if fails are present'
  334. },
  335. {
  336. check: {
  337. "check": "Configuration Merge Check",
  338. "status": "WARNING",
  339. "reason": "Conflict",
  340. "failed_on": [],
  341. "failed_detail": [
  342. {
  343. type: 't0',
  344. property: 'p0',
  345. current: 'c0',
  346. new_stack_value: 'n0',
  347. result_value: 'n0'
  348. },
  349. {
  350. type: 't1',
  351. property: 'p1',
  352. current: 'c1',
  353. new_stack_value: null,
  354. result_value: 'c1'
  355. },
  356. {
  357. type: 't2',
  358. property: 'p2',
  359. current: 'c2',
  360. new_stack_value: null,
  361. result_value: null
  362. }
  363. ],
  364. "check_type": "CLUSTER",
  365. "id": "CONFIG_MERGE"
  366. },
  367. showClusterCheckPopupCalledCount: 1,
  368. upgradeCalledCount: 0,
  369. configs: [
  370. {
  371. type: 't0',
  372. name: 'p0',
  373. currentValue: 'c0',
  374. recommendedValue: 'n0',
  375. resultingValue: 'n0',
  376. isDeprecated: false,
  377. willBeRemoved: false
  378. },
  379. {
  380. type: 't1',
  381. name: 'p1',
  382. currentValue: 'c1',
  383. recommendedValue: Em.I18n.t('popup.clusterCheck.Upgrade.configsMerge.deprecated'),
  384. resultingValue: 'c1',
  385. isDeprecated: true,
  386. willBeRemoved: false
  387. },
  388. {
  389. type: 't2',
  390. name: 'p2',
  391. currentValue: 'c2',
  392. recommendedValue: Em.I18n.t('popup.clusterCheck.Upgrade.configsMerge.deprecated'),
  393. resultingValue: Em.I18n.t('popup.clusterCheck.Upgrade.configsMerge.willBeRemoved'),
  394. isDeprecated: true,
  395. willBeRemoved: true
  396. }
  397. ],
  398. title: 'popup is displayed if warnings are present; configs merge conflicts'
  399. },
  400. {
  401. check: {
  402. "check": "Work-preserving RM/NM restart is enabled in YARN configs",
  403. "status": "PASS",
  404. "reason": "OK",
  405. "failed_on": [],
  406. "check_type": "SERVICE"
  407. },
  408. showClusterCheckPopupCalledCount: 0,
  409. upgradeCalledCount: 1,
  410. title: 'upgrade is started if fails and warnings are absent'
  411. }
  412. ];
  413. beforeEach(function () {
  414. sinon.stub(App, 'showClusterCheckPopup', Em.K);
  415. sinon.stub(controller, 'upgrade', Em.K);
  416. });
  417. afterEach(function () {
  418. App.showClusterCheckPopup.restore();
  419. controller.upgrade.restore();
  420. });
  421. cases.forEach(function (item) {
  422. it(item.title, function () {
  423. controller.runPreUpgradeCheckSuccess(
  424. {
  425. items: [
  426. {
  427. UpgradeChecks: item.check
  428. }
  429. ]
  430. }, null, {
  431. label: 'name'
  432. }
  433. );
  434. expect(controller.upgrade.callCount).to.equal(item.upgradeCalledCount);
  435. expect(App.showClusterCheckPopup.callCount).to.equal(item.showClusterCheckPopupCalledCount);
  436. if (item.check.id === 'CONFIG_MERGE') {
  437. expect(App.showClusterCheckPopup.firstCall.args[2]).to.eql(item.configs);
  438. }
  439. });
  440. });
  441. });
  442. describe("#initDBProperties()", function() {
  443. before(function () {
  444. this.mock = sinon.stub(controller, 'getDBProperties');
  445. });
  446. after(function () {
  447. this.mock.restore();
  448. });
  449. it("set string properties", function () {
  450. this.mock.returns({prop: 'string'});
  451. controller.initDBProperties();
  452. expect(controller.get('prop')).to.equal('string');
  453. });
  454. it("set number properties", function () {
  455. this.mock.returns({prop: 0});
  456. controller.initDBProperties();
  457. expect(controller.get('prop')).to.equal(0);
  458. });
  459. it("set boolean properties", function () {
  460. this.mock.returns({prop: false});
  461. controller.initDBProperties();
  462. expect(controller.get('prop')).to.be.false;
  463. });
  464. it("set undefined properties", function () {
  465. this.mock.returns({prop: undefined});
  466. controller.set('prop', 'value');
  467. controller.initDBProperties();
  468. expect(controller.get('prop')).to.equal('value');
  469. });
  470. it("set null properties", function () {
  471. this.mock.returns({prop: null});
  472. controller.set('prop', 'value');
  473. controller.initDBProperties();
  474. expect(controller.get('prop')).to.equal('value');
  475. });
  476. });
  477. describe("#init()", function() {
  478. before(function () {
  479. sinon.stub(controller, 'initDBProperties', Em.K);
  480. });
  481. after(function () {
  482. controller.initDBProperties.restore();
  483. });
  484. it("call initDBProperties", function () {
  485. controller.init();
  486. expect(controller.initDBProperties.calledOnce).to.be.true;
  487. });
  488. });
  489. describe("#upgrade()", function() {
  490. var callArgs;
  491. beforeEach(function () {
  492. sinon.stub(controller, 'setDBProperty', Em.K);
  493. controller.set('currentVersion', {
  494. repository_version: '2.2'
  495. });
  496. controller.upgrade({
  497. value: '2.2',
  498. label: 'HDP-2.2'
  499. });
  500. callArgs = testHelpers.findAjaxRequest('name', 'admin.upgrade.start')[0];
  501. });
  502. afterEach(function () {
  503. controller.setDBProperty.restore();
  504. });
  505. it("request-data is valid", function() {
  506. expect(callArgs.data).to.eql({"value": '2.2', "label": 'HDP-2.2'});
  507. });
  508. it('request-name is valid', function () {
  509. expect(callArgs.name).to.equal('admin.upgrade.start');
  510. });
  511. it('request-sender is valid', function () {
  512. expect(callArgs.sender).to.eql(controller);
  513. });
  514. it('callback is valid', function () {
  515. expect(callArgs.success).to.equal('upgradeSuccessCallback');
  516. });
  517. it('callback is called', function () {
  518. expect(callArgs.callback).to.be.called;
  519. });
  520. it('setDBProperty is called with valid data', function () {
  521. expect(controller.setDBProperty.calledWith('currentVersion', {
  522. repository_version: '2.2'
  523. })).to.be.true;
  524. });
  525. });
  526. describe("#upgradeSuccessCallback()", function() {
  527. beforeEach(function () {
  528. sinon.stub(App.clusterStatus, 'setClusterStatus', Em.K);
  529. sinon.stub(controller, 'openUpgradeDialog', Em.K);
  530. sinon.stub(controller, 'setDBProperties', Em.K);
  531. sinon.stub(controller, 'load', Em.K);
  532. var data = {
  533. resources: [
  534. {
  535. Upgrade: {
  536. request_id: 1
  537. }
  538. }
  539. ]
  540. };
  541. controller.upgradeSuccessCallback(data, {}, {label: 'HDP-2.2.1', isDowngrade: true});
  542. });
  543. afterEach(function () {
  544. App.clusterStatus.setClusterStatus.restore();
  545. controller.openUpgradeDialog.restore();
  546. controller.setDBProperties.restore();
  547. controller.load.restore();
  548. });
  549. it('load is called ocne', function() {
  550. expect(controller.load.calledOnce).to.be.true;
  551. });
  552. it('upgradeVersion is HDP-2.2.1', function() {
  553. expect(controller.get('upgradeVersion')).to.equal('HDP-2.2.1');
  554. });
  555. it('upgradeData is null', function() {
  556. expect(controller.get('upgradeData')).to.be.null;
  557. });
  558. it('isDowngrade is true', function() {
  559. expect(controller.get('isDowngrade')).to.be.true;
  560. });
  561. it('App.clusterStatus.setClusterStatus is called once', function() {
  562. expect(App.clusterStatus.setClusterStatus.calledOnce).to.be.true;
  563. });
  564. it('controller.openUpgradeDialog is called once', function() {
  565. expect(controller.openUpgradeDialog.calledOnce).to.be.true;
  566. });
  567. });
  568. describe("#updateUpgradeData()", function() {
  569. beforeEach(function () {
  570. sinon.stub(controller, 'initUpgradeData', Em.K);
  571. });
  572. afterEach(function () {
  573. controller.initUpgradeData.restore();
  574. });
  575. it("data loaded first time", function() {
  576. controller.set('upgradeData', null);
  577. controller.updateUpgradeData({});
  578. expect(controller.initUpgradeData.calledWith({})).to.be.true;
  579. });
  580. describe('upgradeData exists', function () {
  581. var groups;
  582. beforeEach(function() {
  583. var oldData = Em.Object.create({
  584. upgradeGroups: [
  585. Em.Object.create({
  586. group_id: 1,
  587. upgradeItems: [
  588. Em.Object.create({
  589. stage_id: 1
  590. })
  591. ]
  592. }),
  593. Em.Object.create({
  594. group_id: 2,
  595. upgradeItems: [
  596. Em.Object.create({
  597. stage_id: 2
  598. }),
  599. Em.Object.create({
  600. stage_id: 3
  601. })
  602. ]
  603. })
  604. ]
  605. });
  606. var newData = {
  607. Upgrade: {
  608. request_id: 1
  609. },
  610. upgrade_groups: [
  611. {
  612. UpgradeGroup: {
  613. group_id: 1,
  614. status: 'COMPLETED',
  615. display_status: 'COMPLETED',
  616. progress_percent: 100,
  617. completed_task_count: 3
  618. },
  619. upgrade_items: [
  620. {
  621. UpgradeItem: {
  622. stage_id: 1,
  623. status: 'COMPLETED',
  624. display_status: 'COMPLETED',
  625. progress_percent: 100
  626. }
  627. }
  628. ]
  629. },
  630. {
  631. UpgradeGroup: {
  632. group_id: 2,
  633. status: 'ABORTED',
  634. display_status: 'ABORTED',
  635. progress_percent: 50,
  636. completed_task_count: 1
  637. },
  638. upgrade_items: [
  639. {
  640. UpgradeItem: {
  641. stage_id: 2,
  642. status: 'ABORTED',
  643. display_status: 'ABORTED',
  644. progress_percent: 99
  645. }
  646. },
  647. {
  648. UpgradeItem: {
  649. stage_id: 3,
  650. status: 'PENDING',
  651. display_status: 'PENDING',
  652. progress_percent: 0
  653. }
  654. }
  655. ]
  656. }
  657. ]
  658. };
  659. controller.set('upgradeData', oldData);
  660. controller.updateUpgradeData(newData);
  661. groups = controller.get('upgradeData.upgradeGroups');
  662. });
  663. describe("checking 1st group", function() {
  664. it('status is COMPLETED', function () {
  665. expect(groups[0].get('status')).to.equal('COMPLETED');
  666. });
  667. it('display_status is COMPLETED', function () {
  668. expect(groups[0].get('display_status')).to.equal('COMPLETED');
  669. });
  670. it('progress_percent is 100', function () {
  671. expect(groups[0].get('progress_percent')).to.equal(100);
  672. });
  673. it('completed_task_count = 3', function () {
  674. expect(groups[0].get('completed_task_count')).to.equal(3);
  675. });
  676. it('upgradeItems.0.status is COMPLETED', function () {
  677. expect(groups[0].get('upgradeItems')[0].get('status')).to.equal('COMPLETED');
  678. });
  679. it('upgradeItems.0.display_status is COMPLETED', function () {
  680. expect(groups[0].get('upgradeItems')[0].get('display_status')).to.equal('COMPLETED');
  681. });
  682. it('upgradeItems.0.progress_percent is 100', function () {
  683. expect(groups[0].get('upgradeItems')[0].get('progress_percent')).to.equal(100);
  684. });
  685. it('hasExpandableItems is true', function () {
  686. expect(groups[0].get('hasExpandableItems')).to.be.true;
  687. });
  688. });
  689. describe('checking 2nd group', function () {
  690. it('status is ABORTED', function () {
  691. expect(groups[1].get('status')).to.equal('ABORTED');
  692. });
  693. it('display_status is ABORTED', function () {
  694. expect(groups[1].get('display_status')).to.equal('ABORTED');
  695. });
  696. it('progress_percent is 50', function () {
  697. expect(groups[1].get('progress_percent')).to.equal(50);
  698. });
  699. it('completed_task_count = 1', function () {
  700. expect(groups[1].get('completed_task_count')).to.equal(1);
  701. });
  702. it('upgradeItems.[].status = ["ABORTED", "PENDING"]', function () {
  703. expect(groups[1].get('upgradeItems').mapProperty('status')).to.eql(['ABORTED', 'PENDING']);
  704. });
  705. it('upgradeItems.[].display_status = ["ABORTED", "PENDING"]', function () {
  706. expect(groups[1].get('upgradeItems').mapProperty('display_status')).to.eql(['ABORTED', 'PENDING']);
  707. });
  708. it('upgradeItems.[].progress_percent = [99, 0]', function () {
  709. expect(groups[1].get('upgradeItems').mapProperty('progress_percent')).to.eql([99, 0]);
  710. });
  711. it('hasExpandableItems is false', function () {
  712. expect(groups[1].get('hasExpandableItems')).to.be.false;
  713. });
  714. });
  715. });
  716. });
  717. describe("#initUpgradeData()", function() {
  718. beforeEach(function () {
  719. sinon.stub(controller, 'setDBProperty');
  720. sinon.stub(controller, 'formatMessages');
  721. var newData = {
  722. Upgrade: {
  723. request_id: 1,
  724. downgrade_allowed: false
  725. },
  726. upgrade_groups: [
  727. {
  728. UpgradeGroup: {
  729. group_id: 1
  730. },
  731. upgrade_items: [
  732. {
  733. UpgradeItem: {
  734. stage_id: 1,
  735. status: 'IN_PROGRESS'
  736. }
  737. },
  738. {
  739. UpgradeItem: {
  740. stage_id: 2
  741. }
  742. }
  743. ]
  744. },
  745. {
  746. UpgradeGroup: {
  747. group_id: 2
  748. },
  749. upgrade_items: []
  750. },
  751. {
  752. UpgradeGroup: {
  753. group_id: 3
  754. },
  755. upgrade_items: [
  756. {
  757. UpgradeItem: {
  758. stage_id: 3,
  759. status: 'ABORTED'
  760. }
  761. },
  762. {
  763. UpgradeItem: {
  764. stage_id: 4,
  765. status: 'PENDING'
  766. }
  767. }
  768. ]
  769. }
  770. ]
  771. };
  772. controller.initUpgradeData(newData);
  773. });
  774. afterEach(function () {
  775. controller.setDBProperty.restore();
  776. controller.formatMessages.restore();
  777. });
  778. it("setDBProperty called with valid arguments", function() {
  779. expect(controller.setDBProperty.calledWith('downgradeAllowed', false)).to.be.true;
  780. });
  781. it('downgradeAllowed is false', function () {
  782. expect(controller.get('downgradeAllowed')).to.be.false;
  783. });
  784. it('upgradeData.Upgrade.request_id is 1', function () {
  785. expect(controller.get('upgradeData.Upgrade.request_id')).to.equal(1);
  786. });
  787. it('upgradeData.upgradeGroups contain valid data', function () {
  788. var groups = controller.get('upgradeData.upgradeGroups');
  789. expect(groups.mapProperty('group_id')).to.eql([3,2,1]);
  790. expect(groups[2].get('upgradeItems').mapProperty('stage_id')).to.eql([2,1]);
  791. expect(groups.mapProperty('hasExpandableItems')).to.eql([false, false, true]);
  792. });
  793. });
  794. describe.skip("#finish()", function() {
  795. before(function () {
  796. sinon.stub(App.clusterStatus, 'setClusterStatus', Em.K);
  797. sinon.stub(controller, 'setDBProperty', Em.K);
  798. });
  799. after(function () {
  800. App.clusterStatus.setClusterStatus.restore();
  801. controller.setDBProperty.restore();
  802. });
  803. it("upgradeState is not COMPLETED", function() {
  804. App.set('upgradeState', 'UPGRADING');
  805. controller.finish();
  806. expect(App.clusterStatus.setClusterStatus.called).to.be.false;
  807. });
  808. it("upgradeState is COMPLETED", function() {
  809. App.set('upgradeState', 'COMPLETED');
  810. controller.finish();
  811. expect(controller.setDBProperty.calledWith('upgradeId', undefined)).to.be.true;
  812. expect(controller.setDBProperty.calledWith('upgradeVersion', undefined)).to.be.true;
  813. expect(controller.setDBProperty.calledWith('upgradeState', 'INIT')).to.be.true;
  814. expect(controller.setDBProperty.calledWith('currentVersion', undefined)).to.be.true;
  815. expect(App.get('upgradeState')).to.equal('INIT');
  816. expect(App.clusterStatus.setClusterStatus.calledOnce).to.be.true;
  817. });
  818. });
  819. describe("#confirmDowngrade()", function() {
  820. before(function () {
  821. sinon.spy(App, 'showConfirmationPopup');
  822. sinon.stub(controller, 'downgrade', Em.K);
  823. });
  824. after(function () {
  825. App.showConfirmationPopup.restore();
  826. controller.downgrade.restore();
  827. });
  828. it("show confirmation popup", function() {
  829. controller.set('currentVersion', Em.Object.create({
  830. repository_version: '2.2',
  831. repository_name: 'HDP-2.2'
  832. }));
  833. var popup = controller.confirmDowngrade();
  834. expect(App.showConfirmationPopup.calledOnce).to.be.true;
  835. popup.onPrimary();
  836. expect(controller.downgrade.calledWith(Em.Object.create({
  837. repository_version: '2.2',
  838. repository_name: 'HDP-2.2'
  839. }))).to.be.true;
  840. });
  841. });
  842. describe("#upgradeOptions()", function() {
  843. var version = Em.Object.create({displayName: 'HDP-2.2'});
  844. beforeEach(function () {
  845. sinon.spy(App.ModalPopup, 'show');
  846. sinon.spy(App, 'showConfirmationFeedBackPopup');
  847. sinon.stub(controller, 'getSupportedUpgradeTypes').returns({
  848. done: function (callback) {
  849. callback([1]);
  850. return {
  851. always: function (alwaysCallback) {
  852. alwaysCallback();
  853. return {};
  854. }
  855. };
  856. }
  857. });
  858. sinon.stub(controller, 'runPreUpgradeCheck', Em.K);
  859. sinon.stub(App.RepositoryVersion, 'find').returns([
  860. Em.Object.create({
  861. status: 'CURRENT'
  862. })
  863. ]);
  864. controller.get('runningCheckRequests').clear();
  865. });
  866. afterEach(function () {
  867. App.ModalPopup.show.restore();
  868. App.showConfirmationFeedBackPopup.restore();
  869. controller.runPreUpgradeCheck.restore();
  870. controller.getSupportedUpgradeTypes.restore();
  871. controller.get('upgradeMethods').setEach('selected', false);
  872. App.RepositoryVersion.find.restore();
  873. });
  874. describe("show confirmation popup", function() {
  875. beforeEach(function () {
  876. controller.set('isDowngrade', false);
  877. this.popup = controller.upgradeOptions(false, version);
  878. });
  879. it('popup is shown', function () {
  880. expect(App.ModalPopup.show.calledOnce).to.be.true;
  881. });
  882. it('all upgradeMethods have isCheckRequestInProgress = true', function () {
  883. expect(controller.get('upgradeMethods').everyProperty('isCheckRequestInProgress')).to.be.true;
  884. });
  885. it('upgradeMethods no one is selected', function () {
  886. expect(controller.get('upgradeMethods').someProperty('selected')).to.be.false;
  887. });
  888. describe('#popup.onPrimary', function () {
  889. beforeEach(function () {
  890. controller.get('upgradeMethods')[0].set('selected', true);
  891. this.confirmPopup = this.popup.onPrimary();
  892. });
  893. it('showConfirmationFeedBackPopup is called once', function () {
  894. expect(App.showConfirmationFeedBackPopup.calledOnce).to.be.true;
  895. });
  896. describe('#confirmPopup.onPrimary', function () {
  897. beforeEach(function () {
  898. this.confirmPopup.onPrimary();
  899. });
  900. it('runPreUpgradeCheck is called with correct version', function () {
  901. expect(controller.runPreUpgradeCheck.calledWith(version)).to.be.true;
  902. });
  903. it('runningCheckRequests has 1 item', function () {
  904. expect(controller.get('runningCheckRequests')).to.have.length(1);
  905. });
  906. });
  907. });
  908. });
  909. describe("NOT show confirmation popup on Downgrade", function() {
  910. beforeEach(function () {
  911. controller.set('isDowngrade', true);
  912. controller.upgradeOptions(false, version);
  913. });
  914. it('runningCheckRequests has 1 item', function () {
  915. expect( controller.get('runningCheckRequests')).to.have.length(1);
  916. });
  917. });
  918. });
  919. describe("#confirmUpgrade()", function() {
  920. before(function () {
  921. sinon.stub(controller, 'upgradeOptions', Em.K);
  922. });
  923. after(function () {
  924. controller.upgradeOptions.restore();
  925. });
  926. it("show show upgrade options popup window", function() {
  927. var version = Em.Object.create({displayName: 'HDP-2.2'});
  928. controller.confirmUpgrade(version);
  929. expect(controller.upgradeOptions.calledWith(false, version)).to.be.true;
  930. });
  931. });
  932. describe("#downgrade", function() {
  933. beforeEach(function () {
  934. sinon.stub(controller, 'abortUpgrade').returns({
  935. done: function(callback) {callback()}
  936. });
  937. sinon.stub(controller, 'startDowngrade');
  938. controller.downgrade('versionInfo');
  939. });
  940. afterEach(function () {
  941. controller.abortUpgrade.restore();
  942. controller.startDowngrade.restore();
  943. });
  944. it('should run abortUpgrade', function() {
  945. expect(controller.abortUpgrade.calledOnce).to.be.true;
  946. });
  947. it('should run startDowngrade on done', function() {
  948. expect(controller.startDowngrade.calledWith('versionInfo')).to.be.true;
  949. });
  950. });
  951. describe("#startDowngrade()", function() {
  952. beforeEach(function () {
  953. sinon.stub(App.RepositoryVersion, 'find').returns([
  954. Em.Object.create({
  955. displayName: 'HDP-2.3',
  956. repositoryVersion: '2.3'
  957. })
  958. ]);
  959. controller.set('upgradeVersion', 'HDP-2.3');
  960. controller.set('upgradeType', 'NON_ROLLING');
  961. controller.startDowngrade(Em.Object.create({
  962. repository_version: '2.2',
  963. repository_name: 'HDP-2.2'
  964. }));
  965. this.callArgs = testHelpers.findAjaxRequest('name', 'admin.downgrade.start')[0];
  966. });
  967. afterEach(function () {
  968. App.RepositoryVersion.find.restore();
  969. });
  970. it('request-data is valid', function () {
  971. expect(this.callArgs.data).to.eql({
  972. from: '2.3',
  973. value: '2.2',
  974. label: 'HDP-2.2',
  975. isDowngrade: true,
  976. upgradeType: "NON_ROLLING"
  977. });
  978. });
  979. it('request-name is valid', function () {
  980. expect(this.callArgs.name).to.be.equal('admin.downgrade.start');
  981. });
  982. it('request-sender is valid', function () {
  983. expect(this.callArgs.sender).to.be.eql(controller);
  984. });
  985. it('callback is valid', function () {
  986. expect(this.callArgs.success).to.be.equal('upgradeSuccessCallback');
  987. });
  988. it('callback is called', function () {
  989. expect(this.callArgs.callback).to.be.called;
  990. });
  991. });
  992. describe("#installRepoVersionConfirmation()", function () {
  993. before(function () {
  994. sinon.stub(controller, 'installRepoVersion', Em.K);
  995. });
  996. after(function () {
  997. controller.installRepoVersion.restore();
  998. });
  999. it("show popup", function () {
  1000. var repo = Em.Object.create({'displayName': 'HDP-2.2'});
  1001. var popup = controller.installRepoVersionConfirmation(repo);
  1002. popup.onPrimary();
  1003. expect(controller.installRepoVersion.calledWith(repo)).to.be.true;
  1004. });
  1005. });
  1006. describe("#installRepoVersion()", function () {
  1007. it("make ajax call", function () {
  1008. var repo = Em.Object.create({
  1009. stackVersionType: 'HDP',
  1010. stackVersionNumber: '2.2',
  1011. repositoryVersion: '2.2.1',
  1012. repoId: 1
  1013. });
  1014. controller.installRepoVersion(repo);
  1015. var args = testHelpers.findAjaxRequest('name', 'admin.stack_version.install.repo_version');
  1016. expect(args).to.exists;
  1017. });
  1018. });
  1019. describe("#installRepoVersionSuccess()", function() {
  1020. var mock = Em.Object.create({
  1021. id: 1,
  1022. defaultStatus: 'INIT',
  1023. stackVersion: {}
  1024. });
  1025. beforeEach(function () {
  1026. sinon.spy(mock, 'set');
  1027. sinon.stub(App.db, 'set', Em.K);
  1028. sinon.stub(App.clusterStatus, 'setClusterStatus', Em.K);
  1029. sinon.stub(App.RepositoryVersion, 'find').returns(mock);
  1030. sinon.stub(App, 'showAlertPopup');
  1031. });
  1032. afterEach(function () {
  1033. App.db.set.restore();
  1034. App.clusterStatus.setClusterStatus.restore();
  1035. App.RepositoryVersion.find.restore();
  1036. mock.set.restore();
  1037. App.showAlertPopup.restore();
  1038. });
  1039. it("App.showAlertPopup should be called", function() {
  1040. expect(controller.installRepoVersionSuccess({statusText: 'timeout'}, {}, {id: 1})).to.be.false;
  1041. expect(App.showAlertPopup.calledWith(
  1042. Em.I18n.t('admin.stackVersions.upgrade.installPackage.fail.title'),
  1043. Em.I18n.t('admin.stackVersions.upgrade.installPackage.fail.timeout')
  1044. )).to.be.true;
  1045. });
  1046. it("data sdtored to the local db", function() {
  1047. controller.installRepoVersionSuccess({Requests: {id: 1}}, {}, {id: 1});
  1048. expect(App.db.set.calledWith('repoVersionInstall', 'id', [1])).to.be.true;
  1049. });
  1050. it('clusterStatus is updated', function () {
  1051. controller.installRepoVersionSuccess({Requests: {id: 1}}, {}, {id: 1});
  1052. expect(App.clusterStatus.setClusterStatus.calledOnce).to.be.true;
  1053. });
  1054. it('App.RepositoryVersion models have valid states', function () {
  1055. controller.installRepoVersionSuccess({Requests: {id: 1}}, {}, {id: 1});
  1056. expect(App.RepositoryVersion.find.calledWith(1)).to.be.true;
  1057. expect(App.RepositoryVersion.find(1).get('defaultStatus')).to.equal('INSTALLING');
  1058. expect(App.RepositoryVersion.find(1).get('stackVersion.state')).to.equal('INSTALLING');
  1059. });
  1060. });
  1061. describe("#setUpgradeItemStatus()", function () {
  1062. var item;
  1063. beforeEach(function () {
  1064. item = Em.Object.create({
  1065. request_id: 1,
  1066. stage_id: 1,
  1067. group_id: 1
  1068. });
  1069. controller.setUpgradeItemStatus(item, 'PENDING');
  1070. this.callArgs = testHelpers.findAjaxRequest('name', 'admin.upgrade.upgradeItem.setState')[0];
  1071. });
  1072. it('request-data is valid', function () {
  1073. expect(this.callArgs.data).to.be.eql({upgradeId: 1, itemId: 1, groupId: 1, status: 'PENDING'});
  1074. });
  1075. it('request-name is valid', function () {
  1076. expect(this.callArgs.name).to.be.equal('admin.upgrade.upgradeItem.setState');
  1077. });
  1078. it('request-sendeer is valid', function () {
  1079. expect(this.callArgs.sender).to.be.eql(controller);
  1080. });
  1081. it('callback is called', function () {
  1082. expect(this.callArgs.callback).to.be.called;
  1083. });
  1084. it('item.status is PENDING', function () {
  1085. expect(item.get('status')).to.equal('PENDING');
  1086. });
  1087. });
  1088. describe("#prepareRepoForSaving()", function () {
  1089. it("prepare date for saving", function () {
  1090. var repo = Em.Object.create({
  1091. operatingSystems: [
  1092. Em.Object.create({
  1093. osType: "redhat6",
  1094. isDisabled: Em.computed.not('isSelected'),
  1095. repositories: [Em.Object.create({
  1096. "baseUrl": "111121",
  1097. "repoId": "HDP-2.2",
  1098. "repoName": "HDP",
  1099. hasError: false
  1100. }),
  1101. Em.Object.create({
  1102. "baseUrl": "1",
  1103. "repoId": "HDP-UTILS-1.1.0.20",
  1104. "repoName": "HDP-UTILS",
  1105. hasError: false
  1106. })]
  1107. })
  1108. ]
  1109. });
  1110. var result = {
  1111. "operating_systems": [
  1112. {
  1113. "OperatingSystems": {
  1114. "os_type": "redhat6",
  1115. "ambari_managed_repositories": true
  1116. },
  1117. "repositories": [
  1118. {
  1119. "Repositories": {
  1120. "base_url": "111121",
  1121. "repo_id": "HDP-2.2",
  1122. "repo_name": "HDP"
  1123. }
  1124. },
  1125. {
  1126. "Repositories": {
  1127. "base_url": "1",
  1128. "repo_id": "HDP-UTILS-1.1.0.20",
  1129. "repo_name": "HDP-UTILS"
  1130. }
  1131. }
  1132. ]
  1133. }
  1134. ]};
  1135. expect(controller.prepareRepoForSaving(repo)).to.eql(result);
  1136. });
  1137. });
  1138. describe("#getStackVersionNumber()", function(){
  1139. it("get stack version number", function(){
  1140. var repo = Em.Object.create({
  1141. "stackVersionType": 'HDP',
  1142. "stackVersion": '2.3',
  1143. "repositoryVersion": '2.2.1'
  1144. });
  1145. var stackVersion = controller.getStackVersionNumber(repo);
  1146. expect(stackVersion).to.equal('2.3');
  1147. });
  1148. it("get default stack version number", function(){
  1149. App.set('currentStackVersion', '1.2.3');
  1150. var repo = Em.Object.create({
  1151. "stackVersionType": 'HDP',
  1152. "repositoryVersion": '2.2.1'
  1153. });
  1154. var stackVersion = controller.getStackVersionNumber(repo);
  1155. expect(stackVersion).to.equal('1.2.3');
  1156. });
  1157. });
  1158. describe("#saveRepoOS()", function() {
  1159. before(function(){
  1160. this.mock = sinon.stub(controller, 'validateRepoVersions');
  1161. sinon.stub(controller, 'prepareRepoForSaving', Em.K);
  1162. });
  1163. after(function(){
  1164. this.mock.restore();
  1165. controller.prepareRepoForSaving.restore();
  1166. });
  1167. describe("validation errors present", function() {
  1168. beforeEach(function () {
  1169. this.mock.returns({
  1170. done: function(callback) {callback([1]);}
  1171. });
  1172. controller.saveRepoOS(Em.Object.create({repoVersionId: 1}), true);
  1173. this.args = testHelpers.findAjaxRequest('name', 'admin.stack_versions.edit.repo');
  1174. });
  1175. it('validateRepoVersions is called with valid arguments', function () {
  1176. expect(controller.validateRepoVersions.calledWith(Em.Object.create({repoVersionId: 1}), true)).to.be.true;
  1177. });
  1178. it('prepareRepoForSaving is not called', function () {
  1179. expect(controller.prepareRepoForSaving.called).to.be.false;
  1180. });
  1181. it('no requests are sent', function () {
  1182. expect(this.args).to.not.exists;
  1183. });
  1184. });
  1185. describe("no validation errors", function() {
  1186. beforeEach(function () {
  1187. this.mock.returns({
  1188. done: function(callback) {callback([]);}
  1189. });
  1190. controller.saveRepoOS(Em.Object.create({repoVersionId: 1}), true);
  1191. });
  1192. it('validateRepoVersions is called with valid arguments', function () {
  1193. expect(controller.validateRepoVersions.calledWith(Em.Object.create({repoVersionId: 1}), true)).to.be.true;
  1194. });
  1195. it('prepareRepoForSaving is called with valid arguments', function () {
  1196. expect(controller.prepareRepoForSaving.calledWith(Em.Object.create({repoVersionId: 1}))).to.be.true;
  1197. });
  1198. });
  1199. });
  1200. describe("#validateRepoVersions()", function () {
  1201. it("skip validation", function () {
  1202. controller.validateRepoVersions(Em.Object.create({repoVersionId: 1}), true);
  1203. var args = testHelpers.findAjaxRequest('name', 'admin.stack_versions.validate.repo');
  1204. expect(args).to.not.exists;
  1205. });
  1206. it("do validation", function () {
  1207. var repo = Em.Object.create({
  1208. repoVersionId: 1,
  1209. operatingSystems: [
  1210. Em.Object.create({
  1211. isSelected: true,
  1212. repositories: [
  1213. Em.Object.create()
  1214. ]
  1215. })
  1216. ]
  1217. });
  1218. controller.validateRepoVersions(repo, false);
  1219. var args = testHelpers.findAjaxRequest('name', 'admin.stack_versions.validate.repo');
  1220. expect(args[0]).to.exists;
  1221. });
  1222. });
  1223. describe("#getUrl()", function() {
  1224. beforeEach(function(){
  1225. controller.reopen({
  1226. realStackUrl: 'realStackUrl',
  1227. realRepoUrl: 'realRepoUrl',
  1228. realUpdateUrl: 'realUpdateUrl'
  1229. });
  1230. });
  1231. it("full load is true, stack is null", function() {
  1232. expect(controller.getUrl(null, true)).to.equal('realRepoUrl');
  1233. });
  1234. it("full load is true, stack is valid", function() {
  1235. expect(controller.getUrl({}, true)).to.equal('realStackUrl');
  1236. });
  1237. it("full load is false, stack is valid", function() {
  1238. expect(controller.getUrl({}, false)).to.equal('realUpdateUrl');
  1239. });
  1240. });
  1241. describe("#loadStackVersionsToModel()", function () {
  1242. before(function () {
  1243. sinon.stub(App.HttpClient, 'get');
  1244. });
  1245. after(function () {
  1246. App.HttpClient.get.restore();
  1247. });
  1248. it("HttpClient did get-request", function () {
  1249. controller.loadStackVersionsToModel();
  1250. expect(App.HttpClient.get.calledOnce).to.be.true;
  1251. });
  1252. });
  1253. describe("#loadRepoVersionsToModel()", function () {
  1254. before(function () {
  1255. sinon.stub(App.HttpClient, 'get');
  1256. });
  1257. after(function () {
  1258. App.HttpClient.get.restore();
  1259. });
  1260. it("HttpClient did get-request", function () {
  1261. controller.loadRepoVersionsToModel();
  1262. expect(App.HttpClient.get.calledOnce).to.be.true;
  1263. });
  1264. });
  1265. describe('#currentVersionObserver()', function () {
  1266. var cases = [
  1267. {
  1268. stackVersionType: 'HDP',
  1269. repoVersion: '2.2.1.1.0-1',
  1270. isStormMetricsSupported: false,
  1271. title: 'HDP < 2.2.2'
  1272. },
  1273. {
  1274. stackVersionType: 'HDP',
  1275. repoVersion: '2.2.2.1.0-1',
  1276. isStormMetricsSupported: true,
  1277. title: 'HDP 2.2.2'
  1278. },
  1279. {
  1280. stackVersionType: 'HDP',
  1281. repoVersion: '2.2.3.1.0-1',
  1282. isStormMetricsSupported: true,
  1283. title: 'HDP > 2.2.2'
  1284. },
  1285. {
  1286. stackVersionType: 'BIGTOP',
  1287. repoVersion: '0.8.1.1.0-1',
  1288. isStormMetricsSupported: true,
  1289. title: 'not HDP'
  1290. }
  1291. ];
  1292. afterEach(function () {
  1293. App.RepositoryVersion.find.restore();
  1294. });
  1295. cases.forEach(function (item) {
  1296. describe(item.title, function () {
  1297. beforeEach(function () {
  1298. sinon.stub(App.RepositoryVersion, 'find').returns([
  1299. Em.Object.create({
  1300. status: 'CURRENT',
  1301. stackVersionType: item.stackVersionType
  1302. })
  1303. ]);
  1304. controller.set('currentVersion', {
  1305. repository_version: item.repoVersion
  1306. });
  1307. });
  1308. it('isStormMetricsSupported is ' + (item.isStormMetricsSupported ? '' : 'not') + ' supported', function () {
  1309. expect(App.get('isStormMetricsSupported')).to.equal(item.isStormMetricsSupported);
  1310. });
  1311. });
  1312. });
  1313. });
  1314. describe('#updateFinalize', function () {
  1315. beforeEach(function() {
  1316. controller.set('isFinalizeItem', true);
  1317. this.stub = sinon.stub(App, 'get');
  1318. });
  1319. afterEach(function () {
  1320. this.stub.restore();
  1321. });
  1322. describe('should do ajax-request', function () {
  1323. beforeEach(function () {
  1324. this.stub.withArgs('upgradeState').returns('HOLDING');
  1325. controller.updateFinalize();
  1326. this.args = testHelpers.findAjaxRequest('name', 'admin.upgrade.finalizeContext');
  1327. });
  1328. it('request is sent', function () {
  1329. expect(this.args[0]).to.exists;
  1330. });
  1331. });
  1332. describe('shouldn\'t do ajax-request', function () {
  1333. beforeEach(function () {
  1334. this.stub.withArgs('upgradeState').returns('HOLDING_TIMEDOUT');
  1335. controller.updateFinalize();
  1336. this.args = testHelpers.findAjaxRequest('name', 'admin.upgrade.finalizeContext');
  1337. });
  1338. it('request is not sent', function () {
  1339. expect(this.args).to.not.exists;
  1340. });
  1341. it('isFinalizeItem is false', function () {
  1342. expect(controller.get('isFinalizeItem')).to.be.false;
  1343. });
  1344. });
  1345. });
  1346. describe('#updateFinalizeSuccessCallback', function () {
  1347. it('data exists and Finalize should be true', function() {
  1348. var data = {
  1349. items: [
  1350. {
  1351. upgrade_groups: [
  1352. {
  1353. upgrade_items: [
  1354. {
  1355. UpgradeItem: {
  1356. context: controller.get('finalizeContext'),
  1357. status: "HOLDING"
  1358. }
  1359. }
  1360. ]
  1361. }
  1362. ]
  1363. }
  1364. ]
  1365. };
  1366. controller.set('isFinalizeItem', false);
  1367. controller.updateFinalizeSuccessCallback(data);
  1368. expect(controller.get('isFinalizeItem')).to.be.true;
  1369. });
  1370. it('data exists and Finalize should be false', function() {
  1371. var data = {
  1372. upgrade_groups: [
  1373. {
  1374. upgrade_items: [
  1375. {
  1376. UpgradeItem: {
  1377. context: '!@#$%^&',
  1378. status: "HOLDING"
  1379. }
  1380. }
  1381. ]
  1382. }
  1383. ]
  1384. };
  1385. controller.set('isFinalizeItem', true);
  1386. controller.updateFinalizeSuccessCallback(data);
  1387. expect(controller.get('isFinalizeItem')).to.be.false;
  1388. });
  1389. it('data doesn\'t exist', function() {
  1390. var data = null;
  1391. controller.set('isFinalizeItem', true);
  1392. controller.updateFinalizeSuccessCallback(data);
  1393. expect(controller.get('isFinalizeItem')).to.be.false;
  1394. });
  1395. });
  1396. describe('#updateFinalizeErrorCallback', function () {
  1397. it('should set isFinalizeItem to false', function () {
  1398. controller.set('isFinalizeItem', true);
  1399. controller.updateFinalizeErrorCallback();
  1400. expect(controller.get('isFinalizeItem')).to.be.false;
  1401. });
  1402. });
  1403. describe("#suspendUpgrade()", function() {
  1404. beforeEach(function () {
  1405. sinon.stub(controller, 'abortUpgradeWithSuspend').returns({
  1406. done: Em.clb
  1407. });
  1408. sinon.stub(controller, 'setDBProperty', Em.K);
  1409. sinon.stub(App.clusterStatus, 'setClusterStatus', Em.K);
  1410. controller.suspendUpgrade();
  1411. });
  1412. afterEach(function () {
  1413. controller.abortUpgradeWithSuspend.restore();
  1414. controller.setDBProperty.restore();
  1415. App.clusterStatus.setClusterStatus.restore();
  1416. });
  1417. it("upgrade aborted", function() {
  1418. expect(controller.abortUpgradeWithSuspend.calledOnce).to.be.true;
  1419. });
  1420. it('App.upgradeState is ABORTED', function () {
  1421. expect(App.get('upgradeState')).to.equal('ABORTED');
  1422. });
  1423. it('new upgradeState is saved to the localDB', function () {
  1424. expect(controller.setDBProperty.calledWith('upgradeState', 'ABORTED')).to.be.true;
  1425. });
  1426. it('clusterStatus is updated', function () {
  1427. expect(App.clusterStatus.setClusterStatus.calledOnce).to.be.true;
  1428. });
  1429. });
  1430. describe("#resumeUpgrade()", function() {
  1431. beforeEach(function () {
  1432. sinon.stub(controller, 'retryUpgrade').returns({
  1433. done: Em.clb
  1434. });
  1435. sinon.stub(controller, 'setDBProperty', Em.K);
  1436. sinon.stub(App.clusterStatus, 'setClusterStatus', Em.K);
  1437. controller.resumeUpgrade();
  1438. });
  1439. afterEach(function () {
  1440. controller.retryUpgrade.restore();
  1441. controller.setDBProperty.restore();
  1442. App.clusterStatus.setClusterStatus.restore();
  1443. });
  1444. it("Upgrade is retrying", function() {
  1445. expect(controller.retryUpgrade.calledOnce).to.be.true;
  1446. });
  1447. it('App.upgradeState is PENDING', function () {
  1448. expect(App.get('upgradeState')).to.equal('PENDING');
  1449. });
  1450. it('new upgradeState is saved to the localDB', function () {
  1451. expect(controller.setDBProperty.calledWith('upgradeState', 'PENDING')).to.be.true;
  1452. });
  1453. it('clusterStatus is updated', function () {
  1454. expect(App.clusterStatus.setClusterStatus.calledOnce).to.be.true;
  1455. });
  1456. });
  1457. describe("#runUpgradeMethodChecks()", function() {
  1458. beforeEach(function () {
  1459. sinon.stub(controller, 'runPreUpgradeCheckOnly');
  1460. });
  1461. afterEach(function () {
  1462. controller.runPreUpgradeCheckOnly.restore();
  1463. controller.get('upgradeMethods').setEach('allowed', true);
  1464. });
  1465. it("no allowed upgrade methods", function () {
  1466. controller.get('upgradeMethods').setEach('allowed', false);
  1467. controller.runUpgradeMethodChecks();
  1468. expect(controller.runPreUpgradeCheckOnly.called).to.be.false;
  1469. });
  1470. it("Rolling method allowed", function () {
  1471. controller.get('upgradeMethods').setEach('allowed', true);
  1472. controller.runUpgradeMethodChecks(Em.Object.create({
  1473. repositoryVersion: 'v1',
  1474. displayName: 'V1'
  1475. }));
  1476. expect(controller.runPreUpgradeCheckOnly.calledWith({
  1477. value: 'v1',
  1478. label: 'V1',
  1479. type: 'ROLLING'
  1480. })).to.be.true;
  1481. });
  1482. });
  1483. describe("#restoreLastUpgrade()", function () {
  1484. var data = {
  1485. Upgrade: {
  1486. request_id: 1,
  1487. direction: 'UPGRADE',
  1488. request_status: 'PENDING',
  1489. upgrade_type: 'ROLLING',
  1490. downgrade_allowed: true,
  1491. skip_failures: true,
  1492. skip_service_check_failures: true,
  1493. to_version: '1'
  1494. }
  1495. };
  1496. beforeEach(function () {
  1497. sinon.stub(App.RepositoryVersion, 'find').returns([Em.Object.create({
  1498. repositoryVersion: '1',
  1499. displayName: 'HDP-1'
  1500. })]);
  1501. sinon.stub(controller, 'setDBProperties');
  1502. sinon.stub(controller, 'loadRepoVersionsToModel', function () {
  1503. return {
  1504. done: function (callback) {
  1505. callback();
  1506. }
  1507. }
  1508. });
  1509. sinon.stub(controller, 'setDBProperty');
  1510. sinon.stub(controller, 'initDBProperties');
  1511. sinon.stub(controller, 'loadUpgradeData');
  1512. controller.restoreLastUpgrade(data);
  1513. });
  1514. afterEach(function () {
  1515. App.RepositoryVersion.find.restore();
  1516. controller.setDBProperties.restore();
  1517. controller.loadRepoVersionsToModel.restore();
  1518. controller.setDBProperty.restore();
  1519. controller.initDBProperties.restore();
  1520. controller.loadUpgradeData.restore();
  1521. });
  1522. it('proper data is saved to the localDB', function () {
  1523. expect(controller.setDBProperties.getCall(0).args[0]).to.eql({
  1524. upgradeId: 1,
  1525. isDowngrade: false,
  1526. upgradeState: 'PENDING',
  1527. upgradeType: "ROLLING",
  1528. downgradeAllowed: true,
  1529. upgradeTypeDisplayName: Em.I18n.t('admin.stackVersions.version.upgrade.upgradeOptions.RU.title'),
  1530. failuresTolerance: Em.Object.create({
  1531. skipComponentFailures: true,
  1532. skipSCFailures: true
  1533. })
  1534. });
  1535. });
  1536. it('models are saved', function () {
  1537. expect(controller.loadRepoVersionsToModel.calledOnce).to.be.true;
  1538. });
  1539. it('correct upgradeVersion is saved to the DB', function () {
  1540. expect(controller.setDBProperty.calledWith('upgradeVersion', 'HDP-1')).to.be.true;
  1541. });
  1542. it('initDBProperties is called', function () {
  1543. expect(controller.initDBProperties.calledOnce).to.be.true;
  1544. });
  1545. it('loadUpgradeData called with valid arguments', function () {
  1546. expect(controller.loadUpgradeData.calledWith(true)).to.be.true;
  1547. });
  1548. });
  1549. describe("#getServiceCheckItemSuccessCallback()", function() {
  1550. var testCases = [
  1551. {
  1552. title: 'no tasks',
  1553. data: {
  1554. tasks: []
  1555. },
  1556. expected: {
  1557. slaveComponentStructuredInfo: null,
  1558. serviceCheckFailuresServicenames: []
  1559. }
  1560. },
  1561. {
  1562. title: 'no structured_out property',
  1563. data: {
  1564. tasks: [
  1565. {
  1566. Tasks: {}
  1567. }
  1568. ]
  1569. },
  1570. expected: {
  1571. slaveComponentStructuredInfo: null,
  1572. serviceCheckFailuresServicenames: []
  1573. }
  1574. },
  1575. {
  1576. title: 'no failures',
  1577. data: {
  1578. tasks: [
  1579. {
  1580. Tasks: {
  1581. structured_out: {}
  1582. }
  1583. }
  1584. ]
  1585. },
  1586. expected: {
  1587. slaveComponentStructuredInfo: null,
  1588. serviceCheckFailuresServicenames: []
  1589. }
  1590. },
  1591. {
  1592. title: 'service check failures',
  1593. data: {
  1594. tasks: [
  1595. {
  1596. Tasks: {
  1597. structured_out: {
  1598. failures: {
  1599. service_check: ['HDSF', 'YARN']
  1600. }
  1601. }
  1602. }
  1603. }
  1604. ]
  1605. },
  1606. expected: {
  1607. slaveComponentStructuredInfo: {
  1608. hosts: [],
  1609. host_detail: {}
  1610. },
  1611. serviceCheckFailuresServicenames: ['HDSF', 'YARN']
  1612. }
  1613. },
  1614. {
  1615. title: 'host-component failures',
  1616. data: {
  1617. tasks: [
  1618. {
  1619. Tasks: {
  1620. structured_out: {
  1621. failures: {
  1622. service_check: ['HDSF'],
  1623. host_component: {
  1624. "host1": [
  1625. {
  1626. component: "DATANODE",
  1627. service: 'HDFS'
  1628. }
  1629. ]
  1630. }
  1631. }
  1632. }
  1633. }
  1634. }
  1635. ]
  1636. },
  1637. expected: {
  1638. slaveComponentStructuredInfo: {
  1639. hosts: ['host1'],
  1640. host_detail: {
  1641. "host1": [
  1642. {
  1643. component: "DATANODE",
  1644. service: 'HDFS'
  1645. }
  1646. ]
  1647. }
  1648. },
  1649. serviceCheckFailuresServicenames: ['HDSF']
  1650. }
  1651. }
  1652. ];
  1653. testCases.forEach(function(test) {
  1654. it(test.title, function() {
  1655. controller.set('slaveComponentStructuredInfo', null);
  1656. controller.set('serviceCheckFailuresServicenames', []);
  1657. controller.getServiceCheckItemSuccessCallback(test.data);
  1658. expect(controller.get('serviceCheckFailuresServicenames')).eql(test.expected.serviceCheckFailuresServicenames);
  1659. expect(controller.get('slaveComponentStructuredInfo')).eql(test.expected.slaveComponentStructuredInfo);
  1660. });
  1661. });
  1662. });
  1663. describe("#getSlaveComponentItemSuccessCallback()", function () {
  1664. var testCases = [
  1665. {
  1666. title: 'no tasks',
  1667. data: {
  1668. tasks: []
  1669. },
  1670. expected: {
  1671. slaveComponentStructuredInfo: null
  1672. }
  1673. },
  1674. {
  1675. title: 'structured_out property absent',
  1676. data: {
  1677. tasks: [
  1678. {
  1679. Tasks: {}
  1680. }
  1681. ]
  1682. },
  1683. expected: {
  1684. slaveComponentStructuredInfo: null
  1685. }
  1686. },
  1687. {
  1688. title: 'structured_out property present',
  1689. data: {
  1690. tasks: [
  1691. {
  1692. Tasks: {
  1693. "structured_out" : {
  1694. "hosts" : [
  1695. "host1"
  1696. ],
  1697. "host_detail" : {
  1698. "host1" : [
  1699. {
  1700. "service" : "FLUME",
  1701. "component" : "FLUME_HANDLER"
  1702. }
  1703. ]
  1704. }
  1705. }
  1706. }
  1707. }
  1708. ]
  1709. },
  1710. expected: {
  1711. slaveComponentStructuredInfo: {
  1712. "hosts" : [
  1713. "host1"
  1714. ],
  1715. "host_detail" : {
  1716. "host1" : [
  1717. {
  1718. "service" : "FLUME",
  1719. "component" : "FLUME_HANDLER"
  1720. }
  1721. ]
  1722. }
  1723. }
  1724. }
  1725. }
  1726. ];
  1727. testCases.forEach(function (test) {
  1728. it(test.title, function () {
  1729. controller.set('slaveComponentStructuredInfo', null);
  1730. controller.getSlaveComponentItemSuccessCallback(test.data);
  1731. expect(controller.get('slaveComponentStructuredInfo')).eql(test.expected.slaveComponentStructuredInfo);
  1732. });
  1733. });
  1734. });
  1735. describe('#getConfigsWarnings', function () {
  1736. var cases = [
  1737. {
  1738. configs: [],
  1739. title: 'no warning'
  1740. },
  1741. {
  1742. configsMergeWarning: {},
  1743. configs: [],
  1744. title: 'empty data'
  1745. },
  1746. {
  1747. configsMergeWarning: {
  1748. UpgradeChecks: {}
  1749. },
  1750. configs: [],
  1751. title: 'incomplete data'
  1752. },
  1753. {
  1754. configsMergeWarning: {
  1755. UpgradeChecks: {
  1756. failed_detail: {}
  1757. }
  1758. },
  1759. configs: [],
  1760. title: 'invalid data'
  1761. },
  1762. {
  1763. configsMergeWarning: {
  1764. UpgradeChecks: {
  1765. failed_detail: []
  1766. }
  1767. },
  1768. configs: [],
  1769. title: 'empty configs array'
  1770. },
  1771. {
  1772. configsMergeWarning: {
  1773. UpgradeChecks: {
  1774. status: 'FAIL',
  1775. failed_detail: [
  1776. {
  1777. type: 't0',
  1778. property: 'p0',
  1779. current: 'c0',
  1780. new_stack_value: 'n0',
  1781. result_value: 'r0'
  1782. },
  1783. {
  1784. type: 't1',
  1785. property: 'p1',
  1786. current: 'c1',
  1787. new_stack_value: 'n1'
  1788. },
  1789. {
  1790. type: 't2',
  1791. property: 'p2',
  1792. current: 'c2',
  1793. result_value: 'r2'
  1794. }
  1795. ]
  1796. }
  1797. },
  1798. configs: [],
  1799. title: 'not a warning'
  1800. },
  1801. {
  1802. configsMergeWarning: {
  1803. UpgradeChecks: {
  1804. status: 'WARNING',
  1805. failed_detail: [
  1806. {
  1807. type: 't0',
  1808. property: 'p0',
  1809. current: 'c0',
  1810. new_stack_value: 'n0',
  1811. result_value: 'r0'
  1812. },
  1813. {
  1814. type: 't1',
  1815. property: 'p1',
  1816. current: 'c1',
  1817. new_stack_value: 'n1'
  1818. },
  1819. {
  1820. type: 't2',
  1821. property: 'p2',
  1822. current: 'c2',
  1823. result_value: 'r2'
  1824. }
  1825. ]
  1826. }
  1827. },
  1828. configs: [
  1829. {
  1830. type: 't0',
  1831. name: 'p0',
  1832. currentValue: 'c0',
  1833. recommendedValue: 'n0',
  1834. isDeprecated: false,
  1835. resultingValue: 'r0',
  1836. willBeRemoved: false
  1837. },
  1838. {
  1839. type: 't1',
  1840. name: 'p1',
  1841. currentValue: 'c1',
  1842. recommendedValue: 'n1',
  1843. isDeprecated: false,
  1844. resultingValue: Em.I18n.t('popup.clusterCheck.Upgrade.configsMerge.willBeRemoved'),
  1845. willBeRemoved: true
  1846. },
  1847. {
  1848. type: 't2',
  1849. name: 'p2',
  1850. currentValue: 'c2',
  1851. recommendedValue: Em.I18n.t('popup.clusterCheck.Upgrade.configsMerge.deprecated'),
  1852. isDeprecated: true,
  1853. resultingValue: 'r2',
  1854. willBeRemoved: false
  1855. }
  1856. ],
  1857. title: 'normal case'
  1858. }
  1859. ];
  1860. cases.forEach(function (item) {
  1861. it(item.title, function () {
  1862. expect(controller.getConfigsWarnings(item.configsMergeWarning)).to.eql(item.configs);
  1863. });
  1864. });
  1865. });
  1866. describe('#runPreUpgradeCheckOnly', function () {
  1867. var appGetMock,
  1868. upgradeMethods = controller.get('upgradeMethods'),
  1869. cases = [
  1870. {
  1871. supportsPreUpgradeCheck: false,
  1872. ru: {
  1873. isCheckComplete: true,
  1874. isCheckRequestInProgress: false,
  1875. action: 'a'
  1876. },
  1877. eu: {
  1878. isCheckComplete: true,
  1879. isCheckRequestInProgress: false,
  1880. action: 'a'
  1881. },
  1882. ajaxCallCount: 0,
  1883. runningCheckRequestsLength: 0,
  1884. title: 'pre-upgrade checks not supported'
  1885. },
  1886. {
  1887. supportsPreUpgradeCheck: true,
  1888. ru: {
  1889. isCheckComplete: false,
  1890. isCheckRequestInProgress: true,
  1891. action: ''
  1892. },
  1893. eu: {
  1894. isCheckComplete: true,
  1895. isCheckRequestInProgress: false,
  1896. action: 'a'
  1897. },
  1898. ajaxCallCount: 1,
  1899. type: 'ROLLING',
  1900. runningCheckRequestsLength: 1,
  1901. title: 'rolling upgrade'
  1902. },
  1903. {
  1904. supportsPreUpgradeCheck: true,
  1905. ru: {
  1906. isCheckComplete: true,
  1907. isCheckRequestInProgress: false,
  1908. action: 'a'
  1909. },
  1910. eu: {
  1911. isCheckComplete: false,
  1912. isCheckRequestInProgress: true,
  1913. action: ''
  1914. },
  1915. ajaxCallCount: 1,
  1916. type: 'NON_ROLLING',
  1917. runningCheckRequestsLength: 1,
  1918. title: 'express upgrade'
  1919. }
  1920. ];
  1921. beforeEach(function () {
  1922. appGetMock = sinon.stub(App, 'get');
  1923. controller.get('runningCheckRequests').clear();
  1924. upgradeMethods.forEach(function (method) {
  1925. method.setProperties({
  1926. isCheckComplete: true,
  1927. isCheckRequestInProgress: false,
  1928. action: 'a'
  1929. });
  1930. });
  1931. App.ajax.send.restore();
  1932. sinon.stub(App.ajax, 'send').returns({});
  1933. });
  1934. afterEach(function () {
  1935. appGetMock.restore();
  1936. });
  1937. cases.forEach(function (item) {
  1938. describe(item.title, function () {
  1939. var runningCheckRequests;
  1940. beforeEach(function () {
  1941. runningCheckRequests = controller.get('runningCheckRequests');
  1942. appGetMock.returns(item.supportsPreUpgradeCheck);
  1943. controller.runPreUpgradeCheckOnly({
  1944. type: item.type
  1945. });
  1946. this.ajaxCalls = testHelpers.filterAjaxRequests('name', 'admin.upgrade.pre_upgrade_check');
  1947. });
  1948. it('ROLLING properties', function () {
  1949. expect(upgradeMethods.findProperty('type', 'ROLLING').getProperties('isCheckComplete', 'isCheckRequestInProgress', 'action')).to.eql(item.ru);
  1950. });
  1951. it('NON_ROLLING properties', function () {
  1952. expect(upgradeMethods.findProperty('type', 'NON_ROLLING').getProperties('isCheckComplete', 'isCheckRequestInProgress', 'action')).to.eql(item.eu);
  1953. });
  1954. it(item.ajaxCallCount + ' requests sent', function () {
  1955. expect(this.ajaxCalls.length).to.be.equal(item.ajaxCallCount);
  1956. });
  1957. it('runningCheckRequests length is ' + item.runningCheckRequestsLength, function () {
  1958. expect(runningCheckRequests).to.have.length(item.runningCheckRequestsLength);
  1959. });
  1960. if (item.runningCheckRequestsLength) {
  1961. it('runningCheckRequests.type is ' + item.type, function () {
  1962. expect(runningCheckRequests[0].type).to.equal(item.type);
  1963. });
  1964. }
  1965. });
  1966. });
  1967. });
  1968. describe("#openConfigsInNewWindow()", function () {
  1969. var mock = {
  1970. document: {
  1971. write: function () {}
  1972. },
  1973. focus: function () {}
  1974. };
  1975. beforeEach(function(){
  1976. sinon.stub(window, 'open', function () {
  1977. return mock;
  1978. });
  1979. sinon.spy(mock.document, 'write');
  1980. sinon.spy(mock, 'focus');
  1981. controller.openConfigsInNewWindow({
  1982. context: [
  1983. {
  1984. type: 'type1',
  1985. name: 'name1',
  1986. currentValue: 'currentValue1',
  1987. recommendedValue: 'recommendedValue1',
  1988. resultingValue: 'resultingValue1'
  1989. },
  1990. {
  1991. type: 'type2',
  1992. name: 'name2',
  1993. currentValue: 'currentValue2',
  1994. recommendedValue: 'recommendedValue2',
  1995. resultingValue: 'resultingValue2'
  1996. }
  1997. ]
  1998. });
  1999. });
  2000. afterEach(function(){
  2001. window.open.restore();
  2002. mock.document.write.restore();
  2003. mock.focus.restore();
  2004. });
  2005. it('new window is open', function () {
  2006. expect(window.open.calledOnce).to.be.true;
  2007. });
  2008. it('new window content is valid', function () {
  2009. /*eslint-disable no-useless-concat */
  2010. expect(mock.document.write.calledWith('<table style="text-align: left;"><thead><tr>' +
  2011. '<th>' + Em.I18n.t('popup.clusterCheck.Upgrade.configsMerge.configType') + '</th>' +
  2012. '<th>' + Em.I18n.t('popup.clusterCheck.Upgrade.configsMerge.propertyName') + '</th>' +
  2013. '<th>' + Em.I18n.t('popup.clusterCheck.Upgrade.configsMerge.currentValue') + '</th>' +
  2014. '<th>' + Em.I18n.t('popup.clusterCheck.Upgrade.configsMerge.recommendedValue') + '</th>' +
  2015. '<th>' + Em.I18n.t('popup.clusterCheck.Upgrade.configsMerge.resultingValue') + '</th>' +
  2016. '</tr></thead><tbody>' +
  2017. '<tr>' +
  2018. '<td>' + 'type1' + '</td>' +
  2019. '<td>' + 'name1' + '</td>' +
  2020. '<td>' + 'currentValue1' + '</td>' +
  2021. '<td>' + 'recommendedValue1' + '</td>' +
  2022. '<td>' + 'resultingValue1' + '</td>' +
  2023. '</tr>' +
  2024. '<tr>' +
  2025. '<td>' + 'type2' + '</td>' +
  2026. '<td>' + 'name2' + '</td>' +
  2027. '<td>' + 'currentValue2' + '</td>' +
  2028. '<td>' + 'recommendedValue2' + '</td>' +
  2029. '<td>' + 'resultingValue2' + '</td>' +
  2030. '</tr></tbody></table>')).to.be.true;
  2031. /*eslint-enable no-useless-concat */
  2032. });
  2033. it('document.focus is called once', function () {
  2034. expect(mock.focus.calledOnce).to.be.true;
  2035. });
  2036. });
  2037. describe("#formatMessages()", function () {
  2038. it("item with malformed text", function() {
  2039. var item = Em.Object.create({
  2040. text: null
  2041. });
  2042. controller.formatMessages(item);
  2043. expect(item.get('messages')).to.be.empty;
  2044. expect(item.get('text')).to.be.null;
  2045. });
  2046. it("item with correct text", function() {
  2047. var item = Em.Object.create({
  2048. text: '[{"message":"msg1"},{"message":"msg2"}]'
  2049. });
  2050. controller.formatMessages(item);
  2051. expect(item.get('messages')).to.be.eql(['msg1', 'msg2']);
  2052. expect(item.get('text')).to.be.equal('msg1 msg2');
  2053. });
  2054. });
  2055. describe("#getUpgradeItemSuccessCallback()", function () {
  2056. beforeEach(function() {
  2057. controller.set('upgradeData', Em.Object.create({
  2058. upgradeGroups: [
  2059. Em.Object.create({
  2060. group_id: 'g1',
  2061. upgradeItems: [Em.Object.create({
  2062. stage_id: 'i1',
  2063. tasks: [],
  2064. isTasksLoaded: false
  2065. })]
  2066. })
  2067. ]
  2068. }));
  2069. });
  2070. it("group has different id", function() {
  2071. var data = {UpgradeItem: {group_id: 'g2'}};
  2072. controller.getUpgradeItemSuccessCallback(data);
  2073. expect(controller.get('upgradeData.upgradeGroups')[0].get('upgradeItems')[0].get('isTasksLoaded')).to.be.false;
  2074. });
  2075. it("item has different id", function() {
  2076. var data = {UpgradeItem: {group_id: 'g1', stage_id: 'i2'}};
  2077. controller.getUpgradeItemSuccessCallback(data);
  2078. expect(controller.get('upgradeData.upgradeGroups')[0].get('upgradeItems')[0].get('isTasksLoaded')).to.be.false;
  2079. });
  2080. it("item has no tasks", function() {
  2081. var data = {
  2082. UpgradeItem: {
  2083. group_id: 'g1',
  2084. stage_id: 'i1'
  2085. },
  2086. tasks: [
  2087. {
  2088. Tasks: {id: 't1'}
  2089. }
  2090. ]
  2091. };
  2092. controller.getUpgradeItemSuccessCallback(data);
  2093. expect(controller.get('upgradeData.upgradeGroups')[0].get('upgradeItems')[0].get('isTasksLoaded')).to.be.true;
  2094. expect(controller.get('upgradeData.upgradeGroups')[0].get('upgradeItems')[0].get('tasks')).to.not.be.empty;
  2095. });
  2096. it("item has tasks", function() {
  2097. controller.get('upgradeData.upgradeGroups')[0].get('upgradeItems')[0].set('tasks', [
  2098. Em.Object.create({
  2099. id: 't1',
  2100. status: 'OLD'
  2101. })
  2102. ]);
  2103. var data = {
  2104. UpgradeItem: {
  2105. group_id: 'g1',
  2106. stage_id: 'i1'
  2107. },
  2108. tasks: [
  2109. {
  2110. Tasks: {
  2111. id: 't1',
  2112. status: 'NEW'
  2113. }
  2114. }
  2115. ]
  2116. };
  2117. controller.getUpgradeItemSuccessCallback(data);
  2118. expect(controller.get('upgradeData.upgradeGroups')[0].get('upgradeItems')[0].get('isTasksLoaded')).to.be.true;
  2119. expect(controller.get('upgradeData.upgradeGroups')[0].get('upgradeItems')[0].get('tasks')[0].get('status')).to.be.equal('NEW');
  2120. });
  2121. });
  2122. describe("#abortUpgrade()", function () {
  2123. it("isDowngrade is true", function() {
  2124. controller.set('isDowngrade', true);
  2125. controller.set('upgradeId', 1);
  2126. controller.abortUpgrade();
  2127. var args = testHelpers.findAjaxRequest('name', 'admin.upgrade.abort');
  2128. expect(args[0]).to.be.eql({
  2129. name: 'admin.upgrade.abort',
  2130. sender: controller,
  2131. data: {
  2132. upgradeId: 1,
  2133. isDowngrade: true
  2134. },
  2135. error: 'abortDowngradeErrorCallback'
  2136. });
  2137. });
  2138. it("isDowngrade is false", function() {
  2139. controller.set('isDowngrade', false);
  2140. controller.set('upgradeId', 1);
  2141. controller.abortUpgrade();
  2142. var args = testHelpers.findAjaxRequest('name', 'admin.upgrade.abort');
  2143. expect(args[0]).to.be.eql({
  2144. name: 'admin.upgrade.abort',
  2145. sender: controller,
  2146. data: {
  2147. upgradeId: 1,
  2148. isDowngrade: false
  2149. },
  2150. error: 'abortUpgradeErrorCallback'
  2151. });
  2152. });
  2153. });
  2154. describe("#abortUpgradeWithSuspend()", function () {
  2155. it("isDowngrade is true", function() {
  2156. controller.set('isDowngrade', true);
  2157. controller.set('upgradeId', 1);
  2158. controller.abortUpgradeWithSuspend();
  2159. var args = testHelpers.findAjaxRequest('name', 'admin.upgrade.suspend');
  2160. expect(args[0]).to.be.eql({
  2161. name: 'admin.upgrade.suspend',
  2162. sender: controller,
  2163. data: {
  2164. upgradeId: 1,
  2165. isDowngrade: true
  2166. },
  2167. error: 'abortDowngradeErrorCallback'
  2168. });
  2169. });
  2170. it("isDowngrade is false", function() {
  2171. controller.set('isDowngrade', false);
  2172. controller.set('upgradeId', 1);
  2173. controller.abortUpgradeWithSuspend();
  2174. var args = testHelpers.findAjaxRequest('name', 'admin.upgrade.suspend');
  2175. expect(args[0]).to.be.eql({
  2176. name: 'admin.upgrade.suspend',
  2177. sender: controller,
  2178. data: {
  2179. upgradeId: 1,
  2180. isDowngrade: false
  2181. },
  2182. error: 'abortUpgradeErrorCallback'
  2183. });
  2184. });
  2185. });
  2186. describe("#abortUpgradeErrorCallback()", function () {
  2187. var header = Em.I18n.t('admin.stackUpgrade.state.paused.fail.header');
  2188. var body = Em.I18n.t('admin.stackUpgrade.state.paused.fail.body');
  2189. beforeEach(function() {
  2190. sinon.stub(App, 'showAlertPopup');
  2191. });
  2192. afterEach(function() {
  2193. App.showAlertPopup.restore();
  2194. });
  2195. it("data is null", function() {
  2196. controller.abortUpgradeErrorCallback(null);
  2197. expect(App.showAlertPopup.calledWith(header, body)).to.be.true;
  2198. });
  2199. it("data.responseText is null", function() {
  2200. controller.abortUpgradeErrorCallback({responseText: null});
  2201. expect(App.showAlertPopup.calledWith(header, body)).to.be.true;
  2202. });
  2203. it("data.responseText is incorrect", function() {
  2204. controller.abortUpgradeErrorCallback({responseText: "//"});
  2205. expect(App.showAlertPopup.calledWith(header, body)).to.be.true;
  2206. });
  2207. it("data.responseText is correct", function() {
  2208. controller.abortUpgradeErrorCallback({responseText: '{"message": "msg"}'});
  2209. expect(App.showAlertPopup.calledWith(header, body + ' msg')).to.be.true;
  2210. });
  2211. });
  2212. describe("#abortDowngradeErrorCallback()", function () {
  2213. var header = Em.I18n.t('admin.stackDowngrade.state.paused.fail.header');
  2214. var body = Em.I18n.t('admin.stackDowngrade.state.paused.fail.body');
  2215. beforeEach(function() {
  2216. sinon.stub(App, 'showAlertPopup');
  2217. });
  2218. afterEach(function() {
  2219. App.showAlertPopup.restore();
  2220. });
  2221. it("data is null", function() {
  2222. controller.abortDowngradeErrorCallback(null);
  2223. expect(App.showAlertPopup.calledWith(header, body)).to.be.true;
  2224. });
  2225. it("data.responseText is null", function() {
  2226. controller.abortDowngradeErrorCallback({responseText: null});
  2227. expect(App.showAlertPopup.calledWith(header, body)).to.be.true;
  2228. });
  2229. it("data.responseText is incorrect", function() {
  2230. controller.abortDowngradeErrorCallback({responseText: "//"});
  2231. expect(App.showAlertPopup.calledWith(header, body)).to.be.true;
  2232. });
  2233. it("data.responseText is correct", function() {
  2234. controller.abortDowngradeErrorCallback({responseText: '{"message": "msg"}'});
  2235. expect(App.showAlertPopup.calledWith(header, body + ' msg')).to.be.true;
  2236. });
  2237. });
  2238. describe("#retryUpgrade()", function () {
  2239. it("requestInProgress should be true", function() {
  2240. controller.retryUpgrade();
  2241. expect(controller.get('requestInProgress')).to.be.true;
  2242. });
  2243. it("isRetryPending should be true", function() {
  2244. controller.retryUpgrade();
  2245. expect(controller.get('isRetryPending')).to.be.true;
  2246. });
  2247. it("App.ajax.send should be called", function() {
  2248. controller.set('upgradeId', 1);
  2249. controller.retryUpgrade();
  2250. var args = testHelpers.findAjaxRequest('name', 'admin.upgrade.retry');
  2251. expect(args[0]).to.be.eql({
  2252. name: 'admin.upgrade.retry',
  2253. sender: controller,
  2254. data: {
  2255. upgradeId: 1
  2256. }
  2257. });
  2258. });
  2259. });
  2260. describe("#upgradeErrorCallback()", function () {
  2261. var header = Em.I18n.t('admin.stackVersions.upgrade.start.fail.title');
  2262. var body = "";
  2263. beforeEach(function() {
  2264. sinon.stub(App, 'showAlertPopup');
  2265. });
  2266. afterEach(function() {
  2267. App.showAlertPopup.restore();
  2268. });
  2269. it("data is null", function() {
  2270. controller.upgradeErrorCallback(null);
  2271. expect(App.showAlertPopup.calledWith(header, body)).to.be.true;
  2272. });
  2273. it("data.responseText is null", function() {
  2274. controller.upgradeErrorCallback({responseText: null});
  2275. expect(App.showAlertPopup.calledWith(header, body)).to.be.true;
  2276. });
  2277. it("data.responseText is incorrect", function() {
  2278. controller.upgradeErrorCallback({responseText: "//"});
  2279. expect(App.showAlertPopup.calledWith(header, body)).to.be.true;
  2280. });
  2281. it("data.responseText is correct", function() {
  2282. controller.upgradeErrorCallback({responseText: '{"message": "msg"}'});
  2283. expect(App.showAlertPopup.calledWith(header, 'msg')).to.be.true;
  2284. });
  2285. });
  2286. describe("#updateOptionsSuccessCallback()", function () {
  2287. it("skipComponentFailures: true, skipSCFailures: true", function() {
  2288. var params = {
  2289. skipComponentFailures: 'true',
  2290. skipSCFailures: 'true'
  2291. };
  2292. controller.updateOptionsSuccessCallback({}, {}, params);
  2293. expect(controller.get('failuresTolerance')).to.be.eql(Em.Object.create({
  2294. skipComponentFailures: true,
  2295. skipSCFailures: true
  2296. }));
  2297. });
  2298. it("skipComponentFailures: false, skipSCFailures: false", function() {
  2299. var params = {
  2300. skipComponentFailures: 'false',
  2301. skipSCFailures: 'false'
  2302. };
  2303. controller.updateOptionsSuccessCallback({}, {}, params);
  2304. expect(controller.get('failuresTolerance')).to.be.eql(Em.Object.create({
  2305. skipComponentFailures: false,
  2306. skipSCFailures: false
  2307. }));
  2308. });
  2309. });
  2310. describe("#openUpgradeOptions()", function () {
  2311. beforeEach(function() {
  2312. sinon.stub(controller, 'upgradeOptions');
  2313. });
  2314. afterEach(function() {
  2315. controller.upgradeOptions.restore();
  2316. });
  2317. it("upgradeOptions should not be called", function() {
  2318. controller.set('isDowngrade', true);
  2319. controller.openUpgradeOptions();
  2320. expect(controller.upgradeOptions.called).to.be.false;
  2321. });
  2322. it("upgradeOptions should be called", function() {
  2323. controller.set('isDowngrade', false);
  2324. controller.openUpgradeOptions();
  2325. expect(controller.upgradeOptions.calledWith(true, null)).to.be.true;
  2326. });
  2327. });
  2328. describe("#getSupportedUpgradeTypes()", function () {
  2329. it("App.ajax.send should be called", function() {
  2330. controller.getSupportedUpgradeTypes({});
  2331. var args = testHelpers.findAjaxRequest('name', 'admin.upgrade.get_supported_upgradeTypes');
  2332. expect(args[0]).to.be.eql({
  2333. name: "admin.upgrade.get_supported_upgradeTypes",
  2334. sender: controller,
  2335. data: {},
  2336. success: "getSupportedUpgradeTypesSuccess"
  2337. });
  2338. });
  2339. });
  2340. describe("#getSupportedUpgradeTypesSuccess()", function () {
  2341. var testCases = [
  2342. {
  2343. data: {
  2344. items: []
  2345. },
  2346. expected: false
  2347. },
  2348. {
  2349. data: {
  2350. items: [{
  2351. CompatibleRepositoryVersions: {}
  2352. }]
  2353. },
  2354. expected: false
  2355. },
  2356. {
  2357. data: {
  2358. items: [{
  2359. CompatibleRepositoryVersions: {
  2360. upgrade_types: []
  2361. }
  2362. }]
  2363. },
  2364. expected: false
  2365. },
  2366. {
  2367. data: {
  2368. items: [{
  2369. CompatibleRepositoryVersions: {
  2370. upgrade_types: ['t1']
  2371. }
  2372. }]
  2373. },
  2374. expected: true
  2375. }
  2376. ];
  2377. testCases.forEach(function(test) {
  2378. it("data: " + JSON.stringify(test.data), function() {
  2379. controller.set('upgradeMethods', [Em.Object.create({
  2380. type: 't1',
  2381. allowed: true
  2382. })]);
  2383. controller.getSupportedUpgradeTypesSuccess(test.data);
  2384. expect(controller.get('upgradeMethods')[0].get('allowed')).to.be.equal(test.expected);
  2385. });
  2386. });
  2387. });
  2388. describe("#runPreUpgradeCheckOnlySuccess()", function () {
  2389. beforeEach(function() {
  2390. sinon.stub(controller, 'formatPreCheckMessage').returns({precheckResultsMessage: 'formatted'});
  2391. sinon.stub(controller, 'updateSelectedMethod');
  2392. sinon.stub(controller, 'addPrecheckMessageTooltip');
  2393. controller.set('upgradeMethods', [Em.Object.create({
  2394. type: 'ROLLING'
  2395. })]);
  2396. });
  2397. afterEach(function() {
  2398. controller.formatPreCheckMessage.restore();
  2399. controller.updateSelectedMethod.restore();
  2400. controller.addPrecheckMessageTooltip.restore();
  2401. });
  2402. it("failed check", function() {
  2403. var data = {
  2404. items: [
  2405. {
  2406. UpgradeChecks: {
  2407. status: 'FAIL'
  2408. }
  2409. }
  2410. ]
  2411. };
  2412. var properties = {
  2413. precheckResultsTitle: Em.I18n.t('admin.stackVersions.version.upgrade.upgradeOptions.preCheck.msg.title'),
  2414. precheckResultsData: data,
  2415. isCheckComplete: true,
  2416. action: 'openMessage',
  2417. precheckResultsMessage: '',
  2418. recheckResultsMessageClass: 'GREEN',
  2419. isPrecheckFailed: false,
  2420. precheckResultsMessageIconClass: 'icon-ok',
  2421. bypassedFailures: false
  2422. };
  2423. controller.runPreUpgradeCheckOnlySuccess(data, {}, {type: 'ROLLING'});
  2424. expect(controller.formatPreCheckMessage.calledWith('FAIL', data, properties)).to.be.true;
  2425. var msg = controller.get('upgradeMethods').findProperty('type', 'ROLLING').get('precheckResultsMessage');
  2426. expect(msg).to.be.equal('formatted');
  2427. });
  2428. it("success check", function() {
  2429. var data = {
  2430. items: []
  2431. };
  2432. controller.runPreUpgradeCheckOnlySuccess(data, {}, {type: 'ROLLING'});
  2433. var msg = controller.get('upgradeMethods').findProperty('type', 'ROLLING').get('precheckResultsMessage');
  2434. expect(msg).to.be.equal(Em.I18n.t('admin.stackVersions.version.upgrade.upgradeOptions.preCheck.allPassed'));
  2435. });
  2436. it("updateSelectedMethod should be called", function() {
  2437. var data = {
  2438. items: []
  2439. };
  2440. controller.runPreUpgradeCheckOnlySuccess(data, {}, {type: 'ROLLING'});
  2441. expect(controller.updateSelectedMethod.calledWith(false)).to.be.true;
  2442. });
  2443. it("addPrecheckMessageTooltip should be called", function() {
  2444. var data = {
  2445. items: []
  2446. };
  2447. controller.runPreUpgradeCheckOnlySuccess(data, {}, {type: 'ROLLING'});
  2448. expect(controller.addPrecheckMessageTooltip.calledOnce).to.be.true;
  2449. });
  2450. });
  2451. describe("#formatPreCheckMessage()", function () {
  2452. it("should return formatted message", function() {
  2453. var data = {
  2454. items: [{
  2455. UpgradeChecks: {
  2456. status: 'FAIL'
  2457. }
  2458. }]
  2459. };
  2460. expect(controller.formatPreCheckMessage('FAIL', data, {precheckResultsMessage: 'pre'})).to.be.eql({
  2461. "precheckResultsMessage": "1 Required pre",
  2462. "precheckResultsMessageClass": "RED",
  2463. "isPrecheckFailed": true,
  2464. "precheckResultsMessageIconClass": "icon-remove"
  2465. });
  2466. });
  2467. });
  2468. describe("#addPrecheckMessageTooltip()", function () {
  2469. beforeEach(function() {
  2470. sinon.stub(Em.run, 'later', function(ctx, callback) {
  2471. callback();
  2472. });
  2473. sinon.stub(App, 'tooltip');
  2474. });
  2475. afterEach(function() {
  2476. Em.run.later.restore();
  2477. App.tooltip.restore();
  2478. });
  2479. it("App.tooltip should be called", function() {
  2480. controller.addPrecheckMessageTooltip();
  2481. expect(App.tooltip.calledOnce).to.be.true;
  2482. });
  2483. });
  2484. describe("#runPreUpgradeCheckOnlyError()", function () {
  2485. it("upgradeMethod should be updated", function() {
  2486. controller.set('upgradeMethods', [Em.Object.create({
  2487. type: 'ROLLING'
  2488. })]);
  2489. controller.runPreUpgradeCheckOnlyError({}, {}, '', {}, {type: 'ROLLING'});
  2490. expect(JSON.stringify(controller.get('upgradeMethods').findProperty('type', 'ROLLING'))).to.be.equal(JSON.stringify({
  2491. "type": "ROLLING",
  2492. "precheckResultsMessage": Em.I18n.t('admin.stackVersions.version.upgrade.upgradeOptions.preCheck.msg.failed.link'),
  2493. "precheckResultsTitle": Em.I18n.t('admin.stackVersions.version.upgrade.upgradeOptions.preCheck.msg.failed.title'),
  2494. "precheckResultsMessageClass": "RED",
  2495. "isPrecheckFailed": true,
  2496. "precheckResultsMessageIconClass": "icon-warning-sign",
  2497. "action": "rerunCheck"
  2498. }));
  2499. });
  2500. });
  2501. describe("#updateSelectedMethod()", function () {
  2502. beforeEach(function() {
  2503. controller.set('upgradeMethods', [
  2504. Em.Object.create({
  2505. type: 'ROLLING',
  2506. isPrecheckFailed: false,
  2507. selected: true
  2508. }),
  2509. Em.Object.create({
  2510. type: 'NON_ROLLING',
  2511. isPrecheckFailed: false,
  2512. selected: true
  2513. })
  2514. ]);
  2515. });
  2516. it("should select upgrade method", function() {
  2517. controller.set('upgradeType', 'ROLLING');
  2518. controller.updateSelectedMethod(true);
  2519. expect(controller.get('upgradeMethods').findProperty('type', 'ROLLING').get('selected')).to.be.true;
  2520. });
  2521. it("isPrecheckFailed true for ROLLING and NON_ROLLING", function() {
  2522. controller.updateSelectedMethod(false);
  2523. expect(controller.get('upgradeMethods').findProperty('type', 'ROLLING').get('selected')).to.be.true;
  2524. expect(controller.get('upgradeMethods').findProperty('type', 'NON_ROLLING').get('selected')).to.be.true;
  2525. });
  2526. it("isPrecheckFailed false for ROLLING and NON_ROLLING", function() {
  2527. controller.get('upgradeMethods').setEach('isPrecheckFailed', true);
  2528. controller.updateSelectedMethod(false);
  2529. expect(controller.get('upgradeMethods').findProperty('type', 'ROLLING').get('selected')).to.be.false;
  2530. expect(controller.get('upgradeMethods').findProperty('type', 'NON_ROLLING').get('selected')).to.be.false;
  2531. });
  2532. });
  2533. describe("#runPreUpgradeCheckError()", function () {
  2534. it("requestInProgress should be false", function() {
  2535. controller.runPreUpgradeCheckError();
  2536. expect(controller.get('requestInProgress')).to.be.false;
  2537. });
  2538. });
  2539. describe("#confirmRetryUpgrade()", function () {
  2540. beforeEach(function() {
  2541. sinon.spy(App, 'showConfirmationPopup');
  2542. sinon.stub(controller, 'retryUpgrade');
  2543. });
  2544. afterEach(function() {
  2545. App.showConfirmationPopup.restore();
  2546. controller.retryUpgrade.restore();
  2547. });
  2548. it("App.showConfirmationPopup should be called", function() {
  2549. var popup = controller.confirmRetryUpgrade(Em.Object.create());
  2550. expect(App.showConfirmationPopup.calledOnce).to.be.true;
  2551. popup.onPrimary();
  2552. expect(controller.retryUpgrade.calledOnce).to.be.true;
  2553. });
  2554. });
  2555. describe("#confirmRetryDowngrade()", function () {
  2556. beforeEach(function() {
  2557. sinon.spy(App, 'showConfirmationPopup');
  2558. sinon.stub(controller, 'retryUpgrade');
  2559. });
  2560. afterEach(function() {
  2561. App.showConfirmationPopup.restore();
  2562. controller.retryUpgrade.restore();
  2563. });
  2564. it("App.showConfirmationPopup should be called", function() {
  2565. var popup = controller.confirmRetryDowngrade(Em.Object.create());
  2566. expect(App.showConfirmationPopup.calledOnce).to.be.true;
  2567. popup.onPrimary();
  2568. expect(controller.retryUpgrade.calledOnce).to.be.true;
  2569. });
  2570. });
  2571. describe("#installRepoVersionError()", function () {
  2572. var header = Em.I18n.t('admin.stackVersions.upgrade.installPackage.fail.title');
  2573. beforeEach(function() {
  2574. sinon.stub(App, 'showAlertPopup');
  2575. });
  2576. afterEach(function() {
  2577. App.showAlertPopup.restore();
  2578. });
  2579. it("responseText is incorrect", function() {
  2580. var data = {
  2581. responseText: null
  2582. };
  2583. controller.installRepoVersionError(data);
  2584. expect(App.showAlertPopup.calledWith(header, "")).to.be.true;
  2585. });
  2586. it("statusText is timeout", function() {
  2587. var data = {
  2588. responseText: '',
  2589. statusText: 'timeout'
  2590. };
  2591. controller.installRepoVersionError(data);
  2592. expect(App.showAlertPopup.calledWith(header, Em.I18n.t('admin.stackVersions.upgrade.installPackage.fail.timeout'))).to.be.true;
  2593. });
  2594. it("responseText is correct", function() {
  2595. var data = {
  2596. responseText: '{"message":"msg"}'
  2597. };
  2598. controller.installRepoVersionError(data);
  2599. expect(App.showAlertPopup.calledWith(header, 'msg')).to.be.true;
  2600. });
  2601. });
  2602. describe("#showProgressPopup()", function () {
  2603. var mock = {
  2604. initPopup: Em.K
  2605. };
  2606. beforeEach(function() {
  2607. sinon.stub(App.router, 'get').withArgs('highAvailabilityProgressPopupController').returns(mock);
  2608. sinon.stub(mock, 'initPopup');
  2609. sinon.stub(App.db, 'get').returns([1]);
  2610. });
  2611. afterEach(function() {
  2612. App.router.get.restore();
  2613. mock.initPopup.restore();
  2614. App.db.get.restore();
  2615. });
  2616. it("initPopup should be called", function() {
  2617. controller.showProgressPopup(Em.Object.create({displayName: 'v1'}));
  2618. expect(mock.initPopup.calledWith(
  2619. Em.I18n.t('admin.stackVersions.details.install.hosts.popup.title').format('v1'),
  2620. [1],
  2621. controller
  2622. )).to.be.true;
  2623. });
  2624. });
  2625. describe("#finish()", function () {
  2626. beforeEach(function() {
  2627. sinon.stub(controller, 'setDBProperties', Em.K);
  2628. sinon.stub(App.clusterStatus, 'setClusterStatus');
  2629. App.set('upgradeState', 'COMPLETED');
  2630. controller.set('upgradeVersion', '');
  2631. });
  2632. afterEach(function() {
  2633. controller.setDBProperties.restore();
  2634. App.clusterStatus.setClusterStatus.restore();
  2635. });
  2636. it("App.clusterStatus.setClusterStatus should be called", function() {
  2637. controller.finish();
  2638. expect(App.clusterStatus.setClusterStatus.calledOnce).to.be.true;
  2639. });
  2640. it("upgradeState should be INIT", function() {
  2641. controller.finish();
  2642. expect(App.get('upgradeState')).to.be.equal('INIT');
  2643. });
  2644. it("currentStackVersion should be set", function() {
  2645. controller.set('upgradeVersion', 'HDP-2.2');
  2646. controller.finish();
  2647. expect(controller.get('upgradeVersion')).to.be.equal('HDP-2.2');
  2648. });
  2649. });
  2650. describe("#loadRepositories()", function () {
  2651. beforeEach(function() {
  2652. sinon.stub(App.router, 'get').withArgs('clusterController.isLoaded').returns(true);
  2653. });
  2654. afterEach(function() {
  2655. App.router.get.restore();
  2656. });
  2657. it("App.ajax.send should be called", function() {
  2658. App.set('currentStackVersion', 'HDP-2.2');
  2659. controller.loadRepositories();
  2660. var args = testHelpers.findAjaxRequest('name', 'cluster.load_repositories');
  2661. expect(args[0]).to.be.eql({
  2662. name: 'cluster.load_repositories',
  2663. sender: controller,
  2664. data: {
  2665. stackName: 'HDP',
  2666. stackVersion: '2.2'
  2667. },
  2668. success: 'loadRepositoriesSuccessCallback',
  2669. error: 'loadRepositoriesErrorCallback'
  2670. });
  2671. });
  2672. });
  2673. describe("#loadRepositoriesSuccessCallback()", function () {
  2674. it("allRepos should be set", function() {
  2675. var data = {
  2676. items: [
  2677. {
  2678. repositories: [
  2679. {
  2680. Repositories: {
  2681. os_type: 'redhat',
  2682. base_url: 'base_url',
  2683. repo_id: 'repo_id',
  2684. repo_name: 'repo_name',
  2685. stack_name: 'stack_name',
  2686. stack_version: 'stack_version'
  2687. }
  2688. }
  2689. ]
  2690. }
  2691. ]
  2692. };
  2693. controller.loadRepositoriesSuccessCallback(data);
  2694. expect(controller.get('allRepos')[0].name).to.be.equal('redhat');
  2695. expect(JSON.stringify(controller.get('allRepos')[0].repositories[0])).to.be.equal(JSON.stringify({
  2696. "baseUrl": "base_url",
  2697. "osType": "redhat",
  2698. "repoId": "repo_id",
  2699. "repoName": "repo_name",
  2700. "stackName": "stack_name",
  2701. "stackVersion": "stack_version",
  2702. "isFirst": true
  2703. }));
  2704. });
  2705. });
  2706. describe("#loadServiceVersionFromVersionDefinitions()", function () {
  2707. it("App.ajax.send should be called", function() {
  2708. App.set('clusterName', 'c1');
  2709. controller.loadServiceVersionFromVersionDefinitions();
  2710. var args = testHelpers.findAjaxRequest('name', 'cluster.load_current_repo_stack_services');
  2711. expect(args[0]).to.be.eql({
  2712. name: 'cluster.load_current_repo_stack_services',
  2713. sender: controller,
  2714. data: {
  2715. clusterName: App.get('clusterName')
  2716. },
  2717. success: 'loadServiceVersionFromVersionDefinitionsSuccessCallback',
  2718. error: 'loadServiceVersionFromVersionDefinitionsErrorCallback'
  2719. });
  2720. });
  2721. });
  2722. describe("#loadServiceVersionFromVersionDefinitionsSuccessCallback()", function () {
  2723. it("serviceVersionsMap should be set", function() {
  2724. controller.set('serviceVersionsMap', {});
  2725. var data = {
  2726. items: [
  2727. {
  2728. repository_versions: [
  2729. {
  2730. RepositoryVersions: {
  2731. stack_services: [
  2732. {
  2733. name: 'S1',
  2734. versions: ['v1']
  2735. }
  2736. ]
  2737. }
  2738. }
  2739. ]
  2740. }
  2741. ]
  2742. };
  2743. controller.loadServiceVersionFromVersionDefinitionsSuccessCallback(data);
  2744. expect(controller.get('serviceVersionsMap')).to.be.eql({
  2745. "S1": "v1"
  2746. });
  2747. });
  2748. });
  2749. });