summaryrefslogtreecommitdiff
path: root/tempest-pull/app/app.py
blob: 22d8f2a8fd2cd221109d2570f1a138f4a47dd056 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import gc
import os
import string
import urllib2

from neo4j import Neo4JDatabase
from lava import LAVADashboard
from bundlestore import BundleStore
from bundle import Bundle

def run(config, print_config):
   if print_config:
      print config

   # allow overriding the contents of config with values from the environment
   for s in [ "BUNDLE_STREAM_NAME", "BUNDLES_ROOT", "LOGS_ROOT", "LAVA_XMLRPC_ENDPOINT", "NEO4J_ENDPOINT" ]:
      if s in os.environ:
         new_val = os.environ.get(s)
         print "overriding config [%s] from environment: '%s'" % (s, new_val)
         config[s] = new_val

   # pull misc data files
   annotations = urllib2.urlopen('https://git.linaro.org/leg/openstack/lava-openstack.git/blob/HEAD:/test-annotations.json')
   with open(os.path.combine(config["LOGS_ROOT"], 'test-annotations.json'), 'w') as f:
      f.write(annotations.read())

   # pull result bundles from LAVA
   lava = LAVADashboard(config["LAVA_XMLRPC_ENDPOINT"], config["BUNDLE_STREAM_NAME"])
   lava.connect()

   store = BundleStore(config["BUNDLES_ROOT"])
   store_sha1_list = store.bundle_list()

   bundle_sha1_list, bundle_list = lava.server_bundle_list()
   for entry in bundle_list:
      sha1 = entry["content_sha1"]
      if sha1 in store_sha1_list:
         print "[%s] skipping, already processed" % sha1
         continue

      print "------------------------------------------------------------------------------------------------------"

      print "downloading new entry:"
      print entry

      bundle = lava.retrieve_bundle(entry)

      print "[%s]:" % sha1
      
      metadata = bundle.expand(config["WHITELIST"], config["LOGS_ROOT"])

      if metadata is None:
         print "Invalid / incomplete bundle - skipping"
      else:
         database = Neo4JDatabase(config["NEO4J_ENDPOINT"])
         database.store_bundle(bundle)
         store.write_bundle_receipt(bundle)

      del bundle
      gc.collect()