Skip to content

Commit 83637a9

Browse files
committed
Merge pull request #101 from xapi-project/run-without-root
Fix travis
2 parents 05847ee + 348e93a commit 83637a9

File tree

5 files changed

+21
-9
lines changed

5 files changed

+21
-9
lines changed

.travis.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ eval `opam config env`
55
export BISECT_FILE=_build/xenvm.coverage
66
# Needed to support Unix domain sockets:
77
sudo opam pin add conduit git://github.com/mirage/ocaml-conduit -y
8-
sudo make test
8+
make test
99

1010
echo Generating bisect report-- this fails on travis
1111
(cd _build; bisect-report xenvm*.out -summary-only -html /vagrant/report/ || echo Ignoring bisect-report failure)

.travis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
language: c
22
install: wget https://raw.githubusercontent.com/ocaml/ocaml-travisci-skeleton/master/.travis-opam.sh
33
script: cp .travis.oasis _oasis && bash -ex .travis-opam.sh && bash -ex .travis.sh
4+
sudo: true
45
env:
5-
- OCAML_VERSION=4.02 PACKAGE=thin_lvhd_tools EXTRA_REMOTES="git://github.com/xapi-project/thin-lvhd-opam-repo"
6-
sudo: required
6+
- 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"

test/common.ml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ open Lvm
1717
open Vg
1818
open Lwt
1919

20+
(* Mock kernel devices so we can run as a regular user *)
21+
let use_mock = ref true
22+
2023
module Log = struct
2124
let debug fmt = Printf.ksprintf (fun s -> print_endline s) fmt
2225
let info fmt = Printf.ksprintf (fun s -> print_endline s) fmt
@@ -227,7 +230,7 @@ let with_temp_file fn =
227230
result
228231
(* NB we leak the file on error, but this is quite useful *)
229232

230-
let with_loop_device path f =
233+
let with_loop_device path f = if !use_mock then f path else begin
231234
ignore_string (run "losetup" [ "-f"; path ]);
232235
(* /dev/loop0: [fd00]:1973802 (/tmp/SR.createc04251volume) *)
233236
let line = run "losetup" [ "-j"; path ] in
@@ -241,6 +244,7 @@ let with_loop_device path f =
241244
error "Failed to parse output of losetup -j: [%s]" line;
242245
ignore_string (run "losetup" [ "-d"; path ]);
243246
failwith (Printf.sprintf "Failed to parse output of losetup -j: [%s]" line)
247+
end
244248

245249
let with_block filename f =
246250
let open Lwt in
@@ -251,5 +255,9 @@ let with_block filename f =
251255
| `Ok x ->
252256
f x (* no point catching errors here *)
253257

254-
let xenvm = run "./xenvm.native"
258+
let xenvm = function
259+
| [] -> run "./xenvm.native" []
260+
| cmd :: args ->
261+
let args = if !use_mock then "--mock-devmapper" :: "--configdir" :: "/tmp/xenvm.d" :: args else args in
262+
run "./xenvm.native" (cmd :: args)
255263
let xenvmd = run "./xenvmd.native"

test/test.ml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ let vgs_offline =
4141
(fun () ->
4242
with_temp_file (fun filename ->
4343
xenvm [ "vgcreate"; vg; filename ] |> ignore_string;
44-
mkdir_rec "/etc/xenvm.d" 0o0644;
44+
mkdir_rec "/tmp/xenvm.d" 0o0755;
4545
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;
4646
xenvm [ "vgs"; vg ] |> ignore_string
4747
)
@@ -118,13 +118,17 @@ let lvchange_n =
118118
let vg_metadata, lv_metadata = Lwt_main.run (Client.get_lv "test") in
119119
let name = Mapper.name_of vg_metadata lv_metadata in
120120
xenvm [ "lvchange"; "-ay"; "/dev/" ^ vg ^ "/test" ] |> ignore_string;
121+
if not !Common.use_mock then begin (* FIXME: #99 *)
121122
assert_equal ~printer:string_of_bool true (file_exists (dev_path_of "test"));
122123
assert_equal ~printer:string_of_bool true (file_exists (mapper_path_of "test"));
123124
assert_equal ~printer:string_of_bool true (dm_exists name);
125+
end;
124126
xenvm [ "lvchange"; "-an"; "/dev/" ^ vg ^ "/test" ] |> ignore_string;
127+
if not !Common.use_mock then begin (* FIXME: #99 *)
125128
assert_equal ~printer:string_of_bool false (file_exists (dev_path_of"test"));
126129
assert_equal ~printer:string_of_bool false (file_exists (mapper_path_of"test"));
127130
assert_equal ~printer:string_of_bool false (dm_exists name);
131+
end;
128132
xenvm [ "lvremove"; vg ^ "/test" ] |> ignore_string
129133

130134
let parse_int x =
@@ -155,11 +159,11 @@ let xenvmd_suite = "Commands which require xenvmd" >::: [
155159
]
156160

157161
let _ =
162+
mkdir_rec "/tmp/xenvm.d" 0o0755;
158163
run_test_tt_main no_xenvmd_suite |> ignore;
159164
with_temp_file (fun filename' ->
160165
with_loop_device filename' (fun loop ->
161166
xenvm [ "vgcreate"; vg; loop ] |> ignore_string;
162-
mkdir_rec "/etc/xenvm.d" 0o0644;
163167
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;
164168
file_of_string "test.xenvmd.conf" ("( (listenPort ()) (listenPath (Some \"/tmp/xenvmd\")) (host_allocation_quantum 128) (host_low_water_mark 8) (vg "^vg^") (devices ("^loop^")))");
165169
xenvmd [ "--config"; "./test.xenvmd.conf"; "--daemon" ] |> ignore_string;

xenvm/vgcreate.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ open Lwt
33
open Xenvm_common
44
open Errors
55

6-
let vgcreate vg_name devices =
6+
let vgcreate _ vg_name devices =
77
let open Lvm in
88
let t =
99
let module Vg_IO = Vg.Make(Log)(Block)(Time)(Clock) in
@@ -61,5 +61,5 @@ let vgcreate_cmd =
6161
`S "DESCRIPTION";
6262
`P "vgcreate creates a volume group on the specified physical block devices";
6363
] in
64-
Term.(pure vgcreate $ vg_name_arg $ devices_arg),
64+
Term.(pure vgcreate $ Xenvm_common.copts_t $ vg_name_arg $ devices_arg),
6565
Term.info "vgcreate" ~sdocs:copts_sect ~doc ~man

0 commit comments

Comments
 (0)