fix autoinstall crash with no network
This commit is contained in:
parent
d19de79e4c
commit
881be5ea52
|
@ -78,8 +78,11 @@ class MirrorController(SubiquityController):
|
||||||
async def apply_autoinstall_config(self, context):
|
async def apply_autoinstall_config(self, context):
|
||||||
if not self.geoip_enabled:
|
if not self.geoip_enabled:
|
||||||
return
|
return
|
||||||
|
if self.lookup_task.task is None:
|
||||||
|
return
|
||||||
try:
|
try:
|
||||||
await asyncio.wait_for(self.lookup_task.wait(), 10)
|
with context.child('waiting'):
|
||||||
|
await asyncio.wait_for(self.lookup_task.wait(), 10)
|
||||||
except asyncio.TimeoutError:
|
except asyncio.TimeoutError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@ -90,34 +93,34 @@ class MirrorController(SubiquityController):
|
||||||
self.check_state = CheckState.CHECKING
|
self.check_state = CheckState.CHECKING
|
||||||
self.lookup_task.start_sync()
|
self.lookup_task.start_sync()
|
||||||
|
|
||||||
async def lookup(self):
|
@with_context()
|
||||||
with self.context.child("lookup"):
|
async def lookup(self, context):
|
||||||
try:
|
try:
|
||||||
response = await run_in_thread(
|
response = await run_in_thread(
|
||||||
requests.get, "https://geoip.ubuntu.com/lookup")
|
requests.get, "https://geoip.ubuntu.com/lookup")
|
||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
except requests.exceptions.RequestException:
|
except requests.exceptions.RequestException:
|
||||||
log.exception("geoip lookup failed")
|
log.exception("geoip lookup failed")
|
||||||
self.check_state = CheckState.FAILED
|
self.check_state = CheckState.FAILED
|
||||||
return
|
return
|
||||||
try:
|
try:
|
||||||
e = ElementTree.fromstring(response.text)
|
e = ElementTree.fromstring(response.text)
|
||||||
except ElementTree.ParseError:
|
except ElementTree.ParseError:
|
||||||
log.exception("parsing %r failed", response.text)
|
log.exception("parsing %r failed", response.text)
|
||||||
self.check_state = CheckState.FAILED
|
self.check_state = CheckState.FAILED
|
||||||
return
|
return
|
||||||
cc = e.find("CountryCode")
|
cc = e.find("CountryCode")
|
||||||
if cc is None:
|
if cc is None:
|
||||||
log.debug("no CountryCode found in %r", response.text)
|
log.debug("no CountryCode found in %r", response.text)
|
||||||
self.check_state = CheckState.FAILED
|
self.check_state = CheckState.FAILED
|
||||||
return
|
return
|
||||||
cc = cc.text.lower()
|
cc = cc.text.lower()
|
||||||
if len(cc) != 2:
|
if len(cc) != 2:
|
||||||
log.debug("bogus CountryCode found in %r", response.text)
|
log.debug("bogus CountryCode found in %r", response.text)
|
||||||
self.check_state = CheckState.FAILED
|
self.check_state = CheckState.FAILED
|
||||||
return
|
return
|
||||||
self.check_state = CheckState.DONE
|
self.check_state = CheckState.DONE
|
||||||
self.model.set_country(cc)
|
self.model.set_country(cc)
|
||||||
|
|
||||||
def start_ui(self):
|
def start_ui(self):
|
||||||
self.check_state = CheckState.DONE
|
self.check_state = CheckState.DONE
|
||||||
|
|
Loading…
Reference in New Issue