[WebUI] Fix error stopping daemon in connection manager
The wrong number of arguments was being parsed from get_host_info.
This commit is contained in:
parent
80985c02da
commit
1e5f248fb8
|
@ -78,27 +78,28 @@ class TestWebAPI(WebServerTestBase):
|
|||
|
||||
@defer.inlineCallbacks
|
||||
def get_host_status(self):
|
||||
host = list(self.deluge_web.web_api._get_host(self.host_id))
|
||||
host = list(self.deluge_web.web_api.hostlist.get_host_info(self.host_id))
|
||||
host[3] = 'Online'
|
||||
host[4] = '2.0.0.dev562'
|
||||
status = yield self.deluge_web.web_api.get_host_status(self.host_id)
|
||||
assert status == tuple(status)
|
||||
|
||||
def test_get_host(self):
|
||||
assert not self.deluge_web.web_api._get_host('invalid_id')
|
||||
conn = list(self.deluge_web.web_api.hostlist.get_hosts_info()[0])
|
||||
assert self.deluge_web.web_api._get_host(conn[0]) == conn[0:4]
|
||||
def test_get_hosts(self):
|
||||
hosts = self.deluge_web.web_api.hostlist.get_hosts_info()
|
||||
assert self.deluge_web.web_api.get_hosts() == hosts
|
||||
|
||||
def test_add_host(self):
|
||||
conn = ['abcdef', '10.0.0.1', 0, 'user123', 'pass123']
|
||||
assert not self.deluge_web.web_api._get_host(conn[0])
|
||||
assert not self.deluge_web.web_api.hostlist.get_host_info(conn[0])
|
||||
# Add valid host
|
||||
result, host_id = self.deluge_web.web_api.add_host(
|
||||
conn[1], conn[2], conn[3], conn[4]
|
||||
)
|
||||
assert result
|
||||
conn[0] = host_id
|
||||
assert self.deluge_web.web_api._get_host(conn[0]) == conn[0:4]
|
||||
assert (
|
||||
list(self.deluge_web.web_api.hostlist.get_host_info(conn[0])) == conn[0:4]
|
||||
)
|
||||
|
||||
# Add already existing host
|
||||
ret = self.deluge_web.web_api.add_host(conn[1], conn[2], conn[3], conn[4])
|
||||
|
@ -112,10 +113,10 @@ class TestWebAPI(WebServerTestBase):
|
|||
def test_remove_host(self):
|
||||
conn = ['connection_id', '', 0, '', '']
|
||||
self.deluge_web.web_api.hostlist.config['hosts'].append(conn)
|
||||
assert self.deluge_web.web_api._get_host(conn[0]) == conn[0:4]
|
||||
assert self.deluge_web.web_api.hostlist.get_host_info(conn[0]) == conn[0:4]
|
||||
# Remove valid host
|
||||
assert self.deluge_web.web_api.remove_host(conn[0])
|
||||
assert not self.deluge_web.web_api._get_host(conn[0])
|
||||
assert not self.deluge_web.web_api.hostlist.get_host_info(conn[0])
|
||||
# Remove non-existing host
|
||||
assert not self.deluge_web.web_api.remove_host(conn[0])
|
||||
|
||||
|
|
|
@ -22,9 +22,10 @@ from twisted.web import http, resource, server
|
|||
from deluge import component, httpdownloader
|
||||
from deluge.common import AUTH_LEVEL_DEFAULT, get_magnet_info, is_magnet
|
||||
from deluge.configmanager import get_config_dir
|
||||
from deluge.decorators import maybe_coroutine
|
||||
from deluge.error import NotAuthorizedError
|
||||
from deluge.i18n import get_languages
|
||||
from deluge.ui.client import Client, client
|
||||
from deluge.ui.client import client
|
||||
from deluge.ui.common import FileTree2, TorrentInfo
|
||||
from deluge.ui.coreconfig import CoreConfig
|
||||
from deluge.ui.hostlist import HostList
|
||||
|
@ -744,18 +745,6 @@ class WebApi(JSONComponent):
|
|||
deferreds.append(d)
|
||||
return DeferredList(deferreds, consumeErrors=False)
|
||||
|
||||
def _get_host(self, host_id):
|
||||
"""Information about a host from supplied host id.
|
||||
|
||||
Args:
|
||||
host_id (str): The id of the host.
|
||||
|
||||
Returns:
|
||||
list: The host information, empty list if not found.
|
||||
|
||||
"""
|
||||
return list(self.hostlist.get_host_info(host_id))
|
||||
|
||||
@export
|
||||
def get_hosts(self):
|
||||
"""
|
||||
|
@ -838,39 +827,18 @@ class WebApi(JSONComponent):
|
|||
client.start_daemon(port, get_config_dir())
|
||||
|
||||
@export
|
||||
def stop_daemon(self, host_id):
|
||||
"""
|
||||
Stops a running daemon.
|
||||
|
||||
:param host_id: the hash id of the host
|
||||
:type host_id: string
|
||||
"""
|
||||
main_deferred = Deferred()
|
||||
host = self._get_host(host_id)
|
||||
if not host:
|
||||
main_deferred.callback((False, _('Daemon does not exist')))
|
||||
return main_deferred
|
||||
|
||||
@maybe_coroutine
|
||||
async def stop_daemon(self, host_id):
|
||||
try:
|
||||
await self.hostlist.connect_host(host_id)
|
||||
except Exception as err:
|
||||
msg = f'Error occurred stopping daemon: {err}'
|
||||
result = (False, msg)
|
||||
else:
|
||||
client.daemon.shutdown()
|
||||
result = (True,)
|
||||
|
||||
def on_connect(connected, c):
|
||||
if not connected:
|
||||
main_deferred.callback((False, _('Daemon not running')))
|
||||
return
|
||||
c.daemon.shutdown()
|
||||
main_deferred.callback((True,))
|
||||
|
||||
def on_connect_failed(reason):
|
||||
main_deferred.callback((False, reason))
|
||||
|
||||
host, port, user, password = host[1:5]
|
||||
c = Client()
|
||||
d = c.connect(host, port, user, password)
|
||||
d.addCallback(on_connect, c)
|
||||
d.addErrback(on_connect_failed)
|
||||
except Exception:
|
||||
main_deferred.callback((False, 'An error occurred'))
|
||||
return main_deferred
|
||||
return Deferred().callback(result)
|
||||
|
||||
@export
|
||||
def get_config(self):
|
||||
|
|
Loading…
Reference in New Issue