mirror of
				https://github.com/apache/cloudstack.git
				synced 2025-11-04 00:02:37 +01:00 
			
		
		
		
	Refactoring PingTestCommand to cope with new design
- Basic tests added
This commit is contained in:
		
							parent
							
								
									3a70912b7c
								
							
						
					
					
						commit
						18470a48d0
					
				@ -453,8 +453,6 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe
 | 
			
		||||
 | 
			
		||||
        if (cmd instanceof NetworkElementCommand) {
 | 
			
		||||
            return _vrResource.executeRequest((NetworkElementCommand)cmd);
 | 
			
		||||
        } else if (clazz == PingTestCommand.class) {
 | 
			
		||||
            return execute((PingTestCommand)cmd);
 | 
			
		||||
        } else if (clazz == CheckOnHostCommand.class) {
 | 
			
		||||
            return execute((CheckOnHostCommand)cmd);
 | 
			
		||||
        } else if (clazz == ModifySshKeysCommand.class) {
 | 
			
		||||
@ -1945,7 +1943,7 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe
 | 
			
		||||
        return new Answer(cmd);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private boolean doPingTest(final Connection conn, final String computingHostIp) {
 | 
			
		||||
    public boolean doPingTest(final Connection conn, final String computingHostIp) {
 | 
			
		||||
        final com.trilead.ssh2.Connection sshConnection = new com.trilead.ssh2.Connection(_host.getIp(), 22);
 | 
			
		||||
        try {
 | 
			
		||||
            sshConnection.connect(null, 60000, 60000);
 | 
			
		||||
@ -1970,7 +1968,7 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe
 | 
			
		||||
        return new CheckOnHostAnswer(cmd, null, "Not Implmeneted");
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private boolean doPingTest(final Connection conn, final String domRIp, final String vmIp) {
 | 
			
		||||
    public boolean doPingTest(final Connection conn, final String domRIp, final String vmIp) {
 | 
			
		||||
        final String args = "-i " + domRIp + " -p " + vmIp;
 | 
			
		||||
        final String result = callHostPlugin(conn, "vmops", "pingtest", "args", args);
 | 
			
		||||
        if (result == null || result.isEmpty()) {
 | 
			
		||||
 | 
			
		||||
@ -0,0 +1,47 @@
 | 
			
		||||
//
 | 
			
		||||
// 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.
 | 
			
		||||
//
 | 
			
		||||
 | 
			
		||||
package com.cloud.hypervisor.xenserver.resource.wrapper;
 | 
			
		||||
 | 
			
		||||
import com.cloud.agent.api.Answer;
 | 
			
		||||
import com.cloud.agent.api.PingTestCommand;
 | 
			
		||||
import com.cloud.hypervisor.xenserver.resource.CitrixResourceBase;
 | 
			
		||||
import com.cloud.resource.CommandWrapper;
 | 
			
		||||
import com.xensource.xenapi.Connection;
 | 
			
		||||
 | 
			
		||||
public final class CitrixPingTestCommandWrapper extends CommandWrapper<PingTestCommand, Answer, CitrixResourceBase> {
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public Answer execute(final PingTestCommand command, final CitrixResourceBase citrixResourceBase) {
 | 
			
		||||
        final Connection conn = citrixResourceBase.getConnection();
 | 
			
		||||
        boolean result = false;
 | 
			
		||||
        final String computingHostIp = command.getComputingHostIp();
 | 
			
		||||
 | 
			
		||||
        if (computingHostIp != null) {
 | 
			
		||||
            result = citrixResourceBase.doPingTest(conn, computingHostIp);
 | 
			
		||||
        } else {
 | 
			
		||||
            result = citrixResourceBase.doPingTest(conn, command.getRouterIp(), command.getPrivateIp());
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (!result) {
 | 
			
		||||
            return new Answer(command, false, "PingTestCommand failed");
 | 
			
		||||
        }
 | 
			
		||||
        return new Answer(command);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@ -37,6 +37,7 @@ import com.cloud.agent.api.GetVncPortCommand;
 | 
			
		||||
import com.cloud.agent.api.MaintainCommand;
 | 
			
		||||
import com.cloud.agent.api.MigrateCommand;
 | 
			
		||||
import com.cloud.agent.api.ModifyStoragePoolCommand;
 | 
			
		||||
import com.cloud.agent.api.PingTestCommand;
 | 
			
		||||
import com.cloud.agent.api.PrepareForMigrationCommand;
 | 
			
		||||
import com.cloud.agent.api.ReadyCommand;
 | 
			
		||||
import com.cloud.agent.api.RebootCommand;
 | 
			
		||||
@ -99,6 +100,7 @@ public class CitrixRequestWrapper extends RequestWrapper {
 | 
			
		||||
        map.put(GetVncPortCommand.class, new CitrixGetVncPortCommandWrapper());
 | 
			
		||||
        map.put(SetupCommand.class, new CitrixSetupCommandWrapper());
 | 
			
		||||
        map.put(MaintainCommand.class, new CitrixMaintainCommandWrapper());
 | 
			
		||||
        map.put(PingTestCommand.class, new CitrixPingTestCommandWrapper());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static CitrixRequestWrapper getInstance() {
 | 
			
		||||
 | 
			
		||||
@ -38,6 +38,7 @@ import com.cloud.agent.api.GetVncPortCommand;
 | 
			
		||||
import com.cloud.agent.api.MaintainCommand;
 | 
			
		||||
import com.cloud.agent.api.MigrateCommand;
 | 
			
		||||
import com.cloud.agent.api.ModifyStoragePoolCommand;
 | 
			
		||||
import com.cloud.agent.api.PingTestCommand;
 | 
			
		||||
import com.cloud.agent.api.PrepareForMigrationCommand;
 | 
			
		||||
import com.cloud.agent.api.ReadyCommand;
 | 
			
		||||
import com.cloud.agent.api.RebootAnswer;
 | 
			
		||||
@ -554,6 +555,19 @@ public class CitrixRequestWrapperTest {
 | 
			
		||||
 | 
			
		||||
        assertFalse(answer.getResult());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Test
 | 
			
		||||
    public void testPingTestCommandHostIp() {
 | 
			
		||||
        final PingTestCommand storageDownloadCommand = new PingTestCommand("127.0.0.1");
 | 
			
		||||
 | 
			
		||||
        final CitrixRequestWrapper wrapper = CitrixRequestWrapper.getInstance();
 | 
			
		||||
        assertNotNull(wrapper);
 | 
			
		||||
 | 
			
		||||
        final Answer answer = wrapper.execute(storageDownloadCommand, citrixResourceBase);
 | 
			
		||||
        verify(citrixResourceBase, times(1)).getConnection();
 | 
			
		||||
 | 
			
		||||
        assertFalse(answer.getResult());
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
class NotAValidCommand extends Command {
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user