Skip to content

Commit 0700d91

Browse files
committed
Merge branch '4.12'
- Fixes PR #3146 db cleanup to the correct 4.12->4.13 upgrade path - Fixes failing unit test due to jdk specific changes after forward merging Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com>
2 parents e11f7ee + 00ff536 commit 0700d91

20 files changed

Lines changed: 246 additions & 346 deletions

File tree

api/src/main/java/com/cloud/storage/Volume.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ enum State {
5252
UploadInProgress("Volume upload is in progress"),
5353
UploadError("Volume upload encountered some error"),
5454
UploadAbandoned("Volume upload is abandoned since the upload was never initiated within a specificed time"),
55-
Attaching("The volume is attaching to a VM");
55+
Attaching("The volume is attaching to a VM from Ready state.");
5656

5757
String _description;
5858

@@ -72,6 +72,8 @@ public String getDescription() {
7272
static {
7373
s_fsm.addTransition(new StateMachine2.Transition<State, Event>(Allocated, Event.CreateRequested, Creating, null));
7474
s_fsm.addTransition(new StateMachine2.Transition<State, Event>(Allocated, Event.DestroyRequested, Destroy, null));
75+
s_fsm.addTransition(new StateMachine2.Transition<State, Event>(Allocated, Event.OperationFailed, Allocated, null));
76+
s_fsm.addTransition(new StateMachine2.Transition<State, Event>(Allocated, Event.OperationSucceeded, Allocated, null));
7577
s_fsm.addTransition(new StateMachine2.Transition<State, Event>(Creating, Event.OperationRetry, Creating, null));
7678
s_fsm.addTransition(new StateMachine2.Transition<State, Event>(Creating, Event.OperationFailed, Allocated, null));
7779
s_fsm.addTransition(new StateMachine2.Transition<State, Event>(Creating, Event.OperationSucceeded, Ready, null));

engine/schema/src/main/java/com/cloud/configuration/dao/ResourceCountDaoImpl.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,13 +266,14 @@ public long countMemoryAllocatedToAccount(long accountId) {
266266
}
267267

268268
private long executeSqlCountComputingResourcesForAccount(long accountId, String sqlCountComputingResourcesAllocatedToAccount) {
269-
try (TransactionLegacy tx = TransactionLegacy.currentTxn()) {
269+
TransactionLegacy tx = TransactionLegacy.currentTxn();
270+
try {
270271
PreparedStatement pstmt = tx.prepareAutoCloseStatement(sqlCountComputingResourcesAllocatedToAccount);
271272
pstmt.setLong(1, accountId);
272273

273274
ResultSet rs = pstmt.executeQuery();
274275
if (!rs.next()) {
275-
throw new CloudRuntimeException(String.format("An unexpected case happened while counting allocated computing resources for account: " + accountId));
276+
return 0L;
276277
}
277278
return rs.getLong("total");
278279
} catch (SQLException e) {

engine/schema/src/main/resources/META-INF/db/schema-41120to41200-cleanup.sql

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,3 @@ DROP TABLE IF EXISTS `cloud`.`iam_group_policy_map`;
2525
DROP TABLE IF EXISTS `cloud`.`iam_group`;
2626
DROP TABLE IF EXISTS `cloud`.`iam_policy_permission`;
2727
DROP TABLE IF EXISTS `cloud`.`iam_policy`;
28-
29-
-- Cleanup Nuage VSP
30-
DELETE FROM `cloud`.`host` WHERE id in (SELECT vsp.host_id FROM `cloud`.`external_nuage_vsp_devices` vsp);
31-
DROP TABLE IF EXISTS `cloud`.`external_nuage_vsp_devices`;
32-
delete from `cloud`.`role_permissions` where rule = 'issueNuageVspResourceRequest';

engine/schema/src/main/resources/META-INF/db/schema-41200to41300-cleanup.sql

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,7 @@
1919
-- Schema upgrade cleanup from 4.12.0.0 to 4.13.0.0
2020
--;
2121

22+
-- Cleanup Nuage VSP
23+
DELETE FROM `cloud`.`host` WHERE id in (SELECT vsp.host_id FROM `cloud`.`external_nuage_vsp_devices` vsp);
24+
DROP TABLE IF EXISTS `cloud`.`external_nuage_vsp_devices`;
25+
DELETE FROM `cloud`.`role_permissions` WHERE rule = 'issueNuageVspResourceRequest';

engine/storage/volume/src/main/java/org/apache/cloudstack/storage/volume/VolumeServiceImpl.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,9 @@ public boolean grantAccess(DataObject dataObject, Host host, DataStore dataStore
217217
@Override
218218
public void revokeAccess(DataObject dataObject, Host host, DataStore dataStore) {
219219
DataStoreDriver dataStoreDriver = dataStore != null ? dataStore.getDriver() : null;
220+
if (dataStoreDriver == null) {
221+
return;
222+
}
220223

221224
if (dataStoreDriver instanceof PrimaryDataStoreDriver) {
222225
((PrimaryDataStoreDriver)dataStoreDriver).revokeAccess(dataObject, host, dataStore);

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

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
201201

202202
private String _modifyVlanPath;
203203
private String _versionstringpath;
204-
private String _patchViaSocketPath;
204+
private String _patchScriptPath;
205205
private String _createvmPath;
206206
private String _manageSnapshotPath;
207207
private String _resizeVolumePath;
@@ -694,9 +694,9 @@ public boolean configure(final String name, final Map<String, Object> params) th
694694
throw new ConfigurationException("Unable to find versions.sh");
695695
}
696696

697-
_patchViaSocketPath = Script.findScript(kvmScriptsDir + "/patch/", "patchviasocket.py");
698-
if (_patchViaSocketPath == null) {
699-
throw new ConfigurationException("Unable to find patchviasocket.py");
697+
_patchScriptPath = Script.findScript(kvmScriptsDir, "patch.sh");
698+
if (_patchScriptPath == null) {
699+
throw new ConfigurationException("Unable to find patch.sh");
700700
}
701701

702702
_heartBeatPath = Script.findScript(kvmScriptsDir, "kvmheartbeat.sh");
@@ -1391,13 +1391,13 @@ private boolean checkOvsNetwork(final String networkName) {
13911391
}
13921392

13931393
public boolean passCmdLine(final String vmName, final String cmdLine) throws InternalErrorException {
1394-
final Script command = new Script(_patchViaSocketPath, 5 * 1000, s_logger);
1394+
final Script command = new Script(_patchScriptPath, 30 * 1000, s_logger);
13951395
String result;
13961396
command.add("-n", vmName);
1397-
command.add("-p", cmdLine.replaceAll(" ", "%"));
1397+
command.add("-c", cmdLine);
13981398
result = command.execute();
13991399
if (result != null) {
1400-
s_logger.error("passcmd failed:" + result);
1400+
s_logger.error("Passing cmdline failed:" + result);
14011401
return false;
14021402
}
14031403
return true;
@@ -2186,12 +2186,6 @@ So if getMinSpeed() returns null we fall back to getSpeed().
21862186
final SerialDef serial = new SerialDef("pty", null, (short)0);
21872187
devices.addDevice(serial);
21882188

2189-
/* Add a VirtIO channel for SystemVMs for communication and provisioning */
2190-
if (vmTO.getType() != VirtualMachine.Type.User) {
2191-
File virtIoChannel = Paths.get(_qemuSocketsPath.getPath(), vmTO.getName() + ".agent").toFile();
2192-
devices.addDevice(new ChannelDef(vmTO.getName() + ".vport", ChannelDef.ChannelType.UNIX, virtIoChannel));
2193-
}
2194-
21952189
if (_rngEnable) {
21962190
final RngDef rngDevice = new RngDef(_rngPath, _rngBackendModel, _rngRateBytes, _rngRatePeriod);
21972191
devices.addDevice(rngDevice);

plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtStartCommandWrapper.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,17 +108,18 @@ public Answer execute(final StartCommand command, final LibvirtComputingResource
108108

109109
// pass cmdline info to system vms
110110
if (vmSpec.getType() != VirtualMachine.Type.User) {
111-
//wait and try passCmdLine for 5 minutes at most for CLOUDSTACK-2823
112111
String controlIp = null;
113112
for (final NicTO nic : nics) {
114113
if (nic.getType() == TrafficType.Control) {
115114
controlIp = nic.getIp();
116115
break;
117116
}
118117
}
119-
for (int count = 0; count < 30; count++) {
118+
// try to patch and SSH into the systemvm for up to 5 minutes
119+
for (int count = 0; count < 10; count++) {
120+
// wait and try passCmdLine for 30 seconds at most for CLOUDSTACK-2823
120121
libvirtComputingResource.passCmdLine(vmName, vmSpec.getBootArgs());
121-
//check router is up?
122+
// check router is up?
122123
final VirtualRoutingResource virtRouterResource = libvirtComputingResource.getVirtRouterResource();
123124
final boolean result = virtRouterResource.connect(controlIp, 1, 5000);
124125
if (result) {

plugins/hypervisors/kvm/src/test/java/com/cloud/hypervisor/kvm/resource/LibvirtDomainXMLParserTest.java

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@
2222
import java.io.File;
2323
import java.util.List;
2424

25-
import junit.framework.TestCase;
26-
2725
import com.cloud.hypervisor.kvm.resource.LibvirtVMDef.ChannelDef;
2826
import com.cloud.hypervisor.kvm.resource.LibvirtVMDef.DiskDef;
2927
import com.cloud.hypervisor.kvm.resource.LibvirtVMDef.InterfaceDef;
3028
import com.cloud.hypervisor.kvm.resource.LibvirtVMDef.RngDef;
3129
import com.cloud.hypervisor.kvm.resource.LibvirtVMDef.WatchDogDef;
3230

31+
import junit.framework.TestCase;
32+
3333
public class LibvirtDomainXMLParserTest extends TestCase {
3434

3535
public void testDomainXMLParser() {
@@ -45,9 +45,6 @@ public void testDomainXMLParser() {
4545
InterfaceDef.GuestNetType ifType = InterfaceDef.GuestNetType.BRIDGE;
4646

4747
ChannelDef.ChannelType channelType = ChannelDef.ChannelType.UNIX;
48-
ChannelDef.ChannelState channelState = ChannelDef.ChannelState.DISCONNECTED;
49-
String ssvmAgentPath = "/var/lib/libvirt/qemu/s-2970-VM.agent";
50-
String ssvmAgentName = "s-2970-VM.vport";
5148
String guestAgentPath = "/var/lib/libvirt/qemu/guest-agent.org.qemu.guest_agent.0";
5249
String guestAgentName = "org.qemu.guest_agent.0";
5350

@@ -155,12 +152,6 @@ public void testDomainXMLParser() {
155152
"<target type='serial' port='0'/>" +
156153
"<alias name='serial0'/>" +
157154
"</console>" +
158-
"<channel type='unix'>" +
159-
"<source mode='bind' path='/var/lib/libvirt/qemu/s-2970-VM.agent'/>" +
160-
"<target type='virtio' name='s-2970-VM.vport' state='disconnected'/>" +
161-
"<alias name='channel0'/>" +
162-
"<address type='virtio-serial' controller='0' bus='0' port='1'/>" +
163-
"</channel>" +
164155
"<input type='tablet' bus='usb'>" +
165156
"<alias name='input0'/>" +
166157
"</input>" +
@@ -215,14 +206,9 @@ public void testDomainXMLParser() {
215206
assertEquals(channelType, channels.get(i).getChannelType());
216207
}
217208

218-
/* SSVM provisioning port/channel */
219-
assertEquals(channelState, channels.get(0).getChannelState());
220-
assertEquals(new File(ssvmAgentPath), channels.get(0).getPath());
221-
assertEquals(ssvmAgentName, channels.get(0).getName());
222-
223209
/* Qemu Guest Agent port/channel */
224-
assertEquals(new File(guestAgentPath), channels.get(1).getPath());
225-
assertEquals(guestAgentName, channels.get(1).getName());
210+
assertEquals(new File(guestAgentPath), channels.get(0).getPath());
211+
assertEquals(guestAgentName, channels.get(0).getName());
226212

227213
List<InterfaceDef> ifs = parser.getInterfaces();
228214
for (int i = 0; i < ifs.size(); i++) {

plugins/hypervisors/kvm/src/test/java/com/cloud/hypervisor/kvm/resource/LibvirtVMDefTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ public void testRngDef() {
261261
public void testChannelDef() {
262262
ChannelDef.ChannelType type = ChannelDef.ChannelType.UNIX;
263263
ChannelDef.ChannelState state = ChannelDef.ChannelState.CONNECTED;
264-
String name = "v-136-VM.vport";
264+
String name = "v-136-VM.org.qemu.guest_agent.0";
265265
File path = new File("/var/lib/libvirt/qemu/" + name);
266266

267267
ChannelDef channelDef = new ChannelDef(name, type, state, path);

scripts/vm/hypervisor/kvm/patch.sh

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
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+
set -e
20+
21+
# Get the VM name and cmdline
22+
while getopts "n:c:h" opt; do
23+
case ${opt} in
24+
n )
25+
name=$OPTARG
26+
;;
27+
c )
28+
cmdline=$(echo $OPTARG | base64 -w 0)
29+
;;
30+
h )
31+
echo "Usage: $0 -n [VM name] -c [command line]"
32+
exit 0
33+
;;
34+
esac
35+
done
36+
37+
SSHKEY_FILE="/root/.ssh/id_rsa.pub.cloud"
38+
if [ ! -e $SSHKEY_FILE ]; then
39+
echo "SSH public key file $SSHKEY_FILE not found!"
40+
exit 1
41+
fi
42+
43+
if ! which virsh > /dev/null; then
44+
echo "Libvirt CLI 'virsh' not found"
45+
exit 1
46+
fi
47+
48+
# Read the SSH public key
49+
sshkey=$(cat $SSHKEY_FILE | base64 -w 0)
50+
51+
# Method to send and write payload inside the VM
52+
send_file() {
53+
local name=${1}
54+
local path=${2}
55+
local content=${@:3}
56+
local fd=$(virsh qemu-agent-command $name "{\"execute\":\"guest-file-open\", \"arguments\":{\"path\":\"$path\",\"mode\":\"w+\"}}" | sed 's/[^:]*:\([^}]*\).*/\1/')
57+
virsh qemu-agent-command $name "{\"execute\":\"guest-file-write\", \"arguments\":{\"handle\":$fd,\"buf-b64\":\"$content\"}}" > /dev/null
58+
virsh qemu-agent-command $name "{\"execute\":\"guest-file-close\", \"arguments\":{\"handle\":$fd}}" > /dev/null
59+
}
60+
61+
# Wait for the guest agent to come online
62+
while ! virsh qemu-agent-command $name '{"execute":"guest-ping"}' >/dev/null 2>&1
63+
do
64+
sleep 0.1
65+
done
66+
67+
# Test guest agent sanity
68+
while [ "$(virsh qemu-agent-command $name '{"execute":"guest-sync","arguments":{"id":1234567890}}' 2>/dev/null)" != '{"return":1234567890}' ]
69+
do
70+
sleep 0.1
71+
done
72+
73+
# Write ssh public key
74+
send_file $name "/root/.ssh/authorized_keys" $sshkey
75+
76+
# Fix ssh public key permission
77+
virsh qemu-agent-command $name '{"execute":"guest-exec","arguments":{"path":"chmod","arg":["go-rwx","/root/.ssh/authorized_keys"]}}' > /dev/null
78+
79+
# Write cmdline payload
80+
send_file $name "/var/cache/cloud/cmdline" $cmdline

0 commit comments

Comments
 (0)