summaryrefslogtreecommitdiff
path: root/tempest-pull/app/neo4j.py
blob: 7f33600142dbaf147b1680b610271a3976cb25ac (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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import os
import string

from util import *
from py2neo import Graph, Node, Relationship
from bundle import Bundle

class Neo4JDatabase(object):
   def __init__(self, endpoint):
      self.endpoint = endpoint

   def store_bundle(self, bundle):
      if not isinstance(bundle, Bundle):
         raise Exception("argument is not a Bundle")

      graph = Graph(self.endpoint)

      print "creating graph for bundle"

      # axis:
      # find (or create) the OS version + distro node
      os_version = bundle.metadata["lava_job_attributes"]["os-version"]
      os_distro = bundle.metadata["lava_job_attributes"]["os-distro"]
      os_name = "%s/%s" % (os_distro, os_version)
      OS_node = graph.find_one("OS", "name", os_name)
      if not OS_node:
         print "creating new OS node: %s" % os_name
         OS_node = Node("OS", name=os_name, distro=os_distro, version=os_version)
         graph.create(OS_node)

      # axis:
      # find (or create) the Device node
      device = bundle.metadata["lava_testdef_metadata"]["devices"]
      Device_node = graph.find_one("Device", "name", device)
      if not Device_node:
         print "creating new Device node: %s" % device
         Device_node = Node("Device", name=device)
         graph.create(Device_node)

      # axis:
      # find (or create) the devstack branch node
      devstack_branch = bundle.metadata["lava_job_attributes"]["devstack-branch"]
      Branch_node = graph.find_one("Branch", "name", devstack_branch)
      if not Branch_node:
         print "creating new Branch node: %s" % devstack_branch
         Branch_node = Node("Branch", name=devstack_branch)
         graph.create(Branch_node)

      # create the main tempest run node and associate with the OS and Branch
      
      TempestRun_node = Node("Run", "Tempest",                \
         date = bundle.metadata["date_uploaded"],            \
         epoch_time = bundle.metadata["timestamp_uploaded"],  \
         lava_job = bundle.metadata["lava_job_id"],          \
         sha1 = bundle.metadata["bundle_sha1"])
      if bundle.all_tests:
         TempestRun_node.properties["all_tests"] = len(bundle.all_tests)
      if bundle.tests_run:
         TempestRun_node.properties["tests_run"] = len(bundle.tests_run)
      if bundle.failing_tests:
         TempestRun_node.properties["failing_tests"] = len(bundle.failing_tests)
      if bundle.skipped_tests:
         TempestRun_node.properties["skipped_tests"] = len(bundle.skipped_tests)
      if bundle.ignored_tests:
         TempestRun_node.properties["ignored_tests"] = len(bundle.ignored_tests)
      if bundle.passing_tests:
         TempestRun_node.properties["passing_tests"] = len(bundle.passing_tests)
      if bundle.enabled_services:
         TempestRun_node.properties["enabled_services"] = bundle.enabled_services
      if bundle.disabled_services:
         TempestRun_node.properties["disabled_services"] = bundle.disabled_services
      OS_relationship = Relationship(TempestRun_node, "ON", OS_node)
      Branch_relationship = Relationship(TempestRun_node, "USING", Branch_node)
      Device_relationship = Relationship(TempestRun_node, "ON", Device_node)
      graph.create(TempestRun_node, OS_relationship, Branch_relationship, Device_relationship)

      # find the necessary test nodes (or create missing ones)  and relate them back
      # to the tempest node
      for test_set in [bundle.failing_tests, bundle.passing_tests, bundle.skipped_tests, bundle.ignored_tests]:
         if test_set:
            print "adding tests"
            for test in test_set:
               test_key = test["class"] + "::" + test["name"]
               Test_node = graph.find_one("Test", "key", test_key)
               if not Test_node:
                  print "creating new Test node: %s" % test["fullname"]
                  Test_node = Node("Test",  \
                     name=test["name"], \
                     key=test_key, \
                     full_name=test["fullname"], \
                     test_class=test["class"], \
                     test_category=test["category"])
               Test_relationship = Relationship(TempestRun_node, \
                  "HAS_TEST", Test_node, status=test["status"], time=test["time"])
               if (test["status"] == "skip") or (test["status"] == "ignore"):
                  Test_relationship.properties["reason"] = test["reason"]
               graph.create(Test_node, Test_relationship)