summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--cobbler/action_litesync.py6
-rw-r--r--cobbler/action_reposync.py14
-rw-r--r--cobbler/action_sync.py138
-rw-r--r--tests/tests.py23
4 files changed, 124 insertions, 57 deletions
diff --git a/cobbler/action_litesync.py b/cobbler/action_litesync.py
index a1f9eea..a35d16c 100644
--- a/cobbler/action_litesync.py
+++ b/cobbler/action_litesync.py
@@ -78,11 +78,13 @@ class BootLiteSync:
raise CX(_("error in profile lookup"))
# rebuild profile_list YAML file in webdir
self.sync.write_listings()
+ # rebuild the yum configuration files for any attached repos
+ self.sync.retemplate_yum_repos(obj,is_profile)
# add profiles/$name YAML file in webdir
self.sync.write_profile_file(profile)
# generate kickstart for kickstarts/$name/ks.cfg in webdir
self.sync.validate_kickstart_for_specific_profile(profile)
-
+
def remove_single_profile(self, name):
# rebuild profile_list YAML file in webdir
self.sync.write_listings()
@@ -99,6 +101,8 @@ class BootLiteSync:
# rebuild system_list file in webdir
self.sync.regen_ethers() # /etc/ethers, for dnsmasq & rarpd
self.sync.regen_hosts() # /var/lib/cobbler/cobbler_hosts, pretty much for dnsmasq
+ # rebuild the yum configuration files for any attached repos
+ self.sync.retemplate_yum_repos(obj,is_profile)
self.sync.write_listings()
# write the PXE and YAML files for the system
self.sync.write_all_system_files(system)
diff --git a/cobbler/action_reposync.py b/cobbler/action_reposync.py
index d49efd1..fdd9c3a 100644
--- a/cobbler/action_reposync.py
+++ b/cobbler/action_reposync.py
@@ -224,16 +224,14 @@ class RepoSync:
def create_local_file(self, repo, dest_path, output=True):
"""
Two uses:
- (A) Create local files that can be used with yum on provisioned clients to make use of thisi mirror.
- (B) Create a temporary file for yum to feed into reposync
+ (A) output=True, Create local files that can be used with yum on provisioned clients to make use of thisi mirror.
+ (B) output=False, Create a temporary file for yum to feed into yum for mirroring
"""
- # FIXME: the output case will generate repo configuration files which are usable
+ # the output case will generate repo configuration files which are usable
# for the installed systems. They need to be made compatible with --server-override
- # which means that we should NOT replace @@server@@ except in a dynamically generated
- # post script that runs on each file we wget, and replace it there. Until then
- # installed repos may require a host file setting that allows them to find the
- # main server address used for the initial mirroring. We can clean this up :)
+ # which means they are actually templates, which need to be rendered by a cobbler-sync
+ # on per profile/system basis.
if output:
fname = os.path.join(dest_path,"config.repo")
@@ -246,7 +244,7 @@ class RepoSync:
if output:
# see note above: leave as @@server@@ and fix in %post of kickstart when
# we generate the stanza
- line = "baseurl=http://%s/cobbler/repo_mirror/%s\n" % (self.settings.server, repo.name)
+ line = "baseurl=http://${server}/cobbler/repo_mirror/%s\n" % (repo.name)
config_file.write(line)
else:
line = "baseurl=%s\n" % repo.mirror
diff --git a/cobbler/action_sync.py b/cobbler/action_sync.py
index 75e5389..76ad5b9 100644
--- a/cobbler/action_sync.py
+++ b/cobbler/action_sync.py
@@ -362,8 +362,8 @@ class BootSync:
ksmeta = meta["ks_meta"]
del meta["ks_meta"]
meta.update(ksmeta) # make available at top level
- meta["yum_repo_stanza"] = self.generate_repo_stanza(g)
- meta["yum_config_stanza"] = self.generate_config_stanza(g)
+ meta["yum_repo_stanza"] = self.generate_repo_stanza(g,True)
+ meta["yum_config_stanza"] = self.generate_config_stanza(g,True)
meta["kickstart_done"] = self.generate_kickstart_signal(g, None)
meta["kernel_options"] = utils.hash_to_string(meta["kernel_options"])
kfile = open(kickstart_path)
@@ -410,56 +410,60 @@ class BootSync:
return buf
- def generate_repo_stanza(self, profile):
- # returns the line of repo additions (Anaconda supports in FC-6 and later) that adds
- # the list of repos to things that Anaconda can install from. This corresponds
- # will replace "TEMPLATE::yum_repo_stanza" in a cobbler kickstart file.
+ def generate_repo_stanza(self, obj, is_profile=True):
+
+ """
+ Automatically attaches yum repos to profiles/systems in kickstart files
+ that contain the magic $yum_repo_stanza variable.
+ """
+
buf = ""
- blended = utils.blender(self.api, False, profile)
- repos = blended["repos"]
- for r in repos:
- repo = self.repos.find(name=r)
- if repo is None:
- continue
- http_url = "http://%s/cblr/repo_mirror/%s" % (blended["server"], repo.name)
- buf = buf + "repo --name=%s --baseurl=%s\n" % (repo.name, http_url)
- distro = profile.get_conceptual_parent()
+ blended = utils.blender(self.api, False, obj)
- # tack on all the install source repos IF there is more than one.
- # this is basically to support things like RHEL5 split trees
- # if there is only one, then there is no need to do this.
- if len(distro.source_repos) > 1:
- for r in distro.source_repos:
- base = r[1].split("/")[-1].replace(".repo","")
- buf = buf + "repo --name=%s --baseurl=%s\n" % (base, r[1])
+ # for all yum repo templates we have rendered rendered ...
+ globpath = os.path.join(self.settings.webdir, "repos_profile", blended["name"], "*")
+ configs = glob.glob(globpath)
+
+ # add a yum configuration line that makes the kickstart use them ...
+ for c in configs:
+ name = c.split("/")[-1].replace(".repo","")
+ url = c.replace(self.settings.webdir, "%s/cobbler" % blended["server"])
+ buf = buf + "repo --name=%s --baseurl=%s\n" % (name, url)
return buf
- def generate_config_stanza(self, profile):
- # returns the line in post that would configure yum to use repos added with "cobbler repo add"
- blended = utils.blender(self.api, False,profile)
- repos = blended["repos"]
- buf = ""
- for r in repos:
- repo = self.repos.find(name=r)
- if repo is None:
- continue
- repo.local_filename = repo.local_filename.replace(".repo","")
- if not (repo.local_filename is None) and not (repo.local_filename == ""):
- buf = buf + "wget http://%s/cblr/repo_mirror/%s/config.repo --output-document=/etc/yum.repos.d/%s.repo\n" % (blended["server"], repo.name, repo.local_filename)
+ def generate_config_stanza(self, obj, is_profile=True):
+
+ """
+ Add in automatic to configure /etc/yum.repos.d on the remote system
+ if the kickstart file contains the magic $yum_config_stanza.
+ """
- # now install the core repos
- distro = profile.get_conceptual_parent()
if self.settings.yum_core_mirror_from_server:
- for r in distro.source_repos:
- short = r[0].split("/")[-1]
- buf = buf + "wget %s --output-document=/etc/yum.repos.d/%s\n" % (r[0], short)
+ return
+
+ if is_profile:
+ urlseg = "repos_profile"
+ else:
+ urlseg = "repos_system"
+
+ distro = obj.get_conceptual_parent()
+ if not is_profile:
+ distro = distro.get_conceptual_parent()
- # if there were any core repos, install the voodoo to disable the OS public core
- # location -- FIXME: should probably run sed on the files, rather than rename them.
- if len(distro.source_repos) > 0:
- for x in ["fedora-core", "CentOS-Base"] :
- buf = buf + "test -e /etc/yum.repos.d/%s.repo && mv /etc/yum.repos.d/%s.repo /etc/yum.repos.d/disabled-%s\n" % (x,x,x)
+ blended = utils.blender(self.api, False, obj)
+ globpath = os.path.join(self.settings.webdir, "repos_profile", blended["name"], "*")
+ configs = glob.glob(globpath)
+
+ # for each kickstart template we have rendered ...
+ for c in configs:
+
+ name = c.split("/")[-1].replace(".repo","")
+ url = c.replace(self.settings.webdir, "%s/cobbler" % blended["server"])
+ buf = buf + "repo --name=%s --baseurl=%s\n" % (name, url)
+
+ # add the line to create the yum config file on the target box
+ buf = buf + "wget http://%s/cblr/%s/%s/%s/config.repo --output-document=/etc/yum.repos.d/%s.repo\n" % (blended["server"], urlseg, blended["name"], name)
return buf
@@ -613,11 +617,57 @@ class BootSync:
self.write_distro_file(d)
for p in self.profiles:
+ self.retemplate_yum_repos(p,True)
self.write_profile_file(p)
for system in self.systems:
+ self.retemplate_yum_repos(system,False)
self.write_all_system_files(system)
+ def retemplate_yum_repos(self,obj,is_profile):
+ # FIXME: blender could use caching for performance
+ # FIXME: make stanza generation code load stuff from the right place
+ """
+ Yum repository management files are in self.settings.webdir/repo_mirror/$name/config.repo
+ and also potentially in listed in the source_repos structure of the distro object, however
+ these files have server URLs in them that must be templated out. This function does this.
+ """
+ blended = utils.blender(self.api, False, obj)
+
+ if is_profile:
+ outseg = "repos_profile"
+ else:
+ outseg = "repos_system"
+
+ confdir = os.path.join(self.settings.webdir, outseg)
+ shutil.rmtree(confdir, ignore_errors=True, onerror=None)
+
+ input_files = []
+
+ # tack on all the install source repos IF there is more than one.
+ # this is basically to support things like RHEL5 split trees
+ # if there is only one, then there is no need to do this.
+ if len(blended["source_repos"]) > 1:
+ for r in blended["source_repos"]:
+ input_files.append(r)
+
+ for repo in blended["repos"]:
+ input_files.append(os.path.join(self.settings.webdir, "repo_mirror", repo, "config.repo"))
+
+ for infile in input_files:
+ dispname = infile.split("/")[-1].replace(".repo","")
+ outdir = os.path.join(confdir, outseg, blended["name"])
+ self.mkdir(outdir)
+ try:
+ infile_h = open(infile)
+ except:
+ raise CX(_("cobbler reposync needs to be run on repo (%s) first" % dispname))
+ infile_data = infile_h.read()
+ infile_h.close()
+ outfile = os.path.join(outdir, "config.repo")
+ self.apply_template(infile_data, blended, outfile)
+
+
def write_all_system_files(self,system):
profile = system.get_conceptual_parent()
diff --git a/tests/tests.py b/tests/tests.py
index 9f4fe9c..9c7fe59 100644
--- a/tests/tests.py
+++ b/tests/tests.py
@@ -49,7 +49,6 @@ class BootTest(unittest.TestCase):
# Create temp dir
self.topdir = tempfile.mkdtemp(prefix="_cobbler-",dir="/tmp")
- #self.topdir = "/tmp" # only for refactoring, fix later
self.fk_initrd = os.path.join(self.topdir, FAKE_INITRD)
self.fk_initrd2 = os.path.join(self.topdir, FAKE_INITRD2)
self.fk_initrd3 = os.path.join(self.topdir, FAKE_INITRD3)
@@ -265,11 +264,14 @@ class Utilities(BootTest):
repo = self.api.new_repo()
try:
- os.path.makedirs("/tmp/test_cobbler_repo")
+ os.makedirs("/tmp/test_cobbler_repo")
except:
pass
+ fd = open("/tmp/test_cobbler_repo/test.file", "w+")
+ fd.write("hello!")
+ fd.close()
self.assertTrue(repo.set_name("testrepo"))
- self.assertTrue(repo.set_mirror("/tmp"))
+ self.assertTrue(repo.set_mirror("/tmp/test_cobbler_repo"))
self.assertTrue(self.api.repos().add(repo))
profile = self.api.new_profile()
@@ -278,6 +280,7 @@ class Utilities(BootTest):
self.assertTrue(profile.set_kickstart("http://127.0.0.1/foo"))
self.assertTrue(profile.set_repos(["testrepo"]))
self.assertTrue(self.api.profiles().add(profile))
+ self.api.reposync()
self.api.sync()
system = self.api.new_system()
self.assertTrue(system.set_name("foo"))
@@ -297,6 +300,7 @@ class Utilities(BootTest):
profile2.set_name("testprofile12b3")
profile2.set_parent("testprofile12b2")
self.assertTrue(self.api.profiles().add(profile2))
+ self.api.reposync()
self.api.sync()
# FIXME: now add a system to the inherited profile
@@ -307,6 +311,7 @@ class Utilities(BootTest):
self.assertTrue(system2.set_profile("testprofile12b3"))
self.assertTrue(system2.set_ksmeta({"narf" : "troz"}))
self.assertTrue(self.api.systems().add(system2))
+ self.api.reposync()
self.api.sync()
# FIXME: now evaluate the system object and make sure
@@ -323,8 +328,15 @@ class Utilities(BootTest):
# (FIXME)
repo2 = self.api.new_repo()
+ try:
+ os.makedirs("/tmp/cobbler_test_repo")
+ except:
+ pass
+ fd = open("/tmp/cobbler_test_repo/file.test","w+")
+ fd.write("Hi!")
+ fd.close()
self.assertTrue(repo2.set_name("testrepo2"))
- self.assertTrue(repo2.set_mirror("/tmp"))
+ self.assertTrue(repo2.set_mirror("/tmp/cobbler_test_repo"))
self.assertTrue(self.api.repos().add(repo2))
profile2 = self.api.profiles().find("testprofile12b3")
# note: side check to make sure we can also set to string values
@@ -332,6 +344,7 @@ class Utilities(BootTest):
self.api.profiles().add(profile2) # save it
# random bug testing: run sync several times and ensure cardinality doesn't change
+ self.api.reposync()
self.api.sync()
self.api.sync()
self.api.sync()
@@ -360,9 +373,11 @@ class Utilities(BootTest):
profile = self.api.profiles().find("testprofile12b2")
self.assertTrue(type(profile.ks_meta) == type({}))
+ self.api.reposync()
self.api.sync()
self.assertFalse(profile.ks_meta.has_key("narf"), "profile does not have the system ksmeta")
+ self.api.reposync()
self.api.sync()
# verify that the distro did not acquire the property