Skip to content

Commit a957d52

Browse files
author
Likitha Shetty
committed
CLOUDSTACK-5707. Hitting multiple 'User unauthenticated' exceptions when vCenter is upgraded to 5.5 from 5.1.
We hit these excptions whenever a management server held session that was with the old 5.1 vCenter server is used to make resource calls to the new 5.5 vCenter. Validate a vCenter session context before it is being used to make a resource call. And if the context is invalid then discard the context and retrieve a new one. During the invalidation of an old context handle the context disconnect better by catching the appropriate exception and returning a newly created context. Conflicts: plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareContextFactory.java plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java plugins/hypervisors/vmware/src/com/cloud/storage/resource/VmwareSecondaryStorageResourceHandler.java vmware-base/src/com/cloud/hypervisor/vmware/util/VmwareContext.java
1 parent af657b3 commit a957d52

4 files changed

Lines changed: 31 additions & 17 deletions

File tree

plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareContextFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public static VmwareContext getContext(String vCenterAddress, String vCenterUser
8989
} else {
9090
// Validate current context and verify if vCenter session timeout value of the context matches the timeout value set by Admin
9191
if (!context.validate() || (context.getVimClient().getVcenterSessionTimeout() != s_vmwareMgr.getVcenterSessionTimeout())) {
92-
s_logger.info("Validation of the context faild. dispose and create a new one");
92+
s_logger.info("Validation of the context failed, dispose and create a new one");
9393
context.close();
9494
context = create(vCenterAddress, vCenterUserName, vCenterPassword);
9595
}

plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6896,10 +6896,16 @@ public VmwareHypervisorHost getHyperHost(VmwareContext context) {
68966896

68976897
@Override
68986898
public VmwareContext getServiceContext(Command cmd) {
6899-
if (s_serviceContext.get() != null)
6900-
return s_serviceContext.get();
6901-
69026899
VmwareContext context = null;
6900+
if(s_serviceContext.get() != null) {
6901+
context = s_serviceContext.get();
6902+
if (context.validate()) {
6903+
return context;
6904+
} else {
6905+
s_logger.info("Validation of the context failed, dispose and use a new one");
6906+
invalidateServiceContext(context);
6907+
}
6908+
}
69036909
try {
69046910
context = VmwareContextFactory.getContext(_vCenterAddress, _username, _password);
69056911
s_serviceContext.set(context);

plugins/hypervisors/vmware/src/com/cloud/storage/resource/VmwareSecondaryStorageResourceHandler.java

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -214,18 +214,23 @@ public VmwareContext getServiceContext(Command cmd) {
214214
_resource.ensureOutgoingRuleForAddress(vCenterAddress);
215215

216216
VmwareContext context = currentContext.get();
217-
if (context == null) {
217+
if (context != null) {
218+
if(!context.validate()) {
219+
invalidateServiceContext(context);
220+
context = null;
221+
} else {
222+
context.registerStockObject("serviceconsole", cmd.getContextParam("serviceconsole"));
223+
context.registerStockObject("manageportgroup", cmd.getContextParam("manageportgroup"));
224+
context.registerStockObject("noderuninfo", cmd.getContextParam("noderuninfo"));
225+
}
226+
}
227+
if(context == null) {
218228
s_logger.info("Open new VmwareContext. vCenter: " + vCenterAddress + ", user: " + username + ", password: " +
219-
StringUtils.getMaskedPasswordForDisplay(password));
229+
StringUtils.getMaskedPasswordForDisplay(password));
220230
VmwareSecondaryStorageContextFactory.setVcenterSessionTimeout(vCenterSessionTimeout);
221231
context = VmwareSecondaryStorageContextFactory.getContext(vCenterAddress, username, password);
222232
}
223233

224-
if (context != null) {
225-
context.registerStockObject("serviceconsole", cmd.getContextParam("serviceconsole"));
226-
context.registerStockObject("manageportgroup", cmd.getContextParam("manageportgroup"));
227-
context.registerStockObject("noderuninfo", cmd.getContextParam("noderuninfo"));
228-
}
229234
currentContext.set(context);
230235
return context;
231236
} catch (Exception e) {

vmware-base/src/com/cloud/hypervisor/vmware/util/VmwareContext.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import javax.net.ssl.HostnameVerifier;
3838
import javax.net.ssl.HttpsURLConnection;
3939
import javax.net.ssl.SSLSession;
40+
import javax.xml.ws.soap.SOAPFaultException;
4041

4142
import org.apache.log4j.Logger;
4243

@@ -638,16 +639,18 @@ private static void connectWithRetry(HttpURLConnection conn) throws Exception {
638639
public void close() {
639640
clearStockObjects();
640641
try {
642+
s_logger.info("Disconnecting VMware session");
641643
_vimClient.disconnect();
644+
} catch(SOAPFaultException sfe) {
645+
s_logger.debug("Tried to disconnect a session that is no longer valid");
642646
} catch (Exception e) {
643647
s_logger.warn("Unexpected exception: ", e);
648+
} finally {
649+
if (_pool != null) {
650+
_pool.unregisterOutstandingContext(this);
651+
}
652+
unregisterOutstandingContext();
644653
}
645-
646-
if (_pool != null) {
647-
_pool.unregisterOutstandingContext(this);
648-
}
649-
650-
unregisterOutstandingContext();
651654
}
652655

653656
public static class TrustAllManager implements javax.net.ssl.TrustManager, javax.net.ssl.X509TrustManager {

0 commit comments

Comments
 (0)