STC scenario to start/stop all apps in a minimal environment

Change-Id: I7364e0c348dcea9964124843f2cff2de9dcaafb3
diff --git a/tools/test/bin/onos-activate-all-scenario-default-app-list b/tools/test/bin/onos-activate-all-scenario-default-app-list
new file mode 100644
index 0000000..217f780
--- /dev/null
+++ b/tools/test/bin/onos-activate-all-scenario-default-app-list
@@ -0,0 +1,181 @@
+cpr
+mappingmanagement
+yang
+yang-gui
+config
+restconf
+protocols.restconfserver
+faultmanagement
+netconf
+netconfsb
+models.common
+models.l3vpn
+tunnel
+bgpcep
+l3vpn
+models.huawei
+drivers.huawei
+models.microsemi
+drivers.netconf
+netcfglinksprovider
+openflow-message
+cpman
+protocols.grpc
+protocols.p4runtime
+hostprovider
+ovsdb-base
+drivers.ovsdb
+openstacknode
+openstacknetworking
+models.ietf
+kafka-integration
+inbandtelemetry
+configsync
+models.tapi
+models.openconfig
+models.openconfig-infinera
+models.openconfig-odtn
+odtn-api
+restsb
+optical-model
+drivers.optical
+drivers.odtn-driver
+configsync-netconf
+# crashes in Atomix
+#odtn-service
+vtn
+loadtest
+protocols.gnmi
+generaldeviceprovider
+p4runtime
+drivers.p4runtime
+pipelines.basic
+pipelines.fabric
+events
+intentsynchronizer
+route-service
+fpm
+dhcprelay
+metrics
+fwd
+proxyarp
+models.polatis
+drivers.polatis.netconf
+lldpprovider
+openflow-base
+openflow
+drivers.corsa
+network-troubleshoot
+drivers.mellanox
+drivermatrix
+messaging-perf
+hostprobingprovider
+pcep-api
+distributedprimitives
+openstackvtap
+virtual
+models.openroadm
+openroadm
+tetopology
+tetunnel
+ovsdbhostprovider
+ovsdb
+drivers.barefoot
+influxdbmetrics
+evpn-route-service
+gluon
+evpnopenflow
+drivers.juniper
+pathpainter
+simplefabric
+flowanalyzer
+null
+# throws rejected execution exception
+#transaction-perf
+drivers.server
+drivers.gnmi
+drivers.stratum
+workflow
+fibinstaller
+vrouter
+sdnip
+artemis
+flow-perf
+# app crashes on startup
+#lisp
+#drivers.lisp
+rabbitmq
+snmp
+newoptical
+linkdiscovery
+drivers.arista
+pim
+routescale
+mcast
+segmentrouting
+# crashes during shutdown
+#bgprouter
+protocols.xmpp
+openstacktelemetry
+# crashes during shutdown
+#castor
+drivers.ciena.c5162
+netcfg-monitor
+xmpp.device
+flowspec-api
+routeradvertisement
+packet-stats
+mlb
+drivers.flowspec
+pcep
+ofagent
+demo
+t3
+virtualbng
+gangliametrics
+drivers.ciena.c5170
+drivers.oplink
+# missing dependency on startup
+# isis
+drivers.hp
+drivers.cisco.rest
+roadm
+drivers.bmv2
+vpls
+p4tutorial.pipeconf
+p4tutorial.mytunnel
+openstacktroubleshoot
+models.ciena.waveserverai
+drivers.ciena.waveserverai
+drivers.fujitsu
+drivers.polatis.openflow
+layout
+# missing a dependency
+#graphitemetrics
+powermanagement
+optical-rest
+tl1
+drivers.lumentum
+acl
+cord-support
+intentperf
+mfwd
+drivers.ciena.waveserver
+imr
+dhcp
+drivers.cisco.netconf
+openstacknetworkingui
+cfm
+scalablegateway
+cluster-ha
+drivers.microsemi.ea1000
+reactive-routing
+nodemetrics
+mobility
+bgp
+linkprops
+cip
+election
+primitiveperf
+protocols.xmpp.pubsub
+netcfghostprovider
\ No newline at end of file
diff --git a/tools/test/bin/onos-generate-activate-all-scenario b/tools/test/bin/onos-generate-activate-all-scenario
new file mode 100755
index 0000000..c12400b
--- /dev/null
+++ b/tools/test/bin/onos-generate-activate-all-scenario
@@ -0,0 +1,92 @@
+#!/usr/bin/env python
+
+import sys, os
+
+SCENARIO_HEADER = '''
+<!--
+  ~ Copyright 2019-present Open Networking Foundation
+  ~
+  ~ Licensed under the Apache License, Version 2.0 (the "License");
+  ~ you may not use this file except in compliance with the License.
+  ~ You may obtain a copy of the License at
+  ~
+  ~     http://www.apache.org/licenses/LICENSE-2.0
+  ~
+  ~ Unless required by applicable law or agreed to in writing, software
+  ~ distributed under the License is distributed on an "AS IS" BASIS,
+  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  ~ See the License for the specific language governing permissions and
+  ~ limitations under the License.
+  -->
+  
+  <!--
+     This scenario is auto generated by onos-generate-activate-all-scenario. DO NOT EDIT
+  -->
+  <scenario name="app-activate-all" description="Tests that all apps can be activated by themselves">
+    <group name="App-Activate-All">
+       <step name="App-Activate-All.Minimal-Apps"
+                 exec="onos-set-up-minimal-apps ${OCI}"/>
+'''
+
+SCENARIO_FOOTER = '''
+    </group>
+  </scenario>
+'''
+
+ACTIVATE_GROUP_TEMPLATE = '''
+        <group name="App-Activate-All.%(app_id)s" %(requires)s>
+           <step name="App-Activate-All.Activate-%(app_id)s"
+                 exec="onos ${OCI} app activate org.onosproject.%(app_id)s" %(requires)s/>
+           <group name="App-Activate-All.App-Check-%(app_id)s" requires="App-Activate-All.Activate-%(app_id)s">
+              <parallel var="${OC#}">
+                 <step name="App-Activate-All.App-Check-${#}-%(app_id)s"
+                       exec="onos-check-apps ${OC#} %(app_id)s includes"/>
+                 <step name="App-Activate-All.Check-Logs-${#}-%(app_id)s" exec="onos-check-logs ${OC#}"/>
+              </parallel>
+           </group>
+           <step name="App-Activate-All.App-Deactivate-%(app_id)s"
+                 exec="onos ${OCI} app deactivate org.onosproject.%(app_id)s" requires="App-Activate-All.App-Check-%(app_id)s"/>
+           <step name="App-Activate-All.Wait-For-Deactivate-%(app_id)s"
+                 exec="onos-check-apps ${OCI} org.onosproject.drivers" requires="App-Activate-All.App-Deactivate-%(app_id)s"/>      
+           <group name="App-Activate-All.App-Check-After-%(app_id)s" requires="App-Activate-All.Wait-For-Deactivate-%(app_id)s">
+              <parallel var="${OC#}">
+                 <step name="App-Activate-All.Check-Logs-After-${#}-%(app_id)s" exec="onos-check-logs ${OC#}"/>
+              </parallel>
+           </group>
+           <step name="App-Activate-All.Minimal-Apps-%(app_id)s" requires="App-Activate-All.App-Deactivate-%(app_id)s"
+                 exec="onos-set-up-minimal-apps ${OCI}"/>
+        </group>
+
+'''
+
+app_list = []
+app_list_file = ""
+
+if len(sys.argv) > 1:
+    app_list_file = sys.argv[1]
+else:
+    print "Usage: onos-generate-activate-all-scenario file-name-of-app-list"
+    sys.exit()
+
+with open(app_list_file) as apps:
+    for app in apps:
+        if not "#" in app:
+            normalized_app = app.strip(" \n")
+            if not normalized_app == "":
+                app_list.append(normalized_app)
+
+scenario = SCENARIO_HEADER + "\n"
+
+app_group_requires = 'requires="App-Activate-All.Minimal-Apps"'
+for app_id in app_list:
+    parameters = {
+        'requires': app_group_requires,
+        'app_id': app_id,
+    }
+    scenario = scenario + (ACTIVATE_GROUP_TEMPLATE % parameters)
+    app_group_requires = 'requires="App-Activate-All.' + app_id + '"'
+
+scenario = scenario + SCENARIO_FOOTER
+
+print scenario
+
diff --git a/tools/test/bin/onos-set-up-minimal-apps b/tools/test/bin/onos-set-up-minimal-apps
new file mode 100755
index 0000000..666c96c
--- /dev/null
+++ b/tools/test/bin/onos-set-up-minimal-apps
@@ -0,0 +1,44 @@
+#!/usr/bin/env python
+
+import subprocess, sys, json, os
+
+REQUIRED_APPS = ["org.onosproject.drivers"]
+
+
+def _main():
+    # Get the ONOS node address
+    onos_node = ""
+
+    if len(sys.argv) > 1:
+        onos_node = sys.argv[1]
+    else:
+        onos_node = os.environ["OCI"]
+
+    # Get a JSON representation of the apps that are currently running
+    current_apps_json = subprocess.check_output(["onos", onos_node, "onos:apps", "-a", "-s", "-j"])
+
+    # Determine which apps need to be deactivated
+    apps_to_deactivate = []
+    config = json.loads(current_apps_json)
+
+    for app_description in config:
+        apps_to_deactivate.append(app_description["name"])
+
+    # Deactivate all apps
+    if len(apps_to_deactivate) > 0:
+        deactivate_command = ["onos", onos_node, "onos:app", "deactivate"]
+        for app_to_deactivate in apps_to_deactivate:
+            deactivate_command.append(app_to_deactivate)
+        subprocess.check_output(deactivate_command)
+
+    # Activate apps that are part of the base set
+    if len(REQUIRED_APPS) > 0:
+        activate_command = ["onos", onos_node, "onos:app", "activate"]
+        for app_to_activate in REQUIRED_APPS:
+            activate_command.append(app_to_activate)
+        subprocess.check_output(activate_command)
+
+
+
+if __name__ == "__main__":
+    _main()