12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135 |
- /**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- var App = require('app');
- require('controllers/main/admin/stack_and_upgrade_controller');
- require('utils/string_utils');
- var testHelpers = require('test/helpers');
- describe('App.MainAdminStackAndUpgradeController', function() {
- var controller = App.MainAdminStackAndUpgradeController.create({
- getDBProperty: Em.K,
- setDBProperty: Em.K
- });
- before(function () {
- sinon.stub(App.router, 'get').withArgs('clusterController.isLoaded').returns(false);
- });
- after(function () {
- App.router.get.restore();
- controller.destroy();
- });
- describe("#realRepoUrl", function() {
- before(function () {
- this.mock = sinon.stub(App, 'get');
- this.mock.withArgs('apiPrefix').returns('apiPrefix')
- .withArgs('stackVersionURL').returns('stackVersionURL');
- });
- after(function () {
- this.mock.restore();
- });
- it("should be valid", function() {
- controller.propertyDidChange('realRepoUrl');
- expect(controller.get('realRepoUrl')).to.equal('apiPrefixstackVersionURL/compatible_repository_versions?fields=*,operating_systems/*,operating_systems/repositories/*');
- });
- });
- describe("#realStackUrl", function() {
- before(function () {
- this.mock = sinon.stub(App, 'get');
- this.mock.withArgs('apiPrefix').returns('apiPrefix')
- .withArgs('clusterName').returns('clusterName');
- });
- after(function () {
- this.mock.restore();
- });
- it("should be valid", function() {
- controller.propertyDidChange('realStackUrl');
- expect(controller.get('realStackUrl')).to.equal('apiPrefix/clusters/clusterName/stack_versions?fields=*,repository_versions/*,repository_versions/operating_systems/repositories/*');
- });
- });
- describe("#realUpdateUrl", function() {
- before(function () {
- this.mock = sinon.stub(App, 'get');
- this.mock.withArgs('apiPrefix').returns('apiPrefix')
- .withArgs('clusterName').returns('clusterName');
- });
- after(function () {
- this.mock.restore();
- });
- it("realUpdateUrl is valid", function() {
- controller.propertyDidChange('realUpdateUrl');
- expect(controller.get('realUpdateUrl')).to.equal('apiPrefix/clusters/clusterName/stack_versions?fields=ClusterStackVersions/*');
- });
- });
- describe("#requestStatus", function() {
- it("state ABORTED", function() {
- controller.set('upgradeData', { Upgrade: {request_status: 'ABORTED'}});
- controller.propertyDidChange('requestStatus');
- expect(controller.get('requestStatus')).to.equal('SUSPENDED');
- });
- it("state not ABORTED", function() {
- controller.set('upgradeData', { Upgrade: {request_status: 'INIT'}});
- controller.propertyDidChange('requestStatus');
- expect(controller.get('requestStatus')).to.equal('INIT');
- });
- });
- describe("#load()", function() {
- beforeEach(function(){
- sinon.stub(controller, 'loadUpgradeData').returns({
- done: Em.clb
- });
- sinon.stub(controller, 'loadStackVersionsToModel').returns({
- done: Em.clb
- });
- sinon.stub(controller, 'loadRepoVersionsToModel').returns({
- done: Em.clb
- });
- sinon.stub(App.StackVersion, 'find').returns([Em.Object.create({
- state: 'CURRENT',
- repositoryVersion: {
- repositoryVersion: '2.2',
- displayName: 'HDP-2.2'
- }
- })]);
- controller.load();
- });
- afterEach(function(){
- controller.loadUpgradeData.restore();
- controller.loadStackVersionsToModel.restore();
- controller.loadRepoVersionsToModel.restore();
- App.StackVersion.find.restore();
- });
- it("loadUpgradeData called with valid arguments", function() {
- expect(controller.loadUpgradeData.calledWith(true)).to.be.true;
- });
- it('loadStackVersionsToModel called with valid arguments', function () {
- expect(controller.loadStackVersionsToModel.calledWith(true)).to.be.true;
- });
- it('loadRepoVersionsToModel called once', function () {
- expect(controller.loadRepoVersionsToModel.calledOnce).to.be.true;
- });
- it('currentVersion is corrent', function () {
- expect(controller.get('currentVersion')).to.eql({
- "repository_version": "2.2",
- "repository_name": "HDP-2.2"
- });
- });
- });
- describe("#loadUpgradeData()", function() {
- it("get entire data", function() {
- controller.set('upgradeId', 1);
- controller.loadUpgradeData();
- var args = testHelpers.findAjaxRequest('name', 'admin.upgrade.data');
- expect(args[0]).to.exists;
- expect(args[0].sender).to.be.eql(controller);
- expect(args[0].data).to.be.eql({
- id: 1
- });
- });
- it("get only state", function() {
- controller.set('upgradeId', 1);
- controller.loadUpgradeData(true);
- var args = testHelpers.findAjaxRequest('name', 'admin.upgrade.state');
- expect(args[0]).to.exists;
- expect(args[0].sender).to.be.eql(controller);
- expect(args[0].data).to.be.eql({
- id: 1
- });
- });
- it("upgrade id is null", function() {
- controller.set('upgradeId', null);
- controller.loadUpgradeData();
- var args = testHelpers.findAjaxRequest('name', 'admin.upgrade.state');
- var args2 = testHelpers.findAjaxRequest('name', 'admin.upgrade.data');
- expect(args).to.not.exists;
- expect(args2).to.not.exists;
- });
- });
- describe("#loadUpgradeDataSuccessCallback()", function() {
- var retryCases = [
- {
- isRetryPendingInitial: true,
- status: 'ABORTED',
- isRetryPending: true,
- requestInProgress: true,
- title: 'retry request not yet applied'
- },
- {
- isRetryPendingInitial: true,
- status: 'UPGRADING',
- isRetryPending: false,
- requestInProgress: false,
- title: 'retry request applied'
- },
- {
- isRetryPendingInitial: false,
- status: 'ABORTED',
- isRetryPending: false,
- requestInProgress: true,
- title: 'no retry request sent'
- },
- {
- isRetryPendingInitial: false,
- status: 'UPGRADING',
- isRetryPending: false,
- requestInProgress: true,
- title: 'upgrade wasn\'t aborted'
- }
- ];
- beforeEach(function () {
- sinon.stub(controller, 'updateUpgradeData', Em.K);
- sinon.stub(controller, 'setDBProperty', Em.K);
- });
- afterEach(function () {
- controller.updateUpgradeData.restore();
- controller.setDBProperty.restore();
- });
- it("correct data", function() {
- var data = {
- "Upgrade": {
- "request_status": "UPGRADED"
- },
- "upgrade_groups": [
- {
- "UpgradeGroup": {
- "id": 1
- },
- "upgrade_items": []
- }
- ]};
- controller.loadUpgradeDataSuccessCallback(data);
- expect(App.get('upgradeState')).to.equal('UPGRADED');
- expect(controller.updateUpgradeData.calledOnce).to.be.true;
- expect(controller.setDBProperty.calledWith('upgradeState', 'UPGRADED')).to.be.true;
- });
- it("data is null", function() {
- var data = null;
- controller.loadUpgradeDataSuccessCallback(data);
- expect(controller.updateUpgradeData.called).to.be.false;
- expect(controller.setDBProperty.called).to.be.false;
- });
- retryCases.forEach(function (item) {
- it(item.title, function () {
- var data = {
- "Upgrade": {
- "request_status": item.status
- }
- };
- controller.setProperties({
- isRetryPending: item.isRetryPendingInitial,
- requestInProgress: true
- });
- controller.loadUpgradeDataSuccessCallback(data);
- expect(controller.getProperties(['isRetryPending', 'requestInProgress'])).to.eql({
- isRetryPending: item.isRetryPending,
- requestInProgress: item.requestInProgress
- });
- });
- });
- });
- describe("#getUpgradeItem()", function() {
- it("default callback", function() {
- var item = Em.Object.create({
- request_id: 1,
- group_id: 2,
- stage_id: 3
- });
- controller.getUpgradeItem(item);
- var args = testHelpers.findAjaxRequest('name', 'admin.upgrade.upgrade_item');
- expect(args[0]).to.exists;
- expect(args[0].sender).to.be.eql(controller);
- expect(args[0].success).to.be.equal('getUpgradeItemSuccessCallback');
- expect(args[0].data).to.be.eql({
- upgradeId: 1,
- groupId: 2,
- stageId: 3
- });
- });
- it("custom callback", function() {
- var item = Em.Object.create({
- request_id: 1,
- group_id: 2,
- stage_id: 3
- });
- controller.getUpgradeItem(item, 'customCallback');
- var args = testHelpers.findAjaxRequest('name', 'admin.upgrade.upgrade_item');
- expect(args[0]).to.exists;
- expect(args[0].sender).to.be.eql(controller);
- expect(args[0].success).to.be.equal('customCallback');
- expect(args[0].data).to.be.eql({
- upgradeId: 1,
- groupId: 2,
- stageId: 3
- });
- });
- });
- describe("#openUpgradeDialog()", function () {
- before(function () {
- sinon.stub(App.router, 'transitionTo', Em.K);
- });
- after(function () {
- App.router.transitionTo.restore();
- });
- it("should open dialog", function () {
- controller.openUpgradeDialog();
- expect(App.router.transitionTo.calledWith('admin.stackUpgrade')).to.be.true;
- });
- });
- describe("#runPreUpgradeCheck()", function() {
- it("make ajax call", function() {
- controller.runPreUpgradeCheck(Em.Object.create({
- repositoryVersion: '2.2',
- displayName: 'HDP-2.2',
- upgradeType: 'ROLLING',
- skipComponentFailures: false,
- skipSCFailures: false
- }));
- var args = testHelpers.findAjaxRequest('name', 'admin.upgrade.pre_upgrade_check');
- expect(args[0]).to.exists;
- expect(args[0].sender).to.be.eql(controller);
- expect(args[0].data).to.be.eql({
- value: '2.2',
- label: 'HDP-2.2',
- type: 'ROLLING',
- skipComponentFailures: 'false',
- skipSCFailures: 'false'
- });
- });
- });
- describe("#runPreUpgradeCheckSuccess()", function () {
- var cases = [
- {
- check: {
- "check": "Work-preserving RM/NM restart is enabled in YARN configs",
- "status": "FAIL",
- "reason": "FAIL",
- "failed_on": [],
- "check_type": "SERVICE"
- },
- showClusterCheckPopupCalledCount: 1,
- upgradeCalledCount: 0,
- title: 'popup is displayed if fails are present'
- },
- {
- check: {
- "check": "Configuration Merge Check",
- "status": "WARNING",
- "reason": "Conflict",
- "failed_on": [],
- "failed_detail": [
- {
- type: 't0',
- property: 'p0',
- current: 'c0',
- new_stack_value: 'n0',
- result_value: 'n0'
- },
- {
- type: 't1',
- property: 'p1',
- current: 'c1',
- new_stack_value: null,
- result_value: 'c1'
- },
- {
- type: 't2',
- property: 'p2',
- current: 'c2',
- new_stack_value: null,
- result_value: null
- }
- ],
- "check_type": "CLUSTER",
- "id": "CONFIG_MERGE"
- },
- showClusterCheckPopupCalledCount: 1,
- upgradeCalledCount: 0,
- configs: [
- {
- type: 't0',
- name: 'p0',
- currentValue: 'c0',
- recommendedValue: 'n0',
- resultingValue: 'n0',
- isDeprecated: false,
- willBeRemoved: false
- },
- {
- type: 't1',
- name: 'p1',
- currentValue: 'c1',
- recommendedValue: Em.I18n.t('popup.clusterCheck.Upgrade.configsMerge.deprecated'),
- resultingValue: 'c1',
- isDeprecated: true,
- willBeRemoved: false
- },
- {
- type: 't2',
- name: 'p2',
- currentValue: 'c2',
- recommendedValue: Em.I18n.t('popup.clusterCheck.Upgrade.configsMerge.deprecated'),
- resultingValue: Em.I18n.t('popup.clusterCheck.Upgrade.configsMerge.willBeRemoved'),
- isDeprecated: true,
- willBeRemoved: true
- }
- ],
- title: 'popup is displayed if warnings are present; configs merge conflicts'
- },
- {
- check: {
- "check": "Work-preserving RM/NM restart is enabled in YARN configs",
- "status": "PASS",
- "reason": "OK",
- "failed_on": [],
- "check_type": "SERVICE"
- },
- showClusterCheckPopupCalledCount: 0,
- upgradeCalledCount: 1,
- title: 'upgrade is started if fails and warnings are absent'
- }
- ];
- beforeEach(function () {
- sinon.stub(App, 'showClusterCheckPopup', Em.K);
- sinon.stub(controller, 'upgrade', Em.K);
- });
- afterEach(function () {
- App.showClusterCheckPopup.restore();
- controller.upgrade.restore();
- });
- cases.forEach(function (item) {
- it(item.title, function () {
- controller.runPreUpgradeCheckSuccess(
- {
- items: [
- {
- UpgradeChecks: item.check
- }
- ]
- }, null, {
- label: 'name'
- }
- );
- expect(controller.upgrade.callCount).to.equal(item.upgradeCalledCount);
- expect(App.showClusterCheckPopup.callCount).to.equal(item.showClusterCheckPopupCalledCount);
- if (item.check.id === 'CONFIG_MERGE') {
- expect(App.showClusterCheckPopup.firstCall.args[2]).to.eql(item.configs);
- }
- });
- });
- });
- describe("#initDBProperties()", function() {
- before(function () {
- this.mock = sinon.stub(controller, 'getDBProperties');
- });
- after(function () {
- this.mock.restore();
- });
- it("set string properties", function () {
- this.mock.returns({prop: 'string'});
- controller.initDBProperties();
- expect(controller.get('prop')).to.equal('string');
- });
- it("set number properties", function () {
- this.mock.returns({prop: 0});
- controller.initDBProperties();
- expect(controller.get('prop')).to.equal(0);
- });
- it("set boolean properties", function () {
- this.mock.returns({prop: false});
- controller.initDBProperties();
- expect(controller.get('prop')).to.be.false;
- });
- it("set undefined properties", function () {
- this.mock.returns({prop: undefined});
- controller.set('prop', 'value');
- controller.initDBProperties();
- expect(controller.get('prop')).to.equal('value');
- });
- it("set null properties", function () {
- this.mock.returns({prop: null});
- controller.set('prop', 'value');
- controller.initDBProperties();
- expect(controller.get('prop')).to.equal('value');
- });
- });
- describe("#init()", function() {
- before(function () {
- sinon.stub(controller, 'initDBProperties', Em.K);
- });
- after(function () {
- controller.initDBProperties.restore();
- });
- it("call initDBProperties", function () {
- controller.init();
- expect(controller.initDBProperties.calledOnce).to.be.true;
- });
- });
- describe("#upgrade()", function() {
- var callArgs;
- beforeEach(function () {
- sinon.stub(controller, 'setDBProperty', Em.K);
- controller.set('currentVersion', {
- repository_version: '2.2'
- });
- controller.upgrade({
- value: '2.2',
- label: 'HDP-2.2'
- });
- callArgs = testHelpers.findAjaxRequest('name', 'admin.upgrade.start')[0];
- });
- afterEach(function () {
- controller.setDBProperty.restore();
- });
- it("request-data is valid", function() {
- expect(callArgs.data).to.eql({"value": '2.2', "label": 'HDP-2.2'});
- });
- it('request-name is valid', function () {
- expect(callArgs.name).to.equal('admin.upgrade.start');
- });
- it('request-sender is valid', function () {
- expect(callArgs.sender).to.eql(controller);
- });
- it('callback is valid', function () {
- expect(callArgs.success).to.equal('upgradeSuccessCallback');
- });
- it('callback is called', function () {
- expect(callArgs.callback).to.be.called;
- });
- it('setDBProperty is called with valid data', function () {
- expect(controller.setDBProperty.calledWith('currentVersion', {
- repository_version: '2.2'
- })).to.be.true;
- });
- });
- describe("#upgradeSuccessCallback()", function() {
- beforeEach(function () {
- sinon.stub(App.clusterStatus, 'setClusterStatus', Em.K);
- sinon.stub(controller, 'openUpgradeDialog', Em.K);
- sinon.stub(controller, 'setDBProperties', Em.K);
- sinon.stub(controller, 'load', Em.K);
- var data = {
- resources: [
- {
- Upgrade: {
- request_id: 1
- }
- }
- ]
- };
- controller.upgradeSuccessCallback(data, {}, {label: 'HDP-2.2.1', isDowngrade: true});
- });
- afterEach(function () {
- App.clusterStatus.setClusterStatus.restore();
- controller.openUpgradeDialog.restore();
- controller.setDBProperties.restore();
- controller.load.restore();
- });
- it('load is called ocne', function() {
- expect(controller.load.calledOnce).to.be.true;
- });
- it('upgradeVersion is HDP-2.2.1', function() {
- expect(controller.get('upgradeVersion')).to.equal('HDP-2.2.1');
- });
- it('upgradeData is null', function() {
- expect(controller.get('upgradeData')).to.be.null;
- });
- it('isDowngrade is true', function() {
- expect(controller.get('isDowngrade')).to.be.true;
- });
- it('App.clusterStatus.setClusterStatus is called once', function() {
- expect(App.clusterStatus.setClusterStatus.calledOnce).to.be.true;
- });
- it('controller.openUpgradeDialog is called once', function() {
- expect(controller.openUpgradeDialog.calledOnce).to.be.true;
- });
- });
- describe("#updateUpgradeData()", function() {
- beforeEach(function () {
- sinon.stub(controller, 'initUpgradeData', Em.K);
- });
- afterEach(function () {
- controller.initUpgradeData.restore();
- });
- it("data loaded first time", function() {
- controller.set('upgradeData', null);
- controller.updateUpgradeData({});
- expect(controller.initUpgradeData.calledWith({})).to.be.true;
- });
- describe('upgradeData exists', function () {
- var groups;
- beforeEach(function() {
- var oldData = Em.Object.create({
- upgradeGroups: [
- Em.Object.create({
- group_id: 1,
- upgradeItems: [
- Em.Object.create({
- stage_id: 1
- })
- ]
- }),
- Em.Object.create({
- group_id: 2,
- upgradeItems: [
- Em.Object.create({
- stage_id: 2
- }),
- Em.Object.create({
- stage_id: 3
- })
- ]
- })
- ]
- });
- var newData = {
- Upgrade: {
- request_id: 1
- },
- upgrade_groups: [
- {
- UpgradeGroup: {
- group_id: 1,
- status: 'COMPLETED',
- progress_percent: 100,
- completed_task_count: 3
- },
- upgrade_items: [
- {
- UpgradeItem: {
- stage_id: 1,
- status: 'COMPLETED',
- progress_percent: 100
- }
- }
- ]
- },
- {
- UpgradeGroup: {
- group_id: 2,
- status: 'ABORTED',
- progress_percent: 50,
- completed_task_count: 1
- },
- upgrade_items: [
- {
- UpgradeItem: {
- stage_id: 2,
- status: 'ABORTED',
- progress_percent: 99
- }
- },
- {
- UpgradeItem: {
- stage_id: 3,
- status: 'PENDING',
- progress_percent: 0
- }
- }
- ]
- }
- ]
- };
- controller.set('upgradeData', oldData);
- controller.updateUpgradeData(newData);
- groups = controller.get('upgradeData.upgradeGroups');
- });
- describe("checking 1st group", function() {
- it('status is COMPLETED', function () {
- expect(groups[0].get('status')).to.equal('COMPLETED');
- });
- it('progress_percent is 100', function () {
- expect(groups[0].get('progress_percent')).to.equal(100);
- });
- it('completed_task_count = 3', function () {
- expect(groups[0].get('completed_task_count')).to.equal(3);
- });
- it('upgradeItems.0.status is COMPLETED', function () {
- expect(groups[0].get('upgradeItems')[0].get('status')).to.equal('COMPLETED');
- });
- it('upgradeItems.0.progress_percent is 100', function () {
- expect(groups[0].get('upgradeItems')[0].get('progress_percent')).to.equal(100);
- });
- it('hasExpandableItems is true', function () {
- expect(groups[0].get('hasExpandableItems')).to.be.true;
- });
- });
- describe('checking 2nd group', function () {
- it('status is ABORTED', function () {
- expect(groups[1].get('status')).to.equal('ABORTED');
- });
- it('progress_percent is 50', function () {
- expect(groups[1].get('progress_percent')).to.equal(50);
- });
- it('completed_task_count = 1', function () {
- expect(groups[1].get('completed_task_count')).to.equal(1);
- });
- it('upgradeItems.[].status = ["ABORTED", "PENDING"]', function () {
- expect(groups[1].get('upgradeItems').mapProperty('status')).to.eql(['ABORTED', 'PENDING']);
- });
- it('upgradeItems.[].progress_percent = [99, 0]', function () {
- expect(groups[1].get('upgradeItems').mapProperty('progress_percent')).to.eql([99, 0]);
- });
- it('hasExpandableItems is false', function () {
- expect(groups[1].get('hasExpandableItems')).to.be.false;
- });
- });
- });
- });
- describe("#initUpgradeData()", function() {
- beforeEach(function () {
- sinon.stub(controller, 'setDBProperty');
- var newData = {
- Upgrade: {
- request_id: 1,
- downgrade_allowed: false
- },
- upgrade_groups: [
- {
- UpgradeGroup: {
- group_id: 1
- },
- upgrade_items: [
- {
- UpgradeItem: {
- stage_id: 1,
- status: 'IN_PROGRESS'
- }
- },
- {
- UpgradeItem: {
- stage_id: 2
- }
- }
- ]
- },
- {
- UpgradeGroup: {
- group_id: 2
- },
- upgrade_items: []
- },
- {
- UpgradeGroup: {
- group_id: 3
- },
- upgrade_items: [
- {
- UpgradeItem: {
- stage_id: 3,
- status: 'ABORTED'
- }
- },
- {
- UpgradeItem: {
- stage_id: 4,
- status: 'PENDING'
- }
- }
- ]
- }
- ]
- };
- controller.initUpgradeData(newData);
- });
- afterEach(function () {
- controller.setDBProperty.restore();
- });
- it("setDBProperty called with valid arguments", function() {
- expect(controller.setDBProperty.calledWith('downgradeAllowed', false)).to.be.true;
- });
- it('downgradeAllowed is false', function () {
- expect(controller.get('downgradeAllowed')).to.be.false;
- });
- it('upgradeData.Upgrade.request_id is 1', function () {
- expect(controller.get('upgradeData.Upgrade.request_id')).to.equal(1);
- });
- it('upgradeData.upgradeGroups contain valid data', function () {
- var groups = controller.get('upgradeData.upgradeGroups');
- expect(groups.mapProperty('group_id')).to.eql([3,2,1]);
- expect(groups[2].get('upgradeItems').mapProperty('stage_id')).to.eql([2,1]);
- expect(groups.mapProperty('hasExpandableItems')).to.eql([false, false, true]);
- });
- });
- describe.skip("#finish()", function() {
- before(function () {
- sinon.stub(App.clusterStatus, 'setClusterStatus', Em.K);
- sinon.stub(controller, 'setDBProperty', Em.K);
- });
- after(function () {
- App.clusterStatus.setClusterStatus.restore();
- controller.setDBProperty.restore();
- });
- it("upgradeState is not COMPLETED", function() {
- App.set('upgradeState', 'UPGRADING');
- controller.finish();
- expect(App.clusterStatus.setClusterStatus.called).to.be.false;
- });
- it("upgradeState is COMPLETED", function() {
- App.set('upgradeState', 'COMPLETED');
- controller.finish();
- expect(controller.setDBProperty.calledWith('upgradeId', undefined)).to.be.true;
- expect(controller.setDBProperty.calledWith('upgradeVersion', undefined)).to.be.true;
- expect(controller.setDBProperty.calledWith('upgradeState', 'INIT')).to.be.true;
- expect(controller.setDBProperty.calledWith('currentVersion', undefined)).to.be.true;
- expect(App.get('upgradeState')).to.equal('INIT');
- expect(App.clusterStatus.setClusterStatus.calledOnce).to.be.true;
- });
- });
- describe("#confirmDowngrade()", function() {
- before(function () {
- sinon.spy(App, 'showConfirmationPopup');
- sinon.stub(controller, 'downgrade', Em.K);
- });
- after(function () {
- App.showConfirmationPopup.restore();
- controller.downgrade.restore();
- });
- it("show confirmation popup", function() {
- controller.set('currentVersion', Em.Object.create({
- repository_version: '2.2',
- repository_name: 'HDP-2.2'
- }));
- var popup = controller.confirmDowngrade();
- expect(App.showConfirmationPopup.calledOnce).to.be.true;
- popup.onPrimary();
- expect(controller.downgrade.calledWith(Em.Object.create({
- repository_version: '2.2',
- repository_name: 'HDP-2.2'
- }))).to.be.true;
- });
- });
- describe("#upgradeOptions()", function() {
- var version = Em.Object.create({displayName: 'HDP-2.2'});
- beforeEach(function () {
- sinon.spy(App.ModalPopup, 'show');
- sinon.spy(App, 'showConfirmationFeedBackPopup');
- sinon.stub(controller, 'getSupportedUpgradeTypes').returns({
- done: function (callback) {
- callback([1]);
- return {
- always: function (alwaysCallback) {
- alwaysCallback();
- return {};
- }
- };
- }
- });
- sinon.stub(controller, 'runPreUpgradeCheck', Em.K);
- sinon.stub(App.RepositoryVersion, 'find').returns([
- Em.Object.create({
- status: 'CURRENT'
- })
- ]);
- controller.get('runningCheckRequests').clear();
- });
- afterEach(function () {
- App.ModalPopup.show.restore();
- App.showConfirmationFeedBackPopup.restore();
- controller.runPreUpgradeCheck.restore();
- controller.getSupportedUpgradeTypes.restore();
- controller.get('upgradeMethods').setEach('selected', false);
- App.RepositoryVersion.find.restore();
- });
- describe("show confirmation popup", function() {
- beforeEach(function () {
- controller.set('isDowngrade', false);
- this.popup = controller.upgradeOptions(false, version);
- });
- it('popup is shown', function () {
- expect(App.ModalPopup.show.calledOnce).to.be.true;
- });
- it('all upgradeMethods have isCheckRequestInProgress = true', function () {
- expect(controller.get('upgradeMethods').everyProperty('isCheckRequestInProgress')).to.be.true;
- });
- it('upgradeMethods no one is selected', function () {
- expect(controller.get('upgradeMethods').someProperty('selected')).to.be.false;
- });
- describe('#popup.onPrimary', function () {
- beforeEach(function () {
- controller.get('upgradeMethods')[0].set('selected', true);
- this.confirmPopup = this.popup.onPrimary();
- });
- it('showConfirmationFeedBackPopup is called once', function () {
- expect(App.showConfirmationFeedBackPopup.calledOnce).to.be.true;
- });
- describe('#confirmPopup.onPrimary', function () {
- beforeEach(function () {
- this.confirmPopup.onPrimary();
- });
- it('runPreUpgradeCheck is called with correct version', function () {
- expect(controller.runPreUpgradeCheck.calledWith(version)).to.be.true;
- });
- it('runningCheckRequests has 1 item', function () {
- expect(controller.get('runningCheckRequests')).to.have.length(1);
- });
- });
- });
- });
- describe("NOT show confirmation popup on Downgrade", function() {
- beforeEach(function () {
- controller.set('isDowngrade', true);
- controller.upgradeOptions(false, version);
- });
- it('runningCheckRequests has 1 item', function () {
- expect( controller.get('runningCheckRequests')).to.have.length(1);
- });
- });
- });
- describe("#confirmUpgrade()", function() {
- before(function () {
- sinon.stub(controller, 'upgradeOptions', Em.K);
- });
- after(function () {
- controller.upgradeOptions.restore();
- });
- it("show show upgrade options popup window", function() {
- var version = Em.Object.create({displayName: 'HDP-2.2'});
- controller.confirmUpgrade(version);
- expect(controller.upgradeOptions.calledWith(false, version)).to.be.true;
- });
- });
- describe("#downgrade()", function() {
- beforeEach(function () {
- sinon.stub(controller, 'abortUpgrade');
- sinon.stub(App.RepositoryVersion, 'find').returns([
- Em.Object.create({
- displayName: 'HDP-2.3',
- repositoryVersion: '2.3'
- })
- ]);
- controller.set('upgradeVersion', 'HDP-2.3');
- controller.set('upgradeType', 'NON_ROLLING');
- controller.downgrade(Em.Object.create({
- repository_version: '2.2',
- repository_name: 'HDP-2.2'
- }), {context: 'context'});
- this.callArgs = testHelpers.findAjaxRequest('name', 'admin.downgrade.start')[0];
- });
- afterEach(function () {
- controller.abortUpgrade.restore();
- App.RepositoryVersion.find.restore();
- });
- it('abortUpgrade is called once', function() {
- expect(controller.abortUpgrade.calledOnce).to.be.true;
- });
- it('request-data is valid', function () {
- expect(this.callArgs.data).to.eql({
- from: '2.3',
- value: '2.2',
- label: 'HDP-2.2',
- isDowngrade: true,
- upgradeType: "NON_ROLLING"
- });
- });
- it('request-name is valid', function () {
- expect(this.callArgs.name).to.be.equal('admin.downgrade.start');
- });
- it('request-sender is valid', function () {
- expect(this.callArgs.sender).to.be.eql(controller);
- });
- it('callback is valid', function () {
- expect(this.callArgs.success).to.be.equal('upgradeSuccessCallback');
- });
- it('callback is called', function () {
- expect(this.callArgs.callback).to.be.called;
- });
- });
- describe("#installRepoVersionConfirmation()", function () {
- before(function () {
- sinon.stub(controller, 'installRepoVersion', Em.K);
- });
- after(function () {
- controller.installRepoVersion.restore();
- });
- it("show popup", function () {
- var repo = Em.Object.create({'displayName': 'HDP-2.2'});
- var popup = controller.installRepoVersionConfirmation(repo);
- popup.onPrimary();
- expect(controller.installRepoVersion.calledWith(repo)).to.be.true;
- });
- });
- describe("#installRepoVersion()", function () {
- it("make ajax call", function () {
- var repo = Em.Object.create({
- stackVersionType: 'HDP',
- stackVersionNumber: '2.2',
- repositoryVersion: '2.2.1',
- repoId: 1
- });
- controller.installRepoVersion(repo);
- var args = testHelpers.findAjaxRequest('name', 'admin.stack_version.install.repo_version');
- expect(args).to.exists;
- });
- });
- describe("#installRepoVersionSuccess()", function() {
- var mock = Em.Object.create({
- id: 1,
- defaultStatus: 'INIT',
- stackVersion: {}
- });
- beforeEach(function () {
- sinon.spy(mock, 'set');
- sinon.stub(App.db, 'set', Em.K);
- sinon.stub(App.clusterStatus, 'setClusterStatus', Em.K);
- sinon.stub(App.RepositoryVersion, 'find').returns(mock);
- controller.installRepoVersionSuccess({Requests: {id: 1}}, {}, {id: 1});
- });
- afterEach(function () {
- App.db.set.restore();
- App.clusterStatus.setClusterStatus.restore();
- App.RepositoryVersion.find.restore();
- mock.set.restore();
- });
- it("data sdtored to the local db", function() {
- expect(App.db.set.calledWith('repoVersionInstall', 'id', [1])).to.be.true;
- });
- it('clusterStatus is updated', function () {
- expect(App.clusterStatus.setClusterStatus.calledOnce).to.be.true;
- });
- it('App.RepositoryVersion models have valid states', function () {
- expect(App.RepositoryVersion.find.calledWith(1)).to.be.true;
- expect(App.RepositoryVersion.find(1).get('defaultStatus')).to.equal('INSTALLING');
- expect(App.RepositoryVersion.find(1).get('stackVersion.state')).to.equal('INSTALLING');
- });
- });
- describe("#setUpgradeItemStatus()", function () {
- var item;
- beforeEach(function () {
- item = Em.Object.create({
- request_id: 1,
- stage_id: 1,
- group_id: 1
- });
- controller.setUpgradeItemStatus(item, 'PENDING');
- this.callArgs = testHelpers.findAjaxRequest('name', 'admin.upgrade.upgradeItem.setState')[0];
- });
- it('request-data is valid', function () {
- expect(this.callArgs.data).to.be.eql({upgradeId: 1, itemId: 1, groupId: 1, status: 'PENDING'});
- });
- it('request-name is valid', function () {
- expect(this.callArgs.name).to.be.equal('admin.upgrade.upgradeItem.setState');
- });
- it('request-sendeer is valid', function () {
- expect(this.callArgs.sender).to.be.eql(controller);
- });
- it('callback is called', function () {
- expect(this.callArgs.callback).to.be.called;
- });
- it('item.status is PENDING', function () {
- expect(item.get('status')).to.equal('PENDING');
- });
- });
- describe("#prepareRepoForSaving()", function () {
- it("prepare date for saving", function () {
- var repo = Em.Object.create({
- operatingSystems: [
- Em.Object.create({
- osType: "redhat6",
- isDisabled: Em.computed.not('isSelected'),
- repositories: [Em.Object.create({
- "baseUrl": "111121",
- "repoId": "HDP-2.2",
- "repoName": "HDP",
- hasError: false
- }),
- Em.Object.create({
- "baseUrl": "1",
- "repoId": "HDP-UTILS-1.1.0.20",
- "repoName": "HDP-UTILS",
- hasError: false
- })]
- })
- ]
- });
- var result = {
- "operating_systems": [
- {
- "OperatingSystems": {
- "os_type": "redhat6"
- },
- "repositories": [
- {
- "Repositories": {
- "base_url": "111121",
- "repo_id": "HDP-2.2",
- "repo_name": "HDP"
- }
- },
- {
- "Repositories": {
- "base_url": "1",
- "repo_id": "HDP-UTILS-1.1.0.20",
- "repo_name": "HDP-UTILS"
- }
- }
- ]
- }
- ]};
- expect(controller.prepareRepoForSaving(repo)).to.eql(result);
- });
- });
- describe("#getStackVersionNumber()", function(){
- it("get stack version number", function(){
- var repo = Em.Object.create({
- "stackVersionType": 'HDP',
- "stackVersion": '2.3',
- "repositoryVersion": '2.2.1'
- });
- var stackVersion = controller.getStackVersionNumber(repo);
- expect(stackVersion).to.equal('2.3');
- });
- it("get default stack version number", function(){
- App.set('currentStackVersion', '1.2.3');
- var repo = Em.Object.create({
- "stackVersionType": 'HDP',
- "repositoryVersion": '2.2.1'
- });
- var stackVersion = controller.getStackVersionNumber(repo);
- expect(stackVersion).to.equal('1.2.3');
- });
- });
- describe("#saveRepoOS()", function() {
- before(function(){
- this.mock = sinon.stub(controller, 'validateRepoVersions');
- sinon.stub(controller, 'prepareRepoForSaving', Em.K);
- });
- after(function(){
- this.mock.restore();
- controller.prepareRepoForSaving.restore();
- });
- describe("validation errors present", function() {
- beforeEach(function () {
- this.mock.returns({
- done: function(callback) {callback([1]);}
- });
- controller.saveRepoOS(Em.Object.create({repoVersionId: 1}), true);
- this.args = testHelpers.findAjaxRequest('name', 'admin.stack_versions.edit.repo');
- });
- it('validateRepoVersions is called with valid arguments', function () {
- expect(controller.validateRepoVersions.calledWith(Em.Object.create({repoVersionId: 1}), true)).to.be.true;
- });
- it('prepareRepoForSaving is not called', function () {
- expect(controller.prepareRepoForSaving.called).to.be.false;
- });
- it('no requests are sent', function () {
- expect(this.args).to.not.exists;
- });
- });
- describe("no validation errors", function() {
- beforeEach(function () {
- this.mock.returns({
- done: function(callback) {callback([]);}
- });
- controller.saveRepoOS(Em.Object.create({repoVersionId: 1}), true);
- });
- it('validateRepoVersions is called with valid arguments', function () {
- expect(controller.validateRepoVersions.calledWith(Em.Object.create({repoVersionId: 1}), true)).to.be.true;
- });
- it('prepareRepoForSaving is called with valid arguments', function () {
- expect(controller.prepareRepoForSaving.calledWith(Em.Object.create({repoVersionId: 1}))).to.be.true;
- });
- });
- });
- describe("#validateRepoVersions()", function () {
- it("skip validation", function () {
- controller.validateRepoVersions(Em.Object.create({repoVersionId: 1}), true);
- var args = testHelpers.findAjaxRequest('name', 'admin.stack_versions.validate.repo');
- expect(args).to.not.exists;
- });
- it("do validation", function () {
- var repo = Em.Object.create({
- repoVersionId: 1,
- operatingSystems: [
- Em.Object.create({
- isSelected: true,
- repositories: [
- Em.Object.create()
- ]
- })
- ]
- });
- controller.validateRepoVersions(repo, false);
- var args = testHelpers.findAjaxRequest('name', 'admin.stack_versions.validate.repo');
- expect(args[0]).to.exists;
- });
- });
- describe("#getUrl()", function() {
- beforeEach(function(){
- controller.reopen({
- realStackUrl: 'realStackUrl',
- realRepoUrl: 'realRepoUrl',
- realUpdateUrl: 'realUpdateUrl'
- });
- });
- it("full load is true, stack is null", function() {
- expect(controller.getUrl(null, true)).to.equal('realRepoUrl');
- });
- it("full load is true, stack is valid", function() {
- expect(controller.getUrl({}, true)).to.equal('realStackUrl');
- });
- it("full load is false, stack is valid", function() {
- expect(controller.getUrl({}, false)).to.equal('realUpdateUrl');
- });
- });
- describe("#loadStackVersionsToModel()", function () {
- before(function () {
- sinon.stub(App.HttpClient, 'get');
- });
- after(function () {
- App.HttpClient.get.restore();
- });
- it("HttpClient did get-request", function () {
- controller.loadStackVersionsToModel();
- expect(App.HttpClient.get.calledOnce).to.be.true;
- });
- });
- describe("#loadRepoVersionsToModel()", function () {
- before(function () {
- sinon.stub(App.HttpClient, 'get');
- });
- after(function () {
- App.HttpClient.get.restore();
- });
- it("HttpClient did get-request", function () {
- controller.loadRepoVersionsToModel();
- expect(App.HttpClient.get.calledOnce).to.be.true;
- });
- });
- describe('#currentVersionObserver()', function () {
- var cases = [
- {
- stackVersionType: 'HDP',
- repoVersion: '2.2.1.1.0-1',
- isStormMetricsSupported: false,
- title: 'HDP < 2.2.2'
- },
- {
- stackVersionType: 'HDP',
- repoVersion: '2.2.2.1.0-1',
- isStormMetricsSupported: true,
- title: 'HDP 2.2.2'
- },
- {
- stackVersionType: 'HDP',
- repoVersion: '2.2.3.1.0-1',
- isStormMetricsSupported: true,
- title: 'HDP > 2.2.2'
- },
- {
- stackVersionType: 'BIGTOP',
- repoVersion: '0.8.1.1.0-1',
- isStormMetricsSupported: true,
- title: 'not HDP'
- }
- ];
- afterEach(function () {
- App.RepositoryVersion.find.restore();
- });
- cases.forEach(function (item) {
- describe(item.title, function () {
- beforeEach(function () {
- sinon.stub(App.RepositoryVersion, 'find').returns([
- Em.Object.create({
- status: 'CURRENT',
- stackVersionType: item.stackVersionType
- })
- ]);
- controller.set('currentVersion', {
- repository_version: item.repoVersion
- });
- });
- it('isStormMetricsSupported is ' + (item.isStormMetricsSupported ? '' : 'not') + ' supported', function () {
- expect(App.get('isStormMetricsSupported')).to.equal(item.isStormMetricsSupported);
- });
- });
- });
- });
- describe('#updateFinalize', function () {
- beforeEach(function() {
- controller.set('isFinalizeItem', true);
- this.stub = sinon.stub(App, 'get');
- });
- afterEach(function () {
- this.stub.restore();
- });
- describe('should do ajax-request', function () {
- beforeEach(function () {
- this.stub.withArgs('upgradeState').returns('HOLDING');
- controller.updateFinalize();
- this.args = testHelpers.findAjaxRequest('name', 'admin.upgrade.finalizeContext');
- });
- it('request is sent', function () {
- expect(this.args[0]).to.exists;
- });
- });
- describe('shouldn\'t do ajax-request', function () {
- beforeEach(function () {
- this.stub.withArgs('upgradeState').returns('HOLDING_TIMEDOUT');
- controller.updateFinalize();
- this.args = testHelpers.findAjaxRequest('name', 'admin.upgrade.finalizeContext');
- });
- it('request is not sent', function () {
- expect(this.args).to.not.exists;
- });
- it('isFinalizeItem is false', function () {
- expect(controller.get('isFinalizeItem')).to.be.false;
- });
- });
- });
- describe('#updateFinalizeSuccessCallback', function () {
- it('data exists and Finalize should be true', function() {
- var data = {
- items: [
- {
- upgrade_groups: [
- {
- upgrade_items: [
- {
- UpgradeItem: {
- context: controller.get('finalizeContext'),
- status: "HOLDING"
- }
- }
- ]
- }
- ]
- }
- ]
- };
- controller.set('isFinalizeItem', false);
- controller.updateFinalizeSuccessCallback(data);
- expect(controller.get('isFinalizeItem')).to.be.true;
- });
- it('data exists and Finalize should be false', function() {
- var data = {
- upgrade_groups: [
- {
- upgrade_items: [
- {
- UpgradeItem: {
- context: '!@#$%^&',
- status: "HOLDING"
- }
- }
- ]
- }
- ]
- };
- controller.set('isFinalizeItem', true);
- controller.updateFinalizeSuccessCallback(data);
- expect(controller.get('isFinalizeItem')).to.be.false;
- });
- it('data doesn\'t exist', function() {
- var data = null;
- controller.set('isFinalizeItem', true);
- controller.updateFinalizeSuccessCallback(data);
- expect(controller.get('isFinalizeItem')).to.be.false;
- });
- });
- describe('#updateFinalizeErrorCallback', function () {
- it('should set isFinalizeItem to false', function () {
- controller.set('isFinalizeItem', true);
- controller.updateFinalizeErrorCallback();
- expect(controller.get('isFinalizeItem')).to.be.false;
- });
- });
- describe("#suspendUpgrade()", function() {
- beforeEach(function () {
- sinon.stub(controller, 'abortUpgrade').returns({
- done: Em.clb
- });
- sinon.stub(controller, 'setDBProperty', Em.K);
- sinon.stub(App.clusterStatus, 'setClusterStatus', Em.K);
- controller.suspendUpgrade();
- });
- afterEach(function () {
- controller.abortUpgrade.restore();
- controller.setDBProperty.restore();
- App.clusterStatus.setClusterStatus.restore();
- });
- it("upgrade aborted", function() {
- expect(controller.abortUpgrade.calledOnce).to.be.true;
- });
- it('App.upgradeState is ABORTED', function () {
- expect(App.get('upgradeState')).to.equal('ABORTED');
- });
- it('new upgradeState is saved to the localDB', function () {
- expect(controller.setDBProperty.calledWith('upgradeState', 'ABORTED')).to.be.true;
- });
- it('clusterStatus is updated', function () {
- expect(App.clusterStatus.setClusterStatus.calledOnce).to.be.true;
- });
- });
- describe("#resumeUpgrade()", function() {
- beforeEach(function () {
- sinon.stub(controller, 'retryUpgrade').returns({
- done: Em.clb
- });
- sinon.stub(controller, 'setDBProperty', Em.K);
- sinon.stub(App.clusterStatus, 'setClusterStatus', Em.K);
- controller.resumeUpgrade();
- });
- afterEach(function () {
- controller.retryUpgrade.restore();
- controller.setDBProperty.restore();
- App.clusterStatus.setClusterStatus.restore();
- });
- it("Upgrade is retrying", function() {
- expect(controller.retryUpgrade.calledOnce).to.be.true;
- });
- it('App.upgradeState is PENDING', function () {
- expect(App.get('upgradeState')).to.equal('PENDING');
- });
- it('new upgradeState is saved to the localDB', function () {
- expect(controller.setDBProperty.calledWith('upgradeState', 'PENDING')).to.be.true;
- });
- it('clusterStatus is updated', function () {
- expect(App.clusterStatus.setClusterStatus.calledOnce).to.be.true;
- });
- });
- describe("#runUpgradeMethodChecks()", function() {
- beforeEach(function () {
- sinon.stub(controller, 'runPreUpgradeCheckOnly');
- });
- afterEach(function () {
- controller.runPreUpgradeCheckOnly.restore();
- controller.get('upgradeMethods').setEach('allowed', true);
- });
- it("no allowed upgrade methods", function () {
- controller.get('upgradeMethods').setEach('allowed', false);
- controller.runUpgradeMethodChecks();
- expect(controller.runPreUpgradeCheckOnly.called).to.be.false;
- });
- it("Rolling method allowed", function () {
- controller.get('upgradeMethods').setEach('allowed', true);
- controller.runUpgradeMethodChecks(Em.Object.create({
- repositoryVersion: 'v1',
- displayName: 'V1'
- }));
- expect(controller.runPreUpgradeCheckOnly.calledWith({
- value: 'v1',
- label: 'V1',
- type: 'ROLLING'
- })).to.be.true;
- });
- });
- describe("#restoreLastUpgrade()", function () {
- var data = {
- Upgrade: {
- request_id: 1,
- direction: 'UPGRADE',
- request_status: 'PENDING',
- upgrade_type: 'ROLLING',
- downgrade_allowed: true,
- skip_failures: true,
- skip_service_check_failures: true,
- to_version: '1'
- }
- };
- beforeEach(function () {
- sinon.stub(App.RepositoryVersion, 'find').returns([Em.Object.create({
- repositoryVersion: '1',
- displayName: 'HDP-1'
- })]);
- sinon.stub(controller, 'setDBProperties');
- sinon.stub(controller, 'loadRepoVersionsToModel', function () {
- return {
- done: function (callback) {
- callback();
- }
- }
- });
- sinon.stub(controller, 'setDBProperty');
- sinon.stub(controller, 'initDBProperties');
- sinon.stub(controller, 'loadUpgradeData');
- controller.restoreLastUpgrade(data);
- });
- afterEach(function () {
- App.RepositoryVersion.find.restore();
- controller.setDBProperties.restore();
- controller.loadRepoVersionsToModel.restore();
- controller.setDBProperty.restore();
- controller.initDBProperties.restore();
- controller.loadUpgradeData.restore();
- });
- it('proper data is saved to the localDB', function () {
- expect(controller.setDBProperties.getCall(0).args[0]).to.eql({
- upgradeId: 1,
- isDowngrade: false,
- upgradeState: 'PENDING',
- upgradeType: "ROLLING",
- downgradeAllowed: true,
- upgradeTypeDisplayName: Em.I18n.t('admin.stackVersions.version.upgrade.upgradeOptions.RU.title'),
- failuresTolerance: Em.Object.create({
- skipComponentFailures: true,
- skipSCFailures: true
- })
- });
- });
- it('models are saved', function () {
- expect(controller.loadRepoVersionsToModel.calledOnce).to.be.true;
- });
- it('correct upgradeVersion is saved to the DB', function () {
- expect(controller.setDBProperty.calledWith('upgradeVersion', 'HDP-1')).to.be.true;
- });
- it('initDBProperties is called', function () {
- expect(controller.initDBProperties.calledOnce).to.be.true;
- });
- it('loadUpgradeData called with valid arguments', function () {
- expect(controller.loadUpgradeData.calledWith(true)).to.be.true;
- });
- });
- describe("#getServiceCheckItemSuccessCallback()", function() {
- var testCases = [
- {
- title: 'no tasks',
- data: {
- tasks: []
- },
- expected: {
- slaveComponentStructuredInfo: null,
- serviceCheckFailuresServicenames: []
- }
- },
- {
- title: 'no structured_out property',
- data: {
- tasks: [
- {
- Tasks: {}
- }
- ]
- },
- expected: {
- slaveComponentStructuredInfo: null,
- serviceCheckFailuresServicenames: []
- }
- },
- {
- title: 'no failures',
- data: {
- tasks: [
- {
- Tasks: {
- structured_out: {}
- }
- }
- ]
- },
- expected: {
- slaveComponentStructuredInfo: null,
- serviceCheckFailuresServicenames: []
- }
- },
- {
- title: 'service check failures',
- data: {
- tasks: [
- {
- Tasks: {
- structured_out: {
- failures: {
- service_check: ['HDSF', 'YARN']
- }
- }
- }
- }
- ]
- },
- expected: {
- slaveComponentStructuredInfo: {
- hosts: [],
- host_detail: {}
- },
- serviceCheckFailuresServicenames: ['HDSF', 'YARN']
- }
- },
- {
- title: 'host-component failures',
- data: {
- tasks: [
- {
- Tasks: {
- structured_out: {
- failures: {
- service_check: ['HDSF'],
- host_component: {
- "host1": [
- {
- component: "DATANODE",
- service: 'HDFS'
- }
- ]
- }
- }
- }
- }
- }
- ]
- },
- expected: {
- slaveComponentStructuredInfo: {
- hosts: ['host1'],
- host_detail: {
- "host1": [
- {
- component: "DATANODE",
- service: 'HDFS'
- }
- ]
- }
- },
- serviceCheckFailuresServicenames: ['HDSF']
- }
- }
- ];
- testCases.forEach(function(test) {
- it(test.title, function() {
- controller.set('slaveComponentStructuredInfo', null);
- controller.set('serviceCheckFailuresServicenames', []);
- controller.getServiceCheckItemSuccessCallback(test.data);
- expect(controller.get('serviceCheckFailuresServicenames')).eql(test.expected.serviceCheckFailuresServicenames);
- expect(controller.get('slaveComponentStructuredInfo')).eql(test.expected.slaveComponentStructuredInfo);
- });
- });
- });
- describe("#getSlaveComponentItemSuccessCallback()", function () {
- var testCases = [
- {
- title: 'no tasks',
- data: {
- tasks: []
- },
- expected: {
- slaveComponentStructuredInfo: null
- }
- },
- {
- title: 'structured_out property absent',
- data: {
- tasks: [
- {
- Tasks: {}
- }
- ]
- },
- expected: {
- slaveComponentStructuredInfo: null
- }
- },
- {
- title: 'structured_out property present',
- data: {
- tasks: [
- {
- Tasks: {
- "structured_out" : {
- "hosts" : [
- "host1"
- ],
- "host_detail" : {
- "host1" : [
- {
- "service" : "FLUME",
- "component" : "FLUME_HANDLER"
- }
- ]
- }
- }
- }
- }
- ]
- },
- expected: {
- slaveComponentStructuredInfo: {
- "hosts" : [
- "host1"
- ],
- "host_detail" : {
- "host1" : [
- {
- "service" : "FLUME",
- "component" : "FLUME_HANDLER"
- }
- ]
- }
- }
- }
- }
- ];
- testCases.forEach(function (test) {
- it(test.title, function () {
- controller.set('slaveComponentStructuredInfo', null);
- controller.getSlaveComponentItemSuccessCallback(test.data);
- expect(controller.get('slaveComponentStructuredInfo')).eql(test.expected.slaveComponentStructuredInfo);
- });
- });
- });
- describe('#getConfigsWarnings', function () {
- var cases = [
- {
- configs: [],
- title: 'no warning'
- },
- {
- configsMergeWarning: {},
- configs: [],
- title: 'empty data'
- },
- {
- configsMergeWarning: {
- UpgradeChecks: {}
- },
- configs: [],
- title: 'incomplete data'
- },
- {
- configsMergeWarning: {
- UpgradeChecks: {
- failed_detail: {}
- }
- },
- configs: [],
- title: 'invalid data'
- },
- {
- configsMergeWarning: {
- UpgradeChecks: {
- failed_detail: []
- }
- },
- configs: [],
- title: 'empty configs array'
- },
- {
- configsMergeWarning: {
- UpgradeChecks: {
- status: 'FAIL',
- failed_detail: [
- {
- type: 't0',
- property: 'p0',
- current: 'c0',
- new_stack_value: 'n0',
- result_value: 'r0'
- },
- {
- type: 't1',
- property: 'p1',
- current: 'c1',
- new_stack_value: 'n1'
- },
- {
- type: 't2',
- property: 'p2',
- current: 'c2',
- result_value: 'r2'
- }
- ]
- }
- },
- configs: [],
- title: 'not a warning'
- },
- {
- configsMergeWarning: {
- UpgradeChecks: {
- status: 'WARNING',
- failed_detail: [
- {
- type: 't0',
- property: 'p0',
- current: 'c0',
- new_stack_value: 'n0',
- result_value: 'r0'
- },
- {
- type: 't1',
- property: 'p1',
- current: 'c1',
- new_stack_value: 'n1'
- },
- {
- type: 't2',
- property: 'p2',
- current: 'c2',
- result_value: 'r2'
- }
- ]
- }
- },
- configs: [
- {
- type: 't0',
- name: 'p0',
- currentValue: 'c0',
- recommendedValue: 'n0',
- isDeprecated: false,
- resultingValue: 'r0',
- willBeRemoved: false
- },
- {
- type: 't1',
- name: 'p1',
- currentValue: 'c1',
- recommendedValue: 'n1',
- isDeprecated: false,
- resultingValue: Em.I18n.t('popup.clusterCheck.Upgrade.configsMerge.willBeRemoved'),
- willBeRemoved: true
- },
- {
- type: 't2',
- name: 'p2',
- currentValue: 'c2',
- recommendedValue: Em.I18n.t('popup.clusterCheck.Upgrade.configsMerge.deprecated'),
- isDeprecated: true,
- resultingValue: 'r2',
- willBeRemoved: false
- }
- ],
- title: 'normal case'
- }
- ];
- cases.forEach(function (item) {
- it(item.title, function () {
- expect(controller.getConfigsWarnings(item.configsMergeWarning)).to.eql(item.configs);
- });
- });
- });
- describe('#runPreUpgradeCheckOnly', function () {
- var appGetMock,
- upgradeMethods = controller.get('upgradeMethods'),
- cases = [
- {
- supportsPreUpgradeCheck: false,
- ru: {
- isCheckComplete: true,
- isCheckRequestInProgress: false,
- action: 'a'
- },
- eu: {
- isCheckComplete: true,
- isCheckRequestInProgress: false,
- action: 'a'
- },
- ajaxCallCount: 0,
- runningCheckRequestsLength: 0,
- title: 'pre-upgrade checks not supported'
- },
- {
- supportsPreUpgradeCheck: true,
- ru: {
- isCheckComplete: false,
- isCheckRequestInProgress: true,
- action: ''
- },
- eu: {
- isCheckComplete: true,
- isCheckRequestInProgress: false,
- action: 'a'
- },
- ajaxCallCount: 1,
- type: 'ROLLING',
- runningCheckRequestsLength: 1,
- title: 'rolling upgrade'
- },
- {
- supportsPreUpgradeCheck: true,
- ru: {
- isCheckComplete: true,
- isCheckRequestInProgress: false,
- action: 'a'
- },
- eu: {
- isCheckComplete: false,
- isCheckRequestInProgress: true,
- action: ''
- },
- ajaxCallCount: 1,
- type: 'NON_ROLLING',
- runningCheckRequestsLength: 1,
- title: 'express upgrade'
- }
- ];
- beforeEach(function () {
- appGetMock = sinon.stub(App, 'get');
- controller.get('runningCheckRequests').clear();
- upgradeMethods.forEach(function (method) {
- method.setProperties({
- isCheckComplete: true,
- isCheckRequestInProgress: false,
- action: 'a'
- });
- });
- App.ajax.send.restore();
- sinon.stub(App.ajax, 'send').returns({});
- });
- afterEach(function () {
- appGetMock.restore();
- });
- cases.forEach(function (item) {
- describe(item.title, function () {
- var runningCheckRequests;
- beforeEach(function () {
- runningCheckRequests = controller.get('runningCheckRequests');
- appGetMock.returns(item.supportsPreUpgradeCheck);
- controller.runPreUpgradeCheckOnly({
- type: item.type
- });
- this.ajaxCalls = testHelpers.filterAjaxRequests('name', 'admin.upgrade.pre_upgrade_check');
- });
- it('ROLLING properties', function () {
- expect(upgradeMethods.findProperty('type', 'ROLLING').getProperties('isCheckComplete', 'isCheckRequestInProgress', 'action')).to.eql(item.ru);
- });
- it('NON_ROLLING properties', function () {
- expect(upgradeMethods.findProperty('type', 'NON_ROLLING').getProperties('isCheckComplete', 'isCheckRequestInProgress', 'action')).to.eql(item.eu);
- });
- it(item.ajaxCallCount + ' requests sent', function () {
- expect(this.ajaxCalls.length).to.be.equal(item.ajaxCallCount);
- });
- it('runningCheckRequests length is ' + item.runningCheckRequestsLength, function () {
- expect(runningCheckRequests).to.have.length(item.runningCheckRequestsLength);
- });
- if (item.runningCheckRequestsLength) {
- it('runningCheckRequests.type is ' + item.type, function () {
- expect(runningCheckRequests[0].type).to.equal(item.type);
- });
- }
- });
- });
- });
- describe("#openConfigsInNewWindow()", function () {
- var mock = {
- document: {
- write: function () {}
- },
- focus: function () {}
- };
- beforeEach(function(){
- sinon.stub(window, 'open', function () {
- return mock;
- });
- sinon.spy(mock.document, 'write');
- sinon.spy(mock, 'focus');
- controller.openConfigsInNewWindow({
- context: [
- {
- type: 'type1',
- name: 'name1',
- currentValue: 'currentValue1',
- recommendedValue: 'recommendedValue1',
- resultingValue: 'resultingValue1'
- },
- {
- type: 'type2',
- name: 'name2',
- currentValue: 'currentValue2',
- recommendedValue: 'recommendedValue2',
- resultingValue: 'resultingValue2'
- }
- ]
- });
- });
- afterEach(function(){
- window.open.restore();
- mock.document.write.restore();
- mock.focus.restore();
- });
- it('new window is open', function () {
- expect(window.open.calledOnce).to.be.true;
- });
- it('new window content is valid', function () {
- /*eslint-disable no-useless-concat */
- expect(mock.document.write.calledWith('<table style="text-align: left;"><thead><tr>' +
- '<th>' + Em.I18n.t('popup.clusterCheck.Upgrade.configsMerge.configType') + '</th>' +
- '<th>' + Em.I18n.t('popup.clusterCheck.Upgrade.configsMerge.propertyName') + '</th>' +
- '<th>' + Em.I18n.t('popup.clusterCheck.Upgrade.configsMerge.currentValue') + '</th>' +
- '<th>' + Em.I18n.t('popup.clusterCheck.Upgrade.configsMerge.recommendedValue') + '</th>' +
- '<th>' + Em.I18n.t('popup.clusterCheck.Upgrade.configsMerge.resultingValue') + '</th>' +
- '</tr></thead><tbody>' +
- '<tr>' +
- '<td>' + 'type1' + '</td>' +
- '<td>' + 'name1' + '</td>' +
- '<td>' + 'currentValue1' + '</td>' +
- '<td>' + 'recommendedValue1' + '</td>' +
- '<td>' + 'resultingValue1' + '</td>' +
- '</tr>' +
- '<tr>' +
- '<td>' + 'type2' + '</td>' +
- '<td>' + 'name2' + '</td>' +
- '<td>' + 'currentValue2' + '</td>' +
- '<td>' + 'recommendedValue2' + '</td>' +
- '<td>' + 'resultingValue2' + '</td>' +
- '</tr></tbody></table>')).to.be.true;
- /*eslint-enable no-useless-concat */
- });
- it('document.focus is called once', function () {
- expect(mock.focus.calledOnce).to.be.true;
- });
- });
- });
|