| OLD | NEW |
| 1 """ | 1 """ |
| 2 This module defines the BasePackageManager Class which provides an | 2 This module defines the BasePackageManager Class which provides an |
| 3 implementation of the packaging system API providing methods to fetch, | 3 implementation of the packaging system API providing methods to fetch, |
| 4 upload and remove packages. Site specific extensions to any of these methods | 4 upload and remove packages. Site specific extensions to any of these methods |
| 5 should inherit this class. | 5 should inherit this class. |
| 6 """ | 6 """ |
| 7 | 7 |
| 8 import re, os, sys, traceback, subprocess, shutil, time, traceback, urlparse | 8 import re, os, sys, traceback, subprocess, shutil, time, traceback, urlparse |
| 9 import fcntl, logging | 9 import fcntl, logging |
| 10 from autotest_lib.client.common_lib import error, utils, global_config | 10 from autotest_lib.client.common_lib import error, utils, global_config |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 ''' | 21 ''' |
| 22 | 22 |
| 23 match = re.search('^ssh://(.*?)(/.*)$', repo) | 23 match = re.search('^ssh://(.*?)(/.*)$', repo) |
| 24 if match: | 24 if match: |
| 25 return match.groups() | 25 return match.groups() |
| 26 else: | 26 else: |
| 27 raise error.PackageUploadError( | 27 raise error.PackageUploadError( |
| 28 "Incorrect SSH path in global_config: %s" % repo) | 28 "Incorrect SSH path in global_config: %s" % repo) |
| 29 | 29 |
| 30 | 30 |
| 31 def repo_run_command(repo, cmd, ignore_status=False): | 31 def repo_run_command(repo, cmd, ignore_status=False, cd=True): |
| 32 """Run a command relative to the repos path""" | 32 """Run a command relative to the repos path""" |
| 33 repo = repo.strip() | 33 repo = repo.strip() |
| 34 run_cmd = None | 34 run_cmd = None |
| 35 cd_str = '' |
| 35 if repo.startswith('ssh://'): | 36 if repo.startswith('ssh://'): |
| 36 username = None | 37 username = None |
| 37 hostline, remote_path = parse_ssh_path(repo) | 38 hostline, remote_path = parse_ssh_path(repo) |
| 39 if cd: |
| 40 cd_str = 'cd %s && ' % remote_path |
| 38 if '@' in hostline: | 41 if '@' in hostline: |
| 39 username, host = hostline.split('@') | 42 username, host = hostline.split('@') |
| 40 run_cmd = 'ssh %s@%s "cd %s && %s"' % (username, host, | 43 run_cmd = 'ssh %s@%s "%s%s"' % (username, host, cd_str, cmd) |
| 41 remote_path, cmd) | |
| 42 else: | 44 else: |
| 43 run_cmd = 'ssh %s "cd %s && %s"' % (host, remote_path, cmd) | 45 run_cmd = 'ssh %s "%s%s"' % (host, cd_str, cmd) |
| 44 | 46 |
| 45 else: | 47 else: |
| 46 run_cmd = "cd %s && %s" % (repo, cmd) | 48 if cd: |
| 49 cd_str = 'cd %s && ' % repo |
| 50 run_cmd = "%s%s" % (cd_str, cmd) |
| 47 | 51 |
| 48 if run_cmd: | 52 if run_cmd: |
| 49 return utils.run(run_cmd, ignore_status=ignore_status) | 53 return utils.run(run_cmd, ignore_status=ignore_status) |
| 50 | 54 |
| 51 | 55 |
| 56 def create_directory(repo): |
| 57 _, remote_path = parse_ssh_path(repo) |
| 58 repo_run_command(repo, 'mkdir -p %s' % remote_path, cd=False) |
| 59 |
| 60 |
| 52 def check_diskspace(repo, min_free=None): | 61 def check_diskspace(repo, min_free=None): |
| 53 # Note: 1 GB = 10**9 bytes (SI unit). | 62 # Note: 1 GB = 10**9 bytes (SI unit). |
| 54 if not min_free: | 63 if not min_free: |
| 55 min_free = global_config.global_config.get_config_value('PACKAGES', | 64 min_free = global_config.global_config.get_config_value('PACKAGES', |
| 56 'minimum_free_space', | 65 'minimum_free_space', |
| 57 type=int) | 66 type=int) |
| 58 try: | 67 try: |
| 59 df = repo_run_command(repo, | 68 df = repo_run_command(repo, |
| 60 'df -PB %d . | tail -1' % 10**9).stdout.split() | 69 'df -PB %d . | tail -1' % 10**9).stdout.split() |
| 61 free_space_gb = int(df[3]) | 70 free_space_gb = int(df[3]) |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 265 | 274 |
| 266 def repo_check(self, repo): | 275 def repo_check(self, repo): |
| 267 ''' | 276 ''' |
| 268 Check to make sure the repo is in a sane state: | 277 Check to make sure the repo is in a sane state: |
| 269 ensure we have at least XX amount of free space | 278 ensure we have at least XX amount of free space |
| 270 Make sure we can write to the repo | 279 Make sure we can write to the repo |
| 271 ''' | 280 ''' |
| 272 if not repo.startswith('/') and not repo.startswith('ssh:'): | 281 if not repo.startswith('/') and not repo.startswith('ssh:'): |
| 273 return | 282 return |
| 274 try: | 283 try: |
| 284 # without comment out this, we lost the ability to package into |
| 285 # local directories. -- ericli |
| 286 # create_directory(repo) |
| 275 check_diskspace(repo) | 287 check_diskspace(repo) |
| 276 check_write(repo) | 288 check_write(repo) |
| 277 except (error.RepoWriteError, error.RepoUnknownError, | 289 except (error.RepoWriteError, error.RepoUnknownError, |
| 278 error.RepoDiskFullError), e: | 290 error.RepoDiskFullError), e: |
| 279 raise error.RepoError("ERROR: Repo %s: %s" % (repo, e)) | 291 raise error.RepoError("ERROR: Repo %s: %s" % (repo, e)) |
| 280 | 292 |
| 281 | 293 |
| 282 def upkeep(self, custom_repos=None): | 294 def upkeep(self, custom_repos=None): |
| 283 ''' | 295 ''' |
| 284 Clean up custom upload/download areas | 296 Clean up custom upload/download areas |
| (...skipping 569 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 854 if not match: | 866 if not match: |
| 855 return ('', url) | 867 return ('', url) |
| 856 group, filename = match.groups() | 868 group, filename = match.groups() |
| 857 # Generate the group prefix. | 869 # Generate the group prefix. |
| 858 group = re.sub(r'\W', '_', group) | 870 group = re.sub(r'\W', '_', group) |
| 859 # Drop the extension to get the raw test name. | 871 # Drop the extension to get the raw test name. |
| 860 testname = re.sub(r'\.tar\.bz2', '', filename) | 872 testname = re.sub(r'\.tar\.bz2', '', filename) |
| 861 # Drop any random numbers at the end of the test name if any | 873 # Drop any random numbers at the end of the test name if any |
| 862 testname = re.sub(r'\.(\d*)', '', testname) | 874 testname = re.sub(r'\.(\d*)', '', testname) |
| 863 return (group, testname) | 875 return (group, testname) |
| OLD | NEW |