Matteo Scandolo | d2044a4 | 2017-08-07 16:08:28 -0700 | [diff] [blame] | 1 | |
| 2 | /* |
| 3 | * Copyright 2017-present Open Networking Foundation |
| 4 | |
| 5 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | * you may not use this file except in compliance with the License. |
| 7 | * You may obtain a copy of the License at |
| 8 | |
| 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | |
| 11 | * Unless required by applicable law or agreed to in writing, software |
| 12 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | * See the License for the specific language governing permissions and |
| 15 | * limitations under the License. |
| 16 | */ |
| 17 | |
| 18 | |
Matteo Scandolo | cc0db94 | 2016-02-11 17:37:08 -0800 | [diff] [blame] | 19 | (function () { |
| 20 | 'use strict'; |
| 21 | |
| 22 | const computeNodes = [ |
| 23 | { |
| 24 | humanReadableName: 'cp-1.teone.xos-pg0.clemson.cloudlab.us', |
| 25 | instances: [ |
| 26 | { |
| 27 | instance_name: 'mysite_clients-3' |
| 28 | }, |
| 29 | { |
| 30 | instance_name: 'mysite_clients-4' |
| 31 | }, |
| 32 | { |
| 33 | instance_name: 'mysite_clients-5' |
| 34 | } |
| 35 | ] |
| 36 | }, |
| 37 | { |
| 38 | humanReadableName: 'cp-2.teone.xos-pg0.clemson.cloudlab.us', |
| 39 | instances: [ |
| 40 | { |
| 41 | instance_name: 'mysite_clients-1' |
| 42 | }, |
| 43 | { |
| 44 | instance_name: 'mysite_clients-2' |
| 45 | } |
| 46 | ] |
| 47 | }, |
| 48 | { |
| 49 | humanReadableName: 'cp-2.teone.xos-pg0.clemson.cloudlab.us', |
| 50 | instances: [ |
| 51 | { |
| 52 | instance_name: 'mysite_clients-1' |
| 53 | }, |
| 54 | { |
| 55 | instance_name: 'mysite_clients-2' |
| 56 | } |
| 57 | ] |
| 58 | } |
| 59 | ]; |
| 60 | |
| 61 | describe('The Rack Helper Service', () => { |
| 62 | |
Matteo Scandolo | ca7db31 | 2016-02-16 12:50:50 -0800 | [diff] [blame] | 63 | var Service, Config; |
| 64 | |
| 65 | // results |
| 66 | var cp1, cp2, cp3, rack, instancePos, nodePos; |
Matteo Scandolo | cc0db94 | 2016-02-11 17:37:08 -0800 | [diff] [blame] | 67 | |
Matteo Scandolo | 930e4fd | 2016-03-07 16:41:25 -0800 | [diff] [blame] | 68 | beforeEach(module('xos.diagnostic')); |
Matteo Scandolo | cc0db94 | 2016-02-11 17:37:08 -0800 | [diff] [blame] | 69 | |
| 70 | // inject the rackHelper service |
Matteo Scandolo | ca7db31 | 2016-02-16 12:50:50 -0800 | [diff] [blame] | 71 | beforeEach(inject(function (_RackHelper_, _serviceTopologyConfig_) { |
Matteo Scandolo | cc0db94 | 2016-02-11 17:37:08 -0800 | [diff] [blame] | 72 | // The injector unwraps the underscores (_) from around the parameter names when matching |
| 73 | Service = _RackHelper_; |
Matteo Scandolo | ca7db31 | 2016-02-16 12:50:50 -0800 | [diff] [blame] | 74 | Config = _serviceTopologyConfig_; |
| 75 | |
| 76 | cp1 = { |
| 77 | width: (Config.instance.width * 2) + (Config.instance.margin * 3), |
| 78 | height: (Config.instance.height * 2) + (Config.instance.margin * 5) + Config.computeNode.labelHeight |
| 79 | }; |
| 80 | |
| 81 | cp2 = { |
| 82 | width: (Config.instance.width * 2) + (Config.instance.margin * 3), |
| 83 | height: Config.instance.height + (Config.instance.margin * 4) + Config.computeNode.labelHeight |
| 84 | }; |
| 85 | |
| 86 | cp3 = { |
| 87 | width: (Config.instance.width * 2) + (Config.instance.margin * 3), |
| 88 | height: Config.instance.height + (Config.instance.margin * 4) + Config.computeNode.labelHeight |
| 89 | }; |
| 90 | |
| 91 | rack = { |
| 92 | width: cp1.width + (Config.computeNode.margin * 2), |
| 93 | height: cp1.height + cp2.height + cp3.height + (Config.computeNode.margin * 4) |
| 94 | } |
| 95 | |
| 96 | instancePos = [ |
| 97 | { |
| 98 | x: Config.instance.margin, |
| 99 | y: Config.instance.margin + Service.getComputeNodeLabelSize() |
| 100 | }, |
| 101 | { |
| 102 | x: Config.instance.margin + (Config.instance.width * 1) + (Config.instance.margin * 1), |
| 103 | y: Config.instance.margin + Service.getComputeNodeLabelSize() |
| 104 | }, |
| 105 | { |
| 106 | x: Config.instance.margin, |
| 107 | y: Config.instance.margin + Service.getComputeNodeLabelSize() + + (Config.instance.height * 1) + (Config.instance.margin * 1) |
| 108 | }, |
| 109 | { |
| 110 | x: Config.instance.margin + (Config.instance.width * 1) + (Config.instance.margin * 1), |
| 111 | y: Config.instance.margin + Service.getComputeNodeLabelSize() + + (Config.instance.height * 1) + (Config.instance.margin * 1) |
| 112 | } |
| 113 | ]; |
| 114 | |
| 115 | nodePos = [ |
| 116 | { |
| 117 | x: Config.computeNode.margin, |
| 118 | y: Config.computeNode.margin |
| 119 | }, |
| 120 | { |
| 121 | x: Config.computeNode.margin, |
| 122 | y: (Config.computeNode.margin * 2) + cp1.height |
| 123 | }, |
| 124 | { |
| 125 | x: Config.computeNode.margin, |
| 126 | y: (Config.computeNode.margin * 3) + cp1.height + cp2.height |
| 127 | } |
| 128 | ] |
Matteo Scandolo | cc0db94 | 2016-02-11 17:37:08 -0800 | [diff] [blame] | 129 | })); |
| 130 | |
| 131 | describe('Given a list of instances', () => { |
Matteo Scandolo | ca7db31 | 2016-02-16 12:50:50 -0800 | [diff] [blame] | 132 | it('should calculate the first Compute Node Size', () => { |
Matteo Scandolo | cc0db94 | 2016-02-11 17:37:08 -0800 | [diff] [blame] | 133 | const [width, height] = Service.getComputeNodeSize(computeNodes[0].instances); |
Matteo Scandolo | ca7db31 | 2016-02-16 12:50:50 -0800 | [diff] [blame] | 134 | expect(width).toBe(cp1.width); |
| 135 | expect(height).toBe(cp1.height); |
| 136 | }); |
| 137 | |
| 138 | it('should calculate the second Compute Node Size', () => { |
| 139 | const [width, height] = Service.getComputeNodeSize(computeNodes[1].instances); |
| 140 | expect(width).toBe(cp2.width); |
| 141 | expect(height).toBe(cp2.height); |
| 142 | }); |
| 143 | |
| 144 | it('should calculate the third Compute Node Size', () => { |
| 145 | const [width, height] = Service.getComputeNodeSize(computeNodes[1].instances); |
| 146 | expect(width).toBe(cp3.width); |
| 147 | expect(height).toBe(cp3.height); |
Matteo Scandolo | cc0db94 | 2016-02-11 17:37:08 -0800 | [diff] [blame] | 148 | }); |
| 149 | }); |
| 150 | |
| 151 | describe('Given a list of Compute Nodes', () => { |
| 152 | it('should return rack size', () => { |
| 153 | const [width, height] = Service.getRackSize(computeNodes); |
Matteo Scandolo | ca7db31 | 2016-02-16 12:50:50 -0800 | [diff] [blame] | 154 | expect(width).toBe(rack.width); |
| 155 | expect(height).toBe(rack.height); |
Matteo Scandolo | cc0db94 | 2016-02-11 17:37:08 -0800 | [diff] [blame] | 156 | }); |
| 157 | }); |
| 158 | |
| 159 | describe('Given an instance index', () => { |
| 160 | it('should return the position for first instance', () => { |
| 161 | const [x, y] = Service.getInstancePosition(0); |
Matteo Scandolo | ca7db31 | 2016-02-16 12:50:50 -0800 | [diff] [blame] | 162 | expect(x).toBe(instancePos[0].x); |
| 163 | expect(y).toBe(instancePos[0].y); |
| 164 | }) |
Matteo Scandolo | cc0db94 | 2016-02-11 17:37:08 -0800 | [diff] [blame] | 165 | |
| 166 | it('should return the position for second instance', () => { |
| 167 | const [x, y] = Service.getInstancePosition(1); |
Matteo Scandolo | ca7db31 | 2016-02-16 12:50:50 -0800 | [diff] [blame] | 168 | expect(x).toBe(instancePos[1].x); |
| 169 | expect(y).toBe(instancePos[1].y); |
Matteo Scandolo | cc0db94 | 2016-02-11 17:37:08 -0800 | [diff] [blame] | 170 | }); |
| 171 | |
| 172 | it('should return the position for third instance', () => { |
| 173 | const [x, y] = Service.getInstancePosition(2); |
Matteo Scandolo | ca7db31 | 2016-02-16 12:50:50 -0800 | [diff] [blame] | 174 | expect(x).toBe(instancePos[2].x); |
| 175 | expect(y).toBe(instancePos[2].y); |
Matteo Scandolo | cc0db94 | 2016-02-11 17:37:08 -0800 | [diff] [blame] | 176 | }); |
| 177 | |
| 178 | it('should return the position for 4th instance', () => { |
| 179 | const [x, y] = Service.getInstancePosition(3); |
Matteo Scandolo | ca7db31 | 2016-02-16 12:50:50 -0800 | [diff] [blame] | 180 | expect(x).toBe(instancePos[3].x); |
| 181 | expect(y).toBe(instancePos[3].y); |
Matteo Scandolo | cc0db94 | 2016-02-11 17:37:08 -0800 | [diff] [blame] | 182 | }); |
| 183 | }); |
| 184 | |
| 185 | describe('Given an ComputeNode index', () => { |
| 186 | it('should return the position for 1st node', () => { |
| 187 | const [x, y] = Service.getComputeNodePosition(computeNodes, 0); |
Matteo Scandolo | ca7db31 | 2016-02-16 12:50:50 -0800 | [diff] [blame] | 188 | expect(x).toBe(nodePos[0].x); |
| 189 | expect(y).toBe(nodePos[0].y); |
| 190 | }) |
Matteo Scandolo | cc0db94 | 2016-02-11 17:37:08 -0800 | [diff] [blame] | 191 | |
| 192 | it('should return the position for 2st node', () => { |
| 193 | const [x, y] = Service.getComputeNodePosition(computeNodes, 1); |
Matteo Scandolo | ca7db31 | 2016-02-16 12:50:50 -0800 | [diff] [blame] | 194 | expect(x).toBe(nodePos[1].x); |
| 195 | expect(y).toBe(nodePos[1].y); |
Matteo Scandolo | cc0db94 | 2016-02-11 17:37:08 -0800 | [diff] [blame] | 196 | }); |
| 197 | |
| 198 | it('should return the position for 2st node', () => { |
| 199 | const [x, y] = Service.getComputeNodePosition(computeNodes, 2); |
Matteo Scandolo | ca7db31 | 2016-02-16 12:50:50 -0800 | [diff] [blame] | 200 | expect(x).toBe(nodePos[2].x); |
| 201 | expect(y).toBe(nodePos[2].y); |
Matteo Scandolo | cc0db94 | 2016-02-11 17:37:08 -0800 | [diff] [blame] | 202 | }); |
| 203 | }); |
| 204 | }); |
| 205 | })(); |