Copilot commented on code in PR #12758:
URL: https://github.com/apache/cloudstack/pull/12758#discussion_r3126163450


##########
ui/src/views/storage/CreateVMFromBackup.vue:
##########
@@ -203,7 +213,7 @@ export default {
         args.name = this.form.name
         args.displayname = this.form.name
       }
-
+      args.quickRestore = this.form.quickRestore

Review Comment:
   The API parameter name is `quickrestore` (see ApiConstants.QUICK_RESTORE), 
but this view submits `args.quickRestore`. This will result in the backend 
ignoring the flag. Use the API's expected param key when building the request 
args (consistent with other views like RestoreAttachBackupVolume.vue which uses 
`params.quickrestore`).



##########
server/src/main/java/org/apache/cloudstack/storage/heuristics/HeuristicRuleHelper.java:
##########
@@ -154,6 +164,10 @@ protected void injectPresetVariables(JsInterpreter 
jsInterpreter, PresetVariable
             jsInterpreter.injectVariable("volume", 
presetVariables.getVolume());
         }
 
+        if (presetVariables.getBackup() != null) {
+            jsInterpreter.injectVariable("backup", 
presetVariables.getBackup().toString());
+        }

Review Comment:
   `backup` is injected into the JS interpreter as a string 
(`presetVariables.getBackup().toString()`), unlike the other preset variables 
which are injected as objects. This will prevent heuristic scripts from 
accessing backup fields (e.g. `backup.virtualSize`). Inject the `Backup` object 
itself instead of its string representation (and keep it consistent with 
template/snapshot/volume injection).



##########
utils/src/main/java/com/cloud/utils/exception/BackupException.java:
##########
@@ -0,0 +1,42 @@
+//
+// 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.utils.exception;
+
+public class BackupException extends RuntimeException {
+
+    boolean isVmConsistent;
+

Review Comment:
   `isVmConsistent` should be encapsulated (and ideally immutable) since it 
represents exception state. Consider making it `private final` to prevent 
accidental modification and to match typical exception-field conventions.



##########
tools/marvin/marvin/lib/base.py:
##########
@@ -6289,6 +6310,14 @@ def createVMFromBackup(cls, apiclient, services, mode, 
backupid, accountname, do
         VirtualMachine.program_ssh_access(apiclient, services, mode, 
cmd.networkids, virtual_machine)
         return virtual_machine
 
+    @classmethod
+    def downloadValidationScreenshot(self, apiclient, backupid):
+        """Delete VM backup"""
+
+        cmd = downloadValidationScreenshot.downloadValidationScreenshotCmd()
+        cmd.backupid = backupid
+        return (apiclient.downloadValidationScreenshot(cmd))

Review Comment:
   This new method's docstring is incorrect (it says "Delete VM backup" but the 
method is `downloadValidationScreenshot`). Please update the docstring to match 
the behavior/API for clarity in Marvin tests and callers.



##########
engine/orchestration/src/main/java/com/cloud/vm/VirtualMachineManagerImpl.java:
##########
@@ -1698,9 +1698,10 @@ public void orchestrateStart(final String vmUuid, final 
Map<VirtualMachineProfil
                 }
             }
         } finally {
+            long hostId = vm.getHostId();
             if (startedVm == null) {
                 if (VirtualMachine.Type.User.equals(vm.type) && 
ResourceCountRunningVMsonly.value()) {
-                    
_resourceLimitMgr.decrementVmResourceCount(owner.getAccountId(), 
vm.isDisplay(), offering, template);
+                    
_resourceLimitMgr.decrementVmResourceCount(owner.getAccountId(), 
vm.isDisplay(), offering, template, null);

Review Comment:
   `vm.getHostId()` is a nullable `Long` (evidenced by later calls to 
`vm.setHostId(null)` in this same block). Assigning it to a primitive `long` 
can throw a NullPointerException via unboxing in cases where `hostId` is null. 
Keep it as `Long`, or guard against null before unboxing (e.g., only set 
`lastHostId` when a hostId is present).



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to