summaryrefslogtreecommitdiffstats
path: root/snaps/domain/test/network_tests.py
blob: c394b4ae808e644e13683717d3af2eb0148d3c6d (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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
# Copyright (c) 2017 Cable Television Laboratories, Inc. ("CableLabs")
#                    and others.  All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at:
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import unittest
from snaps.domain.network import (
    Port, SecurityGroup, SecurityGroupRule,  Router, InterfaceRouter)


class PortDomainObjectTests(unittest.TestCase):
    """
    Tests the construction of the snaps.domain.network.Port class
    """

    def test_construction_kwargs(self):
        ips = ['10', '11']
        port = Port(
            **{'name': 'name', 'id': 'id', 'ips': ips})
        self.assertEqual('name', port.name)
        self.assertEqual('id', port.id)
        self.assertEqual(ips, port.ips)

    def test_construction_named(self):
        ips = ['10', '11']
        port = Port(ips=ips, id='id', name='name')
        self.assertEqual('name', port.name)
        self.assertEqual('id', port.id)
        self.assertEqual(ips, port.ips)


class RouterDomainObjectTests(unittest.TestCase):
    """
    Tests the construction of the snaps.domain.network.Router class
    """

    def test_construction_kwargs(self):
        sec_grp = Router(
            **{'name': 'name', 'id': 'id', 'status': 'hello',
               'tenant_id': '1234', 'admin_state_up': 'yes',
               'external_gateway_info': 'no'})
        self.assertEqual('name', sec_grp.name)
        self.assertEqual('id', sec_grp.id)
        self.assertEqual('hello', sec_grp.status)
        self.assertEqual('1234', sec_grp.tenant_id)
        self.assertEqual('yes', sec_grp.admin_state_up)
        self.assertEqual('no', sec_grp.external_gateway_info)

    def test_construction_named(self):
        sec_grp = Router(
            external_gateway_info='no', admin_state_up='yes', tenant_id='1234',
            status='hello', id='id', name='name')
        self.assertEqual('name', sec_grp.name)
        self.assertEqual('id', sec_grp.id)
        self.assertEqual('hello', sec_grp.status)
        self.assertEqual('1234', sec_grp.tenant_id)
        self.assertEqual('yes', sec_grp.admin_state_up)
        self.assertEqual('no', sec_grp.external_gateway_info)


class InterfaceRouterDomainObjectTests(unittest.TestCase):
    """
    Tests the construction of the snaps.domain.network.InterfaceRouter class
    """

    def test_construction_kwargs(self):
        sec_grp = InterfaceRouter(
            **{'id': 'id', 'subnet_id': 'foo', 'port_id': 'bar'})
        self.assertEqual('id', sec_grp.id)
        self.assertEqual('foo', sec_grp.subnet_id)
        self.assertEqual('bar', sec_grp.port_id)

    def test_construction_named(self):
        sec_grp = InterfaceRouter(port_id='bar', subnet_id='foo', id='id')
        self.assertEqual('id', sec_grp.id)
        self.assertEqual('foo', sec_grp.subnet_id)
        self.assertEqual('bar', sec_grp.port_id)


class SecurityGroupDomainObjectTests(unittest.TestCase):
    """
    Tests the construction of the snaps.domain.network.SecurityGroup class
    """

    def test_construction_proj_id_kwargs(self):
        sec_grp = SecurityGroup(
            **{'name': 'name', 'id': 'id',
               'project_id': 'foo'})
        self.assertEqual('name', sec_grp.name)
        self.assertEqual('id', sec_grp.id)
        self.assertEqual('foo', sec_grp.project_id)

    def test_construction_tenant_id_kwargs(self):
        sec_grp = SecurityGroup(
            **{'name': 'name', 'id': 'id',
               'tenant_id': 'foo'})
        self.assertEqual('name', sec_grp.name)
        self.assertEqual('id', sec_grp.id)
        self.assertEqual('foo', sec_grp.project_id)

    def test_construction_named(self):
        sec_grp = SecurityGroup(tenant_id='foo', id='id', name='name')
        self.assertEqual('name', sec_grp.name)
        self.assertEqual('id', sec_grp.id)
        self.assertEqual('foo', sec_grp.project_id)


class SecurityGroupRuleDomainObjectTests(unittest.TestCase):
    """
    Tests the construction of the snaps.domain.network.SecurityGroupRule class
    """

    def test_construction_kwargs(self):
        sec_grp_rule = SecurityGroupRule(
            **{'id': 'id', 'security_group_id': 'grp_id',
               'description': 'desc', 'direction': 'dir', 'ethertype': 'eType',
               'port_range_min': '10.0.0.100', 'port_range_max': '10.0.0.200',
               'protocol': 'proto', 'remote_group_id': 'group_id',
               'remote_ip_prefix': 'ip_prefix'})
        self.assertEqual('id', sec_grp_rule.id)
        self.assertEqual('grp_id', sec_grp_rule.security_group_id)
        self.assertEqual('desc', sec_grp_rule.description)
        self.assertEqual('dir', sec_grp_rule.direction)
        self.assertEqual('eType', sec_grp_rule.ethertype)
        self.assertEqual('10.0.0.100', sec_grp_rule.port_range_min)
        self.assertEqual('10.0.0.200', sec_grp_rule.port_range_max)
        self.assertEqual('proto', sec_grp_rule.protocol)
        self.assertEqual('group_id', sec_grp_rule.remote_group_id)
        self.assertEqual('ip_prefix', sec_grp_rule.remote_ip_prefix)

    def test_construction_named(self):
        sec_grp_rule = SecurityGroupRule(
            remote_ip_prefix='ip_prefix', remote_group_id='group_id',
            protocol='proto', port_range_min='10.0.0.100',
            port_range_max='10.0.0.200', ethertype='eType',
            direction='dir', description='desc', security_group_id='grp_id',
            id='id')
        self.assertEqual('id', sec_grp_rule.id)
        self.assertEqual('grp_id', sec_grp_rule.security_group_id)
        self.assertEqual('desc', sec_grp_rule.description)
        self.assertEqual('dir', sec_grp_rule.direction)
        self.assertEqual('eType', sec_grp_rule.ethertype)
        self.assertEqual('10.0.0.100', sec_grp_rule.port_range_min)
        self.assertEqual('10.0.0.200', sec_grp_rule.port_range_max)
        self.assertEqual('proto', sec_grp_rule.protocol)
        self.assertEqual('group_id', sec_grp_rule.remote_group_id)
        self.assertEqual('ip_prefix', sec_grp_rule.remote_ip_prefix)