Bug-144 -- set the URL for loganalyzer
[osm/SO.git] / rwlaunchpad / test / launchpad.py
index 239f91b..98680ba 100755 (executable)
@@ -1,6 +1,6 @@
 #!/usr/bin/env python3
 
-# 
+#
 #   Copyright 2016 RIFT.IO Inc
 #
 #   Licensed under the Apache License, Version 2.0 (the "License");
@@ -282,6 +282,32 @@ class AutoscalerTasklet(rift.vcs.core.Tasklet):
     plugin_directory = ClassProperty('./usr/lib/rift/plugins/rwautoscaler')
     plugin_name = ClassProperty('rwautoscaler')
 
+class StagingManagerTasklet(rift.vcs.core.Tasklet):
+    """
+    A class that provide a simple staging area for all tasklets
+    """
+
+    def __init__(self, name='StagingManager', uid=None,
+                 config_ready=True,
+                 recovery_action=core.RecoveryType.FAILCRITICAL.value,
+                 data_storetype=core.DataStore.NOSTORE.value,
+                 ):
+        """
+        Creates a StagingMangerTasklet object.
+
+        Arguments:
+            name  - the name of the tasklet
+            uid   - a unique identifier
+
+        """
+        super(StagingManagerTasklet, self).__init__(name=name, uid=uid,
+                                             config_ready=config_ready,
+                                             recovery_action=recovery_action,
+                                             data_storetype=data_storetype,
+                                            )
+
+    plugin_directory = ClassProperty('./usr/lib/rift/plugins/rwstagingmgr')
+    plugin_name = ClassProperty('rwstagingmgr')
 
 def get_ui_ssl_args():
     """Returns the SSL parameter string for launchpad UI processes"""
@@ -343,6 +369,32 @@ class ConfigManagerTasklet(rift.vcs.core.Tasklet):
     plugin_directory = ClassProperty('./usr/lib/rift/plugins/rwconmantasklet')
     plugin_name = ClassProperty('rwconmantasklet')
 
+class PackageManagerTasklet(rift.vcs.core.Tasklet):
+    """
+    This class represents a Resource Manager tasklet.
+    """
+
+    def __init__(self, name='Package-Manager', uid=None,
+                 config_ready=True,
+                 recovery_action=core.RecoveryType.FAILCRITICAL.value,
+                 data_storetype=core.DataStore.NOSTORE.value,
+                 ):
+        """
+        Creates a PackageManager object.
+
+        Arguments:
+            name  - the name of the tasklet
+            uid   - a unique identifier
+        """
+        super(PackageManagerTasklet, self).__init__(name=name, uid=uid,
+                                                   config_ready=config_ready,
+                                                   recovery_action=recovery_action,
+                                                   data_storetype=data_storetype,
+                                                  )
+
+    plugin_directory = ClassProperty('./usr/lib/rift/plugins/rwpkgmgr')
+    plugin_name = ClassProperty('rwpkgmgr')
+
 class GlanceServer(rift.vcs.NativeProcess):
     def __init__(self, name="glance-image-catalog",
                  config_ready=True,
@@ -393,12 +445,14 @@ class Demo(rift.vcs.demo.Demo):
         restart_procs = [
               VnfmTasklet(recovery_action=core.RecoveryType.RESTART.value, data_storetype=datastore),
               VnsTasklet(recovery_action=core.RecoveryType.RESTART.value, data_storetype=datastore),
-              MonitorTasklet(recovery_action=core.RecoveryType.RESTART.value, data_storetype=datastore),
+              MonitorTasklet(recovery_action=core.RecoveryType.RESTART.value, data_storetype=datastore),
               MonitoringParameterTasklet(recovery_action=core.RecoveryType.RESTART.value, data_storetype=datastore),
               NsmTasklet(recovery_action=core.RecoveryType.RESTART.value, data_storetype=datastore),
               ResMgrTasklet(recovery_action=core.RecoveryType.RESTART.value, data_storetype=datastore),
               ImageMgrTasklet(recovery_action=core.RecoveryType.RESTART.value, data_storetype=datastore),
               AutoscalerTasklet(recovery_action=core.RecoveryType.RESTART.value, data_storetype=datastore),
+              PackageManagerTasklet(recovery_action=core.RecoveryType.RESTART.value, data_storetype=datastore),
+              StagingManagerTasklet(recovery_action=core.RecoveryType.RESTART.value, data_storetype=datastore),
             ]
 
         if not mgmt_ip_list or len(mgmt_ip_list) == 0:
@@ -470,20 +524,42 @@ def main(argv=sys.argv[1:]):
     # since it doesn't need it and it will fail within containers
     os.environ["NO_KERNEL_MODS"] = "1"
 
+    cleanup_dir_name = None
+    if os.environ["INSTALLDIR"] in ["/", "/home/rift", "/home/rift/.install",
+        "/usr/rift/build/fc20_debug/install/usr/rift", "/usr/rift"]:
+        cleanup_dir_name = os.environ["INSTALLDIR"] + "/var/rift/"
+
+    if args.test_name and not cleanup_dir_name:
+        cleanup_dir_name = "find {rift_install}/var/rift -name '*{pattern}*' -type d".format( \
+            rift_install=os.environ['RIFT_INSTALL'],
+            pattern = args.test_name)
+        try:
+            cleanup_dir_name = subprocess.check_output(cleanup_dir_name, shell=True)
+            cleanup_dir_name = cleanup_dir_name[:-1].decode("utf-8") + "/"
+        except Exception as e:
+            print ("Directory not found exception occurred. Probably running for first time")
+            print ("Zookeper cleanup cmd = {}".format(cleanup_dir_name))
+    else:
+        if not cleanup_dir_name:
+          cleanup_dir_name = os.environ["INSTALLDIR"] + "/"
+
     # Remove the persistent Redis data
-    for f in os.listdir(os.environ["INSTALLDIR"]):
-        if f.endswith(".aof") or f.endswith(".rdb"):
-           os.remove(os.path.join(os.environ["INSTALLDIR"], f))
-    
-    # Remove the persistant DTS recovery files 
-    for f in os.listdir(os.environ["INSTALLDIR"]):
-        if f.endswith(".db"):
-            os.remove(os.path.join(os.environ["INSTALLDIR"], f))
     try:
-        shutil.rmtree(os.path.join(os.environ["INSTALLDIR"], "zk/server-1"))
+        for f in os.listdir(cleanup_dir_name):
+            if f.endswith(".aof") or f.endswith(".rdb"):
+                os.remove(os.path.join(cleanup_dir_name, f))
+    
+        # Remove the persistant DTS recovery files 
+        for f in os.listdir(cleanup_dir_name):
+            if f.endswith(".db"):
+                os.remove(os.path.join(cleanup_dir_name, f))
+
+        shutil.rmtree(os.path.join(cleanup_dir_name, "zk/server-1"))
         shutil.rmtree(os.path.join(os.environ["INSTALLDIR"], "var/rift/tmp*"))
-    except:
+    except FileNotFoundError as e:
         pass
+    except Exception as e:
+        print ("Error while cleanup: {}".format(str(e)))
 
     ha_mode = args.ha_mode
     mgmt_ip_list = [] if not args.mgmt_ip_list else args.mgmt_ip_list
@@ -496,10 +572,16 @@ def main(argv=sys.argv[1:]):
               northbound_listing="cli_launchpad_schema_listing.txt",
               netconf_trace_override=True)
 
-    confd_ip = socket.gethostbyname(socket.gethostname())
-    intf = netifaces.ifaddresses('eth0')
-    if intf and netifaces.AF_INET in intf and len(intf[netifaces.AF_INET]):
-       confd_ip = intf[netifaces.AF_INET][0]['addr']
+    # Search for externally accessible IP address with netifaces
+    gateways = netifaces.gateways()
+    # Check for default route facing interface and then get its ip address
+    if 'default' in gateways:
+        interface = gateways['default'][netifaces.AF_INET][1]
+        confd_ip = netifaces.ifaddresses(interface)[netifaces.AF_INET][0]['addr']
+    else:
+        # no default gateway.  Revert to 127.0.0.1
+        confd_ip = "127.0.0.1"
+    # TODO: This need to be changed when launchpad starts running on multiple VMs
     rift.vcs.logger.configure_sink(config_file=None, confd_ip=confd_ip)
 
     # Start the prepared system