Thanks Wei-Chiu Chuang for working on this. The patch looks good to me overall and I think you are on the right direction for the fix.
Here are some of my comments:
1. The root cause of this issue is TestKMS#doAs() uses UserGroupInformation.getUGIFromSubject() to retrieve UGI for KMS restart tests. UGI returned from getUGIFromSubject does not contain any loginContext or Keytab file information. When this UGI is later invoked by the newly added code below in KMSClientProvider, it failed at UGI#reloginFromKeytab() because the the login requires loginContext and keytab information.
2. We should use try/finally to logout the user after ugi.doAs() in the new TestKMS#doAsFromKeytab. Ideally, we should update TestKMS#doAs directly to ensure it use the correct/compete UGI. This will need to add a new public logout method in the UGI class.