def create_rescue_image_with_postinst_scripts_test(self, exec_with_redirect): """Test creation of rescue image with postinst scripts.""" kernel_version_list = ["kernel-v1.fc2000.x86_64", "kernel-sad-kernel"] postinst_scripts = ["01-create", "02-rule", "03-aaaand-we-lost"] with TemporaryDirectory() as temp: self._prepare_rescue_test_dirs( temp, fake_machine_id=True, fake_new_kernel_pkg=False, fake_postinst_scripts_list=postinst_scripts) with self.assertLogs(level="WARNING") as cm: create_rescue_image(temp, kernel_version_list) self.assertTrue( any( map(lambda x: "new-kernel-pkg does not exist" in x, cm.output))) calls = [call("systemd-machine-id-setup", [], root=temp)] for kernel in kernel_version_list: for script in sorted(postinst_scripts): script = os.path.join("/etc/kernel/postinst.d", script) kernel_path = "/boot/vmlinuz-{}".format(kernel) calls.append(call(script, [kernel, kernel_path], root=temp)) exec_with_redirect.assert_has_calls(calls)
def run(self): """Run installation of the payload from a tarball.""" cmd = "tar" # preserve: ACL's, xattrs, and SELinux context args = [ "--numeric-owner", "--selinux", "--acls", "--xattrs", "--xattrs-include", "*", "--exclude", "dev/*", "--exclude", "proc/*", "--exclude", "tmp/*", "--exclude", "sys/*", "--exclude", "run/*", "--exclude", "boot/*rescue*", "--exclude", "boot/loader", "--exclude", "boot/efi/loader", "--exclude", "etc/machine-id", "-xaf", self._tarfile_path, "-C", self._dest_path ] try: rc = execWithRedirect(cmd, args) except (OSError, RuntimeError) as e: msg = None err = str(e) log.error(err) else: err = None msg = "%s exited with code %d" % (cmd, rc) log.info(msg) if err: raise InstallError(err or msg) create_rescue_image(self._dest_path, self._kernel_version_list)
def run(self): """Run installation of the payload from image.""" # TODO: remove this check for None when Live Image payload will support sources # The None check is just a temporary hack that Live OS has source but Live Image don't if self._source is not None and not self._source.is_ready(): raise InstallError("Source is not set up!") cmd = "rsync" # preserve: permissions, owners, groups, ACL's, xattrs, times, # symlinks, hardlinks # go recursively, include devices and special files, don't cross # file system boundaries # TODO: source will provide us source path instead of using constant here args = [ "-pogAXtlHrDx", "--exclude", "/dev/", "--exclude", "/proc/", "--exclude", "/tmp/*", "--exclude", "/sys/", "--exclude", "/run/", "--exclude", "/boot/*rescue*", "--exclude", "/boot/loader/", "--exclude", "/boot/efi/loader/", "--exclude", "/etc/machine-id", INSTALL_TREE + "/", self._dest_path ] try: rc = execWithRedirect(cmd, args) except (OSError, RuntimeError) as e: msg = None err = str(e) log.error(err) else: err = None msg = "%s exited with code %d" % (cmd, rc) log.info(msg) if err or rc == 11: raise InstallError(err or msg) create_rescue_image(self._dest_path, self._kernel_version_list)
def create_rescue_image_without_machine_id_test(self, exec_with_redirect): """Test creation of rescue image without machine-id file.""" kernel_version_list = ["kernel-v1.fc2000.x86_64", "kernel-sad-kernel"] with TemporaryDirectory() as temp: self._prepare_rescue_test_dirs(temp, fake_machine_id=False, fake_new_kernel_pkg=True, fake_postinst_scripts_list=[]) create_rescue_image(temp, kernel_version_list) calls = [call("systemd-machine-id-setup", [], root=temp)] for kernel in kernel_version_list: calls.append( call("new-kernel-pkg", ["--rpmposttrans", kernel], root=temp)) exec_with_redirect.assert_has_calls(calls)