mirror of
https://github.com/kevingruesser/bootstrap-vz.git
synced 2025-08-24 15:36:27 +00:00
Add CheckAptProxy task
Check if the specified APT proxy server can be reached, informing the user if this can't be done. That will help them to debug the errors that will be raised by `apt-get` because of the misleading proxy configuration. This closes #95.
This commit is contained in:
parent
4f45749e13
commit
4ba701cfad
2 changed files with 24 additions and 1 deletions
|
@ -6,6 +6,7 @@ def validate_manifest(data, validator, error):
|
||||||
|
|
||||||
def resolve_tasks(taskset, manifest):
|
def resolve_tasks(taskset, manifest):
|
||||||
import tasks
|
import tasks
|
||||||
|
taskset.add(tasks.CheckAptProxy)
|
||||||
taskset.add(tasks.SetAptProxy)
|
taskset.add(tasks.SetAptProxy)
|
||||||
if not manifest.plugins['apt_proxy'].get('persistent', False):
|
if not manifest.plugins['apt_proxy'].get('persistent', False):
|
||||||
taskset.add(tasks.RemoveAptProxy)
|
taskset.add(tasks.RemoveAptProxy)
|
||||||
|
|
|
@ -2,12 +2,34 @@ from bootstrapvz.base import Task
|
||||||
from bootstrapvz.common import phases
|
from bootstrapvz.common import phases
|
||||||
from bootstrapvz.common.tasks import apt
|
from bootstrapvz.common.tasks import apt
|
||||||
import os
|
import os
|
||||||
|
import urllib2
|
||||||
|
|
||||||
|
|
||||||
|
class CheckAptProxy(Task):
|
||||||
|
description = 'Checking APT proxy server'
|
||||||
|
phase = phases.package_installation
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def run(cls, info):
|
||||||
|
proxy_address = info.manifest.plugins['apt_proxy']['address']
|
||||||
|
proxy_port = info.manifest.plugins['apt_proxy']['port']
|
||||||
|
proxy_url = 'http://{address}:{port}'.format(address=proxy_address, port=proxy_port)
|
||||||
|
try:
|
||||||
|
urllib2.urlopen(proxy_url, timeout=5)
|
||||||
|
except Exception as e:
|
||||||
|
# Default response from `apt-cacher-ng`
|
||||||
|
if isinstance(e, urllib2.HTTPError) and e.code == 404 and e.msg == 'Usage Information':
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
import logging
|
||||||
|
log = logging.getLogger(__name__)
|
||||||
|
log.error('The APT proxy server couldn\'t be reached. `apt-get` commands may fail from now on.')
|
||||||
|
|
||||||
|
|
||||||
class SetAptProxy(Task):
|
class SetAptProxy(Task):
|
||||||
description = 'Setting proxy for APT'
|
description = 'Setting proxy for APT'
|
||||||
phase = phases.package_installation
|
phase = phases.package_installation
|
||||||
successors = [apt.AptUpdate]
|
successors = [apt.AptUpdate, CheckAptProxy]
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def run(cls, info):
|
def run(cls, info):
|
||||||
|
|
Loading…
Add table
Reference in a new issue