You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by ro...@apache.org on 2020/02/28 06:30:30 UTC

[cloudstack] branch 4.13 updated: server: send VM password to all Running VRs in network/vpc (#3903)

This is an automated email from the ASF dual-hosted git repository.

rohit pushed a commit to branch 4.13
in repository https://gitbox.apache.org/repos/asf/cloudstack.git


The following commit(s) were added to refs/heads/4.13 by this push:
     new abb39a2  server: send VM password to all Running VRs in network/vpc (#3903)
abb39a2 is described below

commit abb39a25affbbc6144a1becce252f1a836af0434
Author: Rakesh <ra...@gmail.com>
AuthorDate: Fri Feb 28 07:30:16 2020 +0100

    server: send VM password to all Running VRs in network/vpc (#3903)
    
    Currently, the cloudstack sends VM password only to the first
    router in the network even if its the backup and return the result.
    
    In some cases the first router will be back up and the second will be master.
    Since password server is not running in backup, when the user resets the password,
    it is sent to the first router which can be backup.
    In that case, the new password is not stored in the password server and users cant log in with a new password.
    
    This change ensures that we send the password to both the routers instead
    of the first router so that a new password is stored in the master router.
---
 .../network/element/VirtualRouterElement.java      | 26 +++++++++++++++++-----
 1 file changed, 20 insertions(+), 6 deletions(-)

diff --git a/server/src/main/java/com/cloud/network/element/VirtualRouterElement.java b/server/src/main/java/com/cloud/network/element/VirtualRouterElement.java
index 97a26d4..da066f0 100644
--- a/server/src/main/java/com/cloud/network/element/VirtualRouterElement.java
+++ b/server/src/main/java/com/cloud/network/element/VirtualRouterElement.java
@@ -702,18 +702,32 @@ NetworkMigrationResponder, AggregatedCommandExecutor, RedundantResource, DnsServ
 
         // If any router is running then send save password command otherwise
         // save the password in DB
+        boolean savePasswordResult = true;
+        boolean isVrRunning = false;
         for (final VirtualRouter router : routers) {
             if (router.getState() == State.Running) {
                 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);
+                if (!result) {
+                    s_logger.error("Unable to save password for VM " + vm.getInstanceName() +
+                            " on router " + router.getInstanceName());
+                    return false;
                 }
-                return result;
+                isVrRunning = true;
+                savePasswordResult = savePasswordResult && result;
             }
         }
+
+        // return the result only if one of the vr is running
+        if (isVrRunning) {
+            if (savePasswordResult) {
+                // 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 savePasswordResult;
+        }
+
         final String password = (String) uservm.getParameter(VirtualMachineProfile.Param.VmPassword);
         final String password_encrypted = DBEncryptionUtil.encrypt(password);
         final UserVmVO userVmVO = _userVmDao.findById(vm.getId());