Skip to content

Commit 33659fd

Browse files
authored
server,test: fix resourceid for VOLUME.DETROY in restore VM (apache#9032)
Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com>
1 parent f0df8d7 commit 33659fd

2 files changed

Lines changed: 14 additions & 3 deletions

File tree

server/src/main/java/com/cloud/vm/UserVmManagerImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7909,7 +7909,7 @@ public Pair<UserVmVO, Volume> doInTransaction(final TransactionStatus status) th
79097909

79107910
// Detach, destroy and create the usage event for the old root volume.
79117911
_volsDao.detachVolume(root.getId());
7912-
_volumeService.destroyVolume(root.getId(), caller, Volume.State.Allocated.equals(root.getState()) || expunge, false);
7912+
destroyVolumeInContext(vm, Volume.State.Allocated.equals(root.getState()) || expunge, root);
79137913

79147914
// For VMware hypervisor since the old root volume is replaced by the new root volume, force expunge old root volume if it has been created in storage
79157915
if (vm.getHypervisorType() == HypervisorType.VMware) {

test/integration/smoke/test_events_resource.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,20 +116,23 @@ def test_01_events_resource(self):
116116
self.services["domain"],
117117
parentdomainid=self.domain.id
118118
)
119+
self.cleanup.append(domain1)
119120
self.services["domainid"] = domain1.id
120121

121122
account = Account.create(
122123
self.apiclient,
123124
self.services["account"],
124125
domainid=domain1.id
125126
)
127+
self.cleanup.append(account)
126128

127129
account_network = Network.create(
128130
self.apiclient,
129131
self.services["network"],
130132
account.name,
131133
account.domainid
132134
)
135+
self.cleanup.append(account_network)
133136
virtual_machine = VirtualMachine.create(
134137
self.apiclient,
135138
self.services,
@@ -138,6 +141,7 @@ def test_01_events_resource(self):
138141
networkids=account_network.id,
139142
serviceofferingid=self.service_offering.id
140143
)
144+
self.cleanup.append(virtual_machine)
141145
volume = Volume.create(
142146
self.apiclient,
143147
self.services,
@@ -146,6 +150,7 @@ def test_01_events_resource(self):
146150
domainid=account.domainid,
147151
diskofferingid=self.disk_offering.id
148152
)
153+
self.cleanup.append(volume)
149154
virtual_machine.attach_volume(
150155
self.apiclient,
151156
volume
@@ -157,15 +162,20 @@ def test_01_events_resource(self):
157162
time.sleep(self.services["sleep"])
158163
virtual_machine.detach_volume(self.apiclient, volume)
159164
volume.delete(self.apiclient)
165+
self.cleanup.remove(volume)
160166
ts = str(time.time())
161167
virtual_machine.update(self.apiclient, displayname=ts)
162168
virtual_machine.delete(self.apiclient)
169+
self.cleanup.remove(virtual_machine)
163170
account_network.update(self.apiclient, name=account_network.name + ts)
164171
account_network.delete(self.apiclient)
172+
self.cleanup.remove(account_network)
165173
account.update(self.apiclient, newname=account.name + ts)
166174
account.disable(self.apiclient)
167175
account.delete(self.apiclient)
176+
self.cleanup.remove(account)
168177
domain1.delete(self.apiclient)
178+
self.cleanup.remove(domain1)
169179

170180
cmd = listEvents.listEventsCmd()
171181
cmd.startdate = start_time
@@ -185,8 +195,9 @@ def test_01_events_resource(self):
185195
for event in events:
186196
if event.type.startswith("VM.") or (event.type.startswith("NETWORK.") and not event.type.startswith("NETWORK.ELEMENT")) or event.type.startswith("VOLUME.") or event.type.startswith("ACCOUNT.") or event.type.startswith("DOMAIN.") or event.type.startswith("TEMPLATE."):
187197
if event.resourceid is None or event.resourcetype is None:
188-
self.debug("Failed event:: %s" % json.dumps(event, indent=2))
189-
self.fail("resourceid or resourcetype for the event not found!")
198+
event_json = json.dumps(event.__dict__, indent=2)
199+
self.debug("Failed event:: %s" % event_json)
200+
self.fail("resourceid or resourcetype not found for the event: %s" % event_json)
190201
else:
191202
self.debug("Event %s at %s:: Resource Type: %s, Resource ID: %s" % (event.type, event.created, event.resourcetype, event.resourceid))
192203

0 commit comments

Comments
 (0)