-
Notifications
You must be signed in to change notification settings - Fork 292
CA-282006: Prevent IP reconfiguration on a live cluster network #3500
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
edwintorok
merged 3 commits into
xapi-project:feature/REQ477/master
from
minishrink:feature/REQ477/CA-282006
Mar 12, 2018
+122
−12
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
|
||
open Quicktest_common | ||
(* provide test record type and make_test, start, | ||
* debug, success, and failed test functions *) | ||
|
||
open Client | ||
(* provide rpc ref *) | ||
|
||
module C = Client | ||
|
||
let is_empty = function | [] -> true | _ -> false | ||
|
||
(* [failed test.name string_of_failure] removes [test] from a test Hashtbl | ||
* and is therefore only called once, in the try-with statement. | ||
* This exception is raised within the try-with body to trigger | ||
* [failed test string_of_failure] *) | ||
exception Abort_test of string | ||
|
||
(** --- Helpers for reconfiguration --- *) | ||
|
||
let reconfigure_ipv4 ~session_id ~self ~dNS = | ||
let netmask = C.PIF.get_netmask ~session_id ~rpc:!rpc ~self in | ||
let iP = C.PIF.get_IP ~session_id ~rpc:!rpc ~self in | ||
let gateway = C.PIF.get_gateway ~session_id ~rpc:!rpc ~self in | ||
let mode = C.PIF.get_ip_configuration_mode ~session_id ~rpc:!rpc ~self in | ||
C.PIF.reconfigure_ip ~session_id ~rpc:!rpc ~self ~iP ~dNS ~gateway ~netmask ~mode | ||
|
||
let reconfigure_ipv6 ~session_id ~self ~dNS = | ||
|
||
(* confirm valid IPv6 strings exist *) | ||
let iPv6_lst = (C.PIF.get_IPv6 ~session_id ~rpc:!rpc ~self) |> List.filter ((<>) "") in | ||
if is_empty iPv6_lst | ||
then raise (Abort_test "No valid IPv6 strings exist."); | ||
|
||
let gateway = C.PIF.get_ipv6_gateway ~session_id ~rpc:!rpc ~self in | ||
let mode = C.PIF.get_ipv6_configuration_mode ~session_id ~rpc:!rpc ~self in | ||
let iPv6 = List.hd iPv6_lst in | ||
C.PIF.reconfigure_ipv6 ~session_id ~rpc:!rpc ~self ~iPv6 ~dNS ~gateway ~mode | ||
|
||
(** --- Test skeleton, receives environment params before running --- *) | ||
let test_reconfigure_ip ~ipv6 ~session_id ~(self : API.ref_PIF) = | ||
let ip_string = if ipv6 then "IPv6" else "IPv4" in | ||
let test = | ||
make_test (Printf.sprintf "Testing reconfiguring %s with clustering." ip_string) 4 | ||
in | ||
try | ||
start test; | ||
|
||
let dNS = C.PIF.get_DNS ~session_id ~rpc:!rpc ~self in | ||
if ipv6 | ||
then reconfigure_ipv6 ~session_id ~self ~dNS | ||
else reconfigure_ipv4 ~session_id ~self ~dNS; | ||
|
||
failed test "PIF.reconfigure_ip should raise clustering_enabled_on_network." | ||
with | ||
| Api_errors.(Server_error(code,_)) when code=Api_errors.clustering_enabled_on_network | ||
-> debug test (Printf.sprintf "%s raised as expected." Api_errors.clustering_enabled_on_network); | ||
success test | ||
| Api_errors.(Server_error(_,_)) -> () (* Don't fail on other API errors, only test clustering *) | ||
| Abort_test s -> failed test s | ||
| e -> failed test (ExnHelper.string_of_exn e) | ||
|
||
(** --- Check environment before calling test --- *) | ||
let test session_id = | ||
let test_all_pifs = make_test "Testing IP reconfiguration with and without clustering." 2 in | ||
try | ||
print_newline (); | ||
start test_all_pifs; | ||
print_newline (); | ||
let pifs = Client.PIF.get_all ~session_id ~rpc:!rpc in | ||
|
||
List.iter | ||
(fun self -> | ||
let clustering = | ||
let network = C.PIF.get_network ~session_id ~rpc:!rpc ~self in | ||
C.Cluster.get_all ~session_id ~rpc:!rpc | ||
|> List.filter | ||
(fun cluster -> (C.Cluster.get_network ~session_id ~rpc:!rpc ~self:cluster) = network) | ||
|> (fun lst -> not (is_empty lst)) | ||
in | ||
if clustering | ||
then begin | ||
test_reconfigure_ip ~ipv6:false ~session_id ~self | ||
(* IPv6 clusters not yet supported, can run this test once that changes *) | ||
(* test_reconfigure_ip ~ipv6:true ~session_id ~self *) | ||
end | ||
else | ||
debug test_all_pifs "No cluster objects on this PIF, skipping tests." | ||
) pifs; | ||
|
||
success test_all_pifs | ||
with e -> failed test_all_pifs (ExnHelper.string_of_exn e) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like we are missing
errs
declarations on all the cluster APIs too. It would be nice if these errors were checked at compile time by the type system (e.g. by using a Result type) but that is probably a huge amount of work. For now can you open an internal minor ticket to fix the API error declarations on the cluster APIs?