Repository: cloudstack
Updated Branches:
  refs/heads/reporter 5c9978471 -> 28300b5d0 (forced update)


Making possible to update KVM hosts password in the database via the API

   - Make sure the doUpdateHostPassword() method returns the result from the 
answer, not always true
   - Added the LibvirtUpdateHostPasswordCommandWrapper class, which will handle 
the changes in the KVM agent
     That's will be further implemented in the future. The command will avoid 
the agent to complain about Unsupported command
   - Added a test to make sure the current implementation of the comment works
     - If changes in the future, it will also require changes. In that way, we 
make sure nobody will break it

Signed-off-by: wilderrodrigues <[email protected]>

This closes #527


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/527d6ee7
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/527d6ee7
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/527d6ee7

Branch: refs/heads/reporter
Commit: 527d6ee77b6b202a5af00984a5e8a6a79ffa457a
Parents: b8ab3cd
Author: wilderrodrigues <[email protected]>
Authored: Thu Jun 25 14:32:51 2015 +0200
Committer: wilderrodrigues <[email protected]>
Committed: Mon Jun 29 09:59:12 2015 +0200

----------------------------------------------------------------------
 ...LibvirtUpdateHostPasswordCommandWrapper.java | 35 ++++++++++++++++++++
 .../resource/LibvirtComputingResourceTest.java  | 15 +++++++++
 .../com/cloud/resource/ResourceManagerImpl.java |  2 +-
 3 files changed, 51 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/527d6ee7/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtUpdateHostPasswordCommandWrapper.java
----------------------------------------------------------------------
diff --git 
a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtUpdateHostPasswordCommandWrapper.java
 
b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtUpdateHostPasswordCommandWrapper.java
new file mode 100644
index 0000000..5b7c7da
--- /dev/null
+++ 
b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtUpdateHostPasswordCommandWrapper.java
@@ -0,0 +1,35 @@
+//
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+//
+
+package com.cloud.hypervisor.kvm.resource.wrapper;
+
+import com.cloud.agent.api.Answer;
+import com.cloud.agent.api.UpdateHostPasswordCommand;
+import com.cloud.hypervisor.kvm.resource.LibvirtComputingResource;
+import com.cloud.resource.CommandWrapper;
+import com.cloud.resource.ResourceWrapper;
+
+@ResourceWrapper(handles =  UpdateHostPasswordCommand.class)
+public final class LibvirtUpdateHostPasswordCommandWrapper extends 
CommandWrapper<UpdateHostPasswordCommand, Answer, LibvirtComputingResource> {
+
+    @Override
+    public Answer execute(final UpdateHostPasswordCommand command, final 
LibvirtComputingResource libvirtComputingResource) {
+        return new Answer(command, true, null);
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/527d6ee7/plugins/hypervisors/kvm/test/com/cloud/hypervisor/kvm/resource/LibvirtComputingResourceTest.java
----------------------------------------------------------------------
diff --git 
a/plugins/hypervisors/kvm/test/com/cloud/hypervisor/kvm/resource/LibvirtComputingResourceTest.java
 
b/plugins/hypervisors/kvm/test/com/cloud/hypervisor/kvm/resource/LibvirtComputingResourceTest.java
index d3c8824..d5ce9bf 100644
--- 
a/plugins/hypervisors/kvm/test/com/cloud/hypervisor/kvm/resource/LibvirtComputingResourceTest.java
+++ 
b/plugins/hypervisors/kvm/test/com/cloud/hypervisor/kvm/resource/LibvirtComputingResourceTest.java
@@ -127,6 +127,7 @@ import 
com.cloud.agent.api.SecurityGroupRulesCmd.IpPortAndProto;
 import com.cloud.agent.api.StartCommand;
 import com.cloud.agent.api.StopCommand;
 import com.cloud.agent.api.UnPlugNicCommand;
+import com.cloud.agent.api.UpdateHostPasswordCommand;
 import com.cloud.agent.api.UpgradeSnapshotCommand;
 import com.cloud.agent.api.VmStatsEntry;
 import com.cloud.agent.api.check.CheckSshCommand;
@@ -5072,4 +5073,18 @@ public class LibvirtComputingResourceTest {
             fail(e.getMessage());
         }
     }
+
+    @Test
+    public void testUpdateHostPasswordCommand() {
+        final String username = "root";
+        final String newPassword = "password";
+        final UpdateHostPasswordCommand command = new 
UpdateHostPasswordCommand(username, newPassword);
+
+        final LibvirtRequestWrapper wrapper = 
LibvirtRequestWrapper.getInstance();
+        assertNotNull(wrapper);
+
+        final Answer answer = wrapper.execute(command, 
libvirtComputingResource);
+
+        assertTrue(answer.getResult());
+    }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/527d6ee7/server/src/com/cloud/resource/ResourceManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/resource/ResourceManagerImpl.java 
b/server/src/com/cloud/resource/ResourceManagerImpl.java
index c1a7dbc..df6071c 100644
--- a/server/src/com/cloud/resource/ResourceManagerImpl.java
+++ b/server/src/com/cloud/resource/ResourceManagerImpl.java
@@ -2235,7 +2235,7 @@ public class ResourceManagerImpl extends ManagerBase 
implements ResourceManager,
         final String password = nv.getValue();
         final UpdateHostPasswordCommand cmd = new 
UpdateHostPasswordCommand(username, password);
         final Answer answer = _agentMgr.easySend(hostId, cmd);
-        return answer != null;
+        return answer.getResult();
     }
 
     @Override

Reply via email to