123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463 |
- /**
- * 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');
- var misc = require('utils/misc');
- require('models/host');
- describe('App.Host', function () {
- var data = [
- {
- id: 'host1',
- host_name: 'host1',
- memory: 200000,
- disk_total: 100.555,
- disk_free: 90.555,
- health_status: 'HEALTHY',
- last_heart_beat_time: (new Date()).getTime() - 18100000
- },
- {
- id: 'host2',
- host_name: 'host2',
- memory: 99999,
- disk_total: 90,
- disk_free: 90,
- health_status: 'HEALTHY',
- last_heart_beat_time: (new Date()).getTime() - 170000
- },
- {
- id: 'host3',
- host_name: 'host3',
- memory: 99999,
- disk_total: 99.999,
- disk_free: 0,
- health_status: 'UNKNOWN',
- last_heart_beat_time: (new Date()).getTime()
- }
- ];
- before(function() {
- App.set('testMode', false);
- });
- App.Host.reopen({
- hostComponents: []
- });
- App.store.loadMany(App.Host, data);
- var host1 = App.Host.find('host1');
- describe('#diskUsedFormatted', function () {
- it('host1 - 10GB ', function () {
- expect(host1.get('diskUsedFormatted')).to.equal('10GB');
- });
- it('host2 - 0GB', function () {
- var host = App.Host.find().findProperty('hostName', 'host2');
- expect(host.get('diskUsedFormatted')).to.equal('0GB');
- });
- it('host3 - 100GB', function () {
- var host = App.Host.find().findProperty('hostName', 'host3');
- expect(host.get('diskUsedFormatted')).to.equal('100GB');
- });
- });
- describe('#diskTotalFormatted', function () {
- it('host1 - 100.56GB ', function () {
- expect(host1.get('diskTotalFormatted')).to.equal('100.56GB');
- });
- it('host2 - 90GB', function () {
- var host = App.Host.find().findProperty('hostName', 'host2');
- expect(host.get('diskTotalFormatted')).to.equal('90GB');
- });
- it('host3 - 100GB', function () {
- var host = App.Host.find().findProperty('hostName', 'host3');
- expect(host.get('diskTotalFormatted')).to.equal('100GB');
- });
- });
- describe('#diskUsageFormatted', function () {
- it('host1 - 9.94% ', function () {
- expect(host1.get('diskUsageFormatted')).to.equal('9.94%');
- });
- it('host2 - 0%', function () {
- var host = App.Host.find().findProperty('hostName', 'host2');
- expect(host.get('diskUsageFormatted')).to.equal('0%');
- });
- it('host3 - 100%', function () {
- var host = App.Host.find().findProperty('hostName', 'host3');
- expect(host.get('diskUsageFormatted')).to.equal('100%');
- });
- });
- describe('#isNotHeartBeating', function () {
- it('host2 - false', function () {
- var host = App.Host.find().findProperty('hostName', 'host2');
- expect(host.get('isNotHeartBeating')).to.equal(false);
- });
- it('host3 - false', function () {
- var host = App.Host.find().findProperty('hostName', 'host3');
- expect(host.get('isNotHeartBeating')).to.equal(true);
- });
- });
- describe('#cpuUsage', function () {
- var testCases = [
- {
- params: {
- cpuSystem: undefined,
- cpuUser: undefined
- },
- result: 0
- },
- {
- params: {
- cpuSystem: 0,
- cpuUser: 0
- },
- result: 0
- },
- {
- params: {
- cpuSystem: 1,
- cpuUser: 0
- },
- result: 0
- },
- {
- params: {
- cpuSystem: 0,
- cpuUser: 1
- },
- result: 0
- },
- {
- params: {
- cpuSystem: 1,
- cpuUser: 1
- },
- result: 2
- }
- ];
- testCases.forEach(function (test) {
- it('cpuSystem - ' + test.params.cpuSystem + ', cpuUser - ' + test.params.cpuUser, function () {
- host1.set('cpuSystem', test.params.cpuSystem);
- host1.set('cpuUser', test.params.cpuUser);
- host1.propertyDidChange('cpuUsage');
- expect(host1.get('cpuUsage')).to.equal(test.result);
- });
- });
- });
- describe('#memoryUsage', function () {
- var testCases = [
- {
- params: {
- memFree: undefined,
- memTotal: undefined
- },
- result: 0
- },
- {
- params: {
- memFree: 0,
- memTotal: 0
- },
- result: 0
- },
- {
- params: {
- memFree: 1,
- memTotal: 0
- },
- result: 0
- },
- {
- params: {
- memFree: 0,
- memTotal: 1
- },
- result: 0
- },
- {
- params: {
- memFree: 1,
- memTotal: 2
- },
- result: 50
- }
- ];
- testCases.forEach(function (test) {
- it('memFree - ' + test.params.memFree + ', memTotal - ' + test.params.memTotal, function () {
- host1.set('memFree', test.params.memFree);
- host1.set('memTotal', test.params.memTotal);
- host1.propertyDidChange('memoryUsage');
- expect(host1.get('memoryUsage')).to.equal(test.result);
- });
- });
- });
- describe('#componentsWithStaleConfigs', function () {
- it('One component with stale configs', function () {
- host1.set('hostComponents', [Em.Object.create({
- staleConfigs: true
- })]);
- host1.propertyDidChange('componentsWithStaleConfigs');
- expect(host1.get('componentsWithStaleConfigs')).to.eql([Em.Object.create({
- staleConfigs: true
- })]);
- });
- it('No components with stale configs', function () {
- host1.set('hostComponents', [Em.Object.create({
- staleConfigs: false
- })]);
- host1.propertyDidChange('componentsWithStaleConfigs');
- expect(host1.get('componentsWithStaleConfigs')).to.be.empty;
- });
- });
- describe('#componentsInPassiveStateCount', function () {
- it('No component in passive state', function () {
- host1.set('hostComponents', [Em.Object.create({
- passiveState: 'OFF'
- })]);
- host1.propertyDidChange('componentsInPassiveStateCount');
- expect(host1.get('componentsInPassiveStateCount')).to.equal(0);
- });
- it('One component in passive state', function () {
- host1.set('hostComponents', [Em.Object.create({
- passiveState: 'ON'
- })]);
- host1.propertyDidChange('componentsInPassiveStateCount');
- expect(host1.get('componentsInPassiveStateCount')).to.equal(1);
- });
- });
- describe('#disksMounted', function () {
- it('', function () {
- host1.set('diskInfo', [
- {}
- ]);
- host1.propertyDidChange('disksMounted');
- expect(host1.get('disksMounted')).to.equal(1);
- });
- });
- describe('#coresFormatted', function () {
- it('', function () {
- host1.set('cpu', 1);
- host1.set('cpuPhysical', 2);
- host1.propertyDidChange('coresFormatted');
- expect(host1.get('coresFormatted')).to.equal('1 (2)');
- });
- });
- describe('#diskUsed', function () {
- it('diskFree and diskTotal are 0', function () {
- host1.set('diskFree', 0);
- host1.set('diskTotal', 0);
- host1.propertyDidChange('diskUsed');
- expect(host1.get('diskUsed')).to.equal(0);
- });
- it('diskFree is 0 and diskTotal is 10', function () {
- host1.set('diskFree', 0);
- host1.set('diskTotal', 10);
- host1.propertyDidChange('diskUsed');
- expect(host1.get('diskUsed')).to.equal(10);
- });
- });
- describe('#diskUsage', function () {
- it('', function () {
- host1.reopen({
- diskUsed: 10
- });
- host1.set('diskTotal', 100);
- host1.propertyDidChange('diskUsage');
- expect(host1.get('diskUsage')).to.equal(10);
- });
- });
- describe('#memoryFormatted', function () {
- it('', function () {
- host1.set('memory', 1024);
- sinon.stub(misc, 'formatBandwidth', Em.K);
- host1.propertyDidChange('memoryFormatted');
- host1.get('memoryFormatted');
- expect(misc.formatBandwidth.calledWith(1048576)).to.be.true;
- misc.formatBandwidth.restore()
- });
- });
- describe('#loadAvg', function () {
- var testCases = [
- {
- params: {
- loadOne: null,
- loadFive: null,
- loadFifteen: null
- },
- result: null
- },
- {
- params: {
- loadOne: 1.111,
- loadFive: 5.555,
- loadFifteen: 15.555
- },
- result: '1.11'
- },
- {
- params: {
- loadOne: null,
- loadFive: 5.555,
- loadFifteen: 15.555
- },
- result: '5.55'
- },
- {
- params: {
- loadOne: null,
- loadFive: null,
- loadFifteen: 15.555
- },
- result: '15.55'
- }
- ];
- testCases.forEach(function (test) {
- it('loadOne - ' + test.params.loadOne + ', loadFive - ' + test.params.loadFive + ', loadFifteen - ' + test.params.loadFifteen, function () {
- host1.set('loadOne', test.params.loadOne);
- host1.set('loadFive', test.params.loadFive);
- host1.set('loadFifteen', test.params.loadFifteen);
- host1.propertyDidChange('loadAvg');
- expect(host1.get('loadAvg')).to.equal(test.result);
- });
- });
- });
- describe('#healthClass', function () {
- var testCases = [
- {
- params: {
- passiveState: 'ON',
- healthStatus: null
- },
- result: 'icon-medkit'
- },
- {
- params: {
- passiveState: 'OFF',
- healthStatus: 'UNKNOWN'
- },
- result: 'health-status-DEAD-YELLOW'
- },
- {
- params: {
- passiveState: 'OFF',
- healthStatus: 'HEALTHY'
- },
- result: 'health-status-LIVE'
- },
- {
- params: {
- passiveState: 'OFF',
- healthStatus: 'UNHEALTHY'
- },
- result: 'health-status-DEAD-RED'
- },
- {
- params: {
- passiveState: 'OFF',
- healthStatus: 'ALERT'
- },
- result: 'health-status-DEAD-ORANGE'
- },
- {
- params: {
- passiveState: 'OFF',
- healthStatus: null
- },
- result: 'health-status-DEAD-YELLOW'
- }
- ];
- testCases.forEach(function (test) {
- it('passiveState - ' + test.params.passiveState + ', healthStatus - ' + test.params.healthStatus, function () {
- host1.set('passiveState', test.params.passiveState);
- host1.set('healthStatus', test.params.healthStatus);
- host1.propertyDidChange('healthClass');
- expect(host1.get('healthClass')).to.equal(test.result);
- });
- });
- });
- describe('#healthIconClass', function () {
- var testCases = [
- {
- params: {
- healthClass: 'health-status-LIVE'
- },
- result: 'icon-ok-sign'
- },
- {
- params: {
- healthClass: 'health-status-DEAD-RED'
- },
- result: 'icon-warning-sign'
- },
- {
- params: {
- healthClass: 'health-status-DEAD-YELLOW'
- },
- result: 'icon-question-sign'
- },
- {
- params: {
- healthClass: 'health-status-DEAD-ORANGE'
- },
- result: 'icon-minus-sign'
- },
- {
- params: {
- healthClass: ''
- },
- result: ''
- }
- ];
- it('reset healthClass to plain property', function(){
- host1.reopen({
- healthClass: ''
- });
- });
- testCases.forEach(function (test) {
- it('healthClass - ' + test.params.healthClass, function () {
- host1.set('healthClass', test.params.healthClass);
- host1.propertyDidChange('healthIconClass');
- expect(host1.get('healthIconClass')).to.equal(test.result);
- });
- });
- });
- });
|