David Caro has uploaded a new change for review.

Change subject: Added replace-mirrors option
......................................................................

Added replace-mirrors option

That allows us to replace any mirrorlist in the mock repos config by the first
mirror form the mirrorlist

Change-Id: I9c24b9262b10b19d3fc2832c70493481ff758766
Signed-off-by: David Caro <[email protected]>
---
M mock_configs/mock_genconfig
1 file changed, 34 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/jenkins refs/changes/15/37215/1

diff --git a/mock_configs/mock_genconfig b/mock_configs/mock_genconfig
index ccd62f6..164ad03 100755
--- a/mock_configs/mock_genconfig
+++ b/mock_configs/mock_genconfig
@@ -2,6 +2,7 @@
 import re
 import argparse
 import json
+import urllib2
 
 
 class WrongOptionFormat(Exception):
@@ -27,6 +28,24 @@
     if not re.match(r'^(https?|file|ftps?)://.*$', url):
         raise WrongRepoFormat('Wrong url specified on "%s"' % string)
     return (name, url)
+
+
+def is_good_mirror(mirror_url):
+    try:
+        urllib2.urlopen(mirror_url)
+    except Exception:
+        return False
+    return True
+
+
+def get_first_mirror(mirrorlist_url):
+    res = urllib2.urlopen(mirrorlist_url)
+    mirror_url = res.readline()
+    while mirror_url and not is_good_mirror(mirror_url):
+        mirror_url = res.readline().strip()
+    if not mirror_url:
+        raise Exception('Unable to get a good mirror from %s' % mirrorlist_url)
+    return mirror_url
 
 
 def get_repos(repos):
@@ -80,6 +99,10 @@
                         help='path to the configuration to use as base')
     parser.add_argument('--name', dest='name', required=True,
                         help='new name for the config')
+    parser.add_argument('--replace-mirrors', required=False, 
action='store_true',
+                        help='When generating the config, replace the '
+                        'mirrorlist entries for the first mirror from them, '
+                        'useful to allow caching.')
     args = parser.parse_args()
 
     config_opts = {}
@@ -102,6 +125,17 @@
     # add the extra repos passed
     config_opts['yum.conf'] = '%s' % (config_opts.get('yum.conf', '')
                                       + get_repos(args.extra_repos))
+
+    if args.replace_mirrors:
+        yum_conf_lines = []
+        for line in config_opts['yum.conf'].splitlines():
+            if line.startswith('mirrorlist'):
+                mirrorlist_url = line.split('=', 1)[1]
+                mirror_url = get_first_mirror(mirrorlist_url)
+                yum_conf_lines.append('baseurl=%s' % mirror_url)
+            else:
+                yum_conf_lines.append(line)
+        config_opts['yum.conf'] = '\n'.join(yum_conf_lines)
     print dumps_dict(config_opts, 'config_opts')
 
 


-- 
To view, visit http://gerrit.ovirt.org/37215
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I9c24b9262b10b19d3fc2832c70493481ff758766
Gerrit-PatchSet: 1
Gerrit-Project: jenkins
Gerrit-Branch: master
Gerrit-Owner: David Caro <[email protected]>
_______________________________________________
Engine-patches mailing list
[email protected]
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to