Skip to content

Commit 56ae24f

Browse files
authored
CP-52365 adjust interface to dmv-utils (#6314)
* We currently have a mock implementation for driver-tool from the dmv-utils package. Adjust the command line argument structure to the real implementation to make the switch over easy. * Install the mock implementation if the real implementation is not in place. We might want to remove this later. Currently xapi.spec does not list the dependency.
2 parents cadb6d0 + 41b84af commit 56ae24f

File tree

3 files changed

+62
-40
lines changed

3 files changed

+62
-40
lines changed

ocaml/xapi/xapi_globs.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -933,7 +933,7 @@ let xl_cmd = ref "/usr/sbin/xl"
933933

934934
let depmod = ref "/usr/sbin/depmod"
935935

936-
let driver_tool = ref "/opt/xensource/debug/drivertool.sh"
936+
let driver_tool = ref "/usr/sbin/driver-tool"
937937

938938
let dracut = ref "/usr/bin/dracut"
939939

ocaml/xapi/xapi_host_driver.ml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ module Variant = struct
7474
if v.API.driver_variant_hardware_present = false then
7575
no_hardware (Ref.string_of self) ;
7676
let stdout =
77-
Tool.call ["select"; d.API.host_driver_name; v.API.driver_variant_name]
77+
Tool.call
78+
["-s"; "-n"; d.API.host_driver_name; "-v"; v.API.driver_variant_name]
7879
in
7980
info "%s: %s" __FUNCTION__ stdout ;
8081
Db.Host_driver.set_selected_variant ~__context ~self:drv ~value:self
@@ -171,10 +172,12 @@ let remove ~__context ~host ~except =
171172
(** Runs on [host]. We update or create an entry for each driver
172173
reported by drivertool and remove any extra driver that is in xapi. *)
173174
let scan ~__context ~host =
174-
Tool.Mock.install () ;
175+
let path = !Xapi_globs.driver_tool in
176+
(* if the real tool is not installed, install a mock *)
177+
if not (Sys.file_exists path) then Tool.Mock.install () ;
175178
let null = Ref.null in
176179
let drivers (* on this host *) =
177-
Tool.call ["list"]
180+
Tool.call ["-l"]
178181
|> Tool.parse
179182
|> List.map @@ fun (_name, driver) ->
180183
let driver_ref =

ocaml/xapi/xapi_host_driver_tool.ml

Lines changed: 55 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -242,26 +242,6 @@ module Mock = struct
242242

243243
set -o errexit
244244
set -o pipefail
245-
if [[ -n "$TRACE" ]]; then set -o xtrace; fi
246-
set -o nounset
247-
248-
if [[ "${1-}" =~ ^-*h(elp)?$ ]]; then
249-
cat <<EOF
250-
Usage: $0 arg-one arg-two
251-
252-
This is an awesome bash script to make your life better.
253-
EOF
254-
fi
255-
256-
function deselect {
257-
cat <<EOF
258-
{
259-
"driver": "$1",
260-
"exit": 0
261-
}
262-
EOF
263-
}
264-
265245

266246
function selection {
267247
cat <<EOF
@@ -621,22 +601,61 @@ function list() {
621601
EOF
622602
}
623603

604+
# Initialize variables with default values
605+
l_flag=false
606+
s_flag=false
607+
n_value=""
608+
v_value=""
609+
610+
# Use getopt to parse command-line options
611+
while getopts "lsn:v:" opt; do
612+
case "$opt" in
613+
l)
614+
l_flag=true
615+
;;
616+
s)
617+
s_flag=true
618+
;;
619+
n)
620+
n_value="$OPTARG"
621+
;;
622+
v)
623+
v_value="$OPTARG"
624+
;;
625+
\?) # Invalid option
626+
echo "Invalid option: -$OPTARG" >&2 #>&2 redirects error message to stderr
627+
exit 1
628+
;;
629+
:) # Missing argument for option
630+
echo "Option -$OPTARG requires an argument." >&2
631+
exit 1
632+
;;
633+
esac
634+
done
635+
636+
# Shift the remaining positional parameters (if any)
637+
shift $((OPTIND - 1))
638+
639+
# We don't properly prevent illegal combinations because this is just a
640+
# mock. So we recognise -l first.
641+
if $l_flag; then
642+
list
643+
exit 0
644+
fi
624645

625-
case "$1" in
626-
list)
627-
list
628-
;;
629-
select)
630-
selection "$2" "$3"
631-
;;
632-
deselect)
633-
deselect "$2"
634-
;;
635-
*)
636-
echo "unknown command $1" 2>&1
646+
if $s_flag; then
647+
if [ -z "$n_value" ]; then
648+
echo "missing -n" >&2
649+
exit 1
650+
fi
651+
if [ -z "$v_value" ]; then
652+
echo "missing -v" >&2
637653
exit 1
638-
;;
639-
esac
654+
fi
655+
656+
selection "$n_value" "$v_value"
657+
exit 0
658+
fi
640659
|}
641660

642661
let install () =
@@ -645,6 +664,6 @@ esac
645664
Xapi_stdext_unix.Unixext.write_string_to_file path drivertool_sh ;
646665
Unix.chmod path 0o755
647666
with e ->
648-
Helpers.internal_error ~log_err:true "%s: can't install %s: %s"
649-
__FUNCTION__ path (Printexc.to_string e)
667+
Helpers.internal_error "%s: can't install %s: %s" __FUNCTION__ path
668+
(Printexc.to_string e)
650669
end

0 commit comments

Comments
 (0)