|
| 1 | +(* Dump API request/response *) |
| 2 | + |
| 3 | +module Impl : Rrd_interface.Server_impl with type context = unit = struct |
| 4 | + type context = unit |
| 5 | + let has_vm_rrd () ~vm_uuid:_ = true |
| 6 | + let push_rrd_local () ~vm_uuid:_ ~domid:_ = () |
| 7 | + let push_rrd_remote () ~vm_uuid:_ ~remote_address:_ = () |
| 8 | + let remove_rrd () ~uuid:_ = () |
| 9 | + let migrate_rrd () ?session_id:_ ~remote_address:_ ~vm_uuid:_ ~host_uuid:_ = () |
| 10 | + let send_host_rrd_to_master () ~master_address:_ = () |
| 11 | + let backup_rrds () ?remote_address:_ () = () |
| 12 | + let archive_rrd () ~vm_uuid:_ ~remote_address:_ = () |
| 13 | + let archive_sr_rrd () ~sr_uuid:_ = "" |
| 14 | + let push_sr_rrd () ~sr_uuid:_ ~path:_ = () |
| 15 | + let add_host_ds () ~ds_name:_ = () |
| 16 | + let forget_host_ds () ~ds_name:_ = () |
| 17 | + let query_possible_host_dss () () = [Data_source.{name="name"; description=""; enabled=true; standard=true; min=0.0; max=1.0; units="units"}] |
| 18 | + let query_host_ds () ~ds_name:_ = 0.0 |
| 19 | + let add_vm_ds () ~vm_uuid:_ ~domid:_ ~ds_name:_ = () |
| 20 | + let forget_vm_ds () ~vm_uuid:_ ~ds_name:_ = () |
| 21 | + let query_possible_vm_dss () ~vm_uuid:_ = [] |
| 22 | + let query_vm_ds () ~vm_uuid:_ ~ds_name:_ = 0.0 |
| 23 | + let add_sr_ds () ~sr_uuid:_ ~ds_name:_ = () |
| 24 | + let forget_sr_ds () ~sr_uuid:_ ~ds_name:_ = () |
| 25 | + let query_possible_sr_dss () ~sr_uuid:_ = [] |
| 26 | + let query_sr_ds () ~sr_uuid:_ ~ds_name:_ = 0.0 |
| 27 | + let update_use_min_max () ~value:_ = () |
| 28 | + let update_vm_memory_target () ~domid:_ ~target:_ = () |
| 29 | + let set_cache_sr () ~sr_uuid:_ = () |
| 30 | + let unset_cache_sr () () = () |
| 31 | + |
| 32 | + module Plugin = struct |
| 33 | + let get_header () () = "" |
| 34 | + let get_path () ~uid:_ = "" |
| 35 | + |
| 36 | + module Local = struct |
| 37 | + let register () ~uid:_ ~info:_ ~protocol:_ = 0.0 |
| 38 | + let deregister () ~uid:_ = () |
| 39 | + let next_reading () ~uid:_ = 0.0 |
| 40 | + end |
| 41 | + |
| 42 | + module Interdomain = struct |
| 43 | + let register () ~uid:_ ~info:_ ~protocol:_ = 0.0 |
| 44 | + let deregister () ~uid:_ = () |
| 45 | + let next_reading () ~uid:_ = 0.0 |
| 46 | + end |
| 47 | + |
| 48 | + let register () ~uid:_ ~frequency:_ = 0.0 |
| 49 | + let deregister () ~uid:_ = () |
| 50 | + let next_reading () ~uid:_ = 0.0 |
| 51 | + end |
| 52 | + |
| 53 | + module HA = struct |
| 54 | + let enable_and_update () ~statefile_latencies:_ ~heartbeat_latency:_ ~xapi_latency:_ = () |
| 55 | + let disable () () = () |
| 56 | + end |
| 57 | + |
| 58 | + module Deprecated = struct |
| 59 | + let load_rrd () ~uuid:_ ~timescale:_ ~master_address:_ = () |
| 60 | + end |
| 61 | +end |
| 62 | + |
| 63 | +module S = Rrd_interface.Server(Impl) |
| 64 | + |
| 65 | +let write_str filename str = |
| 66 | + let oc = open_out filename in |
| 67 | + Printf.fprintf oc "%s" str; |
| 68 | + close_out oc |
| 69 | + |
| 70 | +let read_str filename = |
| 71 | + let ic = open_in filename in |
| 72 | + let n = in_channel_length ic in |
| 73 | + let s = Bytes.create n in |
| 74 | + really_input ic s 0 n; |
| 75 | + close_in ic; |
| 76 | + s |
| 77 | + |
| 78 | +let dumping_rpc call = |
| 79 | + let request_str = Xmlrpc.string_of_call call in |
| 80 | + let response = S.process () call in |
| 81 | + let response_str = Xmlrpc.string_of_response response in |
| 82 | + write_str (Printf.sprintf "rpc_data/%s.request" call.Rpc.name) request_str; |
| 83 | + write_str (Printf.sprintf "rpc_data/%s.response" call.Rpc.name) response_str; |
| 84 | + response |
| 85 | + |
| 86 | +let run_all rpc = |
| 87 | + let module C = Rrd_interface.Client(struct let rpc = rpc end) in |
| 88 | + begin try Unix.mkdir "rpc_data" 0o755 with Unix.(Unix_error (EEXIST, _, _)) -> () end; |
| 89 | + ignore(C.has_vm_rrd ~vm_uuid:"abcde"); |
| 90 | + ignore(C.push_rrd_local ~vm_uuid:"abcde" ~domid:1); |
| 91 | + ignore(C.push_rrd_remote ~vm_uuid:"abcde" ~remote_address:"127.0.0.1"); |
| 92 | + ignore(C.remove_rrd ~uuid:"abcde"); |
| 93 | + ignore(C.migrate_rrd ~session_id:"session" ~remote_address:"127.0.0.1" ~vm_uuid:"abcde" ~host_uuid:"12345"); |
| 94 | + ignore(C.send_host_rrd_to_master ~master_address:"127.0.0.2"); |
| 95 | + ignore(C.backup_rrds ~remote_address:(Some "127.0.0.1") ()); |
| 96 | + ignore(C.archive_rrd ~vm_uuid:"abcde" ~remote_address:(Some "127.0.0.1")); |
| 97 | + ignore(C.archive_sr_rrd ~sr_uuid:"abcde"); |
| 98 | + ignore(C.push_sr_rrd ~sr_uuid:"abcde" ~path:"/foo"); |
| 99 | + ignore(C.add_host_ds ~ds_name:"ds"); |
| 100 | + ignore(C.forget_host_ds ~ds_name:"ds"); |
| 101 | + ignore(C.query_possible_host_dss ()); |
| 102 | + ignore(C.query_host_ds ~ds_name:"ds"); |
| 103 | + ignore(C.add_vm_ds ~vm_uuid:"abcde" ~domid:1 ~ds_name:"ds"); |
| 104 | + ignore(C.forget_vm_ds ~vm_uuid:"abcde" ~ds_name:"ds"); |
| 105 | + ignore(C.query_possible_vm_dss ~vm_uuid:"abcde"); |
| 106 | + ignore(C.query_vm_ds ~vm_uuid:"abcde" ~ds_name:"ds"); |
| 107 | + ignore(C.add_sr_ds ~sr_uuid:"abcde" ~ds_name:"ds"); |
| 108 | + ignore(C.forget_sr_ds ~sr_uuid:"abcde" ~ds_name:"ds"); |
| 109 | + ignore(C.query_possible_sr_dss ~sr_uuid:"abcde"); |
| 110 | + ignore(C.query_sr_ds ~sr_uuid:"abcde" ~ds_name:"ds"); |
| 111 | + ignore(C.update_use_min_max ~value:true); |
| 112 | + ignore(C.update_vm_memory_target ~domid:1 ~target:1L); |
| 113 | + ignore(C.set_cache_sr ~sr_uuid:"abcde"); |
| 114 | + ignore(C.unset_cache_sr ()); |
| 115 | + ignore(C.Plugin.get_header ()); |
| 116 | + ignore(C.Plugin.get_path ~uid:"uid"); |
| 117 | + ignore(C.Plugin.Local.register ~uid:"uid" ~info:Rrd.Five_Seconds ~protocol:Rrd_interface.V1); |
| 118 | + ignore(C.Plugin.Local.deregister ~uid:"uid"); |
| 119 | + ignore(C.Plugin.Local.next_reading ~uid:"uid"); |
| 120 | + ignore(C.Plugin.Interdomain.register ~uid:(Rrd_interface.{name="uid"; frontend_domid=1}) ~info:(Rrd_interface.{frequency=Rrd.Five_Seconds; shared_page_refs=[1]}) ~protocol:Rrd_interface.V1); |
| 121 | + ignore(C.Plugin.Interdomain.deregister ~uid:(Rrd_interface.{name="uid"; frontend_domid=1})); |
| 122 | + ignore(C.Plugin.Interdomain.next_reading ~uid:(Rrd_interface.{name="uid"; frontend_domid=1})); |
| 123 | + ignore(C.Plugin.register ~uid:"uid" ~frequency:Rrd.Five_Seconds); |
| 124 | + ignore(C.Plugin.deregister ~uid:"uid"); |
| 125 | + ignore(C.Plugin.next_reading ~uid:"uid"); |
| 126 | + ignore(C.HA.enable_and_update ~statefile_latencies:[{id="statefile_latency"; latency=Some 1.0}] ~heartbeat_latency:1.0 ~xapi_latency:1.0); |
| 127 | + ignore(C.HA.disable ()); |
| 128 | + ignore(C.Deprecated.load_rrd ~uuid:"abcde" ~timescale:1 ~master_address:(Some "127.0.0.1")) |
| 129 | + |
| 130 | +let dump_all () = |
| 131 | + run_all dumping_rpc |
| 132 | + |
| 133 | +let test_old_requests () = |
| 134 | + let all_requests = |
| 135 | + let dir = "test_data/rrd/requests" in |
| 136 | + Sys.readdir dir |> |
| 137 | + Array.to_list |> |
| 138 | + List.map (fun f -> read_str ("test_data/rrd/requests/" ^ f)) |
| 139 | + in |
| 140 | + List.iter (fun request -> |
| 141 | + let call = Xmlrpc.call_of_string request in |
| 142 | + let response = S.process () call in |
| 143 | + OUnit.assert_bool (Printf.sprintf "Result of '%s' successful" call.Rpc.name) (response.Rpc.success)) all_requests |
| 144 | + |
| 145 | +let test_old_responses () = |
| 146 | + let new_rpc call = |
| 147 | + let name = call.Rpc.name in |
| 148 | + Xmlrpc.response_of_string (read_str (Printf.sprintf "test_data/rrd/responses/%s.response" name)) |
| 149 | + in |
| 150 | + run_all new_rpc |
| 151 | + |
| 152 | +open OUnit |
| 153 | + |
| 154 | +let tests = |
| 155 | + "rrd_dump" >::: |
| 156 | + [ |
| 157 | + "Check interface works" >:: dump_all; |
| 158 | + "Test old requests" >:: test_old_requests; |
| 159 | + "Test old responses" >:: test_old_responses; |
| 160 | + ] |
0 commit comments