CA-333443: Use the master's address instead of the connection name when joining a pool.

Also, moved code handling RBAC failure from the Failure class into the
PoolJoinAction because it is pretty specific to the latter action.

Signed-off-by: Konstantina Chremmou <konstantina.chremmou@citrix.com>
This commit is contained in:
Konstantina Chremmou 2020-05-02 03:17:40 +01:00 committed by Mihaela Stoica
parent d8cbf38cd8
commit 166fe0ecc5
2 changed files with 18 additions and 38 deletions

View File

@ -31,6 +31,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using XenAdmin.Core;
using XenAPI;
@ -91,24 +92,31 @@ namespace XenAdmin.Actions
bool fixedCpus = FixCpus(Pool, _hostsToCpuMask, AcceptNTolChanges);
if (fixedCpus)
Session = NewSession(); // We've rebooted the server, so we need to grab the new session
RelatedTask = XenAPI.Pool.async_join(Session, Pool.Connection.Hostname, Pool.Connection.Username, Pool.Connection.Password);
var master = Pool.Connection.TryResolveWithTimeout(Pool.master);
var address = master != null ? master.address : Pool.Connection.Hostname;
RelatedTask = Pool.async_join(Session, address, Pool.Connection.Username, Pool.Connection.Password);
PollToCompletion(0, 90);
}
catch (Exception e)
catch (Failure f)
{
Failure f = e as Failure;
// I think we shouldn't trigger this any more, because it's now checked in PoolJoinRules.
// This is probably not needed any more, because it's now checked in PoolJoinRules.
// But let's leave it here in case. SRET.
if (f != null && f.ErrorDescription[0] == Failure.RBAC_PERMISSION_DENIED)
if (f.ErrorDescription.Count > 1 && f.ErrorDescription[0] == Failure.RBAC_PERMISSION_DENIED)
{
Session[] sessions = new Session[] { Session, Pool.Connection.Session };
// Special parse to cope with multiple connections.
Failure.ParseRBACFailure(f, sessions);
// Will not get RBAC parsed again after the throw as we have altered the error description in ParseRBACFailure
throw f;
var sessions = new[] {Session, Pool.Connection.Session};
var authRoles = Role.ValidRoleList(f.ErrorDescription[1], Session.Connection);
var output = string.Join(", ", sessions.Select(s => string.Format(Messages.ROLE_ON_CONNECTION,
s.FriendlyRoleDescription(), Helpers.GetName(s.Connection).Ellipsise(50))));
throw new Failure(Failure.RBAC_PERMISSION_DENIED_FRIENDLY, output, Role.FriendlyCSVRoleList(authRoles));
}
throw;
}
// We need a master session for ClearNonSharedSrs.
// No need to log out the slave session, because the server is going to reset its database anyway.

View File

@ -31,9 +31,6 @@
using System;
using System.Collections.Generic;
using System.Text;
using XenAdmin;
using XenAdmin.Core;
using XenAdmin.Network;
@ -112,30 +109,5 @@ namespace XenAPI
failure.ErrorDescription[2] = Role.FriendlyCSVRoleList(authRoles);
failure.ParseExceptionMessage();
}
/// <summary>
/// This overload is for the special case of us doing an action over multiple connections. Assumes the role requirement is the same across all conections.
/// </summary>
/// <param name="failure">The Failure to update</param>
/// <param name="Sessions">One session per connection, the ones used to perform the action. Passed separately because they could be elevated sessions, different to the heartbeat</param>
public static void ParseRBACFailure(Failure failure, Session[] Sessions)
{
List<Role> authRoles = Role.ValidRoleList(failure.ErrorDescription[1], Sessions[0].Connection);
failure.ErrorDescription[0] = Failure.RBAC_PERMISSION_DENIED_FRIENDLY;
// Current Role(s)
StringBuilder sb = new StringBuilder();
foreach (Session s in Sessions)
{
sb.Append(string.Format(Messages.ROLE_ON_CONNECTION, s.FriendlyRoleDescription(), Helpers.GetName(s.Connection).Ellipsise(50)));
sb.Append(", ");
}
string output = sb.ToString();
// remove trailing comma and space
output = output.Substring(0, output.Length - 2);
failure.ErrorDescription[1] = output;
// Authorized roles
failure.ErrorDescription[2] = Role.FriendlyCSVRoleList(authRoles);
failure.ParseExceptionMessage();
}
}
}