From f1e9917c175412582a70f44942cde69c3d66f524 Mon Sep 17 00:00:00 2001 From: David Scott Date: Tue, 26 May 2015 09:35:27 +0000 Subject: [PATCH 01/11] xenvm vgcreate: add common arguments In particular this allows us to understand --mock-devmapper, even though we don't need it yet. Signed-off-by: David Scott --- xenvm/vgcreate.ml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 From 998d41ebde2fa5e9ceafb47c7a76e38159a73065 Mon Sep 17 00:00:00 2001 From: David Scott Date: Tue, 26 May 2015 09:35:57 +0000 Subject: [PATCH 02/11] test: set "--mock-devmapper" based on a global variable This will allow the tests to run without root (e.g. on travis) but also as root with the real device mapper. Signed-off-by: David Scott --- test/common.ml | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/test/common.ml b/test/common.ml index e2fd45b..86a6df5 100644 --- a/test/common.ml +++ b/test/common.ml @@ -17,6 +17,9 @@ open Lvm open Vg open Lwt +(* Use the --mock-devmapper argument. This allows us to run on travis. *) +let mock_devmapper = 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 @@ -251,5 +254,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 !mock_devmapper then "--mock-devmapper" :: args else args in + run "./xenvm.native" (cmd :: args) let xenvmd = run "./xenvmd.native" From 5c6e3b3c9c674559846fd46741c93e2864eb69e2 Mon Sep 17 00:00:00 2001 From: David Scott Date: Tue, 26 May 2015 10:53:12 +0000 Subject: [PATCH 03/11] test: only create loop devices if we're not in mock mode Signed-off-by: David Scott --- test/common.ml | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/test/common.ml b/test/common.ml index 86a6df5..5c939c0 100644 --- a/test/common.ml +++ b/test/common.ml @@ -17,8 +17,8 @@ open Lvm open Vg open Lwt -(* Use the --mock-devmapper argument. This allows us to run on travis. *) -let mock_devmapper = ref true +(* 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 @@ -230,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 @@ -244,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 @@ -257,6 +258,6 @@ let with_block filename f = let xenvm = function | [] -> run "./xenvm.native" [] | cmd :: args -> - let args = if !mock_devmapper then "--mock-devmapper" :: args else args in + 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" From 586c06f83f06b051bc4e5cb4aaf76e1f29448ac7 Mon Sep 17 00:00:00 2001 From: David Scott Date: Tue, 26 May 2015 10:53:34 +0000 Subject: [PATCH 04/11] test: place our config in /tmp/xenvm.d Obviously /etc/xenvm.d is only for root. Signed-off-by: David Scott --- test/test.ml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/test.ml b/test/test.ml index dbda008..dcfce99 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 ) @@ -159,7 +159,7 @@ let _ = with_temp_file (fun filename' -> with_loop_device filename' (fun loop -> xenvm [ "vgcreate"; vg; loop ] |> ignore_string; - mkdir_rec "/etc/xenvm.d" 0o0644; + mkdir_rec "/tmp/xenvm.d" 0o0755; 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; From b7a441fc90f30179640b37f188b5d10d5e27ba34 Mon Sep 17 00:00:00 2001 From: David Scott Date: Tue, 26 May 2015 10:54:29 +0000 Subject: [PATCH 05/11] test: don't look for real device mapper nodes in mock mode Fixing this properly needs #99 Signed-off-by: David Scott --- test/test.ml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test/test.ml b/test/test.ml index dcfce99..d67d4a5 100644 --- a/test/test.ml +++ b/test/test.ml @@ -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 = From 86958154c2eac1caa2322223eb61474caeb1190d Mon Sep 17 00:00:00 2001 From: David Scott Date: Tue, 26 May 2015 10:59:27 +0000 Subject: [PATCH 06/11] travis: use new docker configuration based on cuekeeper Signed-off-by: David Scott --- .travis-post-install.sh | 5 +++++ .travis.yml | 21 ++++++++++++++++++--- 2 files changed, 23 insertions(+), 3 deletions(-) create mode 100644 .travis-post-install.sh diff --git a/.travis-post-install.sh b/.travis-post-install.sh new file mode 100644 index 0000000..ea0f5bf --- /dev/null +++ b/.travis-post-install.sh @@ -0,0 +1,5 @@ +ocamlfind list +opam list +make clean +make +make test diff --git a/.travis.yml b/.travis.yml index 8e7e0fb..14d4476 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,21 @@ 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 +script: bash -ex .travis-opam.sh +sudo: false +addons: + apt: + sources: + - avsm + packages: + - ocaml + - ocaml-base + - ocaml-native-compilers + - ocaml-compiler-libs + - ocaml-interp + - ocaml-base-nox + - ocaml-nox + - camlp4 + - camlp4-extra + - libdevmapper-dev env: - - OCAML_VERSION=4.02 PACKAGE=thin_lvhd_tools EXTRA_REMOTES="git://github.com/xapi-project/thin-lvhd-opam-repo" -sudo: required + - FORK_USER=talex5 FORK_BRANCH=containers OPAMYES=true 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/conduit" EXTRA_REMOTES="git://github.com/xapi-project/opam-repo-dev" POST_INSTALL_HOOK="bash -eux .travis-post-install.sh" From 26b6ad1b5f8f9663c969ee5a851863ad0065b187 Mon Sep 17 00:00:00 2001 From: David Scott Date: Tue, 26 May 2015 11:03:51 +0000 Subject: [PATCH 07/11] travis: it's ocaml-conduit, not conduit Signed-off-by: David Scott --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 14d4476..6ad4db1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -18,4 +18,4 @@ addons: - camlp4-extra - libdevmapper-dev env: - - FORK_USER=talex5 FORK_BRANCH=containers OPAMYES=true 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/conduit" EXTRA_REMOTES="git://github.com/xapi-project/opam-repo-dev" POST_INSTALL_HOOK="bash -eux .travis-post-install.sh" + - FORK_USER=talex5 FORK_BRANCH=containers OPAMYES=true 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" EXTRA_REMOTES="git://github.com/xapi-project/opam-repo-dev" POST_INSTALL_HOOK="bash -eux .travis-post-install.sh" From 8afa0fb45ec60abe962a577ed83fe76a5bea4ea0 Mon Sep 17 00:00:00 2001 From: David Scott Date: Tue, 26 May 2015 11:06:57 +0000 Subject: [PATCH 08/11] travis: use only one EXTRA_REMOTES Signed-off-by: David Scott --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 6ad4db1..2b485f1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -18,4 +18,4 @@ addons: - camlp4-extra - libdevmapper-dev env: - - FORK_USER=talex5 FORK_BRANCH=containers OPAMYES=true 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" EXTRA_REMOTES="git://github.com/xapi-project/opam-repo-dev" POST_INSTALL_HOOK="bash -eux .travis-post-install.sh" + - FORK_USER=talex5 FORK_BRANCH=containers OPAMYES=true 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" POST_INSTALL_HOOK="bash -eux .travis-post-install.sh" From 66a2c7db58c00fd27815026f0ce14924490dc571 Mon Sep 17 00:00:00 2001 From: David Scott Date: Tue, 26 May 2015 11:44:25 +0000 Subject: [PATCH 09/11] travis: switch back to requiring sudo For the moment camldm does require -ldevmapper (not whitelisted on travis) Signed-off-by: David Scott --- .travis-post-install.sh | 5 ----- .travis.yml | 21 +++------------------ 2 files changed, 3 insertions(+), 23 deletions(-) delete mode 100644 .travis-post-install.sh diff --git a/.travis-post-install.sh b/.travis-post-install.sh deleted file mode 100644 index ea0f5bf..0000000 --- a/.travis-post-install.sh +++ /dev/null @@ -1,5 +0,0 @@ -ocamlfind list -opam list -make clean -make -make test diff --git a/.travis.yml b/.travis.yml index 2b485f1..e864854 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,21 +1,6 @@ language: c install: wget https://raw.githubusercontent.com/ocaml/ocaml-travisci-skeleton/master/.travis-opam.sh -script: bash -ex .travis-opam.sh -sudo: false -addons: - apt: - sources: - - avsm - packages: - - ocaml - - ocaml-base - - ocaml-native-compilers - - ocaml-compiler-libs - - ocaml-interp - - ocaml-base-nox - - ocaml-nox - - camlp4 - - camlp4-extra - - libdevmapper-dev +script: cp .travis.oasis _oasis && bash -ex .travis-opam.sh && bash -ex .travis.sh +sudo: true env: - - FORK_USER=talex5 FORK_BRANCH=containers OPAMYES=true 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" POST_INSTALL_HOOK="bash -eux .travis-post-install.sh" + - 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" From e23f67cbe7e9b14f43cc4565fdf21d02c775a3a7 Mon Sep 17 00:00:00 2001 From: David Scott Date: Tue, 26 May 2015 11:55:05 +0000 Subject: [PATCH 10/11] travis: 'make test' doesn't need sudo Signed-off-by: David Scott --- .travis.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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) From 348e93a286a2c207e5b63379063440812c6d82c4 Mon Sep 17 00:00:00 2001 From: David Scott Date: Tue, 26 May 2015 13:07:15 +0000 Subject: [PATCH 11/11] test: create /tmp/xenvm.d at the beginning Signed-off-by: David Scott --- test/test.ml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test.ml b/test/test.ml index d67d4a5..0dc9b87 100644 --- a/test/test.ml +++ b/test/test.ml @@ -159,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 "/tmp/xenvm.d" 0o0755; 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;