1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158 |
- /**
- * 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');
- 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() {
- beforeEach(function () {
- sinon.stub(App.ajax, 'send').returns({
- then: Em.K,
- complete: Em.K
- });
- });
- afterEach(function () {
- App.ajax.send.restore();
- });
- it("get entire data", function() {
- controller.set('upgradeId', 1);
- controller.loadUpgradeData();
- expect(App.ajax.send.getCall(0).args[0]).to.eql({
- name: 'admin.upgrade.data',
- sender: controller,
- data: {
- id: 1
- },
- success: 'loadUpgradeDataSuccessCallback'
- })
- });
- it("get only state", function() {
- controller.set('upgradeId', 1);
- controller.loadUpgradeData(true);
- expect(App.ajax.send.getCall(0).args[0]).to.eql({
- name: 'admin.upgrade.state',
- sender: controller,
- data: {
- id: 1
- },
- success: 'loadUpgradeDataSuccessCallback'
- })
- });
- it("upgrade id is null", function() {
- controller.set('upgradeId', null);
- controller.loadUpgradeData();
- expect(App.ajax.send.called).to.be.false;
- });
- });
- 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() {
- beforeEach(function () {
- sinon.stub(App.ajax, 'send', Em.K);
- });
- afterEach(function () {
- App.ajax.send.restore();
- });
- it("default callback", function() {
- var item = Em.Object.create({
- request_id: 1,
- group_id: 2,
- stage_id: 3
- });
- controller.getUpgradeItem(item);
- expect(App.ajax.send.getCall(0).args[0]).to.eql({
- name: 'admin.upgrade.upgrade_item',
- sender: controller,
- data: {
- upgradeId: 1,
- groupId: 2,
- stageId: 3
- },
- success: 'getUpgradeItemSuccessCallback'
- });
- });
- it("custom callback", function() {
- var item = Em.Object.create({
- request_id: 1,
- group_id: 2,
- stage_id: 3
- });
- controller.getUpgradeItem(item, 'customCallback');
- expect(App.ajax.send.getCall(0).args[0]).to.eql({
- name: 'admin.upgrade.upgrade_item',
- sender: controller,
- data: {
- upgradeId: 1,
- groupId: 2,
- stageId: 3
- },
- success: 'customCallback'
- });
- });
- });
- 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() {
- before(function () {
- sinon.stub(App.ajax, 'send', Em.K);
- });
- after(function () {
- App.ajax.send.restore();
- });
- it("make ajax call", function() {
- controller.runPreUpgradeCheck(Em.Object.create({
- repositoryVersion: '2.2',
- displayName: 'HDP-2.2',
- upgradeType: 'ROLLING',
- skipComponentFailures: false,
- skipSCFailures: false
- }));
- expect(App.ajax.send.getCall(0).args[0]).to.eql({
- name: "admin.upgrade.pre_upgrade_check",
- sender: controller,
- data: {
- value: '2.2',
- label: 'HDP-2.2',
- type: 'ROLLING',
- skipComponentFailures: 'false',
- skipSCFailures: 'false'
- },
- success: "runPreUpgradeCheckSuccess",
- error: "runPreUpgradeCheckError"
- });
- });
- });
- 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(App.ajax, 'send', Em.K);
- sinon.stub(controller, 'setDBProperty', Em.K);
- controller.set('currentVersion', {
- repository_version: '2.2'
- });
- controller.upgrade({
- value: '2.2',
- label: 'HDP-2.2'
- });
- callArgs = App.ajax.send.getCall(0).args[0];
- });
- afterEach(function () {
- App.ajax.send.restore();
- 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(App.ajax, 'send', Em.K);
- 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 = App.ajax.send.getCall(0).args[0];
- });
- afterEach(function () {
- App.ajax.send.restore();
- 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(App.ajax.send.getCall(0).args[0].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.eql('admin.downgrade.start');
- });
- it('request-sender is valid', function () {
- expect(this.callArgs.sender).to.eql(controller);
- });
- it('callback is valid', function () {
- expect(this.callArgs.success).to.eql('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 () {
- before(function () {
- sinon.stub(App.ajax, 'send', Em.K);
- });
- after(function () {
- App.ajax.send.restore();
- });
- it("make ajax call", function () {
- var repo = Em.Object.create({
- stackVersionType: 'HDP',
- stackVersionNumber: '2.2',
- repositoryVersion: '2.2.1',
- repoId: 1
- });
- controller.installRepoVersion(repo);
- expect(App.ajax.send.calledOnce).to.be.true;
- });
- });
- 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 () {
- sinon.stub(App.ajax, 'send', function () {
- return {
- done: Em.clb
- }
- });
- item = Em.Object.create({
- request_id: 1,
- stage_id: 1,
- group_id: 1
- });
- controller.setUpgradeItemStatus(item, 'PENDING');
- this.callArgs = App.ajax.send.getCall(0).args[0];
- });
- afterEach(function () {
- App.ajax.send.restore();
- });
- it('request-data is valid', function () {
- expect(this.callArgs.data).to.eql({upgradeId: 1, itemId: 1, groupId: 1, status: 'PENDING'});
- });
- it('request-name is valid', function () {
- expect(this.callArgs.name).to.eql('admin.upgrade.upgradeItem.setState');
- });
- it('request-sendeer is valid', function () {
- expect(this.callArgs.sender).to.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);
- sinon.stub(App.ajax, 'send').returns({success: Em.K});
- });
- after(function(){
- this.mock.restore();
- controller.prepareRepoForSaving.restore();
- App.ajax.send.restore();
- });
- it("validation errors present", function() {
- this.mock.returns({
- done: function(callback) {callback([1]);}
- });
- controller.saveRepoOS(Em.Object.create({repoVersionId: 1}), true);
- expect(controller.validateRepoVersions.calledWith(Em.Object.create({repoVersionId: 1}), true)).to.be.true;
- expect(controller.prepareRepoForSaving.called).to.be.false;
- expect(App.ajax.send.called).to.be.false;
- });
- it("no validation errors", function() {
- this.mock.returns({
- done: function(callback) {callback([]);}
- });
- controller.saveRepoOS(Em.Object.create({repoVersionId: 1}), true);
- expect(controller.validateRepoVersions.calledWith(Em.Object.create({repoVersionId: 1}), true)).to.be.true;
- expect(controller.prepareRepoForSaving.calledWith(Em.Object.create({repoVersionId: 1}))).to.be.true;
- });
- });
- describe("#validateRepoVersions()", function () {
- before(function () {
- sinon.stub(App.ajax, 'send').returns({success: Em.K, error: Em.K});
- });
- after(function () {
- App.ajax.send.restore();
- });
- it("skip validation", function () {
- controller.validateRepoVersions(Em.Object.create({repoVersionId: 1}), true);
- expect(App.ajax.send.called).to.be.false;
- });
- 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);
- expect(App.ajax.send.calledOnce).to.be.true;
- });
- });
- 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() {
- sinon.stub($, 'ajax', Em.K);
- controller.set('isFinalizeItem', true);
- this.stub = sinon.stub(App, 'get');
- });
- afterEach(function () {
- $.ajax.restore();
- this.stub.restore();
- });
- describe('should do ajax-request', function () {
- beforeEach(function () {
- this.stub.withArgs('upgradeState').returns('HOLDING');
- controller.updateFinalize();
- });
- it('request is sent', function () {
- expect($.ajax.calledOnce).to.be.true;
- });
- });
- describe('shouldn\'t do ajax-request', function () {
- beforeEach(function () {
- this.stub.withArgs('upgradeState').returns('HOLDING_TIMEDOUT');
- controller.updateFinalize();
- });
- it('request is not sent', function () {
- expect($.ajax.called).to.be.false;
- });
- 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'
- });
- });
- sinon.stub(App.ajax, 'send').returns({});
- });
- afterEach(function () {
- appGetMock.restore();
- App.ajax.send.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
- });
- });
- 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(App.ajax.send.callCount).to.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;
- });
- });
- });
|