Skip to content

Commit 0dd02ce

Browse files
CLOUDSTACK-8607 - Adding support to update host passwd on XenServer hypervisors
- Adding update_host_passwd to VRScripts - Add accessor method to host password on CitrixResourceBase - Add implementation to CitrixUpdateHostPasswordCommandWrapper - Improve testUpdateHostPasswordCommand() unit test on CitrixRequestWrapperTest - Add line to patch files on xenserver directory Concerning the LibVirt change: - I forgot to assing the return of the getDefaultHypervisorScriptsDir() method to the hypervisorScriptsDir variable
1 parent 47c7a10 commit 0dd02ce

13 files changed

Lines changed: 147 additions & 74 deletions

File tree

core/src/com/cloud/agent/resource/virtualnetwork/VRScripts.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ public class VRScripts {
7474
public static final String VPC_STATIC_NAT = "vpc_staticnat.sh";
7575
public static final String VPC_STATIC_ROUTE = "vpc_staticroute.sh";
7676
public static final String VPN_L2TP = "vpn_l2tp.sh";
77+
public static final String UPDATE_HOST_PASSWD = "update_host_passwd.sh";
7778

7879
public static final String VR_CFG = "vr_cfg.sh";
7980

plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,7 @@ protected String getDefaultStorageScriptsDir() {
523523
}
524524

525525
protected String getDefaultHypervisorScriptsDir() {
526-
return "scripts/vm/hypervisor";
526+
return "scripts/vm/hypervisor/kvm";
527527
}
528528

529529
protected String getDefaultKvmScriptsDir() {
@@ -557,9 +557,9 @@ public boolean configure(final String name, final Map<String, Object> params) th
557557
domrScriptsDir = getDefaultDomrScriptsDir();
558558
}
559559

560-
final String hypervisorScriptsDir = (String)params.get("hypervisor.scripts.dir");
560+
String hypervisorScriptsDir = (String)params.get("hypervisor.scripts.dir");
561561
if (hypervisorScriptsDir == null) {
562-
getDefaultHypervisorScriptsDir();
562+
hypervisorScriptsDir = getDefaultHypervisorScriptsDir();
563563
}
564564

565565
String kvmScriptsDir = (String)params.get("kvm.scripts.dir");

plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/CitrixResourceBase.java

Lines changed: 68 additions & 64 deletions
Large diffs are not rendered by default.

plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixUpdateHostPasswordCommandWrapper.java

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,46 @@
1919

2020
package com.cloud.hypervisor.xenserver.resource.wrapper.xenbase;
2121

22+
import org.apache.log4j.Logger;
23+
2224
import com.cloud.agent.api.Answer;
2325
import com.cloud.agent.api.UpdateHostPasswordCommand;
26+
import com.cloud.agent.resource.virtualnetwork.VRScripts;
2427
import com.cloud.hypervisor.xenserver.resource.CitrixResourceBase;
2528
import com.cloud.resource.CommandWrapper;
2629
import com.cloud.resource.ResourceWrapper;
30+
import com.cloud.utils.Pair;
31+
import com.cloud.utils.ssh.SshHelper;
2732

2833
@ResourceWrapper(handles = UpdateHostPasswordCommand.class)
2934
public final class CitrixUpdateHostPasswordCommandWrapper extends CommandWrapper<UpdateHostPasswordCommand, Answer, CitrixResourceBase> {
3035

36+
private static final Logger s_logger = Logger.getLogger(CitrixUpdateHostPasswordCommandWrapper.class);
37+
private static final int TIMEOUT = 10000;
38+
3139
@Override
3240
public Answer execute(final UpdateHostPasswordCommand command, final CitrixResourceBase citrixResourceBase) {
41+
final String hostIp = command.getHostIp();
42+
final String username = command.getUsername();
43+
final String newPassword = command.getNewPassword();
44+
45+
final StringBuffer cmdLine = new StringBuffer();
46+
cmdLine.append(VRScripts.UPDATE_HOST_PASSWD);
47+
cmdLine.append(' ');
48+
cmdLine.append(username);
49+
cmdLine.append(' ');
50+
cmdLine.append(newPassword);
51+
52+
Pair<Boolean, String> result;
53+
54+
try {
55+
s_logger.debug("Executing command in Host: " + cmdLine);
56+
result = SshHelper.sshExecute(hostIp, 22, username, null, citrixResourceBase.getPwdFromQueue(), cmdLine.toString(), 60000, 60000, TIMEOUT);
57+
} catch (final Exception e) {
58+
return new Answer(command, false, e.getMessage());
59+
}
60+
// Add new password to the stack.
3361
citrixResourceBase.addToPwdQueue(command.getNewPassword());
34-
return new Answer(command, true, null);
62+
return new Answer(command, result.first(), result.second());
3563
}
3664
}

plugins/hypervisors/xenserver/test/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixRequestWrapperTest.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@
118118
import com.cloud.agent.api.to.NicTO;
119119
import com.cloud.agent.api.to.StorageFilerTO;
120120
import com.cloud.agent.api.to.VirtualMachineTO;
121+
import com.cloud.agent.resource.virtualnetwork.VRScripts;
121122
import com.cloud.agent.resource.virtualnetwork.VirtualRoutingResource;
122123
import com.cloud.host.HostEnvironment;
123124
import com.cloud.hypervisor.xenserver.resource.CitrixResourceBase;
@@ -129,6 +130,7 @@
129130
import com.cloud.storage.Storage.StoragePoolType;
130131
import com.cloud.storage.VMTemplateStorageResourceAssoc;
131132
import com.cloud.storage.resource.StorageSubsystemCommandHandler;
133+
import com.cloud.utils.ExecutionResult;
132134
import com.cloud.vm.DiskProfile;
133135
import com.cloud.vm.VirtualMachine;
134136
import com.xensource.xenapi.Connection;
@@ -1320,14 +1322,23 @@ public void testOvsDestroyTunnelCommandFailed() {
13201322

13211323
@Test
13221324
public void testUpdateHostPasswordCommand() {
1323-
final UpdateHostPasswordCommand updatePwd = new UpdateHostPasswordCommand("test", "123");
1325+
final ExecutionResult executionResult = Mockito.mock(ExecutionResult.class);
1326+
1327+
final UpdateHostPasswordCommand updatePwd = new UpdateHostPasswordCommand("test", "123", "127.0.0.1");
1328+
1329+
final StringBuffer buff = new StringBuffer();
1330+
buff.append(updatePwd.getUsername());
1331+
buff.append(' ');
1332+
buff.append(updatePwd.getNewPassword());
1333+
1334+
when(citrixResourceBase.executeInVR(updatePwd.getHostIp(), VRScripts.UPDATE_HOST_PASSWD, buff.toString())).thenReturn(executionResult);
13241335

13251336
final CitrixRequestWrapper wrapper = CitrixRequestWrapper.getInstance();
13261337
assertNotNull(wrapper);
13271338

13281339
final Answer answer = wrapper.execute(updatePwd, citrixResourceBase);
13291340

1330-
assertTrue(answer.getResult());
1341+
assertFalse(answer.getResult());
13311342
}
13321343

13331344
@Test

scripts/vm/hypervisor/update_host_passwd.sh renamed to scripts/vm/hypervisor/kvm/update_host_passwd.sh

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,9 @@
1616
# specific language governing permissions and limitations
1717
# under the License.
1818

19-
hostIp=$1
20-
username=$2
21-
new_passwd=$3
19+
username=$1
20+
new_passwd=$2
2221

23-
ssh -o StrictHostKeyChecking=no -p 3922 -i /root/.ssh/id_rsa.cloud root@$hostIp "echo -e "$new_passwd\n$new_passwd" | passwd --stdin $username"
22+
echo -e "$new_passwd\n$new_passwd" | passwd --stdin $username
2423

2524
return $?;
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/bin/bash
2+
# Licensed to the Apache Software Foundation (ASF) under one
3+
# or more contributor license agreements. See the NOTICE file
4+
# distributed with this work for additional information
5+
# regarding copyright ownership. The ASF licenses this file
6+
# to you under the Apache License, Version 2.0 (the
7+
# "License"); you may not use this file except in compliance
8+
# with the License. You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing,
13+
# software distributed under the License is distributed on an
14+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
# KIND, either express or implied. See the License for the
16+
# specific language governing permissions and limitations
17+
# under the License.
18+
19+
username=$1
20+
new_passwd=$2
21+
22+
echo -e "$new_passwd\n$new_passwd" | passwd --stdin $username
23+
24+
return $?;

scripts/vm/hypervisor/xenserver/xcpserver/patch

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,4 @@ add_to_vcpus_params_live.sh=..,0755,/opt/cloud/bin
5959
cloudstack_plugins.conf=..,0644,/etc/xensource
6060
cloudstack_pluginlib.py=..,0755,/etc/xapi.d/plugins
6161
cloudlog=..,0644,/etc/logrotate.d
62+
update_host_passwd.sh=..,0755,/opt/cloud/bin

scripts/vm/hypervisor/xenserver/xenserver56/patch

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,4 @@ add_to_vcpus_params_live.sh=..,0755,/opt/cloud/bin
6363
cloudstack_plugins.conf=..,0644,/etc/xensource
6464
cloudstack_pluginlib.py=..,0755,/etc/xapi.d/plugins
6565
cloudlog=..,0644,/etc/logrotate.d
66+
update_host_passwd.sh=..,0755,/opt/cloud/bin

scripts/vm/hypervisor/xenserver/xenserver56fp1/patch

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,4 @@ add_to_vcpus_params_live.sh=..,0755,/opt/cloud/bin
6262
cloudstack_plugins.conf=..,0644,/etc/xensource
6363
cloudstack_pluginlib.py=..,0755,/etc/xapi.d/plugins
6464
cloudlog=..,0644,/etc/logrotate.d
65+
update_host_passwd.sh=..,0755,/opt/cloud/bin

0 commit comments

Comments
 (0)