mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
Merge LTS branch '4.19' into main
This commit is contained in:
commit
b29391c329
@ -16,11 +16,14 @@
|
|||||||
// under the License.
|
// under the License.
|
||||||
package com.cloud.kubernetes.cluster;
|
package com.cloud.kubernetes.cluster;
|
||||||
|
|
||||||
import com.cloud.utils.component.Adapter;
|
|
||||||
import org.apache.cloudstack.acl.ControlledEntity;
|
import org.apache.cloudstack.acl.ControlledEntity;
|
||||||
|
|
||||||
|
import com.cloud.uservm.UserVm;
|
||||||
|
import com.cloud.utils.component.Adapter;
|
||||||
|
|
||||||
public interface KubernetesClusterHelper extends Adapter {
|
public interface KubernetesClusterHelper extends Adapter {
|
||||||
|
|
||||||
ControlledEntity findByUuid(String uuid);
|
ControlledEntity findByUuid(String uuid);
|
||||||
ControlledEntity findByVmId(long vmId);
|
ControlledEntity findByVmId(long vmId);
|
||||||
|
void checkVmCanBeDestroyed(UserVm userVm);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -48,4 +48,6 @@ public interface UserVm extends VirtualMachine, ControlledEntity {
|
|||||||
void setAccountId(long accountId);
|
void setAccountId(long accountId);
|
||||||
|
|
||||||
public boolean isDisplayVm();
|
public boolean isDisplayVm();
|
||||||
|
|
||||||
|
String getUserVmType();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -16,9 +16,10 @@
|
|||||||
// under the License.
|
// under the License.
|
||||||
package org.apache.cloudstack.api.command.user.vm;
|
package org.apache.cloudstack.api.command.user.vm;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.EnumSet;
|
import java.util.EnumSet;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import org.apache.cloudstack.acl.RoleType;
|
import org.apache.cloudstack.acl.RoleType;
|
||||||
import org.apache.cloudstack.affinity.AffinityGroupResponse;
|
import org.apache.cloudstack.affinity.AffinityGroupResponse;
|
||||||
@ -45,6 +46,7 @@ import org.apache.cloudstack.api.response.UserVmResponse;
|
|||||||
import org.apache.cloudstack.api.response.VpcResponse;
|
import org.apache.cloudstack.api.response.VpcResponse;
|
||||||
import org.apache.cloudstack.api.response.ZoneResponse;
|
import org.apache.cloudstack.api.response.ZoneResponse;
|
||||||
import org.apache.commons.lang3.BooleanUtils;
|
import org.apache.commons.lang3.BooleanUtils;
|
||||||
|
import org.apache.commons.collections.CollectionUtils;
|
||||||
|
|
||||||
import com.cloud.exception.InvalidParameterValueException;
|
import com.cloud.exception.InvalidParameterValueException;
|
||||||
import com.cloud.server.ResourceIcon;
|
import com.cloud.server.ResourceIcon;
|
||||||
@ -56,7 +58,6 @@ import com.cloud.vm.VirtualMachine;
|
|||||||
requestHasSensitiveInfo = false, responseHasSensitiveInfo = true)
|
requestHasSensitiveInfo = false, responseHasSensitiveInfo = true)
|
||||||
public class ListVMsCmd extends BaseListRetrieveOnlyResourceCountCmd implements UserCmd {
|
public class ListVMsCmd extends BaseListRetrieveOnlyResourceCountCmd implements UserCmd {
|
||||||
|
|
||||||
private static final String s_name = "listvirtualmachinesresponse";
|
|
||||||
|
|
||||||
/////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////
|
||||||
//////////////// API parameters /////////////////////
|
//////////////// API parameters /////////////////////
|
||||||
@ -96,7 +97,8 @@ public class ListVMsCmd extends BaseListRetrieveOnlyResourceCountCmd implements
|
|||||||
collectionType = CommandType.STRING,
|
collectionType = CommandType.STRING,
|
||||||
description = "comma separated list of vm details requested, "
|
description = "comma separated list of vm details requested, "
|
||||||
+ "value can be a list of [all, group, nics, stats, secgrp, tmpl, servoff, diskoff, backoff, iso, volume, min, affgrp]."
|
+ "value can be a list of [all, group, nics, stats, secgrp, tmpl, servoff, diskoff, backoff, iso, volume, min, affgrp]."
|
||||||
+ " If no parameter is passed in, the details will be defaulted to all")
|
+ " If no parameter is passed in, the details will be defaulted to all. When return.vm.stats.on.vm.list is true, the default" +
|
||||||
|
"details change to [group, nics, secgrp, tmpl, servoff, diskoff, backoff, iso, volume, min, affgrp], thus the stats will not be returned. ")
|
||||||
private List<String> viewDetails;
|
private List<String> viewDetails;
|
||||||
|
|
||||||
@Parameter(name = ApiConstants.TEMPLATE_ID, type = CommandType.UUID, entityType = TemplateResponse.class, description = "list vms by template")
|
@Parameter(name = ApiConstants.TEMPLATE_ID, type = CommandType.UUID, entityType = TemplateResponse.class, description = "list vms by template")
|
||||||
@ -237,22 +239,32 @@ public class ListVMsCmd extends BaseListRetrieveOnlyResourceCountCmd implements
|
|||||||
return autoScaleVmGroupId;
|
return autoScaleVmGroupId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected boolean isViewDetailsEmpty() {
|
||||||
|
return CollectionUtils.isEmpty(viewDetails);
|
||||||
|
}
|
||||||
|
|
||||||
public EnumSet<VMDetails> getDetails() throws InvalidParameterValueException {
|
public EnumSet<VMDetails> getDetails() throws InvalidParameterValueException {
|
||||||
EnumSet<VMDetails> dv;
|
if (isViewDetailsEmpty()) {
|
||||||
if (viewDetails == null || viewDetails.size() <= 0) {
|
if (_queryService.ReturnVmStatsOnVmList.value()) {
|
||||||
dv = EnumSet.of(VMDetails.all);
|
return EnumSet.of(VMDetails.all);
|
||||||
} else {
|
|
||||||
try {
|
|
||||||
ArrayList<VMDetails> dc = new ArrayList<VMDetails>();
|
|
||||||
for (String detail : viewDetails) {
|
|
||||||
dc.add(VMDetails.valueOf(detail));
|
|
||||||
}
|
|
||||||
dv = EnumSet.copyOf(dc);
|
|
||||||
} catch (IllegalArgumentException e) {
|
|
||||||
throw new InvalidParameterValueException("The details parameter contains a non permitted value. The allowed values are " + EnumSet.allOf(VMDetails.class));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Set<VMDetails> allDetails = new HashSet<>(Set.of(VMDetails.values()));
|
||||||
|
allDetails.remove(VMDetails.stats);
|
||||||
|
allDetails.remove(VMDetails.all);
|
||||||
|
return EnumSet.copyOf(allDetails);
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
Set<VMDetails> dc = new HashSet<>();
|
||||||
|
for (String detail : viewDetails) {
|
||||||
|
dc.add(VMDetails.valueOf(detail));
|
||||||
|
}
|
||||||
|
|
||||||
|
return EnumSet.copyOf(dc);
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
throw new InvalidParameterValueException("The details parameter contains a non permitted value. The allowed values are " + EnumSet.allOf(VMDetails.class));
|
||||||
}
|
}
|
||||||
return dv;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -275,10 +287,6 @@ public class ListVMsCmd extends BaseListRetrieveOnlyResourceCountCmd implements
|
|||||||
/////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////
|
||||||
/////////////// API Implementation///////////////////
|
/////////////// API Implementation///////////////////
|
||||||
/////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////
|
||||||
@Override
|
|
||||||
public String getCommandName() {
|
|
||||||
return s_name;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ApiCommandResourceType getApiResourceType() {
|
public ApiCommandResourceType getApiResourceType() {
|
||||||
|
|||||||
@ -37,6 +37,7 @@ import com.cloud.serializer.Param;
|
|||||||
import com.cloud.uservm.UserVm;
|
import com.cloud.uservm.UserVm;
|
||||||
import com.cloud.vm.VirtualMachine;
|
import com.cloud.vm.VirtualMachine;
|
||||||
import com.google.gson.annotations.SerializedName;
|
import com.google.gson.annotations.SerializedName;
|
||||||
|
import org.apache.commons.collections.CollectionUtils;
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
@EntityReference(value = {VirtualMachine.class, UserVm.class, VirtualRouter.class})
|
@EntityReference(value = {VirtualMachine.class, UserVm.class, VirtualRouter.class})
|
||||||
@ -273,6 +274,10 @@ public class UserVmResponse extends BaseResponseWithTagInformation implements Co
|
|||||||
@Param(description = "the hypervisor on which the template runs")
|
@Param(description = "the hypervisor on which the template runs")
|
||||||
private String hypervisor;
|
private String hypervisor;
|
||||||
|
|
||||||
|
@SerializedName(ApiConstants.IP_ADDRESS)
|
||||||
|
@Param(description = "the VM's primary IP address")
|
||||||
|
private String ipAddress;
|
||||||
|
|
||||||
@SerializedName(ApiConstants.PUBLIC_IP_ID)
|
@SerializedName(ApiConstants.PUBLIC_IP_ID)
|
||||||
@Param(description = "public IP address id associated with vm via Static nat rule")
|
@Param(description = "public IP address id associated with vm via Static nat rule")
|
||||||
private String publicIpId;
|
private String publicIpId;
|
||||||
@ -627,6 +632,10 @@ public class UserVmResponse extends BaseResponseWithTagInformation implements Co
|
|||||||
return hypervisor;
|
return hypervisor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getIpAddress() {
|
||||||
|
return ipAddress;
|
||||||
|
}
|
||||||
|
|
||||||
public String getPublicIpId() {
|
public String getPublicIpId() {
|
||||||
return publicIpId;
|
return publicIpId;
|
||||||
}
|
}
|
||||||
@ -863,6 +872,13 @@ public class UserVmResponse extends BaseResponseWithTagInformation implements Co
|
|||||||
|
|
||||||
public void setNics(Set<NicResponse> nics) {
|
public void setNics(Set<NicResponse> nics) {
|
||||||
this.nics = nics;
|
this.nics = nics;
|
||||||
|
setIpAddress(nics);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIpAddress(final Set<NicResponse> nics) {
|
||||||
|
if (CollectionUtils.isNotEmpty(nics)) {
|
||||||
|
this.ipAddress = nics.iterator().next().getIpaddress();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addNic(NicResponse nic) {
|
public void addNic(NicResponse nic) {
|
||||||
|
|||||||
@ -125,6 +125,10 @@ public interface QueryService {
|
|||||||
static final ConfigKey<Boolean> SharePublicTemplatesWithOtherDomains = new ConfigKey<>("Advanced", Boolean.class, "share.public.templates.with.other.domains", "true",
|
static final ConfigKey<Boolean> SharePublicTemplatesWithOtherDomains = new ConfigKey<>("Advanced", Boolean.class, "share.public.templates.with.other.domains", "true",
|
||||||
"If false, templates of this domain will not show up in the list templates of other domains.", true, ConfigKey.Scope.Domain);
|
"If false, templates of this domain will not show up in the list templates of other domains.", true, ConfigKey.Scope.Domain);
|
||||||
|
|
||||||
|
ConfigKey<Boolean> ReturnVmStatsOnVmList = new ConfigKey<>("Advanced", Boolean.class, "return.vm.stats.on.vm.list", "true",
|
||||||
|
"If false, changes the listVirtualMachines default details to [group, nics, secgrp, tmpl, servoff, diskoff, backoff, iso, volume, min, affgrp], so that the VMs' stats" +
|
||||||
|
" are not returned by default when listing VMs; only when the 'stats' or 'all' detail is informed.", true, ConfigKey.Scope.Global);
|
||||||
|
|
||||||
ListResponse<UserResponse> searchForUsers(ListUsersCmd cmd) throws PermissionDeniedException;
|
ListResponse<UserResponse> searchForUsers(ListUsersCmd cmd) throws PermissionDeniedException;
|
||||||
|
|
||||||
ListResponse<UserResponse> searchForUsers(Long domainId, boolean recursive) throws PermissionDeniedException;
|
ListResponse<UserResponse> searchForUsers(Long domainId, boolean recursive) throws PermissionDeniedException;
|
||||||
|
|||||||
@ -148,6 +148,7 @@ public class UserVmVO extends VMInstanceVO implements UserVm {
|
|||||||
return updateParameters;
|
return updateParameters;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public String getUserVmType() {
|
public String getUserVmType() {
|
||||||
return userVmType;
|
return userVmType;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -18,17 +18,24 @@ package com.cloud.kubernetes.cluster;
|
|||||||
|
|
||||||
import com.cloud.kubernetes.cluster.dao.KubernetesClusterDao;
|
import com.cloud.kubernetes.cluster.dao.KubernetesClusterDao;
|
||||||
import com.cloud.kubernetes.cluster.dao.KubernetesClusterVmMapDao;
|
import com.cloud.kubernetes.cluster.dao.KubernetesClusterVmMapDao;
|
||||||
|
import com.cloud.uservm.UserVm;
|
||||||
import com.cloud.utils.component.AdapterBase;
|
import com.cloud.utils.component.AdapterBase;
|
||||||
|
import com.cloud.utils.exception.CloudRuntimeException;
|
||||||
|
import com.cloud.vm.UserVmManager;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
|
|
||||||
import org.apache.cloudstack.acl.ControlledEntity;
|
import org.apache.cloudstack.acl.ControlledEntity;
|
||||||
import org.apache.cloudstack.framework.config.ConfigKey;
|
import org.apache.cloudstack.framework.config.ConfigKey;
|
||||||
import org.apache.cloudstack.framework.config.Configurable;
|
import org.apache.cloudstack.framework.config.Configurable;
|
||||||
|
import org.apache.log4j.Logger;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
public class KubernetesClusterHelperImpl extends AdapterBase implements KubernetesClusterHelper, Configurable {
|
public class KubernetesClusterHelperImpl extends AdapterBase implements KubernetesClusterHelper, Configurable {
|
||||||
|
private static final Logger logger = Logger.getLogger(KubernetesClusterHelperImpl.class);
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private KubernetesClusterDao kubernetesClusterDao;
|
private KubernetesClusterDao kubernetesClusterDao;
|
||||||
@ -49,6 +56,26 @@ public class KubernetesClusterHelperImpl extends AdapterBase implements Kubernet
|
|||||||
return kubernetesClusterDao.findById(clusterVmMapVO.getClusterId());
|
return kubernetesClusterDao.findById(clusterVmMapVO.getClusterId());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void checkVmCanBeDestroyed(UserVm userVm) {
|
||||||
|
if (!UserVmManager.CKS_NODE.equals(userVm.getUserVmType())) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
KubernetesClusterVmMapVO vmMapVO = kubernetesClusterVmMapDao.findByVmId(userVm.getId());
|
||||||
|
if (vmMapVO == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
logger.error(String.format("VM ID: %s is a part of Kubernetes cluster ID: %d", userVm.getId(), vmMapVO.getClusterId()));
|
||||||
|
KubernetesCluster kubernetesCluster = kubernetesClusterDao.findById(vmMapVO.getClusterId());
|
||||||
|
String msg = "Instance is a part of a Kubernetes cluster";
|
||||||
|
if (kubernetesCluster != null) {
|
||||||
|
msg += String.format(": %s", kubernetesCluster.getName());
|
||||||
|
}
|
||||||
|
msg += ". Use Instance delete option from Kubernetes cluster details or scale API for " +
|
||||||
|
"Kubernetes clusters with 'nodeids' to destroy the instance.";
|
||||||
|
throw new CloudRuntimeException(msg);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getConfigComponentName() {
|
public String getConfigComponentName() {
|
||||||
return KubernetesClusterHelper.class.getSimpleName();
|
return KubernetesClusterHelper.class.getSimpleName();
|
||||||
|
|||||||
@ -30,4 +30,6 @@ public interface KubernetesClusterVmMapDao extends GenericDao<KubernetesClusterV
|
|||||||
int removeByClusterIdAndVmIdsIn(long clusterId, List<Long> vmIds);
|
int removeByClusterIdAndVmIdsIn(long clusterId, List<Long> vmIds);
|
||||||
|
|
||||||
public int removeByClusterId(long clusterId);
|
public int removeByClusterId(long clusterId);
|
||||||
|
|
||||||
|
KubernetesClusterVmMapVO findByVmId(long vmId);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -81,4 +81,14 @@ public class KubernetesClusterVmMapDaoImpl extends GenericDaoBase<KubernetesClus
|
|||||||
sc.setParameters("clusterId", clusterId);
|
sc.setParameters("clusterId", clusterId);
|
||||||
return remove(sc);
|
return remove(sc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public KubernetesClusterVmMapVO findByVmId(long vmId) {
|
||||||
|
SearchBuilder<KubernetesClusterVmMapVO> sb = createSearchBuilder();
|
||||||
|
sb.and("vmId", sb.entity().getVmId(), SearchCriteria.Op.EQ);
|
||||||
|
sb.done();
|
||||||
|
SearchCriteria<KubernetesClusterVmMapVO> sc = sb.create();
|
||||||
|
sc.setParameters("vmId", vmId);
|
||||||
|
return findOneBy(sc);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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.kubernetes.cluster;
|
||||||
|
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.mockito.InjectMocks;
|
||||||
|
import org.mockito.Mock;
|
||||||
|
import org.mockito.Mockito;
|
||||||
|
import org.mockito.junit.MockitoJUnitRunner;
|
||||||
|
|
||||||
|
import com.cloud.kubernetes.cluster.dao.KubernetesClusterDao;
|
||||||
|
import com.cloud.kubernetes.cluster.dao.KubernetesClusterVmMapDao;
|
||||||
|
import com.cloud.uservm.UserVm;
|
||||||
|
import com.cloud.utils.exception.CloudRuntimeException;
|
||||||
|
import com.cloud.vm.UserVmManager;
|
||||||
|
|
||||||
|
@RunWith(MockitoJUnitRunner.class)
|
||||||
|
public class KubernetesClusterHelperImplTest {
|
||||||
|
@Mock
|
||||||
|
KubernetesClusterVmMapDao kubernetesClusterVmMapDao;
|
||||||
|
@Mock
|
||||||
|
KubernetesClusterDao kubernetesClusterDao;
|
||||||
|
|
||||||
|
@InjectMocks
|
||||||
|
KubernetesClusterHelperImpl kubernetesClusterHelper = new KubernetesClusterHelperImpl();
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCheckVmCanBeDestroyedNotCKSNode() {
|
||||||
|
UserVm vm = Mockito.mock(UserVm.class);
|
||||||
|
Mockito.when(vm.getUserVmType()).thenReturn("");
|
||||||
|
kubernetesClusterHelper.checkVmCanBeDestroyed(vm);
|
||||||
|
Mockito.verify(kubernetesClusterVmMapDao, Mockito.never()).findByVmId(Mockito.anyLong());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCheckVmCanBeDestroyedNotInCluster() {
|
||||||
|
UserVm vm = Mockito.mock(UserVm.class);
|
||||||
|
Mockito.when(vm.getId()).thenReturn(1L);
|
||||||
|
Mockito.when(vm.getUserVmType()).thenReturn(UserVmManager.CKS_NODE);
|
||||||
|
Mockito.when(kubernetesClusterVmMapDao.findByVmId(1L)).thenReturn(null);
|
||||||
|
kubernetesClusterHelper.checkVmCanBeDestroyed(vm);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = CloudRuntimeException.class)
|
||||||
|
public void testCheckVmCanBeDestroyedInCluster() {
|
||||||
|
UserVm vm = Mockito.mock(UserVm.class);
|
||||||
|
Mockito.when(vm.getId()).thenReturn(1L);
|
||||||
|
Mockito.when(vm.getUserVmType()).thenReturn(UserVmManager.CKS_NODE);
|
||||||
|
KubernetesClusterVmMapVO map = Mockito.mock(KubernetesClusterVmMapVO.class);
|
||||||
|
Mockito.when(map.getClusterId()).thenReturn(1L);
|
||||||
|
Mockito.when(kubernetesClusterVmMapDao.findByVmId(1L)).thenReturn(map);
|
||||||
|
Mockito.when(kubernetesClusterDao.findById(1L)).thenReturn(Mockito.mock(KubernetesClusterVO.class));
|
||||||
|
kubernetesClusterHelper.checkVmCanBeDestroyed(vm);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -17,10 +17,12 @@
|
|||||||
|
|
||||||
package org.apache.cloudstack.api;
|
package org.apache.cloudstack.api;
|
||||||
|
|
||||||
|
import java.util.EnumSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
|
import com.cloud.exception.InvalidParameterValueException;
|
||||||
import org.apache.cloudstack.acl.RoleType;
|
import org.apache.cloudstack.acl.RoleType;
|
||||||
import org.apache.cloudstack.api.command.user.UserCmd;
|
import org.apache.cloudstack.api.command.user.UserCmd;
|
||||||
import org.apache.cloudstack.api.command.user.vm.ListVMsCmd;
|
import org.apache.cloudstack.api.command.user.vm.ListVMsCmd;
|
||||||
@ -42,18 +44,21 @@ import org.apache.cloudstack.response.VmMetricsResponse;
|
|||||||
* although most of it is not suitable/useful for the API purpose.</li>
|
* although most of it is not suitable/useful for the API purpose.</li>
|
||||||
* </ul>
|
* </ul>
|
||||||
*/
|
*/
|
||||||
@APICommand(name = ListVMsMetricsCmd.APINAME, description = "Lists VM metrics", responseObject = VmMetricsResponse.class,
|
@APICommand(name = "listVirtualMachinesMetrics", description = "Lists VM metrics", responseObject = VmMetricsResponse.class,
|
||||||
requestHasSensitiveInfo = false, responseHasSensitiveInfo = false, responseView = ResponseObject.ResponseView.Restricted,
|
requestHasSensitiveInfo = false, responseHasSensitiveInfo = false, responseView = ResponseObject.ResponseView.Restricted,
|
||||||
since = "4.9.3", authorized = {RoleType.ResourceAdmin, RoleType.DomainAdmin, RoleType.User})
|
since = "4.9.3", authorized = {RoleType.ResourceAdmin, RoleType.DomainAdmin, RoleType.User})
|
||||||
public class ListVMsMetricsCmd extends ListVMsCmd implements UserCmd {
|
public class ListVMsMetricsCmd extends ListVMsCmd implements UserCmd {
|
||||||
public static final String APINAME = "listVirtualMachinesMetrics";
|
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private MetricsService metricsService;
|
private MetricsService metricsService;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getCommandName() {
|
public EnumSet<ApiConstants.VMDetails> getDetails() throws InvalidParameterValueException {
|
||||||
return APINAME.toLowerCase() + BaseCmd.RESPONSE_SUFFIX;
|
if (isViewDetailsEmpty()) {
|
||||||
|
return EnumSet.of(ApiConstants.VMDetails.all);
|
||||||
|
}
|
||||||
|
|
||||||
|
return super.getDetails();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@ -617,7 +617,6 @@ public class MetricsServiceImpl extends MutualExclusiveIdsManagerBase implements
|
|||||||
}
|
}
|
||||||
|
|
||||||
metricsResponse.setHasAnnotation(vmResponse.hasAnnotation());
|
metricsResponse.setHasAnnotation(vmResponse.hasAnnotation());
|
||||||
metricsResponse.setIpAddress(vmResponse.getNics());
|
|
||||||
metricsResponse.setCpuTotal(vmResponse.getCpuNumber(), vmResponse.getCpuSpeed());
|
metricsResponse.setCpuTotal(vmResponse.getCpuNumber(), vmResponse.getCpuSpeed());
|
||||||
metricsResponse.setMemTotal(vmResponse.getMemory());
|
metricsResponse.setMemTotal(vmResponse.getMemory());
|
||||||
metricsResponse.setNetworkRead(vmResponse.getNetworkKbsRead());
|
metricsResponse.setNetworkRead(vmResponse.getNetworkKbsRead());
|
||||||
|
|||||||
@ -17,19 +17,13 @@
|
|||||||
|
|
||||||
package org.apache.cloudstack.response;
|
package org.apache.cloudstack.response;
|
||||||
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import org.apache.cloudstack.api.ApiConstants;
|
import org.apache.cloudstack.api.ApiConstants;
|
||||||
import org.apache.cloudstack.api.response.NicResponse;
|
|
||||||
import org.apache.cloudstack.api.response.UserVmResponse;
|
import org.apache.cloudstack.api.response.UserVmResponse;
|
||||||
|
|
||||||
import com.cloud.serializer.Param;
|
import com.cloud.serializer.Param;
|
||||||
import com.google.gson.annotations.SerializedName;
|
import com.google.gson.annotations.SerializedName;
|
||||||
|
|
||||||
public class VmMetricsResponse extends UserVmResponse {
|
public class VmMetricsResponse extends UserVmResponse {
|
||||||
@SerializedName(ApiConstants.IP_ADDRESS)
|
|
||||||
@Param(description = "the VM's primary IP address")
|
|
||||||
private String ipAddress;
|
|
||||||
|
|
||||||
@SerializedName("cputotal")
|
@SerializedName("cputotal")
|
||||||
@Param(description = "the total cpu capacity in Ghz")
|
@Param(description = "the total cpu capacity in Ghz")
|
||||||
@ -59,11 +53,6 @@ public class VmMetricsResponse extends UserVmResponse {
|
|||||||
@Param(description = "the total disk iops")
|
@Param(description = "the total disk iops")
|
||||||
private Long diskIopsTotal;
|
private Long diskIopsTotal;
|
||||||
|
|
||||||
public void setIpAddress(final Set<NicResponse> nics) {
|
|
||||||
if (nics != null && nics.size() > 0) {
|
|
||||||
this.ipAddress = nics.iterator().next().getIpaddress();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setCpuTotal(final Integer cpuNumber, final Integer cpuSpeed) {
|
public void setCpuTotal(final Integer cpuNumber, final Integer cpuSpeed) {
|
||||||
if (cpuNumber != null && cpuSpeed != null) {
|
if (cpuNumber != null && cpuSpeed != null) {
|
||||||
|
|||||||
@ -135,24 +135,12 @@ public class LinstorStorageAdaptor implements StorageAdaptor {
|
|||||||
List<VolumeDefinition> volumeDefs = api.volumeDefinitionList(rscName, null, null);
|
List<VolumeDefinition> volumeDefs = api.volumeDefinitionList(rscName, null, null);
|
||||||
final long size = volumeDefs.isEmpty() ? 0 : volumeDefs.get(0).getSizeKib() * 1024;
|
final long size = volumeDefs.isEmpty() ? 0 : volumeDefs.get(0).getSizeKib() * 1024;
|
||||||
|
|
||||||
List<ResourceWithVolumes> resources = api.viewResources(
|
final String devicePath = LinstorUtil.getDevicePath(api, rscName);
|
||||||
Collections.emptyList(),
|
final KVMPhysicalDisk kvmDisk = new KVMPhysicalDisk(devicePath, name, pool);
|
||||||
Collections.singletonList(rscName),
|
kvmDisk.setFormat(QemuImg.PhysicalDiskFormat.RAW);
|
||||||
Collections.emptyList(),
|
kvmDisk.setSize(size);
|
||||||
null,
|
kvmDisk.setVirtualSize(size);
|
||||||
null,
|
return kvmDisk;
|
||||||
null);
|
|
||||||
if (!resources.isEmpty() && !resources.get(0).getVolumes().isEmpty()) {
|
|
||||||
final String devPath = resources.get(0).getVolumes().get(0).getDevicePath();
|
|
||||||
final KVMPhysicalDisk kvmDisk = new KVMPhysicalDisk(devPath, name, pool);
|
|
||||||
kvmDisk.setFormat(QemuImg.PhysicalDiskFormat.RAW);
|
|
||||||
kvmDisk.setSize(size);
|
|
||||||
kvmDisk.setVirtualSize(size);
|
|
||||||
return kvmDisk;
|
|
||||||
} else {
|
|
||||||
logger.error("Linstor: viewResources didn't return resources or volumes for " + rscName);
|
|
||||||
throw new CloudRuntimeException("Linstor: viewResources didn't return resources or volumes.");
|
|
||||||
}
|
|
||||||
} catch (ApiException apiEx) {
|
} catch (ApiException apiEx) {
|
||||||
logger.error(apiEx);
|
logger.error(apiEx);
|
||||||
throw new CloudRuntimeException(apiEx.getBestMessage(), apiEx);
|
throw new CloudRuntimeException(apiEx.getBestMessage(), apiEx);
|
||||||
|
|||||||
@ -29,7 +29,6 @@ import com.linbit.linstor.api.model.ResourceDefinitionCreate;
|
|||||||
import com.linbit.linstor.api.model.ResourceDefinitionModify;
|
import com.linbit.linstor.api.model.ResourceDefinitionModify;
|
||||||
import com.linbit.linstor.api.model.ResourceGroupSpawn;
|
import com.linbit.linstor.api.model.ResourceGroupSpawn;
|
||||||
import com.linbit.linstor.api.model.ResourceMakeAvailable;
|
import com.linbit.linstor.api.model.ResourceMakeAvailable;
|
||||||
import com.linbit.linstor.api.model.ResourceWithVolumes;
|
|
||||||
import com.linbit.linstor.api.model.Snapshot;
|
import com.linbit.linstor.api.model.Snapshot;
|
||||||
import com.linbit.linstor.api.model.SnapshotRestore;
|
import com.linbit.linstor.api.model.SnapshotRestore;
|
||||||
import com.linbit.linstor.api.model.VolumeDefinition;
|
import com.linbit.linstor.api.model.VolumeDefinition;
|
||||||
@ -343,25 +342,6 @@ public class LinstorPrimaryDataStoreDriverImpl implements PrimaryDataStoreDriver
|
|||||||
return answers.stream().filter(ApiCallRc::isError).findFirst().map(ApiCallRc::getMessage).orElse(null);
|
return answers.stream().filter(ApiCallRc::isError).findFirst().map(ApiCallRc::getMessage).orElse(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getDeviceName(DevelopersApi linstorApi, String rscName) throws ApiException {
|
|
||||||
List<ResourceWithVolumes> resources = linstorApi.viewResources(
|
|
||||||
Collections.emptyList(),
|
|
||||||
Collections.singletonList(rscName),
|
|
||||||
Collections.emptyList(),
|
|
||||||
null,
|
|
||||||
null,
|
|
||||||
null);
|
|
||||||
if (!resources.isEmpty() && !resources.get(0).getVolumes().isEmpty())
|
|
||||||
{
|
|
||||||
logger.info("Linstor: Created drbd device: " + resources.get(0).getVolumes().get(0).getDevicePath());
|
|
||||||
return resources.get(0).getVolumes().get(0).getDevicePath();
|
|
||||||
} else
|
|
||||||
{
|
|
||||||
logger.error("Linstor: viewResources didn't return resources or volumes.");
|
|
||||||
throw new CloudRuntimeException("Linstor: viewResources didn't return resources or volumes.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void applyQoSSettings(StoragePoolVO storagePool, DevelopersApi api, String rscName, Long maxIops)
|
private void applyQoSSettings(StoragePoolVO storagePool, DevelopersApi api, String rscName, Long maxIops)
|
||||||
throws ApiException
|
throws ApiException
|
||||||
{
|
{
|
||||||
@ -447,7 +427,7 @@ public class LinstorPrimaryDataStoreDriverImpl implements PrimaryDataStoreDriver
|
|||||||
|
|
||||||
applyAuxProps(api, rscName, volName, vmName);
|
applyAuxProps(api, rscName, volName, vmName);
|
||||||
|
|
||||||
return getDeviceName(api, rscName);
|
return LinstorUtil.getDevicePath(api, rscName);
|
||||||
} catch (ApiException apiEx)
|
} catch (ApiException apiEx)
|
||||||
{
|
{
|
||||||
logger.error("Linstor: ApiEx - " + apiEx.getMessage());
|
logger.error("Linstor: ApiEx - " + apiEx.getMessage());
|
||||||
@ -467,7 +447,7 @@ public class LinstorPrimaryDataStoreDriverImpl implements PrimaryDataStoreDriver
|
|||||||
{
|
{
|
||||||
applyQoSSettings(storagePoolVO, linstorApi, rscName, vol.getMaxIops());
|
applyQoSSettings(storagePoolVO, linstorApi, rscName, vol.getMaxIops());
|
||||||
|
|
||||||
return deviceName;
|
return LinstorUtil.getDevicePath(linstorApi, rscName);
|
||||||
} catch (ApiException apiEx)
|
} catch (ApiException apiEx)
|
||||||
{
|
{
|
||||||
logger.error("Linstor: ApiEx - " + apiEx.getMessage());
|
logger.error("Linstor: ApiEx - " + apiEx.getMessage());
|
||||||
@ -519,7 +499,7 @@ public class LinstorPrimaryDataStoreDriverImpl implements PrimaryDataStoreDriver
|
|||||||
applyAuxProps(linstorApi, rscName, volumeInfo.getName(), volumeInfo.getAttachedVmName());
|
applyAuxProps(linstorApi, rscName, volumeInfo.getName(), volumeInfo.getAttachedVmName());
|
||||||
applyQoSSettings(storagePoolVO, linstorApi, rscName, volumeInfo.getMaxIops());
|
applyQoSSettings(storagePoolVO, linstorApi, rscName, volumeInfo.getMaxIops());
|
||||||
|
|
||||||
return getDeviceName(linstorApi, rscName);
|
return LinstorUtil.getDevicePath(linstorApi, rscName);
|
||||||
} catch (ApiException apiEx) {
|
} catch (ApiException apiEx) {
|
||||||
logger.error("Linstor: ApiEx - " + apiEx.getMessage());
|
logger.error("Linstor: ApiEx - " + apiEx.getMessage());
|
||||||
throw new CloudRuntimeException(apiEx.getBestMessage(), apiEx);
|
throw new CloudRuntimeException(apiEx.getBestMessage(), apiEx);
|
||||||
@ -571,7 +551,7 @@ public class LinstorPrimaryDataStoreDriverImpl implements PrimaryDataStoreDriver
|
|||||||
applyAuxProps(linstorApi, rscName, volumeVO.getName(), null);
|
applyAuxProps(linstorApi, rscName, volumeVO.getName(), null);
|
||||||
applyQoSSettings(storagePoolVO, linstorApi, rscName, volumeVO.getMaxIops());
|
applyQoSSettings(storagePoolVO, linstorApi, rscName, volumeVO.getMaxIops());
|
||||||
|
|
||||||
return getDeviceName(linstorApi, rscName);
|
return LinstorUtil.getDevicePath(linstorApi, rscName);
|
||||||
} catch (ApiException apiEx) {
|
} catch (ApiException apiEx) {
|
||||||
logger.error("Linstor: ApiEx - " + apiEx.getMessage());
|
logger.error("Linstor: ApiEx - " + apiEx.getMessage());
|
||||||
throw new CloudRuntimeException(apiEx.getBestMessage(), apiEx);
|
throw new CloudRuntimeException(apiEx.getBestMessage(), apiEx);
|
||||||
@ -940,7 +920,7 @@ public class LinstorPrimaryDataStoreDriverImpl implements PrimaryDataStoreDriver
|
|||||||
|
|
||||||
api.resourceSnapshotRestore(rscName, snapshotName, sr);
|
api.resourceSnapshotRestore(rscName, snapshotName, sr);
|
||||||
|
|
||||||
return getDeviceName(api, restoredName);
|
return LinstorUtil.getDevicePath(api, restoredName);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Answer copyTemplate(DataObject srcData, DataObject dstData) {
|
private Answer copyTemplate(DataObject srcData, DataObject dstData) {
|
||||||
|
|||||||
@ -203,4 +203,37 @@ public class LinstorUtil {
|
|||||||
LOGGER.error("isResourceInUse: null returned from resourceList");
|
LOGGER.error("isResourceInUse: null returned from resourceList");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Try to get the device path for the given resource name.
|
||||||
|
* This could be made a bit more direct after java-linstor api is fixed for layer data subtypes.
|
||||||
|
* @param api developer api object to use
|
||||||
|
* @param rscName resource name to get the device path
|
||||||
|
* @return The device path of the resource.
|
||||||
|
* @throws ApiException if Linstor API call failed.
|
||||||
|
* @throws CloudRuntimeException if no device path could be found.
|
||||||
|
*/
|
||||||
|
public static String getDevicePath(DevelopersApi api, String rscName) throws ApiException, CloudRuntimeException {
|
||||||
|
List<ResourceWithVolumes> resources = api.viewResources(
|
||||||
|
Collections.emptyList(),
|
||||||
|
Collections.singletonList(rscName),
|
||||||
|
Collections.emptyList(),
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
null);
|
||||||
|
for (ResourceWithVolumes rsc : resources) {
|
||||||
|
if (!rsc.getVolumes().isEmpty()) {
|
||||||
|
// CloudStack resource always only have 1 volume
|
||||||
|
String devicePath = rsc.getVolumes().get(0).getDevicePath();
|
||||||
|
if (devicePath != null && !devicePath.isEmpty()) {
|
||||||
|
LOGGER.debug("getDevicePath: {} -> {}", rscName, devicePath);
|
||||||
|
return devicePath;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
final String errMsg = "viewResources didn't return resources or volumes for " + rscName;
|
||||||
|
LOGGER.error(errMsg);
|
||||||
|
throw new CloudRuntimeException("Linstor: " + errMsg);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -31,15 +31,17 @@ import org.apache.cloudstack.auth.UserOAuth2Authenticator;
|
|||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import static org.apache.cloudstack.oauth2.OAuth2AuthManager.OAuth2IsPluginEnabled;
|
||||||
|
|
||||||
public class OAuth2UserAuthenticator extends AdapterBase implements UserAuthenticator {
|
public class OAuth2UserAuthenticator extends AdapterBase implements UserAuthenticator {
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private UserAccountDao _userAccountDao;
|
private UserAccountDao userAccountDao;
|
||||||
@Inject
|
@Inject
|
||||||
private UserDao _userDao;
|
private UserDao userDao;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private OAuth2AuthManager _userOAuth2mgr;
|
private OAuth2AuthManager userOAuth2mgr;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Pair<Boolean, ActionOnFailedAuthentication> authenticate(String username, String password, Long domainId, Map<String, Object[]> requestParameters) {
|
public Pair<Boolean, ActionOnFailedAuthentication> authenticate(String username, String password, Long domainId, Map<String, Object[]> requestParameters) {
|
||||||
@ -47,12 +49,20 @@ public class OAuth2UserAuthenticator extends AdapterBase implements UserAuthenti
|
|||||||
logger.debug("Trying OAuth2 auth for user: " + username);
|
logger.debug("Trying OAuth2 auth for user: " + username);
|
||||||
}
|
}
|
||||||
|
|
||||||
final UserAccount userAccount = _userAccountDao.getUserAccount(username, domainId);
|
if (!isOAuthPluginEnabled()) {
|
||||||
|
logger.debug("OAuth2 plugin is disabled");
|
||||||
|
return new Pair<Boolean, ActionOnFailedAuthentication>(false, null);
|
||||||
|
} else if (requestParameters == null) {
|
||||||
|
logger.debug("Request parameters are null");
|
||||||
|
return new Pair<Boolean, ActionOnFailedAuthentication>(false, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
final UserAccount userAccount = userAccountDao.getUserAccount(username, domainId);
|
||||||
if (userAccount == null) {
|
if (userAccount == null) {
|
||||||
logger.debug("Unable to find user with " + username + " in domain " + domainId + ", or user source is not OAUTH2");
|
logger.debug("Unable to find user with " + username + " in domain " + domainId + ", or user source is not OAUTH2");
|
||||||
return new Pair<Boolean, ActionOnFailedAuthentication>(false, null);
|
return new Pair<Boolean, ActionOnFailedAuthentication>(false, null);
|
||||||
} else {
|
} else {
|
||||||
User user = _userDao.getUser(userAccount.getId());
|
User user = userDao.getUser(userAccount.getId());
|
||||||
final String[] provider = (String[])requestParameters.get(ApiConstants.PROVIDER);
|
final String[] provider = (String[])requestParameters.get(ApiConstants.PROVIDER);
|
||||||
final String[] emailArray = (String[])requestParameters.get(ApiConstants.EMAIL);
|
final String[] emailArray = (String[])requestParameters.get(ApiConstants.EMAIL);
|
||||||
final String[] secretCodeArray = (String[])requestParameters.get(ApiConstants.SECRET_CODE);
|
final String[] secretCodeArray = (String[])requestParameters.get(ApiConstants.SECRET_CODE);
|
||||||
@ -60,7 +70,7 @@ public class OAuth2UserAuthenticator extends AdapterBase implements UserAuthenti
|
|||||||
String email = ((emailArray == null) ? null : emailArray[0]);
|
String email = ((emailArray == null) ? null : emailArray[0]);
|
||||||
String secretCode = ((secretCodeArray == null) ? null : secretCodeArray[0]);
|
String secretCode = ((secretCodeArray == null) ? null : secretCodeArray[0]);
|
||||||
|
|
||||||
UserOAuth2Authenticator authenticator = _userOAuth2mgr.getUserOAuth2AuthenticationProvider(oauthProvider);
|
UserOAuth2Authenticator authenticator = userOAuth2mgr.getUserOAuth2AuthenticationProvider(oauthProvider);
|
||||||
if (user != null && authenticator.verifyUser(email, secretCode)) {
|
if (user != null && authenticator.verifyUser(email, secretCode)) {
|
||||||
return new Pair<Boolean, ActionOnFailedAuthentication>(true, null);
|
return new Pair<Boolean, ActionOnFailedAuthentication>(true, null);
|
||||||
}
|
}
|
||||||
@ -73,4 +83,8 @@ public class OAuth2UserAuthenticator extends AdapterBase implements UserAuthenti
|
|||||||
public String encode(String password) {
|
public String encode(String password) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected boolean isOAuthPluginEnabled() {
|
||||||
|
return OAuth2IsPluginEnabled.value();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -27,21 +27,29 @@ import org.apache.cloudstack.auth.UserOAuth2Authenticator;
|
|||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
import org.mockito.InjectMocks;
|
import org.mockito.InjectMocks;
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
import org.mockito.MockitoAnnotations;
|
import org.mockito.MockitoAnnotations;
|
||||||
|
import org.mockito.Spy;
|
||||||
|
import org.mockito.junit.MockitoJUnitRunner;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertFalse;
|
||||||
|
import static org.junit.Assert.assertNull;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
import static org.mockito.ArgumentMatchers.anyLong;
|
import static org.mockito.ArgumentMatchers.anyLong;
|
||||||
import static org.mockito.ArgumentMatchers.anyString;
|
import static org.mockito.ArgumentMatchers.anyString;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.never;
|
import static org.mockito.Mockito.never;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
import static org.mockito.Mockito.doReturn;
|
||||||
|
|
||||||
|
@RunWith(MockitoJUnitRunner.class)
|
||||||
public class OAuth2UserAuthenticatorTest {
|
public class OAuth2UserAuthenticatorTest {
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
@ -54,13 +62,14 @@ public class OAuth2UserAuthenticatorTest {
|
|||||||
private OAuth2AuthManager userOAuth2mgr;
|
private OAuth2AuthManager userOAuth2mgr;
|
||||||
|
|
||||||
@InjectMocks
|
@InjectMocks
|
||||||
|
@Spy
|
||||||
private OAuth2UserAuthenticator authenticator;
|
private OAuth2UserAuthenticator authenticator;
|
||||||
|
|
||||||
private AutoCloseable closeable;
|
private AutoCloseable closeable;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
closeable = MockitoAnnotations.openMocks(this);
|
closeable = MockitoAnnotations.openMocks(this);
|
||||||
|
doReturn(true).when(authenticator).isOAuthPluginEnabled();
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@After
|
||||||
@ -68,6 +77,7 @@ public class OAuth2UserAuthenticatorTest {
|
|||||||
closeable.close();
|
closeable.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAuthenticateWithValidCredentials() {
|
public void testAuthenticateWithValidCredentials() {
|
||||||
String username = "testuser";
|
String username = "testuser";
|
||||||
@ -92,13 +102,13 @@ public class OAuth2UserAuthenticatorTest {
|
|||||||
|
|
||||||
Pair<Boolean, OAuth2UserAuthenticator.ActionOnFailedAuthentication> result = authenticator.authenticate(username, null, domainId, requestParameters);
|
Pair<Boolean, OAuth2UserAuthenticator.ActionOnFailedAuthentication> result = authenticator.authenticate(username, null, domainId, requestParameters);
|
||||||
|
|
||||||
|
assertTrue(result.first());
|
||||||
|
assertNull(result.second());
|
||||||
|
|
||||||
verify(userAccountDao).getUserAccount(username, domainId);
|
verify(userAccountDao).getUserAccount(username, domainId);
|
||||||
verify(userDao).getUser(userAccount.getId());
|
verify(userDao).getUser(userAccount.getId());
|
||||||
verify(userOAuth2mgr).getUserOAuth2AuthenticationProvider(provider[0]);
|
verify(userOAuth2mgr).getUserOAuth2AuthenticationProvider(provider[0]);
|
||||||
verify(userOAuth2Authenticator).verifyUser(email[0], secretCode[0]);
|
verify(userOAuth2Authenticator).verifyUser(email[0], secretCode[0]);
|
||||||
|
|
||||||
assertEquals(true, result.first().booleanValue());
|
|
||||||
assertEquals(null, result.second());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -114,7 +124,7 @@ public class OAuth2UserAuthenticatorTest {
|
|||||||
UserOAuth2Authenticator userOAuth2Authenticator = mock(UserOAuth2Authenticator.class);
|
UserOAuth2Authenticator userOAuth2Authenticator = mock(UserOAuth2Authenticator.class);
|
||||||
|
|
||||||
when(userAccountDao.getUserAccount(username, domainId)).thenReturn(userAccount);
|
when(userAccountDao.getUserAccount(username, domainId)).thenReturn(userAccount);
|
||||||
when(userDao.getUser(userAccount.getId())).thenReturn( user);
|
when(userDao.getUser(userAccount.getId())).thenReturn(user);
|
||||||
when(userOAuth2mgr.getUserOAuth2AuthenticationProvider(provider[0])).thenReturn(userOAuth2Authenticator);
|
when(userOAuth2mgr.getUserOAuth2AuthenticationProvider(provider[0])).thenReturn(userOAuth2Authenticator);
|
||||||
when(userOAuth2Authenticator.verifyUser(email[0], secretCode[0])).thenReturn(false);
|
when(userOAuth2Authenticator.verifyUser(email[0], secretCode[0])).thenReturn(false);
|
||||||
|
|
||||||
@ -125,13 +135,13 @@ public class OAuth2UserAuthenticatorTest {
|
|||||||
|
|
||||||
Pair<Boolean, OAuth2UserAuthenticator.ActionOnFailedAuthentication> result = authenticator.authenticate(username, null, domainId, requestParameters);
|
Pair<Boolean, OAuth2UserAuthenticator.ActionOnFailedAuthentication> result = authenticator.authenticate(username, null, domainId, requestParameters);
|
||||||
|
|
||||||
|
assertFalse(result.first());
|
||||||
|
assertEquals(OAuth2UserAuthenticator.ActionOnFailedAuthentication.INCREMENT_INCORRECT_LOGIN_ATTEMPT_COUNT, result.second());
|
||||||
|
|
||||||
verify(userAccountDao).getUserAccount(username, domainId);
|
verify(userAccountDao).getUserAccount(username, domainId);
|
||||||
verify(userDao).getUser(userAccount.getId());
|
verify(userDao).getUser(userAccount.getId());
|
||||||
verify(userOAuth2mgr).getUserOAuth2AuthenticationProvider(provider[0]);
|
verify(userOAuth2mgr).getUserOAuth2AuthenticationProvider(provider[0]);
|
||||||
verify(userOAuth2Authenticator).verifyUser(email[0], secretCode[0]);
|
verify(userOAuth2Authenticator).verifyUser(email[0], secretCode[0]);
|
||||||
|
|
||||||
assertEquals(false, result.first().booleanValue());
|
|
||||||
assertEquals(OAuth2UserAuthenticator.ActionOnFailedAuthentication.INCREMENT_INCORRECT_LOGIN_ATTEMPT_COUNT, result.second());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -151,11 +161,11 @@ public class OAuth2UserAuthenticatorTest {
|
|||||||
|
|
||||||
Pair<Boolean, OAuth2UserAuthenticator.ActionOnFailedAuthentication> result = authenticator.authenticate(username, null, domainId, requestParameters);
|
Pair<Boolean, OAuth2UserAuthenticator.ActionOnFailedAuthentication> result = authenticator.authenticate(username, null, domainId, requestParameters);
|
||||||
|
|
||||||
|
assertFalse(result.first());
|
||||||
|
assertNull(result.second());
|
||||||
|
|
||||||
verify(userAccountDao).getUserAccount(username, domainId);
|
verify(userAccountDao).getUserAccount(username, domainId);
|
||||||
verify(userDao, never()).getUser(anyLong());
|
verify(userDao, never()).getUser(anyLong());
|
||||||
verify(userOAuth2mgr, never()).getUserOAuth2AuthenticationProvider(anyString());
|
verify(userOAuth2mgr, never()).getUserOAuth2AuthenticationProvider(anyString());
|
||||||
|
|
||||||
assertEquals(false, result.first().booleanValue());
|
|
||||||
assertEquals(null, result.second());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1004,6 +1004,12 @@ public class ApiResponseHelper implements ResponseGenerator {
|
|||||||
if (!isAdmin) {
|
if (!isAdmin) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
try {
|
||||||
|
nic.getInstanceId();
|
||||||
|
} catch (NullPointerException ex) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
VirtualMachine vm = ApiDBUtils.findVMInstanceById(nic.getInstanceId());
|
VirtualMachine vm = ApiDBUtils.findVMInstanceById(nic.getInstanceId());
|
||||||
if (vm == null) {
|
if (vm == null) {
|
||||||
return;
|
return;
|
||||||
|
|||||||
@ -5718,6 +5718,6 @@ public class QueryManagerImpl extends MutualExclusiveIdsManagerBase implements Q
|
|||||||
@Override
|
@Override
|
||||||
public ConfigKey<?>[] getConfigKeys() {
|
public ConfigKey<?>[] getConfigKeys() {
|
||||||
return new ConfigKey<?>[] {AllowUserViewDestroyedVM, UserVMDeniedDetails, UserVMReadOnlyDetails, SortKeyAscending,
|
return new ConfigKey<?>[] {AllowUserViewDestroyedVM, UserVMDeniedDetails, UserVMReadOnlyDetails, SortKeyAscending,
|
||||||
AllowUserViewAllDomainAccounts, SharePublicTemplatesWithOtherDomains};
|
AllowUserViewAllDomainAccounts, SharePublicTemplatesWithOtherDomains, ReturnVmStatsOnVmList};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -167,6 +167,7 @@ public class ViewResponseHelper {
|
|||||||
// update nics, securitygroups, tags, affinitygroups for 1 to many mapping fields
|
// update nics, securitygroups, tags, affinitygroups for 1 to many mapping fields
|
||||||
userVmData = ApiDBUtils.fillVmDetails(view, userVmData, userVm);
|
userVmData = ApiDBUtils.fillVmDetails(view, userVmData, userVm);
|
||||||
}
|
}
|
||||||
|
userVmData.setIpAddress(userVmData.getNics());
|
||||||
vmDataList.put(userVm.getId(), userVmData);
|
vmDataList.put(userVm.getId(), userVmData);
|
||||||
}
|
}
|
||||||
return new ArrayList<UserVmResponse>(vmDataList.values());
|
return new ArrayList<UserVmResponse>(vmDataList.values());
|
||||||
|
|||||||
@ -330,6 +330,7 @@ public class AccountManagerImpl extends ManagerBase implements AccountManager, M
|
|||||||
|
|
||||||
private List<SecurityChecker> _securityCheckers;
|
private List<SecurityChecker> _securityCheckers;
|
||||||
private int _cleanupInterval;
|
private int _cleanupInterval;
|
||||||
|
private static final String OAUTH2_PROVIDER_NAME = "oauth2";
|
||||||
private List<String> apiNameList;
|
private List<String> apiNameList;
|
||||||
|
|
||||||
protected static Map<String, UserTwoFactorAuthenticator> userTwoFactorAuthenticationProvidersMap = new HashMap<>();
|
protected static Map<String, UserTwoFactorAuthenticator> userTwoFactorAuthenticationProvidersMap = new HashMap<>();
|
||||||
@ -2660,7 +2661,8 @@ public class AccountManagerImpl extends ManagerBase implements AccountManager, M
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (secretCode != null && !authenticator.getName().equals("oauth2")) {
|
if ((secretCode != null && !authenticator.getName().equals(OAUTH2_PROVIDER_NAME))
|
||||||
|
|| (secretCode == null && authenticator.getName().equals(OAUTH2_PROVIDER_NAME))) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
Pair<Boolean, ActionOnFailedAuthentication> result = authenticator.authenticate(username, password, domainId, requestParameters);
|
Pair<Boolean, ActionOnFailedAuthentication> result = authenticator.authenticate(username, password, domainId, requestParameters);
|
||||||
|
|||||||
@ -136,8 +136,8 @@ import org.apache.cloudstack.storage.template.VnfTemplateManager;
|
|||||||
import org.apache.cloudstack.userdata.UserDataManager;
|
import org.apache.cloudstack.userdata.UserDataManager;
|
||||||
import org.apache.cloudstack.utils.bytescale.ByteScaleUtils;
|
import org.apache.cloudstack.utils.bytescale.ByteScaleUtils;
|
||||||
import org.apache.cloudstack.utils.security.ParserUtils;
|
import org.apache.cloudstack.utils.security.ParserUtils;
|
||||||
import org.apache.cloudstack.vm.schedule.VMScheduleManager;
|
|
||||||
import org.apache.cloudstack.vm.UnmanagedVMsManager;
|
import org.apache.cloudstack.vm.UnmanagedVMsManager;
|
||||||
|
import org.apache.cloudstack.vm.schedule.VMScheduleManager;
|
||||||
import org.apache.commons.codec.binary.Base64;
|
import org.apache.commons.codec.binary.Base64;
|
||||||
import org.apache.commons.collections.CollectionUtils;
|
import org.apache.commons.collections.CollectionUtils;
|
||||||
import org.apache.commons.collections.MapUtils;
|
import org.apache.commons.collections.MapUtils;
|
||||||
@ -146,6 +146,7 @@ import org.apache.commons.lang3.StringUtils;
|
|||||||
import org.apache.commons.lang3.builder.ToStringBuilder;
|
import org.apache.commons.lang3.builder.ToStringBuilder;
|
||||||
import org.apache.commons.lang3.builder.ToStringStyle;
|
import org.apache.commons.lang3.builder.ToStringStyle;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.beans.factory.annotation.Qualifier;
|
import org.springframework.beans.factory.annotation.Qualifier;
|
||||||
import org.w3c.dom.Document;
|
import org.w3c.dom.Document;
|
||||||
@ -351,6 +352,7 @@ import com.cloud.utils.DateUtil;
|
|||||||
import com.cloud.utils.Journal;
|
import com.cloud.utils.Journal;
|
||||||
import com.cloud.utils.NumbersUtil;
|
import com.cloud.utils.NumbersUtil;
|
||||||
import com.cloud.utils.Pair;
|
import com.cloud.utils.Pair;
|
||||||
|
import com.cloud.utils.component.ComponentContext;
|
||||||
import com.cloud.utils.component.ManagerBase;
|
import com.cloud.utils.component.ManagerBase;
|
||||||
import com.cloud.utils.concurrency.NamedThreadFactory;
|
import com.cloud.utils.concurrency.NamedThreadFactory;
|
||||||
import com.cloud.utils.crypt.DBEncryptionUtil;
|
import com.cloud.utils.crypt.DBEncryptionUtil;
|
||||||
@ -601,6 +603,7 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir
|
|||||||
@Inject
|
@Inject
|
||||||
NsxProviderDao nsxProviderDao;
|
NsxProviderDao nsxProviderDao;
|
||||||
|
|
||||||
|
|
||||||
private ScheduledExecutorService _executor = null;
|
private ScheduledExecutorService _executor = null;
|
||||||
private ScheduledExecutorService _vmIpFetchExecutor = null;
|
private ScheduledExecutorService _vmIpFetchExecutor = null;
|
||||||
private int _expungeInterval;
|
private int _expungeInterval;
|
||||||
@ -3312,6 +3315,16 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void checkPluginsIfVmCanBeDestroyed(UserVm vm) {
|
||||||
|
try {
|
||||||
|
KubernetesClusterHelper kubernetesClusterHelper =
|
||||||
|
ComponentContext.getDelegateComponentOfType(KubernetesClusterHelper.class);
|
||||||
|
kubernetesClusterHelper.checkVmCanBeDestroyed(vm);
|
||||||
|
} catch (NoSuchBeanDefinitionException ignored) {
|
||||||
|
logger.debug("No KubernetesClusterHelper bean found");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ActionEvent(eventType = EventTypes.EVENT_VM_DESTROY, eventDescription = "destroying Vm", async = true)
|
@ActionEvent(eventType = EventTypes.EVENT_VM_DESTROY, eventDescription = "destroying Vm", async = true)
|
||||||
public UserVm destroyVm(DestroyVMCmd cmd) throws ResourceUnavailableException, ConcurrentOperationException {
|
public UserVm destroyVm(DestroyVMCmd cmd) throws ResourceUnavailableException, ConcurrentOperationException {
|
||||||
@ -3338,6 +3351,9 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir
|
|||||||
// check if vm belongs to AutoScale vm group in Disabled state
|
// check if vm belongs to AutoScale vm group in Disabled state
|
||||||
autoScaleManager.checkIfVmActionAllowed(vmId);
|
autoScaleManager.checkIfVmActionAllowed(vmId);
|
||||||
|
|
||||||
|
// check if vm belongs to any plugin resources
|
||||||
|
checkPluginsIfVmCanBeDestroyed(vm);
|
||||||
|
|
||||||
// check if there are active volume snapshots tasks
|
// check if there are active volume snapshots tasks
|
||||||
logger.debug("Checking if there are any ongoing snapshots on the ROOT volumes associated with VM with ID " + vmId);
|
logger.debug("Checking if there are any ongoing snapshots on the ROOT volumes associated with VM with ID " + vmId);
|
||||||
if (checkStatusOfVolumeSnapshots(vmId, Volume.Type.ROOT)) {
|
if (checkStatusOfVolumeSnapshots(vmId, Volume.Type.ROOT)) {
|
||||||
|
|||||||
@ -247,6 +247,7 @@ public class AccountManagerImplTest extends AccountManagetImplTestBase {
|
|||||||
Mockito.when(userAuthenticator.authenticate("test", "fail", 1L, new HashMap<>())).thenReturn(failureAuthenticationPair);
|
Mockito.when(userAuthenticator.authenticate("test", "fail", 1L, new HashMap<>())).thenReturn(failureAuthenticationPair);
|
||||||
Mockito.lenient().when(userAuthenticator.authenticate("test", null, 1L, new HashMap<>())).thenReturn(successAuthenticationPair);
|
Mockito.lenient().when(userAuthenticator.authenticate("test", null, 1L, new HashMap<>())).thenReturn(successAuthenticationPair);
|
||||||
Mockito.lenient().when(userAuthenticator.authenticate("test", "", 1L, new HashMap<>())).thenReturn(successAuthenticationPair);
|
Mockito.lenient().when(userAuthenticator.authenticate("test", "", 1L, new HashMap<>())).thenReturn(successAuthenticationPair);
|
||||||
|
Mockito.when(userAuthenticator.getName()).thenReturn("test");
|
||||||
|
|
||||||
//Test for incorrect password. authentication should fail
|
//Test for incorrect password. authentication should fail
|
||||||
UserAccount userAccount = accountManagerImpl.authenticateUser("test", "fail", 1L, InetAddress.getByName("127.0.0.1"), new HashMap<>());
|
UserAccount userAccount = accountManagerImpl.authenticateUser("test", "fail", 1L, InetAddress.getByName("127.0.0.1"), new HashMap<>());
|
||||||
|
|||||||
@ -1,188 +0,0 @@
|
|||||||
// 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.sample;
|
|
||||||
|
|
||||||
import java.io.FileInputStream;
|
|
||||||
import java.net.URLEncoder;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Properties;
|
|
||||||
import java.util.StringTokenizer;
|
|
||||||
|
|
||||||
import javax.crypto.Mac;
|
|
||||||
import javax.crypto.spec.SecretKeySpec;
|
|
||||||
|
|
||||||
import org.apache.commons.codec.binary.Base64;
|
|
||||||
import org.apache.commons.httpclient.HttpClient;
|
|
||||||
import org.apache.commons.httpclient.HttpMethod;
|
|
||||||
import org.apache.commons.httpclient.methods.GetMethod;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*
|
|
||||||
*
|
|
||||||
*
|
|
||||||
*
|
|
||||||
*
|
|
||||||
*
|
|
||||||
*
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sample CloudStack Management User API Executor.
|
|
||||||
*
|
|
||||||
* Prerequisites: - Edit usercloud.properties to include your host, apiUrl, apiKey, and secretKey - Use ./executeUserAPI.sh to
|
|
||||||
* execute this test class
|
|
||||||
*
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public class UserCloudAPIExecutor {
|
|
||||||
public static void main(String[] args) {
|
|
||||||
// Host
|
|
||||||
String host = null;
|
|
||||||
|
|
||||||
// Fully qualified URL with http(s)://host:port
|
|
||||||
String apiUrl = null;
|
|
||||||
|
|
||||||
// ApiKey and secretKey as given by your CloudStack vendor
|
|
||||||
String apiKey = null;
|
|
||||||
String secretKey = null;
|
|
||||||
|
|
||||||
try {
|
|
||||||
Properties prop = new Properties();
|
|
||||||
prop.load(new FileInputStream("usercloud.properties"));
|
|
||||||
|
|
||||||
// host
|
|
||||||
host = prop.getProperty("host");
|
|
||||||
if (host == null) {
|
|
||||||
System.out.println("Please specify a valid host in the format of http(s)://:/client/api in your usercloud.properties file.");
|
|
||||||
}
|
|
||||||
|
|
||||||
// apiUrl
|
|
||||||
apiUrl = prop.getProperty("apiUrl");
|
|
||||||
if (apiUrl == null) {
|
|
||||||
System.out.println("Please specify a valid API URL in the format of command=¶m1=¶m2=... in your usercloud.properties file.");
|
|
||||||
}
|
|
||||||
|
|
||||||
// apiKey
|
|
||||||
apiKey = prop.getProperty("apiKey");
|
|
||||||
if (apiKey == null) {
|
|
||||||
System.out.println("Please specify your API Key as provided by your CloudStack vendor in your usercloud.properties file.");
|
|
||||||
}
|
|
||||||
|
|
||||||
// secretKey
|
|
||||||
secretKey = prop.getProperty("secretKey");
|
|
||||||
if (secretKey == null) {
|
|
||||||
System.out.println("Please specify your secret Key as provided by your CloudStack vendor in your usercloud.properties file.");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (apiUrl == null || apiKey == null || secretKey == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
System.out.println("Constructing API call to host = '" + host + "' with API command = '" + apiUrl + "' using apiKey = '" + apiKey + "' and secretKey = '" +
|
|
||||||
secretKey + "'");
|
|
||||||
|
|
||||||
// Step 1: Make sure your APIKey is URL encoded
|
|
||||||
String encodedApiKey = URLEncoder.encode(apiKey, "UTF-8");
|
|
||||||
|
|
||||||
// Step 2: URL encode each parameter value, then sort the parameters and apiKey in
|
|
||||||
// alphabetical order, and then toLowerCase all the parameters, parameter values and apiKey.
|
|
||||||
// Please note that if any parameters with a '&' as a value will cause this test client to fail since we are using
|
|
||||||
// '&' to delimit
|
|
||||||
// the string
|
|
||||||
List<String> sortedParams = new ArrayList<String>();
|
|
||||||
sortedParams.add("apikey=" + encodedApiKey.toLowerCase());
|
|
||||||
StringTokenizer st = new StringTokenizer(apiUrl, "&");
|
|
||||||
String url = null;
|
|
||||||
boolean first = true;
|
|
||||||
while (st.hasMoreTokens()) {
|
|
||||||
String paramValue = st.nextToken();
|
|
||||||
String param = paramValue.substring(0, paramValue.indexOf("="));
|
|
||||||
String value = URLEncoder.encode(paramValue.substring(paramValue.indexOf("=") + 1, paramValue.length()), "UTF-8");
|
|
||||||
if (first) {
|
|
||||||
url = param + "=" + value;
|
|
||||||
first = false;
|
|
||||||
} else {
|
|
||||||
url = url + "&" + param + "=" + value;
|
|
||||||
}
|
|
||||||
sortedParams.add(param.toLowerCase() + "=" + value.toLowerCase());
|
|
||||||
}
|
|
||||||
Collections.sort(sortedParams);
|
|
||||||
|
|
||||||
System.out.println("Sorted Parameters: " + sortedParams);
|
|
||||||
|
|
||||||
// Step 3: Construct the sorted URL and sign and URL encode the sorted URL with your secret key
|
|
||||||
String sortedUrl = null;
|
|
||||||
first = true;
|
|
||||||
for (String param : sortedParams) {
|
|
||||||
if (first) {
|
|
||||||
sortedUrl = param;
|
|
||||||
first = false;
|
|
||||||
} else {
|
|
||||||
sortedUrl = sortedUrl + "&" + param;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
System.out.println("sorted URL : " + sortedUrl);
|
|
||||||
String encodedSignature = signRequest(sortedUrl, secretKey);
|
|
||||||
|
|
||||||
// Step 4: Construct the final URL we want to send to the CloudStack Management Server
|
|
||||||
// Final result should look like:
|
|
||||||
// http(s)://://client/api?&apiKey=&signature=
|
|
||||||
String finalUrl = host + "?" + url + "&apiKey=" + apiKey + "&signature=" + encodedSignature;
|
|
||||||
System.out.println("final URL : " + finalUrl);
|
|
||||||
|
|
||||||
// Step 5: Perform a HTTP GET on this URL to execute the command
|
|
||||||
HttpClient client = new HttpClient();
|
|
||||||
HttpMethod method = new GetMethod(finalUrl);
|
|
||||||
int responseCode = client.executeMethod(method);
|
|
||||||
if (responseCode == 200) {
|
|
||||||
// SUCCESS!
|
|
||||||
System.out.println("Successfully executed command");
|
|
||||||
} else {
|
|
||||||
// FAILED!
|
|
||||||
System.out.println("Unable to execute command with response code: " + responseCode);
|
|
||||||
}
|
|
||||||
|
|
||||||
} catch (Throwable t) {
|
|
||||||
System.out.println(t);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 1. Signs a string with a secret key using SHA-1 2. Base64 encode the result 3. URL encode the final result
|
|
||||||
*
|
|
||||||
* @param request
|
|
||||||
* @param key
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public static String signRequest(String request, String key) {
|
|
||||||
try {
|
|
||||||
Mac mac = Mac.getInstance("HmacSHA1");
|
|
||||||
SecretKeySpec keySpec = new SecretKeySpec(key.getBytes(), "HmacSHA1");
|
|
||||||
mac.init(keySpec);
|
|
||||||
mac.update(request.getBytes());
|
|
||||||
byte[] encryptedBytes = mac.doFinal();
|
|
||||||
return URLEncoder.encode(Base64.encodeBase64String(encryptedBytes), "UTF-8");
|
|
||||||
} catch (Exception ex) {
|
|
||||||
System.out.println(ex);
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,124 +0,0 @@
|
|||||||
// 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.test.longrun;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Random;
|
|
||||||
|
|
||||||
import org.apache.logging.log4j.Logger;
|
|
||||||
import org.apache.logging.log4j.LogManager;
|
|
||||||
|
|
||||||
public class BuildGuestNetwork {
|
|
||||||
|
|
||||||
protected Logger logger = LogManager.getLogger(getClass());
|
|
||||||
private static final int ApiPort = 8096;
|
|
||||||
private static final int DeveloperPort = 8080;
|
|
||||||
private static final String ApiUrl = "/client/api";
|
|
||||||
private static int numVM = 1;
|
|
||||||
private static long zoneId = -1L;
|
|
||||||
private static long templateId = 3;
|
|
||||||
private static long serviceOfferingId = 1;
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
|
||||||
|
|
||||||
List<String> argsList = Arrays.asList(args);
|
|
||||||
Iterator<String> iter = argsList.iterator();
|
|
||||||
String host = "http://localhost";
|
|
||||||
int numThreads = 1;
|
|
||||||
|
|
||||||
while (iter.hasNext()) {
|
|
||||||
String arg = iter.next();
|
|
||||||
if (arg.equals("-h")) {
|
|
||||||
host = "http://" + iter.next();
|
|
||||||
}
|
|
||||||
if (arg.equals("-t")) {
|
|
||||||
numThreads = Integer.parseInt(iter.next());
|
|
||||||
}
|
|
||||||
if (arg.equals("-n")) {
|
|
||||||
numVM = Integer.parseInt(iter.next());
|
|
||||||
}
|
|
||||||
if (arg.equals("-z")) {
|
|
||||||
zoneId = Integer.parseInt(iter.next());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (arg.equals("-e")) {
|
|
||||||
templateId = Integer.parseInt(iter.next());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (arg.equals("-s")) {
|
|
||||||
serviceOfferingId = Integer.parseInt(iter.next());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
final String server = host + ":" + ApiPort + "/";
|
|
||||||
final String developerServer = host + ":" + DeveloperPort + ApiUrl;
|
|
||||||
logger.info("Starting test in " + numThreads + " thread(s). Each thread is launching " + numVM + " VMs");
|
|
||||||
|
|
||||||
for (int i = 0; i < numThreads; i++) {
|
|
||||||
new Thread(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
try {
|
|
||||||
|
|
||||||
String username = null;
|
|
||||||
String singlePrivateIp = null;
|
|
||||||
Random ran = new Random();
|
|
||||||
username = Math.abs(ran.nextInt()) + "-user";
|
|
||||||
|
|
||||||
//Create User
|
|
||||||
User myUser = new User(username, username, server, developerServer);
|
|
||||||
try {
|
|
||||||
myUser.launchUser();
|
|
||||||
myUser.registerUser();
|
|
||||||
} catch (Exception e) {
|
|
||||||
logger.warn("Error code: ", e);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (myUser.getUserId() != null) {
|
|
||||||
logger.info("User " + myUser.getUserName() + " was created successfully, starting VM creation");
|
|
||||||
//create VMs for the user
|
|
||||||
for (int i = 0; i < numVM; i++) {
|
|
||||||
//Create a new VM, add it to the list of user's VMs
|
|
||||||
VirtualMachine myVM = new VirtualMachine(myUser.getUserId());
|
|
||||||
myVM.deployVM(zoneId, serviceOfferingId, templateId, myUser.getDeveloperServer(), myUser.getApiKey(), myUser.getSecretKey());
|
|
||||||
myUser.getVirtualMachines().add(myVM);
|
|
||||||
singlePrivateIp = myVM.getPrivateIp();
|
|
||||||
|
|
||||||
if (singlePrivateIp != null) {
|
|
||||||
logger.info("VM with private Ip " + singlePrivateIp + " was successfully created");
|
|
||||||
} else {
|
|
||||||
logger.info("Problems with VM creation for a user" + myUser.getUserName());
|
|
||||||
logger.info("Deployment failed");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
logger.info("Deployment done..." + numVM + " VMs were created.");
|
|
||||||
}
|
|
||||||
|
|
||||||
} catch (Exception e) {
|
|
||||||
logger.error(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}).start();
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,108 +0,0 @@
|
|||||||
// 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.test.longrun;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Random;
|
|
||||||
|
|
||||||
import org.apache.logging.log4j.Logger;
|
|
||||||
import org.apache.logging.log4j.LogManager;
|
|
||||||
import org.apache.log4j.NDC;
|
|
||||||
|
|
||||||
import com.trilead.ssh2.Connection;
|
|
||||||
import com.trilead.ssh2.Session;
|
|
||||||
|
|
||||||
public class GuestNetwork implements Runnable {
|
|
||||||
protected Logger logger = LogManager.getLogger(getClass());
|
|
||||||
|
|
||||||
private String publicIp;
|
|
||||||
private ArrayList<VirtualMachine> virtualMachines;
|
|
||||||
private int retryNum;
|
|
||||||
|
|
||||||
public GuestNetwork(String publicIp, int retryNum) {
|
|
||||||
this.publicIp = publicIp;
|
|
||||||
this.retryNum = retryNum;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ArrayList<VirtualMachine> getVirtualMachines() {
|
|
||||||
return virtualMachines;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setVirtualMachines(ArrayList<VirtualMachine> virtualMachines) {
|
|
||||||
this.virtualMachines = virtualMachines;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
NDC.push("Following thread has started" + Thread.currentThread().getName());
|
|
||||||
int retry = 0;
|
|
||||||
|
|
||||||
//Start copying files between machines in the network
|
|
||||||
logger.info("The size of the array is " + this.virtualMachines.size());
|
|
||||||
while (true) {
|
|
||||||
try {
|
|
||||||
if (retry > 0) {
|
|
||||||
logger.info("Retry attempt : " + retry + " ...sleeping 120 seconds before next attempt");
|
|
||||||
Thread.sleep(120000);
|
|
||||||
}
|
|
||||||
for (VirtualMachine vm : this.virtualMachines) {
|
|
||||||
|
|
||||||
logger.info("Attempting to SSH into linux host " + this.publicIp + " with retry attempt: " + retry);
|
|
||||||
Connection conn = new Connection(this.publicIp);
|
|
||||||
conn.connect(null, 600000, 600000);
|
|
||||||
|
|
||||||
logger.info("SSHed successfully into linux host " + this.publicIp);
|
|
||||||
|
|
||||||
boolean isAuthenticated = conn.authenticateWithPassword("root", "password");
|
|
||||||
|
|
||||||
if (isAuthenticated == false) {
|
|
||||||
logger.info("Authentication failed");
|
|
||||||
}
|
|
||||||
//execute copy command
|
|
||||||
Session sess = conn.openSession();
|
|
||||||
String fileName;
|
|
||||||
Random ran = new Random();
|
|
||||||
fileName = Math.abs(ran.nextInt()) + "-file";
|
|
||||||
String copyCommand = new String("./scpScript " + vm.getPrivateIp() + " " + fileName);
|
|
||||||
logger.info("Executing " + copyCommand);
|
|
||||||
sess.execCommand(copyCommand);
|
|
||||||
Thread.sleep(120000);
|
|
||||||
sess.close();
|
|
||||||
|
|
||||||
//execute wget command
|
|
||||||
sess = conn.openSession();
|
|
||||||
String downloadCommand =
|
|
||||||
new String("wget http://172.16.0.220/scripts/checkDiskSpace.sh; chmod +x *sh; ./checkDiskSpace.sh; rm -rf checkDiskSpace.sh");
|
|
||||||
logger.info("Executing " + downloadCommand);
|
|
||||||
sess.execCommand(downloadCommand);
|
|
||||||
Thread.sleep(120000);
|
|
||||||
sess.close();
|
|
||||||
|
|
||||||
//close the connection
|
|
||||||
conn.close();
|
|
||||||
}
|
|
||||||
} catch (Exception ex) {
|
|
||||||
logger.error(ex);
|
|
||||||
retry++;
|
|
||||||
if (retry == retryNum) {
|
|
||||||
logger.info("Performance Guest Network test failed with error " + ex.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,191 +0,0 @@
|
|||||||
// 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.test.longrun;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.net.URLEncoder;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Random;
|
|
||||||
|
|
||||||
import org.apache.commons.httpclient.HttpClient;
|
|
||||||
import org.apache.commons.httpclient.HttpMethod;
|
|
||||||
import org.apache.commons.httpclient.methods.GetMethod;
|
|
||||||
import org.apache.logging.log4j.Logger;
|
|
||||||
import org.apache.logging.log4j.LogManager;
|
|
||||||
|
|
||||||
import com.cloud.test.stress.TestClientWithAPI;
|
|
||||||
|
|
||||||
public class PerformanceWithAPI {
|
|
||||||
|
|
||||||
protected Logger logger = LogManager.getLogger(getClass());
|
|
||||||
private static final int Retry = 10;
|
|
||||||
private static final int ApiPort = 8096;
|
|
||||||
private static int s_numVM = 2;
|
|
||||||
private static final long ZoneId = -1L;
|
|
||||||
private static final long TemplateId = 3;
|
|
||||||
private static final long ServiceOfferingId = 1;
|
|
||||||
private static final String ApiUrl = "/client/api";
|
|
||||||
private static final int DeveloperPort = 8080;
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
|
||||||
|
|
||||||
List<String> argsList = Arrays.asList(args);
|
|
||||||
Iterator<String> iter = argsList.iterator();
|
|
||||||
String host = "http://localhost";
|
|
||||||
int numThreads = 1;
|
|
||||||
|
|
||||||
while (iter.hasNext()) {
|
|
||||||
String arg = iter.next();
|
|
||||||
if (arg.equals("-h")) {
|
|
||||||
host = "http://" + iter.next();
|
|
||||||
}
|
|
||||||
if (arg.equals("-t")) {
|
|
||||||
numThreads = Integer.parseInt(iter.next());
|
|
||||||
}
|
|
||||||
if (arg.equals("-n")) {
|
|
||||||
s_numVM = Integer.parseInt(iter.next());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
final String server = host + ":" + ApiPort + "/";
|
|
||||||
final String developerServer = host + ":" + DeveloperPort + ApiUrl;
|
|
||||||
|
|
||||||
logger.info("Starting test in " + numThreads + " thread(s). Each thread is launching " + s_numVM + " VMs");
|
|
||||||
|
|
||||||
for (int i = 0; i < numThreads; i++) {
|
|
||||||
new Thread(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
try {
|
|
||||||
|
|
||||||
String username = null;
|
|
||||||
String singlePrivateIp = null;
|
|
||||||
String singlePublicIp = null;
|
|
||||||
Random ran = new Random();
|
|
||||||
username = Math.abs(ran.nextInt()) + "-user";
|
|
||||||
|
|
||||||
//Create User
|
|
||||||
User myUser = new User(username, username, server, developerServer);
|
|
||||||
try {
|
|
||||||
myUser.launchUser();
|
|
||||||
myUser.registerUser();
|
|
||||||
} catch (Exception e) {
|
|
||||||
logger.warn("Error code: ", e);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (myUser.getUserId() != null) {
|
|
||||||
logger.info("User " + myUser.getUserName() + " was created successfully, starting VM creation");
|
|
||||||
//create VMs for the user
|
|
||||||
for (int i = 0; i < s_numVM; i++) {
|
|
||||||
//Create a new VM, add it to the list of user's VMs
|
|
||||||
VirtualMachine myVM = new VirtualMachine(myUser.getUserId());
|
|
||||||
myVM.deployVM(ZoneId, ServiceOfferingId, TemplateId, myUser.getDeveloperServer(), myUser.getApiKey(), myUser.getSecretKey());
|
|
||||||
myUser.getVirtualMachines().add(myVM);
|
|
||||||
singlePrivateIp = myVM.getPrivateIp();
|
|
||||||
|
|
||||||
if (singlePrivateIp != null) {
|
|
||||||
logger.info("VM with private Ip " + singlePrivateIp + " was successfully created");
|
|
||||||
} else {
|
|
||||||
logger.info("Problems with VM creation for a user" + myUser.getUserName());
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
//get public IP address for the User
|
|
||||||
myUser.retrievePublicIp(ZoneId);
|
|
||||||
singlePublicIp = myUser.getPublicIp().get(myUser.getPublicIp().size() - 1);
|
|
||||||
if (singlePublicIp != null) {
|
|
||||||
logger.info("Successfully got public Ip " + singlePublicIp + " for user " + myUser.getUserName());
|
|
||||||
} else {
|
|
||||||
logger.info("Problems with getting public Ip address for user" + myUser.getUserName());
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
//create ForwardProxy rules for user's VMs
|
|
||||||
int responseCode = CreateForwardingRule(myUser, singlePrivateIp, singlePublicIp, "22", "22");
|
|
||||||
if (responseCode == 500)
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
logger.info("Deployment successful..." + s_numVM + " VMs were created. Waiting for 5 min before performance test");
|
|
||||||
Thread.sleep(300000L); // Wait
|
|
||||||
|
|
||||||
//Start performance test for the user
|
|
||||||
logger.info("Starting performance test for Guest network that has " + myUser.getPublicIp().size() + " public IP addresses");
|
|
||||||
for (int j = 0; j < myUser.getPublicIp().size(); j++) {
|
|
||||||
logger.info("Starting test for user which has " + myUser.getVirtualMachines().size() + " vms. Public IP for the user is " +
|
|
||||||
myUser.getPublicIp().get(j) + " , number of retries is " + Retry + " , private IP address of the machine is" +
|
|
||||||
myUser.getVirtualMachines().get(j).getPrivateIp());
|
|
||||||
GuestNetwork myNetwork = new GuestNetwork(myUser.getPublicIp().get(j), Retry);
|
|
||||||
myNetwork.setVirtualMachines(myUser.getVirtualMachines());
|
|
||||||
new Thread(myNetwork).start();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
logger.error(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}).start();
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static int CreateForwardingRule(User myUser, String privateIp, String publicIp, String publicPort, String privatePort) throws IOException {
|
|
||||||
String encodedPrivateIp = URLEncoder.encode("" + privateIp, "UTF-8");
|
|
||||||
String encodedPublicIp = URLEncoder.encode("" + publicIp, "UTF-8");
|
|
||||||
String encodedPrivatePort = URLEncoder.encode("" + privatePort, "UTF-8");
|
|
||||||
String encodedPublicPort = URLEncoder.encode("" + publicPort, "UTF-8");
|
|
||||||
String encodedApiKey = URLEncoder.encode(myUser.getApiKey(), "UTF-8");
|
|
||||||
int responseCode = 500;
|
|
||||||
|
|
||||||
String requestToSign =
|
|
||||||
"apiKey=" + encodedApiKey + "&command=createOrUpdateIpForwardingRule&privateIp=" + encodedPrivateIp + "&privatePort=" + encodedPrivatePort +
|
|
||||||
"&protocol=tcp&publicIp=" + encodedPublicIp + "&publicPort=" + encodedPublicPort;
|
|
||||||
|
|
||||||
requestToSign = requestToSign.toLowerCase();
|
|
||||||
logger.info("Request to sign is " + requestToSign);
|
|
||||||
|
|
||||||
String signature = TestClientWithAPI.signRequest(requestToSign, myUser.getSecretKey());
|
|
||||||
String encodedSignature = URLEncoder.encode(signature, "UTF-8");
|
|
||||||
|
|
||||||
String url =
|
|
||||||
myUser.getDeveloperServer() + "?command=createOrUpdateIpForwardingRule" + "&publicIp=" + encodedPublicIp + "&publicPort=" + encodedPublicPort +
|
|
||||||
"&privateIp=" + encodedPrivateIp + "&privatePort=" + encodedPrivatePort + "&protocol=tcp&apiKey=" + encodedApiKey + "&signature=" + encodedSignature;
|
|
||||||
|
|
||||||
logger.info("Trying to create IP forwarding rule: " + url);
|
|
||||||
HttpClient client = new HttpClient();
|
|
||||||
HttpMethod method = new GetMethod(url);
|
|
||||||
responseCode = client.executeMethod(method);
|
|
||||||
logger.info("create ip forwarding rule response code: " + responseCode);
|
|
||||||
if (responseCode == 200) {
|
|
||||||
logger.info("The rule is created successfully");
|
|
||||||
} else if (responseCode == 500) {
|
|
||||||
InputStream is = method.getResponseBodyAsStream();
|
|
||||||
Map<String, String> errorInfo = TestClientWithAPI.getSingleValueFromXML(is, new String[] {"errorCode", "description"});
|
|
||||||
logger.error("create ip forwarding rule (linux) test failed with errorCode: " + errorInfo.get("errorCode") + " and description: " +
|
|
||||||
errorInfo.get("description"));
|
|
||||||
} else {
|
|
||||||
logger.error("internal error processing request: " + method.getStatusText());
|
|
||||||
}
|
|
||||||
return responseCode;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,203 +0,0 @@
|
|||||||
// 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.test.longrun;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.net.URLEncoder;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import org.apache.commons.httpclient.HttpClient;
|
|
||||||
import org.apache.commons.httpclient.HttpException;
|
|
||||||
import org.apache.commons.httpclient.HttpMethod;
|
|
||||||
import org.apache.commons.httpclient.methods.GetMethod;
|
|
||||||
import org.apache.logging.log4j.Logger;
|
|
||||||
import org.apache.logging.log4j.LogManager;
|
|
||||||
|
|
||||||
import com.cloud.test.stress.TestClientWithAPI;
|
|
||||||
|
|
||||||
public class User {
|
|
||||||
protected Logger logger = LogManager.getLogger(getClass());
|
|
||||||
|
|
||||||
private ArrayList<VirtualMachine> virtualMachines;
|
|
||||||
private ArrayList<String> publicIp;
|
|
||||||
private String server;
|
|
||||||
private String developerServer;
|
|
||||||
private String userName;
|
|
||||||
private String userId;
|
|
||||||
private String apiKey;
|
|
||||||
private String secretKey;
|
|
||||||
private String password;
|
|
||||||
private String encryptedPassword;
|
|
||||||
|
|
||||||
public User(String userName, String password, String server, String developerServer) {
|
|
||||||
this.server = server;
|
|
||||||
this.developerServer = developerServer;
|
|
||||||
this.userName = userName;
|
|
||||||
this.password = password;
|
|
||||||
this.virtualMachines = new ArrayList<VirtualMachine>();
|
|
||||||
this.publicIp = new ArrayList<String>();
|
|
||||||
}
|
|
||||||
|
|
||||||
public ArrayList<VirtualMachine> getVirtualMachines() {
|
|
||||||
return virtualMachines;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setVirtualMachines(ArrayList<VirtualMachine> virtualMachines) {
|
|
||||||
this.virtualMachines = virtualMachines;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getUserId() {
|
|
||||||
return userId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setUserId(String userId) {
|
|
||||||
this.userId = userId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ArrayList<String> getPublicIp() {
|
|
||||||
return publicIp;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPublicIp(ArrayList<String> publicIp) {
|
|
||||||
this.publicIp = publicIp;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getServer() {
|
|
||||||
return server;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setServer(String server) {
|
|
||||||
this.server = server;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getUserName() {
|
|
||||||
return userName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setUserName(String userName) {
|
|
||||||
this.userName = userName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getApiKey() {
|
|
||||||
return apiKey;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setApiKey(String apiKey) {
|
|
||||||
this.apiKey = apiKey;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getPassword() {
|
|
||||||
return password;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPassword(String password) {
|
|
||||||
this.password = password;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getSecretKey() {
|
|
||||||
return secretKey;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setSecretKey(String secretKey) {
|
|
||||||
this.secretKey = secretKey;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getDeveloperServer() {
|
|
||||||
return developerServer;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setDeveloperServer(String developerServer) {
|
|
||||||
this.developerServer = developerServer;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void launchUser() throws IOException {
|
|
||||||
String encodedUsername = URLEncoder.encode(this.getUserName(), "UTF-8");
|
|
||||||
this.encryptedPassword = TestClientWithAPI.createMD5Password(this.getPassword());
|
|
||||||
String encodedPassword = URLEncoder.encode(this.encryptedPassword, "UTF-8");
|
|
||||||
String url =
|
|
||||||
this.server + "?command=createUser&username=" + encodedUsername + "&password=" + encodedPassword +
|
|
||||||
"&firstname=Test&lastname=Test&email=alena@vmops.com&domainId=1";
|
|
||||||
String userIdStr = null;
|
|
||||||
HttpClient client = new HttpClient();
|
|
||||||
HttpMethod method = new GetMethod(url);
|
|
||||||
int responseCode = client.executeMethod(method);
|
|
||||||
|
|
||||||
if (responseCode == 200) {
|
|
||||||
InputStream is = method.getResponseBodyAsStream();
|
|
||||||
Map<String, String> userIdValues = TestClientWithAPI.getSingleValueFromXML(is, new String[] {"id"});
|
|
||||||
userIdStr = userIdValues.get("id");
|
|
||||||
if ((userIdStr != null) && (Long.parseLong(userIdStr) != -1)) {
|
|
||||||
this.setUserId(userIdStr);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void retrievePublicIp(long zoneId) throws IOException {
|
|
||||||
|
|
||||||
String encodedApiKey = URLEncoder.encode(this.apiKey, "UTF-8");
|
|
||||||
String encodedZoneId = URLEncoder.encode("" + zoneId, "UTF-8");
|
|
||||||
String requestToSign = "apiKey=" + encodedApiKey + "&command=associateIpAddress" + "&zoneId=" + encodedZoneId;
|
|
||||||
requestToSign = requestToSign.toLowerCase();
|
|
||||||
String signature = TestClientWithAPI.signRequest(requestToSign, this.secretKey);
|
|
||||||
String encodedSignature = URLEncoder.encode(signature, "UTF-8");
|
|
||||||
|
|
||||||
String url = this.developerServer + "?command=associateIpAddress" + "&apiKey=" + encodedApiKey + "&zoneId=" + encodedZoneId + "&signature=" + encodedSignature;
|
|
||||||
|
|
||||||
HttpClient client = new HttpClient();
|
|
||||||
HttpMethod method = new GetMethod(url);
|
|
||||||
int responseCode = client.executeMethod(method);
|
|
||||||
if (responseCode == 200) {
|
|
||||||
InputStream is = method.getResponseBodyAsStream();
|
|
||||||
Map<String, String> values = TestClientWithAPI.getSingleValueFromXML(is, new String[] {"ipaddress"});
|
|
||||||
this.getPublicIp().add(values.get("ipaddress"));
|
|
||||||
logger.info("Ip address is " + values.get("ipaddress"));
|
|
||||||
} else if (responseCode == 500) {
|
|
||||||
InputStream is = method.getResponseBodyAsStream();
|
|
||||||
Map<String, String> errorInfo = TestClientWithAPI.getSingleValueFromXML(is, new String[] {"errorcode", "description"});
|
|
||||||
logger.error("associate ip test failed with errorCode: " + errorInfo.get("errorCode") + " and description: " + errorInfo.get("description"));
|
|
||||||
} else {
|
|
||||||
logger.error("internal error processing request: " + method.getStatusText());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public void registerUser() throws HttpException, IOException {
|
|
||||||
|
|
||||||
String encodedUsername = URLEncoder.encode(this.userName, "UTF-8");
|
|
||||||
String encodedPassword = URLEncoder.encode(this.password, "UTF-8");
|
|
||||||
String url = server + "?command=register&username=" + encodedUsername + "&domainid=1";
|
|
||||||
logger.info("registering: " + this.userName + " with url " + url);
|
|
||||||
HttpClient client = new HttpClient();
|
|
||||||
HttpMethod method = new GetMethod(url);
|
|
||||||
int responseCode = client.executeMethod(method);
|
|
||||||
if (responseCode == 200) {
|
|
||||||
InputStream is = method.getResponseBodyAsStream();
|
|
||||||
Map<String, String> requestKeyValues = TestClientWithAPI.getSingleValueFromXML(is, new String[] {"apikey", "secretkey"});
|
|
||||||
this.setApiKey(requestKeyValues.get("apikey"));
|
|
||||||
this.setSecretKey(requestKeyValues.get("secretkey"));
|
|
||||||
} else if (responseCode == 500) {
|
|
||||||
InputStream is = method.getResponseBodyAsStream();
|
|
||||||
Map<String, String> errorInfo = TestClientWithAPI.getSingleValueFromXML(is, new String[] {"errorcode", "description"});
|
|
||||||
logger.error("registration failed with errorCode: " + errorInfo.get("errorCode") + " and description: " + errorInfo.get("description"));
|
|
||||||
} else {
|
|
||||||
logger.error("internal error processing request: " + method.getStatusText());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,96 +0,0 @@
|
|||||||
// 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.test.longrun;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.net.URLEncoder;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import org.apache.commons.httpclient.HttpClient;
|
|
||||||
import org.apache.commons.httpclient.HttpMethod;
|
|
||||||
import org.apache.commons.httpclient.methods.GetMethod;
|
|
||||||
import org.apache.logging.log4j.Logger;
|
|
||||||
import org.apache.logging.log4j.LogManager;
|
|
||||||
|
|
||||||
import com.cloud.test.stress.TestClientWithAPI;
|
|
||||||
|
|
||||||
public class VirtualMachine {
|
|
||||||
protected Logger logger = LogManager.getLogger(getClass());
|
|
||||||
|
|
||||||
private String privateIp;
|
|
||||||
private String userId;
|
|
||||||
|
|
||||||
public VirtualMachine(String userId) {
|
|
||||||
this.userId = userId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getPrivateIp() {
|
|
||||||
return privateIp;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPrivateIp(String privateIp) {
|
|
||||||
this.privateIp = privateIp;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getUserId() {
|
|
||||||
return userId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setUserId(String userId) {
|
|
||||||
this.userId = userId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void deployVM(long zoneId, long serviceOfferingId, long templateId, String server, String apiKey, String secretKey) throws IOException {
|
|
||||||
|
|
||||||
String encodedZoneId = URLEncoder.encode("" + zoneId, "UTF-8");
|
|
||||||
String encodedServiceOfferingId = URLEncoder.encode("" + serviceOfferingId, "UTF-8");
|
|
||||||
String encodedTemplateId = URLEncoder.encode("" + templateId, "UTF-8");
|
|
||||||
String encodedApiKey = URLEncoder.encode(apiKey, "UTF-8");
|
|
||||||
String requestToSign =
|
|
||||||
"apiKey=" + encodedApiKey + "&command=deployVirtualMachine&serviceOfferingId=" + encodedServiceOfferingId + "&templateId=" + encodedTemplateId + "&zoneId=" +
|
|
||||||
encodedZoneId;
|
|
||||||
|
|
||||||
requestToSign = requestToSign.toLowerCase();
|
|
||||||
String signature = TestClientWithAPI.signRequest(requestToSign, secretKey);
|
|
||||||
String encodedSignature = URLEncoder.encode(signature, "UTF-8");
|
|
||||||
String url =
|
|
||||||
server + "?command=deployVirtualMachine" + "&zoneId=" + encodedZoneId + "&serviceOfferingId=" + encodedServiceOfferingId + "&templateId=" +
|
|
||||||
encodedTemplateId + "&apiKey=" + encodedApiKey + "&signature=" + encodedSignature;
|
|
||||||
|
|
||||||
logger.info("Sending this request to deploy a VM: " + url);
|
|
||||||
HttpClient client = new HttpClient();
|
|
||||||
HttpMethod method = new GetMethod(url);
|
|
||||||
int responseCode = client.executeMethod(method);
|
|
||||||
logger.info("deploy linux vm response code: " + responseCode);
|
|
||||||
if (responseCode == 200) {
|
|
||||||
InputStream is = method.getResponseBodyAsStream();
|
|
||||||
Map<String, String> values = TestClientWithAPI.getSingleValueFromXML(is, new String[] {"id", "ipaddress"});
|
|
||||||
long linuxVMId = Long.parseLong(values.get("id"));
|
|
||||||
logger.info("got linux virtual machine id: " + linuxVMId);
|
|
||||||
this.setPrivateIp(values.get("ipaddress"));
|
|
||||||
|
|
||||||
} else if (responseCode == 500) {
|
|
||||||
InputStream is = method.getResponseBodyAsStream();
|
|
||||||
Map<String, String> errorInfo = TestClientWithAPI.getSingleValueFromXML(is, new String[] {"errorcode", "description"});
|
|
||||||
logger.error("deploy linux vm test failed with errorCode: " + errorInfo.get("errorCode") + " and description: " + errorInfo.get("description"));
|
|
||||||
} else {
|
|
||||||
logger.error("internal error processing request: " + method.getStatusText());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,849 +0,0 @@
|
|||||||
// 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.test.regression;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileInputStream;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.net.URLEncoder;
|
|
||||||
import java.sql.Connection;
|
|
||||||
import java.sql.ResultSet;
|
|
||||||
import java.sql.Statement;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Enumeration;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Properties;
|
|
||||||
import java.util.Random;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.TreeMap;
|
|
||||||
|
|
||||||
import javax.xml.parsers.DocumentBuilder;
|
|
||||||
import javax.xml.parsers.DocumentBuilderFactory;
|
|
||||||
|
|
||||||
import org.apache.commons.httpclient.HttpClient;
|
|
||||||
import org.apache.commons.httpclient.HttpMethod;
|
|
||||||
import org.apache.commons.httpclient.methods.GetMethod;
|
|
||||||
import org.apache.logging.log4j.Logger;
|
|
||||||
import org.apache.logging.log4j.LogManager;
|
|
||||||
import org.w3c.dom.Document;
|
|
||||||
import org.w3c.dom.Element;
|
|
||||||
import org.w3c.dom.Node;
|
|
||||||
import org.w3c.dom.NodeList;
|
|
||||||
|
|
||||||
import com.cloud.test.utils.UtilsForTest;
|
|
||||||
|
|
||||||
public class ApiCommand {
|
|
||||||
protected Logger logger = LogManager.getLogger(getClass());
|
|
||||||
|
|
||||||
public static enum CommandType {
|
|
||||||
HTTP, MYSQL, SCRIPT;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static enum ResponseType {
|
|
||||||
ERROR, EMPTY;
|
|
||||||
}
|
|
||||||
|
|
||||||
private Element xmlCommand;
|
|
||||||
private String commandName;
|
|
||||||
private String testCaseInfo;
|
|
||||||
private boolean isUserCommand;
|
|
||||||
private boolean isAsync = false;
|
|
||||||
private CommandType commandType;
|
|
||||||
private ResponseType responseType;
|
|
||||||
|
|
||||||
private TreeMap<String, String> urlParam;
|
|
||||||
private HashMap<String, String> verifyParam = new HashMap<String, String>();;
|
|
||||||
private HashMap<String, String> setParam = new HashMap<String, String>();;
|
|
||||||
private int responseCode;
|
|
||||||
private Element responseBody;
|
|
||||||
|
|
||||||
private String command;
|
|
||||||
private String host;
|
|
||||||
private boolean list;
|
|
||||||
private Element listName;
|
|
||||||
private Element listId;
|
|
||||||
private boolean required = false;
|
|
||||||
private ResultSet result;
|
|
||||||
|
|
||||||
public ApiCommand(Element fstElmnt, HashMap<String, String> param, HashMap<String, String> commands) {
|
|
||||||
this.setXmlCommand(fstElmnt);
|
|
||||||
this.setCommandName();
|
|
||||||
this.setResponseType();
|
|
||||||
this.setUserCommand();
|
|
||||||
this.setCommandType();
|
|
||||||
this.setTestCaseInfo();
|
|
||||||
this.setUrlParam(param);
|
|
||||||
this.setVerifyParam(param);
|
|
||||||
this.setHost("http://" + param.get("hostip"));
|
|
||||||
this.setCommand(param);
|
|
||||||
String async = commands.get(this.getName());
|
|
||||||
if (async != null && async.equals("yes")) {
|
|
||||||
this.isAsync = true;
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public Element getXmlCommand() {
|
|
||||||
return xmlCommand;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setXmlCommand(Element xmlCommand) {
|
|
||||||
this.xmlCommand = xmlCommand;
|
|
||||||
}
|
|
||||||
|
|
||||||
// ================FOLLOWING METHODS USE INPUT XML FILE=======================//
|
|
||||||
public void setCommandName() {
|
|
||||||
NodeList commandName = this.xmlCommand.getElementsByTagName("name");
|
|
||||||
Element commandElmnt = (Element)commandName.item(0);
|
|
||||||
NodeList commandNm = commandElmnt.getChildNodes();
|
|
||||||
this.commandName = (commandNm.item(0).getNodeValue());
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getName() {
|
|
||||||
return commandName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setTestCaseInfo() {
|
|
||||||
this.testCaseInfo = getElementByName("testcase");
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getHost() {
|
|
||||||
return host;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setHost(String host) {
|
|
||||||
this.host = host;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setResponseType() {
|
|
||||||
boolean result = verifyTagValue("error", "true");
|
|
||||||
if (result) {
|
|
||||||
this.responseType = ResponseType.ERROR;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
result = verifyTagValue("empty", "true");
|
|
||||||
if (result) {
|
|
||||||
this.responseType = ResponseType.EMPTY;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setResponseType(ResponseType responseType) {
|
|
||||||
this.responseType = responseType;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ResponseType getResponseType() {
|
|
||||||
return responseType;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setUserCommand() {
|
|
||||||
boolean result = verifyTagValue("usercommand", "true");
|
|
||||||
this.isUserCommand = result;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setCommandType() {
|
|
||||||
boolean result = verifyTagValue("mysql", "true");
|
|
||||||
if (result) {
|
|
||||||
this.commandType = CommandType.MYSQL;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
result = verifyTagValue("script", "true");
|
|
||||||
if (result) {
|
|
||||||
this.commandType = CommandType.SCRIPT;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
this.commandType = CommandType.HTTP;
|
|
||||||
}
|
|
||||||
|
|
||||||
public CommandType getCommandType() {
|
|
||||||
return commandType;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getTestCaseInfo() {
|
|
||||||
return testCaseInfo;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Boolean getRequired() {
|
|
||||||
return required;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setUrlParam(HashMap<String, String> param) {
|
|
||||||
this.urlParam = new TreeMap<String, String>();
|
|
||||||
NodeList parameterLst = this.xmlCommand.getElementsByTagName("parameters");
|
|
||||||
if (parameterLst != null) {
|
|
||||||
for (int j = 0; j < parameterLst.getLength(); j++) {
|
|
||||||
Element parameterElement = (Element)parameterLst.item(j);
|
|
||||||
NodeList itemLst = parameterElement.getElementsByTagName("item");
|
|
||||||
for (int k = 0; k < itemLst.getLength(); k++) {
|
|
||||||
Node item = itemLst.item(k);
|
|
||||||
if (item.getNodeType() == Node.ELEMENT_NODE) {
|
|
||||||
Element itemElement = (Element)item;
|
|
||||||
NodeList itemName = itemElement.getElementsByTagName("name");
|
|
||||||
Element itemNameElement = (Element)itemName.item(0);
|
|
||||||
|
|
||||||
// get value
|
|
||||||
Element itemValueElement = null;
|
|
||||||
if ((itemElement.getElementsByTagName("value") != null) && (itemElement.getElementsByTagName("value").getLength() != 0)) {
|
|
||||||
NodeList itemValue = itemElement.getElementsByTagName("value");
|
|
||||||
itemValueElement = (Element)itemValue.item(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
Element itemParamElement = null;
|
|
||||||
// getparam
|
|
||||||
if ((itemElement.getElementsByTagName("param") != null) && (itemElement.getElementsByTagName("param").getLength() != 0)) {
|
|
||||||
NodeList itemParam = itemElement.getElementsByTagName("param");
|
|
||||||
itemParamElement = (Element)itemParam.item(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((itemElement.getAttribute("getparam").equals("true")) && (itemParamElement != null)) {
|
|
||||||
this.urlParam.put(itemNameElement.getTextContent(), param.get(itemParamElement.getTextContent()));
|
|
||||||
} else if (itemValueElement != null) {
|
|
||||||
this.urlParam.put(itemNameElement.getTextContent(), itemValueElement.getTextContent());
|
|
||||||
} else if (itemElement.getAttribute("random").equals("true")) {
|
|
||||||
Random ran = new Random();
|
|
||||||
String randomString = Math.abs(ran.nextInt()) + "-randomName";
|
|
||||||
this.urlParam.put(itemNameElement.getTextContent(), randomString);
|
|
||||||
if ((itemElement.getAttribute("setparam").equals("true")) && (itemParamElement != null)) {
|
|
||||||
param.put(itemParamElement.getTextContent(), randomString);
|
|
||||||
}
|
|
||||||
} else if (itemElement.getAttribute("randomnumber").equals("true")) {
|
|
||||||
Random ran = new Random();
|
|
||||||
Integer randomNumber = Math.abs(ran.nextInt(65535));
|
|
||||||
this.urlParam.put(itemNameElement.getTextContent(), randomNumber.toString());
|
|
||||||
if ((itemElement.getAttribute("setparam").equals("true")) && (itemParamElement != null)) {
|
|
||||||
param.put(itemParamElement.getTextContent(), randomNumber.toString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set command URL
|
|
||||||
public void setCommand(HashMap<String, String> param) {
|
|
||||||
|
|
||||||
if (this.getCommandType() == CommandType.SCRIPT) {
|
|
||||||
String temp = "bash xen/" + this.commandName;
|
|
||||||
Set<?> c = this.urlParam.entrySet();
|
|
||||||
Iterator<?> it = c.iterator();
|
|
||||||
while (it.hasNext()) {
|
|
||||||
Map.Entry<?, ?> me = (Map.Entry<?, ?>)it.next();
|
|
||||||
String key = (String)me.getKey();
|
|
||||||
String value = (String)me.getValue();
|
|
||||||
try {
|
|
||||||
temp = temp + " -" + key + " " + value;
|
|
||||||
} catch (Exception ex) {
|
|
||||||
logger.error("Unable to set parameter " + key + " for the command " + this.getName());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
this.command = temp;
|
|
||||||
} else if (this.getCommandType() == CommandType.MYSQL) {
|
|
||||||
String temp = this.commandName + " where ";
|
|
||||||
Set<?> c = this.urlParam.entrySet();
|
|
||||||
Iterator<?> it = c.iterator();
|
|
||||||
while (it.hasNext()) {
|
|
||||||
Map.Entry<?, ?> me = (Map.Entry<?, ?>)it.next();
|
|
||||||
String key = (String)me.getKey();
|
|
||||||
String value = (String)me.getValue();
|
|
||||||
try {
|
|
||||||
temp = temp + key + "=" + value;
|
|
||||||
} catch (Exception ex) {
|
|
||||||
logger.error("Unable to set parameter " + key + " for the command " + this.getName());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
this.command = temp;
|
|
||||||
logger.info("The command is " + this.command);
|
|
||||||
|
|
||||||
} else {
|
|
||||||
if ((param.get("apikey") == null) || (param.get("secretkey") == null) || (this.isUserCommand == false)) {
|
|
||||||
String temp = this.host + ":8096/?command=" + this.commandName;
|
|
||||||
Set<?> c = this.urlParam.entrySet();
|
|
||||||
Iterator<?> it = c.iterator();
|
|
||||||
while (it.hasNext()) {
|
|
||||||
Map.Entry<?, ?> me = (Map.Entry<?, ?>)it.next();
|
|
||||||
String key = (String)me.getKey();
|
|
||||||
String value = (String)me.getValue();
|
|
||||||
try {
|
|
||||||
temp = temp + "&" + key + "=" + URLEncoder.encode(value, "UTF-8");
|
|
||||||
} catch (Exception ex) {
|
|
||||||
logger.error("Unable to set parameter " + key + " for the command " + this.getName());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
this.command = temp;
|
|
||||||
} else if (isUserCommand == true) {
|
|
||||||
String apiKey = param.get("apikey");
|
|
||||||
String secretKey = param.get("secretkey");
|
|
||||||
|
|
||||||
String temp = "";
|
|
||||||
this.urlParam.put("apikey", apiKey);
|
|
||||||
this.urlParam.put("command", this.commandName);
|
|
||||||
|
|
||||||
// sort url hash map by key
|
|
||||||
Set<?> c = this.urlParam.entrySet();
|
|
||||||
Iterator<?> it = c.iterator();
|
|
||||||
while (it.hasNext()) {
|
|
||||||
Map.Entry<?, ?> me = (Map.Entry<?, ?>)it.next();
|
|
||||||
String key = (String)me.getKey();
|
|
||||||
String value = (String)me.getValue();
|
|
||||||
try {
|
|
||||||
temp = temp + key + "=" + URLEncoder.encode(value, "UTF-8") + "&";
|
|
||||||
} catch (Exception ex) {
|
|
||||||
logger.error("Unable to set parameter " + value + " for the command " + this.getName());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
temp = temp.substring(0, temp.length() - 1);
|
|
||||||
String requestToSign = temp.toLowerCase();
|
|
||||||
String signature = UtilsForTest.signRequest(requestToSign, secretKey);
|
|
||||||
String encodedSignature = "";
|
|
||||||
try {
|
|
||||||
encodedSignature = URLEncoder.encode(signature, "UTF-8");
|
|
||||||
} catch (Exception ex) {
|
|
||||||
logger.error(ex);
|
|
||||||
}
|
|
||||||
this.command = this.host + ":8080/client/api/?" + temp + "&signature=" + encodedSignature;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setVerifyParam(HashMap<String, String> param) {
|
|
||||||
NodeList returnLst = this.xmlCommand.getElementsByTagName("returnvalue");
|
|
||||||
if (returnLst != null) {
|
|
||||||
for (int m = 0; m < returnLst.getLength(); m++) {
|
|
||||||
Element returnElement = (Element)returnLst.item(m);
|
|
||||||
if (returnElement.getAttribute("list").equals("true")) {
|
|
||||||
this.list = true;
|
|
||||||
NodeList elementLst = returnElement.getElementsByTagName("element");
|
|
||||||
this.listId = (Element)elementLst.item(0);
|
|
||||||
NodeList elementName = returnElement.getElementsByTagName("name");
|
|
||||||
this.listName = (Element)elementName.item(0);
|
|
||||||
} else {
|
|
||||||
this.list = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
NodeList itemLst1 = returnElement.getElementsByTagName("item");
|
|
||||||
if (itemLst1 != null) {
|
|
||||||
for (int n = 0; n < itemLst1.getLength(); n++) {
|
|
||||||
Node item = itemLst1.item(n);
|
|
||||||
if (item.getNodeType() == Node.ELEMENT_NODE) {
|
|
||||||
Element itemElement = (Element)item;
|
|
||||||
// get parameter name
|
|
||||||
NodeList itemName = itemElement.getElementsByTagName("name");
|
|
||||||
Element itemNameElement = (Element)itemName.item(0);
|
|
||||||
|
|
||||||
// Get parameters for future use
|
|
||||||
if (itemElement.getAttribute("setparam").equals("true")) {
|
|
||||||
NodeList itemVariable = itemElement.getElementsByTagName("param");
|
|
||||||
Element itemVariableElement = (Element)itemVariable.item(0);
|
|
||||||
setParam.put(itemVariableElement.getTextContent(), itemNameElement.getTextContent());
|
|
||||||
this.required = true;
|
|
||||||
} else if (itemElement.getAttribute("getparam").equals("true")) {
|
|
||||||
NodeList itemVariable = itemElement.getElementsByTagName("param");
|
|
||||||
Element itemVariableElement = (Element)itemVariable.item(0);
|
|
||||||
this.verifyParam.put(itemNameElement.getTextContent(), param.get(itemVariableElement.getTextContent()));
|
|
||||||
} else if ((itemElement.getElementsByTagName("value") != null) && (itemElement.getElementsByTagName("value").getLength() != 0)) {
|
|
||||||
NodeList itemVariable = itemElement.getElementsByTagName("value");
|
|
||||||
Element itemVariableElement = (Element)itemVariable.item(0);
|
|
||||||
this.verifyParam.put(itemNameElement.getTextContent(), itemVariableElement.getTextContent());
|
|
||||||
} else {
|
|
||||||
this.verifyParam.put(itemNameElement.getTextContent(), "no value");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getResponseCode() {
|
|
||||||
return responseCode;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Send api command to the server
|
|
||||||
public void sendCommand(HttpClient client, Connection conn) {
|
|
||||||
if (TestCaseEngine.s_printUrl == true) {
|
|
||||||
logger.info("url is " + this.command);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.getCommandType() == CommandType.SCRIPT) {
|
|
||||||
try {
|
|
||||||
logger.info("Executing command " + this.command);
|
|
||||||
Runtime rtime = Runtime.getRuntime();
|
|
||||||
Process child = rtime.exec(this.command);
|
|
||||||
Thread.sleep(10000);
|
|
||||||
int retCode = child.waitFor();
|
|
||||||
if (retCode != 0) {
|
|
||||||
this.responseCode = retCode;
|
|
||||||
} else {
|
|
||||||
this.responseCode = 200;
|
|
||||||
}
|
|
||||||
|
|
||||||
} catch (Exception ex) {
|
|
||||||
logger.error("Unable to execute a command " + this.command, ex);
|
|
||||||
}
|
|
||||||
} else if (this.getCommandType() == CommandType.MYSQL) {
|
|
||||||
try {
|
|
||||||
Statement stmt = conn.createStatement();
|
|
||||||
this.result = stmt.executeQuery(this.command);
|
|
||||||
this.responseCode = 200;
|
|
||||||
} catch (Exception ex) {
|
|
||||||
this.responseCode = 400;
|
|
||||||
logger.error("Unable to execute mysql query " + this.command, ex);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
HttpMethod method = new GetMethod(this.command);
|
|
||||||
try {
|
|
||||||
this.responseCode = client.executeMethod(method);
|
|
||||||
|
|
||||||
if (this.responseCode == 200) {
|
|
||||||
InputStream is = method.getResponseBodyAsStream();
|
|
||||||
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
|
|
||||||
DocumentBuilder builder = factory.newDocumentBuilder();
|
|
||||||
Document doc = builder.parse(is);
|
|
||||||
doc.getDocumentElement().normalize();
|
|
||||||
|
|
||||||
if (!(this.isAsync)) {
|
|
||||||
this.responseBody = doc.getDocumentElement();
|
|
||||||
} else {
|
|
||||||
// get async job result
|
|
||||||
Element jobTag = (Element)doc.getDocumentElement().getElementsByTagName("jobid").item(0);
|
|
||||||
String jobId = jobTag.getTextContent();
|
|
||||||
Element responseBodyAsyncEl = queryAsyncJobResult(jobId);
|
|
||||||
if (responseBodyAsyncEl == null) {
|
|
||||||
logger.error("Can't get a async result");
|
|
||||||
} else {
|
|
||||||
this.responseBody = responseBodyAsyncEl;
|
|
||||||
// get status of the job
|
|
||||||
Element jobStatusTag = (Element)responseBodyAsyncEl.getElementsByTagName("jobstatus").item(0);
|
|
||||||
String jobStatus = jobStatusTag.getTextContent();
|
|
||||||
if (!jobStatus.equals("1")) { // Need to modify with different error codes for jobAsync
|
|
||||||
// results
|
|
||||||
// set fake response code by now
|
|
||||||
this.responseCode = 400;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (TestCaseEngine.s_printUrl == true) {
|
|
||||||
logger.info("Response code is " + this.responseCode);
|
|
||||||
}
|
|
||||||
} catch (Exception ex) {
|
|
||||||
logger.error("Command " + command + " failed with exception " + ex.getMessage());
|
|
||||||
} finally {
|
|
||||||
method.releaseConnection();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// verify if response is empty (contains only root element)
|
|
||||||
public boolean isEmpty() {
|
|
||||||
boolean result = false;
|
|
||||||
if (!this.responseBody.hasChildNodes())
|
|
||||||
result = true;
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
// ================FOLLOWING METHODS USE RETURN XML FILE=======================//
|
|
||||||
|
|
||||||
public boolean setParam(HashMap<String, String> param) {
|
|
||||||
if ((this.responseBody == null) && (this.commandType == CommandType.HTTP)) {
|
|
||||||
logger.error("Response body is empty");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
Boolean result = true;
|
|
||||||
|
|
||||||
if (this.getCommandType() == CommandType.MYSQL) {
|
|
||||||
Set<?> set = this.setParam.entrySet();
|
|
||||||
Iterator<?> it = set.iterator();
|
|
||||||
while (it.hasNext()) {
|
|
||||||
Map.Entry<?, ?> me = (Map.Entry<?, ?>)it.next();
|
|
||||||
String key = (String)me.getKey();
|
|
||||||
String value = (String)me.getValue();
|
|
||||||
try {
|
|
||||||
String itemName = null;
|
|
||||||
while (this.result.next()) {
|
|
||||||
itemName = this.result.getString(value);
|
|
||||||
}
|
|
||||||
if (itemName != null) {
|
|
||||||
param.put(key, itemName);
|
|
||||||
} else {
|
|
||||||
logger.error("Following return parameter is missing: " + value);
|
|
||||||
result = false;
|
|
||||||
}
|
|
||||||
} catch (Exception ex) {
|
|
||||||
logger.error("Unable to set parameter " + value, ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if (this.getCommandType() == CommandType.HTTP) {
|
|
||||||
if (this.list == false) {
|
|
||||||
Set<?> set = this.setParam.entrySet();
|
|
||||||
Iterator<?> it = set.iterator();
|
|
||||||
|
|
||||||
while (it.hasNext()) {
|
|
||||||
Map.Entry<?, ?> me = (Map.Entry<?, ?>)it.next();
|
|
||||||
String key = (String)me.getKey();
|
|
||||||
String value = (String)me.getValue();
|
|
||||||
// set parameters needed for the future use
|
|
||||||
NodeList itemName = this.responseBody.getElementsByTagName(value);
|
|
||||||
if ((itemName != null) && (itemName.getLength() != 0)) {
|
|
||||||
for (int i = 0; i < itemName.getLength(); i++) {
|
|
||||||
Element itemNameElement = (Element)itemName.item(i);
|
|
||||||
if (itemNameElement.getChildNodes().getLength() <= 1) {
|
|
||||||
param.put(key, itemNameElement.getTextContent());
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
logger.error("Following return parameter is missing: " + value);
|
|
||||||
result = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
Set<?> set = this.setParam.entrySet();
|
|
||||||
Iterator<?> it = set.iterator();
|
|
||||||
NodeList returnLst = this.responseBody.getElementsByTagName(this.listName.getTextContent());
|
|
||||||
Node requiredNode = returnLst.item(Integer.parseInt(this.listId.getTextContent()));
|
|
||||||
|
|
||||||
if (requiredNode.getNodeType() == Node.ELEMENT_NODE) {
|
|
||||||
Element fstElmnt = (Element)requiredNode;
|
|
||||||
|
|
||||||
while (it.hasNext()) {
|
|
||||||
Map.Entry<?, ?> me = (Map.Entry<?, ?>)it.next();
|
|
||||||
String key = (String)me.getKey();
|
|
||||||
String value = (String)me.getValue();
|
|
||||||
NodeList itemName = fstElmnt.getElementsByTagName(value);
|
|
||||||
if ((itemName != null) && (itemName.getLength() != 0)) {
|
|
||||||
Element itemNameElement = (Element)itemName.item(0);
|
|
||||||
if (itemNameElement.getChildNodes().getLength() <= 1) {
|
|
||||||
param.put(key, itemNameElement.getTextContent());
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
logger.error("Following return parameter is missing: " + value);
|
|
||||||
result = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getUrl() {
|
|
||||||
return command;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean verifyParam() {
|
|
||||||
boolean result = true;
|
|
||||||
if (this.getCommandType() == CommandType.HTTP) {
|
|
||||||
if (this.list == false) {
|
|
||||||
Set<?> set = verifyParam.entrySet();
|
|
||||||
Iterator<?> it = set.iterator();
|
|
||||||
|
|
||||||
while (it.hasNext()) {
|
|
||||||
Map.Entry<?, ?> me = (Map.Entry<?, ?>)it.next();
|
|
||||||
String key = (String)me.getKey();
|
|
||||||
String value = (String)me.getValue();
|
|
||||||
if (value == null) {
|
|
||||||
logger.error("Parameter " + key + " is missing in the list of global parameters");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
NodeList itemName = this.responseBody.getElementsByTagName(key);
|
|
||||||
if ((itemName.getLength() != 0) && (itemName != null)) {
|
|
||||||
Element itemNameElement = (Element)itemName.item(0);
|
|
||||||
if (itemNameElement.hasChildNodes()) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (!(verifyParam.get(key).equals("no value")) && !(itemNameElement.getTextContent().equals(verifyParam.get(key)))) {
|
|
||||||
logger.error("Incorrect value for the following tag: " + key + ". Expected value is " + verifyParam.get(key) + " while actual value is " +
|
|
||||||
itemNameElement.getTextContent());
|
|
||||||
result = false;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
logger.error("Following xml element is missing in the response: " + key);
|
|
||||||
result = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// for multiple elements
|
|
||||||
else {
|
|
||||||
Set<?> set = verifyParam.entrySet();
|
|
||||||
Iterator<?> it = set.iterator();
|
|
||||||
// get list element specified by id
|
|
||||||
NodeList returnLst = this.responseBody.getElementsByTagName(this.listName.getTextContent());
|
|
||||||
Node requiredNode = returnLst.item(Integer.parseInt(this.listId.getTextContent()));
|
|
||||||
|
|
||||||
if (requiredNode.getNodeType() == Node.ELEMENT_NODE) {
|
|
||||||
Element fstElmnt = (Element)requiredNode;
|
|
||||||
|
|
||||||
while (it.hasNext()) {
|
|
||||||
Map.Entry<?, ?> me = (Map.Entry<?, ?>)it.next();
|
|
||||||
String key = (String)me.getKey();
|
|
||||||
String value = (String)me.getValue();
|
|
||||||
if (value == null) {
|
|
||||||
logger.error("Parameter " + key + " is missing in the list of global parameters");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
NodeList itemName = fstElmnt.getElementsByTagName(key);
|
|
||||||
if ((itemName.getLength() != 0) && (itemName != null)) {
|
|
||||||
Element itemNameElement = (Element)itemName.item(0);
|
|
||||||
if (!(verifyParam.get(key).equals("no value")) && !(itemNameElement.getTextContent().equals(verifyParam.get(key)))) {
|
|
||||||
logger.error("Incorrect value for the following tag: " + key + ". Expected value is " + verifyParam.get(key) +
|
|
||||||
" while actual value is " + itemNameElement.getTextContent());
|
|
||||||
result = false;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
logger.error("Following xml element is missing in the response: " + key);
|
|
||||||
result = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if (this.getCommandType() == CommandType.MYSQL) {
|
|
||||||
Set<?> set = verifyParam.entrySet();
|
|
||||||
Iterator<?> it = set.iterator();
|
|
||||||
|
|
||||||
while (it.hasNext()) {
|
|
||||||
Map.Entry<?, ?> me = (Map.Entry<?, ?>)it.next();
|
|
||||||
String key = (String)me.getKey();
|
|
||||||
String value = (String)me.getValue();
|
|
||||||
if (value == null) {
|
|
||||||
logger.error("Parameter " + key + " is missing in the list of global parameters");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
String itemName = null;
|
|
||||||
try {
|
|
||||||
while (this.result.next()) {
|
|
||||||
itemName = this.result.getString(key);
|
|
||||||
}
|
|
||||||
} catch (Exception ex) {
|
|
||||||
logger.error("Unable to get element from result set " + key);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!(value.equals("no value")) && !(itemName.equals(verifyParam.get(key)))) {
|
|
||||||
logger.error("Incorrect value for the following tag: " + key + ". Expected value is " + verifyParam.get(key) + " while actual value is " + itemName);
|
|
||||||
result = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean verifyEvents(String fileName, String level, String host, String account) {
|
|
||||||
boolean result = false;
|
|
||||||
HashMap<String, Integer> expectedEvents = new HashMap<String, Integer>();
|
|
||||||
HashMap<String, Integer> actualEvents = new HashMap<String, Integer>();
|
|
||||||
String key = "";
|
|
||||||
|
|
||||||
File file = new File(fileName);
|
|
||||||
if (file.exists()) {
|
|
||||||
Properties pro = new Properties();
|
|
||||||
try {
|
|
||||||
// get expected events
|
|
||||||
FileInputStream in = new FileInputStream(file);
|
|
||||||
pro.load(in);
|
|
||||||
Enumeration<?> en = pro.propertyNames();
|
|
||||||
while (en.hasMoreElements()) {
|
|
||||||
key = (String)en.nextElement();
|
|
||||||
expectedEvents.put(key, Integer.parseInt(pro.getProperty(key)));
|
|
||||||
}
|
|
||||||
|
|
||||||
// get actual events
|
|
||||||
String url = host + "/?command=listEvents&account=" + account + "&level=" + level + "&domainid=1&pagesize=100";
|
|
||||||
logger.info("Getting events with the following url " + url);
|
|
||||||
HttpClient client = new HttpClient();
|
|
||||||
HttpMethod method = new GetMethod(url);
|
|
||||||
int responseCode = client.executeMethod(method);
|
|
||||||
if (responseCode == 200) {
|
|
||||||
InputStream is = method.getResponseBodyAsStream();
|
|
||||||
ArrayList<HashMap<String, String>> eventValues = UtilsForTest.parseMulXML(is, new String[] {"event"});
|
|
||||||
|
|
||||||
for (int i = 0; i < eventValues.size(); i++) {
|
|
||||||
HashMap<String, String> element = eventValues.get(i);
|
|
||||||
if (element.get("level").equals(level)) {
|
|
||||||
if (actualEvents.containsKey(element.get("type")) == true) {
|
|
||||||
actualEvents.put(element.get("type"), actualEvents.get(element.get("type")) + 1);
|
|
||||||
} else {
|
|
||||||
actualEvents.put(element.get("type"), 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
method.releaseConnection();
|
|
||||||
|
|
||||||
// compare actual events with expected events
|
|
||||||
|
|
||||||
// compare expected result and actual result
|
|
||||||
Iterator<?> iterator = expectedEvents.keySet().iterator();
|
|
||||||
Integer expected;
|
|
||||||
Integer actual;
|
|
||||||
int fail = 0;
|
|
||||||
while (iterator.hasNext()) {
|
|
||||||
expected = null;
|
|
||||||
actual = null;
|
|
||||||
String type = iterator.next().toString();
|
|
||||||
expected = expectedEvents.get(type);
|
|
||||||
actual = actualEvents.get(type);
|
|
||||||
if (actual == null) {
|
|
||||||
logger.error("Event of type " + type + " and level " + level + " is missing in the listEvents response. Expected number of these events is " +
|
|
||||||
expected);
|
|
||||||
fail++;
|
|
||||||
} else if (expected.compareTo(actual) != 0) {
|
|
||||||
fail++;
|
|
||||||
logger.info("Amount of events of " + type + " type and level " + level + " is incorrect. Expected number of these events is " + expected +
|
|
||||||
", actual number is " + actual);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (fail == 0) {
|
|
||||||
result = true;
|
|
||||||
}
|
|
||||||
} catch (Exception ex) {
|
|
||||||
logger.error(ex);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
logger.info("File " + fileName + " not found");
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean verifyEvents(HashMap<String, Integer> expectedEvents, String level, String host, String parameters) {
|
|
||||||
boolean result = false;
|
|
||||||
HashMap<String, Integer> actualEvents = new HashMap<String, Integer>();
|
|
||||||
try {
|
|
||||||
// get actual events
|
|
||||||
String url = host + "/?command=listEvents&" + parameters;
|
|
||||||
HttpClient client = new HttpClient();
|
|
||||||
HttpMethod method = new GetMethod(url);
|
|
||||||
int responseCode = client.executeMethod(method);
|
|
||||||
if (responseCode == 200) {
|
|
||||||
InputStream is = method.getResponseBodyAsStream();
|
|
||||||
ArrayList<HashMap<String, String>> eventValues = UtilsForTest.parseMulXML(is, new String[] {"event"});
|
|
||||||
|
|
||||||
for (int i = 0; i < eventValues.size(); i++) {
|
|
||||||
HashMap<String, String> element = eventValues.get(i);
|
|
||||||
if (element.get("level").equals(level)) {
|
|
||||||
if (actualEvents.containsKey(element.get("type")) == true) {
|
|
||||||
actualEvents.put(element.get("type"), actualEvents.get(element.get("type")) + 1);
|
|
||||||
} else {
|
|
||||||
actualEvents.put(element.get("type"), 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
method.releaseConnection();
|
|
||||||
} catch (Exception ex) {
|
|
||||||
logger.error(ex);
|
|
||||||
}
|
|
||||||
|
|
||||||
// compare actual events with expected events
|
|
||||||
Iterator<?> iterator = expectedEvents.keySet().iterator();
|
|
||||||
Integer expected;
|
|
||||||
Integer actual;
|
|
||||||
int fail = 0;
|
|
||||||
while (iterator.hasNext()) {
|
|
||||||
expected = null;
|
|
||||||
actual = null;
|
|
||||||
String type = iterator.next().toString();
|
|
||||||
expected = expectedEvents.get(type);
|
|
||||||
actual = actualEvents.get(type);
|
|
||||||
if (actual == null) {
|
|
||||||
logger.error("Event of type " + type + " and level " + level + " is missing in the listEvents response. Expected number of these events is " + expected);
|
|
||||||
fail++;
|
|
||||||
} else if (expected.compareTo(actual) != 0) {
|
|
||||||
fail++;
|
|
||||||
logger.info("Amount of events of " + type + " type and level " + level + " is incorrect. Expected number of these events is " + expected +
|
|
||||||
", actual number is " + actual);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (fail == 0) {
|
|
||||||
result = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Element queryAsyncJobResult(String jobId) {
|
|
||||||
Element returnBody = null;
|
|
||||||
int code = 400;
|
|
||||||
String resultUrl = this.host + ":8096/?command=queryAsyncJobResult&jobid=" + jobId;
|
|
||||||
HttpClient client = new HttpClient();
|
|
||||||
HttpMethod method = new GetMethod(resultUrl);
|
|
||||||
while (true) {
|
|
||||||
try {
|
|
||||||
code = client.executeMethod(method);
|
|
||||||
if (code == 200) {
|
|
||||||
InputStream is = method.getResponseBodyAsStream();
|
|
||||||
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
|
|
||||||
DocumentBuilder builder = factory.newDocumentBuilder();
|
|
||||||
Document doc = builder.parse(is);
|
|
||||||
doc.getDocumentElement().normalize();
|
|
||||||
returnBody = doc.getDocumentElement();
|
|
||||||
Element jobStatusTag = (Element)returnBody.getElementsByTagName("jobstatus").item(0);
|
|
||||||
String jobStatus = jobStatusTag.getTextContent();
|
|
||||||
if (jobStatus.equals("0")) {
|
|
||||||
try {
|
|
||||||
Thread.sleep(1000);
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
logger.debug("[ignored] interrupted while during async job result query.");
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
method.releaseConnection();
|
|
||||||
} else {
|
|
||||||
logger.error("Error during queryJobAsync. Error code is " + code);
|
|
||||||
this.responseCode = code;
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
} catch (Exception ex) {
|
|
||||||
logger.error(ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return returnBody;
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getElementByName(String elementName) {
|
|
||||||
NodeList commandName = this.xmlCommand.getElementsByTagName(elementName);
|
|
||||||
if (commandName.getLength() != 0) {
|
|
||||||
Element commandElmnt = (Element)commandName.item(0);
|
|
||||||
NodeList commandNm = commandElmnt.getChildNodes();
|
|
||||||
return commandNm.item(0).getNodeValue();
|
|
||||||
} else {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean verifyTagValue(String elementName, String expectedValue) {
|
|
||||||
NodeList tag = this.xmlCommand.getElementsByTagName(elementName);
|
|
||||||
if (tag.getLength() != 0) {
|
|
||||||
Element commandElmnt = (Element)tag.item(0);
|
|
||||||
NodeList commandNm = commandElmnt.getChildNodes();
|
|
||||||
if (commandNm.item(0).getNodeValue().equals(expectedValue)) {
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,123 +0,0 @@
|
|||||||
// 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.test.regression;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
|
|
||||||
import org.w3c.dom.Element;
|
|
||||||
import org.w3c.dom.Node;
|
|
||||||
import org.w3c.dom.NodeList;
|
|
||||||
|
|
||||||
import com.trilead.ssh2.Connection;
|
|
||||||
import com.trilead.ssh2.Session;
|
|
||||||
|
|
||||||
import com.cloud.test.regression.ApiCommand.ResponseType;
|
|
||||||
|
|
||||||
public class ConfigTest extends TestCase {
|
|
||||||
|
|
||||||
public ConfigTest() {
|
|
||||||
this.setClient();
|
|
||||||
this.setParam(new HashMap<String, String>());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean executeTest() {
|
|
||||||
|
|
||||||
int error = 0;
|
|
||||||
Element rootElement = this.getInputFile().get(0).getDocumentElement();
|
|
||||||
NodeList commandLst = rootElement.getElementsByTagName("command");
|
|
||||||
|
|
||||||
//Analyze each command, send request and build the array list of api commands
|
|
||||||
for (int i = 0; i < commandLst.getLength(); i++) {
|
|
||||||
Node fstNode = commandLst.item(i);
|
|
||||||
Element fstElmnt = (Element)fstNode;
|
|
||||||
|
|
||||||
//new command
|
|
||||||
ApiCommand api = new ApiCommand(fstElmnt, this.getParam(), this.getCommands());
|
|
||||||
|
|
||||||
if (api.getName().equals("rebootManagementServer")) {
|
|
||||||
|
|
||||||
logger.info("Attempting to SSH into management server " + this.getParam().get("hostip"));
|
|
||||||
try {
|
|
||||||
Connection conn = new Connection(this.getParam().get("hostip"));
|
|
||||||
conn.connect(null, 60000, 60000);
|
|
||||||
|
|
||||||
logger.info("SSHed successfully into management server " + this.getParam().get("hostip"));
|
|
||||||
|
|
||||||
boolean isAuthenticated = conn.authenticateWithPassword("root", "password");
|
|
||||||
|
|
||||||
if (isAuthenticated == false) {
|
|
||||||
logger.info("Authentication failed for root with password");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
String restartCommand = "service cloud-management restart; service cloud-usage restart";
|
|
||||||
Session sess = conn.openSession();
|
|
||||||
logger.info("Executing : " + restartCommand);
|
|
||||||
sess.execCommand(restartCommand);
|
|
||||||
Thread.sleep(120000);
|
|
||||||
sess.close();
|
|
||||||
conn.close();
|
|
||||||
|
|
||||||
} catch (Exception ex) {
|
|
||||||
logger.error(ex);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
//send a command
|
|
||||||
api.sendCommand(this.getClient(), null);
|
|
||||||
|
|
||||||
//verify the response of the command
|
|
||||||
if ((api.getResponseType() == ResponseType.ERROR) && (api.getResponseCode() == 200) && (api.getTestCaseInfo() != null)) {
|
|
||||||
logger.error("Test case " + api.getTestCaseInfo() +
|
|
||||||
"failed. Command that was supposed to fail, passed. The command was sent with the following url " + api.getUrl());
|
|
||||||
error++;
|
|
||||||
} else if ((api.getResponseType() != ResponseType.ERROR) && (api.getResponseCode() == 200)) {
|
|
||||||
//set parameters for the future use
|
|
||||||
if (api.setParam(this.getParam()) == false) {
|
|
||||||
logger.error("Exiting the test...Command " + api.getName() +
|
|
||||||
" didn't return parameters needed for the future use. The command was sent with url " + api.getUrl());
|
|
||||||
return false;
|
|
||||||
} else {
|
|
||||||
//verify parameters
|
|
||||||
if (api.verifyParam() == false) {
|
|
||||||
logger.error("Command " + api.getName() + " failed. Verification for returned parameters failed. Command was sent with url " + api.getUrl());
|
|
||||||
error++;
|
|
||||||
} else if (api.getTestCaseInfo() != null) {
|
|
||||||
logger.info("Test case " + api.getTestCaseInfo() + " passed. Command was sent with the url " + api.getUrl());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if ((api.getResponseType() != ResponseType.ERROR) && (api.getResponseCode() != 200)) {
|
|
||||||
logger.error("Command " + api.getName() + " failed with an error code " + api.getResponseCode() + " . Command was sent with url " + api.getUrl() +
|
|
||||||
" Required: " + api.getRequired());
|
|
||||||
if (api.getRequired() == true) {
|
|
||||||
logger.info("The command is required for the future use, so exiging");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
error++;
|
|
||||||
} else if (api.getTestCaseInfo() != null) {
|
|
||||||
logger.info("Test case " + api.getTestCaseInfo() + " passed. Command that was supposed to fail, failed - test passed. Command was sent with url " +
|
|
||||||
api.getUrl());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (error != 0)
|
|
||||||
return false;
|
|
||||||
else
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,127 +0,0 @@
|
|||||||
// 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.test.regression;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
|
|
||||||
import org.w3c.dom.Document;
|
|
||||||
import org.w3c.dom.Element;
|
|
||||||
import org.w3c.dom.Node;
|
|
||||||
import org.w3c.dom.NodeList;
|
|
||||||
|
|
||||||
import com.cloud.test.regression.ApiCommand.ResponseType;
|
|
||||||
|
|
||||||
public class DelegatedAdminTest extends TestCase {
|
|
||||||
|
|
||||||
|
|
||||||
public DelegatedAdminTest() {
|
|
||||||
this.setClient();
|
|
||||||
this.setParam(new HashMap<String, String>());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean executeTest() {
|
|
||||||
int error = 0;
|
|
||||||
|
|
||||||
for (Document eachElement : this.getInputFile()) {
|
|
||||||
|
|
||||||
Element rootElement = eachElement.getDocumentElement();
|
|
||||||
NodeList commandLst = rootElement.getElementsByTagName("command");
|
|
||||||
|
|
||||||
//Analyze each command, send request and build the array list of api commands
|
|
||||||
for (int i = 0; i < commandLst.getLength(); i++) {
|
|
||||||
boolean verify = false;
|
|
||||||
Node fstNode = commandLst.item(i);
|
|
||||||
Element fstElmnt = (Element)fstNode;
|
|
||||||
|
|
||||||
//new command
|
|
||||||
ApiCommand api = new ApiCommand(fstElmnt, this.getParam(), this.getCommands());
|
|
||||||
|
|
||||||
if ((eachElement.getElementsByTagName("delegated_admin_verify_part2").getLength() != 0) && !(api.getName().equals("registerUserKeys"))) {
|
|
||||||
if (api.getName().startsWith("list")) {
|
|
||||||
|
|
||||||
if (this.denyToExecute()) {
|
|
||||||
api.setResponseType(ResponseType.EMPTY);
|
|
||||||
}
|
|
||||||
verify = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.denyToExecute()) {
|
|
||||||
api.setResponseType(ResponseType.ERROR);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//send a command
|
|
||||||
api.sendCommand(this.getClient(), null);
|
|
||||||
|
|
||||||
//verify the response of the command
|
|
||||||
if ((verify == true) && !(api.getResponseType() == ResponseType.ERROR || api.getResponseType() == ResponseType.EMPTY)) {
|
|
||||||
logger.error("Test case " + api.getTestCaseInfo() +
|
|
||||||
" failed. Command that was supposed to fail, passed. The command was sent with the following url " + api.getUrl());
|
|
||||||
error++;
|
|
||||||
} else if ((verify == true) && (api.getResponseType() == ResponseType.ERROR || api.getResponseType() == ResponseType.EMPTY)) {
|
|
||||||
logger.info("Test case " + api.getTestCaseInfo() + " passed");
|
|
||||||
} else if ((api.getResponseType() == ResponseType.ERROR) && (api.getResponseCode() == 200)) {
|
|
||||||
logger.error("Test case " + api.getTestCaseInfo() +
|
|
||||||
" failed. Command that was supposed to fail, passed. The command was sent with the following url " + api.getUrl());
|
|
||||||
error++;
|
|
||||||
} else if ((api.getResponseType() != ResponseType.ERROR) && (api.getResponseCode() == 200)) {
|
|
||||||
//set parameters for the future use
|
|
||||||
if (api.setParam(this.getParam()) == false) {
|
|
||||||
logger.error("Exiting the test...Command " + api.getName() +
|
|
||||||
" didn't return parameters needed for the future use. The command was sent with url " + api.getUrl());
|
|
||||||
return false;
|
|
||||||
} else if (api.getTestCaseInfo() != null) {
|
|
||||||
logger.info("Test case " + api.getTestCaseInfo() + " passed");
|
|
||||||
}
|
|
||||||
} else if ((api.getResponseType() != ResponseType.ERROR) && (api.getResponseCode() != 200)) {
|
|
||||||
logger.error("Test case " + api.getTestCaseInfo() + " failed with an error code " + api.getResponseCode() + " . Command was sent with url " +
|
|
||||||
api.getUrl());
|
|
||||||
if (api.getRequired() == true) {
|
|
||||||
logger.info("The command is required for the future use, so exiging");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
error++;
|
|
||||||
} else if (api.getTestCaseInfo() != null) {
|
|
||||||
logger.info("Test case " + api.getTestCaseInfo() + " passed");
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (error != 0)
|
|
||||||
return false;
|
|
||||||
else
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean denyToExecute() {
|
|
||||||
boolean result = true;
|
|
||||||
Integer level1 = Integer.valueOf(this.getParam().get("domainlevel1"));
|
|
||||||
Integer level2 = Integer.valueOf(this.getParam().get("domainlevel2"));
|
|
||||||
String domain1 = this.getParam().get("domainname1");
|
|
||||||
String domain2 = this.getParam().get("domainname2");
|
|
||||||
|
|
||||||
if (this.getParam().get("accounttype2").equals("1")) {
|
|
||||||
result = false;
|
|
||||||
} else if ((level2.compareTo(level1) < 0) && (domain1.startsWith(domain2)) && (this.getParam().get("accounttype2").equals("2"))) {
|
|
||||||
result = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,107 +0,0 @@
|
|||||||
// 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.test.regression;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.w3c.dom.Element;
|
|
||||||
import org.w3c.dom.Node;
|
|
||||||
import org.w3c.dom.NodeList;
|
|
||||||
|
|
||||||
public class Deploy extends TestCase {
|
|
||||||
|
|
||||||
public Deploy() {
|
|
||||||
this.setClient();
|
|
||||||
this.setParam(new HashMap<String, String>());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean executeTest() {
|
|
||||||
int error = 0;
|
|
||||||
Element rootElement = this.getInputFile().get(0).getDocumentElement();
|
|
||||||
NodeList commandLst = rootElement.getElementsByTagName("command");
|
|
||||||
|
|
||||||
//Analyze each command, send request and build the array list of api commands
|
|
||||||
for (int i = 0; i < commandLst.getLength(); i++) {
|
|
||||||
Node fstNode = commandLst.item(i);
|
|
||||||
Element fstElmnt = (Element)fstNode;
|
|
||||||
|
|
||||||
//new command
|
|
||||||
ApiCommand api = new ApiCommand(fstElmnt, this.getParam(), this.getCommands());
|
|
||||||
|
|
||||||
//send a command
|
|
||||||
api.sendCommand(this.getClient(), null);
|
|
||||||
|
|
||||||
//verify the response of the command
|
|
||||||
if (api.getResponseCode() != 200) {
|
|
||||||
error++;
|
|
||||||
logger.error("The command " + api.getUrl() + " failed");
|
|
||||||
} else {
|
|
||||||
logger.info("The command " + api.getUrl() + " passsed");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (error != 0)
|
|
||||||
return false;
|
|
||||||
else
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
|
||||||
|
|
||||||
List<String> argsList = Arrays.asList(args);
|
|
||||||
Iterator<String> iter = argsList.iterator();
|
|
||||||
String host = null;
|
|
||||||
String file = null;
|
|
||||||
|
|
||||||
while (iter.hasNext()) {
|
|
||||||
String arg = iter.next();
|
|
||||||
// management server host
|
|
||||||
if (arg.equals("-h")) {
|
|
||||||
host = iter.next();
|
|
||||||
}
|
|
||||||
if (arg.equals("-f")) {
|
|
||||||
file = iter.next();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Deploy deploy = new Deploy();
|
|
||||||
|
|
||||||
ArrayList<String> inputFile = new ArrayList<String>();
|
|
||||||
inputFile.add(file);
|
|
||||||
deploy.setInputFile(inputFile);
|
|
||||||
deploy.setTestCaseName("Management server deployment");
|
|
||||||
deploy.getParam().put("hostip", host);
|
|
||||||
deploy.getParam().put("apicommands", "../metadata/func/commands");
|
|
||||||
deploy.setCommands();
|
|
||||||
|
|
||||||
logger.info("Starting deployment against host " + host);
|
|
||||||
|
|
||||||
boolean result = deploy.executeTest();
|
|
||||||
if (result == false) {
|
|
||||||
logger.error("DEPLOYMENT FAILED");
|
|
||||||
System.exit(1);
|
|
||||||
} else {
|
|
||||||
logger.info("DEPLOYMENT IS SUCCESSFUL");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,174 +0,0 @@
|
|||||||
// 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.test.regression;
|
|
||||||
|
|
||||||
import java.sql.Statement;
|
|
||||||
import java.util.HashMap;
|
|
||||||
|
|
||||||
import org.w3c.dom.Element;
|
|
||||||
import org.w3c.dom.Node;
|
|
||||||
import org.w3c.dom.NodeList;
|
|
||||||
|
|
||||||
import com.trilead.ssh2.Connection;
|
|
||||||
import com.trilead.ssh2.Session;
|
|
||||||
|
|
||||||
import com.cloud.test.regression.ApiCommand.ResponseType;
|
|
||||||
|
|
||||||
public class EventsApiTest extends TestCase {
|
|
||||||
|
|
||||||
public EventsApiTest() {
|
|
||||||
this.setClient();
|
|
||||||
this.setParam(new HashMap<String, String>());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean executeTest() {
|
|
||||||
int error = 0;
|
|
||||||
Element rootElement = this.getInputFile().get(0).getDocumentElement();
|
|
||||||
NodeList commandLst = rootElement.getElementsByTagName("command");
|
|
||||||
|
|
||||||
//Analyze each command, send request and build the array list of api commands
|
|
||||||
for (int i = 0; i < commandLst.getLength(); i++) {
|
|
||||||
Node fstNode = commandLst.item(i);
|
|
||||||
Element fstElmnt = (Element)fstNode;
|
|
||||||
|
|
||||||
//!!!check if we need to execute mySql command
|
|
||||||
NodeList commandName = fstElmnt.getElementsByTagName("name");
|
|
||||||
Element commandElmnt = (Element)commandName.item(0);
|
|
||||||
NodeList commandNm = commandElmnt.getChildNodes();
|
|
||||||
if (commandNm.item(0).getNodeValue().equals("mysqlupdate")) {
|
|
||||||
//establish connection to mysql server and execute an update command
|
|
||||||
NodeList mysqlList = fstElmnt.getElementsByTagName("mysqlcommand");
|
|
||||||
for (int j = 0; j < mysqlList.getLength(); j++) {
|
|
||||||
Element itemVariableElement = (Element)mysqlList.item(j);
|
|
||||||
|
|
||||||
logger.info("Executing mysql command " + itemVariableElement.getTextContent());
|
|
||||||
try {
|
|
||||||
Statement st = this.getConn().createStatement();
|
|
||||||
st.executeUpdate(itemVariableElement.getTextContent());
|
|
||||||
} catch (Exception ex) {
|
|
||||||
logger.error(ex);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (commandNm.item(0).getNodeValue().equals("agentcommand")) {
|
|
||||||
//connect to all the agents and execute agent command
|
|
||||||
NodeList commandList = fstElmnt.getElementsByTagName("commandname");
|
|
||||||
Element commandElement = (Element)commandList.item(0);
|
|
||||||
NodeList ipList = fstElmnt.getElementsByTagName("ip");
|
|
||||||
for (int j = 0; j < ipList.getLength(); j++) {
|
|
||||||
Element itemVariableElement = (Element)ipList.item(j);
|
|
||||||
|
|
||||||
logger.info("Attempting to SSH into agent " + itemVariableElement.getTextContent());
|
|
||||||
try {
|
|
||||||
Connection conn = new Connection(itemVariableElement.getTextContent());
|
|
||||||
conn.connect(null, 60000, 60000);
|
|
||||||
|
|
||||||
logger.info("SSHed successfully into agent " + itemVariableElement.getTextContent());
|
|
||||||
|
|
||||||
boolean isAuthenticated = conn.authenticateWithPassword("root", "password");
|
|
||||||
|
|
||||||
if (isAuthenticated == false) {
|
|
||||||
logger.info("Authentication failed for root with password");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
Session sess = conn.openSession();
|
|
||||||
logger.info("Executing : " + commandElement.getTextContent());
|
|
||||||
sess.execCommand(commandElement.getTextContent());
|
|
||||||
Thread.sleep(60000);
|
|
||||||
sess.close();
|
|
||||||
conn.close();
|
|
||||||
|
|
||||||
} catch (Exception ex) {
|
|
||||||
logger.error(ex);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
else {
|
|
||||||
//new command
|
|
||||||
ApiCommand api = new ApiCommand(fstElmnt, this.getParam(), this.getCommands());
|
|
||||||
|
|
||||||
//send a command
|
|
||||||
api.sendCommand(this.getClient(), null);
|
|
||||||
|
|
||||||
//verify the response of the command
|
|
||||||
if ((api.getResponseType() == ResponseType.ERROR) && (api.getResponseCode() == 200)) {
|
|
||||||
logger.error("Test case " + api.getTestCaseInfo() +
|
|
||||||
" failed. Command that was supposed to fail, passed. The command was sent with the following url " + api.getUrl());
|
|
||||||
error++;
|
|
||||||
} else if ((api.getResponseType() != ResponseType.ERROR) && (api.getResponseCode() == 200)) {
|
|
||||||
//verify if response is suppposed to be empty
|
|
||||||
if (api.getResponseType() == ResponseType.EMPTY) {
|
|
||||||
if (api.isEmpty() == true) {
|
|
||||||
logger.info("Test case " + api.getTestCaseInfo() + " passed. Empty response was returned as expected. Command was sent with url " +
|
|
||||||
api.getUrl());
|
|
||||||
} else {
|
|
||||||
logger.error("Test case " + api.getTestCaseInfo() + " failed. Empty response was expected. Command was sent with url " + api.getUrl());
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (api.isEmpty() != false)
|
|
||||||
logger.error("Test case " + api.getTestCaseInfo() + " failed. Non-empty response was expected. Command was sent with url " + api.getUrl());
|
|
||||||
else {
|
|
||||||
//set parameters for the future use
|
|
||||||
if (api.setParam(this.getParam()) == false) {
|
|
||||||
logger.error("Exiting the test...Command " + api.getName() +
|
|
||||||
" didn't return parameters needed for the future use. The command was sent with url " + api.getUrl());
|
|
||||||
return false;
|
|
||||||
} else if (api.getTestCaseInfo() != null) {
|
|
||||||
logger.info("Test case " + api.getTestCaseInfo() + " passed. Command was sent with the url " + api.getUrl());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if ((api.getResponseType() != ResponseType.ERROR) && (api.getResponseCode() != 200)) {
|
|
||||||
logger.error("Command " + api.getName() + " failed with an error code " + api.getResponseCode() + " . Command was sent with url " + api.getUrl());
|
|
||||||
if (api.getRequired() == true) {
|
|
||||||
logger.info("The command is required for the future use, so exiging");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
error++;
|
|
||||||
} else if (api.getTestCaseInfo() != null) {
|
|
||||||
logger.info("Test case " + api.getTestCaseInfo() + " passed. Command that was supposed to fail, failed. Command was sent with url " + api.getUrl());
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//verify events with userid parameter - test case 97
|
|
||||||
HashMap<String, Integer> expectedEvents = new HashMap<String, Integer>();
|
|
||||||
expectedEvents.put("VM.START", 1);
|
|
||||||
boolean eventResult =
|
|
||||||
ApiCommand.verifyEvents(expectedEvents, "INFO", "http://" + this.getParam().get("hostip") + ":8096", "userid=" + this.getParam().get("userid1") +
|
|
||||||
"&type=VM.START");
|
|
||||||
logger.info("Test case 97 - listEvent command verification result is " + eventResult);
|
|
||||||
|
|
||||||
//verify error events
|
|
||||||
eventResult =
|
|
||||||
ApiCommand.verifyEvents("../metadata/error_events.properties", "ERROR", "http://" + this.getParam().get("hostip") + ":8096",
|
|
||||||
this.getParam().get("erroruseraccount"));
|
|
||||||
logger.info("listEvent command verification result is " + eventResult);
|
|
||||||
|
|
||||||
if (error != 0)
|
|
||||||
return false;
|
|
||||||
else
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,78 +0,0 @@
|
|||||||
// 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.test.regression;
|
|
||||||
|
|
||||||
import org.w3c.dom.Element;
|
|
||||||
import org.w3c.dom.Node;
|
|
||||||
import org.w3c.dom.NodeList;
|
|
||||||
|
|
||||||
import com.cloud.test.regression.ApiCommand.ResponseType;
|
|
||||||
|
|
||||||
public class HA extends TestCase {
|
|
||||||
|
|
||||||
|
|
||||||
public HA() {
|
|
||||||
this.setClient();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean executeTest() {
|
|
||||||
int error = 0;
|
|
||||||
Element rootElement = this.getInputFile().get(0).getDocumentElement();
|
|
||||||
NodeList commandLst = rootElement.getElementsByTagName("command");
|
|
||||||
|
|
||||||
//Analyze each command, send request and build the array list of api commands
|
|
||||||
for (int i = 0; i < commandLst.getLength(); i++) {
|
|
||||||
|
|
||||||
Node fstNode = commandLst.item(i);
|
|
||||||
Element fstElmnt = (Element)fstNode;
|
|
||||||
|
|
||||||
//new command
|
|
||||||
ApiCommand api = new ApiCommand(fstElmnt, this.getParam(), this.getCommands());
|
|
||||||
|
|
||||||
//send a command
|
|
||||||
api.sendCommand(this.getClient(), this.getConn());
|
|
||||||
|
|
||||||
//verify the response parameters
|
|
||||||
if ((api.getResponseCode() != 200) && (api.getRequired() == true)) {
|
|
||||||
logger.error("Exiting the test....Command " + api.getName() + " required for the future run, failed with an error code " + api.getResponseCode() +
|
|
||||||
". Command was sent with the url " + api.getUrl());
|
|
||||||
return false;
|
|
||||||
} else if ((api.getResponseCode() != 200) && (api.getResponseType() != ResponseType.ERROR)) {
|
|
||||||
error++;
|
|
||||||
logger.error("Command " + api.getTestCaseInfo() + " failed with an error code " + api.getResponseCode() + " . Command was sent with url " +
|
|
||||||
api.getUrl());
|
|
||||||
} else if ((api.getResponseCode() == 200) && (api.getResponseType() == ResponseType.ERROR)) {
|
|
||||||
error++;
|
|
||||||
logger.error("Command " + api.getTestCaseInfo() + " which was supposed to failed, passed. The command was sent with url " + api.getUrl());
|
|
||||||
} else {
|
|
||||||
//set parameters for the future use
|
|
||||||
if (api.setParam(this.getParam()) == false) {
|
|
||||||
logger.error("Exiting the test...Command " + api.getName() + " didn't return parameters needed for the future use. Command was sent with url " +
|
|
||||||
api.getUrl());
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
logger.info("Command " + api.getTestCaseInfo() + " passed");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (error != 0)
|
|
||||||
return false;
|
|
||||||
else
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,140 +0,0 @@
|
|||||||
// 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.test.regression;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
|
|
||||||
import org.w3c.dom.Element;
|
|
||||||
import org.w3c.dom.Node;
|
|
||||||
import org.w3c.dom.NodeList;
|
|
||||||
|
|
||||||
import com.cloud.test.regression.ApiCommand.ResponseType;
|
|
||||||
|
|
||||||
public class LoadBalancingTest extends TestCase {
|
|
||||||
|
|
||||||
|
|
||||||
public LoadBalancingTest() {
|
|
||||||
this.setClient();
|
|
||||||
this.setParam(new HashMap<String, String>());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean executeTest() {
|
|
||||||
|
|
||||||
int error = 0;
|
|
||||||
Element rootElement = this.getInputFile().get(0).getDocumentElement();
|
|
||||||
NodeList commandLst = rootElement.getElementsByTagName("command");
|
|
||||||
|
|
||||||
//Analyze each command, send request and build the array list of api commands
|
|
||||||
for (int i = 0; i < commandLst.getLength(); i++) {
|
|
||||||
|
|
||||||
Node fstNode = commandLst.item(i);
|
|
||||||
Element fstElmnt = (Element)fstNode;
|
|
||||||
|
|
||||||
//new command
|
|
||||||
ApiCommand api = new ApiCommand(fstElmnt, this.getParam(), this.getCommands());
|
|
||||||
|
|
||||||
//send a command
|
|
||||||
api.sendCommand(this.getClient(), null);
|
|
||||||
|
|
||||||
//verify the response of the command
|
|
||||||
if ((api.getResponseType() == ResponseType.ERROR) && (api.getResponseCode() == 200)) {
|
|
||||||
logger.error("Test case " + api.getTestCaseInfo() + " failed. Command that was supposed to fail, passed. The command was sent with the following url " +
|
|
||||||
api.getUrl());
|
|
||||||
error++;
|
|
||||||
} else if ((api.getResponseType() != ResponseType.ERROR) && (api.getResponseCode() == 200)) {
|
|
||||||
//verify if response is suppposed to be empty
|
|
||||||
if (api.getResponseType() == ResponseType.EMPTY) {
|
|
||||||
if (api.isEmpty() == true) {
|
|
||||||
logger.info("Test case " + api.getTestCaseInfo() + " passed");
|
|
||||||
} else {
|
|
||||||
logger.error("Test case " + api.getTestCaseInfo() + " failed. Empty response was expected. Command was sent with url " + api.getUrl());
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (api.isEmpty() != false)
|
|
||||||
logger.error("Test case " + api.getTestCaseInfo() + " failed. Non-empty response was expected. Command was sent with url " + api.getUrl());
|
|
||||||
else {
|
|
||||||
//set parameters for the future use
|
|
||||||
if (api.setParam(this.getParam()) == false) {
|
|
||||||
logger.error("Exiting the test...Command " + api.getName() +
|
|
||||||
" didn't return parameters needed for the future use. The command was sent with url " + api.getUrl());
|
|
||||||
return false;
|
|
||||||
} else if (api.getTestCaseInfo() != null) {
|
|
||||||
logger.info("Test case " + api.getTestCaseInfo() + " passed");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if ((api.getResponseType() != ResponseType.ERROR) && (api.getResponseCode() != 200)) {
|
|
||||||
logger.error("Test case " + api.getTestCaseInfo() + " failed. Command was sent with url " + api.getUrl());
|
|
||||||
if (api.getRequired() == true) {
|
|
||||||
logger.info("The command is required for the future use, so exiging");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
error++;
|
|
||||||
} else if (api.getTestCaseInfo() != null) {
|
|
||||||
logger.info("Test case " + api.getTestCaseInfo() + " passed");
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// //Try to create portForwarding rule for all available private/public ports
|
|
||||||
// ArrayList<String> port = new ArrayList<String>();
|
|
||||||
// for (int i=1; i<65536; i++){
|
|
||||||
// port.add(Integer.toString(i));
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// //try all public ports
|
|
||||||
// for (String portValue : port) {
|
|
||||||
// try {
|
|
||||||
// String url = this.getHost() + ":8096/?command=createOrUpdateLoadBalancerRule&account=" + this.getParam().get("accountname") + "&publicip=" + this.getParam().get("boundaryip") +
|
|
||||||
// "&privateip=" + this.getParam().get("vmipaddress") + "&privateport=22&protocol=tcp&publicport=" + portValue;
|
|
||||||
// HttpClient client = new HttpClient();
|
|
||||||
// HttpMethod method = new GetMethod(url);
|
|
||||||
// int responseCode = client.executeMethod(method);
|
|
||||||
// if (responseCode != 200 ) {
|
|
||||||
// error++;
|
|
||||||
// logger.error("Can't create LB rule for the public port " + portValue + ". Request was sent with url " + url);
|
|
||||||
// }
|
|
||||||
// }catch (Exception ex) {
|
|
||||||
// logger.error(ex);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// //try all private ports
|
|
||||||
// for (String portValue : port) {
|
|
||||||
// try {
|
|
||||||
// String url = this.getHost() + ":8096/?command=createOrUpdateLoadBalancerRule&account=" + this.getParam().get("accountname") + "&publicip=" + this.getParam().get("boundaryip") +
|
|
||||||
// "&privateip=" + this.getParam().get("vmipaddress") + "&publicport=22&protocol=tcp&privateport=" + portValue;
|
|
||||||
// HttpClient client = new HttpClient();
|
|
||||||
// HttpMethod method = new GetMethod(url);
|
|
||||||
// int responseCode = client.executeMethod(method);
|
|
||||||
// if (responseCode != 200 ) {
|
|
||||||
// error++;
|
|
||||||
// logger.error("Can't create LB rule for the private port " + portValue + ". Request was sent with url " + url);
|
|
||||||
// }
|
|
||||||
// }catch (Exception ex) {
|
|
||||||
// logger.error(ex);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
if (error != 0)
|
|
||||||
return false;
|
|
||||||
else
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,141 +0,0 @@
|
|||||||
// 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.test.regression;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
|
|
||||||
import org.w3c.dom.Element;
|
|
||||||
import org.w3c.dom.Node;
|
|
||||||
import org.w3c.dom.NodeList;
|
|
||||||
|
|
||||||
import com.cloud.test.regression.ApiCommand.ResponseType;
|
|
||||||
|
|
||||||
public class PortForwardingTest extends TestCase {
|
|
||||||
|
|
||||||
public PortForwardingTest() {
|
|
||||||
setClient();
|
|
||||||
setParam(new HashMap<String, String>());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean executeTest() {
|
|
||||||
|
|
||||||
int error = 0;
|
|
||||||
Element rootElement = getInputFile().get(0).getDocumentElement();
|
|
||||||
NodeList commandLst = rootElement.getElementsByTagName("command");
|
|
||||||
|
|
||||||
//Analyze each command, send request and build the array list of api commands
|
|
||||||
for (int i = 0; i < commandLst.getLength(); i++) {
|
|
||||||
|
|
||||||
Node fstNode = commandLst.item(i);
|
|
||||||
Element fstElmnt = (Element)fstNode;
|
|
||||||
|
|
||||||
//new command
|
|
||||||
ApiCommand api = new ApiCommand(fstElmnt, getParam(), getCommands());
|
|
||||||
|
|
||||||
//send a command
|
|
||||||
api.sendCommand(getClient(), null);
|
|
||||||
|
|
||||||
//verify the response of the command
|
|
||||||
if ((api.getResponseType() != ResponseType.ERROR) && (api.getResponseCode() == 200)) {
|
|
||||||
logger.error("Test case " + api.getTestCaseInfo() + " failed. Command that was supposed to fail, passed. The command was sent with the following url " +
|
|
||||||
api.getUrl());
|
|
||||||
error++;
|
|
||||||
} else if ((api.getResponseType() != ResponseType.ERROR) && (api.getResponseCode() == 200)) {
|
|
||||||
//verify if response is suppposed to be empty
|
|
||||||
if (api.getResponseType() == ResponseType.EMPTY) {
|
|
||||||
if (api.isEmpty() == true) {
|
|
||||||
logger.info("Test case " + api.getTestCaseInfo() + " passed");
|
|
||||||
} else {
|
|
||||||
logger.error("Test case " + api.getTestCaseInfo() + " failed. Empty response was expected. Command was sent with url " + api.getUrl());
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (api.isEmpty() != false)
|
|
||||||
logger.error("Test case " + api.getTestCaseInfo() + " failed. Non-empty response was expected. Command was sent with url " + api.getUrl());
|
|
||||||
else {
|
|
||||||
//set parameters for the future use
|
|
||||||
if (api.setParam(getParam()) == false) {
|
|
||||||
logger.error("Exiting the test...Command " + api.getName() +
|
|
||||||
" didn't return parameters needed for the future use. The command was sent with url " + api.getUrl());
|
|
||||||
return false;
|
|
||||||
} else if (api.getTestCaseInfo() != null) {
|
|
||||||
logger.info("Test case " + api.getTestCaseInfo() + " passed");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if ((api.getResponseType() != ResponseType.ERROR) && (api.getResponseCode() != 200)) {
|
|
||||||
logger.error("Test case " + api.getTestCaseInfo() + " failed . Command was sent with url " + api.getUrl());
|
|
||||||
if (api.getRequired() == true) {
|
|
||||||
logger.info("The command is required for the future use, so exiging");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
error++;
|
|
||||||
} else if (api.getTestCaseInfo() != null) {
|
|
||||||
logger.info("Test case " + api.getTestCaseInfo() + " passed");
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// //Try to create portForwarding rule for all available private/public ports
|
|
||||||
// ArrayList<String> port = new ArrayList<String>();
|
|
||||||
// for (int i=1; i<65536; i++){
|
|
||||||
// port.add(Integer.toString(i));
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// //try all public ports
|
|
||||||
// for (String portValue : port) {
|
|
||||||
// try {
|
|
||||||
// logger.info("public port is " + portValue);
|
|
||||||
// String url = this.getHost() + ":8096/?command=createOrUpdateIpForwardingRule&account=" + this.getParam().get("accountname") + "&publicip=" + this.getParam().get("boundaryip") +
|
|
||||||
// "&privateip=" + this.getParam().get("vmipaddress") + "&privateport=22&protocol=tcp&publicport=" + portValue;
|
|
||||||
// HttpClient client = new HttpClient();
|
|
||||||
// HttpMethod method = new GetMethod(url);
|
|
||||||
// int responseCode = client.executeMethod(method);
|
|
||||||
// if (responseCode != 200 ) {
|
|
||||||
// error++;
|
|
||||||
// logger.error("Can't create portForwarding rule for the public port " + portValue + ". Request was sent with url " + url);
|
|
||||||
// }
|
|
||||||
// }catch (Exception ex) {
|
|
||||||
// logger.error(ex);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// //try all private ports
|
|
||||||
// for (String portValue : port) {
|
|
||||||
// try {
|
|
||||||
// String url = this.getHost() + ":8096/?command=createOrUpdateIpForwardingRule&account=" +
|
|
||||||
// this.getParam().get("accountname") + "&publicip=" + this.getParam().get("boundaryip") +
|
|
||||||
// "&privateip=" + this.getParam().get("vmipaddress") + "&publicport=22&protocol=tcp&privateport=" + portValue;
|
|
||||||
// HttpClient client = new HttpClient();
|
|
||||||
// HttpMethod method = new GetMethod(url);
|
|
||||||
// int responseCode = client.executeMethod(method);
|
|
||||||
// if (responseCode != 200 ) {
|
|
||||||
// error++;
|
|
||||||
// logger.error("Can't create portForwarding rule for the private port " + portValue + ". Request was sent with url " + url);
|
|
||||||
// }
|
|
||||||
// }catch (Exception ex) {
|
|
||||||
// logger.error(ex);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
if (error != 0)
|
|
||||||
return false;
|
|
||||||
else
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,84 +0,0 @@
|
|||||||
// 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.test.regression;
|
|
||||||
|
|
||||||
import org.w3c.dom.Element;
|
|
||||||
import org.w3c.dom.Node;
|
|
||||||
import org.w3c.dom.NodeList;
|
|
||||||
|
|
||||||
public class SanityTest extends TestCase {
|
|
||||||
|
|
||||||
|
|
||||||
public SanityTest() {
|
|
||||||
this.setClient();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean executeTest() {
|
|
||||||
int error = 0;
|
|
||||||
Element rootElement = this.getInputFile().get(0).getDocumentElement();
|
|
||||||
NodeList commandLst = rootElement.getElementsByTagName("command");
|
|
||||||
//Analyze each command, send request and build the array list of api commands
|
|
||||||
for (int i = 0; i < commandLst.getLength(); i++) {
|
|
||||||
|
|
||||||
Node fstNode = commandLst.item(i);
|
|
||||||
Element fstElmnt = (Element)fstNode;
|
|
||||||
|
|
||||||
//new command
|
|
||||||
ApiCommand api = new ApiCommand(fstElmnt, this.getParam(), this.getCommands());
|
|
||||||
|
|
||||||
api.sendCommand(this.getClient(), null);
|
|
||||||
|
|
||||||
//verify the response parameters
|
|
||||||
if ((api.getResponseCode() != 200) && (api.getRequired() == true)) {
|
|
||||||
logger.error("Exiting the test....Command " + api.getName() + " required for the future run, failed with an error code " + api.getResponseCode() +
|
|
||||||
". Command was sent with the url " + api.getUrl());
|
|
||||||
return false;
|
|
||||||
} else if (api.getResponseCode() != 200) {
|
|
||||||
error++;
|
|
||||||
logger.error("Test " + api.getTestCaseInfo() + " failed with an error code " + api.getResponseCode() + " . Command was sent with url " + api.getUrl());
|
|
||||||
} else {
|
|
||||||
//set parameters for the future use
|
|
||||||
if (api.setParam(this.getParam()) == false) {
|
|
||||||
logger.error("Exiting the test...Command " + api.getName() + " didn't return parameters needed for the future use. Command was sent with url " +
|
|
||||||
api.getUrl());
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
//verify parameters
|
|
||||||
if (api.verifyParam() == false) {
|
|
||||||
logger.error("Test " + api.getTestCaseInfo() + " failed. Verification for returned parameters failed. The command was sent with url " +
|
|
||||||
api.getUrl());
|
|
||||||
error++;
|
|
||||||
} else if (api.getTestCaseInfo() != null) {
|
|
||||||
logger.info("Test " + api.getTestCaseInfo() + " passed");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//verify event
|
|
||||||
boolean eventResult =
|
|
||||||
ApiCommand.verifyEvents("../metadata/func/regression_events.properties", "INFO", "http://" + this.getParam().get("hostip") + ":8096",
|
|
||||||
this.getParam().get("accountname"));
|
|
||||||
logger.info("listEvent command verification result is " + eventResult);
|
|
||||||
|
|
||||||
if (error != 0)
|
|
||||||
return false;
|
|
||||||
else
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,86 +0,0 @@
|
|||||||
// 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.test.regression;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
|
||||||
|
|
||||||
import org.apache.commons.httpclient.HttpClient;
|
|
||||||
import org.apache.commons.httpclient.HttpMethod;
|
|
||||||
import org.apache.commons.httpclient.methods.GetMethod;
|
|
||||||
import org.w3c.dom.Element;
|
|
||||||
import org.w3c.dom.Node;
|
|
||||||
import org.w3c.dom.NodeList;
|
|
||||||
|
|
||||||
public class Test extends TestCase {
|
|
||||||
|
|
||||||
public Test() {
|
|
||||||
this.setClient();
|
|
||||||
this.setParam(new HashMap<String, String>());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean executeTest() {
|
|
||||||
|
|
||||||
int error = 0;
|
|
||||||
Element rootElement = this.getInputFile().get(0).getDocumentElement();
|
|
||||||
NodeList commandLst = rootElement.getElementsByTagName("command");
|
|
||||||
|
|
||||||
//Analyze each command, send request and build the array list of api commands
|
|
||||||
for (int i = 0; i < commandLst.getLength(); i++) {
|
|
||||||
Node fstNode = commandLst.item(i);
|
|
||||||
Element fstElmnt = (Element)fstNode;
|
|
||||||
|
|
||||||
//new command
|
|
||||||
ApiCommand api = new ApiCommand(fstElmnt, this.getParam(), this.getCommands());
|
|
||||||
|
|
||||||
//send a command
|
|
||||||
api.sendCommand(this.getClient(), null);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
//Try to create portForwarding rule for all available private/public ports
|
|
||||||
ArrayList<String> port = new ArrayList<String>();
|
|
||||||
for (int j = 1; j < 1000; j++) {
|
|
||||||
port.add(Integer.toString(j));
|
|
||||||
}
|
|
||||||
|
|
||||||
//try all public ports
|
|
||||||
for (String portValue : port) {
|
|
||||||
try {
|
|
||||||
logger.info("public port is " + portValue);
|
|
||||||
String url =
|
|
||||||
"http://" + this.getParam().get("hostip") + ":8096/?command=createNetworkRule&publicPort=" + portValue +
|
|
||||||
"&privatePort=22&protocol=tcp&isForward=true&securityGroupId=1&account=admin";
|
|
||||||
HttpClient client = new HttpClient();
|
|
||||||
HttpMethod method = new GetMethod(url);
|
|
||||||
int responseCode = client.executeMethod(method);
|
|
||||||
if (responseCode != 200) {
|
|
||||||
error++;
|
|
||||||
logger.error("Can't create portForwarding network rule for the public port " + portValue + ". Request was sent with url " + url);
|
|
||||||
}
|
|
||||||
} catch (Exception ex) {
|
|
||||||
logger.error(ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (error != 0)
|
|
||||||
return false;
|
|
||||||
else
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,139 +0,0 @@
|
|||||||
// 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.test.regression;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileInputStream;
|
|
||||||
import java.sql.Connection;
|
|
||||||
import java.sql.DriverManager;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Enumeration;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Properties;
|
|
||||||
|
|
||||||
import javax.xml.parsers.DocumentBuilder;
|
|
||||||
import javax.xml.parsers.DocumentBuilderFactory;
|
|
||||||
|
|
||||||
import org.apache.commons.httpclient.HttpClient;
|
|
||||||
import org.apache.logging.log4j.Logger;
|
|
||||||
import org.apache.logging.log4j.LogManager;
|
|
||||||
import org.w3c.dom.Document;
|
|
||||||
|
|
||||||
public abstract class TestCase {
|
|
||||||
|
|
||||||
public static Logger LOGGER = LogManager.getLogger(TestCase.class.getName());
|
|
||||||
private Connection conn;
|
|
||||||
private ArrayList<Document> inputFile = new ArrayList<Document>();
|
|
||||||
private HttpClient client;
|
|
||||||
private String testCaseName;
|
|
||||||
private HashMap<String, String> param = new HashMap<String, String>();
|
|
||||||
private HashMap<String, String> commands = new HashMap<String, String>();
|
|
||||||
|
|
||||||
public HashMap<String, String> getParam() {
|
|
||||||
return param;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setParam(HashMap<String, String> param) {
|
|
||||||
this.param = param;
|
|
||||||
}
|
|
||||||
|
|
||||||
public HashMap<String, String> getCommands() {
|
|
||||||
return commands;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setCommands() {
|
|
||||||
File asyncCommands = null;
|
|
||||||
if (param.get("apicommands") == null) {
|
|
||||||
LOGGER.info("Unable to get the list of commands, exiting");
|
|
||||||
System.exit(1);
|
|
||||||
} else {
|
|
||||||
asyncCommands = new File(param.get("apicommands"));
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
Properties pro = new Properties();
|
|
||||||
FileInputStream in = new FileInputStream(asyncCommands);
|
|
||||||
pro.load(in);
|
|
||||||
Enumeration<?> en = pro.propertyNames();
|
|
||||||
while (en.hasMoreElements()) {
|
|
||||||
String key = (String)en.nextElement();
|
|
||||||
commands.put(key, pro.getProperty(key));
|
|
||||||
}
|
|
||||||
} catch (Exception ex) {
|
|
||||||
LOGGER.info("Unable to find the file " + param.get("apicommands") + " due to following exception " + ex);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public Connection getConn() {
|
|
||||||
return conn;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setConn(String dbPassword) {
|
|
||||||
this.conn = null;
|
|
||||||
try {
|
|
||||||
Class.forName("com.mysql.jdbc.Driver");
|
|
||||||
this.conn = DriverManager.getConnection("jdbc:mysql://" + param.get("db") + "/cloud?" + TransactionLegacy.CONNECTION_PARAMS, "root", dbPassword);
|
|
||||||
if (!this.conn.isValid(0)) {
|
|
||||||
LOGGER.error("Connection to DB failed to establish");
|
|
||||||
}
|
|
||||||
|
|
||||||
} catch (Exception ex) {
|
|
||||||
LOGGER.error(ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setInputFile(ArrayList<String> fileNameInput) {
|
|
||||||
for (String fileName : fileNameInput) {
|
|
||||||
File file = new File(fileName);
|
|
||||||
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
|
|
||||||
Document doc = null;
|
|
||||||
try {
|
|
||||||
DocumentBuilder builder = factory.newDocumentBuilder();
|
|
||||||
doc = builder.parse(file);
|
|
||||||
doc.getDocumentElement().normalize();
|
|
||||||
} catch (Exception ex) {
|
|
||||||
LOGGER.error("Unable to load " + fileName + " due to ", ex);
|
|
||||||
}
|
|
||||||
this.inputFile.add(doc);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public ArrayList<Document> getInputFile() {
|
|
||||||
return inputFile;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setTestCaseName(String testCaseName) {
|
|
||||||
this.testCaseName = testCaseName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getTestCaseName() {
|
|
||||||
return this.testCaseName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setClient() {
|
|
||||||
HttpClient client = new HttpClient();
|
|
||||||
this.client = client;
|
|
||||||
}
|
|
||||||
|
|
||||||
public HttpClient getClient() {
|
|
||||||
return this.client;
|
|
||||||
}
|
|
||||||
|
|
||||||
//abstract methods
|
|
||||||
public abstract boolean executeTest();
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,276 +0,0 @@
|
|||||||
// 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.test.regression;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Random;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import javax.xml.parsers.DocumentBuilder;
|
|
||||||
import javax.xml.parsers.DocumentBuilderFactory;
|
|
||||||
|
|
||||||
import org.apache.logging.log4j.Logger;
|
|
||||||
import org.apache.logging.log4j.LogManager;
|
|
||||||
import org.w3c.dom.Document;
|
|
||||||
import org.w3c.dom.Element;
|
|
||||||
import org.w3c.dom.Node;
|
|
||||||
import org.w3c.dom.NodeList;
|
|
||||||
|
|
||||||
public class TestCaseEngine {
|
|
||||||
|
|
||||||
protected Logger logger = LogManager.getLogger(getClass());
|
|
||||||
public static String s_fileName = "../metadata/adapter.xml";
|
|
||||||
public static HashMap<String, String> s_globalParameters = new HashMap<String, String>();
|
|
||||||
protected static HashMap<String, String> s_componentMap = new HashMap<String, String>();
|
|
||||||
protected static HashMap<String, ArrayList<String>> s_inputFile = new HashMap<String, ArrayList<String>>();
|
|
||||||
protected static String s_testCaseName = new String();
|
|
||||||
protected static ArrayList<String> s_keys = new ArrayList<String>();
|
|
||||||
private static ThreadLocal<Object> s_result = new ThreadLocal<Object>();
|
|
||||||
public static int s_numThreads = 1;
|
|
||||||
public static boolean s_repeat = false;
|
|
||||||
public static boolean s_printUrl = false;
|
|
||||||
public static String s_type = "All";
|
|
||||||
public static boolean s_isSanity = false;
|
|
||||||
public static boolean s_isRegression = false;
|
|
||||||
private static int s_failure = 0;
|
|
||||||
|
|
||||||
public static void main(String args[]) {
|
|
||||||
|
|
||||||
// Parameters
|
|
||||||
List<String> argsList = Arrays.asList(args);
|
|
||||||
Iterator<String> iter = argsList.iterator();
|
|
||||||
while (iter.hasNext()) {
|
|
||||||
String arg = iter.next();
|
|
||||||
// is stress?
|
|
||||||
if (arg.equals("-t")) {
|
|
||||||
s_numThreads = Integer.parseInt(iter.next());
|
|
||||||
}
|
|
||||||
// do you want to print url for all commands?
|
|
||||||
if (arg.equals("-p")) {
|
|
||||||
s_printUrl = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
//type of the test: sanity, regression, all (default)
|
|
||||||
if (arg.equals("-type")) {
|
|
||||||
s_type = iter.next();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (arg.equals("-repeat")) {
|
|
||||||
s_repeat = Boolean.valueOf(iter.next());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (arg.equals("-filename")) {
|
|
||||||
s_fileName = iter.next();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (s_type.equalsIgnoreCase("sanity"))
|
|
||||||
s_isSanity = true;
|
|
||||||
else if (s_type.equalsIgnoreCase("regression"))
|
|
||||||
s_isRegression = true;
|
|
||||||
|
|
||||||
try {
|
|
||||||
// parse adapter.xml file to get list of tests to execute
|
|
||||||
File file = new File(s_fileName);
|
|
||||||
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
|
|
||||||
DocumentBuilder builder = factory.newDocumentBuilder();
|
|
||||||
Document doc = builder.parse(file);
|
|
||||||
doc.getDocumentElement().normalize();
|
|
||||||
Element root = doc.getDocumentElement();
|
|
||||||
|
|
||||||
// set global parameters
|
|
||||||
setGlobalParams(root);
|
|
||||||
|
|
||||||
// populate _componentMap
|
|
||||||
setComponent(root);
|
|
||||||
|
|
||||||
// set error to 0 by default
|
|
||||||
|
|
||||||
// execute test
|
|
||||||
for (int i = 0; i < s_numThreads; i++) {
|
|
||||||
if (s_numThreads > 1) {
|
|
||||||
logger.info("STARTING STRESS TEST IN " + s_numThreads + " THREADS");
|
|
||||||
} else {
|
|
||||||
logger.info("STARTING FUNCTIONAL TEST");
|
|
||||||
}
|
|
||||||
new Thread(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
do {
|
|
||||||
if (s_numThreads == 1) {
|
|
||||||
try {
|
|
||||||
for (String key : s_keys) {
|
|
||||||
Class<?> c = Class.forName(s_componentMap.get(key));
|
|
||||||
TestCase component = (TestCase)c.newInstance();
|
|
||||||
executeTest(key, c, component);
|
|
||||||
}
|
|
||||||
} catch (Exception ex1) {
|
|
||||||
logger.error(ex1);
|
|
||||||
} finally {
|
|
||||||
if (s_failure > 0) {
|
|
||||||
System.exit(1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
Random ran = new Random();
|
|
||||||
Integer randomNumber = Math.abs(ran.nextInt(s_keys.size()));
|
|
||||||
try {
|
|
||||||
String key = s_keys.get(randomNumber);
|
|
||||||
Class<?> c = Class.forName(s_componentMap.get(key));
|
|
||||||
TestCase component = (TestCase)c.newInstance();
|
|
||||||
executeTest(key, c, component);
|
|
||||||
} catch (Exception e) {
|
|
||||||
logger.error("Error in thread ", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} while (s_repeat);
|
|
||||||
}
|
|
||||||
}).start();
|
|
||||||
}
|
|
||||||
|
|
||||||
} catch (Exception exc) {
|
|
||||||
logger.error(exc);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void setGlobalParams(Element rootElement) {
|
|
||||||
NodeList globalParam = rootElement.getElementsByTagName("globalparam");
|
|
||||||
Element parameter = (Element)globalParam.item(0);
|
|
||||||
NodeList paramLst = parameter.getElementsByTagName("param");
|
|
||||||
|
|
||||||
for (int i = 0; i < paramLst.getLength(); i++) {
|
|
||||||
Element paramElement = (Element)paramLst.item(i);
|
|
||||||
|
|
||||||
if (paramElement.getNodeType() == Node.ELEMENT_NODE) {
|
|
||||||
Element itemElement = paramElement;
|
|
||||||
NodeList itemName = itemElement.getElementsByTagName("name");
|
|
||||||
Element itemNameElement = (Element)itemName.item(0);
|
|
||||||
NodeList itemVariable = itemElement.getElementsByTagName("variable");
|
|
||||||
Element itemVariableElement = (Element)itemVariable.item(0);
|
|
||||||
s_globalParameters.put(itemVariableElement.getTextContent(), itemNameElement.getTextContent());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void setComponent(Element rootElement) {
|
|
||||||
NodeList testLst = rootElement.getElementsByTagName("test");
|
|
||||||
for (int j = 0; j < testLst.getLength(); j++) {
|
|
||||||
Element testElement = (Element)testLst.item(j);
|
|
||||||
|
|
||||||
if (testElement.getNodeType() == Node.ELEMENT_NODE) {
|
|
||||||
Element itemElement = testElement;
|
|
||||||
|
|
||||||
// get test case name
|
|
||||||
NodeList testCaseNameList = itemElement.getElementsByTagName("testname");
|
|
||||||
if (testCaseNameList != null) {
|
|
||||||
s_testCaseName = ((Element)testCaseNameList.item(0)).getTextContent();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (s_isSanity == true && !s_testCaseName.equals("SANITY TEST"))
|
|
||||||
continue;
|
|
||||||
else if (s_isRegression == true && !(s_testCaseName.equals("SANITY TEST") || s_testCaseName.equals("REGRESSION TEST")))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
// set class name
|
|
||||||
NodeList className = itemElement.getElementsByTagName("class");
|
|
||||||
if ((className.getLength() == 0) || (className == null)) {
|
|
||||||
s_componentMap.put(s_testCaseName, "com.cloud.test.regression.VMApiTest");
|
|
||||||
} else {
|
|
||||||
String name = ((Element)className.item(0)).getTextContent();
|
|
||||||
s_componentMap.put(s_testCaseName, name);
|
|
||||||
}
|
|
||||||
|
|
||||||
// set input file name
|
|
||||||
NodeList inputFileNameLst = itemElement.getElementsByTagName("filename");
|
|
||||||
s_inputFile.put(s_testCaseName, new ArrayList<String>());
|
|
||||||
for (int k = 0; k < inputFileNameLst.getLength(); k++) {
|
|
||||||
String inputFileName = ((Element)inputFileNameLst.item(k)).getTextContent();
|
|
||||||
s_inputFile.get(s_testCaseName).add(inputFileName);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//If sanity test required, make sure that SANITY TEST componennt got loaded
|
|
||||||
if (s_isSanity == true && s_componentMap.size() == 0) {
|
|
||||||
logger.error("FAILURE!!! Failed to load SANITY TEST component. Verify that the test is uncommented in adapter.xml");
|
|
||||||
System.exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (s_isRegression == true && s_componentMap.size() != 2) {
|
|
||||||
logger.error("FAILURE!!! Failed to load SANITY TEST or REGRESSION TEST components. Verify that these tests are uncommented in adapter.xml");
|
|
||||||
System.exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
// put all keys from _componentMap to the ArrayList
|
|
||||||
Set<?> set = s_componentMap.entrySet();
|
|
||||||
Iterator<?> it = set.iterator();
|
|
||||||
while (it.hasNext()) {
|
|
||||||
Map.Entry<?, ?> me = (Map.Entry<?, ?>)it.next();
|
|
||||||
String key = (String)me.getKey();
|
|
||||||
s_keys.add(key);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean executeTest(String key, Class<?> c, TestCase component) {
|
|
||||||
boolean finalResult = false;
|
|
||||||
try {
|
|
||||||
logger.info("Starting \"" + key + "\" test...\n\n");
|
|
||||||
|
|
||||||
// set global parameters
|
|
||||||
HashMap<String, String> updateParam = new HashMap<String, String>();
|
|
||||||
updateParam.putAll(s_globalParameters);
|
|
||||||
component.setParam(updateParam);
|
|
||||||
|
|
||||||
// set DB ip address
|
|
||||||
component.setConn(s_globalParameters.get("dbPassword"));
|
|
||||||
|
|
||||||
// set commands list
|
|
||||||
component.setCommands();
|
|
||||||
|
|
||||||
// set input file
|
|
||||||
if (s_inputFile.get(key) != null) {
|
|
||||||
component.setInputFile(s_inputFile.get(key));
|
|
||||||
}
|
|
||||||
|
|
||||||
// set test case name
|
|
||||||
if (key != null) {
|
|
||||||
component.setTestCaseName(s_testCaseName);
|
|
||||||
}
|
|
||||||
|
|
||||||
// execute method
|
|
||||||
s_result.set(component.executeTest());
|
|
||||||
if (s_result.get().toString().equals("false")) {
|
|
||||||
logger.error("FAILURE!!! Test \"" + key + "\" failed\n\n\n");
|
|
||||||
s_failure++;
|
|
||||||
} else {
|
|
||||||
finalResult = true;
|
|
||||||
logger.info("SUCCESS!!! Test \"" + key + "\" passed\n\n\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
} catch (Exception ex) {
|
|
||||||
logger.error("error during test execution ", ex);
|
|
||||||
}
|
|
||||||
return finalResult;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,89 +0,0 @@
|
|||||||
// 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.test.regression;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
|
|
||||||
import org.w3c.dom.Element;
|
|
||||||
import org.w3c.dom.Node;
|
|
||||||
import org.w3c.dom.NodeList;
|
|
||||||
|
|
||||||
import com.cloud.test.regression.ApiCommand.ResponseType;
|
|
||||||
|
|
||||||
public class VMApiTest extends TestCase {
|
|
||||||
|
|
||||||
public VMApiTest() {
|
|
||||||
this.setClient();
|
|
||||||
this.setParam(new HashMap<String, String>());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean executeTest() {
|
|
||||||
int error = 0;
|
|
||||||
Element rootElement = this.getInputFile().get(0).getDocumentElement();
|
|
||||||
NodeList commandLst = rootElement.getElementsByTagName("command");
|
|
||||||
|
|
||||||
//Analyze each command, send request and build the array list of api commands
|
|
||||||
for (int i = 0; i < commandLst.getLength(); i++) {
|
|
||||||
Node fstNode = commandLst.item(i);
|
|
||||||
Element fstElmnt = (Element)fstNode;
|
|
||||||
|
|
||||||
//new command
|
|
||||||
ApiCommand api = new ApiCommand(fstElmnt, this.getParam(), this.getCommands());
|
|
||||||
|
|
||||||
//send a command
|
|
||||||
api.sendCommand(this.getClient(), this.getConn());
|
|
||||||
|
|
||||||
//verify the response of the command
|
|
||||||
if ((api.getResponseType() == ResponseType.ERROR) && (api.getResponseCode() == 200)) {
|
|
||||||
logger.error("Test case " + api.getTestCaseInfo() + " failed. Command that was supposed to fail, passed. The command was sent with the following url " +
|
|
||||||
api.getUrl());
|
|
||||||
error++;
|
|
||||||
} else if ((api.getResponseType() != ResponseType.ERROR) && (api.getResponseCode() == 200)) {
|
|
||||||
//set parameters for the future use
|
|
||||||
if (api.setParam(this.getParam()) == false) {
|
|
||||||
logger.error("Exiting the test...Command " + api.getName() + " didn't return parameters needed for the future use. The command was sent with url " +
|
|
||||||
api.getUrl());
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
//verify parameters
|
|
||||||
if (api.verifyParam() == false) {
|
|
||||||
logger.error("Test " + api.getTestCaseInfo() + " failed. Verification for returned parameters failed. The command was sent with url " +
|
|
||||||
api.getUrl());
|
|
||||||
error++;
|
|
||||||
} else {
|
|
||||||
logger.info("Test " + api.getTestCaseInfo() + " passed");
|
|
||||||
}
|
|
||||||
} else if ((api.getResponseType() != ResponseType.ERROR) && (api.getResponseCode() != 200)) {
|
|
||||||
logger.error("Test case " + api.getTestCaseInfo() + " failed with an error code " + api.getResponseCode() + " . Command was sent with url " +
|
|
||||||
api.getUrl());
|
|
||||||
if (api.getRequired() == true) {
|
|
||||||
logger.info("The command is required for the future use, so exiging");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
error++;
|
|
||||||
} else if (api.getTestCaseInfo() != null) {
|
|
||||||
logger.info("Test case " + api.getTestCaseInfo() + " passed");
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (error != 0)
|
|
||||||
return false;
|
|
||||||
else
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,91 +0,0 @@
|
|||||||
// 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.test.stress;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.apache.logging.log4j.Logger;
|
|
||||||
import org.apache.logging.log4j.LogManager;
|
|
||||||
|
|
||||||
import com.trilead.ssh2.Connection;
|
|
||||||
import com.trilead.ssh2.Session;
|
|
||||||
|
|
||||||
public class SshTest {
|
|
||||||
|
|
||||||
protected Logger logger = LogManager.getLogger(getClass());
|
|
||||||
public static String host = "";
|
|
||||||
public static String password = "password";
|
|
||||||
public static String url = "http://google.com";
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
|
||||||
|
|
||||||
// Parameters
|
|
||||||
List<String> argsList = Arrays.asList(args);
|
|
||||||
Iterator<String> iter = argsList.iterator();
|
|
||||||
while (iter.hasNext()) {
|
|
||||||
String arg = iter.next();
|
|
||||||
if (arg.equals("-h")) {
|
|
||||||
host = iter.next();
|
|
||||||
}
|
|
||||||
if (arg.equals("-p")) {
|
|
||||||
password = iter.next();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (arg.equals("-u")) {
|
|
||||||
url = iter.next();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (host == null || host.equals("")) {
|
|
||||||
logger.info("Did not receive a host back from test, ignoring ssh test");
|
|
||||||
System.exit(2);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (password == null) {
|
|
||||||
logger.info("Did not receive a password back from test, ignoring ssh test");
|
|
||||||
System.exit(2);
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
logger.info("Attempting to SSH into host " + host);
|
|
||||||
Connection conn = new Connection(host);
|
|
||||||
conn.connect(null, 60000, 60000);
|
|
||||||
|
|
||||||
logger.info("User + ssHed successfully into host " + host);
|
|
||||||
|
|
||||||
boolean isAuthenticated = conn.authenticateWithPassword("root", password);
|
|
||||||
|
|
||||||
if (isAuthenticated == false) {
|
|
||||||
logger.info("Authentication failed for root with password" + password);
|
|
||||||
System.exit(2);
|
|
||||||
}
|
|
||||||
|
|
||||||
String linuxCommand = "wget " + url;
|
|
||||||
Session sess = conn.openSession();
|
|
||||||
sess.execCommand(linuxCommand);
|
|
||||||
sess.close();
|
|
||||||
conn.close();
|
|
||||||
|
|
||||||
} catch (Exception e) {
|
|
||||||
logger.error("SSH test fail with error", e);
|
|
||||||
System.exit(2);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -1,151 +0,0 @@
|
|||||||
// 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.test.stress;
|
|
||||||
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.apache.logging.log4j.Logger;
|
|
||||||
import org.apache.logging.log4j.LogManager;
|
|
||||||
|
|
||||||
import com.trilead.ssh2.ChannelCondition;
|
|
||||||
import com.trilead.ssh2.Connection;
|
|
||||||
import com.trilead.ssh2.Session;
|
|
||||||
|
|
||||||
public class WgetTest {
|
|
||||||
|
|
||||||
public static final int MAX_RETRY_LINUX = 1;
|
|
||||||
protected Logger logger = LogManager.getLogger(getClass());
|
|
||||||
public static String host = "";
|
|
||||||
public static String password = "rs-ccb35ea5";
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
|
||||||
|
|
||||||
// Parameters
|
|
||||||
List<String> argsList = Arrays.asList(args);
|
|
||||||
Iterator<String> iter = argsList.iterator();
|
|
||||||
while (iter.hasNext()) {
|
|
||||||
String arg = iter.next();
|
|
||||||
// host
|
|
||||||
if (arg.equals("-h")) {
|
|
||||||
host = iter.next();
|
|
||||||
}
|
|
||||||
//password
|
|
||||||
|
|
||||||
if (arg.equals("-p")) {
|
|
||||||
password = iter.next();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
int i = 0;
|
|
||||||
if (host == null || host.equals("")) {
|
|
||||||
logger.info("Did not receive a host back from test, ignoring ssh test");
|
|
||||||
System.exit(2);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (password == null) {
|
|
||||||
logger.info("Did not receive a password back from test, ignoring ssh test");
|
|
||||||
System.exit(2);
|
|
||||||
}
|
|
||||||
int retry = 0;
|
|
||||||
|
|
||||||
try {
|
|
||||||
if (retry > 0) {
|
|
||||||
logger.info("Retry attempt : " + retry + " ...sleeping 120 seconds before next attempt");
|
|
||||||
Thread.sleep(120000);
|
|
||||||
}
|
|
||||||
|
|
||||||
logger.info("Attempting to SSH into linux host " + host + " with retry attempt: " + retry);
|
|
||||||
|
|
||||||
Connection conn = new Connection(host);
|
|
||||||
conn.connect(null, 60000, 60000);
|
|
||||||
|
|
||||||
logger.info("User + ssHed successfully into linux host " + host);
|
|
||||||
|
|
||||||
boolean isAuthenticated = conn.authenticateWithPassword("root", password);
|
|
||||||
|
|
||||||
if (isAuthenticated == false) {
|
|
||||||
logger.info("Authentication failed for root with password" + password);
|
|
||||||
System.exit(2);
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean success = false;
|
|
||||||
String linuxCommand = null;
|
|
||||||
|
|
||||||
if (i % 10 == 0)
|
|
||||||
linuxCommand = "rm -rf *; wget http://192.168.1.250/dump.bin && ls -al dump.bin";
|
|
||||||
else
|
|
||||||
linuxCommand = "wget http://192.168.1.250/dump.bin && ls -al dump.bin";
|
|
||||||
|
|
||||||
Session sess = conn.openSession();
|
|
||||||
sess.execCommand(linuxCommand);
|
|
||||||
|
|
||||||
InputStream stdout = sess.getStdout();
|
|
||||||
InputStream stderr = sess.getStderr();
|
|
||||||
|
|
||||||
byte[] buffer = new byte[8192];
|
|
||||||
while (true) {
|
|
||||||
if ((stdout.available() == 0) && (stderr.available() == 0)) {
|
|
||||||
int conditions = sess.waitForCondition(ChannelCondition.STDOUT_DATA | ChannelCondition.STDERR_DATA | ChannelCondition.EOF, 120000);
|
|
||||||
|
|
||||||
if ((conditions & ChannelCondition.TIMEOUT) != 0) {
|
|
||||||
logger.info("Timeout while waiting for data from peer.");
|
|
||||||
System.exit(2);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((conditions & ChannelCondition.EOF) != 0) {
|
|
||||||
if ((conditions & (ChannelCondition.STDOUT_DATA | ChannelCondition.STDERR_DATA)) == 0) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
while (stdout.available() > 0) {
|
|
||||||
success = true;
|
|
||||||
int len = stdout.read(buffer);
|
|
||||||
if (len > 0) // this check is somewhat paranoid
|
|
||||||
logger.info(new String(buffer, 0, len));
|
|
||||||
}
|
|
||||||
|
|
||||||
while (stderr.available() > 0) {
|
|
||||||
/* int len = */stderr.read(buffer);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
sess.close();
|
|
||||||
conn.close();
|
|
||||||
|
|
||||||
if (!success) {
|
|
||||||
retry++;
|
|
||||||
if (retry == MAX_RETRY_LINUX) {
|
|
||||||
System.exit(2);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
retry++;
|
|
||||||
logger.error("SSH Linux Network test fail with error");
|
|
||||||
if (retry == MAX_RETRY_LINUX) {
|
|
||||||
logger.error("Ssh test failed");
|
|
||||||
System.exit(2);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,55 +0,0 @@
|
|||||||
// 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.test.ui;
|
|
||||||
|
|
||||||
import org.junit.AfterClass;
|
|
||||||
import org.junit.BeforeClass;
|
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.junit.runners.JUnit4;
|
|
||||||
import org.openqa.selenium.server.RemoteControlConfiguration;
|
|
||||||
import org.openqa.selenium.server.SeleniumServer;
|
|
||||||
|
|
||||||
import com.thoughtworks.selenium.DefaultSelenium;
|
|
||||||
|
|
||||||
@RunWith(JUnit4.class)
|
|
||||||
public abstract class AbstractSeleniumTestCase {
|
|
||||||
protected static DefaultSelenium selenium;
|
|
||||||
private static SeleniumServer seleniumServer;
|
|
||||||
|
|
||||||
@BeforeClass
|
|
||||||
public static void setUp() throws Exception {
|
|
||||||
System.out.println("*** Starting selenium ... ***");
|
|
||||||
RemoteControlConfiguration seleniumConfig = new RemoteControlConfiguration();
|
|
||||||
seleniumConfig.setPort(4444);
|
|
||||||
seleniumServer = new SeleniumServer(seleniumConfig);
|
|
||||||
seleniumServer.start();
|
|
||||||
|
|
||||||
String host = System.getProperty("myParam", "localhost");
|
|
||||||
selenium = createSeleniumClient("http://" + host + ":" + "8080/client/");
|
|
||||||
selenium.start();
|
|
||||||
System.out.println("*** Started selenium ***");
|
|
||||||
}
|
|
||||||
|
|
||||||
@AfterClass
|
|
||||||
public static void tearDown() throws Exception {
|
|
||||||
selenium.stop();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected static DefaultSelenium createSeleniumClient(String url) throws Exception {
|
|
||||||
return new DefaultSelenium("localhost", 4444, "*firefox", url);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,127 +0,0 @@
|
|||||||
// 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.test.ui;
|
|
||||||
|
|
||||||
import static org.junit.Assert.assertTrue;
|
|
||||||
import static org.junit.Assert.fail;
|
|
||||||
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import com.thoughtworks.selenium.SeleniumException;
|
|
||||||
|
|
||||||
public class AddAndDeleteAISO extends AbstractSeleniumTestCase {
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testAddAndDeleteISO() throws Exception {
|
|
||||||
try {
|
|
||||||
selenium.open("/client/");
|
|
||||||
selenium.type("account_username", "admin");
|
|
||||||
selenium.type("account_password", "password");
|
|
||||||
selenium.click("loginbutton");
|
|
||||||
Thread.sleep(3000);
|
|
||||||
assertTrue(selenium.isTextPresent("admin"));
|
|
||||||
selenium.click("//div[@id='leftmenu_templates']/div");
|
|
||||||
selenium.click("//div[@id='leftmenu_submenu_my_iso']/div/div[2]");
|
|
||||||
Thread.sleep(3000);
|
|
||||||
selenium.click("label");
|
|
||||||
|
|
||||||
selenium.type("add_iso_name", "abc");
|
|
||||||
selenium.type("add_iso_display_text", "abc");
|
|
||||||
String iso_url = System.getProperty("add_iso_url", "http://10.91.28.6/ISO/Fedora-11-i386-DVD.iso");
|
|
||||||
selenium.type("add_iso_url", iso_url);
|
|
||||||
String iso_zone = System.getProperty("add_iso_zone", "All Zones");
|
|
||||||
selenium.select("add_iso_zone", "label=" + iso_zone);
|
|
||||||
String iso_os_type = System.getProperty("add_iso_os_type", "Fedora 11");
|
|
||||||
selenium.select("add_iso_os_type", "label=" + iso_os_type);
|
|
||||||
selenium.click("//div[28]/div[11]/button[1]");
|
|
||||||
Thread.sleep(3000);
|
|
||||||
int i = 1;
|
|
||||||
try {
|
|
||||||
for (;; i++) {
|
|
||||||
System.out.println("i= " + i);
|
|
||||||
selenium.click("//div[" + i + "]/div/div[2]/span/span");
|
|
||||||
}
|
|
||||||
} catch (Exception ex) {
|
|
||||||
logger.info("[ignored]"
|
|
||||||
+ "error during clicking test on iso: " + e.getLocalizedMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int second = 0;; second++) {
|
|
||||||
if (second >= 60)
|
|
||||||
fail("timeout");
|
|
||||||
try {
|
|
||||||
if (selenium.isVisible("//div[@id='after_action_info_container_on_top']"))
|
|
||||||
break;
|
|
||||||
} catch (Exception e) {
|
|
||||||
logger.info("[ignored]"
|
|
||||||
+ "error during visibility test of iso: " + e.getLocalizedMessage());
|
|
||||||
}
|
|
||||||
Thread.sleep(10000);
|
|
||||||
}
|
|
||||||
|
|
||||||
assertTrue(selenium.isTextPresent("Adding succeeded"));
|
|
||||||
Thread.sleep(3000);
|
|
||||||
int status = 1;
|
|
||||||
while (!selenium.isTextPresent("Ready")) {
|
|
||||||
for (int j = 1; j <= i; j++)
|
|
||||||
|
|
||||||
{
|
|
||||||
if (selenium.isTextPresent("Ready")) {
|
|
||||||
status = 0;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
selenium.click("//div[" + j + "]/div/div[2]/span/span");
|
|
||||||
}
|
|
||||||
if (status == 0) {
|
|
||||||
break;
|
|
||||||
} else {
|
|
||||||
selenium.click("//div[@id='leftmenu_submenu_featured_iso']/div/div[2]");
|
|
||||||
Thread.sleep(3000);
|
|
||||||
selenium.click("//div[@id='leftmenu_submenu_my_iso']/div/div[2]");
|
|
||||||
Thread.sleep(3000);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
selenium.click("link=Delete ISO");
|
|
||||||
selenium.click("//div[28]/div[11]/button[1]");
|
|
||||||
for (int second = 0;; second++) {
|
|
||||||
if (second >= 60)
|
|
||||||
fail("timeout");
|
|
||||||
try {
|
|
||||||
if (selenium.isVisible("after_action_info_container_on_top"))
|
|
||||||
break;
|
|
||||||
} catch (Exception e) {
|
|
||||||
logger.info("[ignored]"
|
|
||||||
+ "error checking visibility after test completion for iso: " + e.getLocalizedMessage());
|
|
||||||
}
|
|
||||||
Thread.sleep(1000);
|
|
||||||
}
|
|
||||||
|
|
||||||
assertTrue(selenium.isTextPresent("Delete ISO action succeeded"));
|
|
||||||
selenium.click("main_logout");
|
|
||||||
selenium.waitForPageToLoad("30000");
|
|
||||||
assertTrue(selenium.isTextPresent("Welcome to Management Console"));
|
|
||||||
|
|
||||||
} catch (SeleniumException ex) {
|
|
||||||
|
|
||||||
System.err.println(ex.getMessage());
|
|
||||||
fail(ex.getMessage());
|
|
||||||
|
|
||||||
throw ex;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,126 +0,0 @@
|
|||||||
// 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.test.ui;
|
|
||||||
|
|
||||||
import static org.junit.Assert.assertTrue;
|
|
||||||
import static org.junit.Assert.fail;
|
|
||||||
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import com.thoughtworks.selenium.SeleniumException;
|
|
||||||
|
|
||||||
public class AddAndDeleteATemplate extends AbstractSeleniumTestCase {
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testAddAndDeleteTemplate() throws Exception {
|
|
||||||
try {
|
|
||||||
selenium.open("/client/");
|
|
||||||
selenium.type("account_username", "admin");
|
|
||||||
selenium.type("account_password", "password");
|
|
||||||
selenium.click("loginbutton");
|
|
||||||
Thread.sleep(3000);
|
|
||||||
assertTrue(selenium.isTextPresent("admin"));
|
|
||||||
selenium.click("//div[@id='leftmenu_templates']/div");
|
|
||||||
selenium.click("//div[@id='leftmenu_submenu_my_template']/div/div[2]");
|
|
||||||
Thread.sleep(3000);
|
|
||||||
selenium.click("label");
|
|
||||||
selenium.type("add_template_name", "abc");
|
|
||||||
selenium.type("add_template_display_text", "abc");
|
|
||||||
String template_url =
|
|
||||||
System.getProperty("add_template_url", "http://10.91.28.6/templates/centos53-x86_64/latest/f59f18fb-ae94-4f97-afd2-f84755767aca.vhd.bz2");
|
|
||||||
selenium.type("add_template_url", template_url);
|
|
||||||
String template_zone = System.getProperty("add_template_zone", "All Zones");
|
|
||||||
selenium.select("add_template_zone", "label=" + template_zone);
|
|
||||||
String template_os_type = System.getProperty("add_template_os_type", "CentOS 5.3 (32-bit)");
|
|
||||||
selenium.select("add_template_os_type", "label=" + template_os_type);
|
|
||||||
selenium.click("//div[28]/div[11]/button[1]");
|
|
||||||
Thread.sleep(3000);
|
|
||||||
int i = 1;
|
|
||||||
try {
|
|
||||||
for (;; i++) {
|
|
||||||
System.out.println("i= " + i);
|
|
||||||
selenium.click("//div[" + i + "]/div/div[2]/span/span");
|
|
||||||
}
|
|
||||||
} catch (Exception ex) {
|
|
||||||
logger.info("[ignored]"
|
|
||||||
+ "error during clicking test on template: " + ex.getLocalizedMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int second = 0;; second++) {
|
|
||||||
if (second >= 60)
|
|
||||||
fail("timeout");
|
|
||||||
try {
|
|
||||||
if (selenium.isVisible("//div[@id='after_action_info_container_on_top']"))
|
|
||||||
break;
|
|
||||||
} catch (Exception e) {
|
|
||||||
logger.info("[ignored]"
|
|
||||||
+ "error during visibility test of template: " + e.getLocalizedMessage());
|
|
||||||
}
|
|
||||||
Thread.sleep(10000);
|
|
||||||
}
|
|
||||||
|
|
||||||
assertTrue(selenium.isTextPresent("Adding succeeded"));
|
|
||||||
Thread.sleep(3000);
|
|
||||||
int status = 1;
|
|
||||||
while (!selenium.isTextPresent("Ready")) {
|
|
||||||
for (int j = 1; j <= i; j++)
|
|
||||||
|
|
||||||
{
|
|
||||||
if (selenium.isTextPresent("Ready")) {
|
|
||||||
status = 0;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
selenium.click("//div[" + j + "]/div/div[2]/span/span");
|
|
||||||
}
|
|
||||||
if (status == 0) {
|
|
||||||
break;
|
|
||||||
} else {
|
|
||||||
selenium.click("//div[@id='leftmenu_submenu_featured_template']/div/div[2]");
|
|
||||||
Thread.sleep(3000);
|
|
||||||
selenium.click("//div[@id='leftmenu_submenu_my_template']/div/div[2]");
|
|
||||||
Thread.sleep(3000);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
selenium.click("link=Delete Template");
|
|
||||||
selenium.click("//div[28]/div[11]/button[1]");
|
|
||||||
for (int second = 0;; second++) {
|
|
||||||
if (second >= 60)
|
|
||||||
fail("timeout");
|
|
||||||
try {
|
|
||||||
if (selenium.isVisible("after_action_info_container_on_top"))
|
|
||||||
break;
|
|
||||||
} catch (Exception e) {
|
|
||||||
logger.info("[ignored]"
|
|
||||||
+ "error checking visibility after test completion for template: " + e.getLocalizedMessage());
|
|
||||||
}
|
|
||||||
Thread.sleep(1000);
|
|
||||||
}
|
|
||||||
|
|
||||||
assertTrue(selenium.isTextPresent("Delete Template action succeeded"));
|
|
||||||
selenium.click("main_logout");
|
|
||||||
selenium.waitForPageToLoad("30000");
|
|
||||||
assertTrue(selenium.isTextPresent("Welcome to Management Console"));
|
|
||||||
} catch (SeleniumException ex) {
|
|
||||||
|
|
||||||
System.err.println(ex.getMessage());
|
|
||||||
fail(ex.getMessage());
|
|
||||||
|
|
||||||
throw ex;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,86 +0,0 @@
|
|||||||
// 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.test.ui;
|
|
||||||
|
|
||||||
import static org.junit.Assert.assertTrue;
|
|
||||||
import static org.junit.Assert.fail;
|
|
||||||
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import com.thoughtworks.selenium.SeleniumException;
|
|
||||||
|
|
||||||
public class UIScenarioTest extends AbstractSeleniumTestCase {
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testLoginStartStopVMScenario() throws Exception {
|
|
||||||
try {
|
|
||||||
selenium.open("/client/");
|
|
||||||
selenium.type("account_username", "admin");
|
|
||||||
selenium.type("account_password", "password");
|
|
||||||
selenium.click("loginbutton");
|
|
||||||
Thread.sleep(3000);
|
|
||||||
assertTrue(selenium.isTextPresent("admin"));
|
|
||||||
selenium.click("//div[@id='leftmenu_instances']/div");
|
|
||||||
selenium.click("//div[@id='leftmenu_instances_stopped_instances']/div/span");
|
|
||||||
|
|
||||||
Thread.sleep(3000);
|
|
||||||
selenium.click("//div[@id='midmenu_startvm_link']/div/div[2]");
|
|
||||||
selenium.click("//div[39]/div[11]/button[1]");
|
|
||||||
|
|
||||||
for (int second = 0;; second++) {
|
|
||||||
if (second >= 60)
|
|
||||||
fail("timeout");
|
|
||||||
try {
|
|
||||||
if (selenium.isVisible("//div/p[@id='after_action_info']"))
|
|
||||||
break;
|
|
||||||
} catch (Exception e) {
|
|
||||||
logger.info("[ignored]"
|
|
||||||
+ "error during visibility test after start vm: " + e.getLocalizedMessage());
|
|
||||||
}
|
|
||||||
Thread.sleep(10000);
|
|
||||||
}
|
|
||||||
assertTrue(selenium.isTextPresent("Start Instance action succeeded"));
|
|
||||||
selenium.click("//div[@id='leftmenu_instances_running_instances']/div/span");
|
|
||||||
|
|
||||||
Thread.sleep(3000);
|
|
||||||
selenium.click("//div[@id='midmenu_stopvm_link']/div/div[2]");
|
|
||||||
selenium.click("//div[39]/div[11]/button[1]");
|
|
||||||
for (int second = 0;; second++) {
|
|
||||||
if (second >= 60)
|
|
||||||
fail("timeout");
|
|
||||||
try {
|
|
||||||
if (selenium.isVisible("//div/p[@id='after_action_info']"))
|
|
||||||
break;
|
|
||||||
} catch (Exception e) {
|
|
||||||
logger.info("[ignored]"
|
|
||||||
+ "error during visibility test after stop vm: " + e.getLocalizedMessage());
|
|
||||||
}
|
|
||||||
Thread.sleep(10000);
|
|
||||||
}
|
|
||||||
|
|
||||||
assertTrue(selenium.isTextPresent("Stop Instance action succeeded"));
|
|
||||||
selenium.click("main_logout");
|
|
||||||
selenium.waitForPageToLoad("30000");
|
|
||||||
assertTrue(selenium.isTextPresent("Welcome to Management Console"));
|
|
||||||
|
|
||||||
} catch (SeleniumException ex) {
|
|
||||||
fail(ex.getMessage());
|
|
||||||
System.err.println(ex.getMessage());
|
|
||||||
throw ex;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,108 +0,0 @@
|
|||||||
// 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.test.utils;
|
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
|
|
||||||
import com.cloud.utils.script.OutputInterpreter;
|
|
||||||
import com.cloud.utils.script.Script;
|
|
||||||
|
|
||||||
public class ConsoleProxy implements Runnable {
|
|
||||||
public static String proxyIp;
|
|
||||||
private String command;
|
|
||||||
private int connectionsMade;
|
|
||||||
private long responseTime;
|
|
||||||
|
|
||||||
public ConsoleProxy(String port, String sid, String host) {
|
|
||||||
this.command = "https://" + proxyIp + ".realhostip.com:8000/getscreen?w=100&h=75&host=" + host + "&port=" + port + "&sid=" + sid;
|
|
||||||
logger.info("Command for a console proxy is " + this.command);
|
|
||||||
this.connectionsMade = 0;
|
|
||||||
this.responseTime = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getConnectionsMade() {
|
|
||||||
return this.connectionsMade;
|
|
||||||
}
|
|
||||||
|
|
||||||
public long getResponseTime() {
|
|
||||||
return this.responseTime;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
while (true) {
|
|
||||||
|
|
||||||
Script myScript = new Script("wget");
|
|
||||||
myScript.add(command);
|
|
||||||
myScript.execute();
|
|
||||||
long begin = System.currentTimeMillis();
|
|
||||||
WgetInt process = new WgetInt();
|
|
||||||
String response = myScript.execute(process);
|
|
||||||
long end = process.getEnd();
|
|
||||||
if (response != null) {
|
|
||||||
logger.info("Content lenght is incorrect: " + response);
|
|
||||||
}
|
|
||||||
|
|
||||||
long duration = (end - begin);
|
|
||||||
this.connectionsMade++;
|
|
||||||
this.responseTime = this.responseTime + duration;
|
|
||||||
try {
|
|
||||||
Thread.sleep(1000);
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
logger.debug("[ignored] interrupted.");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public class WgetInt extends OutputInterpreter {
|
|
||||||
private long end;
|
|
||||||
|
|
||||||
public long getEnd() {
|
|
||||||
return end;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setEnd(long end) {
|
|
||||||
this.end = end;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String interpret(BufferedReader reader) throws IOException {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
end = System.currentTimeMillis();
|
|
||||||
String status = null;
|
|
||||||
String line = null;
|
|
||||||
while ((line = reader.readLine()) != null) {
|
|
||||||
int index = line.indexOf("Length:");
|
|
||||||
if (index == -1) {
|
|
||||||
continue;
|
|
||||||
} else {
|
|
||||||
int index1 = line.indexOf("Length: 1827");
|
|
||||||
if (index1 == -1) {
|
|
||||||
return status;
|
|
||||||
} else
|
|
||||||
status = line;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
return status;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,89 +0,0 @@
|
|||||||
// 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.test.utils;
|
|
||||||
|
|
||||||
import java.io.DataOutputStream;
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileOutputStream;
|
|
||||||
import java.util.StringTokenizer;
|
|
||||||
|
|
||||||
public class IpSqlGenerator {
|
|
||||||
public static void main(String[] args) {
|
|
||||||
try {
|
|
||||||
if (args.length != 5) {
|
|
||||||
System.out.println("Usage -- generate-ip.sh <public|private> <begin ip range> <end ip range> <data center id> <pod id>");
|
|
||||||
System.out.println("Example -- generate-ip.sh public 192.168.1.1 192.168.1.255 1 1");
|
|
||||||
System.out.println(" will generate ips ranging from public ips 192.168.1.1 to 192.168.1.255 for dc 1 and pod 1");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
String type = args[0];
|
|
||||||
|
|
||||||
StringTokenizer st = new StringTokenizer(args[1], ".");
|
|
||||||
int ipS1 = Integer.parseInt(st.nextToken());
|
|
||||||
int ipS2 = Integer.parseInt(st.nextToken());
|
|
||||||
int ipS3 = Integer.parseInt(st.nextToken());
|
|
||||||
int ipS4 = Integer.parseInt(st.nextToken());
|
|
||||||
|
|
||||||
st = new StringTokenizer(args[2], ".");
|
|
||||||
int ipE1 = Integer.parseInt(st.nextToken());
|
|
||||||
int ipE2 = Integer.parseInt(st.nextToken());
|
|
||||||
int ipE3 = Integer.parseInt(st.nextToken());
|
|
||||||
int ipE4 = Integer.parseInt(st.nextToken());
|
|
||||||
|
|
||||||
String dcId = args[3];
|
|
||||||
String podId = args[4];
|
|
||||||
|
|
||||||
if (type.equals("private")) {
|
|
||||||
FileOutputStream fs = new FileOutputStream(new File("private-ips.sql"));
|
|
||||||
DataOutputStream out = new DataOutputStream(fs);
|
|
||||||
for (int i = ipS1; i <= ipE1; i++) {
|
|
||||||
for (int j = ipS2; j <= ipE2; j++) {
|
|
||||||
for (int k = ipS3; k <= ipE3; k++) {
|
|
||||||
for (int l = ipS4; l <= ipE4; l++) {
|
|
||||||
out.writeBytes("INSERT INTO `vmops`.`dc_ip_address_alloc` (ip_address, data_center_id, pod_id) VALUES ('" + i + "." + j + "." + k + "." +
|
|
||||||
l + "'," + dcId + "," + podId + ");\r\n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
out.writeBytes("\r\n");
|
|
||||||
out.flush();
|
|
||||||
out.close();
|
|
||||||
} else {
|
|
||||||
FileOutputStream fs = new FileOutputStream(new File("public-ips.sql"));
|
|
||||||
DataOutputStream out = new DataOutputStream(fs);
|
|
||||||
for (int i = ipS1; i <= ipE1; i++) {
|
|
||||||
for (int j = ipS2; j <= ipE2; j++) {
|
|
||||||
for (int k = ipS3; k <= ipE3; k++) {
|
|
||||||
for (int l = ipS4; l <= ipE4; l++) {
|
|
||||||
out.writeBytes("INSERT INTO `vmops`.`user_ip_address` (ip_address, data_center_id) VALUES ('" + i + "." + j + "." + k + "." + l + "'," +
|
|
||||||
dcId + ");\r\n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
out.writeBytes("\r\n");
|
|
||||||
out.flush();
|
|
||||||
out.close();
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
logger.info("[ignored]"
|
|
||||||
+ "error during ip insert generator: " + e.getLocalizedMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,110 +0,0 @@
|
|||||||
// 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.test.utils;
|
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
|
||||||
import java.io.FileReader;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
|
|
||||||
|
|
||||||
public class ProxyLoadTemp {
|
|
||||||
public static int numThreads = 0;
|
|
||||||
public static ArrayList<ConsoleProxy> proxyList = new ArrayList<ConsoleProxy>();
|
|
||||||
public static long begin;
|
|
||||||
public static long end;
|
|
||||||
public static long sum = 0;
|
|
||||||
|
|
||||||
public ProxyLoadTemp() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
|
||||||
begin = System.currentTimeMillis();
|
|
||||||
Runtime.getRuntime().addShutdownHook(new ShutdownThread(new ProxyLoadTemp()));
|
|
||||||
ConsoleProxy.proxyIp = "172-16-1-101";
|
|
||||||
|
|
||||||
try {
|
|
||||||
BufferedReader consoleInput = new BufferedReader(new FileReader("console.input"));
|
|
||||||
boolean eof = false;
|
|
||||||
logger.info("Started reading file");
|
|
||||||
while (!eof) {
|
|
||||||
String line = consoleInput.readLine();
|
|
||||||
logger.info("Line is " + line);
|
|
||||||
if (line == null) {
|
|
||||||
logger.info("Line " + numThreads + " is null");
|
|
||||||
eof = true;
|
|
||||||
} else {
|
|
||||||
String[] result = null;
|
|
||||||
try {
|
|
||||||
logger.info("Starting parsing line " + line);
|
|
||||||
result = parseLine(line, "[,]");
|
|
||||||
logger.info("Line retrieved from the file is " + result[0] + " " + result[1] + " " + result[2]);
|
|
||||||
ConsoleProxy proxy = new ConsoleProxy(result[0], result[1], result[2]);
|
|
||||||
proxyList.add(proxy);
|
|
||||||
new Thread(proxy).start();
|
|
||||||
numThreads++;
|
|
||||||
|
|
||||||
} catch (Exception ex) {
|
|
||||||
logger.warn(ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
logger.warn(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class ShutdownThread extends Thread {
|
|
||||||
ProxyLoadTemp temp;
|
|
||||||
|
|
||||||
public ShutdownThread(ProxyLoadTemp temp) {
|
|
||||||
this.temp = temp;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
logger.info("Program was running in " + numThreads + " threads");
|
|
||||||
|
|
||||||
for (int j = 0; j < proxyList.size(); j++) {
|
|
||||||
long av = 0;
|
|
||||||
if (proxyList.get(j).getConnectionsMade() != 0) {
|
|
||||||
av = proxyList.get(j).getResponseTime() / proxyList.get(j).getConnectionsMade();
|
|
||||||
}
|
|
||||||
logger.info("Information for " + j + " thread: Number of requests sent is " + proxyList.get(j).getConnectionsMade() + ". Average response time is " +
|
|
||||||
av + " milliseconds");
|
|
||||||
sum = sum + av;
|
|
||||||
|
|
||||||
}
|
|
||||||
ProxyLoadTemp.end = System.currentTimeMillis();
|
|
||||||
logger.info("Summary for all" + numThreads + " threads: Average response time is " + sum / numThreads + " milliseconds");
|
|
||||||
logger.info("Test was running for " + (ProxyLoadTemp.end - ProxyLoadTemp.begin) / 1000 + " seconds");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String[] parseLine(String line, String del) throws Exception {
|
|
||||||
String del1 = del.substring(1, del.length() - 1);
|
|
||||||
if (line.contains(del1) != true) {
|
|
||||||
throw new Exception();
|
|
||||||
} else {
|
|
||||||
String[] token = line.split(del);
|
|
||||||
return token;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,144 +0,0 @@
|
|||||||
// 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.test.utils;
|
|
||||||
|
|
||||||
import java.io.FileInputStream;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.net.URLEncoder;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Properties;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.StringTokenizer;
|
|
||||||
import java.util.TreeMap;
|
|
||||||
|
|
||||||
import org.apache.logging.log4j.Logger;
|
|
||||||
import org.apache.logging.log4j.LogManager;
|
|
||||||
|
|
||||||
public class SignEC2 {
|
|
||||||
public static String url;
|
|
||||||
public static String secretkey;
|
|
||||||
public static String host;
|
|
||||||
public static String port;
|
|
||||||
public static String command;
|
|
||||||
public static String accessPoint;
|
|
||||||
protected Logger logger = LogManager.getLogger(getClass());
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
|
||||||
// Parameters
|
|
||||||
List<String> argsList = Arrays.asList(args);
|
|
||||||
Iterator<String> iter = argsList.iterator();
|
|
||||||
while (iter.hasNext()) {
|
|
||||||
String arg = iter.next();
|
|
||||||
|
|
||||||
if (arg.equals("-u")) {
|
|
||||||
url = iter.next();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Properties prop = new Properties();
|
|
||||||
try {
|
|
||||||
prop.load(new FileInputStream("../conf/tool.properties"));
|
|
||||||
} catch (IOException ex) {
|
|
||||||
logger.error("Error reading from ../conf/tool.properties", ex);
|
|
||||||
System.exit(2);
|
|
||||||
}
|
|
||||||
|
|
||||||
host = prop.getProperty("host");
|
|
||||||
secretkey = prop.getProperty("secretkey");
|
|
||||||
port = prop.getProperty("port");
|
|
||||||
|
|
||||||
if (host == null) {
|
|
||||||
logger.info("Please set host in tool.properties file");
|
|
||||||
System.exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (port == null) {
|
|
||||||
logger.info("Please set port in tool.properties file");
|
|
||||||
System.exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (url == null) {
|
|
||||||
logger.info("Please specify url with -u option");
|
|
||||||
System.exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (secretkey == null) {
|
|
||||||
logger.info("Please set secretkey in tool.properties file");
|
|
||||||
System.exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (prop.get("apikey") == null) {
|
|
||||||
logger.info("Please set apikey in tool.properties file");
|
|
||||||
System.exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (prop.get("accesspoint") == null) {
|
|
||||||
logger.info("Please set apikey in tool.properties file");
|
|
||||||
System.exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
TreeMap<String, String> param = new TreeMap<String, String>();
|
|
||||||
|
|
||||||
String req = "GET\n" + host + ":" + prop.getProperty("port") + "\n/" + prop.getProperty("accesspoint") + "\n";
|
|
||||||
String temp = "";
|
|
||||||
param.put("AWSAccessKeyId", prop.getProperty("apikey"));
|
|
||||||
param.put("Expires", prop.getProperty("expires"));
|
|
||||||
param.put("SignatureMethod", "HmacSHA1");
|
|
||||||
param.put("SignatureVersion", "2");
|
|
||||||
param.put("Version", prop.getProperty("version"));
|
|
||||||
param.put("id", "1");
|
|
||||||
|
|
||||||
StringTokenizer str1 = new StringTokenizer(url, "&");
|
|
||||||
while (str1.hasMoreTokens()) {
|
|
||||||
String newEl = str1.nextToken();
|
|
||||||
StringTokenizer str2 = new StringTokenizer(newEl, "=");
|
|
||||||
String name = str2.nextToken();
|
|
||||||
String value = str2.nextToken();
|
|
||||||
param.put(name, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
//sort url hash map by key
|
|
||||||
Set c = param.entrySet();
|
|
||||||
Iterator it = c.iterator();
|
|
||||||
while (it.hasNext()) {
|
|
||||||
Map.Entry me = (Map.Entry)it.next();
|
|
||||||
String key = (String)me.getKey();
|
|
||||||
String value = (String)me.getValue();
|
|
||||||
try {
|
|
||||||
temp = temp + key + "=" + URLEncoder.encode(value, "UTF-8") + "&";
|
|
||||||
} catch (Exception ex) {
|
|
||||||
logger.error("Unable to set parameter " + value + " for the command " + param.get("command"));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
temp = temp.substring(0, temp.length() - 1);
|
|
||||||
String requestToSign = req + temp;
|
|
||||||
String signature = UtilsForTest.signRequest(requestToSign, secretkey);
|
|
||||||
String encodedSignature = "";
|
|
||||||
try {
|
|
||||||
encodedSignature = URLEncoder.encode(signature, "UTF-8");
|
|
||||||
} catch (Exception ex) {
|
|
||||||
logger.error(ex);
|
|
||||||
}
|
|
||||||
String url = "http://" + host + ":" + prop.getProperty("port") + "/" + prop.getProperty("accesspoint") + "?" + temp + "&Signature=" + encodedSignature;
|
|
||||||
logger.info("Url is " + url);
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,112 +0,0 @@
|
|||||||
// 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.test.utils;
|
|
||||||
|
|
||||||
import java.net.URLEncoder;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.StringTokenizer;
|
|
||||||
import java.util.TreeMap;
|
|
||||||
|
|
||||||
public class SignRequest {
|
|
||||||
public static String url;
|
|
||||||
public static String apikey;
|
|
||||||
public static String secretkey;
|
|
||||||
public static String command;
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
|
||||||
// Parameters
|
|
||||||
List<String> argsList = Arrays.asList(args);
|
|
||||||
Iterator<String> iter = argsList.iterator();
|
|
||||||
while (iter.hasNext()) {
|
|
||||||
String arg = iter.next();
|
|
||||||
if (arg.equals("-a")) {
|
|
||||||
apikey = iter.next();
|
|
||||||
|
|
||||||
}
|
|
||||||
if (arg.equals("-u")) {
|
|
||||||
url = iter.next();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (arg.equals("-s")) {
|
|
||||||
secretkey = iter.next();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (url == null) {
|
|
||||||
System.out.println("Please specify url with -u option. Example: -u \"command=listZones&id=1\"");
|
|
||||||
System.exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (apikey == null) {
|
|
||||||
System.out.println("Please specify apikey with -a option");
|
|
||||||
System.exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (secretkey == null) {
|
|
||||||
System.out.println("Please specify secretkey with -s option");
|
|
||||||
System.exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
TreeMap<String, String> param = new TreeMap<String, String>();
|
|
||||||
|
|
||||||
String temp = "";
|
|
||||||
param.put("apikey", apikey);
|
|
||||||
|
|
||||||
StringTokenizer str1 = new StringTokenizer(url, "&");
|
|
||||||
while (str1.hasMoreTokens()) {
|
|
||||||
String newEl = str1.nextToken();
|
|
||||||
StringTokenizer str2 = new StringTokenizer(newEl, "=");
|
|
||||||
String name = str2.nextToken();
|
|
||||||
String value = str2.nextToken();
|
|
||||||
param.put(name, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
//sort url hash map by key
|
|
||||||
Set c = param.entrySet();
|
|
||||||
Iterator it = c.iterator();
|
|
||||||
while (it.hasNext()) {
|
|
||||||
Map.Entry me = (Map.Entry)it.next();
|
|
||||||
String key = (String)me.getKey();
|
|
||||||
String value = (String)me.getValue();
|
|
||||||
try {
|
|
||||||
temp = temp + key + "=" + URLEncoder.encode(value, "UTF-8") + "&";
|
|
||||||
} catch (Exception ex) {
|
|
||||||
System.out.println("Unable to set parameter " + value + " for the command " + param.get("command"));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
temp = temp.substring(0, temp.length() - 1);
|
|
||||||
String requestToSign = temp.toLowerCase();
|
|
||||||
System.out.println("After sorting: " + requestToSign);
|
|
||||||
String signature = UtilsForTest.signRequest(requestToSign, secretkey);
|
|
||||||
System.out.println("After Base64 encoding: " + signature);
|
|
||||||
String encodedSignature = "";
|
|
||||||
try {
|
|
||||||
encodedSignature = URLEncoder.encode(signature, "UTF-8");
|
|
||||||
} catch (Exception ex) {
|
|
||||||
System.out.println(ex);
|
|
||||||
}
|
|
||||||
System.out.println("After UTF8 encoding: " + encodedSignature);
|
|
||||||
String url = temp + "&signature=" + encodedSignature;
|
|
||||||
System.out.println("After sort and add signature: " + url);
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,49 +0,0 @@
|
|||||||
// 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.test.utils;
|
|
||||||
|
|
||||||
import java.io.DataOutputStream;
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileOutputStream;
|
|
||||||
import java.util.Formatter;
|
|
||||||
|
|
||||||
public class SqlDataGenerator {
|
|
||||||
public static void main(String[] args) {
|
|
||||||
try {
|
|
||||||
FileOutputStream fs = new FileOutputStream(new File("out.txt"));
|
|
||||||
|
|
||||||
DataOutputStream out = new DataOutputStream(fs);
|
|
||||||
|
|
||||||
for (int i = 20; i < 171; i++) {
|
|
||||||
out.writeBytes("INSERT INTO `vmops`.`dc_ip_address_alloc` (ip_address, data_center_id, pod_id) VALUES ('192.168.2." + i + "',1,1);\r\n");
|
|
||||||
}
|
|
||||||
out.writeBytes("\r\n");
|
|
||||||
for (int i = 1; i < 10000; i++) {
|
|
||||||
StringBuilder imagePath = new StringBuilder();
|
|
||||||
Formatter formatter = new Formatter(imagePath);
|
|
||||||
formatter.format("%04x", i);
|
|
||||||
out.writeBytes("INSERT INTO `vmops`.`dc_vnet_alloc` (vnet, data_center_id) VALUES ('" + imagePath.toString() + "',1);\r\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
out.flush();
|
|
||||||
out.close();
|
|
||||||
} catch (Exception e) {
|
|
||||||
logger.info("[ignored]"
|
|
||||||
+ "error during sql generation: " + e.getLocalizedMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,199 +0,0 @@
|
|||||||
// 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.test.utils;
|
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
|
||||||
import java.io.FileInputStream;
|
|
||||||
import java.io.FileReader;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.net.URLEncoder;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Properties;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.StringTokenizer;
|
|
||||||
import java.util.TreeMap;
|
|
||||||
|
|
||||||
import org.apache.commons.httpclient.HttpClient;
|
|
||||||
import org.apache.commons.httpclient.HttpMethod;
|
|
||||||
import org.apache.commons.httpclient.methods.GetMethod;
|
|
||||||
import org.apache.logging.log4j.Logger;
|
|
||||||
import org.apache.logging.log4j.LogManager;
|
|
||||||
|
|
||||||
public class SubmitCert {
|
|
||||||
public static String url = "Action=SetCertificate";
|
|
||||||
public static String secretKey;
|
|
||||||
public static String apiKey;
|
|
||||||
public static String host;
|
|
||||||
public static String port;
|
|
||||||
public static String command;
|
|
||||||
public static String accessPoint;
|
|
||||||
public static String signatureMethod;
|
|
||||||
public static String fileName = "tool.properties";
|
|
||||||
public static String certFileName;
|
|
||||||
public static String cert;
|
|
||||||
protected Logger logger = LogManager.getLogger(getClass());
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
|
||||||
// Parameters
|
|
||||||
List<String> argsList = Arrays.asList(args);
|
|
||||||
Iterator<String> iter = argsList.iterator();
|
|
||||||
while (iter.hasNext()) {
|
|
||||||
String arg = iter.next();
|
|
||||||
|
|
||||||
if (arg.equals("-c")) {
|
|
||||||
certFileName = iter.next();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (arg.equals("-s")) {
|
|
||||||
secretKey = iter.next();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (arg.equals("-a")) {
|
|
||||||
apiKey = iter.next();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (arg.equals("-action")) {
|
|
||||||
url = "Action=" + iter.next();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Properties prop = new Properties();
|
|
||||||
try {
|
|
||||||
prop.load(new FileInputStream("conf/tool.properties"));
|
|
||||||
} catch (IOException ex) {
|
|
||||||
logger.error("Error reading from conf/tool.properties", ex);
|
|
||||||
System.exit(2);
|
|
||||||
}
|
|
||||||
|
|
||||||
host = prop.getProperty("host");
|
|
||||||
port = prop.getProperty("port");
|
|
||||||
|
|
||||||
if (url.equals("Action=SetCertificate") && certFileName == null) {
|
|
||||||
logger.error("Please set path to certificate (including file name) with -c option");
|
|
||||||
System.exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (secretKey == null) {
|
|
||||||
logger.error("Please set secretkey with -s option");
|
|
||||||
System.exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (apiKey == null) {
|
|
||||||
logger.error("Please set apikey with -a option");
|
|
||||||
System.exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (host == null) {
|
|
||||||
logger.error("Please set host in tool.properties file");
|
|
||||||
System.exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (port == null) {
|
|
||||||
logger.error("Please set port in tool.properties file");
|
|
||||||
System.exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
TreeMap<String, String> param = new TreeMap<String, String>();
|
|
||||||
|
|
||||||
String req = "GET\n" + host + ":" + prop.getProperty("port") + "\n/" + prop.getProperty("accesspoint") + "\n";
|
|
||||||
String temp = "";
|
|
||||||
|
|
||||||
if (certFileName != null) {
|
|
||||||
cert = readCert(certFileName);
|
|
||||||
param.put("cert", cert);
|
|
||||||
}
|
|
||||||
|
|
||||||
param.put("AWSAccessKeyId", apiKey);
|
|
||||||
param.put("Expires", prop.getProperty("expires"));
|
|
||||||
param.put("SignatureMethod", prop.getProperty("signaturemethod"));
|
|
||||||
param.put("SignatureVersion", "2");
|
|
||||||
param.put("Version", prop.getProperty("version"));
|
|
||||||
|
|
||||||
StringTokenizer str1 = new StringTokenizer(url, "&");
|
|
||||||
while (str1.hasMoreTokens()) {
|
|
||||||
String newEl = str1.nextToken();
|
|
||||||
StringTokenizer str2 = new StringTokenizer(newEl, "=");
|
|
||||||
String name = str2.nextToken();
|
|
||||||
String value = str2.nextToken();
|
|
||||||
param.put(name, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
//sort url hash map by key
|
|
||||||
Set c = param.entrySet();
|
|
||||||
Iterator it = c.iterator();
|
|
||||||
while (it.hasNext()) {
|
|
||||||
Map.Entry me = (Map.Entry)it.next();
|
|
||||||
String key = (String)me.getKey();
|
|
||||||
String value = (String)me.getValue();
|
|
||||||
try {
|
|
||||||
temp = temp + key + "=" + URLEncoder.encode(value, "UTF-8") + "&";
|
|
||||||
} catch (Exception ex) {
|
|
||||||
logger.error("Unable to set parameter " + value + " for the command " + param.get("command"), ex);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
temp = temp.substring(0, temp.length() - 1);
|
|
||||||
String requestToSign = req + temp;
|
|
||||||
String signature = UtilsForTest.signRequest(requestToSign, secretKey);
|
|
||||||
String encodedSignature = "";
|
|
||||||
try {
|
|
||||||
encodedSignature = URLEncoder.encode(signature, "UTF-8");
|
|
||||||
} catch (Exception ex) {
|
|
||||||
ex.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
String url = "http://" + host + ":" + prop.getProperty("port") + "/" + prop.getProperty("accesspoint") + "?" + temp + "&Signature=" + encodedSignature;
|
|
||||||
logger.info("Sending request with url: " + url + "\n");
|
|
||||||
sendRequest(url);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String readCert(String filePath) {
|
|
||||||
try {
|
|
||||||
StringBuffer fileData = new StringBuffer(1000);
|
|
||||||
BufferedReader reader = new BufferedReader(new FileReader(filePath));
|
|
||||||
char[] buf = new char[1024];
|
|
||||||
int numRead = 0;
|
|
||||||
while ((numRead = reader.read(buf)) != -1) {
|
|
||||||
String readData = String.valueOf(buf, 0, numRead);
|
|
||||||
fileData.append(readData);
|
|
||||||
buf = new char[1024];
|
|
||||||
}
|
|
||||||
reader.close();
|
|
||||||
return fileData.toString();
|
|
||||||
} catch (Exception ex) {
|
|
||||||
logger.error(ex);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void sendRequest(String url) {
|
|
||||||
try {
|
|
||||||
HttpClient client = new HttpClient();
|
|
||||||
HttpMethod method = new GetMethod(url);
|
|
||||||
int responseCode = client.executeMethod(method);
|
|
||||||
String is = method.getResponseBodyAsString();
|
|
||||||
logger.info("Response code " + responseCode + ": " + is);
|
|
||||||
} catch (Exception ex) {
|
|
||||||
ex.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,386 +0,0 @@
|
|||||||
// 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.test.utils;
|
|
||||||
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Random;
|
|
||||||
|
|
||||||
import org.apache.commons.httpclient.HttpClient;
|
|
||||||
import org.apache.commons.httpclient.HttpMethod;
|
|
||||||
import org.apache.commons.httpclient.methods.GetMethod;
|
|
||||||
import org.apache.logging.log4j.Logger;
|
|
||||||
import org.apache.logging.log4j.LogManager;
|
|
||||||
import org.apache.log4j.NDC;
|
|
||||||
|
|
||||||
import com.trilead.ssh2.ChannelCondition;
|
|
||||||
import com.trilead.ssh2.Connection;
|
|
||||||
import com.trilead.ssh2.SCPClient;
|
|
||||||
import com.trilead.ssh2.Session;
|
|
||||||
|
|
||||||
public class TestClient {
|
|
||||||
private static long sleepTime = 180000L; // default 0
|
|
||||||
private static boolean cleanUp = true;
|
|
||||||
protected Logger logger = LogManager.getLogger(getClass());
|
|
||||||
private static boolean repeat = true;
|
|
||||||
private static int numOfUsers = 0;
|
|
||||||
private static String[] users = null;
|
|
||||||
private static boolean internet = true;
|
|
||||||
|
|
||||||
private static final int MAX_RETRY_LINUX = 5;
|
|
||||||
private static final int MAX_RETRY_WIN = 10;
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
|
||||||
String host = "http://localhost";
|
|
||||||
String port = "8080";
|
|
||||||
String testUrl = "/client/test";
|
|
||||||
int numThreads = 1;
|
|
||||||
|
|
||||||
try {
|
|
||||||
// Parameters
|
|
||||||
List<String> argsList = Arrays.asList(args);
|
|
||||||
Iterator<String> iter = argsList.iterator();
|
|
||||||
while (iter.hasNext()) {
|
|
||||||
String arg = iter.next();
|
|
||||||
// host
|
|
||||||
if (arg.equals("-h")) {
|
|
||||||
host = "http://" + iter.next();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (arg.equals("-p")) {
|
|
||||||
port = iter.next();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (arg.equals("-t")) {
|
|
||||||
numThreads = Integer.parseInt(iter.next());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (arg.equals("-s")) {
|
|
||||||
sleepTime = Long.parseLong(iter.next());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (arg.equals("-c")) {
|
|
||||||
cleanUp = Boolean.parseBoolean(iter.next());
|
|
||||||
if (!cleanUp)
|
|
||||||
sleepTime = 0L; // no need to wait if we don't ever cleanup
|
|
||||||
}
|
|
||||||
|
|
||||||
if (arg.equals("-r")) {
|
|
||||||
repeat = Boolean.parseBoolean(iter.next());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (arg.equals("-u")) {
|
|
||||||
numOfUsers = Integer.parseInt(iter.next());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (arg.equals("-i")) {
|
|
||||||
internet = Boolean.parseBoolean(iter.next());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
final String server = host + ":" + port + testUrl;
|
|
||||||
logger.info("Starting test against server: " + server + " with " + numThreads + " thread(s)");
|
|
||||||
if (cleanUp)
|
|
||||||
logger.info("Clean up is enabled, each test will wait " + sleepTime + " ms before cleaning up");
|
|
||||||
|
|
||||||
if (numOfUsers > 0) {
|
|
||||||
logger.info("Pre-generating users for test of size : " + numOfUsers);
|
|
||||||
users = new String[numOfUsers];
|
|
||||||
Random ran = new Random();
|
|
||||||
for (int i = 0; i < numOfUsers; i++) {
|
|
||||||
users[i] = Math.abs(ran.nextInt()) + "-user";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int i = 0; i < numThreads; i++) {
|
|
||||||
new Thread(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
do {
|
|
||||||
String username = null;
|
|
||||||
try {
|
|
||||||
long now = System.currentTimeMillis();
|
|
||||||
Random ran = new Random();
|
|
||||||
if (users != null) {
|
|
||||||
username = users[Math.abs(ran.nextInt()) % numOfUsers];
|
|
||||||
} else {
|
|
||||||
username = Math.abs(ran.nextInt()) + "-user";
|
|
||||||
}
|
|
||||||
NDC.push(username);
|
|
||||||
|
|
||||||
String url = server + "?email=" + username + "&password=" + username + "&command=deploy";
|
|
||||||
logger.info("Launching test for user: " + username + " with url: " + url);
|
|
||||||
HttpClient client = new HttpClient();
|
|
||||||
HttpMethod method = new GetMethod(url);
|
|
||||||
int responseCode = client.executeMethod(method);
|
|
||||||
boolean success = false;
|
|
||||||
String reason = null;
|
|
||||||
if (responseCode == 200) {
|
|
||||||
if (internet) {
|
|
||||||
logger.info("Deploy successful...waiting 5 minute before SSH tests");
|
|
||||||
Thread.sleep(300000L); // Wait 60 seconds so the linux VM can boot up.
|
|
||||||
|
|
||||||
logger.info("Begin Linux SSH test");
|
|
||||||
reason = sshTest(method.getResponseHeader("linuxIP").getValue());
|
|
||||||
|
|
||||||
if (reason == null) {
|
|
||||||
logger.info("Linux SSH test successful");
|
|
||||||
logger.info("Begin Windows SSH test");
|
|
||||||
reason = sshWinTest(method.getResponseHeader("windowsIP").getValue());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (reason == null) {
|
|
||||||
if (internet) {
|
|
||||||
logger.info("Windows SSH test successful");
|
|
||||||
} else {
|
|
||||||
logger.info("deploy test successful....now cleaning up");
|
|
||||||
if (cleanUp) {
|
|
||||||
logger.info("Waiting " + sleepTime + " ms before cleaning up vms");
|
|
||||||
Thread.sleep(sleepTime);
|
|
||||||
} else {
|
|
||||||
success = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (users == null) {
|
|
||||||
logger.info("Sending cleanup command");
|
|
||||||
url = server + "?email=" + username + "&password=" + username + "&command=cleanup";
|
|
||||||
} else {
|
|
||||||
logger.info("Sending stop DomR / destroy VM command");
|
|
||||||
url = server + "?email=" + username + "&password=" + username + "&command=stopDomR";
|
|
||||||
}
|
|
||||||
method = new GetMethod(url);
|
|
||||||
responseCode = client.executeMethod(method);
|
|
||||||
if (responseCode == 200) {
|
|
||||||
success = true;
|
|
||||||
} else {
|
|
||||||
reason = method.getStatusText();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// Just stop but don't destroy the VMs/Routers
|
|
||||||
logger.info("SSH test failed with reason '" + reason + "', stopping VMs");
|
|
||||||
url = server + "?email=" + username + "&password=" + username + "&command=stop";
|
|
||||||
responseCode = client.executeMethod(new GetMethod(url));
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// Just stop but don't destroy the VMs/Routers
|
|
||||||
reason = method.getStatusText();
|
|
||||||
logger.info("Deploy test failed with reason '" + reason + "', stopping VMs");
|
|
||||||
url = server + "?email=" + username + "&password=" + username + "&command=stop";
|
|
||||||
client.executeMethod(new GetMethod(url));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (success) {
|
|
||||||
logger.info("***** Completed test for user : " + username + " in " + ((System.currentTimeMillis() - now) / 1000L) + " seconds");
|
|
||||||
} else {
|
|
||||||
logger.info("##### FAILED test for user : " + username + " in " + ((System.currentTimeMillis() - now) / 1000L) +
|
|
||||||
" seconds with reason : " + reason);
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
logger.warn("Error in thread", e);
|
|
||||||
try {
|
|
||||||
HttpClient client = new HttpClient();
|
|
||||||
String url = server + "?email=" + username + "&password=" + username + "&command=stop";
|
|
||||||
client.executeMethod(new GetMethod(url));
|
|
||||||
} catch (Exception e1) {
|
|
||||||
logger.info("[ignored]"
|
|
||||||
+ "error while executing last resort stop attempt: " + e1.getLocalizedMessage());
|
|
||||||
}
|
|
||||||
} finally {
|
|
||||||
NDC.clear();
|
|
||||||
}
|
|
||||||
} while (repeat);
|
|
||||||
}
|
|
||||||
}).start();
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
logger.error(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static String sshWinTest(String host) {
|
|
||||||
if (host == null) {
|
|
||||||
logger.info("Did not receive a host back from test, ignoring win ssh test");
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
// We will retry 5 times before quitting
|
|
||||||
int retry = 0;
|
|
||||||
|
|
||||||
while (true) {
|
|
||||||
try {
|
|
||||||
if (retry > 0) {
|
|
||||||
logger.info("Retry attempt : " + retry + " ...sleeping 300 seconds before next attempt");
|
|
||||||
Thread.sleep(300000);
|
|
||||||
}
|
|
||||||
|
|
||||||
logger.info("Attempting to SSH into windows host " + host + " with retry attempt: " + retry);
|
|
||||||
|
|
||||||
Connection conn = new Connection(host);
|
|
||||||
conn.connect(null, 60000, 60000);
|
|
||||||
|
|
||||||
logger.info("SSHed successfully into windows host " + host);
|
|
||||||
boolean success = false;
|
|
||||||
boolean isAuthenticated = conn.authenticateWithPassword("vmops", "vmops");
|
|
||||||
if (isAuthenticated == false) {
|
|
||||||
return "Authentication failed";
|
|
||||||
}
|
|
||||||
SCPClient scp = new SCPClient(conn);
|
|
||||||
|
|
||||||
scp.put("wget.exe", "");
|
|
||||||
|
|
||||||
Session sess = conn.openSession();
|
|
||||||
logger.info("Executing : wget http://172.16.0.220/dump.bin");
|
|
||||||
sess.execCommand("wget http://172.16.0.220/dump.bin && dir dump.bin");
|
|
||||||
|
|
||||||
InputStream stdout = sess.getStdout();
|
|
||||||
InputStream stderr = sess.getStderr();
|
|
||||||
|
|
||||||
byte[] buffer = new byte[8192];
|
|
||||||
while (true) {
|
|
||||||
if ((stdout.available() == 0) && (stderr.available() == 0)) {
|
|
||||||
int conditions = sess.waitForCondition(ChannelCondition.STDOUT_DATA | ChannelCondition.STDERR_DATA | ChannelCondition.EOF, 120000);
|
|
||||||
|
|
||||||
if ((conditions & ChannelCondition.TIMEOUT) != 0) {
|
|
||||||
logger.info("Timeout while waiting for data from peer.");
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((conditions & ChannelCondition.EOF) != 0) {
|
|
||||||
if ((conditions & (ChannelCondition.STDOUT_DATA | ChannelCondition.STDERR_DATA)) == 0) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
while (stdout.available() > 0) {
|
|
||||||
success = true;
|
|
||||||
int len = stdout.read(buffer);
|
|
||||||
if (len > 0) // this check is somewhat paranoid
|
|
||||||
logger.info(new String(buffer, 0, len));
|
|
||||||
}
|
|
||||||
|
|
||||||
while (stderr.available() > 0) {
|
|
||||||
int len = stderr.read(buffer);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
sess.close();
|
|
||||||
conn.close();
|
|
||||||
|
|
||||||
if (success) {
|
|
||||||
return null;
|
|
||||||
} else {
|
|
||||||
retry++;
|
|
||||||
if (retry == MAX_RETRY_WIN) {
|
|
||||||
return "SSH Windows Network test fail";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
retry++;
|
|
||||||
if (retry == MAX_RETRY_WIN) {
|
|
||||||
return "SSH Windows Network test fail with error " + e.getMessage();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static String sshTest(String host) {
|
|
||||||
if (host == null) {
|
|
||||||
logger.info("Did not receive a host back from test, ignoring ssh test");
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
// We will retry 5 times before quitting
|
|
||||||
int retry = 0;
|
|
||||||
|
|
||||||
while (true) {
|
|
||||||
try {
|
|
||||||
if (retry > 0) {
|
|
||||||
logger.info("Retry attempt : " + retry + " ...sleeping 120 seconds before next attempt");
|
|
||||||
Thread.sleep(120000);
|
|
||||||
}
|
|
||||||
|
|
||||||
logger.info("Attempting to SSH into linux host " + host + " with retry attempt: " + retry);
|
|
||||||
|
|
||||||
Connection conn = new Connection(host);
|
|
||||||
conn.connect(null, 60000, 60000);
|
|
||||||
|
|
||||||
logger.info("SSHed successfully into linux host " + host);
|
|
||||||
|
|
||||||
boolean isAuthenticated = conn.authenticateWithPassword("root", "password");
|
|
||||||
|
|
||||||
if (isAuthenticated == false) {
|
|
||||||
return "Authentication failed";
|
|
||||||
}
|
|
||||||
boolean success = false;
|
|
||||||
Session sess = conn.openSession();
|
|
||||||
logger.info("Executing : wget http://172.16.0.220/dump.bin");
|
|
||||||
sess.execCommand("wget http://172.16.0.220/dump.bin && ls -al dump.bin");
|
|
||||||
|
|
||||||
InputStream stdout = sess.getStdout();
|
|
||||||
InputStream stderr = sess.getStderr();
|
|
||||||
|
|
||||||
byte[] buffer = new byte[8192];
|
|
||||||
while (true) {
|
|
||||||
if ((stdout.available() == 0) && (stderr.available() == 0)) {
|
|
||||||
int conditions = sess.waitForCondition(ChannelCondition.STDOUT_DATA | ChannelCondition.STDERR_DATA | ChannelCondition.EOF, 120000);
|
|
||||||
|
|
||||||
if ((conditions & ChannelCondition.TIMEOUT) != 0) {
|
|
||||||
logger.info("Timeout while waiting for data from peer.");
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((conditions & ChannelCondition.EOF) != 0) {
|
|
||||||
if ((conditions & (ChannelCondition.STDOUT_DATA | ChannelCondition.STDERR_DATA)) == 0) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
while (stdout.available() > 0) {
|
|
||||||
success = true;
|
|
||||||
int len = stdout.read(buffer);
|
|
||||||
if (len > 0) // this check is somewhat paranoid
|
|
||||||
logger.info(new String(buffer, 0, len));
|
|
||||||
}
|
|
||||||
|
|
||||||
while (stderr.available() > 0) {
|
|
||||||
int len = stderr.read(buffer);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
sess.close();
|
|
||||||
conn.close();
|
|
||||||
|
|
||||||
if (success) {
|
|
||||||
return null;
|
|
||||||
} else {
|
|
||||||
retry++;
|
|
||||||
if (retry == MAX_RETRY_LINUX) {
|
|
||||||
return "SSH Linux Network test fail";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
retry++;
|
|
||||||
if (retry == MAX_RETRY_LINUX) {
|
|
||||||
return "SSH Linux Network test fail with error " + e.getMessage();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,210 +0,0 @@
|
|||||||
// 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.test.utils;
|
|
||||||
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.math.BigInteger;
|
|
||||||
import java.security.MessageDigest;
|
|
||||||
import java.security.NoSuchAlgorithmException;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import javax.crypto.Mac;
|
|
||||||
import javax.crypto.spec.SecretKeySpec;
|
|
||||||
import javax.xml.parsers.DocumentBuilder;
|
|
||||||
import javax.xml.parsers.DocumentBuilderFactory;
|
|
||||||
|
|
||||||
import org.apache.commons.codec.binary.Base64;
|
|
||||||
import org.w3c.dom.Document;
|
|
||||||
import org.w3c.dom.Element;
|
|
||||||
import org.w3c.dom.Node;
|
|
||||||
import org.w3c.dom.NodeList;
|
|
||||||
|
|
||||||
import com.cloud.utils.exception.CloudRuntimeException;
|
|
||||||
|
|
||||||
public class UtilsForTest {
|
|
||||||
|
|
||||||
private static DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
|
|
||||||
|
|
||||||
public static boolean verifyTags(Map<String, String> params) {
|
|
||||||
boolean result = true;
|
|
||||||
for (String value : params.keySet()) {
|
|
||||||
if (params.get(value) == null) {
|
|
||||||
result = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean verifyTagValues(Map<String, String> params, Map<String, String> pattern) {
|
|
||||||
boolean result = true;
|
|
||||||
|
|
||||||
if (pattern != null) {
|
|
||||||
for (String value : pattern.keySet()) {
|
|
||||||
if (!pattern.get(value).equals(params.get(value))) {
|
|
||||||
result = false;
|
|
||||||
System.out.println("Tag " + value + " has " + params.get(value) + " while expected value is: " + pattern.get(value));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Map<String, String> parseXML(InputStream is, String[] tagNames) {
|
|
||||||
Map<String, String> returnValues = new HashMap<String, String>();
|
|
||||||
try {
|
|
||||||
DocumentBuilder docBuilder = factory.newDocumentBuilder();
|
|
||||||
Document doc = docBuilder.parse(is);
|
|
||||||
Element rootElement = doc.getDocumentElement();
|
|
||||||
|
|
||||||
for (int i = 0; i < tagNames.length; i++) {
|
|
||||||
NodeList targetNodes = rootElement.getElementsByTagName(tagNames[i]);
|
|
||||||
if (targetNodes.getLength() <= 0) {
|
|
||||||
System.out.println("no " + tagNames[i] + " tag in the response");
|
|
||||||
returnValues.put(tagNames[i], null);
|
|
||||||
} else {
|
|
||||||
returnValues.put(tagNames[i], targetNodes.item(0).getTextContent());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (Exception ex) {
|
|
||||||
System.out.println("error processing XML");
|
|
||||||
ex.printStackTrace();
|
|
||||||
}
|
|
||||||
return returnValues;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ArrayList<HashMap<String, String>> parseMulXML(InputStream is, String[] tagNames) {
|
|
||||||
ArrayList<HashMap<String, String>> returnValues = new ArrayList<HashMap<String, String>>();
|
|
||||||
|
|
||||||
try {
|
|
||||||
DocumentBuilder docBuilder = factory.newDocumentBuilder();
|
|
||||||
Document doc = docBuilder.parse(is);
|
|
||||||
Element rootElement = doc.getDocumentElement();
|
|
||||||
for (int i = 0; i < tagNames.length; i++) {
|
|
||||||
NodeList targetNodes = rootElement.getElementsByTagName(tagNames[i]);
|
|
||||||
if (targetNodes.getLength() <= 0) {
|
|
||||||
System.out.println("no " + tagNames[i] + " tag in XML response...returning null");
|
|
||||||
} else {
|
|
||||||
for (int j = 0; j < targetNodes.getLength(); j++) {
|
|
||||||
HashMap<String, String> valueList = new HashMap<String, String>();
|
|
||||||
Node node = targetNodes.item(j);
|
|
||||||
//parse child nodes
|
|
||||||
NodeList child = node.getChildNodes();
|
|
||||||
for (int c = 0; c < node.getChildNodes().getLength(); c++) {
|
|
||||||
child.item(c).getNodeName();
|
|
||||||
valueList.put(child.item(c).getNodeName(), child.item(c).getTextContent());
|
|
||||||
}
|
|
||||||
returnValues.add(valueList);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (Exception ex) {
|
|
||||||
System.out.println(ex);
|
|
||||||
}
|
|
||||||
|
|
||||||
return returnValues;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String createMD5String(String password) {
|
|
||||||
MessageDigest md5;
|
|
||||||
try {
|
|
||||||
md5 = MessageDigest.getInstance("MD5");
|
|
||||||
} catch (NoSuchAlgorithmException e) {
|
|
||||||
throw new CloudRuntimeException("Error", e);
|
|
||||||
}
|
|
||||||
|
|
||||||
md5.reset();
|
|
||||||
BigInteger pwInt = new BigInteger(1, md5.digest(password.getBytes()));
|
|
||||||
|
|
||||||
// make sure our MD5 hash value is 32 digits long...
|
|
||||||
StringBuffer sb = new StringBuffer();
|
|
||||||
String pwStr = pwInt.toString(16);
|
|
||||||
int padding = 32 - pwStr.length();
|
|
||||||
for (int i = 0; i < padding; i++) {
|
|
||||||
sb.append('0');
|
|
||||||
}
|
|
||||||
sb.append(pwStr);
|
|
||||||
return sb.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Map<String, String> getSingleValueFromXML(InputStream is, String[] tagNames) {
|
|
||||||
Map<String, String> returnValues = new HashMap<String, String>();
|
|
||||||
try {
|
|
||||||
DocumentBuilder docBuilder = factory.newDocumentBuilder();
|
|
||||||
Document doc = docBuilder.parse(is);
|
|
||||||
Element rootElement = doc.getDocumentElement();
|
|
||||||
|
|
||||||
for (int i = 0; i < tagNames.length; i++) {
|
|
||||||
NodeList targetNodes = rootElement.getElementsByTagName(tagNames[i]);
|
|
||||||
if (targetNodes.getLength() <= 0) {
|
|
||||||
System.out.println("no " + tagNames[i] + " tag in XML response...returning null");
|
|
||||||
} else {
|
|
||||||
returnValues.put(tagNames[i], targetNodes.item(0).getTextContent());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (Exception ex) {
|
|
||||||
System.out.println("error processing XML");
|
|
||||||
ex.printStackTrace();
|
|
||||||
}
|
|
||||||
return returnValues;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Map<String, List<String>> getMultipleValuesFromXML(InputStream is, String[] tagNames) {
|
|
||||||
Map<String, List<String>> returnValues = new HashMap<String, List<String>>();
|
|
||||||
try {
|
|
||||||
DocumentBuilder docBuilder = factory.newDocumentBuilder();
|
|
||||||
Document doc = docBuilder.parse(is);
|
|
||||||
Element rootElement = doc.getDocumentElement();
|
|
||||||
for (int i = 0; i < tagNames.length; i++) {
|
|
||||||
NodeList targetNodes = rootElement.getElementsByTagName(tagNames[i]);
|
|
||||||
if (targetNodes.getLength() <= 0) {
|
|
||||||
System.out.println("no " + tagNames[i] + " tag in XML response...returning null");
|
|
||||||
} else {
|
|
||||||
List<String> valueList = new ArrayList<String>();
|
|
||||||
for (int j = 0; j < targetNodes.getLength(); j++) {
|
|
||||||
Node node = targetNodes.item(j);
|
|
||||||
valueList.add(node.getTextContent());
|
|
||||||
}
|
|
||||||
returnValues.put(tagNames[i], valueList);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (Exception ex) {
|
|
||||||
System.out.println(ex);
|
|
||||||
}
|
|
||||||
return returnValues;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String signRequest(String request, String key) {
|
|
||||||
try {
|
|
||||||
Mac mac = Mac.getInstance("HmacSHA1");
|
|
||||||
SecretKeySpec keySpec = new SecretKeySpec(key.getBytes(), "HmacSHA1");
|
|
||||||
mac.init(keySpec);
|
|
||||||
mac.update(request.getBytes());
|
|
||||||
byte[] encryptedBytes = mac.doFinal();
|
|
||||||
//System.out.println("HmacSHA1 hash: " + encryptedBytes);
|
|
||||||
return Base64.encodeBase64String(encryptedBytes);
|
|
||||||
} catch (Exception ex) {
|
|
||||||
System.out.println("unable to sign request");
|
|
||||||
ex.printStackTrace();
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1762,7 +1762,7 @@
|
|||||||
"label.removing": "Removing",
|
"label.removing": "Removing",
|
||||||
"label.replace.acl": "Replace ACL",
|
"label.replace.acl": "Replace ACL",
|
||||||
"label.replace.acl.list": "Replace ACL list",
|
"label.replace.acl.list": "Replace ACL list",
|
||||||
"label.report.bug": "Report issue",
|
"label.report.bug": "Ask a question or Report an issue",
|
||||||
"label.required": "Required",
|
"label.required": "Required",
|
||||||
"label.requireshvm": "HVM",
|
"label.requireshvm": "HVM",
|
||||||
"label.requiresupgrade": "Requires upgrade",
|
"label.requiresupgrade": "Requires upgrade",
|
||||||
|
|||||||
@ -23,7 +23,7 @@
|
|||||||
<div class="line" v-if="$store.getters.userInfo.roletype === 'Admin'">
|
<div class="line" v-if="$store.getters.userInfo.roletype === 'Admin'">
|
||||||
CloudStack {{ $store.getters.features.cloudstackversion }}
|
CloudStack {{ $store.getters.features.cloudstackversion }}
|
||||||
<a-divider type="vertical" />
|
<a-divider type="vertical" />
|
||||||
<a href="https://github.com/apache/cloudstack/issues/new" target="_blank">
|
<a href="https://github.com/apache/cloudstack/discussions" target="_blank">
|
||||||
<github-outlined />
|
<github-outlined />
|
||||||
{{ $t('label.report.bug') }}
|
{{ $t('label.report.bug') }}
|
||||||
</a>
|
</a>
|
||||||
|
|||||||
@ -74,6 +74,7 @@ function generateRouterMap (section) {
|
|||||||
icon: child.icon,
|
icon: child.icon,
|
||||||
docHelp: vueProps.$applyDocHelpMappings(child.docHelp),
|
docHelp: vueProps.$applyDocHelpMappings(child.docHelp),
|
||||||
permission: child.permission,
|
permission: child.permission,
|
||||||
|
getApiToCall: child.getApiToCall,
|
||||||
resourceType: child.resourceType,
|
resourceType: child.resourceType,
|
||||||
filters: child.filters,
|
filters: child.filters,
|
||||||
params: child.params ? child.params : {},
|
params: child.params ? child.params : {},
|
||||||
|
|||||||
@ -28,7 +28,8 @@ export default {
|
|||||||
title: 'label.instances',
|
title: 'label.instances',
|
||||||
icon: 'cloud-server-outlined',
|
icon: 'cloud-server-outlined',
|
||||||
docHelp: 'adminguide/virtual_machines.html',
|
docHelp: 'adminguide/virtual_machines.html',
|
||||||
permission: ['listVirtualMachinesMetrics'],
|
permission: ['listVirtualMachines', 'listVirtualMachinesMetrics'],
|
||||||
|
getApiToCall: () => store.getters.metrics ? 'listVirtualMachinesMetrics' : 'listVirtualMachines',
|
||||||
resourceType: 'UserVm',
|
resourceType: 'UserVm',
|
||||||
params: () => {
|
params: () => {
|
||||||
var params = { details: 'servoff,tmpl,iso,nics,backoff' }
|
var params = { details: 'servoff,tmpl,iso,nics,backoff' }
|
||||||
|
|||||||
@ -146,6 +146,7 @@ export default {
|
|||||||
message: 'label.outofbandmanagement.configure',
|
message: 'label.outofbandmanagement.configure',
|
||||||
docHelp: 'adminguide/hosts.html#out-of-band-management',
|
docHelp: 'adminguide/hosts.html#out-of-band-management',
|
||||||
dataView: true,
|
dataView: true,
|
||||||
|
post: true,
|
||||||
args: ['hostid', 'address', 'port', 'username', 'password', 'driver'],
|
args: ['hostid', 'address', 'port', 'username', 'password', 'driver'],
|
||||||
mapping: {
|
mapping: {
|
||||||
hostid: {
|
hostid: {
|
||||||
|
|||||||
@ -819,7 +819,7 @@ export default {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (this.$route && this.$route.meta && this.$route.meta.permission) {
|
if (this.$route && this.$route.meta && this.$route.meta.permission) {
|
||||||
this.apiName = this.$route.meta.permission[0]
|
this.apiName = (this.$route.meta.getApiToCall && this.$route.meta.getApiToCall()) || this.$route.meta.permission[0]
|
||||||
if (this.$route.meta.columns) {
|
if (this.$route.meta.columns) {
|
||||||
const columns = this.$route.meta.columns
|
const columns = this.$route.meta.columns
|
||||||
if (columns && typeof columns === 'function') {
|
if (columns && typeof columns === 'function') {
|
||||||
|
|||||||
@ -225,6 +225,10 @@
|
|||||||
<artifactId>tink</artifactId>
|
<artifactId>tink</artifactId>
|
||||||
<version>${cs.tink.version}</version>
|
<version>${cs.tink.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.commons</groupId>
|
||||||
|
<artifactId>commons-collections4</artifactId>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
<build>
|
<build>
|
||||||
<plugins>
|
<plugins>
|
||||||
|
|||||||
@ -31,6 +31,7 @@ import javax.naming.ConfigurationException;
|
|||||||
|
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
import org.apache.commons.collections4.MapUtils;
|
||||||
import org.springframework.aop.framework.Advised;
|
import org.springframework.aop.framework.Advised;
|
||||||
import org.springframework.beans.BeansException;
|
import org.springframework.beans.BeansException;
|
||||||
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
|
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
|
||||||
@ -287,4 +288,22 @@ public class ComponentContext implements ApplicationContextAware {
|
|||||||
private static synchronized void initInitializeBeans(boolean initializeBeans) {
|
private static synchronized void initInitializeBeans(boolean initializeBeans) {
|
||||||
s_initializeBeans = initializeBeans;
|
s_initializeBeans = initializeBeans;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static <T> T getDelegateComponentOfType(Class<T> beanType) {
|
||||||
|
if (s_appContextDelegates == null) {
|
||||||
|
throw new NoSuchBeanDefinitionException(beanType.getName());
|
||||||
|
}
|
||||||
|
T bean = null;
|
||||||
|
for (ApplicationContext context : s_appContextDelegates.values()) {
|
||||||
|
Map<String, T> map = context.getBeansOfType(beanType);
|
||||||
|
if (MapUtils.isNotEmpty(map)) {
|
||||||
|
bean = (T)map.values().toArray()[0];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (bean == null) {
|
||||||
|
throw new NoSuchBeanDefinitionException(beanType.getName());
|
||||||
|
}
|
||||||
|
return bean;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -19,14 +19,16 @@
|
|||||||
|
|
||||||
package org.apache.cloudstack.utils.process;
|
package org.apache.cloudstack.utils.process;
|
||||||
|
|
||||||
import com.google.common.base.Preconditions;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import com.google.common.io.CharStreams;
|
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
import com.google.common.base.Preconditions;
|
||||||
|
import com.google.common.io.CharStreams;
|
||||||
import org.joda.time.Duration;
|
import org.joda.time.Duration;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.Callable;
|
import java.util.concurrent.Callable;
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
@ -34,7 +36,10 @@ import java.util.concurrent.ExecutorService;
|
|||||||
import java.util.concurrent.Future;
|
import java.util.concurrent.Future;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.concurrent.TimeoutException;
|
import java.util.concurrent.TimeoutException;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
import com.cloud.utils.Ternary;
|
||||||
|
|
||||||
public final class ProcessRunner {
|
public final class ProcessRunner {
|
||||||
protected Logger logger = LogManager.getLogger(getClass());
|
protected Logger logger = LogManager.getLogger(getClass());
|
||||||
@ -42,9 +47,26 @@ public final class ProcessRunner {
|
|||||||
// Default maximum timeout of 5 minutes for any command
|
// Default maximum timeout of 5 minutes for any command
|
||||||
public static final Duration DEFAULT_MAX_TIMEOUT = new Duration(5 * 60 * 1000);
|
public static final Duration DEFAULT_MAX_TIMEOUT = new Duration(5 * 60 * 1000);
|
||||||
private final ExecutorService executor;
|
private final ExecutorService executor;
|
||||||
|
private final List<Ternary<String, String, String>> commandLogReplacements = new ArrayList<>();
|
||||||
|
|
||||||
|
String removeCommandSensitiveInfoForLogging(String command) {
|
||||||
|
String commandLog = command.trim();
|
||||||
|
|
||||||
|
for (Ternary<String, String, String> replacement : commandLogReplacements) {
|
||||||
|
if (commandLog.contains(replacement.first())) {
|
||||||
|
Pattern pattern = Pattern.compile(replacement.second());
|
||||||
|
Matcher matcher = pattern.matcher(commandLog);
|
||||||
|
if (matcher.find()) {
|
||||||
|
commandLog = matcher.replaceAll(replacement.third());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return commandLog;
|
||||||
|
}
|
||||||
|
|
||||||
public ProcessRunner(ExecutorService executor) {
|
public ProcessRunner(ExecutorService executor) {
|
||||||
this.executor = executor;
|
this.executor = executor;
|
||||||
|
commandLogReplacements.add(new Ternary<>("ipmitool", "-P\\s+\\S+", "-P *****"));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -73,14 +95,13 @@ public final class ProcessRunner {
|
|||||||
int retVal = -2;
|
int retVal = -2;
|
||||||
String stdOutput = null;
|
String stdOutput = null;
|
||||||
String stdError = null;
|
String stdError = null;
|
||||||
|
String commandLog = removeCommandSensitiveInfoForLogging(StringUtils.join(commands, " "));
|
||||||
String oneLineCommand = StringUtils.join(commands, " ");
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
logger.debug(String.format("Preparing command [%s] to execute.", oneLineCommand));
|
logger.debug("Preparing command [{}] to execute.", commandLog);
|
||||||
final Process process = new ProcessBuilder().command(commands).start();
|
final Process process = new ProcessBuilder().command(commands).start();
|
||||||
|
|
||||||
logger.debug(String.format("Submitting command [%s].", oneLineCommand));
|
logger.debug("Submitting command [{}].", commandLog);
|
||||||
final Future<Integer> processFuture = executor.submit(new Callable<Integer>() {
|
final Future<Integer> processFuture = executor.submit(new Callable<Integer>() {
|
||||||
@Override
|
@Override
|
||||||
public Integer call() throws Exception {
|
public Integer call() throws Exception {
|
||||||
@ -88,14 +109,14 @@ public final class ProcessRunner {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
try {
|
try {
|
||||||
logger.debug(String.format("Waiting for a response from command [%s]. Defined timeout: [%s].", oneLineCommand, timeOut.getStandardSeconds()));
|
logger.debug("Waiting for a response from command [{}]. Defined timeout: [{}].", commandLog, timeOut.getStandardSeconds());
|
||||||
retVal = processFuture.get(timeOut.getStandardSeconds(), TimeUnit.SECONDS);
|
retVal = processFuture.get(timeOut.getStandardSeconds(), TimeUnit.SECONDS);
|
||||||
} catch (ExecutionException e) {
|
} catch (ExecutionException e) {
|
||||||
logger.warn(String.format("Failed to complete the requested command [%s] due to execution error.", oneLineCommand), e);
|
logger.warn("Failed to complete the requested command [{}] due to execution error.", commands, e);
|
||||||
retVal = -2;
|
retVal = -2;
|
||||||
stdError = e.getMessage();
|
stdError = e.getMessage();
|
||||||
} catch (TimeoutException e) {
|
} catch (TimeoutException e) {
|
||||||
logger.warn(String.format("Failed to complete the requested command [%s] within timeout. Defined timeout: [%s].", oneLineCommand, timeOut.getStandardSeconds()), e);
|
logger.warn("Failed to complete the requested command [{}] within timeout. Defined timeout: [{}].", commandLog, timeOut.getStandardSeconds(), e);
|
||||||
retVal = -1;
|
retVal = -1;
|
||||||
stdError = "Operation timed out, aborted.";
|
stdError = "Operation timed out, aborted.";
|
||||||
} finally {
|
} finally {
|
||||||
@ -106,10 +127,10 @@ public final class ProcessRunner {
|
|||||||
process.destroy();
|
process.destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.debug(String.format("Process standard output for command [%s]: [%s].", oneLineCommand, stdOutput));
|
logger.debug("Process standard output for command [{}]: [{}].", commandLog, stdOutput);
|
||||||
logger.debug(String.format("Process standard error output command [%s]: [%s].", oneLineCommand, stdError));
|
logger.debug("Process standard error output command [{}]: [{}].", commandLog, stdError);
|
||||||
} catch (IOException | InterruptedException e) {
|
} catch (IOException | InterruptedException e) {
|
||||||
logger.error(String.format("Exception caught error running command [%s].", oneLineCommand), e);
|
logger.error("Exception caught error running command [{}].", commandLog, e);
|
||||||
stdError = e.getMessage();
|
stdError = e.getMessage();
|
||||||
}
|
}
|
||||||
return new ProcessResult(stdOutput, stdError, retVal);
|
return new ProcessResult(stdOutput, stdError, retVal);
|
||||||
|
|||||||
@ -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 org.apache.cloudstack.utils.process;
|
||||||
|
|
||||||
|
import java.util.concurrent.ExecutorService;
|
||||||
|
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.mockito.InjectMocks;
|
||||||
|
import org.mockito.Mockito;
|
||||||
|
import org.mockito.junit.MockitoJUnitRunner;
|
||||||
|
|
||||||
|
@RunWith(MockitoJUnitRunner.class)
|
||||||
|
public class ProcessRunnerTest {
|
||||||
|
|
||||||
|
@InjectMocks
|
||||||
|
ProcessRunner processRunner = new ProcessRunner(Mockito.mock(ExecutorService.class));
|
||||||
|
|
||||||
|
private int countSubstringOccurrences(String mainString, String subString) {
|
||||||
|
int count = 0;
|
||||||
|
int index = 0;
|
||||||
|
while ((index = mainString.indexOf(subString, index)) != -1) {
|
||||||
|
count++;
|
||||||
|
index += subString.length();
|
||||||
|
}
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testRemoveCommandSensitiveInfoForLoggingIpmi() {
|
||||||
|
String password = "R@ndomP@ss";
|
||||||
|
String command = String.format("/usr/bin/ipmitool -H host -p 1234 -U Admin " +
|
||||||
|
"-P %s chassis power status", password);
|
||||||
|
String log = processRunner.removeCommandSensitiveInfoForLogging(command);
|
||||||
|
Assert.assertFalse(log.contains(password));
|
||||||
|
|
||||||
|
String command1 = String.format("%s -D %s", command, password);
|
||||||
|
log = processRunner.removeCommandSensitiveInfoForLogging(command1);
|
||||||
|
Assert.assertTrue(log.contains(password));
|
||||||
|
Assert.assertEquals(1, countSubstringOccurrences(log, password));
|
||||||
|
|
||||||
|
String command2 = command.replace("ipmitool", "impit00l");
|
||||||
|
log = processRunner.removeCommandSensitiveInfoForLogging(command2);
|
||||||
|
Assert.assertTrue(log.contains(password));
|
||||||
|
Assert.assertEquals(1, countSubstringOccurrences(log, password));
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user