openbmctool: Handle PasswordChangeRequired.

Resolves openbmc/openbmc-tools#53

Tested: Tested with latest op940 release and Joseph's patch image
with the required password setting.

Signed-off-by: Joy Onyerikwu <onyekachukwu.joy.onyerikwu@ibm.com>
Change-Id: Id893e07cf455bd7d42862969e54595c1bac6fc58
diff --git a/thalerj/openbmctool.py b/thalerj/openbmctool.py
index 4541404..715284f 100755
--- a/thalerj/openbmctool.py
+++ b/thalerj/openbmctool.py
@@ -257,7 +257,7 @@
                 return True
     return False
 
-def login(host, username, pw,jsonFormat):
+def login(host, username, pw,jsonFormat, allowExpiredPassword):
     """
          Logs into the BMC and creates a session
 
@@ -265,6 +265,8 @@
          @param username: The user name for the bmc to log into
          @param pw: The password for the BMC to log into
          @param jsonFormat: boolean, flag that will only allow relevant data from user command to be display. This function becomes silent when set to true.
+         @param allowExpiredPassword: true, if the requested operation should
+                be allowed when the password is expired
          @return: Session object
     """
     if(jsonFormat==False):
@@ -282,6 +284,13 @@
             if (loginMessage['status'] != "ok"):
                 print(loginMessage["data"]["description"].encode('utf-8'))
                 sys.exit(1)
+            if (('extendedMessage' in r.json()) and
+                ('The password for this account must be changed' in r.json()['extendedMessage'])):
+                if not allowExpiredPassword:
+                    print("The password for this system has expired and must be changed"+
+                            "\nsee openbmctool.py set_password --help")
+                    logout(host, username, pw, mysess, jsonFormat)
+                    sys.exit(1)
 #         if(sys.version_info < (3,0)):
 #             urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
 #         if sys.version_info >= (3,0):
@@ -4776,7 +4785,7 @@
          main function for running the command line utility as a sub application
     """
     global toolVersion
-    toolVersion = "1.17"
+    toolVersion = "1.18"
     global isRedfishSupport
 
     parser = createCommandParser()
@@ -4806,7 +4815,8 @@
                 print("You must specify a password")
                 sys.exit()
             logintimeStart = int(round(time.time()*1000))
-            mysess = login(args.host, args.user, pw, args.json)
+            mysess = login(args.host, args.user, pw, args.json,
+                           args.command == 'set_password')
             if(mysess == None):
                 print("Login Failed!")
                 sys.exit()