Skip to content

Commit 1192022

Browse files
authored
Merge pull request xapi-project#3019 from sharady/CA-249668
CA-249668: For SXM if remote network is unreachable then raise an API error instead of internal_error.
2 parents 03a6f24 + 96c21c5 commit 1192022

File tree

3 files changed

+27
-19
lines changed

3 files changed

+27
-19
lines changed

ocaml/idl/datamodel.ml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,9 @@ let _ =
505505
error Api_errors.cannot_contact_host ["host"]
506506
~doc:"Cannot forward messages because the host cannot be contacted. The host may be switched off or there may be network connectivity problems." ();
507507

508+
error Api_errors.tls_connection_failed ["address"; "port"]
509+
~doc:"Cannot contact the other host using TLS on the specified address and port" ();
510+
508511
error Api_errors.uuid_invalid [ "type"; "uuid" ]
509512
~doc:"The uuid you supplied was invalid." ();
510513
error Api_errors.object_nolonger_exists []

ocaml/xapi-consts/api_errors.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ let session_invalid = "SESSION_INVALID"
4242
let change_password_rejected = "CHANGE_PASSWORD_REJECTED"
4343
let user_is_not_local_superuser = "USER_IS_NOT_LOCAL_SUPERUSER"
4444
let cannot_contact_host = "CANNOT_CONTACT_HOST"
45+
let tls_connection_failed = "TLS_CONNECTION_FAILED"
4546
let not_supported_during_upgrade = "NOT_SUPPORTED_DURING_UPGRADE"
4647

4748
let handle_invalid = "HANDLE_INVALID"

ocaml/xapi/importexport.ml

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -257,27 +257,31 @@ let remote_metadata_export_import ~__context ~rpc ~session_id ~remote_address ~r
257257
] ~keep_alive:false
258258
Http.Put remote_import_request in
259259
debug "Piping HTTP %s to %s" (Http.Request.to_string get) (Http.Request.to_string put);
260-
with_transport (Unix Xapi_globs.unix_domain_socket)
261-
(with_http get
262-
(fun (r, ifd) ->
263-
debug "Content-length: %s" (Stdext.Opt.default "None" (Stdext.Opt.map Int64.to_string r.Http.Response.content_length));
264-
let put = { put with Http.Request.content_length = r.Http.Response.content_length } in
265-
debug "Connecting to %s:%d" remote_address !Xapi_globs.https_port;
266-
(* Spawn a cached stunnel instance. Otherwise, once metadata tranmission completes, the connection
267-
between local xapi and stunnel will be closed immediately, and the new spawned stunnel instance
268-
will be revoked, this might cause the remote stunnel gets partial metadata xml file, and the
269-
ripple effect is that remote xapi fails to parse metadata xml file. Using a cached stunnel can
270-
not always avoid the problem since any cached stunnel entry might be evicted. However, it is
271-
unlikely to happen in practice because the cache size is large enough.*)
272-
with_transport (SSL (SSL.make ~use_stunnel_cache:true (), remote_address, !Xapi_globs.https_port))
273-
(with_http put
274-
(fun (_, ofd) ->
260+
begin try
261+
with_transport (Unix Xapi_globs.unix_domain_socket)
262+
(with_http get
263+
(fun (r, ifd) ->
264+
debug "Content-length: %s" (Stdext.Opt.default "None" (Stdext.Opt.map Int64.to_string r.Http.Response.content_length));
265+
let put = { put with Http.Request.content_length = r.Http.Response.content_length } in
266+
debug "Connecting to %s:%d" remote_address !Xapi_globs.https_port;
267+
(* Spawn a cached stunnel instance. Otherwise, once metadata tranmission completes, the connection
268+
between local xapi and stunnel will be closed immediately, and the new spawned stunnel instance
269+
will be revoked, this might cause the remote stunnel gets partial metadata xml file, and the
270+
ripple effect is that remote xapi fails to parse metadata xml file. Using a cached stunnel can
271+
not always avoid the problem since any cached stunnel entry might be evicted. However, it is
272+
unlikely to happen in practice because the cache size is large enough.*)
273+
with_transport (SSL (SSL.make ~use_stunnel_cache:true (), remote_address, !Xapi_globs.https_port))
274+
(with_http put
275+
(fun (_, ofd) ->
275276
let (n: int64) = Stdext.Unixext.copy_file ?limit:r.Http.Response.content_length ifd ofd in
276277
debug "Written %Ld bytes" n
277-
)
278-
)
279-
)
280-
);
278+
)
279+
)
280+
)
281+
)
282+
with Xmlrpc_client.Stunnel_connection_failed ->
283+
raise (Api_errors.Server_error(Api_errors.tls_connection_failed, [remote_address; (string_of_int !Xapi_globs.https_port)]))
284+
end;
281285
(* Wait for remote task to succeed or fail *)
282286
Cli_util.wait_for_task_completion rpc session_id remote_task;
283287
match Client.Task.get_status rpc session_id remote_task with

0 commit comments

Comments
 (0)