Skip to content

Commit 8c49449

Browse files
authored
Merge feature branch expose_more_system_info into master (#6713)
2 parents cde5714 + 9b4da93 commit 8c49449

21 files changed

+307
-16
lines changed

ocaml/idl/datamodel_host.ml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2536,6 +2536,22 @@ let latest_synced_updates_applied_state =
25362536
]
25372537
)
25382538

2539+
let get_tracked_user_agents =
2540+
call ~name:"get_tracked_user_agents" ~lifecycle:[]
2541+
~doc:
2542+
"Get the (name, version) list of tracked user agents on this host. If \
2543+
different versions of the same name are seen, keep the last-seen \
2544+
version. The oldest entry will be removed if reach the max num. Note \
2545+
that the list is cleared after host/XAPI restart"
2546+
~params:[(Ref _host, "self", "The host")]
2547+
~allowed_roles:_R_READ_ONLY
2548+
~result:
2549+
( Map (String, String)
2550+
, "The (name, version) list of user agents that have been tracked on \
2551+
this host"
2552+
)
2553+
()
2554+
25392555
(** Hosts *)
25402556
let t =
25412557
create_obj ~in_db:true
@@ -2680,6 +2696,7 @@ let t =
26802696
; set_ssh_enabled_timeout
26812697
; set_console_idle_timeout
26822698
; set_ssh_auto_mode
2699+
; get_tracked_user_agents
26832700
]
26842701
~contents:
26852702
([

ocaml/tests/common/test_common.ml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ let default_cpu_info =
4343
("cpu_count", "0")
4444
; ("socket_count", "0")
4545
; ("threads_per_core", "0")
46+
; ("nr_nodes", "0")
4647
; ("vendor", "Abacus")
4748
; ("speed", "")
4849
; ("modelname", "")
@@ -79,6 +80,7 @@ let make_localhost ~__context ?(features = Features.all_features) () =
7980
cpu_count= 1
8081
; socket_count= 1
8182
; threads_per_core= 1
83+
; nr_nodes= 1
8284
; vendor= ""
8385
; speed= ""
8486
; modelname= ""

ocaml/tests/suite_alcotest.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,5 @@ let () =
7070
@ Test_session.tests
7171
@ Test_xapi_cmd_result.tests
7272
@ Test_extauth_plugin_ADwinbind.tests
73+
@ Test_tracked_user_agents.tests
7374
)
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
(*
2+
* Copyright (C) Cloud Software Group
3+
*
4+
* This program is free software; you can redistribute it and/or modify
5+
* it under the terms of the GNU Lesser General Public License as published
6+
* by the Free Software Foundation; version 2.1 only. with the special
7+
* exception on linking described in file LICENSE.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU Lesser General Public License for more details.
13+
*)
14+
15+
let make_ctx ~user_agent ~client_ip =
16+
let open Context in
17+
let additional_headers =
18+
client_ip
19+
|> Option.fold ~none:[] ~some:(fun x ->
20+
[("STUNNEL_PROXY", Printf.sprintf "TCP6 %s another_ip 443 80" x)]
21+
)
22+
in
23+
let rq = {Http.Request.empty with user_agent; additional_headers} in
24+
(* it doesn't matter which fd is used to here, we are just satisying the
25+
type system. we use stderr because then we don't need to worry about
26+
closing it *)
27+
make ~origin:(Http (rq, Unix.stderr)) "text_ctx"
28+
29+
let test_tracked_user_agents ~agents ~expected () =
30+
Xapi_tracked_user_agents.reset () ;
31+
List.iter
32+
(fun user_agent ->
33+
let __context =
34+
make_ctx ~user_agent:(Some user_agent) ~client_ip:(Some "1.2.3.4")
35+
in
36+
Xapi_tracked_user_agents.track ~__context
37+
)
38+
agents ;
39+
let compare ua1 ua2 = String.compare (fst ua1) (fst ua2) in
40+
Alcotest.(check (list (pair string string)))
41+
"new user agents are equal to expected"
42+
(List.sort compare expected)
43+
(Xapi_tracked_user_agents.get () |> List.sort compare)
44+
45+
let tests =
46+
[
47+
( "tracked_user_agents_base"
48+
, [
49+
( "test_tracked_user_agents_base"
50+
, `Quick
51+
, test_tracked_user_agents
52+
~agents:["XenCenter/2025.2.0.8315"]
53+
~expected:[("XenCenter", "2025.2.0.8315")]
54+
)
55+
; ( "test_tracked_user_agents_version_last_seen"
56+
, `Quick
57+
, test_tracked_user_agents
58+
~agents:
59+
[
60+
"XenCenter/2025.2.0.8315"
61+
; "XenAPI/2.15"
62+
; "Mozilla/5.0 (Windows NT 10.0; Win64; x64)"
63+
; "XenCenter/2025.2.0.8316"
64+
]
65+
~expected:
66+
[
67+
("XenCenter", "2025.2.0.8316")
68+
; ("XenAPI", "2.15")
69+
; ("Mozilla", "5.0")
70+
]
71+
)
72+
; ( "test_tracked_user_agents_no_version"
73+
, `Quick
74+
, test_tracked_user_agents ~agents:["XenCenter"]
75+
~expected:[("XenCenter", "")]
76+
)
77+
; ( "test_tracked_user_agents_no_slash"
78+
, `Quick
79+
, test_tracked_user_agents
80+
~agents:["XenCenter 2025.2.0.8315"]
81+
~expected:[("XenCenter", "")]
82+
)
83+
; ( "test_tracked_user_agents_exceeding_maxstrlen"
84+
, `Quick
85+
, test_tracked_user_agents
86+
~agents:
87+
[
88+
"XenCenter/2025.2.0.8315.11111111111111111111111111111111111111111"
89+
]
90+
~expected:[]
91+
)
92+
; ( "test_tracked_user_agents_exceeding_max_num"
93+
, `Quick
94+
, test_tracked_user_agents
95+
~agents:(List.init 130 (Printf.sprintf "Agent%d/1.0"))
96+
~expected:
97+
(List.init 128 (fun i -> (Printf.sprintf "Agent%d" (i + 2), "1.0"))
98+
)
99+
)
100+
]
101+
)
102+
]

ocaml/xapi-idl/xen/xenops_interface.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,7 @@ module Host = struct
453453
cpu_count: int
454454
; socket_count: int
455455
; threads_per_core: int
456+
; nr_nodes: int
456457
; vendor: string
457458
; speed: string
458459
; modelname: string

ocaml/xapi/cpuid_helpers.ml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ let socket_count = Map_check.(field "socket_count" int)
4242

4343
let threads_per_core = Map_check.(field "threads_per_core" int)
4444

45+
let nr_nodes = Map_check.(field "nr_nodes" int)
46+
4547
let vendor = Map_check.(field "vendor" string)
4648

4749
let get_flags_for_vm ~__context domain_type cpu_info =

ocaml/xapi/cpuid_helpers.mli

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ val socket_count : int Map_check.field
3131

3232
val threads_per_core : int Map_check.field
3333

34+
val nr_nodes : int Map_check.field
35+
3436
val features : [`vm] Xenops_interface.CPU_policy.t Map_check.field
3537

3638
val features_pv : [`host] Xenops_interface.CPU_policy.t Map_check.field

ocaml/xapi/create_misc.ml

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,11 @@ type host_info = {
4848

4949
(** The format of the response looks like
5050
* # xen-livepatch list
51-
* ID | status
52-
* ----------------------------------------+------------
53-
* hp_1_1 | CHECKED
54-
* hp_2_1 | APPLIED
55-
* hp_3_2 | APPLIED *)
51+
* ID | status | metadata
52+
* ----------------------------------------+------------+---------------
53+
* hp_1_1 | CHECKED |
54+
* hp_2_1 | APPLIED |
55+
* hp_3_2 | APPLIED | *)
5656
let make_xen_livepatch_list () =
5757
let lines =
5858
try
@@ -63,8 +63,8 @@ let make_xen_livepatch_list () =
6363
let patches =
6464
List.fold_left
6565
(fun acc l ->
66-
match List.map String.trim (Xstringext.String.split ~limit:2 '|' l) with
67-
| [key; "APPLIED"] ->
66+
match List.map String.trim (String.split_on_char '|' l) with
67+
| key :: "APPLIED" :: _ ->
6868
key :: acc
6969
| _ ->
7070
acc
@@ -76,10 +76,12 @@ let make_xen_livepatch_list () =
7676
(** The format of the response looks like
7777
* # kpatch list
7878
* Loaded patch modules:
79-
* kpatch_hp_1_1
80-
* kpatch_hp_2_1
81-
82-
* Installed patch modules: *)
79+
* lp_4_19_19__8_0_32_xs8__4_19_19__8_0_33_xs8 [enabled]
80+
* lp_4_19_19__8_0_20_xs8__4_19_19__8_0_21_xs8 [enabled]
81+
*
82+
* Installed patch modules:
83+
*
84+
* Only patch name are returned, status are excluded. *)
8385
let make_kpatch_list () =
8486
let start_line = "Loaded patch modules:" in
8587
let end_line = "Installed patch modules:" in
@@ -99,7 +101,14 @@ let make_kpatch_list () =
99101
| line :: rest ->
100102
let line' = String.trim line in
101103
if line' <> "" && started then
102-
loop (line' :: acc) true rest
104+
let patch_name =
105+
match String.split_on_char ' ' line' with
106+
| patch :: _ ->
107+
patch
108+
| [] ->
109+
line'
110+
in
111+
loop (patch_name :: acc) true rest
103112
else
104113
loop acc started rest
105114
in
@@ -567,6 +576,7 @@ let create_host_cpu ~__context host_info =
567576
("cpu_count", string_of_int cpu_info.cpu_count)
568577
; ("socket_count", string_of_int cpu_info.socket_count)
569578
; ("threads_per_core", string_of_int cpu_info.threads_per_core)
579+
; ("nr_nodes", string_of_int cpu_info.nr_nodes)
570580
; ("vendor", cpu_info.vendor)
571581
; ("speed", cpu_info.speed)
572582
; ("modelname", cpu_info.modelname)
@@ -592,11 +602,12 @@ let create_host_cpu ~__context host_info =
592602
let old_cpu_info = Db.Host.get_cpu_info ~__context ~self:host in
593603
debug
594604
"create_host_cpuinfo: setting host cpuinfo: socket_count=%d, \
595-
cpu_count=%d, threads_per_core=%d, features_hvm=%s, features_pv=%s, \
596-
features_hvm_host=%s, features_pv_host=%s"
605+
cpu_count=%d, threads_per_core=%d, nr_nodes=%d, features_hvm=%s, \
606+
features_pv=%s, features_hvm_host=%s, features_pv_host=%s"
597607
(Map_check.getf socket_count cpu)
598608
(Map_check.getf cpu_count cpu)
599609
(Map_check.getf threads_per_core cpu)
610+
(Map_check.getf nr_nodes cpu)
600611
(Map_check.getf features_hvm cpu |> CPU_policy.to_string)
601612
(Map_check.getf features_pv cpu |> CPU_policy.to_string)
602613
(Map_check.getf features_hvm_host cpu |> CPU_policy.to_string)

ocaml/xapi/message_forwarding.ml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4116,6 +4116,13 @@ functor
41164116
let local_fn = Local.Host.set_ssh_auto_mode ~self ~value in
41174117
let remote_fn = Client.Host.set_ssh_auto_mode ~self ~value in
41184118
do_op_on ~local_fn ~__context ~host:self ~remote_fn
4119+
4120+
let get_tracked_user_agents ~__context ~self =
4121+
info "Host.get_tracked_user_agents: host = '%s'"
4122+
(host_uuid ~__context self) ;
4123+
let local_fn = Local.Host.get_tracked_user_agents ~self in
4124+
let remote_fn = Client.Host.get_tracked_user_agents ~self in
4125+
do_op_on ~local_fn ~__context ~host:self ~remote_fn
41194126
end
41204127

41214128
module Host_crashdump = struct

ocaml/xapi/repository.ml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -702,7 +702,8 @@ let apply_livepatch ~__context ~host:_ ~component ~base_build_id ~base_version
702702
with
703703
| Some livepatch_file ->
704704
Livepatch.apply ~component:component' ~livepatch_file ~base_build_id
705-
~base_version ~base_release ~to_version ~to_release
705+
~base_version ~base_release ~to_version ~to_release ;
706+
Create_misc.create_software_version ~__context ()
706707
| None ->
707708
Helpers.internal_error ~log_err:true "No expected livepatch file for %s"
708709
component

0 commit comments

Comments
 (0)