mirror of https://github.com/apache/cloudstack.git
CLOUDSTACK-10380: Fix startvm giving another password after password reset.
This commit is contained in:
parent
8aff96cfc5
commit
02e2825d2d
|
|
@ -1336,7 +1336,7 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra
|
|||
|
||||
//check if the there are no service provider other than virtualrouter.
|
||||
for(Provider provider : providers) {
|
||||
if (provider!=Provider.VirtualRouter)
|
||||
if (provider != Provider.VirtualRouter)
|
||||
throw new UnsupportedOperationException("Cannot update the network resources in sequence when providers other than virtualrouter are used");
|
||||
}
|
||||
//check if routers are in correct state before proceeding with the update
|
||||
|
|
|
|||
|
|
@ -29,11 +29,11 @@ import java.util.Set;
|
|||
import javax.annotation.PostConstruct;
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.network.Network;
|
||||
import com.cloud.network.dao.NetworkDao;
|
||||
import com.cloud.network.dao.NetworkVO;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.server.ResourceTag.ResourceObjectType;
|
||||
import com.cloud.tags.dao.ResourceTagDao;
|
||||
import com.cloud.user.Account;
|
||||
|
|
@ -368,9 +368,13 @@ public class UserVmDaoImpl extends GenericDaoBase<UserVmVO, Long> implements Use
|
|||
if (detailsStr == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
final Map<String, Boolean> visibilityMap = _detailsDao.listDetailsVisibility(vm.getId());
|
||||
|
||||
List<UserVmDetailVO> details = new ArrayList<UserVmDetailVO>();
|
||||
for (String key : detailsStr.keySet()) {
|
||||
details.add(new UserVmDetailVO(vm.getId(), key, detailsStr.get(key), true));
|
||||
for (Map.Entry<String, String> entry : detailsStr.entrySet()) {
|
||||
boolean display = visibilityMap.getOrDefault(entry.getKey(), true);
|
||||
details.add(new UserVmDetailVO(vm.getId(), entry.getKey(), entry.getValue(), display));
|
||||
}
|
||||
|
||||
_detailsDao.saveDetails(details);
|
||||
|
|
|
|||
|
|
@ -73,6 +73,8 @@ public interface ResourceDetailsDao<R extends ResourceDetail> extends GenericDao
|
|||
|
||||
public Map<String, String> listDetailsKeyPairs(long resourceId, boolean forDisplay);
|
||||
|
||||
Map<String, Boolean> listDetailsVisibility(long resourceId);
|
||||
|
||||
public void saveDetails(List<R> details);
|
||||
|
||||
public void addDetail(long resourceId, String key, String value, boolean display);
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ import com.cloud.utils.db.SearchBuilder;
|
|||
import com.cloud.utils.db.SearchCriteria;
|
||||
import com.cloud.utils.db.TransactionLegacy;
|
||||
|
||||
public abstract class ResourceDetailsDaoBase<R extends ResourceDetail> extends GenericDaoBase<R, Long> {
|
||||
public abstract class ResourceDetailsDaoBase<R extends ResourceDetail> extends GenericDaoBase<R, Long> implements ResourceDetailsDao<R> {
|
||||
private SearchBuilder<R> AllFieldsSearch;
|
||||
|
||||
public ResourceDetailsDaoBase() {
|
||||
|
|
@ -81,6 +81,18 @@ public abstract class ResourceDetailsDaoBase<R extends ResourceDetail> extends G
|
|||
return details;
|
||||
}
|
||||
|
||||
public Map<String, Boolean> listDetailsVisibility(long resourceId) {
|
||||
SearchCriteria<R> sc = AllFieldsSearch.create();
|
||||
sc.setParameters("resourceId", resourceId);
|
||||
|
||||
List<R> results = search(sc, null);
|
||||
Map<String, Boolean> details = new HashMap<>(results.size());
|
||||
for (R result : results) {
|
||||
details.put(result.getName(), result.isDisplay());
|
||||
}
|
||||
return details;
|
||||
}
|
||||
|
||||
public List<R> listDetails(long resourceId) {
|
||||
SearchCriteria<R> sc = AllFieldsSearch.create();
|
||||
sc.setParameters("resourceId", resourceId);
|
||||
|
|
|
|||
|
|
@ -24,14 +24,12 @@ import java.util.Set;
|
|||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import com.cloud.utils.net.NetUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import com.cloud.network.router.NetworkHelper;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.cloud.network.router.deployment.RouterDeploymentDefinition;
|
||||
import org.cloud.network.router.deployment.RouterDeploymentDefinitionBuilder;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
|
||||
|
|
@ -83,6 +81,7 @@ import com.cloud.network.dao.OvsProviderDao;
|
|||
import com.cloud.network.dao.VirtualRouterProviderDao;
|
||||
import com.cloud.network.lb.LoadBalancingRule;
|
||||
import com.cloud.network.lb.LoadBalancingRulesManager;
|
||||
import com.cloud.network.router.NetworkHelper;
|
||||
import com.cloud.network.router.VirtualRouter;
|
||||
import com.cloud.network.router.VirtualRouter.Role;
|
||||
import com.cloud.network.router.VpcVirtualNetworkApplianceManager;
|
||||
|
|
@ -103,6 +102,7 @@ import com.cloud.utils.crypt.DBEncryptionUtil;
|
|||
import com.cloud.utils.db.QueryBuilder;
|
||||
import com.cloud.utils.db.SearchCriteria.Op;
|
||||
import com.cloud.utils.exception.CloudRuntimeException;
|
||||
import com.cloud.utils.net.NetUtils;
|
||||
import com.cloud.vm.DomainRouterVO;
|
||||
import com.cloud.vm.NicProfile;
|
||||
import com.cloud.vm.ReservationContext;
|
||||
|
|
@ -703,7 +703,14 @@ NetworkMigrationResponder, AggregatedCommandExecutor, RedundantResource, DnsServ
|
|||
// save the password in DB
|
||||
for (final VirtualRouter router : routers) {
|
||||
if (router.getState() == State.Running) {
|
||||
return networkTopology.savePasswordToRouter(network, nic, uservm, router);
|
||||
final boolean result = networkTopology.savePasswordToRouter(network, nic, uservm, router);
|
||||
if (result) {
|
||||
// Explicit password reset, while VM hasn't generated a password yet.
|
||||
final UserVmVO userVmVO = _userVmDao.findById(vm.getId());
|
||||
userVmVO.setUpdateParameters(false);
|
||||
_userVmDao.update(userVmVO.getId(), userVmVO);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
final String password = (String) uservm.getParameter(VirtualMachineProfile.Param.VmPassword);
|
||||
|
|
|
|||
|
|
@ -39,6 +39,11 @@ import java.util.stream.Collectors;
|
|||
import javax.inject.Inject;
|
||||
import javax.naming.ConfigurationException;
|
||||
|
||||
import org.apache.commons.codec.binary.Base64;
|
||||
import org.apache.commons.collections.MapUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import org.apache.cloudstack.acl.ControlledEntity.ACLType;
|
||||
import org.apache.cloudstack.acl.SecurityChecker.AccessType;
|
||||
import org.apache.cloudstack.affinity.AffinityGroupService;
|
||||
|
|
@ -91,10 +96,6 @@ import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
|
|||
import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
|
||||
import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreDao;
|
||||
import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreVO;
|
||||
import org.apache.commons.codec.binary.Base64;
|
||||
import org.apache.commons.collections.MapUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.agent.AgentManager;
|
||||
import com.cloud.agent.api.Answer;
|
||||
|
|
@ -688,10 +689,6 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir
|
|||
|
||||
if (result) {
|
||||
userVm.setPassword(password);
|
||||
// update the password in vm_details table too
|
||||
// Check if an SSH key pair was selected for the instance and if so
|
||||
// use it to encrypt & save the vm password
|
||||
encryptAndStorePassword(userVm, password);
|
||||
} else {
|
||||
throw new CloudRuntimeException("Failed to reset password for the virtual machine ");
|
||||
}
|
||||
|
|
@ -736,7 +733,6 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir
|
|||
} else {
|
||||
final UserVmVO userVm = _vmDao.findById(vmId);
|
||||
_vmDao.loadDetails(userVm);
|
||||
userVm.setPassword(password);
|
||||
// update the password in vm_details table too
|
||||
// Check if an SSH key pair was selected for the instance and if so
|
||||
// use it to encrypt & save the vm password
|
||||
|
|
@ -850,8 +846,9 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir
|
|||
userVm.setPassword(password);
|
||||
//update the encrypted password in vm_details table too
|
||||
encryptAndStorePassword(userVm, password);
|
||||
} else {
|
||||
_vmDao.saveDetails(userVm);
|
||||
}
|
||||
_vmDao.saveDetails(userVm);
|
||||
|
||||
if (vmInstance.getState() == State.Stopped) {
|
||||
s_logger.debug("Vm " + vmInstance + " is stopped, not rebooting it as a part of SSH Key reset");
|
||||
|
|
@ -4461,6 +4458,7 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir
|
|||
password = DBEncryptionUtil.decrypt(vm.getDetail("password"));
|
||||
} else {
|
||||
password = _mgr.generateRandomPassword();
|
||||
vm.setPassword(password);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -4499,11 +4497,10 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir
|
|||
// this value is not being sent to the backend; need only for api
|
||||
// display purposes
|
||||
if (template.getEnablePassword()) {
|
||||
vm.setPassword((String)vmParamPair.second().get(VirtualMachineProfile.Param.VmPassword));
|
||||
vm.setUpdateParameters(false);
|
||||
if (vm.getDetail("password") != null) {
|
||||
_vmDetailsDao.remove(_vmDetailsDao.findDetail(vm.getId(), "password").getId());
|
||||
_vmDetailsDao.removeDetail(vm.getId(), "password");
|
||||
}
|
||||
vm.setUpdateParameters(false);
|
||||
_vmDao.update(vm.getId(), vm);
|
||||
}
|
||||
}
|
||||
|
|
@ -6180,7 +6177,7 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir
|
|||
vm.setUpdateParameters(false);
|
||||
_vmDao.loadDetails(vm);
|
||||
if (vm.getDetail("password") != null) {
|
||||
_vmDetailsDao.remove(_vmDetailsDao.findDetail(vm.getId(), "password").getId());
|
||||
_vmDetailsDao.removeDetail(vm.getId(), "password");
|
||||
}
|
||||
_vmDao.update(vm.getId(), vm);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,6 +20,8 @@
|
|||
ConfigDrive
|
||||
"""
|
||||
# Import Local Modules
|
||||
from contextlib import contextmanager
|
||||
|
||||
from marvin.cloudstackTestCase import cloudstackTestCase
|
||||
from marvin.cloudstackAPI import (resetSSHKeyForVirtualMachine,
|
||||
updateTemplate,
|
||||
|
|
@ -214,6 +216,12 @@ class ConfigDriveUtils:
|
|||
self.password = password
|
||||
self.presence = True
|
||||
|
||||
@contextmanager
|
||||
def stopped_vm(self, vm):
|
||||
vm.stop(self.api_client)
|
||||
yield
|
||||
vm.start(self.api_client)
|
||||
|
||||
def updateTemplate(self, value):
|
||||
"""Updates value of the guest VM template's password enabled setting
|
||||
"""
|
||||
|
|
@ -439,7 +447,7 @@ class ConfigDriveUtils:
|
|||
)
|
||||
self.assertEqual(
|
||||
str(metadata["local-hostname.txt"]),
|
||||
vm.instancename,
|
||||
vm.name,
|
||||
"vm name inside metadata does not match with the "
|
||||
"instance name"
|
||||
)
|
||||
|
|
@ -754,15 +762,28 @@ class ConfigDriveUtils:
|
|||
:rtype: str
|
||||
"""
|
||||
updated_user_data = base64.b64encode(new_user_data)
|
||||
vm.update(self.api_client, userdata=updated_user_data)
|
||||
return new_user_data
|
||||
with self.stopped_vm(vm):
|
||||
vm.update(self.api_client, userdata=updated_user_data)
|
||||
return updated_user_data
|
||||
|
||||
def reset_password(self, vm):
|
||||
vm.password = vm.resetPassword(self.api_client)
|
||||
"""Resets the password of a VM
|
||||
|
||||
:param vm: the Virtual Machine
|
||||
:type vm: VirtualMachine
|
||||
:returns: The new password
|
||||
:rtype: str
|
||||
"""
|
||||
|
||||
with self.stopped_vm(vm):
|
||||
vm.password = vm.resetPassword(self.api_client)
|
||||
|
||||
self.debug("Password reset to - %s" % vm.password)
|
||||
self.debug("VM - %s password - %s !" %
|
||||
(vm.name, vm.password))
|
||||
|
||||
return vm.password
|
||||
|
||||
def wait_until_done(self, thread_list, name):
|
||||
for aThread in thread_list:
|
||||
self.debug("[Concurrency]Join %s for vm %s" % (name,
|
||||
|
|
@ -774,14 +795,13 @@ class ConfigDriveUtils:
|
|||
|
||||
:type vm: VirtualMachine
|
||||
"""
|
||||
vm.stop(self.api_client)
|
||||
vm_new_ssh = vm.resetSshKey(self.api_client,
|
||||
keypair=self.keypair.name,
|
||||
account=self.account.user[0].account,
|
||||
domainid=self.account.domainid)
|
||||
with self.stopped_vm(vm):
|
||||
vm_new_ssh = vm.resetSshKey(self.api_client,
|
||||
keypair=self.keypair.name,
|
||||
account=self.account.user[0].account,
|
||||
domainid=self.account.domainid)
|
||||
|
||||
self.debug("Sshkey reset to - %s" % self.keypair.name)
|
||||
vm.start(self.api_client)
|
||||
|
||||
vm.details = vm_new_ssh.details
|
||||
|
||||
|
|
@ -1339,6 +1359,46 @@ class TestConfigDrive(cloudstackTestCase, ConfigDriveUtils):
|
|||
self.debug("No host available for migration. "
|
||||
"Test requires at-least 2 hosts")
|
||||
|
||||
# create_NetworkAclList - Creates network ACL list in the given VPC
|
||||
def create_NetworkAclList(self, name, description, vpc):
|
||||
self.debug("Adding NetworkACL list in VPC with ID - %s" % vpc.id)
|
||||
return NetworkACLList.create(self.api_client,
|
||||
services={},
|
||||
name=name,
|
||||
description=description,
|
||||
vpcid=vpc.id
|
||||
)
|
||||
|
||||
# create_NetworkAclRule - Creates Ingress/Egress Network ACL rule in the
|
||||
# given VPC network/acl list
|
||||
def create_NetworkAclRule(self, rule, traffic_type="Ingress", network=None,
|
||||
acl_list=None):
|
||||
self.debug("Adding NetworkACL rule - %s" % rule)
|
||||
if acl_list:
|
||||
return NetworkACL.create(self.api_client,
|
||||
networkid=network.id if network else None,
|
||||
services=rule,
|
||||
traffictype=traffic_type,
|
||||
aclid=acl_list.id
|
||||
)
|
||||
else:
|
||||
return NetworkACL.create(self.api_client,
|
||||
networkid=network.id if network else None,
|
||||
services=rule,
|
||||
traffictype=traffic_type
|
||||
)
|
||||
|
||||
# restart_Vpc - Restarts the given VPC with/without cleanup
|
||||
def restart_Vpc(self, vpc, cleanup=False):
|
||||
self.debug("Restarting VPC with ID - %s" % vpc.id)
|
||||
cmd = restartVPC.restartVPCCmd()
|
||||
cmd.id = vpc.id
|
||||
cmd.cleanup = cleanup
|
||||
cmd.makeredundant = False
|
||||
self.api_client.restartVPC(cmd)
|
||||
self.debug("Restarted VPC with ID - %s" % vpc.id)
|
||||
|
||||
|
||||
@attr(tags=["advanced", "isonw"], required_hardware="true")
|
||||
def test_configdrive_isolated_network(self):
|
||||
"""Test Configdrive as provider for isolated Networks
|
||||
|
|
@ -1410,7 +1470,7 @@ class TestConfigDrive(cloudstackTestCase, ConfigDriveUtils):
|
|||
self.check_Router_state(vr, state="Running")
|
||||
|
||||
# We need to have the vm password
|
||||
vm1.password = vm1.resetPassword(self.api_client)
|
||||
self.reset_password(vm1)
|
||||
self.debug("Password reset to - %s" % vm1.password)
|
||||
self.debug("VM - %s password - %s !" %
|
||||
(vm1.name, vm1.password))
|
||||
|
|
@ -1435,7 +1495,7 @@ class TestConfigDrive(cloudstackTestCase, ConfigDriveUtils):
|
|||
self.generate_ssh_keys()
|
||||
self.update_sshkeypair(vm1)
|
||||
# After sshkey reset we need to have the vm password again
|
||||
vm1.password = vm1.resetPassword(self.api_client)
|
||||
self.reset_password(vm1)
|
||||
self.debug("Password reset to - %s" % vm1.password)
|
||||
self.debug("VM - %s password - %s !" %
|
||||
(vm1.name, vm1.password))
|
||||
|
|
@ -1454,7 +1514,7 @@ class TestConfigDrive(cloudstackTestCase, ConfigDriveUtils):
|
|||
metadata=True,
|
||||
userdata=expected_user_data1,
|
||||
ssh_key=self.keypair)
|
||||
vm1.password = vm1.resetPassword(self.api_client)
|
||||
self.reset_password(vm1)
|
||||
self.debug("Password reset to - %s" % vm1.password)
|
||||
self.debug("VM - %s password - %s !" %
|
||||
(vm1.name, vm1.password))
|
||||
|
|
@ -1481,7 +1541,7 @@ class TestConfigDrive(cloudstackTestCase, ConfigDriveUtils):
|
|||
self.PasswordTest(False),
|
||||
metadata=True,
|
||||
userdata=expected_user_data1)
|
||||
vm1.password = vm1.resetPassword(self.api_client)
|
||||
self.reset_password(vm1)
|
||||
self.debug("Password reset to - %s" % vm1.password)
|
||||
self.debug("VM - %s password - %s !" %
|
||||
(vm1.name, vm1.password))
|
||||
|
|
@ -1535,7 +1595,7 @@ class TestConfigDrive(cloudstackTestCase, ConfigDriveUtils):
|
|||
create_network2.network, operation="remove")
|
||||
create_network2.network.delete(self.api_client)
|
||||
|
||||
vm1.password = vm1.resetPassword(self.api_client)
|
||||
self.reset_password(vm1)
|
||||
self.debug("Password reset to - %s" % vm1.password)
|
||||
self.debug("VM - %s password - %s !" %
|
||||
(vm1.name, vm1.password))
|
||||
|
|
@ -1670,45 +1730,6 @@ class TestConfigDrive(cloudstackTestCase, ConfigDriveUtils):
|
|||
vm1.delete(self.api_client, expunge=True)
|
||||
create_network1.network.delete(self.api_client)
|
||||
|
||||
# create_NetworkAclList - Creates network ACL list in the given VPC
|
||||
def create_NetworkAclList(self, name, description, vpc):
|
||||
self.debug("Adding NetworkACL list in VPC with ID - %s" % vpc.id)
|
||||
return NetworkACLList.create(self.api_client,
|
||||
services={},
|
||||
name=name,
|
||||
description=description,
|
||||
vpcid=vpc.id
|
||||
)
|
||||
|
||||
# create_NetworkAclRule - Creates Ingress/Egress Network ACL rule in the
|
||||
# given VPC network/acl list
|
||||
def create_NetworkAclRule(self, rule, traffic_type="Ingress", network=None,
|
||||
acl_list=None):
|
||||
self.debug("Adding NetworkACL rule - %s" % rule)
|
||||
if acl_list:
|
||||
return NetworkACL.create(self.api_client,
|
||||
networkid=network.id if network else None,
|
||||
services=rule,
|
||||
traffictype=traffic_type,
|
||||
aclid=acl_list.id
|
||||
)
|
||||
else:
|
||||
return NetworkACL.create(self.api_client,
|
||||
networkid=network.id if network else None,
|
||||
services=rule,
|
||||
traffictype=traffic_type
|
||||
)
|
||||
|
||||
# restart_Vpc - Restarts the given VPC with/without cleanup
|
||||
def restart_Vpc(self, vpc, cleanup=False):
|
||||
self.debug("Restarting VPC with ID - %s" % vpc.id)
|
||||
cmd = restartVPC.restartVPCCmd()
|
||||
cmd.id = vpc.id
|
||||
cmd.cleanup = cleanup
|
||||
cmd.makeredundant = False
|
||||
self.api_client.restartVPC(cmd)
|
||||
self.debug("Restarted VPC with ID - %s" % vpc.id)
|
||||
|
||||
@attr(tags=["advanced", "vpc"], required_hardware="true")
|
||||
def test_configdrive_vpc_network(self):
|
||||
"""Test Configdrive for VPC Networks
|
||||
|
|
@ -2188,20 +2209,14 @@ class TestConfigDrive(cloudstackTestCase, ConfigDriveUtils):
|
|||
self.check_Router_state(shared_vr, state="Running")
|
||||
|
||||
# We need to have the vm password
|
||||
vm1.password = vm1.resetPassword(self.api_client)
|
||||
self.debug("Password reset to - %s" % vm1.password)
|
||||
self.debug("VM - %s password - %s !" %
|
||||
(vm1.name, vm1.password))
|
||||
self.reset_password(vm1)
|
||||
self.update_userdata(vm1, "helloworld vm1")
|
||||
|
||||
self.debug("Adding a non-default nic to the VM "
|
||||
"making it a multi-nic VM...")
|
||||
self.nic_operation_VM(vm1, shared_network2.network,
|
||||
operation="add")
|
||||
vm1.password = vm1.resetPassword(self.api_client)
|
||||
self.debug("Password reset to - %s" % vm1.password)
|
||||
self.debug("VM - %s password - %s !" %
|
||||
(vm1.name, vm1.password))
|
||||
self.reset_password(vm1)
|
||||
|
||||
self.debug("updating non-default nic as the default nic "
|
||||
"of the multi-nic VM...")
|
||||
|
|
@ -2210,10 +2225,7 @@ class TestConfigDrive(cloudstackTestCase, ConfigDriveUtils):
|
|||
vm1.stop(self.api_client)
|
||||
vm1.start(self.api_client)
|
||||
|
||||
vm1.password = vm1.resetPassword(self.api_client)
|
||||
self.debug("Password reset to - %s" % vm1.password)
|
||||
self.debug("VM - %s password - %s !" %
|
||||
(vm1.name, vm1.password))
|
||||
self.reset_password(vm1)
|
||||
self.update_userdata(vm1, "hellomultinicvm1")
|
||||
|
||||
self.debug("Updating the default nic of the multi-nic VM, "
|
||||
|
|
@ -2227,10 +2239,7 @@ class TestConfigDrive(cloudstackTestCase, ConfigDriveUtils):
|
|||
shared_network2.network, operation="remove")
|
||||
shared_network2.network.delete(self.api_client)
|
||||
# We need to have the vm password
|
||||
vm1.password = vm1.resetPassword(self.api_client)
|
||||
self.debug("Password reset to - %s" % vm1.password)
|
||||
self.debug("VM - %s password - %s !" %
|
||||
(vm1.name, vm1.password))
|
||||
self.reset_password(vm1)
|
||||
|
||||
self.debug("+++ When template is not password enabled, "
|
||||
"verify configdrive of VM - %s" % vm1.name)
|
||||
|
|
|
|||
|
|
@ -17,8 +17,19 @@
|
|||
|
||||
""" Custom base class for Nuage VSP SDN plugin specific Marvin tests
|
||||
"""
|
||||
import functools
|
||||
import importlib
|
||||
import logging
|
||||
import socket
|
||||
|
||||
import sys
|
||||
import time
|
||||
# Import Local Modules
|
||||
from bambou.nurest_object import NURESTObject
|
||||
from marvin.cloudstackAPI import (restartVPC,
|
||||
enableNuageUnderlayVlanIpRange,
|
||||
disableNuageUnderlayVlanIpRange,
|
||||
listNuageUnderlayVlanIpRanges)
|
||||
from marvin.cloudstackTestCase import cloudstackTestCase, unittest
|
||||
from marvin.lib.base import (Domain,
|
||||
EgressFireWallRule,
|
||||
|
|
@ -44,22 +55,10 @@ from marvin.lib.base import (Domain,
|
|||
from marvin.lib.common import (get_domain,
|
||||
get_template,
|
||||
get_zone)
|
||||
from marvin.cloudstackAPI import (restartVPC,
|
||||
enableNuageUnderlayVlanIpRange,
|
||||
disableNuageUnderlayVlanIpRange,
|
||||
listNuageUnderlayVlanIpRanges)
|
||||
|
||||
from nuage_test_data import nuage_test_data
|
||||
from nuage_vsp_statistics import VsdDataCollector
|
||||
|
||||
# Import System Modules
|
||||
from retry import retry
|
||||
import importlib
|
||||
import functools
|
||||
import logging
|
||||
import socket
|
||||
import time
|
||||
import sys
|
||||
|
||||
from nuage_test_data import nuage_test_data
|
||||
|
||||
|
||||
class needscleanup(object):
|
||||
|
|
@ -89,38 +88,6 @@ class needscleanup(object):
|
|||
return _wrapper
|
||||
|
||||
|
||||
class gherkin(object):
|
||||
"""Decorator to mark a method as Gherkin style.
|
||||
Add extra colored logging
|
||||
"""
|
||||
BLACK = "\033[0;30m"
|
||||
BLUE = "\033[0;34m"
|
||||
GREEN = "\033[0;32m"
|
||||
CYAN = "\033[0;36m"
|
||||
RED = "\033[0;31m"
|
||||
BOLDBLUE = "\033[1;34m"
|
||||
NORMAL = "\033[0m"
|
||||
|
||||
def __init__(self, method):
|
||||
self.method = method
|
||||
|
||||
def __get__(self, obj=None, objtype=None):
|
||||
@functools.wraps(self.method)
|
||||
def _wrapper(*args, **kwargs):
|
||||
gherkin_step = self.method.__name__.replace("_", " ").capitalize()
|
||||
obj.info("=G= %s%s%s" % (self.BOLDBLUE, gherkin_step, self.NORMAL))
|
||||
try:
|
||||
result = self.method(obj, *args, **kwargs)
|
||||
obj.info("=G= %s%s: [SUCCESS]%s" %
|
||||
(self.GREEN, gherkin_step, self.NORMAL))
|
||||
return result
|
||||
except Exception as e:
|
||||
obj.info("=G= %s%s: [FAILED]%s%s" %
|
||||
(self.RED, gherkin_step, self.NORMAL, e))
|
||||
raise
|
||||
return _wrapper
|
||||
|
||||
|
||||
class nuageTestCase(cloudstackTestCase):
|
||||
|
||||
@classmethod
|
||||
|
|
@ -825,7 +792,7 @@ class nuageTestCase(cloudstackTestCase):
|
|||
name=provider_name,
|
||||
physicalnetworkid=self.vsp_physical_network.id
|
||||
)
|
||||
self.assertEqual(isinstance(providers, list), True,
|
||||
self.assertIsInstance(providers, list,
|
||||
"List Network Service Provider should return a "
|
||||
"valid list"
|
||||
)
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@
|
|||
# KIND, either express or implied. See the License for the
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
import functools
|
||||
|
||||
from marvin.cloudstackAPI import createSSHKeyPair, deleteSSHKeyPair
|
||||
|
||||
|
|
@ -44,4 +45,36 @@ class MySSHKeyPair:
|
|||
cmd.name = self.name
|
||||
cmd.account = self.account
|
||||
cmd.domainid = self.domainid
|
||||
apiclient.deleteSSHKeyPair(cmd)
|
||||
apiclient.deleteSSHKeyPair(cmd)
|
||||
|
||||
|
||||
class gherkin(object):
|
||||
"""Decorator to mark a method as Gherkin style.
|
||||
Add extra colored logging
|
||||
"""
|
||||
BLACK = "\033[0;30m"
|
||||
BLUE = "\033[0;34m"
|
||||
GREEN = "\033[0;32m"
|
||||
CYAN = "\033[0;36m"
|
||||
RED = "\033[0;31m"
|
||||
BOLDBLUE = "\033[1;34m"
|
||||
NORMAL = "\033[0m"
|
||||
|
||||
def __init__(self, method):
|
||||
self.method = method
|
||||
|
||||
def __get__(self, obj=None, objtype=None):
|
||||
@functools.wraps(self.method)
|
||||
def _wrapper(*args, **kwargs):
|
||||
gherkin_step = self.method.__name__.replace("_", " ").capitalize()
|
||||
obj.info("=G= %s%s%s" % (self.BOLDBLUE, gherkin_step, self.NORMAL))
|
||||
try:
|
||||
result = self.method(obj, *args, **kwargs)
|
||||
obj.info("=G= %s%s: [SUCCESS]%s" %
|
||||
(self.GREEN, gherkin_step, self.NORMAL))
|
||||
return result
|
||||
except Exception as e:
|
||||
obj.info("=G= %s%s: [FAILED]%s%s" %
|
||||
(self.RED, gherkin_step, self.NORMAL, e))
|
||||
raise
|
||||
return _wrapper
|
||||
|
|
@ -242,6 +242,34 @@ class TestNuageConfigDrive(nuageTestCase, ConfigDriveUtils):
|
|||
# --- Gherkin style helper methods ---
|
||||
# =========================================================================
|
||||
|
||||
def given_config_drive_provider_is(self, state):
|
||||
return self.update_provider_state(state)
|
||||
|
||||
def given_a_network_offering_with_configdrive(self):
|
||||
self.offering = self.create_NetworkOffering(self._get_test_data(
|
||||
"isolated_configdrive_network_offering_withoutdns"))
|
||||
|
||||
def then_creating_a_network_with_that_offering_fails(self):
|
||||
create_network = self.verify_network_creation(
|
||||
offering=self.offering,
|
||||
gateway='10.6.6.6')
|
||||
self.assertFalse(create_network.success,
|
||||
'Network found success = %s, expected success =%s'
|
||||
% (str(create_network.success), 'False'))
|
||||
|
||||
def when_I_create_a_network_with_that_offering(self):
|
||||
return self.verify_network_creation(
|
||||
offering=self.offering,
|
||||
gateway='10.1.1.1')
|
||||
|
||||
def then_the_network_is_successfully_created(self, network):
|
||||
self.assertTrue(network.success,
|
||||
'Network found success = %s, expected success = %s'
|
||||
% (str(network.success), 'True'))
|
||||
|
||||
def then_the_network_is_has(self, network, state):
|
||||
self.validate_Network(network, state=state)
|
||||
|
||||
# =========================================================================
|
||||
# --- TEST CASES ---
|
||||
# =========================================================================
|
||||
|
|
@ -290,34 +318,24 @@ class TestNuageConfigDrive(nuageTestCase, ConfigDriveUtils):
|
|||
|
||||
self.debug("+++Testing configdrive in an Isolated network fails..."
|
||||
"as provider configdrive is still disabled...")
|
||||
self.update_provider_state("Disabled")
|
||||
create_network = self.verify_network_creation(
|
||||
offering_name="isolated_configdrive_network_offering_"
|
||||
"withoutdns",
|
||||
gateway='10.1.1.1')
|
||||
self.assertFalse(create_network.success,
|
||||
'Network found success = %s, expected success =%s'
|
||||
% (str(create_network.success), 'False'))
|
||||
|
||||
|
||||
self.given_config_drive_provider_is("Disabled")
|
||||
self.given_a_network_offering_with_configdrive()
|
||||
self.then_creating_a_network_with_that_offering_fails()
|
||||
|
||||
self.debug("+++Test user data & password reset functionality "
|
||||
"using configdrive in an Isolated network without VR")
|
||||
self.update_provider_state("Enabled")
|
||||
create_network1 = self.verify_network_creation(
|
||||
offering=create_network.offering,
|
||||
gateway='10.1.1.1')
|
||||
self.assertTrue(create_network1.success,
|
||||
'Network found success = %s, expected success = %s'
|
||||
% (str(create_network1.success), 'True'))
|
||||
self.validate_Network(create_network1.network, state="Allocated")
|
||||
create_network2 = self.verify_network_creation(
|
||||
offering=create_network.offering,
|
||||
gateway='10.1.2.1')
|
||||
self.assertTrue(create_network2.success,
|
||||
'Network found success = %s,expected success = %s'
|
||||
% (str(create_network2.success), 'True'))
|
||||
self.validate_Network(create_network2.network, state="Allocated")
|
||||
|
||||
self.given_config_drive_provider_is("Enabled")
|
||||
create_network1 = self.when_I_create_a_network_with_that_offering()
|
||||
self.then_the_network_is_successfully_created(create_network1)
|
||||
self.then_the_network_is_has(create_network1, state="Allocated")
|
||||
|
||||
create_network2 = self.when_I_create_a_network_with_that_offering()
|
||||
self.then_the_network_is_successfully_created(create_network2)
|
||||
self.then_the_network_is_has(create_network2, state="Allocated")
|
||||
|
||||
|
||||
self.update_password_enable_in_template(True)
|
||||
|
||||
self.debug("+++Deploy VM in the created Isolated network "
|
||||
|
|
@ -331,8 +349,9 @@ class TestNuageConfigDrive(nuageTestCase, ConfigDriveUtils):
|
|||
with self.assertRaises(Exception):
|
||||
self.get_Router(create_network1)
|
||||
self.debug("+++Verified no VR is spawned for this network ")
|
||||
|
||||
# We need to have the vm password
|
||||
vm1.password = vm1.resetPassword(self.api_client)
|
||||
self.reset_password(vm1)
|
||||
self.debug("Password reset to - %s" % vm1.password)
|
||||
self.debug("VM - %s password - %s !" %
|
||||
(vm1.name, vm1.password))
|
||||
|
|
@ -362,10 +381,7 @@ class TestNuageConfigDrive(nuageTestCase, ConfigDriveUtils):
|
|||
userdata=expected_user_data1,
|
||||
ssh_key=self.keypair)
|
||||
# After sshkey reset we need to have the vm password again
|
||||
vm1.password = vm1.resetPassword(self.api_client)
|
||||
self.debug("Password reset to - %s" % vm1.password)
|
||||
self.debug("VM - %s password - %s !" %
|
||||
(vm1.name, vm1.password))
|
||||
self.reset_password(vm1)
|
||||
|
||||
self.debug("Adding a non-default nic to the VM "
|
||||
"making it a multi-nic VM...")
|
||||
|
|
@ -376,10 +392,7 @@ class TestNuageConfigDrive(nuageTestCase, ConfigDriveUtils):
|
|||
metadata=True,
|
||||
userdata=expected_user_data1,
|
||||
ssh_key=self.keypair)
|
||||
vm1.password = vm1.resetPassword(self.api_client)
|
||||
self.debug("Password reset to - %s" % vm1.password)
|
||||
self.debug("VM - %s password - %s !" %
|
||||
(vm1.name, vm1.password))
|
||||
self.reset_password(vm1)
|
||||
|
||||
expected_user_data1 = self.update_userdata(vm1,
|
||||
"hellomultinicvm1")
|
||||
|
|
@ -403,10 +416,7 @@ class TestNuageConfigDrive(nuageTestCase, ConfigDriveUtils):
|
|||
self.PasswordTest(False),
|
||||
metadata=True,
|
||||
userdata=expected_user_data1)
|
||||
vm1.password = vm1.resetPassword(self.api_client)
|
||||
self.debug("Password reset to - %s" % vm1.password)
|
||||
self.debug("VM - %s password - %s !" %
|
||||
(vm1.name, vm1.password))
|
||||
self.reset_password(vm1)
|
||||
self.verify_config_drive_content(vm1, public_ip_2,
|
||||
self.PasswordTest(vm1.password),
|
||||
userdata=expected_user_data1)
|
||||
|
|
@ -457,10 +467,7 @@ class TestNuageConfigDrive(nuageTestCase, ConfigDriveUtils):
|
|||
create_network2.network, operation="remove")
|
||||
create_network2.network.delete(self.api_client)
|
||||
|
||||
vm1.password = vm1.resetPassword(self.api_client)
|
||||
self.debug("Password reset to - %s" % vm1.password)
|
||||
self.debug("VM - %s password - %s !" %
|
||||
(vm1.name, vm1.password))
|
||||
self.reset_password(vm1)
|
||||
|
||||
self.debug("+++ Restarting the created Isolated network without "
|
||||
"VR without cleanup...")
|
||||
|
|
@ -517,10 +524,7 @@ class TestNuageConfigDrive(nuageTestCase, ConfigDriveUtils):
|
|||
self.debug("+++Verified VR is spawned for this network ")
|
||||
|
||||
# We need to have the vm password
|
||||
vm2.password = vm2.resetPassword(self.api_client)
|
||||
self.debug("Password reset to - %s" % vm2.password)
|
||||
self.debug("VM2 - %s password - %s !" %
|
||||
(vm2.name, vm2.password))
|
||||
self.reset_password(vm2)
|
||||
public_ip_3 = self.acquire_PublicIPAddress(
|
||||
create_vrnetwork1.network)
|
||||
self.create_and_verify_fip_and_fw(vm2, public_ip_3,
|
||||
|
|
@ -632,7 +636,6 @@ class TestNuageConfigDrive(nuageTestCase, ConfigDriveUtils):
|
|||
self.verify_config_drive_content(vm1, public_ip_1,
|
||||
self.PasswordTest(False),
|
||||
userdata=expected_user_data1)
|
||||
self.debug("Resetting password for VM - %s" % vm1.name)
|
||||
self.reset_password(vm1)
|
||||
self.debug("SSHing into the VM for verifying its new password "
|
||||
"after its password reset...")
|
||||
|
|
@ -966,7 +969,7 @@ class TestNuageConfigDrive(nuageTestCase, ConfigDriveUtils):
|
|||
self.verify_vsd_router(vr2)
|
||||
self.debug("+++Verified VR is spawned for this network ")
|
||||
# We need to have the vm password
|
||||
vm2.password = vm2.resetPassword(self.api_client)
|
||||
self.reset_password(vm2)
|
||||
self.debug("Password reset to - %s" % vm2.password)
|
||||
self.debug("VM2 - %s password - %s !" %
|
||||
(vm2.name, vm2.password))
|
||||
|
|
@ -1431,7 +1434,7 @@ class TestNuageConfigDrive(nuageTestCase, ConfigDriveUtils):
|
|||
self.get_Router(shared_network)
|
||||
self.debug("+++ Verified no VR is spawned for this network ")
|
||||
# We need to have the vm password
|
||||
vm1.password = vm1.resetPassword(self.api_client)
|
||||
self.reset_password(vm1)
|
||||
self.debug("Password reset to - %s" % vm1.password)
|
||||
self.debug("VM - %s password - %s !" %
|
||||
(vm1.name, vm1.password))
|
||||
|
|
@ -1456,7 +1459,7 @@ class TestNuageConfigDrive(nuageTestCase, ConfigDriveUtils):
|
|||
metadata=True,
|
||||
userdata=expected_user_data,
|
||||
ssh_key=self.keypair)
|
||||
vm1.password = vm1.resetPassword(self.api_client)
|
||||
self.reset_password(vm1)
|
||||
self.debug("Password reset to - %s" % vm1.password)
|
||||
self.debug("VM - %s password - %s !" %
|
||||
(vm1.name, vm1.password))
|
||||
|
|
@ -1482,7 +1485,7 @@ class TestNuageConfigDrive(nuageTestCase, ConfigDriveUtils):
|
|||
self.PasswordTest(False),
|
||||
metadata=True,
|
||||
userdata=expected_user_data1)
|
||||
vm1.password = vm1.resetPassword(self.api_client)
|
||||
self.reset_password(vm1)
|
||||
self.debug("Password reset to - %s" % vm1.password)
|
||||
self.debug("VM - %s password - %s !" %
|
||||
(vm1.name, vm1.password))
|
||||
|
|
@ -1534,7 +1537,7 @@ class TestNuageConfigDrive(nuageTestCase, ConfigDriveUtils):
|
|||
|
||||
shared_network2.network.delete(self.api_client)
|
||||
# We need to have the vm password
|
||||
vm1.password = vm1.resetPassword(self.api_client)
|
||||
self.reset_password(vm1)
|
||||
self.debug("Password reset to - %s" % vm1.password)
|
||||
self.debug("VM - %s password - %s !" %
|
||||
(vm1.name, vm1.password))
|
||||
|
|
@ -1687,7 +1690,7 @@ class TestNuageConfigDrive(nuageTestCase, ConfigDriveUtils):
|
|||
self.get_Router(create_network)
|
||||
self.debug("+++Verified no VR is spawned for this network ")
|
||||
# We need to have the vm password
|
||||
vm1.password = vm1.resetPassword(self.api_client)
|
||||
self.reset_password(vm1)
|
||||
self.debug("Password reset to - %s" % vm1.password)
|
||||
self.debug("VM - %s password - %s !" %
|
||||
(vm1.name, vm1.password))
|
||||
|
|
|
|||
|
|
@ -19,7 +19,8 @@
|
|||
Nuage VSP SDN plugin
|
||||
"""
|
||||
# Import Local Modules
|
||||
from nuageTestCase import (nuageTestCase, gherkin)
|
||||
from nuageTestCase import (nuageTestCase)
|
||||
from plugins.nuagevsp.nuage_lib import gherkin
|
||||
from marvin.cloudstackAPI import updateVirtualMachine, updateZone
|
||||
from marvin.lib.base import (Account,
|
||||
Network,
|
||||
|
|
|
|||
Loading…
Reference in New Issue