diff options
| author | Michael DeHaan <mdehaan@redhat.com> | 2008-11-03 17:42:50 -0500 |
|---|---|---|
| committer | Michael DeHaan <mdehaan@redhat.com> | 2008-11-03 17:42:50 -0500 |
| commit | 00a2d0cb75fdb527f1db7ae8a74fc3a9399186ef (patch) | |
| tree | e2d991d17c7db1cef2cf66ba8d0c044662b4f7a4 | |
| parent | 7fcb799040c30ca56d217351068256a05114d4b4 (diff) | |
| download | cobbler-00a2d0cb75fdb527f1db7ae8a74fc3a9399186ef.tar.gz cobbler-00a2d0cb75fdb527f1db7ae8a74fc3a9399186ef.tar.xz cobbler-00a2d0cb75fdb527f1db7ae8a74fc3a9399186ef.zip | |
Moved the implementation of the reposync code back to action_reposync.py and did some general cleanup. Also some work on XMLRPC RW tests (not finished).
| -rw-r--r-- | cobbler/action_reposync.py | 309 | ||||
| -rw-r--r-- | cobbler/collection_repos.py | 23 | ||||
| -rw-r--r-- | cobbler/item_repo.py | 391 | ||||
| -rw-r--r-- | cobbler/remote.py | 59 | ||||
| -rw-r--r-- | contrib/ruby/lib/cobbler/system.rb | 2 |
5 files changed, 369 insertions, 415 deletions
diff --git a/cobbler/action_reposync.py b/cobbler/action_reposync.py index 0b2340b7..d466a8d9 100644 --- a/cobbler/action_reposync.py +++ b/cobbler/action_reposync.py @@ -101,7 +101,7 @@ class RepoSync: for x in range(self.tries+1,1,-1): success = False try: - repo.sync(repo_mirror,self) + self.sync(repo) success = True except: traceback.print_exc() @@ -120,11 +120,316 @@ class RepoSync: raise CX(_("overall reposync failed, at least one repo failed to synchronize")) return True + + # ================================================================================== + + def sync(self, repo): + + """ + Conditionally sync a repo, based on type. + """ + + if repo.breed == "rhn": + return self.rhn_sync(repo) + elif repo.breed == "yum": + return self.yum_sync(repo) + elif repo.breed == "apt": + return self.apt_sync(repo) + elif repo.breed == "rsync": + return self.rsync_sync(repo) + else: + raise CobblerException("unable to sync repo (%s), unknown type (%s)" % (repo.name, repo.breed)) + + # ==================================================================================== + + def createrepo_walker(self, repo, dirname, fnames): + """ + Used to run createrepo on a copied Yum mirror. + """ + if os.path.exists(dirname) or repo['breed'] == 'rsync': + utils.remove_yum_olddata(dirname) + try: + cmd = "createrepo %s %s" % (repo.createrepo_flags, dirname) + print _("- %s") % cmd + sub_process.call(cmd, shell=True) + except: + print _("- createrepo failed. Is it installed?") + del fnames[:] # we're in the right place + + # ==================================================================================== + + def rsync_sync(self, repo): + + """ + Handle copying of rsync:// and rsync-over-ssh repos. + """ + + repo_mirror = repo.mirror + + if not repo.mirror_locally: + raise CX(_("rsync:// urls must be mirrored locally, yum cannot access them directly")) + + if repo.rpm_list != "": + print _("- warning: --rpm-list is not supported for rsync'd repositories") + + # FIXME: don't hardcode + dest_path = os.path.join("/var/www/cobbler/repo_mirror", repo.name) + + spacer = "" + if not repo.mirror.startswith("rsync://") and not repo.mirror.startswith("/"): + spacer = "-e ssh" + if not repo.mirror.endswith("/"): + repo.mirror = "%s/" % repo.mirror + cmd = "rsync -rltDv %s --delete --delete-excluded --exclude-from=/etc/cobbler/rsync.exclude %s %s" % (spacer, repo.mirror, dest_path) + print _("- %s") % cmd + rc = sub_process.call(cmd, shell=True) + if rc !=0: + raise CX(_("cobbler reposync failed")) + print _("- walking: %s") % dest_path + os.path.walk(dest_path, self.createrepo_walker, repo) + self.create_local_file(dest_path, repo) + + # ==================================================================================== + def rhn_sync(self, repo): + + """ + Handle mirroring of RHN repos. + """ + + repo_mirror = repo.mirror + + # FIXME? warn about not having yum-utils. We don't want to require it in the package because + # RHEL4 and RHEL5U0 don't have it. + + if not os.path.exists("/usr/bin/reposync"): + raise CX(_("no /usr/bin/reposync found, please install yum-utils")) + + cmd = "" # command to run + has_rpm_list = False # flag indicating not to pull the whole repo + + # detect cases that require special handling + + if repo.rpm_list != "": + has_rpm_list = True + + # create yum config file for use by reposync + # FIXME: don't hardcode + dest_path = os.path.join("/var/www/cobbler/repo_mirror", repo.name) + temp_path = os.path.join(dest_path, ".origin") + + if not os.path.isdir(temp_path) and repo.mirror_locally: + # FIXME: there's a chance this might break the RHN D/L case + os.makedirs(temp_path) + + # how we invoke yum-utils depends on whether this is RHN content or not. + + + # this is the somewhat more-complex RHN case. + # NOTE: this requires that you have entitlements for the server and you give the mirror as rhn://$channelname + if not repo.mirror_locally: + raise CX(_("rhn:// repos do not work with --mirror-locally=1")) + + if has_rpm_list: + print _("- warning: --rpm-list is not supported for RHN content") + rest = repo.mirror[6:] # everything after rhn:// + cmd = "/usr/bin/reposync %s -r %s --download_path=%s" % (self.rflags, rest, repo_mirror) + if repo.name != rest: + args = { "name" : repo.name, "rest" : rest } + raise CX(_("ERROR: repository %(name)s needs to be renamed %(rest)s as the name of the cobbler repository must match the name of the RHN channel") % args) + + if repo.arch == "i386": + # counter-intuitive, but we want the newish kernels too + repo.arch = "i686" + + if repo.arch != "": + cmd = "%s -a %s" % (cmd, repo.arch) + + # now regardless of whether we're doing yumdownloader or reposync + # or whether the repo was http://, ftp://, or rhn://, execute all queued + # commands here. Any failure at any point stops the operation. + + if repo.mirror_locally: + rc = sub_process.call(cmd, shell=True) + if rc !=0: + raise CX(_("cobbler reposync failed")) + + # some more special case handling for RHN. + # create the config file now, because the directory didn't exist earlier + + temp_file = self.create_local_file(temp_path, repo, output=False) + + # now run createrepo to rebuild the index + + if repo.mirror_locally: + os.path.walk(dest_path, self.createrepo_walker, repo) + + # create the config file the hosts will use to access the repository. + + self.create_local_file(dest_path, repo) + + # ==================================================================================== + + def yum_sync(self, repo): + + """ + Handle copying of http:// and ftp:// yum repos. + """ + + repo_mirror = repo.mirror + + # warn about not having yum-utils. We don't want to require it in the package because + # RHEL4 and RHEL5U0 don't have it. + + if not os.path.exists("/usr/bin/reposync"): + raise CX(_("no /usr/bin/reposync found, please install yum-utils")) + + cmd = "" # command to run + has_rpm_list = False # flag indicating not to pull the whole repo + + # detect cases that require special handling + + if repo.rpm_list != "": + has_rpm_list = True + + # create yum config file for use by reposync + dest_path = os.path.join("/var/www/cobbler/repo_mirror", repo.name) + temp_path = os.path.join(dest_path, ".origin") + + if not os.path.isdir(temp_path) and repo.mirror_locally: + # FIXME: there's a chance this might break the RHN D/L case + os.makedirs(temp_path) + + # create the config file that yum will use for the copying + + if repo.mirror_locally: + temp_file = self.create_local_file(temp_path, repo, output=False) + + if not has_rpm_list and repo.mirror_locally: + # if we have not requested only certain RPMs, use reposync + cmd = "/usr/bin/reposync %s --config=%s --repoid=%s --download_path=%s" % (self.rflags, temp_file, repo.name, repo_mirror) + if repo.arch != "": + if repo.arch == "x86": + repo.arch = "i386" # FIX potential arch errors + if repo.arch == "i386": + # counter-intuitive, but we want the newish kernels too + cmd = "%s -a i686" % (cmd) + else: + cmd = "%s -a %s" % (cmd, repo.arch) + + print _("- %s") % cmd + + elif repo.mirror_locally: + + # create the output directory if it doesn't exist + if not os.path.exists(dest_path): + os.makedirs(dest_path) + + use_source = "" + if repo.arch == "src": + use_source = "--source" + + # older yumdownloader sometimes explodes on --resolvedeps + # if this happens to you, upgrade yum & yum-utils + extra_flags = self.settings.yumdownloader_flags + cmd = "/usr/bin/yumdownloader %s %s -c %s --destdir=%s %s" % (extra_flags, use_source, temp_file, dest_path, " ".join(repo.rpm_list)) + print _("- %s") % cmd + + # now regardless of whether we're doing yumdownloader or reposync + # or whether the repo was http://, ftp://, or rhn://, execute all queued + # commands here. Any failure at any point stops the operation. + + if repo.mirror_locally: + rc = sub_process.call(cmd, shell=True) + if rc !=0: + raise CX(_("cobbler reposync failed")) + + # now run createrepo to rebuild the index + + if repo.mirror_locally: + os.path.walk(dest_path, self.createrepo_walker, repo) + + # create the config file the hosts will use to access the repository. + + self.create_local_file(dest_path, repo) + + # ==================================================================================== + + + def apt_sync(self, repo): + + """ + Handle copying of http:// and ftp:// debian repos. + """ + + repo_mirror = repo.mirror + + # warn about not having mirror program. + + mirror_program = "/usr/bin/debmirror" + if not os.path.exists(mirror_program): + raise CX(_("no %s found, please install it")%(mirror_program)) + + cmd = "" # command to run + has_rpm_list = False # flag indicating not to pull the whole repo + + # detect cases that require special handling + + if repo.rpm_list != "": + raise CX(_("has_rpm_list not yet supported on apt repos")) + + if not repo.arch: + raise CX(_("Architecture is required for apt repositories")) + + # built destination path for the repo + dest_path = os.path.join(repo_mirror, repo.name) + + if repo.mirror_locally: + mirror = repo.mirror + + idx = mirror.find("://") + method = mirror[:idx] + mirror = mirror[idx+3:] + + idx = mirror.find("/") + host = mirror[:idx] + mirror = mirror[idx+1:] + + idx = mirror.rfind("/dists/") + suite = mirror[idx+7:] + mirror = mirror[:idx] + + mirror_data = "--method=%s --host=%s --root=%s --dist=%s " % ( method , host , mirror , suite ) + + # FIXME : flags should come from repo instead of being hardcoded + + rflags = "--passive --nocleanup --ignore-release-gpg --verbose" + cmd = "%s %s %s %s" % (mirror_program, rflags, mirror_data, dest_path) + if repo.arch == "src": + cmd = "%s --source" % cmd + else: + arch = repo.arch + if arch == "x86": + arch = "i386" # FIX potential arch errors + if arch == "x86_64": + arch = "amd64" # FIX potential arch errors + cmd = "%s --nosource -a %s" % (cmd, arch) + + print _("- %s") % cmd + + rc = sub_process.call(cmd, shell=True) + if rc !=0: + raise CX(_("cobbler reposync failed")) + + + # ================================================================================== - def create_local_file(self, repo, dest_path, output=True): + def create_local_file(self, dest_path, repo, output=True): """ + + Creates Yum config files for use by reposync + Two uses: (A) output=True, Create local files that can be used with yum on provisioned clients to make use of this mirror. (B) output=False, Create a temporary file for yum to feed into yum for mirroring diff --git a/cobbler/collection_repos.py b/cobbler/collection_repos.py index f602871e..8ce150d4 100644 --- a/cobbler/collection_repos.py +++ b/cobbler/collection_repos.py @@ -40,29 +40,8 @@ class Repos(collection.Collection): def factory_produce(self,config,seed_data): """ - Return a system forged from seed_data + Return a repo forged from seed_data """ - if seed_data.has_key('breed'): - if seed_data['breed'] == "rsync": - return repo.RsyncRepo(config).from_datastruct(seed_data) - elif seed_data['breed'] == "rhn": - return repo.RhnRepo(config).from_datastruct(seed_data) - elif seed_data['breed'] == "yum": - return repo.YumRepo(config).from_datastruct(seed_data) - elif seed_data['breed'] == "apt": - return repo.AptRepo(config).from_datastruct(seed_data) - else: - # we didn't store a --breed with the repository so we must - # attempt to discover it. - if seed_data['breed'] != '': - raise CX(_("Unknown repository breed: %s") % seed_data['breed']) - - # Required until rsync breed is properly set on every required case - # Block, taken from is_rsync_mirror - lower = seed_data.get("mirror") - if not ( lower.startswith("http://") or lower.startswith("ftp://") or lower.startswith("rhn://") ): - seed_data['breed'] = "rsync" - return repo.RsyncRepo(config).from_datastruct(seed_data) return repo.Repo(config).from_datastruct(seed_data) def remove(self,name,with_delete=True,with_sync=True,with_triggers=True,recursive=False): diff --git a/cobbler/item_repo.py b/cobbler/item_repo.py index 113e9ab1..17736cff 100644 --- a/cobbler/item_repo.py +++ b/cobbler/item_repo.py @@ -77,6 +77,15 @@ class Repo(item.Item): self.set_owners(self.owners) self.set_environment(self.environment) + # backwards compatibility + if self.breed == "": + if self.mirror.startswith("http://") or self.mirror.startswith("ftp://"): + self.set_breed("yum") + elif self.mirror.startswith("rhn://"): + self.set_breed("rhn") + else: + self.set_breed("rsync") + return self def set_mirror(self,mirror): @@ -261,385 +270,3 @@ class Repo(item.Item): 'environment' : self.set_environment } - def sync(self, repo_mirror, obj_sync): - - """ - Handle copying of http:// and ftp:// repos. - """ - - # warn about not having yum-utils. We don't want to require it in the package because - # RHEL4 and RHEL5U0 don't have it. - - if not os.path.exists("/usr/bin/reposync"): - raise CX(_("no /usr/bin/reposync found, please install yum-utils")) - - cmd = "" # command to run - is_rhn = False # RHN repositories require extra black magic - has_rpm_list = False # flag indicating not to pull the whole repo - - # detect cases that require special handling - - if self.mirror.lower().startswith("rhn://"): - is_rhn = True - if self.rpm_list != "": - has_rpm_list = True - - # create yum config file for use by reposync - dest_path = os.path.join(repo_mirror, self.name) - temp_path = os.path.join(repo_mirror, ".origin") - if not os.path.isdir(temp_path) and self.mirror_locally: - # FIXME: there's a chance this might break the RHN D/L case - os.makedirs(temp_path) - - # how we invoke yum-utils depends on whether this is RHN content or not. - - - - if not is_rhn: - - # this is the simple non-RHN case. - # create the config file that yum will use for the copying - - if self.mirror_locally: - temp_file = obj_sync.create_local_file(self, temp_path, output=False) - - if not has_rpm_list and self.mirror_locally: - # if we have not requested only certain RPMs, use reposync - cmd = "/usr/bin/reposync %s --config=%s --repoid=%s --download_path=%s" % (obj_sync.rflags, temp_file, self.name, repo_mirror) - if self.arch != "": - if self.arch == "x86": - self.arch = "i386" # FIX potential arch errors - if self.arch == "i386": - # counter-intuitive, but we want the newish kernels too - cmd = "%s -a i686" % (cmd) - else: - cmd = "%s -a %s" % (cmd, self.arch) - - print _("- %s") % cmd - - elif self.mirror_locally: - - # create the output directory if it doesn't exist - if not os.path.exists(dest_path): - os.makedirs(dest_path) - - use_source = "" - if self.arch == "src": - use_source = "--source" - - # older yumdownloader sometimes explodes on --resolvedeps - # if this happens to you, upgrade yum & yum-utils - extra_flags = obj_sync.settings.yumdownloader_flags - cmd = "/usr/bin/yumdownloader %s %s -c %s --destdir=%s %s" % (extra_flags, use_source, temp_file, dest_path, " ".join(self.rpm_list)) - print _("- %s") % cmd - else: - - # this is the somewhat more-complex RHN case. - # NOTE: this requires that you have entitlements for the server and you give the mirror as rhn://$channelname - if not self.mirror_locally: - raise CX(_("rhn:// repos do not work with --mirror-locally=1")) - - if has_rpm_list: - print _("- warning: --rpm-list is not supported for RHN content") - rest = self.mirror[6:] # everything after rhn:// - cmd = "/usr/bin/reposync %s -r %s --download_path=%s" % (obj_sync.rflags, rest, repo_mirror) - if self.name != rest: - args = { "name" : self.name, "rest" : rest } - raise CX(_("ERROR: repository %(name)s needs to be renamed %(rest)s as the name of the cobbler repository must match the name of the RHN channel") % args) - - if self.arch == "i386": - # counter-intuitive, but we want the newish kernels too - self.arch = "i686" - - if self.arch != "": - cmd = "%s -a %s" % (cmd, self.arch) - - # now regardless of whether we're doing yumdownloader or reposync - # or whether the repo was http://, ftp://, or rhn://, execute all queued - # commands here. Any failure at any point stops the operation. - - if self.mirror_locally: - rc = sub_process.call(cmd, shell=True) - if rc !=0: - raise CX(_("cobbler reposync failed")) - - # some more special case handling for RHN. - # create the config file now, because the directory didn't exist earlier - - if is_rhn: - temp_file = obj_sync.create_local_file(self, temp_path, output=False) - - # now run createrepo to rebuild the index - - if self.mirror_locally: - os.path.walk(dest_path, self.createrepo_walker, self) - - # create the config file the hosts will use to access the repository. - - obj_sync.create_local_file(self, dest_path) - - def createrepo_walker(self, repo, dirname, fnames): - """ - Used to run createrepo on a copied mirror. - """ - if os.path.exists(dirname) or repo['breed'] == 'rsync': - utils.remove_yum_olddata(dirname) - try: - cmd = "createrepo %s %s" % (repo.createrepo_flags, dirname) - print _("- %s") % cmd - sub_process.call(cmd, shell=True) - except: - print _("- createrepo failed. Is it installed?") - del fnames[:] # we're in the right place - - -class RsyncRepo(Repo): - - def sync(self, repo_mirror, obj_sync): - - """ - Handle copying of rsync:// and rsync-over-ssh repos. - """ - - if not self.mirror_locally: - raise CX(_("rsync:// urls must be mirrored locally, yum cannot access them directly")) - - if self.rpm_list != "": - print _("- warning: --rpm-list is not supported for rsync'd repositories") - dest_path = os.path.join(repo_mirror, self.name) - spacer = "" - if not self.mirror.startswith("rsync://") and not self.mirror.startswith("/"): - spacer = "-e ssh" - if not self.mirror.endswith("/"): - self.mirror = "%s/" % self.mirror - cmd = "rsync -rltDv %s --delete --delete-excluded --exclude-from=/etc/cobbler/rsync.exclude %s %s" % (spacer, self.mirror, dest_path) - print _("- %s") % cmd - rc = sub_process.call(cmd, shell=True) - if rc !=0: - raise CX(_("cobbler reposync failed")) - print _("- walking: %s") % dest_path - os.path.walk(dest_path, self.createrepo_walker, self) - obj_sync.create_local_file(self, dest_path) - -class RhnRepo(Repo): - - def sync(self, repo_mirror, obj_sync): - - """ - Handle copying of http:// and ftp:// RHN repos. - """ - - # warn about not having yum-utils. We don't want to require it in the package because - # RHEL4 and RHEL5U0 don't have it. - - if not os.path.exists("/usr/bin/reposync"): - raise CX(_("no /usr/bin/reposync found, please install yum-utils")) - - cmd = "" # command to run - has_rpm_list = False # flag indicating not to pull the whole repo - - # detect cases that require special handling - - if self.rpm_list != "": - has_rpm_list = True - - # create yum config file for use by reposync - dest_path = os.path.join(repo_mirror, self.name) - temp_path = os.path.join(repo_mirror, ".origin") - if not os.path.isdir(temp_path) and self.mirror_locally: - # FIXME: there's a chance this might break the RHN D/L case - os.makedirs(temp_path) - - # how we invoke yum-utils depends on whether this is RHN content or not. - - - # this is the somewhat more-complex RHN case. - # NOTE: this requires that you have entitlements for the server and you give the mirror as rhn://$channelname - if not self.mirror_locally: - raise CX(_("rhn:// repos do not work with --mirror-locally=1")) - - if has_rpm_list: - print _("- warning: --rpm-list is not supported for RHN content") - rest = self.mirror[6:] # everything after rhn:// - cmd = "/usr/bin/reposync %s -r %s --download_path=%s" % (obj_sync.rflags, rest, repo_mirror) - if self.name != rest: - args = { "name" : self.name, "rest" : rest } - raise CX(_("ERROR: repository %(name)s needs to be renamed %(rest)s as the name of the cobbler repository must match the name of the RHN channel") % args) - - if self.arch == "i386": - # counter-intuitive, but we want the newish kernels too - self.arch = "i686" - - if self.arch != "": - cmd = "%s -a %s" % (cmd, self.arch) - - # now regardless of whether we're doing yumdownloader or reposync - # or whether the repo was http://, ftp://, or rhn://, execute all queued - # commands here. Any failure at any point stops the operation. - - if self.mirror_locally: - rc = sub_process.call(cmd, shell=True) - if rc !=0: - raise CX(_("cobbler reposync failed")) - - # some more special case handling for RHN. - # create the config file now, because the directory didn't exist earlier - - temp_file = obj_sync.create_local_file(self, temp_path, output=False) - - # now run createrepo to rebuild the index - - if self.mirror_locally: - os.path.walk(dest_path, self.createrepo_walker, self) - - # create the config file the hosts will use to access the repository. - - obj_sync.create_local_file(self, dest_path) - - -class YumRepo(Repo): - - def sync(self, repo_mirror, obj_sync): - - """ - Handle copying of http:// and ftp:// yum repos. - """ - - # warn about not having yum-utils. We don't want to require it in the package because - # RHEL4 and RHEL5U0 don't have it. - - if not os.path.exists("/usr/bin/reposync"): - raise CX(_("no /usr/bin/reposync found, please install yum-utils")) - - cmd = "" # command to run - has_rpm_list = False # flag indicating not to pull the whole repo - - # detect cases that require special handling - - if self.rpm_list != "": - has_rpm_list = True - - # create yum config file for use by reposync - dest_path = os.path.join(repo_mirror, self.name) - temp_path = os.path.join(repo_mirror, ".origin") - if not os.path.isdir(temp_path) and self.mirror_locally: - # FIXME: there's a chance this might break the RHN D/L case - os.makedirs(temp_path) - - # create the config file that yum will use for the copying - - if self.mirror_locally: - temp_file = obj_sync.create_local_file(self, temp_path, output=False) - - if not has_rpm_list and self.mirror_locally: - # if we have not requested only certain RPMs, use reposync - cmd = "/usr/bin/reposync %s --config=%s --repoid=%s --download_path=%s" % (obj_sync.rflags, temp_file, self.name, repo_mirror) - if self.arch != "": - if self.arch == "x86": - self.arch = "i386" # FIX potential arch errors - if self.arch == "i386": - # counter-intuitive, but we want the newish kernels too - cmd = "%s -a i686" % (cmd) - else: - cmd = "%s -a %s" % (cmd, self.arch) - - print _("- %s") % cmd - - elif self.mirror_locally: - - # create the output directory if it doesn't exist - if not os.path.exists(dest_path): - os.makedirs(dest_path) - - use_source = "" - if self.arch == "src": - use_source = "--source" - - # older yumdownloader sometimes explodes on --resolvedeps - # if this happens to you, upgrade yum & yum-utils - extra_flags = obj_sync.settings.yumdownloader_flags - cmd = "/usr/bin/yumdownloader %s %s -c %s --destdir=%s %s" % (extra_flags, use_source, temp_file, dest_path, " ".join(self.rpm_list)) - print _("- %s") % cmd - - # now regardless of whether we're doing yumdownloader or reposync - # or whether the repo was http://, ftp://, or rhn://, execute all queued - # commands here. Any failure at any point stops the operation. - - if self.mirror_locally: - rc = sub_process.call(cmd, shell=True) - if rc !=0: - raise CX(_("cobbler reposync failed")) - - # now run createrepo to rebuild the index - - if self.mirror_locally: - os.path.walk(dest_path, self.createrepo_walker, self) - - # create the config file the hosts will use to access the repository. - - obj_sync.create_local_file(self, dest_path) - -class AptRepo(Repo): - - def sync(self, repo_mirror, obj_sync): - - """ - Handle copying of http:// and ftp:// debian repos. - """ - - # warn about not having mirror program. - - mirror_program = "/usr/bin/debmirror" - if not os.path.exists(mirror_program): - raise CX(_("no %s found, please install it")%(mirror_program)) - - cmd = "" # command to run - has_rpm_list = False # flag indicating not to pull the whole repo - - # detect cases that require special handling - - if self.rpm_list != "": - raise CX(_("has_rpm_list not yet supported on apt repos")) - - if not self.arch: - raise CX(_("Architecture is required for apt repositories")) - - # built destination path for the repo - dest_path = os.path.join(repo_mirror, self.name) - - if self.mirror_locally: - mirror = self.mirror - - idx = mirror.find("://") - method = mirror[:idx] - mirror = mirror[idx+3:] - - idx = mirror.find("/") - host = mirror[:idx] - mirror = mirror[idx+1:] - - idx = mirror.rfind("/dists/") - suite = mirror[idx+7:] - mirror = mirror[:idx] - - mirror_data = "--method=%s --host=%s --root=%s --dist=%s " % ( method , host , mirror , suite ) - - # FIXME : flags should come from obj_sync instead of being hardcoded - rflags = "--passive --nocleanup --ignore-release-gpg --verbose" - cmd = "%s %s %s %s" % (mirror_program, rflags, mirror_data, dest_path) - if self.arch == "src": - cmd = "%s --source" % cmd - else: - arch = self.arch - if arch == "x86": - arch = "i386" # FIX potential arch errors - if arch == "x86_64": - arch = "amd64" # FIX potential arch errors - cmd = "%s --nosource -a %s" % (cmd, arch) - - print _("- %s") % cmd - - rc = sub_process.call(cmd, shell=True) - if rc !=0: - raise CX(_("cobbler reposync failed")) - diff --git a/cobbler/remote.py b/cobbler/remote.py index f05f2818..8cfb971e 100644 --- a/cobbler/remote.py +++ b/cobbler/remote.py @@ -1322,7 +1322,7 @@ def __test_bootstrap_start_clean(): def test_xmlrpc_ro(): __test_bootstrap_start_clean() - server = xmlrpclib.Server("http://127.0.0.1/cobbler_api_rw") + server = xmlrpclib.Server("http://127.0.0.1/cobbler_api") time.sleep(2) # delete all distributions @@ -1545,14 +1545,57 @@ def test_xmlrpc_ro(): # this last bit mainly tests the tests, to ensure we've left nothing behind # not XMLRPC. Tests polluting the user config is not desirable. - assert len(self.api.get_distros() == before_distros) - assert len(self.api.get_profiles() == before_profiles) - assert len(self.api.get_systems() == before_systems) - assert len(self.api.get_images() == before_images) - assert len(self.api.get_repos() == before_repos) + assert len(api.get_distros() == before_distros) + assert len(api.get_profiles() == before_profiles) + assert len(api.get_systems() == before_systems) + assert len(api.get_images() == before_images) + assert len(api.get_repos() == before_repos) def test_xmlrpc_rw(): - # need tests for the various auth modes, not just one - pass + # ideally we need tests for the various auth modes, not just one + # and the ownership module, though this will provide decent coverage. + __test_bootstrap_start_clean() + server = xmlrpclib.Server("http://127.0.0.1/cobbler_api_rw") # remote + api = cobbler_api.BootAPI() # local + + # read our settings file to see if it looks like the "testing" mode is engaged + modules = open("/etc/cobbler/modules.conf") + data = modules.read() + modules.close() + + if data.find("= authn_testing") == -1 and data.find("=authn_testing"): + raise Exception("switch to authn_testing in /etc/cobbler/modules.conf to proceed with tests") + + # test getting token, will raise remote exception on fail + token = self.server.login("testing","testing") + + # create distro + distro_id = self.serer.new_distro(token) + self.modify_distro(did, "name", "distro1", token) + self.modify_distro(did, "kernel", "/etc/hosts", token) # not a kernel, just for testing + self.modify_distro(did, "initrd", "/etc/hosts", token) # not a kernel, just for testing + self.modify_distro(did, "kopts", { "dog" : "fido", "cat" : "fluffy" }, token) # hash or string + self.modify_distro(did, "ksmeta", "good=sg1 evil=gould", token) # hash or string + self.modify_distro(did, "breed", "redhat", token) + self.modify_distro(did, "os-version", "rhel5", token) + self.modify_distro(did, "owners", "sam dave", token) # array or string + self.modify_distro(did, "mgmt-classes", "blip") # list or string + self.modify_distro(did, "template-files", "/etc/hosts=/tmp/a /etc/fstab=/tmp/b") # hash or string + self.server.save_distro(did) + + # now check via /non-xmlrpc/ API to make sure it's properly there and saved. + api.get_distro("distro1") + + #profile_id = self.server.new_profile(token) + + # FIXME: test renames + # FIXME: test copies + # FIXME: test deletes + + # cleanup + distro = api.get_distro("distro1") + api.remove_distro(distro, recursive=True) + + diff --git a/contrib/ruby/lib/cobbler/system.rb b/contrib/ruby/lib/cobbler/system.rb index 2322bc7c..398f9934 100644 --- a/contrib/ruby/lib/cobbler/system.rb +++ b/contrib/ruby/lib/cobbler/system.rb @@ -95,4 +95,4 @@ module Cobbler System.new(attrs) end end -end
\ No newline at end of file +end |
