abh1sar commented on code in PR #11619:
URL: https://github.com/apache/cloudstack/pull/11619#discussion_r2521605556


##########
plugins/hypervisors/external/src/test/java/org/apache/cloudstack/hypervisor/external/provisioner/ExternalPathPayloadProvisionerTest.java:
##########
@@ -761,6 +762,36 @@ public void getVirtualMachineTOReturnsNullWhenVmIsNull() {
         assertNull(result);
     }
 
+    @Test
+    public void getVmPowerStatesReturnsValidStatesWhenResponseIsSuccessful() {
+        Host host = mock(Host.class);
+        when(host.getId()).thenReturn(1L);
+        when(host.getName()).thenReturn("test-host");
+
+        Map<String, Map<String, String>> accessDetails = new HashMap<>();
+        doReturn(new Pair<>(true, 
"{\"status\":\"success\",\"power_state\":{\"vm1\":\"PowerOn\",\"vm2\":\"PowerOff\"}}"))
+            
.when(provisioner).getInstanceStatusesOnExternalSystem(anyString(), 
anyString(), anyString(), anyMap(), anyInt());
+
+        Map<String, HostVmStateReportEntry> result = 
provisioner.getVmPowerStates(host, accessDetails, "test-extension", 
"test-path");
+
+        assertNotNull(result);
+        assertEquals(2, result.size());
+        assertEquals(VirtualMachine.PowerState.PowerOn, 
result.get("vm1").getState());
+        assertEquals(VirtualMachine.PowerState.PowerOff, 
result.get("vm2").getState());
+    }
+
+    @Test
+    public void getVmPowerStatesReturnsNullWhenResponseIsFailure() {
+        Host host = mock(Host.class);
+        when(host.getName()).thenReturn("test-host");
+
+        Map<String, Map<String, String>> accessDetails = new HashMap<>();
+        doReturn(new Pair<>(false, "Error")).when(provisioner)
+            .getInstanceStatusesOnExternalSystem(anyString(), anyString(), 
anyString(), anyMap(), anyInt());
+
+        Map<String, HostVmStateReportEntry> result = 
provisioner.getVmPowerStates(host, accessDetails, "test-extension", 
"test-path");

Review Comment:
   Any assertion here?



##########
extensions/Proxmox/proxmox.sh:
##########
@@ -325,50 +329,81 @@ get_node_host() {
     echo "$host"
 }
 
- get_console() {
-     check_required_fields node vmid
-
-     local api_resp port ticket
-     if ! api_resp="$(call_proxmox_api POST 
"/nodes/${node}/qemu/${vmid}/vncproxy")"; then
-         echo "$api_resp" | jq -c '{status:"error", error:(.errors.curl // 
(.errors|tostring))}'
-         exit 1
-     fi
-
-     port="$(echo "$api_resp"   | jq -re '.data.port // empty' 2>/dev/null || 
true)"
-     ticket="$(echo "$api_resp" | jq -re '.data.ticket // empty' 2>/dev/null 
|| true)"
-
-     if [[ -z "$port" || -z "$ticket" ]]; then
-         jq -n --arg raw "$api_resp" \
-             '{status:"error", error:"Proxmox response missing port/ticket", 
upstream:$raw}'
-         exit 1
-     fi
-
-     # Derive host from node’s network info
-     local host
-     host="$(get_node_host)"
-     if [[ -z "$host" ]]; then
-         jq -n --arg msg "Could not determine host IP for node $node" \
-             '{status:"error", error:$msg}'
-         exit 1
-     fi
-
-     jq -n \
-         --arg host "$host" \
-         --arg port "$port" \
-         --arg password "$ticket" \
-         --argjson passwordonetimeuseonly true \
-         '{
-             status: "success",
-             message: "Console retrieved",
-             console: {
-                 host: $host,
-                 port: $port,
-                 password: $password,
-                 passwordonetimeuseonly: $passwordonetimeuseonly,
-                 protocol: "vnc"
-             }
-         }'
- }
+get_console() {
+   check_required_fields node vmid

Review Comment:
   indentation is changed from 4 to 3 spaces.



-- 
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