Improvement: Return more states in the 'detailed-status' field - client side 86/7586/7
authorkuuse <johan.kuuse@altran.com>
Fri, 31 May 2019 10:25:42 +0000 (12:25 +0200)
committerkuuse <johan.kuuse@altran.com>
Fri, 14 Jun 2019 12:19:03 +0000 (14:19 +0200)
Change-Id: I425d3a9fe188d07a9be20626ce641325a8602e6a
Signed-off-by: kuuse <johan.kuuse@altran.com>
osmclient/common/wait.py
osmclient/scripts/osm.py
osmclient/sol005/sdncontroller.py
osmclient/sol005/vim.py
osmclient/sol005/wim.py

index 9610856..f55ed6b 100644 (file)
@@ -30,9 +30,7 @@ TIMEOUT_SDNC_OPERATION = TIMEOUT_GENERIC_OPERATION
 TIMEOUT_VIM_OPERATION = TIMEOUT_GENERIC_OPERATION
 TIMEOUT_WIM_OPERATION = TIMEOUT_GENERIC_OPERATION
 TIMEOUT_NS_OPERATION = 3600
-
 POLLING_TIME_INTERVAL = 1
-
 MAX_DELETE_ATTEMPTS = 3
 
 def _show_detailed_status(old_detailed_status, new_detailed_status):
@@ -66,7 +64,7 @@ def _get_operational_state(resp, entity):
         return resp.get('_admin', {}).get('operationalState')
 
 def _op_has_finished(resp, entity):
-    # _op_has_finished() returns:
+    # This function returns:
     # 0 on success (operation has finished)
     # 1 on pending (operation has not finished)
     # -1 on error (bad response)
@@ -113,6 +111,7 @@ def wait_for_status(entity_label, entity_id, timeout, apiUrlStatus, http_cmd, de
     detailed_status_deleted = None
     time_to_return = False
     delete_attempts_left = MAX_DELETE_ATTEMPTS
+    wait_for_404 = False
     try:
         while True:
             http_code, resp_unicode = http_cmd('{}/{}'.format(apiUrlStatus, entity_id))
@@ -127,6 +126,10 @@ def wait_for_status(entity_label, entity_id, timeout, apiUrlStatus, http_cmd, de
                 # Display 'detailed-status: Deleted' and return
                 time_to_return = True
                 detailed_status_deleted = 'Deleted'
+            elif deleteFlag and http_code in (200, 201, 202, 204):
+                # In case of deletion and HTTP Status = 20* OK, deletion may be PROCESSING or COMPLETED
+                # If this is the case, we should keep on polling until 404 (deleted) is returned.
+                wait_for_404 = True
             elif http_code not in (200, 201, 202, 204):
                 raise ClientException(str(resp))
             if not time_to_return:
@@ -148,12 +151,14 @@ def wait_for_status(entity_label, entity_id, timeout, apiUrlStatus, http_cmd, de
                     else:
                         # Operation has finished, either with success or error
                         if deleteFlag:
-                            if delete_attempts_left < MAX_DELETE_ATTEMPTS:
-                                time_to_return = True
                             delete_attempts_left -= 1
+                            if not wait_for_404 and delete_attempts_left < MAX_DELETE_ATTEMPTS:
+                                time_to_return = True
                         else:
                             time_to_return = True
             new_detailed_status = _get_detailed_status(resp, entity_label, detailed_status_deleted)
+            # print 'DETAILED-STATUS: {}'.format(new_detailed_status)
+            # print 'DELETE-ATTEMPTS-LEFT: {}'.format(delete_attempts_left)
             if not new_detailed_status:
                 new_detailed_status = 'In progress'
             # TODO: Change LCM to provide detailed-status more up to date
index 5dacfe4..c369ff5 100755 (executable)
@@ -2203,7 +2203,7 @@ def sdnc_list(ctx, filter):
     except ClientException as inst:
         print((inst.message))
         exit(1)
-    table = PrettyTable(['name', 'id'])
+    table = PrettyTable(['sdnc name', 'id'])
     for sdnc in resp:
         table.add_row([sdnc['name'], sdnc['_id']])
     table.align = 'l'
index 6a6c1c1..6f63a9a 100644 (file)
@@ -51,11 +51,11 @@ class SdnController(object):
     def _get_id_for_wait(self, name):
         # Returns id of name, or the id itself if given as argument
         for sdnc in self.list():
-            if name == sdnc['name']:
-                return sdnc['_id']
-        for wim in self.list():
             if name == sdnc['_id']:
                 return sdnc['_id']
+        for sdnc in self.list():
+            if name == sdnc['name']:
+                return sdnc['_id']
         return ''
 
     def create(self, name, sdn_controller, wait=False):
@@ -87,18 +87,17 @@ class SdnController(object):
         sdnc_id_for_wait = self._get_id_for_wait(name)
         http_code, resp = self._http.put_cmd(endpoint='{}/{}'.format(self._apiBase,sdnc['_id']),
                                        postfields_dict=sdn_controller)
-        #print 'HTTP CODE: {}'.format(http_code)
-        #print 'RESP: {}'.format(resp)
+        # print 'HTTP CODE: {}'.format(http_code)
+        # print 'RESP: {}'.format(resp)
         if http_code in (200, 201, 202, 204):
-            if resp:
-                resp = json.loads(resp)
-            if not resp or 'id' not in resp:
-                raise ClientException('unexpected response from server - {}'.format(
-                                      resp))
             if wait:
-                # Wait for status for SDNC instance update
-                self._wait(sdnc_id_for_wait)
-            print(resp['id'])
+                # In this case, 'resp' always returns None, so 'resp['id']' cannot be used.
+                # Use the previously obtained id instead.
+                wait_id = sdnc_id_for_wait
+                # Wait for status for VI instance update
+                self._wait(wait_id)
+            else:
+                pass
         else:
             msg = ""
             if resp:
index bd95d66..3012ae2 100644 (file)
@@ -48,6 +48,16 @@ class Vim(object):
             self._http.get2_cmd,
             deleteFlag=deleteFlag)
 
+    def _get_id_for_wait(self, name):
+        # Returns id of name, or the id itself if given as argument
+        for vim in self.list():
+            if name == vim['uuid']:
+                return vim['uuid']
+        for vim in self.list():
+            if name == vim['name']:
+                return vim['uuid']
+        return ''
+
     def create(self, name, vim_access, sdn_controller=None, sdn_port_mapping=None, wait=False):
         if 'vim-type' not in vim_access:
             #'openstack' not in vim_access['vim-type']):
@@ -95,7 +105,7 @@ class Vim(object):
 
     def update(self, vim_name, vim_account, sdn_controller, sdn_port_mapping, wait=False):
         vim = self.get(vim_name)
-
+        vim_id_for_wait = self._get_id_for_wait(vim_name)
         vim_config = {}
         if 'config' in vim_account:
             if vim_account.get('config')=="" and (sdn_controller or sdn_port_mapping):
@@ -114,18 +124,17 @@ class Vim(object):
         #vim_account['config'] = json.dumps(vim_config)
         http_code, resp = self._http.put_cmd(endpoint='{}/{}'.format(self._apiBase,vim['_id']),
                                        postfields_dict=vim_account)
-        #print 'HTTP CODE: {}'.format(http_code)
-        #print 'RESP: {}'.format(resp)
+        # print 'HTTP CODE: {}'.format(http_code)
+        # print 'RESP: {}'.format(resp)
         if http_code in (200, 201, 202, 204):
-            if resp:
-                resp = json.loads(resp)
-            if not resp or 'id' not in resp:
-                raise ClientException('unexpected response from server - {}'.format(
-                                      resp))
             if wait:
-                # Wait for status for VIM instance update
-                self._wait(resp.get('id'))
-            print(resp['id'])
+                # In this case, 'resp' always returns None, so 'resp['id']' cannot be used.
+                # Use the previously obtained id instead.
+                wait_id = vim_id_for_wait
+                # Wait for status for VI instance update
+                self._wait(wait_id)
+            else:
+                pass
         else:
             msg = ""
             if resp:
index defc536..bf10e5f 100644 (file)
@@ -51,10 +51,10 @@ class Wim(object):
     def _get_id_for_wait(self, name):
         # Returns id of name, or the id itself if given as argument
         for wim in self.list():
-            if name == wim['name']:
+            if name == wim['uuid']:
                 return wim['uuid']
         for wim in self.list():
-            if name == wim['uuid']:
+            if name == wim['name']:
                 return wim['uuid']
         return ''
 
@@ -120,13 +120,9 @@ class Wim(object):
         #print 'RESP: {}'.format(resp)
         if http_code in (200, 201, 202, 204):
             if wait:
-                # 'resp' may be None.
-                # In that case, 'resp['id']' cannot be used.
-                # In that case, 'resp['id']' cannot be used, so use the previously obtained id instead
+                # In this case, 'resp' always returns None, so 'resp['id']' cannot be used.
+                # Use the previously obtained id instead.
                 wait_id = wim_id_for_wait
-                if resp:
-                    resp = json.loads(resp)
-                    wait_id = resp.get('id')
                 # Wait for status for WIM instance update
                 self._wait(wait_id)
             else: