X-Git-Url: http://git.annexia.org/?p=libguestfs.git;a=blobdiff_plain;f=src%2Fgenerator.ml;h=08c28fc7c70785c0c204ae74faba38b45e91f6ae;hp=9d961703cb273ade09cf02f5c906ab5622941a70;hb=9c5f05ec14655195fc94dc7c72d132087abe634b;hpb=3a5a66de8f847a0ff11fdcf6c1644e19aa54c0f7 diff --git a/src/generator.ml b/src/generator.ml index 9d96170..08c28fc 100755 --- a/src/generator.ml +++ b/src/generator.ml @@ -139,6 +139,7 @@ and argt = | Dev_or_Path of string (* /dev device name or Pathname, cannot be NULL *) | OptString of string (* const char *name, may be NULL *) | StringList of string(* list of strings (each string cannot be NULL) *) + | DeviceList of string(* list of Device names (each cannot be NULL) *) | Bool of string (* boolean *) | Int of string (* int (smallish ints, signed, <= 31 bits) *) (* These are treated as filenames (simple string parameters) in @@ -342,6 +343,19 @@ and cmd = string list * Apart from that, long descriptions are just perldoc paragraphs. *) +(* Generate a random UUID (used in tests). *) +let uuidgen () = + let chan = Unix.open_process_in "uuidgen" in + let uuid = input_line chan in + (match Unix.close_process_in chan with + | Unix.WEXITED 0 -> () + | Unix.WEXITED _ -> + failwith "uuidgen: process exited with non-zero status" + | Unix.WSIGNALED _ | Unix.WSTOPPED _ -> + failwith "uuidgen: process signalled or stopped by signal" + ); + uuid + (* These test functions are used in the language binding tests. *) let test_all_args = [ @@ -856,7 +870,7 @@ Note that this function cannot correctly handle binary files as end of string). For those you need to use the C or C functions which have a more complex interface."); - ("ll", (RString "listing", [String "directory"]), 5, [], + ("ll", (RString "listing", [Pathname "directory"]), 5, [], [], (* XXX Tricky to test because it depends on the exact format * of the 'ls -l' command, which changes between F10 and F11. *) @@ -868,7 +882,7 @@ there is no cwd) in the format of 'ls -la'. This command is mostly useful for interactive sessions. It is I intended that you try to parse the output string."); - ("ls", (RStringList "listing", [String "directory"]), 6, [], + ("ls", (RStringList "listing", [Pathname "directory"]), 6, [], [InitBasicFS, Always, TestOutputList ( [["touch"; "/new"]; ["touch"; "/newer"]; @@ -1307,7 +1321,7 @@ This creates an LVM physical volume on the named C, where C should usually be a partition name such as C."); - ("vgcreate", (RErr, [String "volgroup"; StringList "physvols"]), 40, [], + ("vgcreate", (RErr, [String "volgroup"; DeviceList "physvols"]), 40, [], [InitEmpty, Always, TestOutputList ( [["sfdiskM"; "/dev/sda"; ",100 ,200 ,"]; ["pvcreate"; "/dev/sda1"]; @@ -1910,7 +1924,7 @@ I tar file) into C. To upload an uncompressed tarball, use C."); - ("tgz_out", (RErr, [String "directory"; FileOut "tarball"]), 72, [], + ("tgz_out", (RErr, [Pathname "directory"; FileOut "tarball"]), 72, [], [], "pack directory into compressed tarball", "\ @@ -2077,17 +2091,18 @@ This returns the ext2/3/4 filesystem label of the filesystem on C."); ("set_e2uuid", (RErr, [Device "device"; String "uuid"]), 82, [], - [InitBasicFS, Always, TestOutput ( - [["set_e2uuid"; "/dev/sda1"; "a3a61220-882b-4f61-89f4-cf24dcc7297d"]; - ["get_e2uuid"; "/dev/sda1"]], "a3a61220-882b-4f61-89f4-cf24dcc7297d"); - InitBasicFS, Always, TestOutput ( - [["set_e2uuid"; "/dev/sda1"; "clear"]; - ["get_e2uuid"; "/dev/sda1"]], ""); - (* We can't predict what UUIDs will be, so just check the commands run. *) - InitBasicFS, Always, TestRun ( - [["set_e2uuid"; "/dev/sda1"; "random"]]); - InitBasicFS, Always, TestRun ( - [["set_e2uuid"; "/dev/sda1"; "time"]])], + (let uuid = uuidgen () in + [InitBasicFS, Always, TestOutput ( + [["set_e2uuid"; "/dev/sda1"; uuid]; + ["get_e2uuid"; "/dev/sda1"]], uuid); + InitBasicFS, Always, TestOutput ( + [["set_e2uuid"; "/dev/sda1"; "clear"]; + ["get_e2uuid"; "/dev/sda1"]], ""); + (* We can't predict what UUIDs will be, so just check the commands run. *) + InitBasicFS, Always, TestRun ( + [["set_e2uuid"; "/dev/sda1"; "random"]]); + InitBasicFS, Always, TestRun ( + [["set_e2uuid"; "/dev/sda1"; "time"]])]), "set the ext2/3/4 filesystem UUID", "\ This sets the ext2/3/4 filesystem UUID of the filesystem on @@ -2170,7 +2185,7 @@ See also: C."); This command installs GRUB (the Grand Unified Bootloader) on C, with the root directory being C."); - ("cp", (RErr, [String "src"; String "dest"]), 87, [], + ("cp", (RErr, [Pathname "src"; Pathname "dest"]), 87, [], [InitBasicFS, Always, TestOutput ( [["write_file"; "/old"; "file content"; "0"]; ["cp"; "/old"; "/new"]; @@ -2189,7 +2204,7 @@ C, with the root directory being C."); This copies a file from C to C where C is either a destination filename or destination directory."); - ("cp_a", (RErr, [String "src"; String "dest"]), 88, [], + ("cp_a", (RErr, [Pathname "src"; Pathname "dest"]), 88, [], [InitBasicFS, Always, TestOutput ( [["mkdir"; "/olddir"]; ["mkdir"; "/newdir"]; @@ -2201,7 +2216,7 @@ either a destination filename or destination directory."); This copies a file or directory from C to C recursively using the C command."); - ("mv", (RErr, [String "src"; String "dest"]), 89, [], + ("mv", (RErr, [Pathname "src"; Pathname "dest"]), 89, [], [InitBasicFS, Always, TestOutput ( [["write_file"; "/old"; "file content"; "0"]; ["mv"; "/old"; "/new"]; @@ -2595,7 +2610,7 @@ more difficult. It is an interface to the L program. See that manual page for more details."); - ("scrub_file", (RErr, [String "file"]), 115, [], + ("scrub_file", (RErr, [Pathname "file"]), 115, [], [InitBasicFS, Always, TestRun ( [["write_file"; "/file"; "content"; "0"]; ["scrub_file"; "/file"]])], @@ -2609,7 +2624,7 @@ The file is I after scrubbing. It is an interface to the L program. See that manual page for more details."); - ("scrub_freespace", (RErr, [String "dir"]), 116, [], + ("scrub_freespace", (RErr, [Pathname "dir"]), 116, [], [], (* XXX needs testing *) "scrub (securely wipe) free space", "\ @@ -2776,7 +2791,7 @@ Old Linux kernels (2.4 and earlier) used a compressed ext2 filesystem as initrd. We I support the newer initramfs format (compressed cpio files)."); - ("mount_loop", (RErr, [String "file"; String "mountpoint"]), 129, [], + ("mount_loop", (RErr, [Pathname "file"; Pathname "mountpoint"]), 129, [], [], "mount a file using the loop device", "\ @@ -2805,9 +2820,10 @@ Note that you cannot attach a swap label to a block device a limitation of the kernel or swap tools."); ("mkswap_U", (RErr, [String "uuid"; Device "device"]), 132, [], - [InitEmpty, Always, TestRun ( - [["sfdiskM"; "/dev/sda"; ","]; - ["mkswap_U"; "a3a61220-882b-4f61-89f4-cf24dcc7297d"; "/dev/sda1"]])], + (let uuid = uuidgen () in + [InitEmpty, Always, TestRun ( + [["sfdiskM"; "/dev/sda"; ","]; + ["mkswap_U"; uuid; "/dev/sda1"]])]), "create a swap partition with an explicit UUID", "\ Create a swap partition on C with UUID C."); @@ -2882,7 +2898,7 @@ See also L, C, C. This call returns the previous umask."); - ("readdir", (RStructList ("entries", "dirent"), [String "dir"]), 138, [], + ("readdir", (RStructList ("entries", "dirent"), [Pathname "dir"]), 138, [], [], "read directories entries", "\ @@ -3278,7 +3294,7 @@ This command disables the libguestfs appliance swap device or partition named C. See C."); - ("swapon_file", (RErr, [String "file"]), 172, [], + ("swapon_file", (RErr, [Pathname "file"]), 172, [], [InitBasicFS, Always, TestRun ( [["fallocate"; "/swap"; "8388608"]; ["mkswap_file"; "/swap"]; @@ -3289,7 +3305,7 @@ See C."); This command enables swap to a file. See C for other notes."); - ("swapoff_file", (RErr, [String "file"]), 173, [], + ("swapoff_file", (RErr, [Pathname "file"]), 173, [], [], (* XXX tested by swapon_file *) "disable swap on file", "\ @@ -3316,10 +3332,11 @@ This command disables the libguestfs appliance swap on labeled swap partition."); ("swapon_uuid", (RErr, [String "uuid"]), 176, [], - [InitEmpty, Always, TestRun ( - [["mkswap_U"; "a3a61220-882b-4f61-89f4-cf24dcc7297d"; "/dev/sdb"]; - ["swapon_uuid"; "a3a61220-882b-4f61-89f4-cf24dcc7297d"]; - ["swapoff_uuid"; "a3a61220-882b-4f61-89f4-cf24dcc7297d"]])], + (let uuid = uuidgen () in + [InitEmpty, Always, TestRun ( + [["mkswap_U"; uuid; "/dev/sdb"]; + ["swapon_uuid"; uuid]; + ["swapoff_uuid"; uuid]])]), "enable swap on swap partition by UUID", "\ This command enables swap to a swap partition with the given UUID. @@ -3459,6 +3476,90 @@ This gets the SELinux security context of the daemon. See the documentation about SELINUX in L, and C"); + ("mkfs_b", (RErr, [String "fstype"; Int "blocksize"; Device "device"]), 187, [], + [InitEmpty, Always, TestOutput ( + [["sfdiskM"; "/dev/sda"; ","]; + ["mkfs_b"; "ext2"; "4096"; "/dev/sda1"]; + ["mount"; "/dev/sda1"; "/"]; + ["write_file"; "/new"; "new file contents"; "0"]; + ["cat"; "/new"]], "new file contents")], + "make a filesystem with block size", + "\ +This call is similar to C, but it allows you to +control the block size of the resulting filesystem. Supported +block sizes depend on the filesystem type, but typically they +are C<1024>, C<2048> or C<4096> only."); + + ("mke2journal", (RErr, [Int "blocksize"; Device "device"]), 188, [], + [InitEmpty, Always, TestOutput ( + [["sfdiskM"; "/dev/sda"; ",100 ,"]; + ["mke2journal"; "4096"; "/dev/sda1"]; + ["mke2fs_J"; "ext2"; "4096"; "/dev/sda2"; "/dev/sda1"]; + ["mount"; "/dev/sda2"; "/"]; + ["write_file"; "/new"; "new file contents"; "0"]; + ["cat"; "/new"]], "new file contents")], + "make ext2/3/4 external journal", + "\ +This creates an ext2 external journal on C. It is equivalent +to the command: + + mke2fs -O journal_dev -b blocksize device"); + + ("mke2journal_L", (RErr, [Int "blocksize"; String "label"; Device "device"]), 189, [], + [InitEmpty, Always, TestOutput ( + [["sfdiskM"; "/dev/sda"; ",100 ,"]; + ["mke2journal_L"; "4096"; "JOURNAL"; "/dev/sda1"]; + ["mke2fs_JL"; "ext2"; "4096"; "/dev/sda2"; "JOURNAL"]; + ["mount"; "/dev/sda2"; "/"]; + ["write_file"; "/new"; "new file contents"; "0"]; + ["cat"; "/new"]], "new file contents")], + "make ext2/3/4 external journal with label", + "\ +This creates an ext2 external journal on C with label C