def test_repository_with_metadata(self): """Test with one driver disk repository.""" with tempfile.TemporaryDirectory() as d: make_directories(join_paths(d, "DD-1")) make_directories(join_paths(d, "DD-1", "repodata")) touch(join_paths(d, "DD-1", "x.rpm")) (r, *rs) = generate_driver_disk_repositories(d) assert rs == [] assert r.name == "DD-1" assert r.url == "file://{}/DD-1".format(d)
def test_delete_existing_file(self): """Delete a file that exists.""" with tempfile.TemporaryDirectory() as d: image_path = join_paths(d, "image.img") touch(image_path) assert os.path.exists(image_path) # Delete the file. task = RemoveImageTask(image_path) task.run() assert not os.path.exists(image_path)
def test_get_kernel_version_list(self): """Test the get_kernel_version_list method.""" with tempfile.TemporaryDirectory() as tmp: # Create the image source. image_source = self._create_source() image_source._mount_point = tmp # Create a fake kernel file. os.makedirs(join_paths(tmp, "boot")) kernel_file = join_paths(tmp, "boot", "vmlinuz-1.2-3.x86_64") touch(kernel_file) self.module._update_kernel_version_list(image_source) assert self.module.get_kernel_version_list() == ["1.2-3.x86_64"]
def test_touch(self): """Test if the touch function correctly creates empty files""" test_dir = tempfile.mkdtemp() try: file_path = os.path.join(test_dir, "EMPTY_FILE") # try to create an empty file with touch() touch(file_path) # check if it exists & is a file assert os.path.isfile(file_path) # check if the file is empty assert os.stat(file_path).st_size == 0 finally: shutil.rmtree(test_dir)
def _create_tar(self, files): """Create a new tarball.""" # Create the content. for path in files: file_path = join_paths(self.directory, path) make_directories(os.path.dirname(file_path)) touch(file_path) # Create a local tarball. with tarfile.open(self.tarball, "w") as tar: for path in files: tar.add(join_paths(self.directory, path), path) tar.list() # Set up the configuration data. self.data.url = "file://" + self.tarball
def _create_image(self, files, mount_task_cls): """Create a fake image.""" # Create the image. touch(self.image) # Set up the configuration data. self.data.url = "file://" + self.image # Set up the mount point. os.makedirs(self.mount_point) for path in files: file_path = join_paths(self.mount_point, path) make_directories(os.path.dirname(file_path)) touch(file_path) mount_task = mount_task_cls() mount_task.run.return_value = self.mount_point
def test_mount_iso(self, exec_mock, mount_mock): """Mount an ISO file in the LiveOS directory.""" exec_mock.return_value = 0 mount_mock.return_value = 0 with self._create_directory(): iso_dir = join_paths(self.image_mount, "LiveOS") os.makedirs(iso_dir) iso_path = join_paths(iso_dir, "iso.img") touch(iso_path) assert self._run_task() == self.iso_mount exec_mock.assert_called_once_with("mount", ["--make-rprivate", "/"]) assert mount_mock.mock_calls == [ call(self.image_path, self.image_mount, fstype="auto", options="ro"), call(iso_path, self.iso_mount, fstype="auto", options="ro") ]
def test_repositories(self): """Test with multiple driver disk repositories.""" with tempfile.TemporaryDirectory() as d: make_directories(join_paths(d, "DD-1")) touch(join_paths(d, "DD-1", "x.rpm")) make_directories(join_paths(d, "DD-2")) touch(join_paths(d, "DD-2", "y.rpm")) make_directories(join_paths(d, "DD-3")) touch(join_paths(d, "DD-3", "z.rpm")) (r1, r2, r3, *rs) = generate_driver_disk_repositories(d) assert rs == [] assert r1.name == "DD-1" assert r1.url == "file://{}/DD-1".format(d) assert r2.name == "DD-2" assert r2.url == "file://{}/DD-2".format(d) assert r3.name == "DD-3" assert r3.url == "file://{}/DD-3".format(d)
def _enable_reconfig_mode(self): """Write the reconfig mode trigger file.""" log.debug("Initial Setup reconfiguration mode will be enabled.") touch(os.path.join(self._sysroot, "etc/reconfigSys"))
def _make_file(self, root, name, uid, gid): touch(root + name) os.chown(root + name, uid, gid)