Skip to content

Commit

Permalink
Making possible to update KVM hosts password in the database via the API
Browse files Browse the repository at this point in the history
   - 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 apache#527
  • Loading branch information
wilderrodrigues committed Jun 29, 2015
1 parent b8ab3cd commit 527d6ee
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@
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;
Expand Down Expand Up @@ -5072,4 +5073,18 @@ public void testStartCommandIsolationEc2() {
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());
}
}
2 changes: 1 addition & 1 deletion server/src/com/cloud/resource/ResourceManagerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -2235,7 +2235,7 @@ private boolean doUpdateHostPassword(final long hostId) {
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
Expand Down

0 comments on commit 527d6ee

Please sign in to comment.