Exemple #1
0
    def _create_entity_graph(self, name, num_of_alarms_per_host,
                             num_of_alarms_per_vm,
                             num_of_hosts_per_node,
                             num_of_vms_per_host,
                             num_of_tests_per_host):

        start = time.time()
        g = create_graph(name)
        g.add_vertex(v_node)
        g.add_vertex(v_switch)
        g.add_edge(e_node_to_switch)

        # Add Hosts
        for host_id in xrange(num_of_hosts_per_node):
            host_to_add = add_connected_vertex(g, RESOURCE, HOST, host_id,
                                               ELabel.CONTAINS, v_node, True)

            g.add_edge(graph_utils.create_edge(host_to_add.vertex_id,
                                               v_switch.vertex_id, 'USES'))

            # Add Host Alarms
            for j in xrange(num_of_alarms_per_host):
                add_connected_vertex(g, ALARM, ALARM_ON_HOST,
                                     self.host_alarm_id, ELabel.ON,
                                     host_to_add)
                self.host_alarm_id += 1

            # Add Host Tests
            for j in xrange(num_of_tests_per_host):
                add_connected_vertex(g, TEST, TEST_ON_HOST, self.host_test_id,
                                     ELabel.ON, host_to_add)
                self.host_test_id += 1

            # Add Host Vms
            for j in xrange(num_of_vms_per_host):
                vm_to_add = add_connected_vertex(g, RESOURCE, INSTANCE,
                                                 self.vm_id, ELabel.CONTAINS,
                                                 host_to_add, True)
                self.vm_id += 1
                self.vms.append(vm_to_add)

                # Add Instance Alarms
                for k in xrange(num_of_alarms_per_vm):
                    add_connected_vertex(g, ALARM, ALARM_ON_VM,
                                         self.vm_alarm_id, ELabel.ON,
                                         vm_to_add)
                    self.vm_alarm_id += 1

        end = time.time()
        LOG.debug('Graph creation took ' + str(end - start) +
                  ' seconds, size is: ' + str(len(g)))
        expected_graph_size = \
            2 + num_of_hosts_per_node + num_of_hosts_per_node * \
            num_of_alarms_per_host + num_of_hosts_per_node * \
            num_of_vms_per_host + num_of_hosts_per_node * \
            num_of_vms_per_host * num_of_alarms_per_vm + num_of_tests_per_host * \
            num_of_hosts_per_node
        assert expected_graph_size == len(g), 'Graph size'
        return g
Exemple #2
0
    def _evaluate_and_condition(self, condition, element, scenario_element):

        condition_g = create_graph("scenario condition")
        for term in condition:
            if not term.positive:
                # todo(erosensw): add support for NOT clauses
                LOG.error('Unsupported template with NOT operator')
                return []

            if term.type == ENTITY:
                term.variable[VProps.IS_DELETED] = False
                condition_g.add_vertex(term.variable)

            else:  # type = relationship
                edge_desc = term.variable
                self._set_relationship_not_deleted(edge_desc)
                self._add_relationship(condition_g, edge_desc)

        if isinstance(element, Vertex):
            initial_map = Mapping(scenario_element, element, True)
        else:
            initial_map = Mapping(scenario_element.edge, element, False)
        return self._graph_algs.sub_graph_matching(condition_g, [initial_map])
    def _evaluate_and_condition(self, condition, element, scenario_element):

        condition_g = create_graph("scenario condition")
        for term in condition:
            if not term.positive:
                # todo(erosensw): add support for NOT clauses
                LOG.error('Template with NOT operator current not supported')
                return []

            if term.type == ENTITY:
                term.variable[VProps.IS_DELETED] = False
                condition_g.add_vertex(term.variable)

            else:  # type = relationship
                edge_desc = term.variable
                self._set_relationship_not_deleted(edge_desc)
                self._add_relationship(condition_g, edge_desc)

        if isinstance(element, Vertex):
            initial_map = Mapping(scenario_element, element, True)
        else:
            initial_map = Mapping(scenario_element.edge, element, False)
        return self._graph_algs.sub_graph_matching(condition_g, [initial_map])
Exemple #4
0
    def _create_entity_graph(self, name, num_of_alarms_per_host,
                             num_of_alarms_per_vm,
                             num_of_hosts_per_node,
                             num_of_vms_per_host,
                             num_of_tests_per_host):

        start = time.time()
        g = create_graph(name, EntityCategory.RESOURCE + ':' +
                         OPENSTACK_CLUSTER)
        g.add_vertex(v_node)
        g.add_vertex(v_switch)
        g.add_edge(e_node_to_switch)

        # Add Hosts
        for host_id in range(num_of_hosts_per_node):
            host_to_add = add_connected_vertex(g,
                                               RESOURCE,
                                               NOVA_HOST_DATASOURCE,
                                               host_id,
                                               ELabel.CONTAINS,
                                               v_node,
                                               True)

            g.add_edge(graph_utils.create_edge(host_to_add.vertex_id,
                                               v_switch.vertex_id, 'USES'))

            # Add Host Alarms
            for j in range(num_of_alarms_per_host):
                add_connected_vertex(g, ALARM, ALARM_ON_HOST,
                                     self.host_alarm_id, ELabel.ON,
                                     host_to_add)
                self.host_alarm_id += 1

            # Add Host Tests
            for j in range(num_of_tests_per_host):
                add_connected_vertex(g, TEST, TEST_ON_HOST, self.host_test_id,
                                     ELabel.ON, host_to_add)
                self.host_test_id += 1

            # Add Host Vms
            for j in range(num_of_vms_per_host):
                vm_to_add = add_connected_vertex(g,
                                                 RESOURCE,
                                                 NOVA_INSTANCE_DATASOURCE,
                                                 self.vm_id,
                                                 ELabel.CONTAINS,
                                                 host_to_add,
                                                 True)
                self.vm_id += 1
                self.vms.append(vm_to_add)

                # Add Instance Alarms
                for k in range(num_of_alarms_per_vm):
                    add_connected_vertex(g, ALARM, ALARM_ON_VM,
                                         self.vm_alarm_id, ELabel.ON,
                                         vm_to_add)
                    self.vm_alarm_id += 1

        end = time.time()
        LOG.debug('Graph creation took ' + str(end - start) +
                  ' seconds, size is: ' + str(len(g)))
        expected_graph_size = \
            2 + num_of_hosts_per_node + num_of_hosts_per_node * \
            num_of_alarms_per_host + num_of_hosts_per_node * \
            num_of_vms_per_host + num_of_hosts_per_node * \
            num_of_vms_per_host * num_of_alarms_per_vm + \
            num_of_tests_per_host * num_of_hosts_per_node
        assert expected_graph_size == len(g), 'Graph size'
        return g