def test_nfs_combine(self): """Test combination of parse and create nfs functions.""" host = "host" path = "/path/to/somewhere" options = "options" url = util.create_nfs_url(host, path, options) self.assertEqual(util.parse_nfs_url(url), (options, host, path)) url = "nfs:options:host:/my/path" (options, host, path) = util.parse_nfs_url(url) self.assertEqual(util.create_nfs_url(host, path, options), url)
def run(self): """Set up the installation source.""" log.debug("Setting up NFS source: %s", self._url) for mount_point in [self._device_mount, self._iso_mount]: if os.path.ismount(mount_point): raise SourceSetupError("The mount point {} is already in use.".format( mount_point )) options, host, path = parse_nfs_url(self._url) path, image = self._split_iso_from_path(path) try: self._mount_nfs(host, options, path) except PayloadSetupError: raise SourceSetupError("Could not mount NFS url '{}'".format(self._url)) iso_source_path = join_paths(self._device_mount, image) if image else self._device_mount iso_name = find_and_mount_iso_image(iso_source_path, self._iso_mount) if iso_name: log.debug("Using the ISO '%s' mounted at '%s'.", iso_name, self._iso_mount) return self._iso_mount if verify_valid_repository(self._device_mount): log.debug("Using the directory at '%s'.", self._device_mount) return self._device_mount # nothing found unmount the existing device unmount(self._device_mount) raise SourceSetupError( "Nothing useful found for NFS source at {}".format(self._url))
def _get_nfs(self): """Get the NFS options, host and path of the current source.""" source_proxy = self.payload.get_source_proxy() if source_proxy.Type == SOURCE_TYPE_NFS: return parse_nfs_url(source_proxy.URL) return "", "", ""
def setup_kickstart(self, data): """Setup the kickstart data.""" (opts, host, path) = parse_nfs_url(self.url) data.nfs.server = host data.nfs.dir = path data.nfs.opts = opts data.nfs.seen = True
def test_parse_nfs_url(self): """Test parseNfsUrl.""" # empty NFS url should return 3 blanks assert util.parse_nfs_url("") == ("", "", "") # the string is delimited by :, there is one prefix and 3 parts, # the prefix is discarded and all parts after the 3th part # are also discarded assert util.parse_nfs_url("nfs:options:host:path") == \ ("options", "host", "path") assert util.parse_nfs_url("nfs:options:host:path:foo:bar") == \ ("options", "host", "path") # if there is only prefix & 2 parts, # the two parts are host and path assert util.parse_nfs_url("nfs://host:path") == \ ("", "host", "path") assert util.parse_nfs_url("nfs:host:path") == \ ("", "host", "path") # if there is only a prefix and single part, # the part is the host assert util.parse_nfs_url("nfs://host") == \ ("", "host", "") assert util.parse_nfs_url("nfs:host") == \ ("", "host", "")
def _mount_nfs(self): options, host, path = parse_nfs_url(self._url) if not options: options = "nolock" elif "nolock" not in options: options += ",nolock" mount("{}:{}".format(host, path), self._device_mount, fstype="nfs", options=options)
def parse_repo_cmdline_string(cls, cmdline): """Parse cmdline string to source class.""" if cls.is_cdrom(cmdline): return CDRomSource() elif cls.is_nfs(cmdline): nfs_options, server, path = parse_nfs_url(cmdline) return NFSSource(server, path, nfs_options) elif cls.is_harddrive(cmdline): url = cmdline.split(":", 1)[1] url_parts = url.split(":") device = url_parts[0] path = "" if len(url_parts) == 2: path = url_parts[1] elif len(url_parts) == 3: path = url_parts[2] return HDDSource(device, path) elif cls.is_http(cmdline): # installation source specified by bootoption # overrides source set from kickstart; # the kickstart might have specified a mirror list, # so we need to clear it here if plain url source is provided # by a bootoption, because having both url & mirror list # set at once is not supported and breaks dnf in # unpredictable ways return HTTPSource(cmdline) elif cls.is_https(cmdline): return HTTPSSource(cmdline) elif cls.is_ftp(cmdline): return FTPSource(cmdline) elif cls.is_file(cmdline): return FileSource(cmdline) elif cls.is_hmc(cmdline): return HMCSource() else: raise PayloadSourceTypeUnrecognized( "Can't find source type for {}".format(cmdline))
def test_parse_nfs_url(self): """Test parseNfsUrl.""" # empty NFS url should return 3 blanks self.assertEqual(util.parse_nfs_url(""), ("", "", "")) # the string is delimited by :, there is one prefix and 3 parts, # the prefix is discarded and all parts after the 3th part # are also discarded self.assertEqual(util.parse_nfs_url("discard:options:host:path"), ("options", "host", "path")) self.assertEqual( util.parse_nfs_url("discard:options:host:path:foo:bar"), ("options", "host", "path")) self.assertEqual(util.parse_nfs_url(":options:host:path::"), ("options", "host", "path")) self.assertEqual(util.parse_nfs_url(":::::"), ("", "", "")) # if there is only prefix & 2 parts, # the two parts are host and path self.assertEqual(util.parse_nfs_url("prefix:host:path"), ("", "host", "path")) self.assertEqual(util.parse_nfs_url(":host:path"), ("", "host", "path")) self.assertEqual(util.parse_nfs_url("::"), ("", "", "")) # if there is only a prefix and single part, # the part is the host self.assertEqual(util.parse_nfs_url("prefix:host"), ("", "host", "")) self.assertEqual(util.parse_nfs_url(":host"), ("", "host", "")) self.assertEqual(util.parse_nfs_url(":"), ("", "", ""))