diff --git a/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/CitrixResourceBase.java b/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/CitrixResourceBase.java index c9b05a4cf68..4477a701e54 100644 --- a/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/CitrixResourceBase.java +++ b/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/CitrixResourceBase.java @@ -461,12 +461,6 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe if (cmd instanceof NetworkElementCommand) { return _vrResource.executeRequest((NetworkElementCommand)cmd); - } else if (clazz == CheckSshCommand.class) { - return execute((CheckSshCommand)cmd); - } else if (clazz == SecurityGroupRulesCmd.class) { - return execute((SecurityGroupRulesCmd)cmd); - } else if (clazz == OvsFetchInterfaceCommand.class) { - return execute((OvsFetchInterfaceCommand)cmd); } else if (clazz == OvsCreateGreTunnelCommand.class) { return execute((OvsCreateGreTunnelCommand)cmd); } else if (clazz == OvsDeleteFlowCommand.class) { @@ -847,17 +841,17 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe } if (type == TrafficType.Guest) { - return new XsLocalNetwork(Network.getByUuid(conn, _host.getGuestNetwork()), null, PIF.getByUuid(conn, _host.getGuestPif()), null); + return new XsLocalNetwork(this, Network.getByUuid(conn, _host.getGuestNetwork()), null, PIF.getByUuid(conn, _host.getGuestPif()), null); } else if (type == TrafficType.Control) { setupLinkLocalNetwork(conn); - return new XsLocalNetwork(Network.getByUuid(conn, _host.getLinkLocalNetwork())); + return new XsLocalNetwork(this, Network.getByUuid(conn, _host.getLinkLocalNetwork())); } else if (type == TrafficType.Management) { - return new XsLocalNetwork(Network.getByUuid(conn, _host.getPrivateNetwork()), null, PIF.getByUuid(conn, _host.getPrivatePif()), null); + return new XsLocalNetwork(this, Network.getByUuid(conn, _host.getPrivateNetwork()), null, PIF.getByUuid(conn, _host.getPrivatePif()), null); } else if (type == TrafficType.Public) { - return new XsLocalNetwork(Network.getByUuid(conn, _host.getPublicNetwork()), null, PIF.getByUuid(conn, _host.getPublicPif()), null); + return new XsLocalNetwork(this, Network.getByUuid(conn, _host.getPublicNetwork()), null, PIF.getByUuid(conn, _host.getPublicPif()), null); } else if (type == TrafficType.Storage) { /* TrafficType.Storage is for secondary storage, while storageNetwork1 is for primary storage, we need better name here */ - return new XsLocalNetwork(Network.getByUuid(conn, _host.getStorageNetwork1()), null, PIF.getByUuid(conn, _host.getStoragePif1()), null); + return new XsLocalNetwork(this, Network.getByUuid(conn, _host.getStorageNetwork1()), null, PIF.getByUuid(conn, _host.getStoragePif1()), null); } throw new CloudRuntimeException("Unsupported network type: " + type); @@ -3571,7 +3565,7 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe return vdis; } - protected String connect(final Connection conn, final String vmName, final String ipAddress, final int port) { + public String connect(final Connection conn, final String vmName, final String ipAddress, final int port) { for (int i = 0; i <= _retry; i++) { try { final Set vms = VM.getByNameLabel(conn, vmName); @@ -3729,7 +3723,7 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe } final Network nk = mgmtPifRec.network; final Network.Record nkRec = nk.getRecord(conn); - return new XsLocalNetwork(nk, nkRec, mgmtPif, mgmtPifRec); + return new XsLocalNetwork(this, nk, nkRec, mgmtPif, mgmtPifRec); } protected VIF getCorrectVif(final Connection conn, final VM router, final Network network) throws XmlRpcException, XenAPIException { @@ -3864,10 +3858,10 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe * * @see CitrixResourceBase#enableVlanNetwork */ - protected XsLocalNetwork getNetworkByName(final Connection conn, final String name) throws XenAPIException, XmlRpcException { + public XsLocalNetwork getNetworkByName(final Connection conn, final String name) throws XenAPIException, XmlRpcException { final Set networks = Network.getByNameLabel(conn, name); if (networks.size() == 1) { - return new XsLocalNetwork(networks.iterator().next(), null, null, null); + return new XsLocalNetwork(this, networks.iterator().next(), null, null, null); } if (networks.size() == 0) { @@ -3882,7 +3876,7 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe long earliestTimestamp = Long.MAX_VALUE; int earliestRandom = Integer.MAX_VALUE; for (final Network network : networks) { - final XsLocalNetwork nic = new XsLocalNetwork(network); + final XsLocalNetwork nic = new XsLocalNetwork(this, network); if (nic.getPif(conn) != null) { return nic; @@ -3906,7 +3900,7 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe } } - return earliestNetwork != null ? new XsLocalNetwork(earliestNetwork, earliestNetworkRecord, null, null) : null; + return earliestNetwork != null ? new XsLocalNetwork(this, earliestNetwork, earliestNetworkRecord, null, null) : null; } protected String generateTimeStamp() { @@ -5314,7 +5308,7 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe String label = cmd.getLabel(); //FIXME: this is a tricky to pass the network checking in XCP. I temporary get default label from Host. - if (is_xcp()) { + if (isXcp()) { label = getLabel(); } s_logger.debug("Will look for network with name-label:" + label + " on host " + _host.getIp()); @@ -6894,67 +6888,6 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe return new Answer(cmd, true, result); } - /** - * XsNic represents a network and the host's specific PIF. - */ - protected class XsLocalNetwork { - private final Network _n; - private Network.Record _nr; - private PIF _p; - private PIF.Record _pr; - - public XsLocalNetwork(final Network n) { - this(n, null, null, null); - } - - public XsLocalNetwork(final Network n, final Network.Record nr, final PIF p, final PIF.Record pr) { - _n = n; - _nr = nr; - _p = p; - _pr = pr; - } - - public Network getNetwork() { - return _n; - } - - public Network.Record getNetworkRecord(final Connection conn) throws XenAPIException, XmlRpcException { - if (_nr == null) { - _nr = _n.getRecord(conn); - } - - return _nr; - } - - public PIF getPif(final Connection conn) throws XenAPIException, XmlRpcException { - if (_p == null) { - final Network.Record nr = getNetworkRecord(conn); - for (final PIF pif : nr.PIFs) { - final PIF.Record pr = pif.getRecord(conn); - if (_host.getUuid().equals(pr.host.getUuid(conn))) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Found a network called " + nr.nameLabel + " on host=" + _host.getIp() + "; Network=" + nr.uuid + "; pif=" + pr.uuid); - } - _p = pif; - _pr = pr; - break; - } - } - } - return _p; - } - - public PIF.Record getPifRecord(final Connection conn) throws XenAPIException, XmlRpcException { - if (_pr == null) { - final PIF p = getPif(conn); - if (_pr == null) { - _pr = p.getRecord(conn); - } - } - return _pr; - } - } - protected String getGuestOsType(final String stdType, String platformEmulator, final boolean bootFromCD) { if (platformEmulator == null) { s_logger.debug("no guest OS type, start it as HVM guest"); @@ -7259,7 +7192,7 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe public void setRunLevel(final int level) { } - private boolean is_xcp() { + public boolean isXcp() { final Connection conn = getConnection(); final String result = callHostPlugin(conn, "ovstunnel", "is_xcp"); if (result.equals("XCP")) { @@ -7268,7 +7201,7 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe return false; } - private String getLabel() { + public String getLabel() { final Connection conn = getConnection(); final String result = callHostPlugin(conn, "ovstunnel", "getLabel"); return result; diff --git a/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/XsLocalNetwork.java b/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/XsLocalNetwork.java new file mode 100644 index 00000000000..c7f4f8369ea --- /dev/null +++ b/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/XsLocalNetwork.java @@ -0,0 +1,91 @@ +// 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; + +import org.apache.log4j.Logger; +import org.apache.xmlrpc.XmlRpcException; + +import com.xensource.xenapi.Connection; +import com.xensource.xenapi.Network; +import com.xensource.xenapi.PIF; +import com.xensource.xenapi.Types.XenAPIException; + +/** + * XsNic represents a network and the host's specific PIF. + */ +public class XsLocalNetwork { + + private static final Logger s_logger = Logger.getLogger(XsLocalNetwork.class); + + private final CitrixResourceBase _citrixResourceBase; + private final Network _n; + private Network.Record _nr; + private PIF _p; + private PIF.Record _pr; + + public XsLocalNetwork(final CitrixResourceBase citrixResourceBase, final Network n) { + this(citrixResourceBase, n, null, null, null); + } + + public XsLocalNetwork(final CitrixResourceBase citrixResourceBase, final Network n, final Network.Record nr, final PIF p, final PIF.Record pr) { + _citrixResourceBase = citrixResourceBase; + _n = n; + _nr = nr; + _p = p; + _pr = pr; + } + + public Network getNetwork() { + return _n; + } + + public Network.Record getNetworkRecord(final Connection conn) throws XenAPIException, XmlRpcException { + if (_nr == null) { + _nr = _n.getRecord(conn); + } + + return _nr; + } + + public PIF getPif(final Connection conn) throws XenAPIException, XmlRpcException { + if (_p == null) { + final Network.Record nr = getNetworkRecord(conn); + for (final PIF pif : nr.PIFs) { + final PIF.Record pr = pif.getRecord(conn); + if (_citrixResourceBase.getHost().getUuid().equals(pr.host.getUuid(conn))) { + if (s_logger.isDebugEnabled()) { + s_logger.debug("Found a network called " + nr.nameLabel + " on host=" + _citrixResourceBase.getHost().getIp() + "; Network=" + nr.uuid + "; pif=" + pr.uuid); + } + _p = pif; + _pr = pr; + break; + } + } + } + return _p; + } + + public PIF.Record getPifRecord(final Connection conn) throws XenAPIException, XmlRpcException { + if (_pr == null) { + final PIF p = getPif(conn); + if (_pr == null) { + _pr = p.getRecord(conn); + } + } + return _pr; + } +} \ No newline at end of file diff --git a/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/CitrixCheckSshCommandWrapper.java b/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/CitrixCheckSshCommandWrapper.java new file mode 100644 index 00000000000..4437641d405 --- /dev/null +++ b/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/CitrixCheckSshCommandWrapper.java @@ -0,0 +1,63 @@ +// +// 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 org.apache.log4j.Logger; + +import com.cloud.agent.api.Answer; +import com.cloud.agent.api.check.CheckSshAnswer; +import com.cloud.agent.api.check.CheckSshCommand; +import com.cloud.hypervisor.xenserver.resource.CitrixResourceBase; +import com.cloud.resource.CommandWrapper; +import com.xensource.xenapi.Connection; + +public final class CitrixCheckSshCommandWrapper extends CommandWrapper { + + private static final Logger s_logger = Logger.getLogger(CitrixCheckSshCommandWrapper.class); + + @Override + public Answer execute(final CheckSshCommand command, final CitrixResourceBase citrixResourceBase) { + final Connection conn = citrixResourceBase.getConnection(); + final String vmName = command.getName(); + final String privateIp = command.getIp(); + final int cmdPort = command.getPort(); + + if (s_logger.isDebugEnabled()) { + s_logger.debug("Ping command port, " + privateIp + ":" + cmdPort); + } + + try { + final String result = citrixResourceBase.connect(conn, command.getName(), privateIp, cmdPort); + if (result != null) { + return new CheckSshAnswer(command, "Can not ping System vm " + vmName + "due to:" + result); + } + //Do not destroy the disk here! It will stio the patching process. Please, don't! + //destroyPatchVbd(conn, vmName); + } catch (final Exception e) { + return new CheckSshAnswer(command, e); + } + + if (s_logger.isDebugEnabled()) { + s_logger.debug("Ping command port succeeded for vm " + vmName); + } + + return new CheckSshAnswer(command); + } +} \ No newline at end of file diff --git a/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/CitrixOvsFetchInterfaceCommandWrapper.java b/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/CitrixOvsFetchInterfaceCommandWrapper.java new file mode 100644 index 00000000000..1f211a48494 --- /dev/null +++ b/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/CitrixOvsFetchInterfaceCommandWrapper.java @@ -0,0 +1,71 @@ +// +// 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 org.apache.log4j.Logger; +import org.apache.xmlrpc.XmlRpcException; + +import com.cloud.agent.api.Answer; +import com.cloud.agent.api.OvsFetchInterfaceAnswer; +import com.cloud.agent.api.OvsFetchInterfaceCommand; +import com.cloud.hypervisor.xenserver.resource.CitrixResourceBase; +import com.cloud.hypervisor.xenserver.resource.XsLocalNetwork; +import com.cloud.resource.CommandWrapper; +import com.cloud.utils.exception.CloudRuntimeException; +import com.xensource.xenapi.Connection; +import com.xensource.xenapi.PIF; +import com.xensource.xenapi.Types.BadServerResponse; +import com.xensource.xenapi.Types.XenAPIException; + +public final class CitrixOvsFetchInterfaceCommandWrapper extends CommandWrapper { + + private static final Logger s_logger = Logger.getLogger(CitrixOvsFetchInterfaceCommandWrapper.class); + + @Override + public Answer execute(final OvsFetchInterfaceCommand command, final CitrixResourceBase citrixResourceBase) { + String label = command.getLabel(); + //FIXME: this is a tricky to pass the network checking in XCP. I temporary get default label from Host. + if (citrixResourceBase.isXcp()) { + label = citrixResourceBase.getLabel(); + } + s_logger.debug("Will look for network with name-label:" + label + " on host " + citrixResourceBase.getHost().getIp()); + final Connection conn = citrixResourceBase.getConnection(); + try { + final XsLocalNetwork nw = citrixResourceBase.getNetworkByName(conn, label); + if(nw == null) { + throw new CloudRuntimeException("Unable to locate the network with name-label: " + label + " on host: " + citrixResourceBase.getHost().getIp()); + } + s_logger.debug("Network object:" + nw.getNetwork().getUuid(conn)); + final PIF pif = nw.getPif(conn); + final PIF.Record pifRec = pif.getRecord(conn); + s_logger.debug("PIF object:" + pifRec.uuid + "(" + pifRec.device + ")"); + return new OvsFetchInterfaceAnswer(command, true, "Interface " + pifRec.device + " retrieved successfully", pifRec.IP, pifRec.netmask, pifRec.MAC); + } catch (final BadServerResponse e) { + s_logger.error("An error occurred while fetching the interface for " + label + " on host " + citrixResourceBase.getHost().getIp(), e); + return new OvsFetchInterfaceAnswer(command, false, "EXCEPTION:" + e.getMessage()); + } catch (final XenAPIException e) { + s_logger.error("An error occurred while fetching the interface for " + label + " on host " + citrixResourceBase.getHost().getIp(), e); + return new OvsFetchInterfaceAnswer(command, false, "EXCEPTION:" + e.getMessage()); + } catch (final XmlRpcException e) { + s_logger.error("An error occurred while fetching the interface for " + label + " on host " + citrixResourceBase.getHost().getIp(), e); + return new OvsFetchInterfaceAnswer(command, false, "EXCEPTION:" + e.getMessage()); + } + } +} \ No newline at end of file diff --git a/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/CitrixRequestWrapper.java b/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/CitrixRequestWrapper.java index fbb3f27c42d..be7aec66485 100644 --- a/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/CitrixRequestWrapper.java +++ b/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/CitrixRequestWrapper.java @@ -39,16 +39,19 @@ import com.cloud.agent.api.MaintainCommand; import com.cloud.agent.api.MigrateCommand; import com.cloud.agent.api.ModifySshKeysCommand; import com.cloud.agent.api.ModifyStoragePoolCommand; +import com.cloud.agent.api.OvsFetchInterfaceCommand; import com.cloud.agent.api.OvsSetTagAndFlowCommand; import com.cloud.agent.api.PingTestCommand; import com.cloud.agent.api.PrepareForMigrationCommand; import com.cloud.agent.api.ReadyCommand; import com.cloud.agent.api.RebootCommand; import com.cloud.agent.api.RebootRouterCommand; +import com.cloud.agent.api.SecurityGroupRulesCmd; import com.cloud.agent.api.SetupCommand; import com.cloud.agent.api.StartCommand; import com.cloud.agent.api.StopCommand; import com.cloud.agent.api.UpgradeSnapshotCommand; +import com.cloud.agent.api.check.CheckSshCommand; import com.cloud.agent.api.proxy.CheckConsoleProxyLoadCommand; import com.cloud.agent.api.proxy.WatchConsoleProxyLoadCommand; import com.cloud.agent.api.storage.CreateCommand; @@ -109,6 +112,9 @@ public class CitrixRequestWrapper extends RequestWrapper { map.put(ModifySshKeysCommand.class, new CitrixModifySshKeysCommandWrapper()); map.put(StartCommand.class, new CitrixStartCommandWrapper()); map.put(OvsSetTagAndFlowCommand.class, new CitrixOvsSetTagAndFlowCommandWrapper()); + map.put(CheckSshCommand.class, new CitrixCheckSshCommandWrapper()); + map.put(SecurityGroupRulesCmd.class, new CitrixSecurityGroupRulesCommandWrapper()); + map.put(OvsFetchInterfaceCommand.class, new CitrixOvsFetchInterfaceCommandWrapper()); } public static CitrixRequestWrapper getInstance() { diff --git a/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/CitrixSecurityGroupRulesCommandWrapper.java b/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/CitrixSecurityGroupRulesCommandWrapper.java new file mode 100644 index 00000000000..0cf4a8ab29b --- /dev/null +++ b/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/CitrixSecurityGroupRulesCommandWrapper.java @@ -0,0 +1,61 @@ +// +// 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 org.apache.log4j.Logger; + +import com.cloud.agent.api.Answer; +import com.cloud.agent.api.SecurityGroupRuleAnswer; +import com.cloud.agent.api.SecurityGroupRulesCmd; +import com.cloud.hypervisor.xenserver.resource.CitrixResourceBase; +import com.cloud.resource.CommandWrapper; +import com.xensource.xenapi.Connection; + +public final class CitrixSecurityGroupRulesCommandWrapper extends CommandWrapper { + + private static final Logger s_logger = Logger.getLogger(CitrixSecurityGroupRulesCommandWrapper.class); + + @Override + public Answer execute(final SecurityGroupRulesCmd command, final CitrixResourceBase citrixResourceBase) { + final Connection conn = citrixResourceBase.getConnection(); + if (s_logger.isTraceEnabled()) { + s_logger.trace("Sending network rules command to " + citrixResourceBase.getHost().getIp()); + } + + if (!citrixResourceBase.canBridgeFirewall()) { + s_logger.warn("Host " + citrixResourceBase.getHost().getIp() + " cannot do bridge firewalling"); + return new SecurityGroupRuleAnswer(command, false, "Host " + citrixResourceBase.getHost().getIp() + " cannot do bridge firewalling", + SecurityGroupRuleAnswer.FailureReason.CANNOT_BRIDGE_FIREWALL); + } + + final String result = citrixResourceBase.callHostPlugin(conn, "vmops", "network_rules", "vmName", command.getVmName(), "vmIP", command.getGuestIp(), "vmMAC", + command.getGuestMac(), "vmID", Long.toString(command.getVmId()), "signature", command.getSignature(), "seqno", Long.toString(command.getSeqNum()), "deflated", + "true", "rules", command.compressStringifiedRules(), "secIps", command.getSecIpsString()); + + if (result == null || result.isEmpty() || !Boolean.parseBoolean(result)) { + s_logger.warn("Failed to program network rules for vm " + command.getVmName()); + return new SecurityGroupRuleAnswer(command, false, "programming network rules failed"); + } else { + s_logger.info("Programmed network rules for vm " + command.getVmName() + " guestIp=" + command.getGuestIp() + ", ingress numrules=" + + command.getIngressRuleSet().length + ", egress numrules=" + command.getEgressRuleSet().length); + return new SecurityGroupRuleAnswer(command); + } + } +} \ No newline at end of file diff --git a/plugins/hypervisors/xenserver/test/com/cloud/hypervisor/xenserver/resource/wrapper/CitrixRequestWrapperTest.java b/plugins/hypervisors/xenserver/test/com/cloud/hypervisor/xenserver/resource/wrapper/CitrixRequestWrapperTest.java index 0ffa7f4f92e..75dd051ffcf 100644 --- a/plugins/hypervisors/xenserver/test/com/cloud/hypervisor/xenserver/resource/wrapper/CitrixRequestWrapperTest.java +++ b/plugins/hypervisors/xenserver/test/com/cloud/hypervisor/xenserver/resource/wrapper/CitrixRequestWrapperTest.java @@ -49,10 +49,12 @@ import com.cloud.agent.api.ReadyCommand; import com.cloud.agent.api.RebootAnswer; import com.cloud.agent.api.RebootCommand; import com.cloud.agent.api.RebootRouterCommand; +import com.cloud.agent.api.SecurityGroupRulesCmd; import com.cloud.agent.api.SetupCommand; import com.cloud.agent.api.StartCommand; import com.cloud.agent.api.StopCommand; import com.cloud.agent.api.UpgradeSnapshotCommand; +import com.cloud.agent.api.check.CheckSshCommand; import com.cloud.agent.api.proxy.CheckConsoleProxyLoadCommand; import com.cloud.agent.api.proxy.WatchConsoleProxyLoadCommand; import com.cloud.agent.api.storage.CreateAnswer; @@ -66,6 +68,7 @@ import com.cloud.agent.api.to.VirtualMachineTO; import com.cloud.host.HostEnvironment; import com.cloud.hypervisor.xenserver.resource.CitrixResourceBase; import com.cloud.hypervisor.xenserver.resource.XsHost; +import com.cloud.hypervisor.xenserver.resource.XsLocalNetwork; import com.cloud.storage.Storage.ImageFormat; import com.cloud.storage.Storage.StoragePoolType; import com.cloud.storage.VMTemplateStorageResourceAssoc; @@ -586,6 +589,7 @@ public class CitrixRequestWrapperTest { assertNotNull(wrapper); final Answer answer = wrapper.execute(pingTestCommand, citrixResourceBase); + verify(citrixResourceBase, times(1)).getConnection(); assertFalse(answer.getResult()); @@ -627,6 +631,7 @@ public class CitrixRequestWrapperTest { assertNotNull(wrapper); final Answer answer = wrapper.execute(startCommand, citrixResourceBase); + verify(citrixResourceBase, times(1)).getConnection(); assertFalse(answer.getResult()); @@ -661,6 +666,74 @@ public class CitrixRequestWrapperTest { assertFalse(answer.getResult()); } + + @Test + public void testCheckSshCommand() { + final CheckSshCommand sshCommand = new CheckSshCommand("Test", "127.0.0.1", 22); + + final CitrixRequestWrapper wrapper = CitrixRequestWrapper.getInstance(); + assertNotNull(wrapper); + + final Answer answer = wrapper.execute(sshCommand, citrixResourceBase); + + verify(citrixResourceBase, times(1)).getConnection(); + + assertTrue(answer.getResult()); + } + + @Test + public void testSecurityGroupRulesCommand() { + final Connection conn = Mockito.mock(Connection.class); + final XsHost xsHost = Mockito.mock(XsHost.class); + + final SecurityGroupRulesCmd sshCommand = new SecurityGroupRulesCmd(); + + final CitrixRequestWrapper wrapper = CitrixRequestWrapper.getInstance(); + assertNotNull(wrapper); + + when(citrixResourceBase.getConnection()).thenReturn(conn); + when(citrixResourceBase.getHost()).thenReturn(xsHost); + + final Answer answer = wrapper.execute(sshCommand, citrixResourceBase); + + verify(citrixResourceBase, times(1)).getConnection(); + + assertFalse(answer.getResult()); + } + + @Test + public void testOvsFetchInterfaceCommand() { + final String label = "[abc]"; + + final Connection conn = Mockito.mock(Connection.class); + final XsLocalNetwork network = Mockito.mock(XsLocalNetwork.class); + + final XsHost xsHost = Mockito.mock(XsHost.class); + + final SecurityGroupRulesCmd sshCommand = new SecurityGroupRulesCmd(); + + final CitrixRequestWrapper wrapper = CitrixRequestWrapper.getInstance(); + assertNotNull(wrapper); + + when(citrixResourceBase.isXcp()).thenReturn(true); + when(citrixResourceBase.getLabel()).thenReturn("[abc]"); + when(citrixResourceBase.getConnection()).thenReturn(conn); + when(citrixResourceBase.getHost()).thenReturn(xsHost); + + try { + when(citrixResourceBase.getNetworkByName(conn, label)).thenReturn(network); + } catch (final XenAPIException e) { + fail(e.getMessage()); + } catch (final XmlRpcException e) { + fail(e.getMessage()); + } + + final Answer answer = wrapper.execute(sshCommand, citrixResourceBase); + + verify(citrixResourceBase, times(1)).getConnection(); + + assertFalse(answer.getResult()); + } } class NotAValidCommand extends Command {