Skip to content

Commit abd993a

Browse files
authored
CA-403867: Block pool join if IP not configured on joining cluster network (#6290)
2 parents 541124b + fa929c4 commit abd993a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+365
-866
lines changed

ocaml/idl/datamodel_errors.ml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -897,6 +897,14 @@ let _ =
897897
the pool coordinator. Make sure the sm are of the same versions and try \
898898
again."
899899
() ;
900+
error Api_errors.pool_joining_pool_cannot_enable_clustering_on_vlan_network
901+
["vlan"] ~doc:"The remote pool cannot enable clustering on vlan network" () ;
902+
error Api_errors.pool_joining_host_must_have_only_one_IP_on_clustering_network
903+
[]
904+
~doc:
905+
"The host joining the pool must have one and only one IP on the \
906+
clustering network"
907+
() ;
900908

901909
(* External directory service *)
902910
error Api_errors.subject_cannot_be_resolved []

ocaml/tests/test_clustering.ml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -165,15 +165,15 @@ let test_find_cluster_host_finds_multiple_cluster_hosts () =
165165
let host = Db.Host.get_all ~__context |> List.hd in
166166
let _ = T.make_cluster_host ~__context ~host () in
167167
let _ = T.make_cluster_host ~__context ~host () in
168+
let err =
169+
Printf.sprintf "Multiple cluster_hosts found for host %s %s"
170+
(Db.Host.get_uuid ~__context ~self:host)
171+
(Ref.string_of host)
172+
in
168173
Alcotest.check_raises
169174
"test_find_cluster_host_finds_multiple_cluster_hosts should throw an \
170175
internal error"
171-
Api_errors.(
172-
Server_error
173-
( internal_error
174-
, ["Multiple cluster_hosts found for host"; Ref.string_of host]
175-
)
176-
)
176+
Api_errors.(Server_error (internal_error, [err]))
177177
(fun () -> ignore (Xapi_clustering.find_cluster_host ~__context ~host))
178178

179179
let test_find_cluster_host =

ocaml/xapi-consts/api_errors.ml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -757,6 +757,12 @@ let pool_joining_host_ca_certificates_conflict =
757757
let pool_joining_sm_features_incompatible =
758758
add_error "POOL_JOINING_SM_FEATURES_INCOMPATIBLE"
759759

760+
let pool_joining_pool_cannot_enable_clustering_on_vlan_network =
761+
add_error "POOL_JOINING_POOL_CANNOT_ENABLE_CLUSTERING_ON_VLAN_NETWORK"
762+
763+
let pool_joining_host_must_have_only_one_IP_on_clustering_network =
764+
add_error "POOL_JOINING_HOST_MUST_HAVE_ONLY_ONE_IP_ON_CLUSTERING_NETWORK"
765+
760766
(*workload balancing*)
761767
let wlb_not_initialized = add_error "WLB_NOT_INITIALIZED"
762768

ocaml/xapi/cert_distrib.ml

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ let raise_internal ?e ?(details = "") msg : 'a =
101101
e
102102
in
103103
[msg; details; e] |> String.concat ". " |> D.error "%s" ;
104-
raise Api_errors.(Server_error (internal_error, [msg]))
104+
Helpers.internal_error "%s" msg
105105

106106
module type CertificateProvider = sig
107107
val store_path : string
@@ -404,13 +404,8 @@ let exchange_certificates_in_pool ~__context =
404404
let throw_op =
405405
( "FIST"
406406
, fun () ->
407-
raise
408-
Api_errors.(
409-
Server_error
410-
( internal_error
411-
, ["/tmp/fist_exchange_certificates_in_pool FIST!"]
412-
)
413-
)
407+
Helpers.internal_error
408+
"/tmp/fist_exchange_certificates_in_pool FIST!"
414409
)
415410
in
416411
let ops' = insert_at rand_i throw_op ops in

ocaml/xapi/certificates_sync.ml

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -119,19 +119,13 @@ let update ~__context =
119119
let* () = sync ~__context ~type':`host_internal in
120120
Ok ()
121121

122-
let internal_error fmt =
123-
fmt
124-
|> Printf.ksprintf @@ fun msg ->
125-
error "%s" msg ;
126-
raise Api_errors.(Server_error (internal_error, [msg]))
127-
128122
let remove_from_db ~__context cert =
129123
try
130124
Db.Certificate.destroy ~__context ~self:cert ;
131125
info "removed host certificate %s from db" (Ref.string_of cert)
132126
with e ->
133-
internal_error "failed to remove cert %s: %s" (Ref.string_of cert)
134-
(Printexc.to_string e)
127+
Helpers.internal_error ~log_err:true "failed to remove cert %s: %s"
128+
(Ref.string_of cert) (Printexc.to_string e)
135129

136130
let path host_uuid =
137131
let prefix = !Xapi_globs.trusted_pool_certs_dir in
@@ -161,5 +155,5 @@ let eject_certs_from_fs_for ~__context host =
161155
| false ->
162156
info "host %s has no certificate %s to remove" host_uuid file
163157
with e ->
164-
internal_error "failed to remove cert %s on pool eject: %s" file
165-
(Printexc.to_string e)
158+
Helpers.internal_error ~log_err:true
159+
"failed to remove cert %s on pool eject: %s" file (Printexc.to_string e)

ocaml/xapi/dbsync_slave.ml

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -136,12 +136,9 @@ let refresh_localhost_info ~__context info =
136136
let network_state = Scanf.sscanf script_output "Port 80 open: %B" Fun.id in
137137
Db.Host.set_https_only ~__context ~self:host ~value:network_state
138138
with _ ->
139-
let message =
140-
Printf.sprintf
141-
"unexpected output from /etc/xapi.d/plugins/firewall-port: %s"
142-
script_output
143-
in
144-
raise Api_errors.(Server_error (internal_error, [message]))
139+
Helpers.internal_error
140+
"unexpected output from /etc/xapi.d/plugins/firewall-port: %s"
141+
script_output
145142
(*************** update database tools ******************)
146143

147144
(** Record host memory properties in database *)

ocaml/xapi/helpers.ml

Lines changed: 20 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,15 @@ module StringSet = Set.Make (String)
3434

3535
let ( let* ) = Result.bind
3636

37+
let internal_error ?(log_err = false) ?(err_fun = error) fmt =
38+
Printf.ksprintf
39+
(fun str ->
40+
if log_err then
41+
err_fun "%s" str ;
42+
raise Api_errors.(Server_error (internal_error, [str]))
43+
)
44+
fmt
45+
3746
let log_exn_continue msg f x =
3847
try f x
3948
with e ->
@@ -719,8 +728,7 @@ let check_domain_type : API.domain_type -> [`hvm | `pv_in_pvh | `pv | `pvh] =
719728
| `pvh ->
720729
`pvh
721730
| `unspecified ->
722-
raise
723-
Api_errors.(Server_error (internal_error, ["unspecified domain type"]))
731+
internal_error "unspecified domain type"
724732

725733
let domain_type ~__context ~self : [`hvm | `pv_in_pvh | `pv | `pvh] =
726734
let vm = Db.VM.get_record ~__context ~self in
@@ -1498,11 +1506,8 @@ let resolve_uri_path ~root ~uri_path =
14981506
| true, true ->
14991507
x
15001508
| _ ->
1501-
let msg =
1502-
Printf.sprintf "Failed to resolve uri path '%s' under '%s': %s" uri_path
1503-
root x
1504-
in
1505-
raise Api_errors.(Server_error (internal_error, [msg]))
1509+
internal_error "Failed to resolve uri path '%s' under '%s': %s" uri_path
1510+
root x
15061511

15071512
let run_in_parallel ~funs ~capacity =
15081513
let rec run_in_parallel' acc funs capacity =
@@ -1727,42 +1732,21 @@ let rec retry_until_timeout ?(interval = 0.1) ?(timeout = 5.) doc f =
17271732
let next_interval = interval *. 1.5 in
17281733
let next_timeout = timeout -. interval in
17291734
if next_timeout < 0. then
1730-
raise
1731-
Api_errors.(
1732-
Server_error (internal_error, [Printf.sprintf "retry %s failed" doc])
1733-
) ;
1735+
internal_error "retry %s failed" doc ;
17341736
Thread.delay interval ;
17351737
retry_until_timeout ~interval:next_interval ~timeout:next_timeout doc f
17361738

17371739
let get_first_pusb ~__context usb_group =
17381740
try List.hd (Db.USB_group.get_PUSBs ~__context ~self:usb_group)
17391741
with _ ->
1740-
raise
1741-
Api_errors.(
1742-
Server_error
1743-
( internal_error
1744-
, [
1745-
Printf.sprintf
1746-
"there is no PUSB associated with the USB_group: %s"
1747-
(Ref.string_of usb_group)
1748-
]
1749-
)
1750-
)
1742+
internal_error "there is no PUSB associated with the USB_group: %s"
1743+
(Ref.string_of usb_group)
17511744

17521745
let get_first_vusb ~__context usb_group =
17531746
try List.hd (Db.USB_group.get_VUSBs ~__context ~self:usb_group)
17541747
with _ ->
1755-
raise
1756-
Api_errors.(
1757-
Server_error
1758-
( internal_error
1759-
, [
1760-
Printf.sprintf
1761-
"there is no VUSB associated with the USB_group: %s"
1762-
(Ref.string_of usb_group)
1763-
]
1764-
)
1765-
)
1748+
internal_error "there is no VUSB associated with the USB_group: %s"
1749+
(Ref.string_of usb_group)
17661750

17671751
let host_supports_hvm ~__context host =
17681752
(* We say that a host supports HVM if any of
@@ -1873,13 +1857,7 @@ end = struct
18731857
let to_result ~__context ~of_rpc ~t =
18741858
Context.with_tracing ~__context __FUNCTION__ @@ fun __context ->
18751859
wait_for_mirror ~__context ~propagate_cancel:true ~t ;
1876-
let fail msg =
1877-
raise
1878-
Api_errors.(
1879-
Server_error
1880-
(internal_error, [Printf.sprintf "%s, %s" (Ref.string_of t) msg])
1881-
)
1882-
in
1860+
let fail msg = internal_error "%s, %s" (Ref.string_of t) msg in
18831861
let res =
18841862
match Db.Task.get_status ~__context ~self:t with
18851863
| `pending ->
@@ -1965,15 +1943,8 @@ end = struct
19651943
in
19661944
let sufficiently_secret = String.length x > 36 in
19671945
if has_valid_chars && sufficiently_secret |> not then
1968-
raise
1969-
Api_errors.(
1970-
Server_error
1971-
( internal_error
1972-
, [
1973-
{|expected pool secret to match the following regex '^[0-9a-f\/\-]{37,}$'|}
1974-
]
1975-
)
1976-
) ;
1946+
internal_error
1947+
{|expected pool secret to match the following regex '^[0-9a-f\/\-]{37,}$'|} ;
19771948
SecretString.of_string x
19781949

19791950
let _make () =

ocaml/xapi/livepatch.ml

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ let of_json js =
6868
(ExnHelper.string_of_exn e)
6969
msg
7070
(Yojson.Basic.pretty_to_string js) ;
71-
raise Api_errors.(Server_error (internal_error, [msg]))
71+
Helpers.internal_error "%s" msg
7272

7373
let get_latest_livepatch lps =
7474
List.map (fun (_, _, t_v, t_r) -> (t_v, t_r)) lps
@@ -344,14 +344,11 @@ let apply ~component ~livepatch_file ~base_build_id ~base_version ~base_release
344344
| expected_id, Some real_id when expected_id = real_id ->
345345
()
346346
| _ ->
347-
let msg =
348-
Printf.sprintf
349-
"The livepatch is against build ID %s, but the build ID of the \
350-
running %s is %s"
351-
expected component_str
352-
(Option.value real ~default:"None")
353-
in
354-
raise Api_errors.(Server_error (internal_error, [msg]))
347+
Helpers.internal_error
348+
"The livepatch is against build ID %s, but the build ID of the \
349+
running %s is %s"
350+
expected component_str
351+
(Option.value real ~default:"None")
355352
in
356353
match component with
357354
| Xen ->

ocaml/xapi/message_forwarding.ml

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3858,15 +3858,8 @@ functor
38583858
in
38593859
()
38603860
with Forkhelpers.Spawn_internal_error (_, _, _) ->
3861-
raise
3862-
(Api_errors.Server_error
3863-
( Api_errors.internal_error
3864-
, [
3865-
"Generation of alerts for server certificate expiration \
3866-
failed."
3867-
]
3868-
)
3869-
)
3861+
Helpers.internal_error
3862+
"Generation of alerts for server certificate expiration failed."
38703863

38713864
let reset_server_certificate ~__context ~host =
38723865
info "Host.reset_server_certificate: host = '%s'"

ocaml/xapi/nm.ml

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -441,11 +441,7 @@ let rec create_bridges ~__context pif_rc net_rc =
441441
]
442442
)
443443
| Network_sriov_logical _ ->
444-
raise
445-
Api_errors.(
446-
Server_error
447-
(internal_error, ["Should not create bridge for SRIOV logical PIF"])
448-
)
444+
Helpers.internal_error "Should not create bridge for SRIOV logical PIF"
449445

450446
let rec destroy_bridges ~__context ~force pif_rc bridge =
451447
let open Xapi_pif_helpers in
@@ -468,11 +464,7 @@ let rec destroy_bridges ~__context ~force pif_rc bridge =
468464
| Physical _ ->
469465
[(bridge, false)]
470466
| Network_sriov_logical _ ->
471-
raise
472-
Api_errors.(
473-
Server_error
474-
(internal_error, ["Should not destroy bridge for SRIOV logical PIF"])
475-
)
467+
Helpers.internal_error "Should not destroy bridge for SRIOV logical PIF"
476468

477469
let determine_static_routes net_rc =
478470
if List.mem_assoc "static-routes" net_rc.API.network_other_config then

ocaml/xapi/repository.ml

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ let parse_updateinfo ~__context ~self ~check =
372372
hash md.RepoMetaData.checksum
373373
in
374374
error "%s: %s" repo_name msg ;
375-
raise Api_errors.(Server_error (internal_error, [msg]))
375+
Helpers.internal_error "%s" msg
376376
)
377377
) ;
378378
let updateinfo_xml_gz_path =
@@ -691,9 +691,8 @@ let apply_livepatch ~__context ~host:_ ~component ~base_build_id ~base_version
691691
let component' =
692692
try component_of_string component
693693
with _ ->
694-
let msg = Printf.sprintf "Invalid component name '%s'" component in
695-
error "%s" msg ;
696-
raise Api_errors.(Server_error (internal_error, [msg]))
694+
Helpers.internal_error ~log_err:true "Invalid component name '%s'"
695+
component
697696
in
698697
match
699698
Livepatch.get_livepatch_file_path ~component:component' ~base_build_id
@@ -703,9 +702,8 @@ let apply_livepatch ~__context ~host:_ ~component ~base_build_id ~base_version
703702
Livepatch.apply ~component:component' ~livepatch_file ~base_build_id
704703
~base_version ~base_release ~to_version ~to_release
705704
| None ->
706-
let msg = Printf.sprintf "No expected livepatch file for %s" component in
707-
error "%s" msg ;
708-
raise Api_errors.(Server_error (internal_error, [msg]))
705+
Helpers.internal_error ~log_err:true "No expected livepatch file for %s"
706+
component
709707

710708
let apply_livepatches' ~__context ~host ~livepatches =
711709
List.partition_map

0 commit comments

Comments
 (0)