Fix write options handling (#84)

* Fix write options handling

* Fix bug
This commit is contained in:
Pascal Vizeli 2017-06-28 23:06:06 +02:00 committed by GitHub
parent d5eb66bc0d
commit 56a9f64730
3 changed files with 15 additions and 9 deletions

View File

@ -235,7 +235,7 @@ class Addon(object):
"""Return path to this addon.""" """Return path to this addon."""
return Path(self._mesh[ATTR_LOCATON]) return Path(self._mesh[ATTR_LOCATON])
def write_addon_options(self): def write_options(self):
"""Return True if addon options is written to data.""" """Return True if addon options is written to data."""
schema = self.schema schema = self.schema
options = self.options options = self.options
@ -313,9 +313,6 @@ class Addon(object):
_LOGGER.error("Addon %s is not installed", self._id) _LOGGER.error("Addon %s is not installed", self._id)
return False return False
if not self.write_addon_options():
return False
return await self.addon_docker.run() return await self.addon_docker.run()
async def stop(self): async def stop(self):
@ -350,9 +347,6 @@ class Addon(object):
_LOGGER.error("Addon %s is not installed", self._id) _LOGGER.error("Addon %s is not installed", self._id)
return False return False
if not self.write_addon_options():
return False
return await self.addon_docker.restart() return await self.addon_docker.restart()
async def logs(self): async def logs(self):

View File

@ -3,6 +3,7 @@ import asyncio
import logging import logging
import voluptuous as vol import voluptuous as vol
from voluptuous.humanize import humanize_error
from .util import api_process, api_process_raw, api_validate from .util import api_process, api_process_raw, api_validate
from ..const import ( from ..const import (
@ -92,13 +93,20 @@ class APIAddons(object):
async def uninstall(self, request): async def uninstall(self, request):
"""Uninstall addon.""" """Uninstall addon."""
addon = self._extract_addon(request) addon = self._extract_addon(request)
return await asyncio.shield(addon.uninstall(), loop=self.loop) return await asyncio.shield(addon.uninstall(), loop=self.loop)
@api_process @api_process
async def start(self, request): async def start(self, request):
"""Start addon.""" """Start addon."""
addon = self._extract_addon(request) addon = self._extract_addon(request)
# check options
options = addon.options
try:
addon.schema(options)
except vol.Invalid as ex:
raise RuntimeError(humanize_error(options, ex)) from None
return await asyncio.shield(addon.start(), loop=self.loop) return await asyncio.shield(addon.start(), loop=self.loop)
@api_process @api_process

View File

@ -94,11 +94,15 @@ class DockerAddon(DockerBase):
Need run inside executor. Need run inside executor.
""" """
if self._is_running(): if self._is_running():
return return True
# cleanup # cleanup
self._stop() self._stop()
# write config
if not self.addon.write_options():
return False
try: try:
self.dock.containers.run( self.dock.containers.run(
self.image, self.image,