summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDarryl L. Pierce <dpierce@redhat.com>2009-01-12 12:42:15 -0500
committerDarryl L. Pierce <dpierce@redhat.com>2009-01-12 13:48:41 -0500
commit33b10868a6e4cb7205f01fc20668af55fa803705 (patch)
treedd38845ced370ab1c143fec5c89ba78481ba3653
parent329a224ce409d386ffab8dd117c2f8a9c325142d (diff)
downloadcobbler-33b10868a6e4cb7205f01fc20668af55fa803705.tar.gz
cobbler-33b10868a6e4cb7205f01fc20668af55fa803705.tar.xz
cobbler-33b10868a6e4cb7205f01fc20668af55fa803705.zip
Fixed the conditional statements for image tests and cleaned up
the hostname handling.
-rw-r--r--cobbler/item_image.py20
-rw-r--r--cobbler/test_basic.py9
2 files changed, 24 insertions, 5 deletions
diff --git a/cobbler/item_image.py b/cobbler/item_image.py
index 481951d8..b11dc9c0 100644
--- a/cobbler/item_image.py
+++ b/cobbler/item_image.py
@@ -119,6 +119,7 @@ class Image(item.Item):
* hostname:/path/to/the/filename.ext
* /path/to/the/filename.ext
"""
+ print "STARTING WITH FILENAME: %s" % filename
uri = ""
auth = hostname = path = ""
# we'll discard the protocol if it's supplied, for legacy support
@@ -128,13 +129,22 @@ class Image(item.Item):
else:
uri = filename
- if filename.find("@") != -1: auth, filename = filename.split("@")
- if filename.find(":") != -1: hostname, filename = filename.split(":")
+ if filename.find("@") != -1:
+ auth, filename = filename.split("@")
+ if filename.find(":") != -1:
+ hostname, filename = filename.split(":")
+ elif filename[0] != '/':
+ index = filename.find("/")
+ hostname = filename[:index]
+ filename = filename[index:]
# raise an exception if we don't have a valid path
- if filename[0] != '/': raise CX(_("file contains an invalid path"))
- if filename.find("/") != -1: path, filename = filename.rsplit("/", 1)
+ if filename[0] != '/':
+ raise CX(_("file contains an invalid path: %s" % filename))
+ if filename.find("/") != -1:
+ path, filename = filename.rsplit("/", 1)
- if len(filename) == 0: raise CX(_("missing filename"))
+ if len(filename) == 0:
+ raise CX(_("missing filename"))
if len(auth) > 0 and len(hostname) == 0:
raise CX(_("a hostname must be specified with authentication details"))
diff --git a/cobbler/test_basic.py b/cobbler/test_basic.py
index c2c934dd..7f6a062b 100644
--- a/cobbler/test_basic.py
+++ b/cobbler/test_basic.py
@@ -867,6 +867,15 @@ class TestListings(BootTest):
self.assertTrue(len(self.api.profiles().printable()) > 0)
self.assertTrue(len(self.api.distros().printable()) > 0)
+class TestImage(BootTest):
+
+ def test_image_file(self):
+ # ensure that only valid names are accepted and invalid ones are rejected
+ image = self.api.new_image()
+ self.assertTrue(image.set_file("nfs://hostname/path/to/filename.iso"))
+ self.assertTrue(image.set_file("/mcpierce@hostname:/path/to/filename.iso"))
+ self.assertTrue(image.set_file("path/to/filename.iso"))
+
#class TestCLIBasic(BootTest):
#
# def test_cli(self):