fix(xo-server/xen-servers): pool property not deleted on disconnecting a connecting server (#3977)

Fixes #3976
This commit is contained in:
badrAZ 2019-02-21 17:15:39 +01:00 committed by Pierre Donias
parent 7a2a88b7ad
commit 29b4cf414a
2 changed files with 37 additions and 15 deletions

View File

@ -12,7 +12,8 @@
- [Host] Fix multipathing status for XenServer < 7.5 [#3956](https://github.com/vatesfr/xen-orchestra/issues/3956) (PR [#3961](https://github.com/vatesfr/xen-orchestra/pull/3961)) - [Host] Fix multipathing status for XenServer < 7.5 [#3956](https://github.com/vatesfr/xen-orchestra/issues/3956) (PR [#3961](https://github.com/vatesfr/xen-orchestra/pull/3961))
- [Home/VM] Show creation date of the VM on if it available [#3953](https://github.com/vatesfr/xen-orchestra/issues/3953) (PR [#3959](https://github.com/vatesfr/xen-orchestra/pull/3959)) - [Home/VM] Show creation date of the VM on if it available [#3953](https://github.com/vatesfr/xen-orchestra/issues/3953) (PR [#3959](https://github.com/vatesfr/xen-orchestra/pull/3959))
- [Notifications] Fix invalid notifications when not registered (PR [#3966](https://github.com/vatesfr/xen-orchestra/pull/3966)) - [Notifications] Fix invalid notifications when not registered (PR [#3966](https://github.com/vatesfr/xen-orchestra/pull/3966))
- [Import] Fix import of some OVA files [#3962](https://github.com/vatesfr/xen-orchestra/issues/3962) (PR [##3974](https://github.com/vatesfr/xen-orchestra/pull/3974)) - [Import] Fix import of some OVA files [#3962](https://github.com/vatesfr/xen-orchestra/issues/3962) (PR [#3974](https://github.com/vatesfr/xen-orchestra/pull/3974))
- [Servers] Fix *already connected error* after a server has been removed during connection [#3976](https://github.com/vatesfr/xen-orchestra/issues/3976) (PR [#3977](https://github.com/vatesfr/xen-orchestra/pull/3977))
### Released packages ### Released packages

View File

@ -30,6 +30,15 @@ class PoolAlreadyConnected extends BaseError {
const log = createLogger('xo:xo-mixins:xen-servers') const log = createLogger('xo:xo-mixins:xen-servers')
// Server is disconnected:
// - _xapis[server.id] is undefined
// Server is connecting:
// - _xapis[server.id] is defined
// Server is connected:
// - _xapis[server.id] id defined
// - _serverIdsByPool[xapi.pool.$id] is server.id
export default class { export default class {
constructor(xo, { xapiOptions }) { constructor(xo, { xapiOptions }) {
this._objectConflicts = { __proto__: null } // TODO: clean when a server is disconnected. this._objectConflicts = { __proto__: null } // TODO: clean when a server is disconnected.
@ -267,6 +276,12 @@ export default class {
try { try {
await xapi.connect() await xapi.connect()
// requesting disconnection on the connecting server
if (this._xapis[server.id] === undefined) {
xapi.disconnect()::ignoreErrors()
return
}
const serverIdsByPool = this._serverIdsByPool const serverIdsByPool = this._serverIdsByPool
const poolId = xapi.pool.$id const poolId = xapi.pool.$id
if (serverIdsByPool[poolId] !== undefined) { if (serverIdsByPool[poolId] !== undefined) {
@ -390,15 +405,17 @@ export default class {
} }
async disconnectXenServer(id) { async disconnectXenServer(id) {
const xapi = this._xapis[id] const status = this._getXenServerStatus(id)
if (!xapi) { if (status === 'disconnected') {
throw noSuchObject(id, 'xenServer') return
} }
const xapi = this._xapis[id]
delete this._xapis[id] delete this._xapis[id]
delete this._serverIdsByPool[xapi.pool.$id] if (status === 'connected') {
delete this._serverIdsByPool[xapi.pool.$id]
xapi.xo.uninstall() xapi.xo.uninstall()
}
return xapi.disconnect() return xapi.disconnect()
} }
@ -425,18 +442,22 @@ export default class {
return xapi return xapi
} }
_getXenServerStatus(id) {
const xapi = this._xapis[id]
return xapi === undefined
? 'disconnected'
: this._serverIdsByPool[(xapi.pool?.$id)] === id
? 'connected'
: 'connecting'
}
async getAllXenServers() { async getAllXenServers() {
const servers = await this._servers.get() const servers = await this._servers.get()
const xapis = this._xapis const xapis = this._xapis
forEach(servers, server => { forEach(servers, server => {
const xapi = xapis[server.id] server.status = this._getXenServerStatus(server.id)
if (xapi !== undefined) { if (server.status === 'connected' && server.label === undefined) {
server.status = xapi.status server.label = xapis[server.id].pool.name_label
let pool
if (server.label === undefined && (pool = xapi.pool) != null) {
server.label = pool.name_label
}
} }
// Do not expose password. // Do not expose password.