blob: 763302997969c2e32581a32b87c56a50fbe995f5 [file] [log] [blame]
Matteo Scandolod2044a42017-08-07 16:08:28 -07001
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 Scandolocc0db942016-02-11 17:37:08 -080019(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 Scandoloca7db312016-02-16 12:50:50 -080063 var Service, Config;
64
65 // results
66 var cp1, cp2, cp3, rack, instancePos, nodePos;
Matteo Scandolocc0db942016-02-11 17:37:08 -080067
Matteo Scandolo930e4fd2016-03-07 16:41:25 -080068 beforeEach(module('xos.diagnostic'));
Matteo Scandolocc0db942016-02-11 17:37:08 -080069
70 // inject the rackHelper service
Matteo Scandoloca7db312016-02-16 12:50:50 -080071 beforeEach(inject(function (_RackHelper_, _serviceTopologyConfig_) {
Matteo Scandolocc0db942016-02-11 17:37:08 -080072 // The injector unwraps the underscores (_) from around the parameter names when matching
73 Service = _RackHelper_;
Matteo Scandoloca7db312016-02-16 12:50:50 -080074 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 Scandolocc0db942016-02-11 17:37:08 -0800129 }));
130
131 describe('Given a list of instances', () => {
Matteo Scandoloca7db312016-02-16 12:50:50 -0800132 it('should calculate the first Compute Node Size', () => {
Matteo Scandolocc0db942016-02-11 17:37:08 -0800133 const [width, height] = Service.getComputeNodeSize(computeNodes[0].instances);
Matteo Scandoloca7db312016-02-16 12:50:50 -0800134 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 Scandolocc0db942016-02-11 17:37:08 -0800148 });
149 });
150
151 describe('Given a list of Compute Nodes', () => {
152 it('should return rack size', () => {
153 const [width, height] = Service.getRackSize(computeNodes);
Matteo Scandoloca7db312016-02-16 12:50:50 -0800154 expect(width).toBe(rack.width);
155 expect(height).toBe(rack.height);
Matteo Scandolocc0db942016-02-11 17:37:08 -0800156 });
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 Scandoloca7db312016-02-16 12:50:50 -0800162 expect(x).toBe(instancePos[0].x);
163 expect(y).toBe(instancePos[0].y);
164 })
Matteo Scandolocc0db942016-02-11 17:37:08 -0800165
166 it('should return the position for second instance', () => {
167 const [x, y] = Service.getInstancePosition(1);
Matteo Scandoloca7db312016-02-16 12:50:50 -0800168 expect(x).toBe(instancePos[1].x);
169 expect(y).toBe(instancePos[1].y);
Matteo Scandolocc0db942016-02-11 17:37:08 -0800170 });
171
172 it('should return the position for third instance', () => {
173 const [x, y] = Service.getInstancePosition(2);
Matteo Scandoloca7db312016-02-16 12:50:50 -0800174 expect(x).toBe(instancePos[2].x);
175 expect(y).toBe(instancePos[2].y);
Matteo Scandolocc0db942016-02-11 17:37:08 -0800176 });
177
178 it('should return the position for 4th instance', () => {
179 const [x, y] = Service.getInstancePosition(3);
Matteo Scandoloca7db312016-02-16 12:50:50 -0800180 expect(x).toBe(instancePos[3].x);
181 expect(y).toBe(instancePos[3].y);
Matteo Scandolocc0db942016-02-11 17:37:08 -0800182 });
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 Scandoloca7db312016-02-16 12:50:50 -0800188 expect(x).toBe(nodePos[0].x);
189 expect(y).toBe(nodePos[0].y);
190 })
Matteo Scandolocc0db942016-02-11 17:37:08 -0800191
192 it('should return the position for 2st node', () => {
193 const [x, y] = Service.getComputeNodePosition(computeNodes, 1);
Matteo Scandoloca7db312016-02-16 12:50:50 -0800194 expect(x).toBe(nodePos[1].x);
195 expect(y).toBe(nodePos[1].y);
Matteo Scandolocc0db942016-02-11 17:37:08 -0800196 });
197
198 it('should return the position for 2st node', () => {
199 const [x, y] = Service.getComputeNodePosition(computeNodes, 2);
Matteo Scandoloca7db312016-02-16 12:50:50 -0800200 expect(x).toBe(nodePos[2].x);
201 expect(y).toBe(nodePos[2].y);
Matteo Scandolocc0db942016-02-11 17:37:08 -0800202 });
203 });
204 });
205})();