Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
fdb0da9
[maintenance]: quicktest: add the ability to run without XAPI
edwintorok Mar 10, 2023
8eddc8e
CP-41667: forkexecd: use a string map for env and fix quoting for pro…
edwintorok Mar 10, 2023
b74478d
[maintenance] fe_test.sh: reduce minimum sleep time
edwintorok Mar 10, 2023
27e73a5
CP-41667: fe_systemctl: add start_templated and set_properties
edwintorok Mar 10, 2023
a077192
[maintenance]: bump dune language version
edwintorok Mar 20, 2023
43f768e
[maintenance] bump minimum dune language version to 3.7
edwintorok Mar 20, 2023
878329e
[maintenance]: do not build bytecode versions of internal libraries
edwintorok Mar 20, 2023
ff21d4d
[maintenance]: remove xapi-xenopsd.opam
edwintorok Mar 20, 2023
36615c9
[maintenance]: drop {gzip,zstd,xapi-compression}.opam
edwintorok Mar 20, 2023
6afabaf
[maintenance]: make pciutil internal library
edwintorok Mar 20, 2023
2a07b7f
[maintenance] cdrommon: minimize dependencies
edwintorok Mar 20, 2023
7203430
[maintenance]: disable implicit transitive deps
edwintorok Mar 20, 2023
37de50c
[maintenance]: xapi-aux does not need to depend on xapi-types
edwintorok Mar 20, 2023
9f11651
[maintenance]: preprocess only modules containing @@deriving
edwintorok Mar 20, 2023
e1468f3
[maintenance]: split server.ml into separate library
edwintorok Mar 20, 2023
bdf835b
[maintenance]: remove dependency between most tests and server.ml
edwintorok Mar 20, 2023
99d3ad2
[maintenance]: remove API.API
edwintorok Mar 20, 2023
b0eba7f
[maintenance]: reduce timeout in fe_test
edwintorok Mar 20, 2023
3fd3847
[maintenance]: reduce basic-rpc-test time
edwintorok Mar 20, 2023
15d515c
[maintenance]: try to reconnect to message-switch every 0.5s
edwintorok Mar 20, 2023
fb99a47
[maintenance]: speed up fe_test.sh when max_fds is very large
edwintorok Mar 20, 2023
869853c
fix build after merge: implicit transitive deps is disabled
edwintorok May 31, 2023
47a4d85
fe_test.sh: reliably detect when server is listening on the socket
edwintorok Jun 5, 2023
f17dd60
Forkexecd: shut down the socket before closing in the child
edwintorok Jun 6, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
name: Ocaml tests
runs-on: ubuntu-20.04
env:
package: "xapi-cli-protocol xapi-client xapi-consts xapi-datamodel xapi-types xapi xe xen-api-sdk xen-api-client xen-api-client-lwt xen-api-client-async xapi-rrdd xapi-rrdd-plugin xapi-rrd-transport xapi-rrd-transport-utils rrd-transport rrdd-plugin rrdd-plugins rrddump gzip http-lib pciutil safe-resources sexpr stunnel uuid xapi-compression xml-light2 zstd vhd-tool xapi-networkd xapi-squeezed xapi-xenopsd xapi-xenopsd-cli xapi-xenopsd-simulator xapi-xenopsd-xc message-switch message-switch-async message-switch-cli message-switch-core message-switch-lwt message-switch-unix xapi-idl forkexec xapi-forkexecd xapi-storage xapi-storage-script xapi-storage-cli wsproxy xapi-nbd varstored-guard xapi-log xapi-open-uri vhd-format vhd-format-lwt"
package: "xapi-cli-protocol xapi-client xapi-consts xapi-datamodel xapi-types xapi xe xen-api-sdk xen-api-client xen-api-client-lwt xen-api-client-async xapi-rrdd xapi-rrdd-plugin xapi-rrd-transport xapi-rrd-transport-utils rrd-transport rrdd-plugin rrdd-plugins rrddump http-lib safe-resources sexpr stunnel uuid xml-light2 vhd-tool xapi-networkd xapi-squeezed xapi-xenopsd-cli xapi-xenopsd-simulator xapi-xenopsd-xc message-switch message-switch-async message-switch-cli message-switch-core message-switch-lwt message-switch-unix xapi-idl forkexec xapi-forkexecd xapi-storage xapi-storage-script xapi-storage-cli wsproxy xapi-nbd varstored-guard xapi-log xapi-open-uri vhd-format vhd-format-lwt"
XAPI_VERSION: "v0.0.0-${{ github.sha }}"

steps:
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ install: build doc sdk doc-json
dune install --destdir=$(DESTDIR) --prefix=$(PREFIX) --libdir=$(LIBDIR) --mandir=$(MANDIR) \
xapi-client xapi-schema xapi-consts xapi-cli-protocol xapi-datamodel xapi-types \
xen-api-client xen-api-client-lwt xen-api-client-async rrdd-plugin rrd-transport \
gzip http-lib pciutil sexpr stunnel uuid xml-light2 zstd xapi-compression safe-resources \
http-lib sexpr stunnel uuid xml-light2 safe-resources \
message-switch message-switch-async message-switch-cli message-switch-core message-switch-lwt \
message-switch-unix xapi-idl forkexec xapi-forkexecd xapi-storage xapi-storage-script xapi-storage-cli \
xapi-nbd varstored-guard xapi-log xapi-open-uri
Expand All @@ -216,7 +216,7 @@ uninstall:
dune uninstall --destdir=$(DESTDIR) --prefix=$(PREFIX) --libdir=$(LIBDIR) --mandir=$(MANDIR) \
xapi-client xapi-schema xapi-consts xapi-cli-protocol xapi-datamodel xapi-types \
xen-api-client xen-api-client-lwt xen-api-client-async rrdd-plugin rrd-transport \
gzip http-lib pciutil sexpr stunnel uuid xml-light2 zstd xapi-compression safe-resources \
http-lib sexpr stunnel uuid xml-light2 safe-resources \
message-switch message-switch-async message-switch-cli message-switch-core message-switch-lwt \
message-switch-unix xapi-idl forkexec xapi-forkexecd xapi-storage xapi-storage-script xapi-log \
xapi-open-uri
Expand Down
2 changes: 1 addition & 1 deletion README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ To build xen-api from source, we recommend using [opam](https://opam.ocaml.org/d
6) Install all the Packages.

```bash
PACKAGES="xapi-cli-protocol xapi-client xapi-consts xapi-datamodel xapi-types xapi xe xen-api-sdk xen-api-client xen-api-client-lwt xen-api-client-async xapi-rrdd xapi-rrdd-plugin xapi-rrd-transport xapi-rrd-transport-utils rrd-transport rrdd-plugin rrdd-plugins rrddump gzip http-lib pciutil safe-resources sexpr stunnel uuid xapi-compression xml-light2 zstd vhd-tool xs-toolstack"
PACKAGES="xapi-cli-protocol xapi-client xapi-consts xapi-datamodel xapi-types xapi xe xen-api-sdk xen-api-client xen-api-client-lwt xen-api-client-async xapi-rrdd xapi-rrdd-plugin xapi-rrd-transport xapi-rrd-transport-utils rrd-transport rrdd-plugin rrdd-plugins rrddump http-lib pciutil safe-resources sexpr stunnel uuid xml-light2 vhd-tool xs-toolstack"

# NOT needed with opam>=2.1.0) Install all the dependencies (Including OS):
opam --yes depext --yes -u $PACKAGES # The first '--yes' is to install depext itself
Expand Down
2 changes: 1 addition & 1 deletion dune
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
(ocamlopt_flags (:standard -g -p -w -39))
(flags (:standard -w -39))
)
(dev (flags (:standard -g -w -39)))
(dev (flags (:standard -g -w -39 -warn-error -32-38-67-69)))
(release
(flags (:standard -w -39-6))
(env-vars (ALCOTEST_COMPACT 1))
Expand Down
3 changes: 2 additions & 1 deletion dune-project
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
(lang dune 2.0)
(lang dune 3.7)

(implicit_transitive_deps false)
(formatting (enabled_for ocaml))
22 changes: 0 additions & 22 deletions gzip.opam

This file was deleted.

2 changes: 1 addition & 1 deletion message-switch-async.opam
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ build: [
]
depends: [
"ocaml"
"dune" {build & >= "1.4"}
"dune" {build & >= "3.7"}
"odoc" {with-doc}
"async" {>= "v0.9.0"}
"cohttp-async" {>= "1.0.2"}
Expand Down
2 changes: 1 addition & 1 deletion message-switch-cli.opam
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ build: [
]
depends: [
"ocaml"
"dune" {build & >= "1.4"}
"dune" {build & >= "3.7"}
"odoc" {with-doc}
"cmdliner"
"message-switch-unix"
Expand Down
2 changes: 1 addition & 1 deletion message-switch-core.opam
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ build: [
]
depends: [
"ocaml"
"dune" {build & >= "1.4"}
"dune" {build & >= "3.7"}
"odoc" {with-doc}
"astring"
"cohttp" {>= "0.21.1"}
Expand Down
2 changes: 1 addition & 1 deletion message-switch-lwt.opam
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ build: [
]
depends: [
"ocaml"
"dune" {build & >= "1.4"}
"dune" {build & >= "3.7"}
"odoc" {with-doc}
"cohttp-lwt-unix"
"lwt" {>= "3.0.0"}
Expand Down
2 changes: 1 addition & 1 deletion message-switch-unix.opam
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ build: [
]
depends: [
"ocaml"
"dune" {build & >= "1.4"}
"dune" {build & >= "3.7"}
"odoc" {with-doc}
"base-threads"
"message-switch-core"
Expand Down
2 changes: 1 addition & 1 deletion message-switch.opam
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ build: [
]
depends: [
"ocaml"
"dune" {build & >= "1.4"}
"dune" {build & >= "3.7"}
"odoc" {with-doc}
"cmdliner"
"cohttp-async" {with-test}
Expand Down
1 change: 1 addition & 0 deletions ocaml/alerts/certificate/dune
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
(library
(name certificate_check)
(modules certificate_check)
(modes best)
(libraries
astring
xapi-client
Expand Down
1 change: 1 addition & 0 deletions ocaml/auth/dune
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
(library
(modes best)
(foreign_stubs
(language c)
(names xa_auth xa_auth_stubs)
Expand Down
16 changes: 6 additions & 10 deletions ocaml/cdrommon/cdrommon.ml
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,13 @@
let oldnotify = ref false

let disc_inserted name =
let args = [|"xe"; "host-notify"; "type=cdrom"; "params=inserted:" ^ name|] in
let ret = Xapi_stdext_unix.Unixext.spawnvp args.(0) args in
let cmd =
Filename.quote_command "xe"
["host-notify"; "type=cdrom"; "params=inserted:" ^ name]
in
let ret = Sys.command cmd in
(* check if we got an error, and record the fact *)
match ret with
| Unix.WEXITED 0 ->
oldnotify := false
| Unix.WEXITED _ ->
oldnotify := true
| _ ->
oldnotify := true
match ret with 0 -> oldnotify := false | _ -> oldnotify := true

let disc_removed (_ : string) =
(* we don't need to do anything *)
Expand Down Expand Up @@ -63,6 +60,5 @@ let () =
Printf.eprintf "usage: %s <cdrompath>\n" Sys.argv.(0) ;
exit 1
) ;
Xapi_stdext_unix.Unixext.daemonize () ;
(* check every 2 seconds *)
check 2 Sys.argv.(1)
3 changes: 0 additions & 3 deletions ocaml/cdrommon/dune
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
(package xapi)
(libraries
cdrom
threads
unix
xapi-stdext-unix
)
)

8 changes: 6 additions & 2 deletions ocaml/database/dune
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@
xapi-stdext-encodings
)
(wrapped false)
(preprocess (pps ppx_sexp_conv))
(preprocess (per_module ((pps ppx_sexp_conv) Schema)))
)

(library
(name xapi_database)
(modes best)
(modules
(:standard \ database_server_main db_cache_test db_names db_exn
block_device_io string_marshall_helper string_unmarshall_helper schema
Expand Down Expand Up @@ -49,7 +50,10 @@
xmlm
)
(wrapped false)
(preprocess (pps ppx_deriving_rpc))
(preprocess
(per_module
((pps ppx_deriving_rpc)
Db_cache_types Db_filter_types Db_rpc_common_v2 Db_secret_string)))
)

(executable
Expand Down
3 changes: 1 addition & 2 deletions ocaml/forkexecd/lib/dune
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,4 @@
xapi-stdext-pervasives
xapi-stdext-unix
)
(preprocess
(pps ppx_deriving_rpc)))
(preprocess (per_module ((pps ppx_deriving_rpc) Fe))))
134 changes: 106 additions & 28 deletions ocaml/forkexecd/lib/fe_systemctl.ml
Original file line number Diff line number Diff line change
Expand Up @@ -18,54 +18,127 @@ type status = {
; active_state: string
}

module StringMap = Map.Make (String)

type 'a string_map = 'a StringMap.t

let systemctl = "/usr/bin/systemctl"

let action ~service action =
let _, _stderr =
Forkhelpers.execute_command_get_output systemctl [action; service]
let test_mode = ref false

let execute_command_get_output cmd args =
(* for systemctl --user to work it needs env vars *)
let env, args =
if !test_mode then
(Some (Unix.environment ()), "--user" :: args)
else
(None, args)
in
Forkhelpers.execute_command_get_output ?env cmd args

let action ?(args = []) ~service action =
let _, _ = execute_command_get_output systemctl (action :: service :: args) in
()

let default_env = ["PATH=" ^ String.concat ":" Forkhelpers.default_path]
let default_env =
StringMap.singleton "PATH" @@ String.concat ":" Forkhelpers.default_path

let run_path = "/run/systemd/system/"

let start_transient ?(env = Array.of_list default_env) ?(properties = [])
~service cmd args =
(* see https://www.freedesktop.org/software/systemd/man/systemd.syntax.html#Quoting
Neither [Filename.quote] or [String.escaped] would produce correct results
*)
let systemd_quote s =
let b = Buffer.create (String.length s) in
Buffer.add_char b '\'' ;
let () =
s
|> String.iter @@ function
| '\\' ->
Buffer.add_string b {|\\|}
| '\'' ->
(* these hex escapes work regardless what outer quotes are used *)
Buffer.add_string b {|\x27|}
| '"' ->
Buffer.add_string b {|\x22|}
| c when Astring.Char.Ascii.is_print c ->
Buffer.add_char b c
| _ ->
invalid_arg ("Values can only contain printable characters: " ^ s)
in
Buffer.add_char b '\'' ; Buffer.contents b

let env_pair (k, v) = Printf.sprintf "%s=%s" k v

let environment env =
env
|> StringMap.bindings
|> List.map env_pair
|> List.map (fun v -> ("Environment", [v]))
(* we could build just a single environment line, but might be too long and
difficult to debug *)

let build_properties env base properties =
"[Service]"
:: (List.concat [environment env; base; properties]
|> List.map (fun (k, v) ->
String.concat ""
[k; "="; List.map systemd_quote v |> String.concat " "]
)
)

let start_transient ?(env = default_env) ?(properties = []) ~service cmd args =
let syslog_key = service in
let service = syslog_key ^ ".service" in
let destination = Filename.concat run_path service in
properties
|> List.append
[
( "Environment"
, env |> Array.to_list |> List.map Filename.quote |> String.concat " "
)
; ("SyslogIdentifier", syslog_key)
; ("SyslogLevel", "debug")
; ("StandardOutput", "syslog")
; ("StandardError", "inherit")
; ("StartLimitInterval", "0") (* no rate-limit, for bootstorms *)
; ("ExecStart", String.concat " " (cmd :: List.map Filename.quote args))
; ("Type", "simple")
(* our systemd is too old, and doesn't support 'exec' *)
; ("Restart", "no")
(* can't restart the device-model, it would've lost all state already *)
; ("Slice", "system.slice")
; ("TimeoutStopSec", "10")
]
|> List.map (fun (k, v) -> k ^ "=" ^ v)
build_properties env
[
("SyslogIdentifier", [syslog_key])
; ("SyslogLevel", ["debug"])
; ("StandardOutput", ["syslog"])
; ("StandardError", ["inherit"])
; ("StartLimitInterval", ["0"]) (* no rate-limit, for bootstorms *)
; ("ExecStart", cmd :: args)
; ("Type", ["simple"])
(* our systemd is too old, and doesn't support 'exec' *)
; ("Restart", ["no"])
(* can't restart the device-model, it would've lost all state already *)
; ("Slice", ["system.slice"])
; ("TimeoutStopSec", ["10"])
]
properties
|> List.append
[
"[Unit]"
; "Description=transient unit for " ^ syslog_key
; "DefaultDependencies=no" (* lifecycle tied to domain, not systemd *)
; "[Service]"
]
|> String.concat "\n"
|> Xapi_stdext_unix.Unixext.write_string_to_file destination ;
action ~service "start"

let unit_path () =
if !test_mode then
let home = Sys.getenv_opt "HOME" |> Option.value ~default:"/root" in
Filename.concat home ".config/systemd/user"
else
"/etc/systemd/system"

let drop_in_path service =
Printf.sprintf "%s/%s.service.d/10-xapi.conf" (unit_path ()) service

let set_properties ?(env = StringMap.empty) ?(properties = []) ~service () =
let path = drop_in_path service in
Xapi_stdext_unix.Unixext.mkdir_rec (Filename.dirname path) 0o700 ;
build_properties env [] properties
|> String.concat "\n"
|> Xapi_stdext_unix.Unixext.write_string_to_file ~perms:0o600 path ;
let _, _ = execute_command_get_output systemctl ["daemon-reload"] in
()

let start_templated ~template ~instance =
action ~service:(Printf.sprintf "%s@%s" template instance) "start"

let show ~service =
let result = "Result" in
let exec_main_pid = "ExecMainPID" in
Expand All @@ -75,7 +148,7 @@ let show ~service =
[result; exec_main_pid; exec_main_status; active_state] |> String.concat ","
|> fun properties ->
["show"; "-p"; properties; service]
|> Forkhelpers.execute_command_get_output systemctl
|> execute_command_get_output systemctl
|> fst
|> Astring.String.cuts ~sep:"\n"
|> List.to_seq
Expand Down Expand Up @@ -104,6 +177,9 @@ let stop ~service =
) ;
let destination = Filename.concat run_path (service ^ ".service") in
Xapi_stdext_unix.Unixext.unlink_safe destination ;
let dropin = drop_in_path service in
Xapi_stdext_unix.Unixext.unlink_safe dropin ;
let () = try Unix.rmdir (Filename.dirname dropin) with _ -> () in
status

let is_active ~service =
Expand Down Expand Up @@ -135,3 +211,5 @@ let start_transient ?env ?properties ~service cmd args =
with _ -> ()
) ;
raise e

let set_test () = test_mode := true
Loading