~rvb/maas/transaction-1.7-bug-1409852

« back to all changes in this revision

Viewing changes to src/maasserver/rpc/tests/test_nodegroupinterface.py

merged upstream

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright 2014 Canonical Ltd.  This software is licensed under the
 
2
# GNU Affero General Public License version 3 (see the file LICENSE).
 
3
 
 
4
"""Tests for `NodeGroupInterface` part of region service."""
 
5
 
 
6
from __future__ import (
 
7
    absolute_import,
 
8
    print_function,
 
9
    unicode_literals,
 
10
    )
 
11
 
 
12
str = None
 
13
 
 
14
__metaclass__ = type
 
15
__all__ = []
 
16
 
 
17
from maasserver.rpc.nodegroupinterface import get_cluster_interfaces_as_dicts
 
18
from maasserver.testing.factory import factory
 
19
from maasserver.testing.testcase import MAASServerTestCase
 
20
 
 
21
 
 
22
class TestGetClusterInterfacesAsDicts(MAASServerTestCase):
 
23
 
 
24
    def test__returns_cluster_interface(self):
 
25
        interface = factory.make_NodeGroupInterface(factory.make_NodeGroup())
 
26
        self.assertEqual(
 
27
            [
 
28
                {
 
29
                    b'name': interface.name,
 
30
                    b'interface': interface.interface,
 
31
                    b'ip': interface.ip,
 
32
                },
 
33
            ],
 
34
            get_cluster_interfaces_as_dicts(interface.nodegroup.uuid))
 
35
 
 
36
    def test__returns_all_interfaces_on_cluster(self):
 
37
        nodegroup = factory.make_NodeGroup()
 
38
        interfaces = [
 
39
            factory.make_NodeGroupInterface(nodegroup)
 
40
            for _ in range(3)
 
41
            ]
 
42
        received_interfaces = get_cluster_interfaces_as_dicts(nodegroup.uuid)
 
43
        self.assertItemsEqual(
 
44
            [expected_interface.name for expected_interface in interfaces],
 
45
            [
 
46
                received_interface['name']
 
47
                for received_interface in received_interfaces
 
48
            ])
 
49
 
 
50
    def test__ignores_other_clusters(self):
 
51
        nodegroup = factory.make_NodeGroup()
 
52
        factory.make_NodeGroupInterface(factory.make_NodeGroup())
 
53
        self.assertEqual([], get_cluster_interfaces_as_dicts(nodegroup.uuid))