~landscape/charms/trusty/neutron-api-odl-vpp/trunk

« back to all changes in this revision

Viewing changes to unit_tests/test_odl_data.py

  • Committer: Liam Young
  • Date: 2015-06-24 12:44:33 UTC
  • Revision ID: liam.young@canonical.com-20150624124433-7pqnnn8bn5ccvdb8
Fix unit tests

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
from test_utils import CharmTestCase
2
2
from mock import patch
3
 
import vpp_data
 
3
import odl_data
4
4
import charmhelpers
5
5
import charmhelpers.core.services.helpers
6
6
import json
17
17
    return outer
18
18
 
19
19
 
20
 
FULL_AMQP = {
21
 
    'data': {
22
 
        'password': '123',
23
 
        'private-address': '10.0.0.10',
24
 
    },
25
 
    'rids': ['amqp:2'],
26
 
    'runits': ['rabbitmq-server/0'],
27
 
}
28
 
 
29
 
MISSING_DATA_AMQP = {
30
 
    'data': {},
31
 
    'rids': ['amqp:2'],
32
 
    'runits': ['rabbitmq-server/0'],
33
 
}
34
 
 
35
 
FULL_NPAPI = {
36
 
    'data': {
37
 
        'overlay-network-type': 'gre',
38
 
        'network-device-mtu': '1200',
39
 
    },
40
 
    'rids': ['neutron-plugin-api:2'],
41
 
    'runits': ['neutron-api/0'],
42
 
}
43
 
 
44
 
NOMTU_NPAPI = {
45
 
    'data': {
46
 
        'overlay-network-type': 'gre',
47
 
    },
48
 
    'rids': ['neutron-plugin-api:2'],
49
 
    'runits': ['neutron-api/0'],
50
 
}
51
 
 
52
 
MISSING_DATA_NPAPI = {
53
 
    'data': {},
54
 
    'rids': ['neutron-plugin-api:2'],
55
 
    'runits': ['neutron-api/0'],
56
 
}
57
 
 
58
20
FULL_ODLCTRL = {
59
21
    'data': {
60
22
        'private-address': '10.0.0.27',
75
37
}
76
38
 
77
39
 
78
 
class AMQPRelationTest(CharmTestCase):
79
 
 
80
 
    def setUp(self):
81
 
        super(AMQPRelationTest, self).setUp(vpp_data, TO_PATCH)
82
 
        self.config.side_effect = self.test_config.get
83
 
        self.test_config.set('debug', True)
84
 
        self.test_config.set('verbose', True)
85
 
        self.test_config.set('rabbit-user', 'neut')
86
 
        self.test_config.set('rabbit-vhost', 'os')
87
 
 
88
 
    def tearDown(self):
89
 
        super(AMQPRelationTest, self).tearDown()
90
 
 
91
 
    @patch.object(charmhelpers.contrib.openstack.context, 'config')
92
 
    @patch.object(charmhelpers.contrib.openstack.context, 'relation_get')
93
 
    @patch.object(charmhelpers.contrib.openstack.context, 'related_units')
94
 
    @patch.object(charmhelpers.contrib.openstack.context, 'relation_ids')
95
 
    @patch.object(charmhelpers.core.hookenv, 'relation_get')
96
 
    @patch.object(charmhelpers.core.hookenv, 'related_units')
97
 
    @patch.object(charmhelpers.core.hookenv, 'relation_ids')
98
 
    def get_amqprel(self, _hrids, _hrunits, _hrget, _crids, _crunits,
99
 
                    _crget, _cconfig, relinfo=None):
100
 
        _hrids.return_value = relinfo['rids']
101
 
        _crids.return_value = relinfo['rids']
102
 
        _hrunits.return_value = relinfo['runits']
103
 
        _crunits.return_value = relinfo['runits']
104
 
        self.test_relation.set(relinfo['data'])
105
 
        _hrget.side_effect = self.test_relation.get
106
 
        _crget.side_effect = self.test_relation.get
107
 
        _cconfig.side_effect = self.test_config.get
108
 
        amqp_rel = vpp_data.AMQPRelation()
109
 
        amqp_rel.get_data()
110
 
        return amqp_rel
111
 
 
112
 
    def test_get_data(self):
113
 
        amqp_rel = self.get_amqprel(relinfo=FULL_AMQP)
114
 
        self.assertEqual(amqp_rel['rabbitmq_password'], '123')
115
 
        self.assertEqual(amqp_rel['amqp'][0]['password'], '123')
116
 
 
117
 
    def test_provide_data(self):
118
 
        amqp_rel = self.get_amqprel(relinfo=FULL_AMQP)
119
 
        self.assertEqual(amqp_rel.provide_data(), {'username': 'neut',
120
 
                                                   'vhost': 'os'})
121
 
 
122
 
    def test_is_ready_empty_context(self):
123
 
        amqp_rel = self.get_amqprel(relinfo=MISSING_DATA_AMQP)
124
 
        self.assertEqual(amqp_rel.is_ready(), False)
125
 
 
126
 
    def test_is_ready_context(self):
127
 
        amqp_rel = self.get_amqprel(relinfo=FULL_AMQP)
128
 
        self.assertEqual(amqp_rel.is_ready(), True)
129
 
 
130
 
 
131
40
class NeutronApiSDNRelationTest(CharmTestCase):
132
41
 
133
42
    def setUp(self):
134
 
        super(NeutronApiSDNRelationTest, self).setUp(vpp_data, TO_PATCH)
 
43
        super(NeutronApiSDNRelationTest, self).setUp(odl_data, TO_PATCH)
135
44
        self.config.side_effect = self.test_config.get
136
45
 
137
46
    def tearDown(self):
141
50
    @patch.object(charmhelpers.core.hookenv, 'related_units')
142
51
    @patch.object(charmhelpers.core.hookenv, 'relation_ids')
143
52
    def test_provide_data(self, _hrids, _hrunits, _hrget):
144
 
        sdn_relation = vpp_data.NeutronApiSDNRelation()
 
53
        sdn_relation = odl_data.NeutronApiSDNRelation()
145
54
        expect = {
146
55
            'core-plugin': 'neutron.plugins.ml2.plugin.Ml2Plugin',
147
56
            'neutron-plugin': 'odl',
159
68
                         '/etc/neutron/neutron.conf')
160
69
 
161
70
 
162
 
class NeutronPluginAPIRelationTest(CharmTestCase):
163
 
 
164
 
    def setUp(self):
165
 
        super(NeutronPluginAPIRelationTest, self).setUp(vpp_data, TO_PATCH)
166
 
        self.config.side_effect = self.test_config.get
167
 
 
168
 
    def tearDown(self):
169
 
        super(NeutronPluginAPIRelationTest, self).tearDown()
170
 
 
171
 
    @patch.object(charmhelpers.core.hookenv, 'relation_get')
172
 
    @patch.object(charmhelpers.core.hookenv, 'related_units')
173
 
    @patch.object(charmhelpers.core.hookenv, 'relation_ids')
174
 
    def get_apirel(self, _hrids, _hrunits, _hrget, relinfo=None):
175
 
        _hrids.return_value = relinfo['rids']
176
 
        _hrunits.return_value = relinfo['runits']
177
 
        self.test_relation.set(relinfo['data'])
178
 
        _hrget.side_effect = self.test_relation.get
179
 
        api_rel = vpp_data.NeutronPluginAPIRelation()
180
 
        api_rel.get_data()
181
 
        return api_rel
182
 
 
183
 
    def test_get_first_data(self):
184
 
        api_rel = self.get_apirel(relinfo=FULL_NPAPI)
185
 
        expect = {
186
 
            'network-device-mtu': '1200',
187
 
            'overlay-network-type': 'gre'
188
 
        }
189
 
        self.assertEqual(api_rel.get_first_data(), expect)
190
 
 
191
 
    def test_is_ready(self):
192
 
        api_rel = self.get_apirel(relinfo=FULL_NPAPI)
193
 
        self.assertEqual(api_rel.is_ready(), True)
194
 
 
195
 
    def test_is_ready_incomplete(self):
196
 
        api_rel = self.get_apirel(relinfo=MISSING_DATA_NPAPI)
197
 
        self.assertEqual(api_rel.is_ready(), False)
198
 
 
199
 
    def test_get_data(self):
200
 
        api_rel = self.get_apirel(relinfo=FULL_NPAPI)
201
 
        expect = {
202
 
            'veth_mtu': '1200',
203
 
            'network_device_mtu': '1200',
204
 
            'overlay_network_type': 'gre'
205
 
        }
206
 
        for key in expect.keys():
207
 
            self.assertEqual(api_rel[key], expect[key])
208
 
 
209
 
    def test_get_data_nomtu(self):
210
 
        api_rel = self.get_apirel(relinfo=NOMTU_NPAPI)
211
 
        expect = {
212
 
            'overlay_network_type': 'gre'
213
 
        }
214
 
        for key in expect.keys():
215
 
            self.assertEqual(api_rel[key], expect[key])
216
 
 
217
 
 
218
71
class ODLControllerRelationTest(CharmTestCase):
219
72
 
220
73
    def setUp(self):
221
 
        super(ODLControllerRelationTest, self).setUp(vpp_data, TO_PATCH)
 
74
        super(ODLControllerRelationTest, self).setUp(odl_data, TO_PATCH)
222
75
        self.config.side_effect = self.test_config.get
223
76
 
224
77
    def tearDown(self):
232
85
        _hrunits.return_value = relinfo['runits']
233
86
        self.test_relation.set(relinfo['data'])
234
87
        _hrget.side_effect = self.test_relation.get
235
 
        odl_rel = vpp_data.ODLControllerRelation()
 
88
        odl_rel = odl_data.ODLControllerRelation()
236
89
        odl_rel.get_data()
237
90
        return odl_rel
238
91
 
271
124
class ConfigTranslationTest(CharmTestCase):
272
125
 
273
126
    def setUp(self):
274
 
        super(ConfigTranslationTest, self).setUp(vpp_data, TO_PATCH)
 
127
        super(ConfigTranslationTest, self).setUp(odl_data, TO_PATCH)
275
128
        self.config.side_effect = self.test_config.get
276
129
 
277
130
    def tearDown(self):
278
131
        super(ConfigTranslationTest, self).tearDown()
279
132
 
280
133
    def test_config_default(self):
281
 
        ctxt = vpp_data.ConfigTranslation()
 
134
        ctxt = odl_data.ConfigTranslation()
282
135
        self.assertEqual(ctxt, {'use_syslog': False,
283
 
                                'vlan_ranges': 'physnet1:1000:2000'})
 
136
                                'vlan_ranges': 'physnet1:1000:2000',
 
137
                                'overlay_network_type': 'gre'})
284
138
 
285
139
        self.test_config.set('use-syslog', True)
286
 
        ctxt = vpp_data.ConfigTranslation()
 
140
        ctxt = odl_data.ConfigTranslation()
287
141
        self.assertEqual(ctxt, {'use_syslog': True,
288
 
                                'vlan_ranges': 'physnet1:1000:2000'})
 
142
                                'vlan_ranges': 'physnet1:1000:2000',
 
143
                                'overlay_network_type': 'gre'})
289
144
 
290
145
        self.test_config.set('vlan-ranges', 'physnet1:1000:3000')
291
 
        ctxt = vpp_data.ConfigTranslation()
292
 
        self.assertEqual(ctxt, {'use_syslog': True,
293
 
                                'vlan_ranges': 'physnet1:1000:3000'})
 
146
        ctxt = odl_data.ConfigTranslation()
 
147
        self.assertEqual(ctxt, {'use_syslog': True,
 
148
                                'vlan_ranges': 'physnet1:1000:3000',
 
149
                                'overlay_network_type': 'gre'})
 
150
 
 
151
        self.test_config.set('overlay-network-type', 'vxlan')
 
152
        ctxt = odl_data.ConfigTranslation()
 
153
        self.assertEqual(ctxt, {'use_syslog': True,
 
154
                                'vlan_ranges': 'physnet1:1000:3000',
 
155
                                'overlay_network_type': 'vxlan'})