Skip to content
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

CP-4102: xapi licensing changes #1080

Merged
merged 12 commits into from Mar 19, 2013
2 changes: 2 additions & 0 deletions ocaml/client_records/records.ml
Expand Up @@ -485,6 +485,8 @@ let pool_record rpc session_id pool =
~get_set:(fun () -> (x ()).API.pool_tags)
~add_to_set:(fun tag -> Client.Pool.add_tags rpc session_id pool tag)
~remove_from_set:(fun tag -> Client.Pool.remove_tags rpc session_id pool tag) ();
make_field ~name:"license-state"
~get:(fun () -> Record_util.s2sm_to_string "; " (Client.Pool.get_license_state rpc session_id pool)) ();
]}

let subject_record rpc session_id subject =
Expand Down
24 changes: 24 additions & 0 deletions ocaml/idl/datamodel.ml
Expand Up @@ -6164,6 +6164,28 @@ let pool_disable_local_storage_caching = call
~allowed_roles:_R_POOL_OP
()

let pool_get_license_state = call
~name:"get_license_state"
~in_oss_since:None
~in_product_since:rel_clearwater
~params:[Ref _pool, "self", "Reference to the pool"]
~doc:"This call returns the license state for the pool"
~allowed_roles:_R_READ_ONLY
~result:(Map(String,String), "The pool's license state")
()

let pool_apply_edition = call
~name:"apply_edition"
~in_oss_since:None
~in_product_since:rel_clearwater
~params:[
Ref _pool, "self", "Reference to the pool";
String, "edition", "The requested edition";
]
~doc:"Apply an edition to all hosts in the pool"
~allowed_roles:_R_POOL_OP
()

(** A pool class *)
let pool =
create_obj
Expand Down Expand Up @@ -6228,6 +6250,8 @@ let pool =
; pool_test_archive_target
; pool_enable_local_storage_caching
; pool_disable_local_storage_caching
; pool_get_license_state
; pool_apply_edition
]
~contents:
[uid ~in_oss_since:None _pool
Expand Down
2 changes: 2 additions & 0 deletions ocaml/test/OMakefile
Expand Up @@ -25,11 +25,13 @@ OCAML_LIBS = \
OCAML_OBJS = \
../idl/api_lowlevel \
mock \
test_highlevel \
test_common \
test_basic \
test_pool_db_backup \
test_xapi_db_upgrade \
test_ca91480 \
test_pr1510 \
test_pool_license \

OCamlProgram(suite, suite $(OCAML_OBJS) )
1 change: 1 addition & 0 deletions ocaml/test/suite.ml
Expand Up @@ -22,6 +22,7 @@ let base_suite =
Test_xapi_db_upgrade.test;
Test_ca91480.test;
Test_pr1510.suite;
Test_pool_license.test;
]

let _ = run_test_tt_main base_suite
20 changes: 20 additions & 0 deletions ocaml/test/test_common.ml
Expand Up @@ -83,3 +83,23 @@ let make_pif ~__context ~network ~host ?(device="eth0") ?(mAC="C0:FF:EE:C0:FF:EE
let make_network ~__context ?(name_label="net") ?(name_description="description") ?(mTU=1500L)
?(other_config=[]) ?(bridge="xenbr0") () =
Xapi_network.pool_introduce ~__context ~name_label ~name_description ~mTU ~other_config ~bridge

let make_pool ~__context ~master ?(name_label="") ?(name_description="")
?(default_SR=Ref.null) ?(suspend_image_SR=Ref.null) ?(crash_dump_SR=Ref.null)
?(ha_enabled=false) ?(ha_configuration=[]) ?(ha_statefiles=[])
?(ha_host_failures_to_tolerate=0L) ?(ha_plan_exists_for=0L)
?(ha_allow_overcommit=false) ?(ha_overcommitted=false) ?(blobs=[]) ?(tags=[])
?(gui_config=[]) ?(wlb_url="") ?(wlb_username="") ?(wlb_password=Ref.null)
?(wlb_enabled=false) ?(wlb_verify_cert=false) ?(redo_log_enabled=false)
?(redo_log_vdi=Ref.null) ?(vswitch_controller="") ?(restrictions=[])
?(other_config=[Xapi_globs.memory_ratio_hvm; Xapi_globs.memory_ratio_pv]) () =
let pool_ref = Ref.make () in
Db.Pool.create ~__context ~ref:pool_ref
~uuid:(Uuid.to_string (Uuid.make_uuid ())) ~name_label ~name_description
~master ~default_SR ~suspend_image_SR ~crash_dump_SR ~ha_enabled
~ha_configuration ~ha_statefiles ~ha_host_failures_to_tolerate
~ha_plan_exists_for ~ha_allow_overcommit ~ha_overcommitted ~blobs ~tags
~gui_config ~wlb_url ~wlb_username ~wlb_password ~wlb_enabled
~wlb_verify_cert ~redo_log_enabled ~redo_log_vdi ~vswitch_controller
~restrictions ~other_config;
pool_ref
101 changes: 101 additions & 0 deletions ocaml/test/test_highlevel.ml
@@ -0,0 +1,101 @@
(*
* Copyright (C) 2006-2013 Citrix Systems Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation; version 2.1 only. with the special
* exception on linking described in file LICENSE.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*)

(* This framework should be useful if you want to apply lots of different
* inputs to a function or system, and check that the output is correct in
* each case.
*
* The basic idea is to either:
*
* 1. Create a module of type STATELESS_TEST or
* 2. Create a module of type STATEFUL_TEST and turn it into a STATELESS_TEST
* with the EncapsulateState functor
*
* and then pass the STATELESS_TEST into the Make functor.
*
* This gives you a module with the functions test_equal and
* test_equal_multiple, which take an input-output pair or a list of
* input-output pairs and check that the output of the system is as expected
* for each input.
*)

open OUnit

module Generic = struct
module type IO = sig
(* The type of inputs to a system being tested. *)
type input_t
(* The type of outputs from a system being tested. *)
type output_t

(* Helper functions for printing error messages on test failure. *)
val string_of_input_t : input_t -> string
val string_of_output_t : output_t -> string
end

module type STATE = sig
(* The type of system state, which will be modified by inputs to the system. *)
type state_t
(* Create a base system state. *)
val create_default_state : unit -> state_t
end

module type STATELESS_TEST = sig
module Io : IO
(* A function to transform an input into an output. *)
val transform : Io.input_t -> Io.output_t
end

module type STATEFUL_TEST = sig
module Io : IO
module State : STATE
(* A function to apply an input to the system state. *)
val load_input : State.state_t -> Io.input_t -> unit
(* A function to extract an output from the system state. *)
val extract_output : State.state_t -> Io.output_t
end

(* Turn a stateful test module into a stateless test module. *)
module EncapsulateState(T: STATEFUL_TEST) = struct
module Io = T.Io

let transform input =
let state = T.State.create_default_state () in
T.load_input state input;
T.extract_output state
end

(* Create functions which will actually run a test or tests. *)
module Make(T: STATELESS_TEST) = struct
let test_equal ~input ~expected_output =
let actual_output = T.transform input in
assert_equal
~msg:(Printf.sprintf
"Failure: input = %s, output = %s, expected output = %s"
(T.Io.string_of_input_t input)
(T.Io.string_of_output_t actual_output)
(T.Io.string_of_output_t expected_output))
actual_output expected_output

let test_equal_multiple ~input_output_pairs =
List.iter
(fun (input, expected_output) -> test_equal ~input ~expected_output)
input_output_pairs
end
end

module XapiDb : Generic.STATE with type state_t = Context.t = struct
type state_t = Context.t
let create_default_state () = Mock.make_context_with_new_db "test context"
end