diff --git a/.travis.sh b/.travis.sh index 6becd44..338ad72 100755 --- a/.travis.sh +++ b/.travis.sh @@ -5,7 +5,7 @@ eval `opam config env` export BISECT_FILE=_build/xenvm.coverage # Needed to support Unix domain sockets: sudo opam pin add conduit git://github.com/mirage/ocaml-conduit -y -sudo make test +make test echo Generating bisect report-- this fails on travis (cd _build; bisect-report xenvm*.out -summary-only -html /vagrant/report/ || echo Ignoring bisect-report failure) diff --git a/.travis.yml b/.travis.yml index 8e7e0fb..e864854 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,6 @@ language: c install: wget https://raw.githubusercontent.com/ocaml/ocaml-travisci-skeleton/master/.travis-opam.sh script: cp .travis.oasis _oasis && bash -ex .travis-opam.sh && bash -ex .travis.sh +sudo: true env: - - OCAML_VERSION=4.02 PACKAGE=thin_lvhd_tools EXTRA_REMOTES="git://github.com/xapi-project/thin-lvhd-opam-repo" -sudo: required + - OCAML_VERSION=4.02 PACKAGE=thin_lvhd_tools EXTRA_REMOTES="git://github.com/xapi-project/thin-lvhd-opam-repo" TESTS=true PINS="conduit:git://github.com/mirage/ocaml-conduit" diff --git a/test/common.ml b/test/common.ml index e2fd45b..5c939c0 100644 --- a/test/common.ml +++ b/test/common.ml @@ -17,6 +17,9 @@ open Lvm open Vg open Lwt +(* Mock kernel devices so we can run as a regular user *) +let use_mock = ref true + module Log = struct let debug fmt = Printf.ksprintf (fun s -> print_endline s) fmt let info fmt = Printf.ksprintf (fun s -> print_endline s) fmt @@ -227,7 +230,7 @@ let with_temp_file fn = result (* NB we leak the file on error, but this is quite useful *) -let with_loop_device path f = +let with_loop_device path f = if !use_mock then f path else begin ignore_string (run "losetup" [ "-f"; path ]); (* /dev/loop0: [fd00]:1973802 (/tmp/SR.createc04251volume) *) let line = run "losetup" [ "-j"; path ] in @@ -241,6 +244,7 @@ let with_loop_device path f = error "Failed to parse output of losetup -j: [%s]" line; ignore_string (run "losetup" [ "-d"; path ]); failwith (Printf.sprintf "Failed to parse output of losetup -j: [%s]" line) +end let with_block filename f = let open Lwt in @@ -251,5 +255,9 @@ let with_block filename f = | `Ok x -> f x (* no point catching errors here *) -let xenvm = run "./xenvm.native" +let xenvm = function + | [] -> run "./xenvm.native" [] + | cmd :: args -> + let args = if !use_mock then "--mock-devmapper" :: "--configdir" :: "/tmp/xenvm.d" :: args else args in + run "./xenvm.native" (cmd :: args) let xenvmd = run "./xenvmd.native" diff --git a/test/test.ml b/test/test.ml index dbda008..0dc9b87 100644 --- a/test/test.ml +++ b/test/test.ml @@ -41,7 +41,7 @@ let vgs_offline = (fun () -> with_temp_file (fun filename -> xenvm [ "vgcreate"; vg; filename ] |> ignore_string; - mkdir_rec "/etc/xenvm.d" 0o0644; + mkdir_rec "/tmp/xenvm.d" 0o0755; xenvm [ "set-vg-info"; "--pvpath"; filename; "-S"; "/tmp/xenvmd"; vg; "--local-allocator-path"; "/tmp/xenvm-local-allocator"; "--uri"; "file://local/services/xenvmd/"^vg ] |> ignore_string; xenvm [ "vgs"; vg ] |> ignore_string ) @@ -118,13 +118,17 @@ let lvchange_n = let vg_metadata, lv_metadata = Lwt_main.run (Client.get_lv "test") in let name = Mapper.name_of vg_metadata lv_metadata in xenvm [ "lvchange"; "-ay"; "/dev/" ^ vg ^ "/test" ] |> ignore_string; + if not !Common.use_mock then begin (* FIXME: #99 *) assert_equal ~printer:string_of_bool true (file_exists (dev_path_of "test")); assert_equal ~printer:string_of_bool true (file_exists (mapper_path_of "test")); assert_equal ~printer:string_of_bool true (dm_exists name); + end; xenvm [ "lvchange"; "-an"; "/dev/" ^ vg ^ "/test" ] |> ignore_string; + if not !Common.use_mock then begin (* FIXME: #99 *) assert_equal ~printer:string_of_bool false (file_exists (dev_path_of"test")); assert_equal ~printer:string_of_bool false (file_exists (mapper_path_of"test")); assert_equal ~printer:string_of_bool false (dm_exists name); + end; xenvm [ "lvremove"; vg ^ "/test" ] |> ignore_string let parse_int x = @@ -155,11 +159,11 @@ let xenvmd_suite = "Commands which require xenvmd" >::: [ ] let _ = + mkdir_rec "/tmp/xenvm.d" 0o0755; run_test_tt_main no_xenvmd_suite |> ignore; with_temp_file (fun filename' -> with_loop_device filename' (fun loop -> xenvm [ "vgcreate"; vg; loop ] |> ignore_string; - mkdir_rec "/etc/xenvm.d" 0o0644; xenvm [ "set-vg-info"; "--pvpath"; loop; "-S"; "/tmp/xenvmd"; vg; "--local-allocator-path"; "/tmp/xenvm-local-allocator"; "--uri"; "file://local/services/xenvmd/"^vg ] |> ignore_string; file_of_string "test.xenvmd.conf" ("( (listenPort ()) (listenPath (Some \"/tmp/xenvmd\")) (host_allocation_quantum 128) (host_low_water_mark 8) (vg "^vg^") (devices ("^loop^")))"); xenvmd [ "--config"; "./test.xenvmd.conf"; "--daemon" ] |> ignore_string; diff --git a/xenvm/vgcreate.ml b/xenvm/vgcreate.ml index a6159fa..b5643f4 100644 --- a/xenvm/vgcreate.ml +++ b/xenvm/vgcreate.ml @@ -3,7 +3,7 @@ open Lwt open Xenvm_common open Errors -let vgcreate vg_name devices = +let vgcreate _ vg_name devices = let open Lvm in let t = let module Vg_IO = Vg.Make(Log)(Block)(Time)(Clock) in @@ -61,5 +61,5 @@ let vgcreate_cmd = `S "DESCRIPTION"; `P "vgcreate creates a volume group on the specified physical block devices"; ] in - Term.(pure vgcreate $ vg_name_arg $ devices_arg), + Term.(pure vgcreate $ Xenvm_common.copts_t $ vg_name_arg $ devices_arg), Term.info "vgcreate" ~sdocs:copts_sect ~doc ~man