From 1a341151a44137d776ce713c5334e58db96803b5 Mon Sep 17 00:00:00 2001 From: Richard W.M. Jones Date: Jan 12 2014 18:19:48 +0000 Subject: Backport more virt-builder patches from upstream to Fedora. --- diff --git a/0039-builder-Add-CirrOS-0.3.1-disk-image.patch b/0039-builder-Add-CirrOS-0.3.1-disk-image.patch new file mode 100644 index 0000000..e130b95 --- /dev/null +++ b/0039-builder-Add-CirrOS-0.3.1-disk-image.patch @@ -0,0 +1,133 @@ +From 406ee778aab64122ef55c27568671fc16e5259b4 Mon Sep 17 00:00:00 2001 +From: "Richard W.M. Jones" +Date: Sat, 4 Jan 2014 12:37:40 +0000 +Subject: [PATCH] builder: Add CirrOS 0.3.1 disk image. + +(cherry picked from commit 40b88fdbc76515fd21b33f54587c7f4f7b6e9715) +--- + builder/website/cirros-0.3.1.xz.sig | 17 ++++++++++++++ + builder/website/index | 19 +++++++++++++++ + builder/website/index.asc | 47 ++++++++++++++++++++++++++----------- + 3 files changed, 69 insertions(+), 14 deletions(-) + create mode 100644 builder/website/cirros-0.3.1.xz.sig + +diff --git a/builder/website/cirros-0.3.1.xz.sig b/builder/website/cirros-0.3.1.xz.sig +new file mode 100644 +index 0000000..973d86c +--- /dev/null ++++ b/builder/website/cirros-0.3.1.xz.sig +@@ -0,0 +1,17 @@ ++-----BEGIN PGP SIGNATURE----- ++Version: GnuPG v1 ++ ++iQIcBAABAgAGBQJSx//LAAoJEJFzj3Pht2igtekP/11RH1POvryBWsmtjgwviPJV ++P8eIGuUBy38BYbEO0jBWTsT6CAfwOCtyUUMWCBPJ3meoRd4C5AGWHUS5F6z6fZWq ++Qo+LU1BfPWDa3TMXP9TybexUCI6cIBMlbzbwkSE/fR2JDwl3K58ZWUrI1rxfKKNJ ++CM8rcpLVVP19sAiurndqiIU43bEOS7UwKhBYr1LtNQndpaDH2l+9XnC/HlOrAKgR ++H/X9GgscJ43MtA3VPY140RKgZ716c/zznd2yLXrXIJ9JJ9DsoPsooZ6cZSoxDl2E ++Y16lnQyAcDySPY+NZluQ6xvtk4JiDWxLFqdXMksRtUb14D91bJ2okhjtztg5yuLh ++tC1aNiwcZaDynjXec4SnB+06oPZGstO6uPotasb9sBH/Prm1mv1A4jLwwMTOjSLT ++svZ2/xy83lZqBBwU2oFTiSL+hSS3zTm8X0JaInZJPXlgDOTrdKb7UlzVEJ6SqOZo ++4omjaYnHWIe9H2SPxCH/7/DC9WW1K9fuxkIEjvqbxTC3n/6WziK2Aq2k5s1Aq0Yy ++Z0am0Xhi169V8s8BaLFWiHGi/VlCd81/q2bg+3qCZcWE4zonEZDZSNrL1FtDtHRj ++Cgzo0su2LYHhdt0+2QYnAfUJN7Q5kGA1apWrmVI2cvvDpx0eHsFKLcdJnzOntabv ++fI+rI2o+Lhp1DW7ywVzl ++=KKLo ++-----END PGP SIGNATURE----- +diff --git a/builder/website/index b/builder/website/index +index 648d890..32cc402 100644 +--- a/builder/website/index ++++ b/builder/website/index +@@ -21,6 +21,25 @@ notes=CentOS 6.5 + Note that `virt-builder centos-6' will always install the latest + 6.x release. + ++[cirros-0.3.1] ++name=CirrOS 0.3.1 ++file=cirros-0.3.1.xz ++sig=cirros-0.3.1.xz.sig ++checksum=096209f00eb62d5722accf3d22ca3a4ee5baaac6d7d4ce0be93b56bbd1c8ab2e3eb4f5db1deffcb570e2c3d41f4d721798a1c499675346cee9546554a4b10388 ++format=raw ++size=41126400 ++compressed_size=11419004 ++expand=/dev/sda1 ++notes=CirrOS 0.3.1 ++ ++ CirrOS is a commonly used test image, ideal because it is very ++ small and boots into a minimally usable Linux system. ++ ++ Note this is not a real Linux distribution, and several virt-builder ++ features such as installing packages will not (and cannot) work. ++ ++ This CirrOS image comes from https://launchpad.net/cirros ++ + [debian-6] + name=Debian 6 (Squeeze) + osinfo=debian6 +diff --git a/builder/website/index.asc b/builder/website/index.asc +index c826d4a..b2291ca 100644 +--- a/builder/website/index.asc ++++ b/builder/website/index.asc +@@ -24,6 +24,25 @@ notes=CentOS 6.5 + Note that `virt-builder centos-6' will always install the latest + 6.x release. + ++[cirros-0.3.1] ++name=CirrOS 0.3.1 ++file=cirros-0.3.1.xz ++sig=cirros-0.3.1.xz.sig ++checksum=096209f00eb62d5722accf3d22ca3a4ee5baaac6d7d4ce0be93b56bbd1c8ab2e3eb4f5db1deffcb570e2c3d41f4d721798a1c499675346cee9546554a4b10388 ++format=raw ++size=41126400 ++compressed_size=11419004 ++expand=/dev/sda1 ++notes=CirrOS 0.3.1 ++ ++ CirrOS is a commonly used test image, ideal because it is very ++ small and boots into a minimally usable Linux system. ++ ++ Note this is not a real Linux distribution, and several virt-builder ++ features such as installing packages will not (and cannot) work. ++ ++ This CirrOS image comes from https://launchpad.net/cirros ++ + [debian-6] + name=Debian 6 (Squeeze) + osinfo=debian6 +@@ -252,19 +271,19 @@ notes=Ubuntu 13.10 (Saucy). + + --firstboot-command "dpkg-reconfigure openssh-server" + -----BEGIN PGP SIGNATURE----- +-Version: GnuPG v1.4.15 (GNU/Linux) ++Version: GnuPG v1 + +-iQIcBAEBAgAGBQJSsHIWAAoJEJFzj3Pht2igj4YQAJldrmQcSGYQkewurpJXd6IX +-+HVUPZPLSc1w5Wdba7+ayYisUGpcXbdYlsNIEgO3W503YDT7HhsfVJojlY2PiBrl +-d1oMpFxupDYfcLllFhaVvgqqT3gK/xVCOyNhzZjWhC4vJrJjfJDFrkh8f6I0xNeI +-gzU3nwJ5aB8Ip9MG0oJqaRtL8b2wvMcdpv2BkIQCScCHPNIr8G5XYHbj+8ur2rlq +-7I1Q4p5P0S0+uBUHA4vQt+lNi3DuXJjfrqZTSkYtMmMxtbfH+ReswN3NfPaU2iVW +-BiUmGn8mMmLndOnfYF1mDdzByznSYQBfmQEJVrrUZQtL8jUjeEOfVURMIxd6iuly +-COU1eJ53qTuYZV/PuHJgFS1BV03icT2I/Yk7WowWsbIWZgqKhEf8HpskZh7UoSqD +-LSxYdqV8cYnKjXqL2WLk+2/V0Nul5ceIYO6fGHjz/EuS4T7vjyMC+DaoItLuC1IR +-55P7Xksw0hLXKPmOkfPObStPfBG/+lZyOaf1OjC/yFfCUc054kvL1Q0QXMBXuw1R +-e3Suc2CVSDp3AWSJi4a7kSH1GqyMfFF6FSuSd3Vbp3MC2N/iHk/PIs1uR/ogO0oR +-4ESXH30RJBfDa00LkoNabBs97AqmYrh8lqIi0XqEiJvJaeR/LR5uLyVpbynvU3r4 +-LCE8XQ8F06ZKkg8JBksF +-=15Z8 ++iQIcBAEBAgAGBQJSx/+uAAoJEJFzj3Pht2igUzQP/2ssVh9l6TL7vd9z13rbernd ++fsxcTwV/2Vpv2qUVbxuCOZj1uFxkRb+CVk6kRaLKrGYH/bNROJitn6FieHM7lf09 ++0vd/vEj7Ie9pATxMzFoEy+M8sSJAXTVH2k8OjGhpOuevSswb/JQx23L/KdGa/ERu ++X9ZRpsNTaJ/xDOx9tZt/YbWP/SesF8G/LWFG30ULRH8S5jqPUb/DS2k1sgZjCeUk ++kawf7/kLzPTuH51YpjZGHDgCIOoyRQORtZDmcaMWFcEVyvoyvMMnK0vsq7mvzvhO ++FYqq+32TadS9cLC1O0R6rQxQALmFMuZCd/O2XO6E8mMMeLHS7ooCjdoxl4ospecf ++9NefsIXAcHk69hT3EBZflxCkZT5H7rXIAsrDfoK0p3259vgBh8qiYaC7v3RLbJBy ++ZICixl9s5KcizI/GU5qZ2/eYXDnsrYRXOFNtKltwe+PeGDDVokmoILMupvAuci1i ++e52rxe0jHPsdoJGdAtS61/8jnpL5MbCSbImjZroaWic4NSv9L1klElTNc2cRRQN8 ++rS/7P7zmBdno8/Ft/UWVePaS4x0BN/JWbe3SgmWjAuw7gYCVh6FPq/paUyKa6p93 ++ZA+UziEXDxUvE6YNPjjwR1n1X9qqkNTyMu3fL3KyaPc3VfCfPKYmfOfzxhcXA/Ou ++9LVnGbZKRdOke5wJ572Z ++=fOtX + -----END PGP SIGNATURE----- +-- +1.8.4.2 + diff --git a/0040-builder-Note-in-man-page-how-to-specify-size-in-byte.patch b/0040-builder-Note-in-man-page-how-to-specify-size-in-byte.patch new file mode 100644 index 0000000..b07e1e8 --- /dev/null +++ b/0040-builder-Note-in-man-page-how-to-specify-size-in-byte.patch @@ -0,0 +1,27 @@ +From 105aa91d38a8817a3be6540a4571780394b7387e Mon Sep 17 00:00:00 2001 +From: "Richard W.M. Jones" +Date: Tue, 7 Jan 2014 14:52:08 +0000 +Subject: [PATCH] builder: Note in man page how to specify size in bytes. + +(cherry picked from commit ac41f616db35921074a4909524b9bc1a2bd2406d) +--- + builder/virt-builder.pod | 3 +++ + 1 file changed, 3 insertions(+) + +diff --git a/builder/virt-builder.pod b/builder/virt-builder.pod +index 09315e4..c3f685c 100644 +--- a/builder/virt-builder.pod ++++ b/builder/virt-builder.pod +@@ -560,6 +560,9 @@ output is a file, then the size is the same as the template. If the + output is a device, partition, etc then the size of that device is + used. + ++To specify size in bytes, the number must be followed by the lowercase ++letter I, eg: S>. ++ + =item B<--smp> N + + Enable N E 2 virtual CPUs for I<--run> scripts to use. +-- +1.8.4.2 + diff --git a/0041-builder-Pass-prog-global-program-name-around.patch b/0041-builder-Pass-prog-global-program-name-around.patch new file mode 100644 index 0000000..baed601 --- /dev/null +++ b/0041-builder-Pass-prog-global-program-name-around.patch @@ -0,0 +1,164 @@ +From 3b82395206dd43033624b8afab6df3f2194ca06c Mon Sep 17 00:00:00 2001 +From: "Richard W.M. Jones" +Date: Tue, 7 Jan 2014 17:30:20 +0000 +Subject: [PATCH] builder: Pass ~prog global (program name) around. + +(cherry picked from commit 3e802605b52dccd2574353d5aff220de8d8eb3b8) +--- + builder/builder.ml | 8 ++++---- + builder/downloader.ml | 17 +++++++++-------- + builder/downloader.mli | 2 +- + builder/index_parser.ml | 4 ++-- + builder/index_parser.mli | 2 +- + 5 files changed, 17 insertions(+), 16 deletions(-) + +diff --git a/builder/builder.ml b/builder/builder.ml +index 07c2b02..0f8e069 100644 +--- a/builder/builder.ml ++++ b/builder/builder.ml +@@ -138,7 +138,7 @@ let main () = + fun (source, fingerprint) -> + let sigchecker = + Sigchecker.create ~debug ~gpg ~fingerprint ~check_signature in +- Index_parser.get_index ~debug ~downloader ~sigchecker source ++ Index_parser.get_index ~prog ~debug ~downloader ~sigchecker source + ) sources + ) in + +@@ -178,7 +178,7 @@ let main () = + let template = name, revision in + msg (f_"Downloading: %s") file_uri; + let progress_bar = not quiet in +- ignore (Downloader.download downloader ~template ~progress_bar ++ ignore (Downloader.download ~prog downloader ~template ~progress_bar + file_uri) + ) index; + exit 0 +@@ -218,7 +218,7 @@ let main () = + let template = arg, revision in + msg (f_"Downloading: %s") file_uri; + let progress_bar = not quiet in +- Downloader.download downloader ~template ~progress_bar file_uri in ++ Downloader.download ~prog downloader ~template ~progress_bar file_uri in + if delete_on_exit then unlink_on_exit template; + template in + +@@ -236,7 +236,7 @@ let main () = + | { Index_parser.signature_uri = None } -> None + | { Index_parser.signature_uri = Some signature_uri } -> + let sigfile, delete_on_exit = +- Downloader.download downloader signature_uri in ++ Downloader.download ~prog downloader signature_uri in + if delete_on_exit then unlink_on_exit sigfile; + Some sigfile in + +diff --git a/builder/downloader.ml b/builder/downloader.ml +index 918227e..442a011 100644 +--- a/builder/downloader.ml ++++ b/builder/downloader.ml +@@ -43,19 +43,19 @@ let create ~debug ~curl ~cache = { + cache = cache; + } + +-let rec download t ?template ?progress_bar uri = ++let rec download ~prog t ?template ?progress_bar uri = + match template with + | None -> (* no cache, simple download *) + (* Create a temporary name. *) + let tmpfile = Filename.temp_file "vbcache" ".txt" in +- download_to t ?progress_bar uri tmpfile; ++ download_to ~prog t ?progress_bar uri tmpfile; + (tmpfile, true) + + | Some (name, revision) -> + match t.cache with + | None -> + (* Not using the cache at all? *) +- download t ?progress_bar uri ++ download t ~prog ?progress_bar uri + + | Some cachedir -> + let filename = cache_of_name cachedir name revision in +@@ -64,11 +64,11 @@ let rec download t ?template ?progress_bar uri = + * If not, download it. + *) + if not (Sys.file_exists filename) then +- download_to t ?progress_bar uri filename; ++ download_to ~prog t ?progress_bar uri filename; + + (filename, false) + +-and download_to t ?(progress_bar = false) uri filename = ++and download_to ~prog t ?(progress_bar = false) uri filename = + (* Get the status code first to ensure the file exists. *) + let cmd = sprintf "%s%s -g -o /dev/null -I -w '%%{http_code}' %s" + t.curl +@@ -99,8 +99,8 @@ and download_to t ?(progress_bar = false) uri filename = + | _ -> false + in + if bad_status_code status_code then ( +- eprintf (f_"virt-builder: failed to download %s: HTTP status code %s\n") +- uri status_code; ++ eprintf (f_"%s: failed to download %s: HTTP status code %s\n") ++ prog uri status_code; + exit 1 + ); + +@@ -120,7 +120,8 @@ and download_to t ?(progress_bar = false) uri filename = + if t.debug then eprintf "%s\n%!" cmd; + let r = Sys.command cmd in + if r <> 0 then ( +- eprintf (f_"virt-builder: curl (download) command failed downloading '%s'\n") uri; ++ eprintf (f_"%s: curl (download) command failed downloading '%s'\n") ++ prog uri; + exit 1 + ); + +diff --git a/builder/downloader.mli b/builder/downloader.mli +index 8cb7404..62d500d 100644 +--- a/builder/downloader.mli ++++ b/builder/downloader.mli +@@ -32,7 +32,7 @@ type t + val create : debug:bool -> curl:string -> cache:string option -> t + (** Create the abstract type. *) + +-val download : t -> ?template:(string*int) -> ?progress_bar:bool -> uri -> (filename * bool) ++val download : prog:string -> t -> ?template:(string*int) -> ?progress_bar:bool -> uri -> (filename * bool) + (** Download the URI, returning the downloaded filename and a + temporary file flag. The temporary file flag is [true] iff + the downloaded file is temporary and should be deleted by the +diff --git a/builder/index_parser.ml b/builder/index_parser.ml +index fb47e50..453a3a1 100644 +--- a/builder/index_parser.ml ++++ b/builder/index_parser.ml +@@ -106,7 +106,7 @@ and field = string * string (* key + value *) + (* Calls yyparse in the C code. *) + external parse_index : string -> sections = "virt_builder_parse_index" + +-let get_index ~debug ~downloader ~sigchecker source = ++let get_index ~prog ~debug ~downloader ~sigchecker source = + let corrupt_file () = + eprintf (f_"\nThe index file downloaded from '%s' is corrupt.\nYou need to ask the supplier of this file to fix it and upload a fixed version.\n") + source; +@@ -115,7 +115,7 @@ let get_index ~debug ~downloader ~sigchecker source = + + let rec get_index () = + (* Get the index page. *) +- let tmpfile, delete_tmpfile = Downloader.download downloader source in ++ let tmpfile, delete_tmpfile = Downloader.download ~prog downloader source in + + (* Check index file signature (also verifies it was fully + * downloaded and not corrupted in transit). +diff --git a/builder/index_parser.mli b/builder/index_parser.mli +index 0b6317d..54f1807 100644 +--- a/builder/index_parser.mli ++++ b/builder/index_parser.mli +@@ -35,4 +35,4 @@ and entry = { + sigchecker : Sigchecker.t; + } + +-val get_index : debug:bool -> downloader:Downloader.t -> sigchecker:Sigchecker.t -> string -> index ++val get_index : prog:string -> debug:bool -> downloader:Downloader.t -> sigchecker:Sigchecker.t -> string -> index +-- +1.8.4.2 + diff --git a/0042-mllib-Add-library-function-to-run-external-command-a.patch b/0042-mllib-Add-library-function-to-run-external-command-a.patch new file mode 100644 index 0000000..cc7298d --- /dev/null +++ b/0042-mllib-Add-library-function-to-run-external-command-a.patch @@ -0,0 +1,85 @@ +From 91ff15fb954b3cee51384a72c9771149f256719b Mon Sep 17 00:00:00 2001 +From: "Richard W.M. Jones" +Date: Tue, 7 Jan 2014 17:30:57 +0000 +Subject: [PATCH] mllib: Add library function to run external command and slurp + up the output. + +This also changes a couple of functions to use this new library +function. + +(cherry picked from commit a403febb8c43bf573c2354c39df22a29cf8863d8) +--- + builder/downloader.ml | 19 ++++--------------- + mllib/common_utils.ml | 16 +++++++++++++--- + 2 files changed, 17 insertions(+), 18 deletions(-) + +diff --git a/builder/downloader.ml b/builder/downloader.ml +index 442a011..77f48ae 100644 +--- a/builder/downloader.ml ++++ b/builder/downloader.ml +@@ -75,23 +75,12 @@ and download_to ~prog t ?(progress_bar = false) uri filename = + (if t.debug then "" else " -s -S") + (quote uri) in + if t.debug then eprintf "%s\n%!" cmd; +- let chan = open_process_in cmd in +- let status_code = input_line chan in +- let stat = close_process_in chan in +- (match stat with +- | WEXITED 0 -> () +- | WEXITED i -> +- eprintf (f_"virt-builder: curl (download) command failed downloading '%s'\n") uri; +- exit 1 +- | WSIGNALED i -> +- eprintf (f_"virt-builder: external command '%s' killed by signal %d\n") +- cmd i; +- exit 1 +- | WSTOPPED i -> +- eprintf (f_"virt-builder: external command '%s' stopped by signal %d\n") +- cmd i; ++ let lines = external_command ~prog cmd in ++ if List.length lines < 1 then ( ++ eprintf (f_"%s: unexpected output from curl command, enable debug and look at previous messages\n") prog; + exit 1 + ); ++ let status_code = List.hd lines in + let bad_status_code = function + | "" -> true + | s when s.[0] = '4' -> true (* 4xx *) +diff --git a/mllib/common_utils.ml b/mllib/common_utils.ml +index 80c5aca..3943417 100644 +--- a/mllib/common_utils.ml ++++ b/mllib/common_utils.ml +@@ -332,10 +332,13 @@ let display_long_options () = + ) !long_options; + exit 0 + +-let uuidgen ~prog () = +- let cmd = "uuidgen -r" in ++(* Run an external command, slurp up the output as a list of lines. *) ++let external_command ~prog cmd = + let chan = Unix.open_process_in cmd in +- let uuid = input_line chan in ++ let lines = ref [] in ++ (try while true do lines := input_line chan :: !lines done ++ with End_of_file -> ()); ++ let lines = List.rev !lines in + let stat = Unix.close_process_in chan in + (match stat with + | Unix.WEXITED 0 -> () +@@ -346,6 +349,13 @@ let uuidgen ~prog () = + | Unix.WSTOPPED i -> + error ~prog (f_"external command '%s' stopped by signal %d") cmd i + ); ++ lines ++ ++(* Run uuidgen to return a random UUID. *) ++let uuidgen ~prog () = ++ let lines = external_command ~prog "uuidgen -r" in ++ assert (List.length lines >= 1); ++ let uuid = List.hd lines in + let len = String.length uuid in + let uuid, len = + if len > 0 && uuid.[len-1] = '\n' then +-- +1.8.4.2 + diff --git a/0043-builder-Fix-handling-of-size-parameter.patch b/0043-builder-Fix-handling-of-size-parameter.patch new file mode 100644 index 0000000..da887fc --- /dev/null +++ b/0043-builder-Fix-handling-of-size-parameter.patch @@ -0,0 +1,96 @@ +From f60ef10973d1bdc0df93603d5667d0528eeb0dd0 Mon Sep 17 00:00:00 2001 +From: "Richard W.M. Jones" +Date: Tue, 7 Jan 2014 17:32:04 +0000 +Subject: [PATCH] builder: Fix handling of --size parameter. + +It now matches the documentation: + + "Select the size of the output disk, [...] + + Virt-builder will resize filesystems inside the disk image + automatically. + + If the size is not specified, then one of two things happens. If + the output is a file, then the size is the same as the template. If + the output is a device, partition, etc then the size of that device + is used." + +This also adds checks to make sure that users don't try to shrink a +disk (which is not possible), and they don't try to resize larger than +the output block device. + +(cherry picked from commit 06f7bea14883c4903c58077757179341c0e1471a) +--- + builder/builder.ml | 43 ++++++++++++++++++++++++++++++++++--------- + 1 file changed, 34 insertions(+), 9 deletions(-) + +diff --git a/builder/builder.ml b/builder/builder.ml +index 0f8e069..f007b46 100644 +--- a/builder/builder.ml ++++ b/builder/builder.ml +@@ -261,9 +261,6 @@ let main () = + format_tag @ compression_tag in + + (* Planner: Goal. *) +- let output_size = +- let { Index_parser.size = default_size } = entry in +- match size with None -> default_size | Some size -> size in + let output_filename, output_format = + match output, format with + | None, None -> sprintf "%s.img" arg, "raw" +@@ -271,18 +268,46 @@ let main () = + | None, Some format -> sprintf "%s.%s" arg format, format + | Some output, None -> output, "raw" + | Some output, Some format -> output, format in +- let output_is_block_dev = is_block_device output_filename in +- +- if output_is_block_dev && size <> None then ( +- eprintf (f_"%s: you cannot use --size option with block devices\n") prog; +- exit 1 +- ); + + if is_char_device output_filename then ( + eprintf (f_"%s: cannot output to a character device or /dev/null\n") prog; + exit 1 + ); + ++ let blockdev_getsize64 dev = ++ let cmd = sprintf "blockdev --getsize64 %s" (quote dev) in ++ let lines = external_command ~prog cmd in ++ assert (List.length lines >= 1); ++ Int64.of_string (List.hd lines) ++ in ++ let output_is_block_dev, blockdev_size = ++ let b = is_block_device output_filename in ++ let sz = if b then blockdev_getsize64 output_filename else 0L in ++ b, sz in ++ ++ let output_size = ++ let { Index_parser.size = original_image_size } = entry in ++ ++ let size = ++ match size with ++ | Some size -> size ++ (* --size parameter missing, output to file: use original image size *) ++ | None when not output_is_block_dev -> original_image_size ++ (* --size parameter missing, block device: use block device size *) ++ | None -> blockdev_size in ++ ++ if size < original_image_size then ( ++ eprintf (f_"%s: images cannot be shrunk, the output size is too small for this image. Requested size = %s, minimum size = %s\n") ++ prog (human_size size) (human_size original_image_size); ++ exit 1 ++ ) ++ else if output_is_block_dev && output_format = "raw" && size > blockdev_size then ( ++ eprintf (f_"%s: output size is too large for this block device. Requested size = %s, output block device = %s, output block device size = %s\n") ++ prog (human_size size) output_filename (human_size blockdev_size); ++ exit 1 ++ ); ++ size in ++ + let goal = + (* MUST *) + let goal_must = [ +-- +1.8.4.2 + diff --git a/0044-libvirt-auth-Provide-a-friendlier-wrapper-around-vir.patch b/0044-libvirt-auth-Provide-a-friendlier-wrapper-around-vir.patch new file mode 100644 index 0000000..181b3f1 --- /dev/null +++ b/0044-libvirt-auth-Provide-a-friendlier-wrapper-around-vir.patch @@ -0,0 +1,122 @@ +From 816462383a0cc7827177e97bbe4de775950b1aac Mon Sep 17 00:00:00 2001 +From: "Richard W.M. Jones" +Date: Thu, 2 Jan 2014 12:20:18 +0000 +Subject: [PATCH] libvirt-auth: Provide a friendlier wrapper around + virConnectAuthPtrDefault (RHBZ#1044014). + +(cherry picked from commit 4125064554c8cb1b96680e24e49d74ee6024f761) +--- + src/guestfs-internal.h | 1 + + src/libvirt-auth.c | 55 +++++++++++++++++++++++++++++++++++++++++--------- + 2 files changed, 46 insertions(+), 10 deletions(-) + +diff --git a/src/guestfs-internal.h b/src/guestfs-internal.h +index 8888603..a1f3f02 100644 +--- a/src/guestfs-internal.h ++++ b/src/guestfs-internal.h +@@ -469,6 +469,7 @@ struct guestfs_h + unsigned int nr_supported_credentials; + int supported_credentials[NR_CREDENTIAL_TYPES]; + const char *saved_libvirt_uri; /* Doesn't need to be freed. */ ++ bool wrapper_warning_done; + unsigned int nr_requested_credentials; + virConnectCredentialPtr requested_credentials; + #endif +diff --git a/src/libvirt-auth.c b/src/libvirt-auth.c +index fb18f8a..f8ed1b1 100644 +--- a/src/libvirt-auth.c ++++ b/src/libvirt-auth.c +@@ -20,6 +20,7 @@ + + #include + #include ++#include + + #ifdef HAVE_LIBVIRT + #include +@@ -147,6 +148,34 @@ libvirt_auth_callback (virConnectCredentialPtr cred, + return 0; + } + ++/* Libvirt provides a default authentication handler. However it is ++ * confusing to end-users ++ * (https://bugzilla.redhat.com/show_bug.cgi?id=1044014#c0). ++ * ++ * Unfortunately #1 the libvirt handler cannot easily be modified to ++ * make it non-confusing, but unfortunately #2 we have to actually ++ * call it because it handles all the policykit crap. ++ * ++ * Therefore we add a wrapper around it here. ++ */ ++static int ++libvirt_auth_default_wrapper (virConnectCredentialPtr cred, ++ unsigned int ncred, ++ void *gv) ++{ ++ guestfs_h *g = gv; ++ ++ if (!g->wrapper_warning_done) { ++ printf (_("libvirt needs authentication to connect to libvirt URI %s\n" ++ "(see also: http://libvirt.org/auth.html http://libvirt.org/uri.html)\n"), ++ g->saved_libvirt_uri ? g->saved_libvirt_uri : "NULL"); ++ g->wrapper_warning_done = true; ++ } ++ ++ return virConnectAuthPtrDefault->cb (cred, ncred, ++ virConnectAuthPtrDefault->cbdata); ++} ++ + static int + exists_libvirt_auth_event (guestfs_h *g) + { +@@ -165,31 +194,37 @@ guestfs___open_libvirt_connection (guestfs_h *g, const char *uri, + unsigned int flags) + { + virConnectAuth authdata; +- virConnectAuthPtr authdataptr; + virConnectPtr conn; ++ const char *authtype; ++ ++ g->saved_libvirt_uri = uri; ++ g->wrapper_warning_done = false; + + /* Did the caller register a GUESTFS_EVENT_LIBVIRT_AUTH event and + * call guestfs_set_libvirt_supported_credentials? + */ + if (g->nr_supported_credentials > 0 && exists_libvirt_auth_event (g)) { ++ authtype = "custom"; + memset (&authdata, 0, sizeof authdata); + authdata.credtype = g->supported_credentials; + authdata.ncredtype = g->nr_supported_credentials; + authdata.cb = libvirt_auth_callback; + authdata.cbdata = g; +- authdataptr = &authdata; +- g->saved_libvirt_uri = uri; + } +- else +- authdataptr = virConnectAuthPtrDefault; ++ else { ++ /* Wrapper around libvirt's virConnectAuthPtrDefault, see comment ++ * above. ++ */ ++ authtype = "default+wrapper"; ++ authdata = *virConnectAuthPtrDefault; ++ authdata.cb = libvirt_auth_default_wrapper; ++ authdata.cbdata = g; ++ } + + debug (g, "opening libvirt handle: URI = %s, auth = %s, flags = %u", +- uri ? uri : "NULL", +- authdataptr == virConnectAuthPtrDefault +- ? "virConnectAuthPtrDefault" : "", +- flags); ++ uri ? uri : "NULL", authtype, flags); + +- conn = virConnectOpenAuth (uri, authdataptr, flags); ++ conn = virConnectOpenAuth (uri, &authdata, flags); + + if (conn) + debug (g, "successfully opened libvirt handle: conn = %p", conn); +-- +1.8.4.2 + diff --git a/0045-tests-Add-a-regression-test-of-libvirt-authenticatio.patch b/0045-tests-Add-a-regression-test-of-libvirt-authenticatio.patch new file mode 100644 index 0000000..f3ddba1 --- /dev/null +++ b/0045-tests-Add-a-regression-test-of-libvirt-authenticatio.patch @@ -0,0 +1,303 @@ +From 4f769c49cbd8e89f0e143b153357725327fb69d5 Mon Sep 17 00:00:00 2001 +From: "Richard W.M. Jones" +Date: Wed, 8 Jan 2014 19:36:00 +0000 +Subject: [PATCH] tests: Add a regression test of libvirt authentication + events. + +This requires a change to libvirt (in libvirt >= 1.2.1), see: + +https://www.redhat.com/archives/libvir-list/2014-January/msg00378.html +(cherry picked from commit 873db60c0e52893a38c374d867d0a305e5419d6a) +--- + .gitignore | 1 + + tests/events/Makefile.am | 36 ++++-- + tests/events/libvirt-auth.xml | 22 ++++ + tests/events/test-libvirt-auth-callbacks.c | 185 +++++++++++++++++++++++++++++ + 4 files changed, 237 insertions(+), 7 deletions(-) + create mode 100644 tests/events/libvirt-auth.xml + create mode 100644 tests/events/test-libvirt-auth-callbacks.c + +diff --git a/.gitignore b/.gitignore +index b967dbd..b44af29 100644 +--- a/.gitignore ++++ b/.gitignore +@@ -461,6 +461,7 @@ Makefile.in + /tests/data/initrd-x86_64.img.gz + /tests/data/test-grep.txt.gz + /tests/data/test.iso ++/tests/events/test-libvirt-auth-callbacks + /tests/guests/blank-*.img + /tests/guests/debian.img + /tests/guests/fedora.img +diff --git a/tests/events/Makefile.am b/tests/events/Makefile.am +index 9f6e5aa..9751edc 100644 +--- a/tests/events/Makefile.am ++++ b/tests/events/Makefile.am +@@ -1,5 +1,5 @@ + # libguestfs +-# Copyright (C) 2013 Red Hat Inc. ++# Copyright (C) 2013-2014 Red Hat Inc. + # + # This program is free software; you can redistribute it and/or modify + # it under the terms of the GNU General Public License as published by +@@ -17,10 +17,32 @@ + + include $(top_srcdir)/subdir-rules.mk + +-TESTS = \ +- test-console-debug.pl +- +-TESTS_ENVIRONMENT = $(top_builddir)/run --test +- + EXTRA_DIST = \ +- $(TESTS) ++ test-console-debug.pl \ ++ libvirt-auth.xml ++ ++TESTS_ENVIRONMENT = $(top_builddir)/run --test ++ ++check_PROGRAMS = ++ ++TESTS = test-console-debug.pl ++ ++if HAVE_LIBVIRT ++TESTS += test-libvirt-auth-callbacks ++check_PROGRAMS += test-libvirt-auth-callbacks ++ ++test_libvirt_auth_callbacks_SOURCES = test-libvirt-auth-callbacks.c ++test_libvirt_auth_callbacks_CPPFLAGS = \ ++ -I$(top_srcdir)/gnulib/lib -I$(top_builddir)/gnulib/lib \ ++ -I$(top_srcdir)/src -I$(top_builddir)/src ++test_libvirt_auth_callbacks_CFLAGS = \ ++ $(WARN_CFLAGS) $(WERROR_CFLAGS) \ ++ $(GPROF_CFLAGS) $(GCOV_CFLAGS) \ ++ $(LIBVIRT_CFLAGS) ++test_libvirt_auth_callbacks_LDADD = \ ++ $(top_builddir)/src/libutils.la \ ++ $(top_builddir)/src/libguestfs.la \ ++ $(LIBVIRT_LIBS) \ ++ $(LIBXML2_LIBS) \ ++ $(top_builddir)/gnulib/lib/libgnu.la ++endif +diff --git a/tests/events/libvirt-auth.xml b/tests/events/libvirt-auth.xml +new file mode 100644 +index 0000000..d138d4d +--- /dev/null ++++ b/tests/events/libvirt-auth.xml +@@ -0,0 +1,22 @@ ++ ++ ++ test ++ 1048576 ++ ++ hvm ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ rich ++ jane ++ ++ +diff --git a/tests/events/test-libvirt-auth-callbacks.c b/tests/events/test-libvirt-auth-callbacks.c +new file mode 100644 +index 0000000..7c26bbe +--- /dev/null ++++ b/tests/events/test-libvirt-auth-callbacks.c +@@ -0,0 +1,185 @@ ++/* libguestfs ++ * Copyright (C) 2014 Red Hat Inc. ++ * ++ * This program is free software; you can redistribute it and/or modify ++ * it under the terms of the GNU General Public License as published by ++ * the Free Software Foundation; either version 2 of the License, or ++ * (at your option) any later version. ++ * ++ * 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 General Public License for more details. ++ * ++ * You should have received a copy of the GNU General Public License along ++ * with this program; if not, write to the Free Software Foundation, Inc., ++ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ++ */ ++ ++#include ++ ++#include ++#include ++#include ++#include ++ ++#include ++ ++#include "guestfs.h" ++#include "guestfs-internal-frontend.h" ++ ++#define EXPECT_OK 1 ++#define EXPECT_FAIL -1 ++ ++struct auth_data { ++ const char *username; ++ const char *password; ++}; ++ ++static void do_test (const char *prog, const char *libvirt_uri, const struct auth_data *auth_data, int expected); ++static void auth_callback (guestfs_h *g, void *opaque, uint64_t event, int event_handle, int flags, const char *buf, size_t buf_len, const uint64_t *array, size_t array_len); ++ ++int ++main (int argc, char *argv[]) ++{ ++ unsigned long ver; ++ const char *srcdir; ++ char *cwd; ++ char *test_uri; ++ ++ virInitialize (); ++ ++ /* Check that the version of libvirt we are linked against ++ * supports the new test-driver auth feature. ++ */ ++ virGetVersion (&ver, NULL, NULL); ++ if (ver < 1002001) { ++ fprintf (stderr, "%s: test skipped because libvirt is too old (%lu)\n", ++ argv[0], ver); ++ exit (77); ++ } ++ ++ /* $srcdir must have been passed (by automake). */ ++ srcdir = getenv ("srcdir"); ++ if (!srcdir) { ++ fprintf (stderr, ++ "%s: environment variable $srcdir is not defined.\n" ++ "Normally it is defined by automake. If you are running the\n" ++ "tests directly, set $srcdir to point to the source tests/events\n" ++ "directory.\n", argv[0]); ++ exit (EXIT_FAILURE); ++ } ++ ++ cwd = get_current_dir_name (); ++ if (cwd == NULL) { ++ perror ("get_current_dir_name"); ++ exit (EXIT_FAILURE); ++ } ++ ++ if (asprintf (&test_uri, "test://%s/%s/libvirt-auth.xml", cwd, srcdir) == -1) { ++ perror ("asprintf"); ++ exit (EXIT_FAILURE); ++ } ++ ++ free (cwd); ++ ++ /* Perform the tests. */ ++ struct auth_data ad1 = { .username = "rich", .password = "123456" }; ++ do_test (argv[0], test_uri, &ad1, EXPECT_OK); ++ struct auth_data ad2 = { .username = "rich", .password = "654321" }; ++ do_test (argv[0], test_uri, &ad2, EXPECT_FAIL); ++ struct auth_data ad3 = { .username = "jane", .password = NULL }; ++ do_test (argv[0], test_uri, &ad3, EXPECT_OK); ++ struct auth_data ad4 = { .username = "nouser", .password = "123456" }; ++ do_test (argv[0], test_uri, &ad4, EXPECT_FAIL); ++ ++ free (test_uri); ++ exit (EXIT_SUCCESS); ++} ++ ++static void ++do_test (const char *prog, const char *libvirt_uri, ++ const struct auth_data *auth_data, ++ int expected) ++{ ++ guestfs_h *g; ++ const char *creds[] = ++ { "authname", "passphrase", "noechoprompt", NULL }; ++ int r, eh; ++ ++ g = guestfs_create (); ++ if (!g) ++ exit (EXIT_FAILURE); ++ ++ r = guestfs_set_libvirt_supported_credentials (g, (char **) creds); ++ if (r == -1) ++ exit (EXIT_FAILURE); ++ ++ eh = guestfs_set_event_callback (g, auth_callback, ++ GUESTFS_EVENT_LIBVIRT_AUTH, 0, ++ (void *) auth_data); ++ if (eh == -1) ++ exit (EXIT_FAILURE); ++ ++ r = guestfs_add_domain (g, "test", ++ GUESTFS_ADD_DOMAIN_LIBVIRTURI, libvirt_uri, ++ GUESTFS_ADD_DOMAIN_READONLY, 1, ++ -1); ++ if (r != expected) { ++ fprintf (stderr, ++ "%s: test failed: u=%s p=%s: got %d expected %d\n", ++ prog, auth_data->username, auth_data->password ? : "(none)", ++ r, expected); ++ exit (EXIT_FAILURE); ++ } ++ ++ guestfs_close (g); ++} ++ ++static void ++auth_callback (guestfs_h *g, void *opaque, ++ uint64_t event, int event_handle, ++ int flags, ++ const char *buf, size_t buf_len, ++ const uint64_t *array, size_t array_len) ++{ ++ CLEANUP_FREE_STRING_LIST char **creds = NULL; ++ const struct auth_data *auth_data = opaque; ++ size_t i; ++ int r; ++ const char *reply; ++ size_t len; ++ ++ /* Ask libguestfs what credentials libvirt is demanding. */ ++ creds = guestfs_get_libvirt_requested_credentials (g); ++ if (creds == NULL) ++ exit (EXIT_FAILURE); ++ ++ /* Try to answer from the authentication data. */ ++ for (i = 0; creds[i] != NULL; ++i) { ++ if (STREQ (creds[i], "authname")) { ++ reply = auth_data->username; ++ len = strlen (reply); ++ } ++ else if (STREQ (creds[i], "passphrase") || ++ STREQ (creds[i], "noechoprompt")) { ++ if (!auth_data->password) { ++ fprintf (stderr, "test failed: libvirt asked for a password, but auth_data->password == NULL\n"); ++ exit (EXIT_FAILURE); ++ } ++ ++ reply = auth_data->password; ++ len = strlen (reply); ++ } ++ else { ++ fprintf (stderr, "test failed: libvirt asked for '%s' which is not in creds list\n(This is probably a libvirt bug)\n", ++ creds[i]); ++ exit (EXIT_FAILURE); ++ } ++ ++ r = guestfs_set_libvirt_requested_credential (g, i, ++ reply, len); ++ if (r == -1) ++ exit (EXIT_FAILURE); ++ } ++} +-- +1.8.4.2 + diff --git a/0046-tests-Add-a-regression-test-for-libvirt-authenticati.patch b/0046-tests-Add-a-regression-test-for-libvirt-authenticati.patch new file mode 100644 index 0000000..5583398 --- /dev/null +++ b/0046-tests-Add-a-regression-test-for-libvirt-authenticati.patch @@ -0,0 +1,265 @@ +From d4938044d2be6f8ed90022fb7ca9378378f2604b Mon Sep 17 00:00:00 2001 +From: "Richard W.M. Jones" +Date: Wed, 8 Jan 2014 20:22:21 +0000 +Subject: [PATCH] tests: Add a regression test for libvirt authentication + (RHBZ#1044014). + +This tests the virConnectAuthPtrDefault wrapper path. + +(cherry picked from commit 746a0b1f19667606ee63c8d3ab6a75531a8bd71c) +--- + .gitignore | 2 ++ + tests/regressions/Makefile.am | 29 +++++++++++++++- + tests/regressions/rhbz1044014.c | 69 ++++++++++++++++++++++++++++++++++++++ + tests/regressions/rhbz1044014.in | 1 + + tests/regressions/rhbz1044014.sh | 70 +++++++++++++++++++++++++++++++++++++++ + tests/regressions/rhbz1044014.xml | 5 +++ + 6 files changed, 175 insertions(+), 1 deletion(-) + create mode 100644 tests/regressions/rhbz1044014.c + create mode 100644 tests/regressions/rhbz1044014.in + create mode 100755 tests/regressions/rhbz1044014.sh + create mode 100644 tests/regressions/rhbz1044014.xml + +diff --git a/.gitignore b/.gitignore +index b44af29..90cd68b 100644 +--- a/.gitignore ++++ b/.gitignore +@@ -483,6 +483,8 @@ Makefile.in + /tests/regressions/rhbz501893 + /tests/regressions/rhbz790721 + /tests/regressions/rhbz914931 ++/tests/regressions/rhbz1044014 ++/tests/regressions/rhbz1044014.out + /tests/rsync/rsyncd.pid + /tests/syslinux/extlinux-guest.img + /tests/syslinux/syslinux-guest.img +diff --git a/tests/regressions/Makefile.am b/tests/regressions/Makefile.am +index 1b0fb69..8051c14 100644 +--- a/tests/regressions/Makefile.am ++++ b/tests/regressions/Makefile.am +@@ -36,6 +36,10 @@ TESTS = \ + rhbz1001875.sh \ + test-noexec-stack.pl + ++if HAVE_LIBVIRT ++TESTS += rhbz1044014.sh ++endif ++ + tests_not_run = \ + rhbz727178.sh \ + rhbz909624.sh +@@ -49,6 +53,10 @@ check_PROGRAMS = \ + rhbz790721 \ + rhbz914931 + ++if HAVE_LIBVIRT ++check_PROGRAMS += rhbz1044014 ++endif ++ + rhbz501893_SOURCES = rhbz501893.c + rhbz501893_CPPFLAGS = \ + -I$(top_srcdir)/src -I$(top_builddir)/src +@@ -79,11 +87,30 @@ rhbz914931_CFLAGS = \ + rhbz914931_LDADD = \ + $(top_builddir)/src/libguestfs.la + ++if HAVE_LIBVIRT ++rhbz1044014_SOURCES = rhbz1044014.c ++rhbz1044014_CPPFLAGS = \ ++ -I$(top_srcdir)/gnulib/lib -I$(top_builddir)/gnulib/lib \ ++ -I$(top_srcdir)/src -I$(top_builddir)/src ++rhbz1044014_CFLAGS = \ ++ $(WARN_CFLAGS) $(WERROR_CFLAGS) \ ++ $(GPROF_CFLAGS) $(GCOV_CFLAGS) \ ++ $(LIBVIRT_CFLAGS) ++rhbz1044014_LDADD = \ ++ $(top_builddir)/src/libutils.la \ ++ $(top_builddir)/src/libguestfs.la \ ++ $(LIBVIRT_LIBS) \ ++ $(LIBXML2_LIBS) \ ++ $(top_builddir)/gnulib/lib/libgnu.la ++endif ++ + EXTRA_DIST = \ + $(TESTS) \ + $(tests_not_run) \ + rhbz557655-expected.stdout \ +- rhbz557655-expected.stderr ++ rhbz557655-expected.stderr \ ++ rhbz1044014.in \ ++ rhbz1044014.xml + + check-slow: + $(MAKE) TESTS="rhbz909624.sh" check +diff --git a/tests/regressions/rhbz1044014.c b/tests/regressions/rhbz1044014.c +new file mode 100644 +index 0000000..18ce4a7 +--- /dev/null ++++ b/tests/regressions/rhbz1044014.c +@@ -0,0 +1,69 @@ ++/* libguestfs ++ * Copyright (C) 2014 Red Hat Inc. ++ * ++ * This program is free software; you can redistribute it and/or modify ++ * it under the terms of the GNU General Public License as published by ++ * the Free Software Foundation; either version 2 of the License, or ++ * (at your option) any later version. ++ * ++ * 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 General Public License for more details. ++ * ++ * You should have received a copy of the GNU General Public License ++ * along with this program; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ++ */ ++ ++/* Regression test for RHBZ#1044014. ++ * ++ * The only reason to write this in C is so we can easily check the ++ * version of libvirt >= 1.2.1. In the future when we can assume a ++ * newer libvirt, we can just have the main rhbz1044014.sh script set ++ * some environment variables and use guestfish. ++ */ ++ ++#include ++ ++#include ++#include ++#include ++#include ++#include ++ ++#include ++ ++#include "guestfs.h" ++#include "guestfs-internal-frontend.h" ++ ++int ++main (int argc, char *argv[]) ++{ ++ unsigned long ver; ++ guestfs_h *g; ++ ++ virInitialize (); ++ ++ /* Check that the version of libvirt we are linked against ++ * supports the new test-driver auth feature. ++ */ ++ virGetVersion (&ver, NULL, NULL); ++ if (ver < 1002001) { ++ fprintf (stderr, "%s: test skipped because libvirt is too old (%lu)\n", ++ argv[0], ver); ++ exit (77); ++ } ++ ++ g = guestfs_create (); ++ if (!g) ++ exit (EXIT_FAILURE); ++ ++ /* This will ask the user for credentials. It will also fail ++ * (expectedly) because the test driver does not support qemu/KVM. ++ */ ++ guestfs_launch (g); ++ ++ guestfs_close (g); ++ exit (EXIT_SUCCESS); ++} +diff --git a/tests/regressions/rhbz1044014.in b/tests/regressions/rhbz1044014.in +new file mode 100644 +index 0000000..3f382dd +--- /dev/null ++++ b/tests/regressions/rhbz1044014.in +@@ -0,0 +1 @@ ++rich +diff --git a/tests/regressions/rhbz1044014.sh b/tests/regressions/rhbz1044014.sh +new file mode 100755 +index 0000000..f1e458c +--- /dev/null ++++ b/tests/regressions/rhbz1044014.sh +@@ -0,0 +1,70 @@ ++#!/bin/bash - ++# libguestfs ++# Copyright (C) 2014 Red Hat Inc. ++# ++# This program is free software; you can redistribute it and/or modify ++# it under the terms of the GNU General Public License as published by ++# the Free Software Foundation; either version 2 of the License, or ++# (at your option) any later version. ++# ++# 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 General Public License for more details. ++# ++# You should have received a copy of the GNU General Public License ++# along with this program; if not, write to the Free Software ++# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ++ ++# Regression test for: ++# https://bugzilla.redhat.com/show_bug.cgi?id=1044014 ++ ++set -e ++export LANG=C ++ ++if [ -n "$SKIP_TEST_RHBZ1044014_SH" ]; then ++ echo "$0: test skipped because environment variable is set." ++ exit 77 ++fi ++ ++# Check we are running against the libvirt backend. ++backend="$(../../fish/guestfish get-backend)" ++if [[ ! ( "$backend" =~ ^libvirt ) ]]; then ++ echo "$0: test skipped because backend ($backend) is not libvirt." ++ exit 77 ++fi ++ ++# Set the backend to the test driver. ++export LIBGUESTFS_BACKEND="libvirt:test://$(pwd)/$srcdir/rhbz1044014.xml" ++ ++rm -f rhbz1044014.out ++ ++./rhbz1044014 < $srcdir/rhbz1044014.in > rhbz1044014.out 2>&1 || { ++ r=$? ++ if [ $r -ne 0 ]; then ++ cat rhbz1044014.out ++ exit $r ++ fi ++} ++ ++# We are expecting this message to be printed (see commit which fixed ++# RHBZ#1044014). ++grep "libvirt needs authentication to connect to libvirt URI" rhbz1044014.out || { ++ echo "$0: expecting to see message from commit which fixed RHBZ#1044014" ++ echo ++ echo "actual output was:" ++ echo ++ cat rhbz1044014.out ++ exit 1 ++} ++ ++# This is the error we are expecting to see. If we see it then it ++# indicates that authentication was successful. ++grep "error: libvirt hypervisor doesn't support qemu or KVM" rhbz1044014.out || { ++ echo "$0: unexpected output:" ++ echo ++ cat rhbz1044014.out ++ exit 1 ++} ++ ++rm rhbz1044014.out +diff --git a/tests/regressions/rhbz1044014.xml b/tests/regressions/rhbz1044014.xml +new file mode 100644 +index 0000000..72feaf4 +--- /dev/null ++++ b/tests/regressions/rhbz1044014.xml +@@ -0,0 +1,5 @@ ++ ++ ++ rich ++ ++ +-- +1.8.4.2 + diff --git a/0047-sysprep-builder-Add-timezone-option-to-set-timezone-.patch b/0047-sysprep-builder-Add-timezone-option-to-set-timezone-.patch new file mode 100644 index 0000000..83355cf --- /dev/null +++ b/0047-sysprep-builder-Add-timezone-option-to-set-timezone-.patch @@ -0,0 +1,363 @@ +From 441fc2a889d8e1196f2f364f66e465b67984a828 Mon Sep 17 00:00:00 2001 +From: "Richard W.M. Jones" +Date: Fri, 10 Jan 2014 12:12:30 +0000 +Subject: [PATCH] sysprep, builder: Add --timezone option to set timezone of + guest. + +You can use it like this: + + virt-sysprep --timezone Europe/London ... + virt-builder --timezone Europe/London ... + +(cherry picked from commit dd1bfea513658368afd3728e0c5bf8ab6041cd1f) +--- + builder/Makefile.am | 1 + + builder/builder.ml | 12 ++++++- + builder/cmdline.ml | 9 ++++- + builder/test-virt-builder.sh | 1 + + builder/virt-builder.pod | 8 ++++- + mllib/Makefile.am | 3 ++ + mllib/timezone.ml | 39 +++++++++++++++++++++ + mllib/timezone.mli | 22 ++++++++++++ + po/POTFILES-ml | 2 ++ + sysprep/Makefile.am | 2 ++ + sysprep/sysprep_operation_timezone.ml | 66 +++++++++++++++++++++++++++++++++++ + 11 files changed, 162 insertions(+), 3 deletions(-) + create mode 100644 mllib/timezone.ml + create mode 100644 mllib/timezone.mli + create mode 100644 sysprep/sysprep_operation_timezone.ml + +diff --git a/builder/Makefile.am b/builder/Makefile.am +index 3f35cc6..fc4c552 100644 +--- a/builder/Makefile.am ++++ b/builder/Makefile.am +@@ -69,6 +69,7 @@ OBJECTS = \ + $(top_builddir)/mllib/urandom.cmx \ + $(top_builddir)/mllib/random_seed.cmx \ + $(top_builddir)/mllib/hostname.cmx \ ++ $(top_builddir)/mllib/timezone.cmx \ + $(top_builddir)/mllib/firstboot.cmx \ + $(top_builddir)/mllib/crypt-c.o \ + $(top_builddir)/mllib/crypt.cmx \ +diff --git a/builder/builder.ml b/builder/builder.ml +index f007b46..90300a3 100644 +--- a/builder/builder.ml ++++ b/builder/builder.ml +@@ -39,7 +39,8 @@ let main () = + attach, cache, check_signature, curl, debug, delete, edit, + firstboot, run, format, gpg, hostname, install, list_long, memsize, mkdirs, + network, output, password_crypto, quiet, root_password, scrub, +- scrub_logfile, size, smp, sources, sync, update, upload, writes = ++ scrub_logfile, size, smp, sources, sync, timezone, update, upload, ++ writes = + parse_cmdline () in + + (* Timestamped messages in ordinary, non-debug non-quiet mode. *) +@@ -619,6 +620,15 @@ let main () = + eprintf (f_"%s: warning: hostname could not be set for this type of guest\n%!") prog + ); + ++ (* Set the timezone. *) ++ (match timezone with ++ | None -> () ++ | Some timezone -> ++ msg (f_"Setting the timezone: %s") timezone; ++ if not (Timezone.set_timezone ~prog g root timezone) then ++ eprintf (f_"%s: warning: timezone could not be set for this type of guest\n%!") prog ++ ); ++ + (* Root password. + * Note 'None' means that we randomize the root password. + *) +diff --git a/builder/cmdline.ml b/builder/cmdline.ml +index c6a3cd8..99412bb 100644 +--- a/builder/cmdline.ml ++++ b/builder/cmdline.ml +@@ -169,6 +169,10 @@ let parse_cmdline () = + let add_source arg = sources := arg :: !sources in + + let sync = ref true in ++ ++ let timezone = ref None in ++ let set_timezone s = timezone := Some s in ++ + let update = ref false in + + let upload = ref [] in +@@ -260,6 +264,7 @@ let parse_cmdline () = + "--smp", Arg.Int set_smp, "vcpus" ^ " " ^ s_"Set number of vCPUs"; + "--source", Arg.String add_source, "URL" ^ " " ^ s_"Set source URL"; + "--no-sync", Arg.Clear sync, " " ^ s_"Do not fsync output file on exit"; ++ "--timezone",Arg.String set_timezone, "timezone" ^ " " ^ s_"Set the default timezone"; + "--update", Arg.Set update, " " ^ s_"Update core packages"; + "--upload", Arg.String add_upload, "file:dest" ^ " " ^ s_"Upload file to dest"; + "-v", Arg.Set debug, " " ^ s_"Enable debugging messages"; +@@ -321,6 +326,7 @@ read the man page virt-builder(1). + let smp = !smp in + let sources = List.rev !sources in + let sync = !sync in ++ let timezone = !timezone in + let update = !update in + let upload = List.rev !upload in + let writes = List.rev !writes in +@@ -421,4 +427,5 @@ read the man page virt-builder(1). + attach, cache, check_signature, curl, debug, delete, edit, + firstboot, run, format, gpg, hostname, install, list_long, memsize, mkdirs, + network, output, password_crypto, quiet, root_password, scrub, +- scrub_logfile, size, smp, sources, sync, update, upload, writes ++ scrub_logfile, size, smp, sources, sync, timezone, update, upload, ++ writes +diff --git a/builder/test-virt-builder.sh b/builder/test-virt-builder.sh +index 438f2e9..8d2766a 100755 +--- a/builder/test-virt-builder.sh ++++ b/builder/test-virt-builder.sh +@@ -53,6 +53,7 @@ $VG ./virt-builder phony-fedora \ + -v --no-cache --no-check-signature $no_network \ + -o $output --size 2G --format $format \ + --hostname test.example.com \ ++ --timezone Europe/London \ + --root-password password:123456 \ + --mkdir /etc/foo/bar/baz \ + --write '/etc/foo/bar/baz/foo:Hello World' \ +diff --git a/builder/virt-builder.pod b/builder/virt-builder.pod +index c3f685c..a703346 100644 +--- a/builder/virt-builder.pod ++++ b/builder/virt-builder.pod +@@ -17,6 +17,7 @@ virt-builder - Build virtual machine images quickly + [--attach ISOFILE] + [--root-password SELECTOR] + [--hostname HOSTNAME] ++ [--timezone TIMEZONE] + [--update] + [--install PKG,[PKG...]] + [--mkdir DIR] +@@ -583,6 +584,11 @@ Note that you should not point I<--source> to sources that you don't + trust (unless the source is signed by someone you do trust). See also + the I<--no-network> option. + ++=item B<--timezone> TIMEZONE ++ ++Set the default timezone of the guest to C. Use a location ++string like C ++ + =item B<--update> + + Do the equivalent of C, C, or whatever +@@ -834,7 +840,7 @@ A new random seed is generated for the guest. + + =item * + +-The hostname is set (I<--hostname>). ++The hostname and timezone are set (I<--hostname>, I<--timezone>). + + =item * + +diff --git a/mllib/Makefile.am b/mllib/Makefile.am +index 67027d2..5568e02 100644 +--- a/mllib/Makefile.am ++++ b/mllib/Makefile.am +@@ -47,6 +47,8 @@ SOURCES = \ + progress.ml \ + random_seed.mli \ + random_seed.ml \ ++ timezone.mli \ ++ timezone.ml \ + tty-c.c \ + tTY.mli \ + tTY.ml \ +@@ -77,6 +79,7 @@ OBJECTS = \ + urandom.cmx \ + random_seed.cmx \ + hostname.cmx \ ++ timezone.cmx \ + firstboot.cmx \ + tTY.cmx \ + fsync.cmx \ +diff --git a/mllib/timezone.ml b/mllib/timezone.ml +new file mode 100644 +index 0000000..8b302d9 +--- /dev/null ++++ b/mllib/timezone.ml +@@ -0,0 +1,39 @@ ++(* Set timezone in virt-sysprep and virt-builder. ++ * Copyright (C) 2014 Red Hat Inc. ++ * ++ * This program is free software; you can redistribute it and/or modify ++ * it under the terms of the GNU General Public License as published by ++ * the Free Software Foundation; either version 2 of the License, or ++ * (at your option) any later version. ++ * ++ * 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 General Public License for more details. ++ * ++ * You should have received a copy of the GNU General Public License along ++ * with this program; if not, write to the Free Software Foundation, Inc., ++ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ++ *) ++ ++open Common_utils ++ ++open Printf ++ ++let set_timezone ~prog (g : Guestfs.guestfs) root timezone = ++ let typ = g#inspect_get_type root in ++ ++ match typ with ++ (* Every known Linux has /etc/localtime be either a copy of or a ++ * symlink to a timezone file in /usr/share/zoneinfo. ++ * Even systemd didn't fuck this up. ++ *) ++ | "linux" -> ++ let target = sprintf "/usr/share/zoneinfo/%s" timezone in ++ if not (g#exists target) then ++ error ~prog "timezone '%s' does not exist, use a location like 'Europe/London'" timezone; ++ g#ln_sf target "/etc/localtime"; ++ true ++ ++ | _ -> ++ false +diff --git a/mllib/timezone.mli b/mllib/timezone.mli +new file mode 100644 +index 0000000..ad0d4b2 +--- /dev/null ++++ b/mllib/timezone.mli +@@ -0,0 +1,22 @@ ++(* Set timezone in virt-sysprep and virt-builder. ++ * Copyright (C) 2014 Red Hat Inc. ++ * ++ * This program is free software; you can redistribute it and/or modify ++ * it under the terms of the GNU General Public License as published by ++ * the Free Software Foundation; either version 2 of the License, or ++ * (at your option) any later version. ++ * ++ * 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 General Public License for more details. ++ * ++ * You should have received a copy of the GNU General Public License along ++ * with this program; if not, write to the Free Software Foundation, Inc., ++ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ++ *) ++ ++val set_timezone : prog:string -> Guestfs.guestfs -> string -> string -> bool ++(** [set_timezone ~prog g root "Europe/London"] sets the default timezone ++ of the guest. Returns [true] if it was able to set the ++ timezone or [false] if not. *) +diff --git a/po/POTFILES-ml b/po/POTFILES-ml +index 8ae6ea9..4c69258 100644 +--- a/po/POTFILES-ml ++++ b/po/POTFILES-ml +@@ -21,6 +21,7 @@ mllib/planner.ml + mllib/progress.ml + mllib/random_seed.ml + mllib/tTY.ml ++mllib/timezone.ml + mllib/uRI.ml + mllib/urandom.ml + resize/resize.ml +@@ -62,6 +63,7 @@ sysprep/sysprep_operation_smolt_uuid.ml + sysprep/sysprep_operation_ssh_hostkeys.ml + sysprep/sysprep_operation_ssh_userdir.ml + sysprep/sysprep_operation_sssd_db_log.ml ++sysprep/sysprep_operation_timezone.ml + sysprep/sysprep_operation_tmp_files.ml + sysprep/sysprep_operation_udev_persistent_net.ml + sysprep/sysprep_operation_user_account.ml +diff --git a/sysprep/Makefile.am b/sysprep/Makefile.am +index 621d2b6..835d4a6 100644 +--- a/sysprep/Makefile.am ++++ b/sysprep/Makefile.am +@@ -65,6 +65,7 @@ operations = \ + ssh_hostkeys \ + ssh_userdir \ + sssd_db_log \ ++ timezone \ + tmp_files \ + udev_persistent_net \ + user_account \ +@@ -92,6 +93,7 @@ OBJECTS = \ + $(top_builddir)/mllib/password.cmx \ + $(top_builddir)/mllib/random_seed.cmx \ + $(top_builddir)/mllib/hostname.cmx \ ++ $(top_builddir)/mllib/timezone.cmx \ + $(top_builddir)/mllib/firstboot.cmx \ + $(top_builddir)/mllib/config.cmx \ + sysprep_operation.cmx \ +diff --git a/sysprep/sysprep_operation_timezone.ml b/sysprep/sysprep_operation_timezone.ml +new file mode 100644 +index 0000000..7557f44 +--- /dev/null ++++ b/sysprep/sysprep_operation_timezone.ml +@@ -0,0 +1,66 @@ ++(* virt-sysprep ++ * Copyright (C) 2014 Red Hat Inc. ++ * ++ * This program is free software; you can redistribute it and/or modify ++ * it under the terms of the GNU General Public License as published by ++ * the Free Software Foundation; either version 2 of the License, or ++ * (at your option) any later version. ++ * ++ * 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 General Public License for more details. ++ * ++ * You should have received a copy of the GNU General Public License along ++ * with this program; if not, write to the Free Software Foundation, Inc., ++ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ++ *) ++ ++open Printf ++ ++open Common_utils ++open Sysprep_operation ++open Common_gettext.Gettext ++ ++module G = Guestfs ++ ++let timezone = ref None ++ ++let timezone_perform (g : Guestfs.guestfs) root = ++ match !timezone with ++ | None -> [] ++ | Some tz -> ++ if Timezone.set_timezone ~prog g root tz then [ `Created_files ] else [] ++ ++let op = { ++ defaults with ++ name = "timezone"; ++ enabled_by_default = true; ++ heading = s_"Change the default timezone of the guest"; ++ ++ pod_description = Some (s_"\ ++This operation changes the default timezone of the guest to the value ++given in the I<--timezone> parameter. ++ ++If the I<--timezone> parameter is not given, then the timezone is not ++changed. ++ ++This parameter affects the default timezone that users see when they log ++in, but they can still change their timezone per-user account."); ++ ++ pod_notes = Some (s_"\ ++Currently this can only set the timezone on Linux guests."); ++ ++ extra_args = [ ++ let set_timezone str = timezone := Some str in ++ { extra_argspec = "--timezone", Arg.String set_timezone, s_"timezone" ^ " " ^ s_"New timezone"; ++ extra_pod_argval = Some "TIMEZONE"; ++ extra_pod_description = s_"\ ++Change the timezone. Use a location string such as C" ++ } ++ ]; ++ ++ perform_on_filesystems = Some timezone_perform; ++} ++ ++let () = register_operation op +-- +1.8.4.2 + diff --git a/0048-builder-docs-Remove-confusing-reference-to-timezone.patch b/0048-builder-docs-Remove-confusing-reference-to-timezone.patch new file mode 100644 index 0000000..5a456f8 --- /dev/null +++ b/0048-builder-docs-Remove-confusing-reference-to-timezone.patch @@ -0,0 +1,27 @@ +From 7317d80d502a8e26321aaed11290ff10b953d59b Mon Sep 17 00:00:00 2001 +From: "Richard W.M. Jones" +Date: Fri, 10 Jan 2014 13:47:05 +0000 +Subject: [PATCH] builder: docs: Remove confusing reference to timezone. + +(cherry picked from commit 1e1b027c1b7c592ae8f04bcef8ffe93b7f2841d4) +--- + builder/virt-builder.pod | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/builder/virt-builder.pod b/builder/virt-builder.pod +index a703346..6db3dd9 100644 +--- a/builder/virt-builder.pod ++++ b/builder/virt-builder.pod +@@ -1233,8 +1233,8 @@ least one character of whitespace (even on blank lines): + notes=This image was prepared using + the following kickstart script: + <-- one space at beginning of line +- timezone Europe/London + part /boot --fstype ext3 ++ ... + + =item C + +-- +1.8.4.2 + diff --git a/0049-builder-Document-how-to-change-keyboard-layout.patch b/0049-builder-Document-how-to-change-keyboard-layout.patch new file mode 100644 index 0000000..fafd728 --- /dev/null +++ b/0049-builder-Document-how-to-change-keyboard-layout.patch @@ -0,0 +1,69 @@ +From cace864fa0bd50a00aeb6df62bb34cf441d25281 Mon Sep 17 00:00:00 2001 +From: "Richard W.M. Jones" +Date: Fri, 10 Jan 2014 14:21:17 +0000 +Subject: [PATCH] builder: Document how to change keyboard layout. + +This is too complex to implement directly in virt-builder. + +Instead we just document how to do it for some common Linux distros +using --run-command, --edit etc. + +(cherry picked from commit 8ae6b6c9ff855f5eaf3f16188b1bcb4ddba095c5) +--- + builder/virt-builder.pod | 40 ++++++++++++++++++++++++++++++++++++++++ + 1 file changed, 40 insertions(+) + +diff --git a/builder/virt-builder.pod b/builder/virt-builder.pod +index 6db3dd9..f81c556 100644 +--- a/builder/virt-builder.pod ++++ b/builder/virt-builder.pod +@@ -779,6 +779,46 @@ The above command will create an C account with no password, + and force the user to set a password when they first log in. There + are other ways to manage passwords, see L for details. + ++=head2 KEYBOARD LAYOUT ++ ++Because there are so many different ways to set the keyboard layout in ++Linux distributions, virt-builder does not yet attempt to have a ++simple command line option. This section describes how to set the ++keyboard for some common Linux distributions. ++ ++=head3 Keyboard layout with systemd ++ ++For distros that use systemd C, use a command like this: ++ ++ virt-builder fedora-20 \ ++ --firstboot-command 'localectl set-keymap uk' ++ ++See L and ++L ++for more details. ++ ++=head3 Keyboard layout using C ++ ++For RHEL E 6, Fedora E 18 and similar, upload or modify the ++keyboard configuration file using the I<--upload>, I<--write> or ++I<--edit> options. For example: ++ ++ virt-builder centos-6 \ ++ --edit '/etc/sysconfig/keyboard: s/^KEYTABLE=.*/KEYTABLE="uk"/' ++ ++The format of this file can be found documented in many places online. ++ ++=head3 Keyboard layout with Debian-derived distros ++ ++For Debian-derived distros using C, upload or ++modify the keyboard file using the I<--upload>, I<--write> or ++I<--edit> options. For example: ++ ++ virt-builder debian-7 \ ++ --edit '/etc/default/keyboard: s/^XKBLAYOUT=.*/XKBLAYOUT="gb"/' ++ ++See L. ++ + =head2 LOG FILE + + Scripts and package installation that runs at build time (I<--run>, +-- +1.8.4.2 + diff --git a/0050-builder-List-install-packages-in-the-same-order-as-o.patch b/0050-builder-List-install-packages-in-the-same-order-as-o.patch new file mode 100644 index 0000000..18e101e --- /dev/null +++ b/0050-builder-List-install-packages-in-the-same-order-as-o.patch @@ -0,0 +1,31 @@ +From 46461012e3fb5a1672346abdff7c16ea2786ee93 Mon Sep 17 00:00:00 2001 +From: "Richard W.M. Jones" +Date: Fri, 10 Jan 2014 17:04:28 +0000 +Subject: [PATCH] builder: List --install packages in the same order as on the + command line. + +Previously the list was reversed. Note this doesn't have any effect +on how the packages are installed since the guest package manager +doesn't care about the order. + +(cherry picked from commit 39bc959c5b3a972e9a12921e002f27aaab2cd5ff) +--- + builder/cmdline.ml | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/builder/cmdline.ml b/builder/cmdline.ml +index 99412bb..813fbd8 100644 +--- a/builder/cmdline.ml ++++ b/builder/cmdline.ml +@@ -311,7 +311,7 @@ read the man page virt-builder(1). + let format = match !format with "" -> None | s -> Some s in + let gpg = !gpg in + let hostname = !hostname in +- let install = !install in ++ let install = List.rev !install in + let list_long = !list_long in + let memsize = !memsize in + let mkdirs = List.rev !mkdirs in +-- +1.8.4.2 + diff --git a/0051-builder-Add-link-option-for-creating-symbolic-links.patch b/0051-builder-Add-link-option-for-creating-symbolic-links.patch new file mode 100644 index 0000000..36bbb3f --- /dev/null +++ b/0051-builder-Add-link-option-for-creating-symbolic-links.patch @@ -0,0 +1,147 @@ +From 289e050b75532cce6bfb9d75a8646f02b189b44f Mon Sep 17 00:00:00 2001 +From: "Richard W.M. Jones" +Date: Fri, 10 Jan 2014 21:18:07 +0000 +Subject: [PATCH] builder: Add --link option for creating symbolic links. + +This is useful for configuring systemd services. + +(cherry picked from commit 6d4ac696e54902baf7d76de527b3df3d66c7dfa1) +--- + builder/builder.ml | 13 ++++++++++++- + builder/cmdline.ml | 16 +++++++++++++++- + builder/test-virt-builder.sh | 2 ++ + builder/virt-builder.pod | 12 ++++++++++++ + 4 files changed, 41 insertions(+), 2 deletions(-) + +diff --git a/builder/builder.ml b/builder/builder.ml +index 90300a3..16ffa7a 100644 +--- a/builder/builder.ml ++++ b/builder/builder.ml +@@ -37,7 +37,8 @@ let main () = + (* Command line argument parsing - see cmdline.ml. *) + let mode, arg, + attach, cache, check_signature, curl, debug, delete, edit, +- firstboot, run, format, gpg, hostname, install, list_long, memsize, mkdirs, ++ firstboot, run, format, gpg, hostname, install, list_long, links, ++ memsize, mkdirs, + network, output, password_crypto, quiet, root_password, scrub, + scrub_logfile, size, smp, sources, sync, timezone, update, upload, + writes = +@@ -837,6 +838,16 @@ exec >>%s 2>&1 + g#rm_rf file + ) delete; + ++ (* Symbolic links. *) ++ List.iter ( ++ fun (target, links) -> ++ List.iter ( ++ fun link -> ++ msg (f_"Linking: %s -> %s") link target; ++ g#ln_sf target link ++ ) links ++ ) links; ++ + (* Scrub files. *) + List.iter ( + fun file -> +diff --git a/builder/cmdline.ml b/builder/cmdline.ml +index 813fbd8..58e8a6b 100644 +--- a/builder/cmdline.ml ++++ b/builder/cmdline.ml +@@ -117,6 +117,17 @@ let parse_cmdline () = + install := pkgs @ !install + in + ++ let links = ref [] in ++ let add_link arg = ++ let target, lns = ++ match string_nsplit ":" arg with ++ | [] | [_] -> ++ eprintf (f_"%s: invalid --link format, see the man page.\n") prog; ++ exit 1 ++ | target :: lns -> target, lns in ++ links := (target, lns) :: !links ++ in ++ + let list_long = ref false in + + let memsize = ref None in +@@ -237,6 +248,7 @@ let parse_cmdline () = + "--gpg", Arg.Set_string gpg, "gpg" ^ " " ^ s_"Set GPG binary/command"; + "--hostname", Arg.String set_hostname, "hostname" ^ " " ^ s_"Set the hostname"; + "--install", Arg.String add_install, "pkg,pkg" ^ " " ^ s_"Add package(s) to install"; ++ "--link", Arg.String add_link, "target:link.." ^ " " ^ s_"Create symbolic links"; + "-l", Arg.Unit list_mode, " " ^ s_"List available templates"; + "--list", Arg.Unit list_mode, ditto; + "--long", Arg.Set list_long, ditto; +@@ -313,6 +325,7 @@ read the man page virt-builder(1). + let hostname = !hostname in + let install = List.rev !install in + let list_long = !list_long in ++ let links = List.rev !links in + let memsize = !memsize in + let mkdirs = List.rev !mkdirs in + let network = !network in +@@ -425,7 +438,8 @@ read the man page virt-builder(1). + + mode, arg, + attach, cache, check_signature, curl, debug, delete, edit, +- firstboot, run, format, gpg, hostname, install, list_long, memsize, mkdirs, ++ firstboot, run, format, gpg, hostname, install, list_long, links, ++ memsize, mkdirs, + network, output, password_crypto, quiet, root_password, scrub, + scrub_logfile, size, smp, sources, sync, timezone, update, upload, + writes +diff --git a/builder/test-virt-builder.sh b/builder/test-virt-builder.sh +index 8d2766a..47d20a4 100755 +--- a/builder/test-virt-builder.sh ++++ b/builder/test-virt-builder.sh +@@ -60,6 +60,8 @@ $VG ./virt-builder phony-fedora \ + --upload Makefile:/Makefile \ + --upload Makefile:/etc/foo/bar/baz \ + --delete /Makefile \ ++ --link /etc/foo/bar/baz/foo:/foo \ ++ --link /etc/foo/bar/baz/foo:/foo1:/foo2:/foo3 \ + --firstboot Makefile --firstboot-command 'echo "hello"' \ + --firstboot-install "minicom,inkscape" + +diff --git a/builder/virt-builder.pod b/builder/virt-builder.pod +index f81c556..584a0e0 100644 +--- a/builder/virt-builder.pod ++++ b/builder/virt-builder.pod +@@ -23,6 +23,7 @@ virt-builder - Build virtual machine images quickly + [--mkdir DIR] + [--write FILE:CONTENT] + [--upload FILE:DEST] ++ [--link TARGET:LINK[:LINK]] + [--edit FILE:EXPR] + [--delete FILE] [--scrub FILE] + [--run SCRIPT] [--run-command 'CMD ARGS ...'] +@@ -353,6 +354,13 @@ L. + + See also I<--update>. + ++=item B<--link TARGET:LINK> ++ ++=item B<--link TARGET:LINK[:LINK...]> ++ ++Create symbolic link(s) in the guest, starting at C and ++pointing at C. ++ + =item B<-l> + + =item B<--list> +@@ -916,6 +924,10 @@ Files are deleted (I<--delete>, I<--scrub>). + + =item * + ++Symbolic links are created (I<--link). ++ ++=item * ++ + Firstboot scripts are installed (I<--firstboot>, + I<--firstboot-command>, I<--firstboot-install>). + +-- +1.8.4.2 + diff --git a/0052-builder-Document-how-to-change-the-language-locale-o.patch b/0052-builder-Document-how-to-change-the-language-locale-o.patch new file mode 100644 index 0000000..715ee48 --- /dev/null +++ b/0052-builder-Document-how-to-change-the-language-locale-o.patch @@ -0,0 +1,55 @@ +From 67d5d90d6d5f8a983ddd39616f0e2d43ba4e326d Mon Sep 17 00:00:00 2001 +From: "Richard W.M. Jones" +Date: Fri, 10 Jan 2014 19:48:28 +0000 +Subject: [PATCH] builder: Document how to change the language/locale of a new + guest. + +(cherry picked from commit 7e8ad13e863a5c87e3da47288bcecdb88ca0e4cb) +--- + builder/virt-builder.pod | 30 ++++++++++++++++++++++++++++++ + 1 file changed, 30 insertions(+) + +diff --git a/builder/virt-builder.pod b/builder/virt-builder.pod +index 584a0e0..031f3d7 100644 +--- a/builder/virt-builder.pod ++++ b/builder/virt-builder.pod +@@ -827,6 +827,36 @@ I<--edit> options. For example: + + See L. + ++=head2 LANGUAGE ++ ++Most Linux distributions support multiple locale settings so that you ++can have guest messages printed in another language such as Russian. ++However there is no single setting which controls this, since extra ++packages may need to be installed to support console and X fonts and ++keyboard input methods. The packages required, and their ++configuration is highly distro-specific, and it is outside the scope ++of virt-builder to do this. ++ ++=begin comment ++ ++This section contains examples for some common Linux distributions. ++ ++=head3 Setting Japanese in Fedora 20 ++ ++XXX This does not work. ++ ++ virt-builder fedora-20 \ ++ --size 20G \ ++ --update \ ++ --install @gnome-desktop --install @japanese-support \ ++ --firstboot-command 'localectl set-locale LANG=ja_JP.utf8' \ ++ --firstboot-command 'localectl set-keymap jp' \ ++ --firstboot-command 'systemctl enable gdm.service' \ ++ --firstboot-command 'systemctl start gdm.service' \ ++ --link /usr/lib/systemd/system/graphical.target:/etc/systemd/system/default.target ++ ++=end comment ++ + =head2 LOG FILE + + Scripts and package installation that runs at build time (I<--run>, +-- +1.8.4.2 + diff --git a/0053-builder-Document-how-to-set-up-local-mirrors-for-per.patch b/0053-builder-Document-how-to-set-up-local-mirrors-for-per.patch new file mode 100644 index 0000000..91ca3f5 --- /dev/null +++ b/0053-builder-Document-how-to-set-up-local-mirrors-for-per.patch @@ -0,0 +1,86 @@ +From 20adf1506b99ae4c7a2ed901e6d14ba83e017325 Mon Sep 17 00:00:00 2001 +From: "Richard W.M. Jones" +Date: Fri, 10 Jan 2014 19:49:02 +0000 +Subject: [PATCH] builder: Document how to set up local mirrors for performance + and reliability. + +(cherry picked from commit f40e44c2f97a7fa17e6078d958ae2779b7ca83c7) +--- + builder/virt-builder.pod | 52 +++++++++++++++++++++++++++++++++++++++++++++--- + 1 file changed, 49 insertions(+), 3 deletions(-) + +diff --git a/builder/virt-builder.pod b/builder/virt-builder.pod +index 031f3d7..000dfae 100644 +--- a/builder/virt-builder.pod ++++ b/builder/virt-builder.pod +@@ -1410,6 +1410,8 @@ The index is always encoded in UTF-8. + + =head2 CACHING + ++=head3 Caching templates ++ + Since the templates are usually very large, downloaded templates are + cached in the user's home directory. + +@@ -1434,11 +1436,55 @@ To disable the template cache, use I<--no-cache>. + Only templates are cached. The index and detached digital signatures + are not cached. + ++=head3 Caching packages ++ + Virt-builder uses L to download files and it also uses the + current C (etc) settings when installing packages +-(I<--install>, I<--update>). You may therefore want to set those +-environment variables in order to maximize the amount of local caching +-that happens. See L and L. ++(I<--install>, I<--update>). ++ ++You may therefore want to set those environment variables in order to ++maximize the amount of local caching that happens. See ++L and L. ++ ++=head3 Local mirrors ++ ++To increase both speed and reliability of installing packages, you can ++set up a local mirror of the target distribution, and point the guest ++package manager at that. ++ ++Because of the order in which each phase of installation happens, you ++cannot use I<--write> (to point the package manager at a repo) ++followed by I<--install> (to install from that repo). The I<--write> ++and I<--install> steps run in the opposite order, regardless of their ++order on the command line. You have to do this using I<--run-command> ++instead of I<--install>. ++ ++=head4 Using a local mirror with Fedora ++ ++To install a Fedora guest using a local mirror: ++ ++ virt-builder fedora 20 \ ++ --edit '/etc/yum.repos.d/fedora.repo: ++ s{.*baseurl=.*}{baseurl=http://example.com/mirror/}; ++ s{.*metalink=.*}{}; ++ ' \ ++ --edit '/etc/yum.repos.d/fedora-updates.repo: ++ s{.*baseurl=.*}{baseurl=http://example.com/mirror-updates/}; ++ s{.*metalink=.*}{}; ++ ' \ ++ --run-command 'yum -y update' \ ++ --run-command 'yum -y install pkg1 pkg2 ...' ++ ++=head4 Using a local mirror with Debian ++ ++Assuming that you are using C to mirror the repository, you ++should create a new C file to point to your proxy (see ++L) and then do: ++ ++ virt-builder fedora 20 \ ++ --upload sources.list:/etc/apt/sources.list \ ++ --run-command 'apt-get -y update' \ ++ --run-command 'apt-get -y install pkg1 pkg2 ...' + + =head2 DIGITAL SIGNATURES + +-- +1.8.4.2 + diff --git a/0054-builder-Document-that-SELinux-guests-will-reboot-for.patch b/0054-builder-Document-that-SELinux-guests-will-reboot-for.patch new file mode 100644 index 0000000..26c4b54 --- /dev/null +++ b/0054-builder-Document-that-SELinux-guests-will-reboot-for.patch @@ -0,0 +1,37 @@ +From 23c4148eed3193660f173baad89a7e1ce582248b Mon Sep 17 00:00:00 2001 +From: "Richard W.M. Jones" +Date: Fri, 10 Jan 2014 21:17:09 +0000 +Subject: [PATCH] builder: Document that SELinux guests will reboot for + autorelabel. + +(cherry picked from commit a8c9aedd51a88b3e08d6cc2580053d44b11f716b) +--- + builder/virt-builder.pod | 12 ++++++++++++ + 1 file changed, 12 insertions(+) + +diff --git a/builder/virt-builder.pod b/builder/virt-builder.pod +index 000dfae..c1adfa8 100644 +--- a/builder/virt-builder.pod ++++ b/builder/virt-builder.pod +@@ -1607,6 +1607,18 @@ fixed in a future version. + The qcow2 output format is not supported by UML. You can only create + raw-format guests. + ++=head2 SELINUX ++ ++Guests which use SELinux (such as Fedora and Red Hat Enterprise Linux) ++require that each file has a correct SELinux label. ++ ++Since virt-builder does not know how to give new files a correct ++label, it touches C in the guest and relies on the ++guest to relabel itself at first boot. ++ ++This usually means that these guests will reboot themselves once the ++first time you use them. This is normal, and harmless. ++ + =head1 ENVIRONMENT VARIABLES + + For other environment variables which affect all libguestfs programs, +-- +1.8.4.2 + diff --git a/0055-builder-Document-how-to-set-Japanese-language-suppor.patch b/0055-builder-Document-how-to-set-Japanese-language-suppor.patch new file mode 100644 index 0000000..0e61be3 --- /dev/null +++ b/0055-builder-Document-how-to-set-Japanese-language-suppor.patch @@ -0,0 +1,59 @@ +From bf1c985746c136b39ed0a60817242731a09d2a19 Mon Sep 17 00:00:00 2001 +From: "Richard W.M. Jones" +Date: Sun, 12 Jan 2014 17:06:02 +0000 +Subject: [PATCH] builder: Document how to set Japanese language support in + Fedora 20. + +This updates/fixes commit 7e8ad13e863a5c87e3da47288bcecdb88ca0e4cb. + +(cherry picked from commit fcdea83c6b9dc94a565a819a9f42e0c4721166e8) +--- + builder/virt-builder.pod | 18 +++++++----------- + 1 file changed, 7 insertions(+), 11 deletions(-) + +diff --git a/builder/virt-builder.pod b/builder/virt-builder.pod +index c1adfa8..f7eb9e9 100644 +--- a/builder/virt-builder.pod ++++ b/builder/virt-builder.pod +@@ -831,31 +831,27 @@ See L. + + Most Linux distributions support multiple locale settings so that you + can have guest messages printed in another language such as Russian. ++ + However there is no single setting which controls this, since extra +-packages may need to be installed to support console and X fonts and ++packages may need to be installed to support console and X fonts, and + keyboard input methods. The packages required, and their + configuration is highly distro-specific, and it is outside the scope + of virt-builder to do this. + +-=begin comment +- + This section contains examples for some common Linux distributions. + + =head3 Setting Japanese in Fedora 20 + +-XXX This does not work. +- + virt-builder fedora-20 \ + --size 20G \ + --update \ +- --install @gnome-desktop --install @japanese-support \ ++ --install @japanese-support \ ++ --install @xfce \ ++ --install xorg-x11-server-Xorg,xorg-x11-drivers,rsyslog \ ++ --link /usr/lib/systemd/system/graphical.target:/etc/systemd/system/default.target \ + --firstboot-command 'localectl set-locale LANG=ja_JP.utf8' \ + --firstboot-command 'localectl set-keymap jp' \ +- --firstboot-command 'systemctl enable gdm.service' \ +- --firstboot-command 'systemctl start gdm.service' \ +- --link /usr/lib/systemd/system/graphical.target:/etc/systemd/system/default.target +- +-=end comment ++ --firstboot-command 'systemctl isolate graphical.target' + + =head2 LOG FILE + +-- +1.8.4.2 + diff --git a/0056-builder-Fix-virt-builder-test.patch b/0056-builder-Fix-virt-builder-test.patch new file mode 100644 index 0000000..db00860 --- /dev/null +++ b/0056-builder-Fix-virt-builder-test.patch @@ -0,0 +1,40 @@ +From d3dcc80c16b3731fefcde76659661b44b1bb881b Mon Sep 17 00:00:00 2001 +From: "Richard W.M. Jones" +Date: Sun, 12 Jan 2014 17:49:48 +0000 +Subject: [PATCH] builder: Fix virt-builder test. + +Add Europe/London timezone to phony Fedora guest. + +This fixes commit dd1bfea513658368afd3728e0c5bf8ab6041cd1f. + +(cherry picked from commit 7500ae3f75f4650c18f2a8433c6b5edcca6e88a6) +--- + tests/guests/guest-aux/make-fedora-img.pl | 6 +++++- + 1 file changed, 5 insertions(+), 1 deletion(-) + +diff --git a/tests/guests/guest-aux/make-fedora-img.pl b/tests/guests/guest-aux/make-fedora-img.pl +index 7c96eb8..0537bd2 100755 +--- a/tests/guests/guest-aux/make-fedora-img.pl ++++ b/tests/guests/guest-aux/make-fedora-img.pl +@@ -1,6 +1,6 @@ + #!/usr/bin/perl + # libguestfs +-# Copyright (C) 2010-2012 Red Hat Inc. ++# Copyright (C) 2010-2014 Red Hat Inc. + # + # This program is free software; you can redistribute it and/or modify + # it under the terms of the GNU General Public License as published by +@@ -201,6 +201,10 @@ $g->mkdir ('/bin'); + $g->mkdir ('/etc'); + $g->mkdir ('/etc/sysconfig'); + $g->mkdir ('/usr'); ++$g->mkdir ('/usr/share'); ++$g->mkdir ('/usr/share/zoneinfo'); ++$g->mkdir ('/usr/share/zoneinfo/Europe'); ++$g->touch ('/usr/share/zoneinfo/Europe/London'); + $g->mkdir_p ('/var/lib/rpm'); + $g->mkdir_p ('/var/log/journal'); + +-- +1.8.4.2 + diff --git a/0057-builder-website-Add-CirrOS-signature-file-to-EXTRA_D.patch b/0057-builder-website-Add-CirrOS-signature-file-to-EXTRA_D.patch new file mode 100644 index 0000000..d470e9b --- /dev/null +++ b/0057-builder-website-Add-CirrOS-signature-file-to-EXTRA_D.patch @@ -0,0 +1,27 @@ +From ceef6f1e6e8d8c23d6fa859caf0c1565ced628a9 Mon Sep 17 00:00:00 2001 +From: "Richard W.M. Jones" +Date: Sun, 12 Jan 2014 18:06:26 +0000 +Subject: [PATCH] builder/website: Add CirrOS signature file to EXTRA_DIST. + +This fixes commit 40b88fdbc76515fd21b33f54587c7f4f7b6e9715. + +(cherry picked from commit ed43cc12c4492510e38eee9c7f8a5076956e4066) +--- + builder/website/Makefile.am | 1 + + 1 file changed, 1 insertion(+) + +diff --git a/builder/website/Makefile.am b/builder/website/Makefile.am +index dff186f..a5b1bcf 100644 +--- a/builder/website/Makefile.am ++++ b/builder/website/Makefile.am +@@ -27,6 +27,7 @@ EXTRA_DIST = \ + index.asc \ + centos.sh \ + centos-*.xz.sig \ ++ cirros-*.xz.sig \ + debian.preseed \ + debian.sh \ + debian-*.xz.sig \ +-- +1.8.4.2 + diff --git a/libguestfs.spec b/libguestfs.spec index 81eae9d..f994a55 100644 --- a/libguestfs.spec +++ b/libguestfs.spec @@ -12,7 +12,7 @@ Summary: Access and modify virtual machine disk images Name: libguestfs Epoch: 1 Version: 1.24.4 -Release: 1%{?dist} +Release: 2%{?dist} License: LGPLv2+ # Source and patches. @@ -63,6 +63,25 @@ Patch0035: 0035-builder-Refuse-to-write-to-a-char-device-or-dev-null.patch Patch0036: 0036-builder-Remove-blank-line.patch Patch0037: 0037-builder-Add-update-option-to-update-template-core-pa.patch Patch0038: 0038-launch-libvirt-Don-t-default-to-using-NULL-for-libvi.patch +Patch0039: 0039-builder-Add-CirrOS-0.3.1-disk-image.patch +Patch0040: 0040-builder-Note-in-man-page-how-to-specify-size-in-byte.patch +Patch0041: 0041-builder-Pass-prog-global-program-name-around.patch +Patch0042: 0042-mllib-Add-library-function-to-run-external-command-a.patch +Patch0043: 0043-builder-Fix-handling-of-size-parameter.patch +Patch0044: 0044-libvirt-auth-Provide-a-friendlier-wrapper-around-vir.patch +Patch0045: 0045-tests-Add-a-regression-test-of-libvirt-authenticatio.patch +Patch0046: 0046-tests-Add-a-regression-test-for-libvirt-authenticati.patch +Patch0047: 0047-sysprep-builder-Add-timezone-option-to-set-timezone-.patch +Patch0048: 0048-builder-docs-Remove-confusing-reference-to-timezone.patch +Patch0049: 0049-builder-Document-how-to-change-keyboard-layout.patch +Patch0050: 0050-builder-List-install-packages-in-the-same-order-as-o.patch +Patch0051: 0051-builder-Add-link-option-for-creating-symbolic-links.patch +Patch0052: 0052-builder-Document-how-to-change-the-language-locale-o.patch +Patch0053: 0053-builder-Document-how-to-set-up-local-mirrors-for-per.patch +Patch0054: 0054-builder-Document-that-SELinux-guests-will-reboot-for.patch +Patch0055: 0055-builder-Document-how-to-set-Japanese-language-suppor.patch +Patch0056: 0056-builder-Fix-virt-builder-test.patch +Patch0057: 0057-builder-website-Add-CirrOS-signature-file-to-EXTRA_D.patch # Add any non-git patches here. # Use git for patch management. @@ -1054,6 +1073,9 @@ mkdir -p $RPM_BUILD_ROOT%{_localstatedir}/run/libguestfs %changelog +* Sun Jan 12 2014 Richard W.M. Jones - 1:1.24.4-2 +- Backport more virt-builder patches from upstream to Fedora. + * Fri Jan 3 2014 Richard W.M. Jones - 1:1.24.4-1 - New stable branch version 1.24.4. - Fix source URL.