|
| 1 | +// Licensed to the Apache Software Foundation (ASF) under one |
| 2 | +// or more contributor license agreements. See the NOTICE file |
| 3 | +// distributed with this work for additional information |
| 4 | +// regarding copyright ownership. The ASF licenses this file |
| 5 | +// to you under the Apache License, Version 2.0 (the |
| 6 | +// "License"); you may not use this file except in compliance |
| 7 | +// with the License. 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, |
| 12 | +// software distributed under the License is distributed on an |
| 13 | +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 14 | +// KIND, either express or implied. See the License for the |
| 15 | +// specific language governing permissions and limitations |
| 16 | +// under the License. |
| 17 | +package com.cloud.host; |
| 18 | + |
| 19 | +import com.cloud.resource.ResourceState; |
| 20 | + |
| 21 | +import junit.framework.TestCase; |
| 22 | + |
| 23 | +import org.junit.Assert; |
| 24 | +import org.junit.Test; |
| 25 | + |
| 26 | +public class ControlStateTest extends TestCase { |
| 27 | + |
| 28 | + void verifyHostControlState(Status hostStatus, ResourceState hostResourceState, ControlState expectedControlState) { |
| 29 | + Assert.assertEquals(expectedControlState, ControlState.getControlState(hostStatus, hostResourceState)); |
| 30 | + } |
| 31 | + |
| 32 | + @Test |
| 33 | + public void testHostControlState1() { |
| 34 | + // Unknown state |
| 35 | + verifyHostControlState(null, null, ControlState.Unknown); |
| 36 | + verifyHostControlState(null, ResourceState.Enabled, ControlState.Unknown); |
| 37 | + verifyHostControlState(Status.Up, null, ControlState.Unknown); |
| 38 | + verifyHostControlState(Status.Disconnected, null, ControlState.Unknown); |
| 39 | + verifyHostControlState(Status.Down, null, ControlState.Unknown); |
| 40 | + |
| 41 | + verifyHostControlState(Status.Unknown, null, ControlState.Unknown); |
| 42 | + verifyHostControlState(Status.Unknown, ResourceState.Enabled, ControlState.Unknown); |
| 43 | + verifyHostControlState(Status.Unknown, ResourceState.ErrorInPrepareForMaintenance, ControlState.Unknown); |
| 44 | + verifyHostControlState(Status.Unknown, ResourceState.PrepareForMaintenance, ControlState.Unknown); |
| 45 | + verifyHostControlState(Status.Unknown, ResourceState.ErrorInMaintenance, ControlState.Unknown); |
| 46 | + verifyHostControlState(Status.Unknown, ResourceState.Maintenance, ControlState.Unknown); |
| 47 | + verifyHostControlState(Status.Unknown, ResourceState.Creating, ControlState.Unknown); |
| 48 | + verifyHostControlState(Status.Unknown, ResourceState.Disabled, ControlState.Unknown); |
| 49 | + verifyHostControlState(Status.Unknown, ResourceState.Error, ControlState.Unknown); |
| 50 | + verifyHostControlState(Status.Unknown, ResourceState.Degraded, ControlState.Unknown); |
| 51 | + } |
| 52 | + @Test |
| 53 | + public void testHostControlState2() { |
| 54 | + // Host is Up and Enabled |
| 55 | + verifyHostControlState(Status.Creating, ResourceState.Enabled, ControlState.Enabled); |
| 56 | + verifyHostControlState(Status.Connecting, ResourceState.Enabled, ControlState.Enabled); |
| 57 | + verifyHostControlState(Status.Up, ResourceState.Enabled, ControlState.Enabled); |
| 58 | + } |
| 59 | + |
| 60 | + @Test |
| 61 | + public void testHostControlState3() { |
| 62 | + // Host is Up and not Enabled |
| 63 | + verifyHostControlState(Status.Up, ResourceState.Creating, ControlState.Disabled); |
| 64 | + verifyHostControlState(Status.Up, ResourceState.Disabled, ControlState.Disabled); |
| 65 | + verifyHostControlState(Status.Up, ResourceState.Error, ControlState.Disabled); |
| 66 | + verifyHostControlState(Status.Up, ResourceState.Degraded, ControlState.Disabled); |
| 67 | + |
| 68 | + // Host is Creating and not Enabled |
| 69 | + verifyHostControlState(Status.Creating, ResourceState.Creating, ControlState.Disabled); |
| 70 | + verifyHostControlState(Status.Creating, ResourceState.Disabled, ControlState.Disabled); |
| 71 | + verifyHostControlState(Status.Creating, ResourceState.Error, ControlState.Disabled); |
| 72 | + verifyHostControlState(Status.Creating, ResourceState.Degraded, ControlState.Disabled); |
| 73 | + |
| 74 | + // Host is Connecting and not Enabled |
| 75 | + verifyHostControlState(Status.Connecting, ResourceState.Creating, ControlState.Disabled); |
| 76 | + verifyHostControlState(Status.Connecting, ResourceState.Disabled, ControlState.Disabled); |
| 77 | + verifyHostControlState(Status.Connecting, ResourceState.Error, ControlState.Disabled); |
| 78 | + verifyHostControlState(Status.Connecting, ResourceState.Degraded, ControlState.Disabled); |
| 79 | + } |
| 80 | + |
| 81 | + @Test |
| 82 | + public void testHostControlState4() { |
| 83 | + // Host is Up and Maintenance mode |
| 84 | + verifyHostControlState(Status.Up, ResourceState.ErrorInPrepareForMaintenance, ControlState.Maintenance); |
| 85 | + verifyHostControlState(Status.Up, ResourceState.PrepareForMaintenance, ControlState.Maintenance); |
| 86 | + verifyHostControlState(Status.Up, ResourceState.ErrorInMaintenance, ControlState.Maintenance); |
| 87 | + verifyHostControlState(Status.Up, ResourceState.Maintenance, ControlState.Maintenance); |
| 88 | + } |
| 89 | + |
| 90 | + @Test |
| 91 | + public void testHostControlState5() { |
| 92 | + // Host in other states and Enabled |
| 93 | + verifyHostControlState(Status.Down, ResourceState.Enabled, ControlState.Offline); |
| 94 | + verifyHostControlState(Status.Disconnected, ResourceState.Enabled, ControlState.Offline); |
| 95 | + verifyHostControlState(Status.Alert, ResourceState.Enabled, ControlState.Offline); |
| 96 | + verifyHostControlState(Status.Removed, ResourceState.Enabled, ControlState.Offline); |
| 97 | + verifyHostControlState(Status.Error, ResourceState.Enabled, ControlState.Offline); |
| 98 | + verifyHostControlState(Status.Rebalancing, ResourceState.Enabled, ControlState.Offline); |
| 99 | + |
| 100 | + // Host in other states and Disabled |
| 101 | + verifyHostControlState(Status.Down, ResourceState.Disabled, ControlState.Offline); |
| 102 | + verifyHostControlState(Status.Disconnected, ResourceState.Disabled, ControlState.Offline); |
| 103 | + verifyHostControlState(Status.Alert, ResourceState.Disabled, ControlState.Offline); |
| 104 | + verifyHostControlState(Status.Removed, ResourceState.Disabled, ControlState.Offline); |
| 105 | + verifyHostControlState(Status.Error, ResourceState.Disabled, ControlState.Offline); |
| 106 | + verifyHostControlState(Status.Rebalancing, ResourceState.Disabled, ControlState.Offline); |
| 107 | + } |
| 108 | + |
| 109 | +} |
0 commit comments