Beispiel #1
0
 def test_get_role_relations(self):
     """Should return role dependencies when roles with relationships are given"""
     prod_nodes = chef.filter_nodes(self.nodes, "production")
     extra_roles = graphs.get_role_relations("production", "dbserver", prod_nodes)
     self.assertEqual(extra_roles, ["webserver", "worker"])
     extra_roles = graphs.get_role_relations("production", "loadbalancer", prod_nodes)
     self.assertEqual(extra_roles, ["webserver"])
     extra_roles = graphs.get_role_relations("production", "worker", prod_nodes)
     self.assertEqual(extra_roles, ["dbserver"])
     extra_roles = graphs.get_role_relations("production", "webserver", prod_nodes)
     self.assertEqual(extra_roles, ["dbserver", "loadbalancer"])
Beispiel #2
0
 def test_get_role_relations(self):
     """Should return role dependencies when roles with relationships are given"""
     prod_nodes = chef.filter_nodes(self.nodes, 'production')
     extra_roles = graphs.get_role_relations('production', 'dbserver',
                                             prod_nodes)
     self.assertEqual(extra_roles, ['webserver', 'worker'])
     extra_roles = graphs.get_role_relations('production', 'loadbalancer',
                                             prod_nodes)
     self.assertEqual(extra_roles, ['webserver'])
     extra_roles = graphs.get_role_relations('production', 'worker',
                                             prod_nodes)
     self.assertEqual(extra_roles, ['dbserver'])
     extra_roles = graphs.get_role_relations('production', 'webserver',
                                             prod_nodes)
     self.assertEqual(extra_roles, ['dbserver', 'loadbalancer'])
Beispiel #3
0
def graph(request):
    """Graph view where users can visualize graphs of their nodes
    generated using Graphviz open source graph visualization library

    """
    _show_repo_sync_date(request)
    data = {}
    options = _set_options(request.GET.get('options'))
    env_filter = request.GET.get('env', REPO['DEFAULT_ENV'])
    roles_filter = request.GET.get('roles', '')
    env_nodes = []
    try:
        data = _get_data(request, env_filter, '', 'guest')
    except RepoError as e:
        add_message(request, ERROR, str(e))
    else:
        if env_filter:
            env_nodes = data['nodes_extended']
            if roles_filter:
                # Filter the env nodes by role
                data['nodes_extended'] = filter_nodes(data['nodes_extended'],
                                                      roles=roles_filter)
                data['filter_roles'] = roles_filter
            success, msg = graphs.generate_node_map(
                data['nodes_extended'], data.get('roles', []),
                'show_hostnames' in options)
            data['draw_graph'] = success
            if not success:
                add_message(request, ERROR, msg)
            else:
                data['related_roles'] = graphs.get_role_relations(env_filter,
                                                                  roles_filter,
                                                                  env_nodes)
        else:
            add_message(request, WARNING, "Please select an environment")

    data['show_hostnames'] = 'show_hostnames' in options
    data['query_string'] = request.META['QUERY_STRING']

    return render_to_response('graph.html',
                              data, context_instance=RequestContext(request))
Beispiel #4
0
 def test_get_role_relations_empty_when_no_roles(self):
     """Should obtain no roles when a role filter list is not given"""
     prod_nodes = chef.filter_nodes(self.nodes, 'staging')
     extra_roles = graphs.get_role_relations('production', '', prod_nodes)
     self.assertEqual(extra_roles, [])
Beispiel #5
0
 def test_get_role_relations_empty_when_roles(self):
     """Should obtain no roles when the given roles have no extra relationships"""
     stag_nodes = chef.filter_nodes(self.nodes, 'staging')
     extra_roles = graphs.get_role_relations('staging', 'webserver',
                                             stag_nodes)
     self.assertEqual(extra_roles, [])