Fix bug 1162: return without printing VNF record when KDU status could not be determined
[osm/osmclient.git] / osmclient / scripts / osm.py
index 78f7896..af20edf 100755 (executable)
@@ -368,7 +368,8 @@ def ns_list(ctx, filter, long):
             else:
                 current_operation = "{} ({})".format(nsr['_admin'].get('current-operation','-'), nsr['_admin']['nslcmop'])
             error_details = "N/A"
-            if ns_state == "BROKEN" or ns_state == "DEGRADED" or nsr.get('errorDescription'):
+            if ns_state == "BROKEN" or ns_state == "DEGRADED" or \
+                ('currentOperation' not in nsr and nsr.get('errorDescription')):
                 error_details = "{}\nDetail: {}".format(nsr['errorDescription'], nsr['errorDetail'])
         else:
             nsopdata = ctx.obj.ns.get_opdata(ns['id'])
@@ -561,18 +562,6 @@ def vnfd_list2(ctx, nf_type, filter, long):
     logger.debug("")
     vnfd_list(ctx, nf_type, filter, long)
 
-@cli_osm.command(name='vnfpkg-repo-list', short_help='list all xNF from OSM repositories')
-@click.option('--filter', default=None,
-              help='restricts the list to the NFpkg matching the filter')
-@click.option('--repo', default=None,
-              help='restricts the list to a particular OSM repository')
-@click.option('--long', is_flag=True, help='get more details')
-@click.pass_context
-def vnfd_list3(ctx, filter, repo, long):
-    """list xNF packages from OSM repositories"""
-    pkgtype = 'vnf'
-    pkg_repo_list(ctx, pkgtype, filter, repo, long)
-
 @cli_osm.command(name='nfpkg-list', short_help='list all xNF packages (VNF, HNF, PNF)')
 @click.option('--nf_type', help='type of NF (vnf, pnf, hnf)')
 @click.option('--filter', default=None,
@@ -589,6 +578,18 @@ def nfpkg_list(ctx, nf_type, filter, long):
     #     print(str(e))
     #     exit(1)
 
+@cli_osm.command(name='vnfpkg-repo-list', short_help='list all xNF from OSM repositories')
+@click.option('--filter', default=None,
+              help='restricts the list to the NFpkg matching the filter')
+@click.option('--repo', default=None,
+              help='restricts the list to a particular OSM repository')
+@click.option('--long', is_flag=True, help='get more details')
+@click.pass_context
+def nfpkg_repo_list1(ctx, filter, repo, long):
+    """list xNF packages from OSM repositories"""
+    pkgtype = 'vnf'
+    pkg_repo_list(ctx, pkgtype, filter, repo, long)
+
 @cli_osm.command(name='nfpkg-repo-list', short_help='list all xNF from OSM repositories')
 @click.option('--filter', default=None,
               help='restricts the list to the NFpkg matching the filter')
@@ -596,7 +597,7 @@ def nfpkg_list(ctx, nf_type, filter, long):
               help='restricts the list to a particular OSM repository')
 @click.option('--long', is_flag=True, help='get more details')
 @click.pass_context
-def vnfd_list4(ctx, filter, repo, long):
+def nfpkg_repo_list2(ctx, filter, repo, long):
     """list xNF packages from OSM repositories"""
     pkgtype = 'vnf'
     pkg_repo_list(ctx, pkgtype, filter, repo, long)
@@ -670,7 +671,7 @@ def vnf_list1(ctx, ns, filter, long):
               help='restricts the list to a particular OSM repository')
 @click.option('--long', is_flag=True, help='get more details')
 @click.pass_context
-def nsd_list3(ctx, filter, repo, long):
+def nspkg_repo_list(ctx, filter, repo, long):
     """list xNF packages from OSM repositories"""
     pkgtype = 'ns'
     pkg_repo_list(ctx, pkgtype, filter, repo, long)
@@ -682,7 +683,7 @@ def nsd_list3(ctx, filter, repo, long):
               help='restricts the list to a particular OSM repository')
 @click.option('--long', is_flag=True, help='get more details')
 @click.pass_context
-def nspkg_list(ctx, filter, repo, long):
+def nspkg_repo_list2(ctx, filter, repo, long):
     """list xNF packages from OSM repositories"""
     pkgtype = 'ns'
     pkg_repo_list(ctx, pkgtype, filter, repo, long)
@@ -786,12 +787,12 @@ def ns_op_list(ctx, name, long):
         if op['lcmOperationType']=='action':
             action_name = op['operationParams']['primitive']
         detail = "-"
-        if op['operationState']=='PROCESSING':
-            if op['lcmOperationType'] in ('instantiate', 'terminate'):
+        if op['operationState'] == 'PROCESSING':
+            if op['queuePosition'] is not None and op['queuePosition'] > 0:
+                detail = "In queue. Current position: {}".format(op['queuePosition'])
+            elif op['lcmOperationType'] in ('instantiate', 'terminate'):
                 if op['stage']:
                     detail = op['stage']
-            else:
-                detail = "In queue. Current position: {}".format(op['queuePosition'])
         elif op['operationState'] in ('FAILED', 'FAILED_TEMP'):
             detail = op.get('errorMessage','-')
         date = datetime.fromtimestamp(op['startTime']).strftime("%Y-%m-%dT%H:%M:%S")
@@ -1305,6 +1306,7 @@ def vnf_show(ctx, name, literal, filter, kdu):
             time.sleep(5)
             t += 5
         print ("Could not determine KDU status")
+        return
 
     if literal:
         print(yaml.safe_dump(resp, indent=4, default_flow_style=False))