Merge release branch 4.8 to master

* 4.8:
  CLOUDSTACK-9353: [XenServer] Fixed VM migration with storage
  Added ASF license to unit test file
  Added unit test to verify ordering
  Fixed ordering of network ACL rules being sent to the VR. The comparator was inverted
This commit is contained in:
Will Stevens 2016-06-28 11:21:04 -04:00
commit f7f23ec720
3 changed files with 72 additions and 12 deletions

View File

@ -45,12 +45,8 @@ public class SetNetworkACLCommand extends NetworkElementCommand {
public String[][] generateFwRules() { public String[][] generateFwRules() {
final List<NetworkACLTO> aclList = Arrays.asList(rules); final List<NetworkACLTO> aclList = Arrays.asList(rules);
Collections.sort(aclList, new Comparator<NetworkACLTO>() {
@Override orderNetworkAclRulesByRuleNumber(aclList);
public int compare(final NetworkACLTO acl1, final NetworkACLTO acl2) {
return acl1.getNumber() < acl2.getNumber() ? 1 : -1;
}
});
final String[][] result = new String[2][aclList.size()]; final String[][] result = new String[2][aclList.size()];
int i = 0; int i = 0;
@ -97,6 +93,15 @@ public class SetNetworkACLCommand extends NetworkElementCommand {
return result; return result;
} }
protected void orderNetworkAclRulesByRuleNumber(List<NetworkACLTO> aclList) {
Collections.sort(aclList, new Comparator<NetworkACLTO>() {
@Override
public int compare(final NetworkACLTO acl1, final NetworkACLTO acl2) {
return acl1.getNumber() > acl2.getNumber() ? 1 : -1;
}
});
}
public NicTO getNic() { public NicTO getNic() {
return nic; return nic;
} }

View File

@ -0,0 +1,53 @@
//
// 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.agent.api.routing;
import static org.junit.Assert.assertEquals;
import java.util.List;
import org.junit.Test;
import com.cloud.agent.api.to.NetworkACLTO;
import com.google.common.collect.Lists;
public class SetNetworkACLCommandTest {
@Test
public void testNetworkAclRuleOrdering(){
//given
List<NetworkACLTO> aclList = Lists.newArrayList();
aclList.add(new NetworkACLTO(3, null, null, null, null, false, false, null, null, null, null, false, 3));
aclList.add(new NetworkACLTO(1, null, null, null, null, false, false, null, null, null, null, false, 1));
aclList.add(new NetworkACLTO(2, null, null, null, null, false, false, null, null, null, null, false, 2));
SetNetworkACLCommand cmd = new SetNetworkACLCommand(aclList, null);
//when
cmd.orderNetworkAclRulesByRuleNumber(aclList);
//then
for(int i=0; i< aclList.size();i++){
assertEquals(aclList.get(i).getNumber(), i+1);
}
}
}

View File

@ -24,6 +24,7 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import com.cloud.utils.Pair;
import org.apache.cloudstack.storage.to.VolumeObjectTO; import org.apache.cloudstack.storage.to.VolumeObjectTO;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
@ -60,7 +61,7 @@ public final class XenServer610MigrateWithStorageCommandWrapper extends CommandW
public Answer execute(final MigrateWithStorageCommand command, final XenServer610Resource xenServer610Resource) { public Answer execute(final MigrateWithStorageCommand command, final XenServer610Resource xenServer610Resource) {
final Connection connection = xenServer610Resource.getConnection(); final Connection connection = xenServer610Resource.getConnection();
final VirtualMachineTO vmSpec = command.getVirtualMachine(); final VirtualMachineTO vmSpec = command.getVirtualMachine();
final Map<VolumeTO, StorageFilerTO> volumeToFiler = command.getVolumeToFiler(); final List<Pair<VolumeTO, StorageFilerTO>> volumeToFiler = command.getVolumeToFilerAsList();
final String vmName = vmSpec.getName(); final String vmName = vmSpec.getName();
Task task = null; Task task = null;
@ -80,13 +81,14 @@ public final class XenServer610MigrateWithStorageCommandWrapper extends CommandW
final XsLocalNetwork nativeNetworkForTraffic = xenServer610Resource.getNativeNetworkForTraffic(connection, TrafficType.Storage, null); final XsLocalNetwork nativeNetworkForTraffic = xenServer610Resource.getNativeNetworkForTraffic(connection, TrafficType.Storage, null);
final Network networkForSm = nativeNetworkForTraffic.getNetwork(); final Network networkForSm = nativeNetworkForTraffic.getNetwork();
// Create the vif map. The vm stays in the same cluster so we have to pass an empty vif map. // Create the vif map. The vm stays in the same cluster so we have to pass an empty vif map.
final Map<VIF, Network> vifMap = new HashMap<VIF, Network>(); final Map<VIF, Network> vifMap = new HashMap<VIF, Network>();
final Map<VDI, SR> vdiMap = new HashMap<VDI, SR>(); final Map<VDI, SR> vdiMap = new HashMap<VDI, SR>();
for (final Map.Entry<VolumeTO, StorageFilerTO> entry : volumeToFiler.entrySet()) {
final VolumeTO volume = entry.getKey(); for (final Pair<VolumeTO, StorageFilerTO> entry : volumeToFiler) {
final StorageFilerTO sotrageFiler = entry.getValue(); final StorageFilerTO storageFiler = entry.second();
vdiMap.put(xenServer610Resource.getVDIbyUuid(connection, volume.getPath()), xenServer610Resource.getStorageRepository(connection, sotrageFiler.getUuid())); final VolumeTO volume = entry.first();
vdiMap.put(xenServer610Resource.getVDIbyUuid(connection, volume.getPath()), xenServer610Resource.getStorageRepository(connection, storageFiler.getUuid()));
} }
// Get the vm to migrate. // Get the vm to migrate.