Skip to content

Commit f2743cf

Browse files
authored
CA-404693 prohibit selecting driver variant if h/w not present (#6243)
Introduce a new error and raise it if a host driver variant is selected for hardware that is not present.
2 parents b731195 + c46ed3f commit f2743cf

File tree

3 files changed

+12
-0
lines changed

3 files changed

+12
-0
lines changed

ocaml/idl/datamodel_errors.ml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2010,6 +2010,9 @@ let _ =
20102010

20112011
error Api_errors.too_many_groups [] ~doc:"VM can only belong to one group." () ;
20122012

2013+
error Api_errors.host_driver_no_hardware ["driver variant"]
2014+
~doc:"No hardware present for this host driver variant" () ;
2015+
20132016
message
20142017
(fst Api_messages.ha_pool_overcommitted)
20152018
~doc:

ocaml/xapi-consts/api_errors.ml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1403,3 +1403,5 @@ let telemetry_next_collection_too_late =
14031403
let illegal_in_fips_mode = add_error "ILLEGAL_IN_FIPS_MODE"
14041404

14051405
let too_many_groups = add_error "TOO_MANY_GROUPS"
1406+
1407+
let host_driver_no_hardware = add_error "HOST_DRIVER_NO_HARDWARE"

ocaml/xapi/xapi_host_driver.ml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ module Tool = Xapi_host_driver_tool
2121
let invalid_value field value =
2222
raise Api_errors.(Server_error (invalid_value, [field; value]))
2323

24+
let no_hardware driver_variant =
25+
raise Api_errors.(Server_error (host_driver_no_hardware, [driver_variant]))
26+
2427
module Variant = struct
2528
let create ~__context ~name ~version ~driver ~hw_present ~priority ~dev_status
2629
=
@@ -68,6 +71,8 @@ module Variant = struct
6871
let drv = Db.Driver_variant.get_driver ~__context ~self in
6972
let d = Db.Host_driver.get_record ~__context ~self:drv in
7073
let v = Db.Driver_variant.get_record ~__context ~self in
74+
if v.API.driver_variant_hardware_present = false then
75+
no_hardware (Ref.string_of self) ;
7176
let stdout =
7277
Tool.call ["select"; d.API.host_driver_name; v.API.driver_variant_name]
7378
in
@@ -133,6 +138,8 @@ let select ~__context ~self ~variant =
133138
D.debug "%s selecting driver %s variant %s" __FUNCTION__ drv var ;
134139
let d = Db.Host_driver.get_record ~__context ~self in
135140
let v = Db.Driver_variant.get_record ~__context ~self:variant in
141+
if v.API.driver_variant_hardware_present = false then
142+
no_hardware (Ref.string_of variant) ;
136143
let stdout =
137144
Tool.call ["select"; d.API.host_driver_name; v.API.driver_variant_name]
138145
in

0 commit comments

Comments
 (0)