GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — vmware-base: fix template copy from secondary to primary (#13977) · apache/cloudstack@18c4bdf

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • test/integration/smoke
    • test_routers_network_ops.py
  • vmware-base/src/main/java/com/cloud/hypervisor/vmware/util
    • VmwareContext.java
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎test/integration/smoke/test_routers_network_ops.py‎

Copy file name to clipboardExpand all lines: test/integration/smoke/test_routers_network_ops.py
+8-8Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ def test_01_RVR_Network_FW_PF_SSH_default_routes_egress_true(self):
287287
)
288288

289289
expected = 1
290-
ssh_command = "curl -v -m 1 -o index.html -sL www.google.com"
290+
ssh_command = "wget -t 1 -T 5 www.google.com"
291291
check_string = "200 OK"
292292
result = check_router_command(virtual_machine, nat_rule.ipaddress, ssh_command, check_string, self)
293293

@@ -307,7 +307,7 @@ def test_01_RVR_Network_FW_PF_SSH_default_routes_egress_true(self):
307307
)
308308

309309
expected = 0
310-
ssh_command = "curl -v -m 1 -o index.html -sL www.google.com"
310+
ssh_command = "wget -t 1 -T 1 www.google.com"
311311
check_string = "200 OK"
312312
result = check_router_command(virtual_machine, nat_rule.ipaddress, ssh_command, check_string, self)
313313

@@ -451,7 +451,7 @@ def test_02_RVR_Network_FW_PF_SSH_default_routes_egress_false(self):
451451
)
452452

453453
expected = 0
454-
ssh_command = "curl -v -m 1 -o index.html -sL www.google.com"
454+
ssh_command = "wget -t 1 -T 1 www.google.com"
455455
check_string = "200 OK"
456456
result = check_router_command(virtual_machine, nat_rule.ipaddress, ssh_command, check_string, self)
457457

@@ -480,7 +480,7 @@ def test_02_RVR_Network_FW_PF_SSH_default_routes_egress_false(self):
480480
)
481481

482482
expected = 1
483-
ssh_command = "curl -v -m 1 -o index.html -sL www.google.com"
483+
ssh_command = "wget -t 1 -T 5 www.google.com"
484484
check_string = "200 OK"
485485
result = check_router_command(virtual_machine, nat_rule.ipaddress, ssh_command, check_string, self)
486486

@@ -840,7 +840,7 @@ def test_01_isolate_network_FW_PF_default_routes_egress_true(self):
840840
)
841841

842842
expected = 1
843-
ssh_command = "curl -v -m 1 -o index.html -sL www.google.com"
843+
ssh_command = "wget -t 1 -T 5 www.google.com"
844844
check_string = "200 OK"
845845
result = check_router_command(virtual_machine, nat_rule.ipaddress, ssh_command, check_string, self)
846846

@@ -860,7 +860,7 @@ def test_01_isolate_network_FW_PF_default_routes_egress_true(self):
860860
)
861861

862862
expected = 0
863-
ssh_command = "curl -v -m 1 -o index.html -sL www.google.com"
863+
ssh_command = "wget -t 1 -T 1 www.google.com"
864864
check_string = "200 OK"
865865
result = check_router_command(virtual_machine, nat_rule.ipaddress, ssh_command, check_string, self)
866866

@@ -995,7 +995,7 @@ def test_02_isolate_network_FW_PF_default_routes_egress_false(self):
995995
)
996996

997997
expected = 0
998-
ssh_command = "curl -v -m 1 -o index.html -sL www.google.com"
998+
ssh_command = "wget -t 1 -T 1 www.google.com"
999999
check_string = "200 OK"
10001000
result = check_router_command(virtual_machine, nat_rule.ipaddress, ssh_command, check_string, self)
10011001

@@ -1015,7 +1015,7 @@ def test_02_isolate_network_FW_PF_default_routes_egress_false(self):
10151015
)
10161016

10171017
expected = 1
1018-
ssh_command = "curl -v -m 1 -o index.html -sL www.google.com"
1018+
ssh_command = "wget -t 1 -T 5 www.google.com"
10191019
check_string = "200 OK"
10201020
result = check_router_command(virtual_machine, nat_rule.ipaddress, ssh_command, check_string, self)
10211021

Collapse file

‎vmware-base/src/main/java/com/cloud/hypervisor/vmware/util/VmwareContext.java‎

Copy file name to clipboardExpand all lines: vmware-base/src/main/java/com/cloud/hypervisor/vmware/util/VmwareContext.java
+80-29Lines changed: 80 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import java.io.File;
2424
import java.io.FileInputStream;
2525
import java.io.FileOutputStream;
26+
import java.io.IOException;
2627
import java.io.InputStream;
2728
import java.io.InputStreamReader;
2829
import java.io.OutputStream;
@@ -384,29 +385,29 @@ public void uploadFile(String httpMethod, String urlString, String localFileName
384385
conn.setRequestProperty("content-type", contentType);
385386
conn.setRequestProperty("content-length", Long.toString(new File(localFileName).length()));
386387
connectWithRetry(conn);
387-
OutputStream out = null;
388-
InputStream in = null;
389-
BufferedReader br = null;
390388

391389
try {
392-
out = conn.getOutputStream();
393-
in = new FileInputStream(localFileName);
390+
writeFileToConnection(conn, httpMethod, urlString, localFileName);
391+
checkUploadResponse(conn, httpMethod, urlString, localFileName);
392+
} finally {
393+
conn.disconnect();
394+
}
395+
}
396+
397+
private void writeFileToConnection(HttpURLConnection conn, String httpMethod, String urlString, String localFileName) throws IOException {
398+
long bytesWritten = 0;
399+
try (OutputStream out = conn.getOutputStream();
400+
InputStream in = new FileInputStream(localFileName)) {
394401
byte[] buf = new byte[ChunkSize];
395-
int len = 0;
402+
int len;
396403
while ((len = in.read(buf)) > 0) {
397404
out.write(buf, 0, len);
405+
bytesWritten += len;
398406
}
399407
out.flush();
400-
} finally {
401-
if (in != null)
402-
in.close();
403-
404-
if (out != null)
405-
out.close();
406-
407-
if (br != null)
408-
br.close();
409-
conn.disconnect();
408+
} catch (IOException e) {
409+
throw new IOException(String.format("Upload of %s to %s %s failed after writing %d of %d bytes: %s",
410+
localFileName, httpMethod, urlString, bytesWritten, new File(localFileName).length(), e.getMessage()), e);
410411
}
411412
}
412413

@@ -442,32 +443,82 @@ public void uploadVmdkFile(String httpMethod, String urlString, String localFile
442443
conn.setRequestProperty("content-length", Long.toString(new File(localFileName).length()));
443444
connectWithRetry(conn);
444445

445-
BufferedOutputStream bos = null;
446-
BufferedInputStream is = null;
447446
try {
448-
bos = new BufferedOutputStream(conn.getOutputStream());
449-
is = new BufferedInputStream(new FileInputStream(localFileName));
450-
int bufferSize = ChunkSize;
451-
byte[] buffer = new byte[bufferSize];
447+
writeVmdkFileToConnection(conn, httpMethod, urlString, localFileName, totalBytesUpdated, progressUpdater);
448+
checkUploadResponse(conn, httpMethod, urlString, localFileName);
449+
} finally {
450+
conn.disconnect();
451+
}
452+
}
453+
454+
private void writeVmdkFileToConnection(HttpURLConnection conn, String httpMethod, String urlString, String localFileName, long totalBytesUpdated,
455+
ActionDelegate<Long> progressUpdater) throws IOException {
456+
long bytesWrittenThisCall = 0;
457+
try (BufferedOutputStream bos = new BufferedOutputStream(conn.getOutputStream());
458+
BufferedInputStream is = new BufferedInputStream(new FileInputStream(localFileName))) {
459+
byte[] buffer = new byte[ChunkSize];
452460
while (true) {
453-
int bytesRead = is.read(buffer, 0, bufferSize);
461+
int bytesRead = is.read(buffer, 0, ChunkSize);
454462
if (bytesRead == -1) {
455463
break;
456464
}
457465
bos.write(buffer, 0, bytesRead);
458466
totalBytesUpdated += bytesRead;
467+
bytesWrittenThisCall += bytesRead;
459468
bos.flush();
460469
if (progressUpdater != null)
461470
progressUpdater.action(new Long(totalBytesUpdated));
462471
}
463472
bos.flush();
464-
} finally {
465-
if (is != null)
466-
is.close();
467-
if (bos != null)
468-
bos.close();
473+
} catch (IOException e) {
474+
throw new IOException(String.format("Upload of %s to %s %s failed after writing %d of %d bytes for this file " +
475+
"(%d bytes total written so far for this import): %s",
476+
localFileName, httpMethod, urlString, bytesWrittenThisCall, new File(localFileName).length(), totalBytesUpdated, e.getMessage()), e);
477+
}
478+
}
469479

470-
conn.disconnect();
480+
/**
481+
* HttpURLConnection does not surface a failed request just because the client finished writing the
482+
* request body without an IOException: with chunked transfer encoding many HTTP servers, including
483+
* ESXi's NFC endpoint, read and discard the whole body before responding with an error status (e.g. a
484+
* VMFS file lock, an out-of-space datastore, or an authentication/session failure). Silently ignoring
485+
* the response code is exactly how a rejected/short write can look like a "successful" upload to
486+
* CloudStack. Surface the actual status code, reason phrase and (if any) response body so failures like
487+
* "file locked" are visible in the CloudStack logs instead of only in vCenter/ESXi's own logs, if at all.
488+
*/
489+
private void checkUploadResponse(HttpURLConnection conn, String httpMethod, String urlString, String localFileName) throws IOException {
490+
int responseCode;
491+
try {
492+
responseCode = conn.getResponseCode();
493+
} catch (IOException e) {
494+
throw new IOException(String.format("Unable to read the response for %s %s (uploading %s): %s",
495+
httpMethod, urlString, localFileName, e.getMessage()), e);
496+
}
497+
498+
if (responseCode < 200 || responseCode >= 300) {
499+
String responseBody = readResponseBodyQuietly(conn);
500+
boolean hasBody = responseBody != null && !responseBody.trim().isEmpty();
501+
throw new IOException(String.format(
502+
"%s %s rejected the upload of %s with HTTP %d %s%s",
503+
httpMethod, urlString, localFileName, responseCode, conn.getResponseMessage(),
504+
hasBody ? (": " + responseBody) : ""));
505+
}
506+
}
507+
508+
private String readResponseBodyQuietly(HttpURLConnection conn) {
509+
InputStream errorStream = conn.getErrorStream();
510+
if (errorStream == null) {
511+
return null;
512+
}
513+
try (BufferedReader reader = new BufferedReader(new InputStreamReader(errorStream, getCharSetFromConnection(conn)))) {
514+
StringBuilder sb = new StringBuilder();
515+
String line;
516+
while ((line = reader.readLine()) != null && sb.length() < 1024) {
517+
sb.append(line);
518+
}
519+
return sb.toString();
520+
} catch (IOException e) {
521+
return null;
471522
}
472523
}
473524

0 commit comments

Comments
0 (0)
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.