~hopem/charms/trusty/quantum-gateway/fix-bug-1379324

« back to all changes in this revision

Viewing changes to tests/basic_deployment.py

  • Committer: james.page at ubuntu
  • Date: 2014-07-28 11:32:22 UTC
  • mfrom: (53.1.3 quantum-gateway)
  • Revision ID: james.page@ubuntu.com-20140728113222-pi9nzrje388v69i0
[coreycb,r=james-page] Add amulet tests.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/python
 
2
 
 
3
import amulet
 
4
try:
 
5
    from quantumclient.v2_0 import client as neutronclient
 
6
except ImportError:
 
7
    from neutronclient.v2_0 import client as neutronclient
 
8
 
 
9
from charmhelpers.contrib.openstack.amulet.deployment import (
 
10
    OpenStackAmuletDeployment
 
11
)
 
12
 
 
13
from charmhelpers.contrib.openstack.amulet.utils import (
 
14
    OpenStackAmuletUtils,
 
15
    DEBUG, # flake8: noqa
 
16
    ERROR
 
17
)
 
18
 
 
19
# Use DEBUG to turn on debug logging
 
20
u = OpenStackAmuletUtils(ERROR)
 
21
 
 
22
 
 
23
class QuantumGatewayBasicDeployment(OpenStackAmuletDeployment):
 
24
    """Amulet tests on a basic quantum-gateway deployment."""
 
25
 
 
26
    def __init__(self, series, openstack=None, source=None):
 
27
        """Deploy the entire test environment."""
 
28
        super(QuantumGatewayBasicDeployment, self).__init__(series, openstack,
 
29
                                                            source)
 
30
        self._add_services()
 
31
        self._add_relations()
 
32
        self._configure_services()
 
33
        self._deploy()
 
34
        self._initialize_tests()
 
35
 
 
36
    def _add_services(self):
 
37
        """Add the service that we're testing, including the number of units,
 
38
           where quantum-gateway is local, and the other charms are from
 
39
           the charm store."""
 
40
        this_service = ('quantum-gateway', 1)
 
41
        other_services = [('mysql', 1),
 
42
                          ('rabbitmq-server', 1), ('keystone', 1),
 
43
                          ('nova-cloud-controller', 1)]
 
44
        super(QuantumGatewayBasicDeployment, self)._add_services(this_service,
 
45
                                                                 other_services)
 
46
 
 
47
    def _add_relations(self):
 
48
        """Add all of the relations for the services."""
 
49
        relations = {
 
50
          'keystone:shared-db': 'mysql:shared-db',
 
51
          'quantum-gateway:shared-db': 'mysql:shared-db',
 
52
          'quantum-gateway:amqp': 'rabbitmq-server:amqp',
 
53
          'nova-cloud-controller:quantum-network-service': \
 
54
                                      'quantum-gateway:quantum-network-service',
 
55
          'nova-cloud-controller:shared-db': 'mysql:shared-db',
 
56
          'nova-cloud-controller:identity-service': 'keystone:identity-service',
 
57
          'nova-cloud-controller:amqp': 'rabbitmq-server:amqp'
 
58
        }
 
59
        super(QuantumGatewayBasicDeployment, self)._add_relations(relations)
 
60
 
 
61
    def _configure_services(self):
 
62
        """Configure all of the services."""
 
63
        keystone_config = {'admin-password': 'openstack',
 
64
                           'admin-token': 'ubuntutesting'}
 
65
        nova_cc_config = {'network-manager': 'Quantum',
 
66
                          'quantum-security-groups': 'yes'}
 
67
        configs = {'keystone': keystone_config,
 
68
                   'nova-cloud-controller': nova_cc_config}
 
69
        super(QuantumGatewayBasicDeployment, self)._configure_services(configs)
 
70
 
 
71
    def _initialize_tests(self):
 
72
        """Perform final initialization before tests get run."""
 
73
        # Access the sentries for inspecting service units
 
74
        self.mysql_sentry = self.d.sentry.unit['mysql/0']
 
75
        self.keystone_sentry = self.d.sentry.unit['keystone/0']
 
76
        self.rabbitmq_sentry = self.d.sentry.unit['rabbitmq-server/0']
 
77
        self.nova_cc_sentry = self.d.sentry.unit['nova-cloud-controller/0']
 
78
        self.quantum_gateway_sentry = self.d.sentry.unit['quantum-gateway/0']
 
79
 
 
80
        # Authenticate admin with keystone
 
81
        self.keystone = u.authenticate_keystone_admin(self.keystone_sentry,
 
82
                                                      user='admin',
 
83
                                                      password='openstack',
 
84
                                                      tenant='admin')
 
85
 
 
86
 
 
87
        # Authenticate admin with neutron
 
88
        ep = self.keystone.service_catalog.url_for(service_type='identity',
 
89
                                                   endpoint_type='publicURL')
 
90
        self.neutron = neutronclient.Client(auth_url=ep,
 
91
                                            username='admin',
 
92
                                            password='openstack',
 
93
                                            tenant_name='admin',
 
94
                                            region_name='RegionOne')
 
95
 
 
96
    def test_services(self):
 
97
        """Verify the expected services are running on the corresponding
 
98
           service units."""
 
99
        if self._get_openstack_release() >= self.precise_havana:
 
100
            neutron_services = ['status neutron-dhcp-agent',
 
101
                                'status neutron-lbaas-agent',
 
102
                                'status neutron-metadata-agent',
 
103
                                'status neutron-plugin-openvswitch-agent']
 
104
            if self._get_openstack_release() == self.precise_havana:
 
105
                neutron_services.append('status neutron-l3-agent')
 
106
            else:
 
107
                neutron_services.append('status neutron-vpn-agent')
 
108
                neutron_services.append('status neutron-metering-agent')
 
109
                neutron_services.append('status neutron-ovs-cleanup')
 
110
        else:
 
111
            neutron_services = ['status quantum-dhcp-agent',
 
112
                                'status quantum-l3-agent',
 
113
                                'status quantum-metadata-agent',
 
114
                                'status quantum-plugin-openvswitch-agent']
 
115
 
 
116
        nova_cc_services = ['status nova-api-ec2',
 
117
                            'status nova-api-os-compute',
 
118
                            'status nova-objectstore',
 
119
                            'status nova-cert',
 
120
                            'status nova-scheduler']
 
121
        if self._get_openstack_release() >= self.precise_grizzly:
 
122
            nova_cc_services.append('status nova-conductor')
 
123
 
 
124
        commands = {
 
125
            self.mysql_sentry: ['status mysql'],
 
126
            self.keystone_sentry: ['status keystone'],
 
127
            self.nova_cc_sentry: nova_cc_services,
 
128
            self.quantum_gateway_sentry: neutron_services
 
129
        }
 
130
 
 
131
        ret = u.validate_services(commands)
 
132
        if ret:
 
133
            amulet.raise_status(amulet.FAIL, msg=ret)
 
134
 
 
135
    def test_quantum_gateway_shared_db_relation(self):
 
136
        """Verify the quantum-gateway to mysql shared-db relation data"""
 
137
        unit = self.quantum_gateway_sentry
 
138
        relation = ['shared-db', 'mysql:shared-db']
 
139
        expected = {
 
140
            'private-address': u.valid_ip,
 
141
            'database': 'nova',
 
142
            'username': 'nova',
 
143
            'hostname': u.valid_ip
 
144
        }
 
145
 
 
146
        ret = u.validate_relation_data(unit, relation, expected)
 
147
        if ret:
 
148
            message = u.relation_error('quantum-gateway shared-db', ret)
 
149
            amulet.raise_status(amulet.FAIL, msg=message)
 
150
 
 
151
    def test_mysql_shared_db_relation(self):
 
152
        """Verify the mysql to quantum-gateway shared-db relation data"""
 
153
        unit = self.mysql_sentry
 
154
        relation = ['shared-db', 'quantum-gateway:shared-db']
 
155
        expected = {
 
156
            'private-address': u.valid_ip,
 
157
            'password': u.not_null,
 
158
            'db_host': u.valid_ip
 
159
        }
 
160
 
 
161
        ret = u.validate_relation_data(unit, relation, expected)
 
162
        if ret:
 
163
            message = u.relation_error('mysql shared-db', ret)
 
164
            amulet.raise_status(amulet.FAIL, msg=message)
 
165
 
 
166
    def test_quantum_gateway_amqp_relation(self):
 
167
        """Verify the quantum-gateway to rabbitmq-server amqp relation data"""
 
168
        unit = self.quantum_gateway_sentry
 
169
        relation = ['amqp', 'rabbitmq-server:amqp']
 
170
        expected = {
 
171
            'username': 'neutron',
 
172
            'private-address': u.valid_ip,
 
173
            'vhost': 'openstack'
 
174
        }
 
175
 
 
176
        ret = u.validate_relation_data(unit, relation, expected)
 
177
        if ret:
 
178
            message = u.relation_error('quantum-gateway amqp', ret)
 
179
            amulet.raise_status(amulet.FAIL, msg=message)
 
180
 
 
181
    def test_rabbitmq_amqp_relation(self):
 
182
        """Verify the rabbitmq-server to quantum-gateway amqp relation data"""
 
183
        unit = self.rabbitmq_sentry
 
184
        relation = ['amqp', 'quantum-gateway:amqp']
 
185
        expected = {
 
186
            'private-address': u.valid_ip,
 
187
            'password': u.not_null,
 
188
            'hostname': u.valid_ip
 
189
        }
 
190
 
 
191
        ret = u.validate_relation_data(unit, relation, expected)
 
192
        if ret:
 
193
            message = u.relation_error('rabbitmq amqp', ret)
 
194
            amulet.raise_status(amulet.FAIL, msg=message)
 
195
 
 
196
    def test_quantum_gateway_network_service_relation(self):
 
197
        """Verify the quantum-gateway to nova-cc quantum-network-service
 
198
           relation data"""
 
199
        unit = self.quantum_gateway_sentry
 
200
        relation = ['quantum-network-service',
 
201
                    'nova-cloud-controller:quantum-network-service']
 
202
        expected = {
 
203
            'private-address': u.valid_ip
 
204
        }
 
205
 
 
206
        ret = u.validate_relation_data(unit, relation, expected)
 
207
        if ret:
 
208
            message = u.relation_error('quantum-gateway network-service', ret)
 
209
            amulet.raise_status(amulet.FAIL, msg=message)
 
210
 
 
211
    def test_nova_cc_network_service_relation(self):
 
212
        """Verify the nova-cc to quantum-gateway quantum-network-service
 
213
           relation data"""
 
214
        unit = self.nova_cc_sentry
 
215
        relation = ['quantum-network-service',
 
216
                    'quantum-gateway:quantum-network-service']
 
217
        expected = {
 
218
            'service_protocol': 'http',
 
219
            'service_tenant': 'services',
 
220
            'quantum_url': u.valid_url,
 
221
            'quantum_port': '9696',
 
222
            'service_port': '5000',
 
223
            'region': 'RegionOne',
 
224
            'service_password': u.not_null,
 
225
            'quantum_host': u.valid_ip,
 
226
            'auth_port': '35357',
 
227
            'auth_protocol': 'http',
 
228
            'private-address': u.valid_ip,
 
229
            'keystone_host': u.valid_ip,
 
230
            'quantum_plugin': 'ovs',
 
231
            'auth_host': u.valid_ip,
 
232
            'service_username': 'quantum_s3_ec2_nova',
 
233
            'service_tenant_name': 'services'
 
234
        }
 
235
 
 
236
        ret = u.validate_relation_data(unit, relation, expected)
 
237
        if ret:
 
238
            message = u.relation_error('nova-cc network-service', ret)
 
239
            amulet.raise_status(amulet.FAIL, msg=message)
 
240
 
 
241
    def test_restart_on_config_change(self):
 
242
        """Verify that the specified services are restarted when the config
 
243
           is changed."""
 
244
        if self._get_openstack_release() >= self.precise_havana:
 
245
            conf = '/etc/neutron/neutron.conf'
 
246
            services = ['neutron-dhcp-agent', 'neutron-openvswitch-agent',
 
247
                        'neutron-metering-agent', 'neutron-lbaas-agent',
 
248
                        'neutron-metadata-agent']
 
249
            if self._get_openstack_release() == self.precise_havana:
 
250
                services.append('neutron-l3-agent')
 
251
            else:
 
252
                services.append('neutron-vpn-agent')
 
253
        else:
 
254
            conf = '/etc/quantum/quantum.conf'
 
255
            services = ['quantum-dhcp-agent', 'quantum-openvswitch-agent',
 
256
                        'quantum-metadata-agent', 'quantum-l3-agent']
 
257
 
 
258
        self.d.configure('quantum-gateway', {'debug': 'True'})
 
259
 
 
260
        time = 20
 
261
        for s in services:
 
262
            if not u.service_restarted(self.quantum_gateway_sentry, s, conf,
 
263
                                       pgrep_full=True, sleep_time=time):
 
264
                msg = "service {} didn't restart after config change".format(s)
 
265
                amulet.raise_status(amulet.FAIL, msg=msg)
 
266
            time = 0
 
267
 
 
268
        self.d.configure('quantum-gateway', {'debug': 'False'})
 
269
 
 
270
    def test_neutron_config(self):
 
271
        """Verify the data in the neutron config file."""
 
272
        unit = self.quantum_gateway_sentry
 
273
        rabbitmq_relation = self.rabbitmq_sentry.relation('amqp',
 
274
                                                         'quantum-gateway:amqp')
 
275
 
 
276
        if self._get_openstack_release() >= self.precise_havana:
 
277
            conf = '/etc/neutron/neutron.conf'
 
278
            expected = {
 
279
                'DEFAULT': {
 
280
                    'verbose': 'False',
 
281
                    'debug': 'False',
 
282
                    'lock_path': '/var/lock/neutron',
 
283
                    'rabbit_userid': 'neutron',
 
284
                    'rabbit_virtual_host': 'openstack',
 
285
                    'rabbit_password': rabbitmq_relation['password'],
 
286
                    'rabbit_host': rabbitmq_relation['hostname'],
 
287
                    'control_exchange': 'neutron',
 
288
                    'notification_driver': 'neutron.openstack.common.notifier.'
 
289
                                           'list_notifier',
 
290
                    'list_notifier_drivers': 'neutron.openstack.common.'
 
291
                                             'notifier.rabbit_notifier'
 
292
                },
 
293
                'agent': {
 
294
                    'root_helper': 'sudo /usr/bin/neutron-rootwrap '
 
295
                                   '/etc/neutron/rootwrap.conf'
 
296
                }
 
297
            }
 
298
        else:
 
299
            conf = '/etc/quantum/quantum.conf'
 
300
            expected = {
 
301
                'DEFAULT': {
 
302
                    'verbose': 'False',
 
303
                    'debug': 'False',
 
304
                    'lock_path': '/var/lock/quantum',
 
305
                    'rabbit_userid': 'neutron',
 
306
                    'rabbit_virtual_host': 'openstack',
 
307
                    'rabbit_password': rabbitmq_relation['password'],
 
308
                    'rabbit_host': rabbitmq_relation['hostname'],
 
309
                    'control_exchange': 'quantum',
 
310
                    'notification_driver': 'quantum.openstack.common.notifier.'
 
311
                                           'list_notifier',
 
312
                    'list_notifier_drivers': 'quantum.openstack.common.'
 
313
                                             'notifier.rabbit_notifier'
 
314
                },
 
315
                'AGENT': {
 
316
                    'root_helper': 'sudo /usr/bin/quantum-rootwrap '
 
317
                                   '/etc/quantum/rootwrap.conf'
 
318
                }
 
319
            }
 
320
 
 
321
        if self._get_openstack_release() >= self.precise_icehouse:
 
322
            expected['DEFAULT']['core_plugin'] = \
 
323
                                          'neutron.plugins.ml2.plugin.Ml2Plugin'
 
324
        elif self._get_openstack_release() >= self.precise_havana:
 
325
            expected['DEFAULT']['core_plugin'] = \
 
326
             'neutron.plugins.openvswitch.ovs_neutron_plugin.OVSNeutronPluginV2'
 
327
        else:
 
328
            expected['DEFAULT']['core_plugin'] = \
 
329
             'quantum.plugins.openvswitch.ovs_quantum_plugin.OVSQuantumPluginV2'
 
330
 
 
331
        for section, pairs in expected.iteritems():
 
332
            ret = u.validate_config_data(unit, conf, section, pairs)
 
333
            if ret:
 
334
                message = "neutron config error: {}".format(ret)
 
335
                amulet.raise_status(amulet.FAIL, msg=message)
 
336
 
 
337
    def test_ml2_config(self):
 
338
        """Verify the data in the ml2 config file. This is only available
 
339
           since icehouse."""
 
340
        if self._get_openstack_release() < self.precise_icehouse:
 
341
            return
 
342
 
 
343
        unit = self.quantum_gateway_sentry
 
344
        conf = '/etc/neutron/plugins/ml2/ml2_conf.ini'
 
345
        quantum_gateway_relation = unit.relation('shared-db', 'mysql:shared-db')
 
346
        expected = {
 
347
            'ml2': {
 
348
                'type_drivers': 'gre,vxlan',
 
349
                'tenant_network_types': 'gre,vxlan',
 
350
                'mechanism_drivers': 'openvswitch'
 
351
            },
 
352
            'ml2_type_gre': {
 
353
                'tunnel_id_ranges': '1:1000'
 
354
            },
 
355
            'ml2_type_vxlan': {
 
356
                'vni_ranges': '1001:2000'
 
357
            },
 
358
            'ovs': {
 
359
                'enable_tunneling': 'True',
 
360
                'local_ip': quantum_gateway_relation['private-address']
 
361
            },
 
362
            'agent': {
 
363
                'tunnel_types': 'gre'
 
364
            },
 
365
            'securitygroup': {
 
366
                'firewall_driver': 'neutron.agent.linux.iptables_firewall.'
 
367
                                   'OVSHybridIptablesFirewallDriver'
 
368
            }
 
369
        }
 
370
 
 
371
        for section, pairs in expected.iteritems():
 
372
            ret = u.validate_config_data(unit, conf, section, pairs)
 
373
            if ret:
 
374
                message = "ml2 config error: {}".format(ret)
 
375
                amulet.raise_status(amulet.FAIL, msg=message)
 
376
 
 
377
    def test_api_paste_config(self):
 
378
        """Verify the data in the api paste config file."""
 
379
        unit = self.quantum_gateway_sentry
 
380
        if self._get_openstack_release() >= self.precise_havana:
 
381
            conf = '/etc/neutron/api-paste.ini'
 
382
            expected = {
 
383
                'composite:neutron': {
 
384
                    'use': 'egg:Paste#urlmap',
 
385
                    '/': 'neutronversions',
 
386
                    '/v2.0': 'neutronapi_v2_0'
 
387
                },
 
388
                'filter:keystonecontext': {
 
389
                    'paste.filter_factory': 'neutron.auth:'
 
390
                                            'NeutronKeystoneContext.factory'
 
391
                },
 
392
                'filter:authtoken': {
 
393
                    'paste.filter_factory': 'keystoneclient.middleware.'
 
394
                                            'auth_token:filter_factory'
 
395
                },
 
396
                'filter:extensions': {
 
397
                    'paste.filter_factory': 'neutron.api.extensions:'
 
398
                                            'plugin_aware_extension_middleware_'
 
399
                                            'factory'
 
400
                },
 
401
                'app:neutronversions': {
 
402
                    'paste.app_factory': 'neutron.api.versions:Versions.factory'
 
403
                },
 
404
                'app:neutronapiapp_v2_0': {
 
405
                    'paste.app_factory': 'neutron.api.v2.router:APIRouter.'
 
406
                                         'factory'
 
407
                }
 
408
            }
 
409
            if self._get_openstack_release() == self.precise_havana:
 
410
                expected_additional = {
 
411
                    'composite:neutronapi_v2_0': {
 
412
                        'use': 'call:neutron.auth:pipeline_factory',
 
413
                        'noauth': 'extensions neutronapiapp_v2_0',
 
414
                        'keystone': 'authtoken keystonecontext extensions '
 
415
                                    'neutronapiapp_v2_0'
 
416
                    }
 
417
                }
 
418
            else:
 
419
                expected_additional = {
 
420
                    'composite:neutronapi_v2_0': {
 
421
                        'use': 'call:neutron.auth:pipeline_factory',
 
422
                        'noauth': 'request_id catch_errors extensions '
 
423
                                  'neutronapiapp_v2_0',
 
424
                        'keystone': 'request_id catch_errors authtoken '
 
425
                                    'keystonecontext extensions '
 
426
                                    'neutronapiapp_v2_0'
 
427
                    }
 
428
                }
 
429
            expected = dict(expected.items() + expected_additional.items())
 
430
        else:
 
431
            conf = '/etc/quantum/api-paste.ini'
 
432
            expected = {
 
433
                'composite:quantum': {
 
434
                    'use': 'egg:Paste#urlmap',
 
435
                    '/': 'quantumversions',
 
436
                    '/v2.0': 'quantumapi_v2_0'
 
437
                },
 
438
                'composite:quantumapi_v2_0': {
 
439
                    'use': 'call:quantum.auth:pipeline_factory',
 
440
                    'noauth': 'extensions quantumapiapp_v2_0',
 
441
                    'keystone': 'authtoken keystonecontext extensions '
 
442
                                'quantumapiapp_v2_0',
 
443
                },
 
444
                'filter:keystonecontext': {
 
445
                    'paste.filter_factory': 'quantum.auth:'
 
446
                                            'QuantumKeystoneContext.factory'
 
447
                },
 
448
                'filter:authtoken': {
 
449
                    'paste.filter_factory': 'keystoneclient.middleware.'
 
450
                                            'auth_token:filter_factory'
 
451
                },
 
452
                'filter:extensions': {
 
453
                    'paste.filter_factory': 'quantum.api.extensions:'
 
454
                                            'plugin_aware_extension_middleware_'
 
455
                                            'factory'
 
456
                },
 
457
                'app:quantumversions': {
 
458
                    'paste.app_factory': 'quantum.api.versions:Versions.factory'
 
459
                },
 
460
                'app:quantumapiapp_v2_0': {
 
461
                    'paste.app_factory': 'quantum.api.v2.router:APIRouter.'
 
462
                                         'factory'
 
463
                }
 
464
            }
 
465
 
 
466
        for section, pairs in expected.iteritems():
 
467
            ret = u.validate_config_data(unit, conf, section, pairs)
 
468
            if ret:
 
469
                message = "api paste config error: {}".format(ret)
 
470
                amulet.raise_status(amulet.FAIL, msg=message)
 
471
 
 
472
    def test_dhcp_agent_config(self):
 
473
        """Verify the data in the dhcp agent config file."""
 
474
        unit = self.quantum_gateway_sentry
 
475
        if self._get_openstack_release() >= self.precise_havana:
 
476
            conf = '/etc/neutron/dhcp_agent.ini'
 
477
            expected = {
 
478
                'state_path': '/var/lib/neutron',
 
479
                'interface_driver': 'neutron.agent.linux.interface.'
 
480
                                    'OVSInterfaceDriver',
 
481
                'dhcp_driver': 'neutron.agent.linux.dhcp.Dnsmasq',
 
482
                'root_helper': 'sudo /usr/bin/neutron-rootwrap '
 
483
                               '/etc/neutron/rootwrap.conf',
 
484
                'ovs_use_veth': 'True'
 
485
            }
 
486
        else:
 
487
            conf = '/etc/quantum/dhcp_agent.ini'
 
488
            expected = {
 
489
                'state_path': '/var/lib/quantum',
 
490
                'interface_driver': 'quantum.agent.linux.interface.'
 
491
                                    'OVSInterfaceDriver',
 
492
                'dhcp_driver': 'quantum.agent.linux.dhcp.Dnsmasq',
 
493
                'root_helper': 'sudo /usr/bin/quantum-rootwrap '
 
494
                               '/etc/quantum/rootwrap.conf'
 
495
            }
 
496
 
 
497
        ret = u.validate_config_data(unit, conf, 'DEFAULT', expected)
 
498
        if ret:
 
499
            message = "dhcp agent config error: {}".format(ret)
 
500
            amulet.raise_status(amulet.FAIL, msg=message)
 
501
 
 
502
    def test_fwaas_driver_config(self):
 
503
        """Verify the data in the fwaas driver config file.  This is only
 
504
           available since havana."""
 
505
        if self._get_openstack_release() < self.precise_havana:
 
506
            return
 
507
 
 
508
        unit = self.quantum_gateway_sentry
 
509
        conf = '/etc/neutron/fwaas_driver.ini'
 
510
        expected = {
 
511
            'driver': 'neutron.services.firewall.drivers.linux.'
 
512
                      'iptables_fwaas.IptablesFwaasDriver',
 
513
            'enabled': 'True'
 
514
        }
 
515
 
 
516
        ret = u.validate_config_data(unit, conf, 'fwaas', expected)
 
517
        if ret:
 
518
            message = "fwaas driver config error: {}".format(ret)
 
519
            amulet.raise_status(amulet.FAIL, msg=message)
 
520
 
 
521
    def test_l3_agent_config(self):
 
522
        """Verify the data in the l3 agent config file."""
 
523
        unit = self.quantum_gateway_sentry
 
524
        nova_cc_relation = self.nova_cc_sentry.relation(\
 
525
                                      'quantum-network-service',
 
526
                                      'quantum-gateway:quantum-network-service')
 
527
        ep = self.keystone.service_catalog.url_for(service_type='identity',
 
528
                                                   endpoint_type='publicURL')
 
529
 
 
530
        if self._get_openstack_release() >= self.precise_havana:
 
531
            conf = '/etc/neutron/l3_agent.ini'
 
532
            expected = {
 
533
                'interface_driver': 'neutron.agent.linux.interface.'
 
534
                                    'OVSInterfaceDriver',
 
535
                'auth_url': ep,
 
536
                'auth_region': 'RegionOne',
 
537
                'admin_tenant_name': 'services',
 
538
                'admin_user': 'quantum_s3_ec2_nova',
 
539
                'admin_password': nova_cc_relation['service_password'],
 
540
                'root_helper': 'sudo /usr/bin/neutron-rootwrap '
 
541
                               '/etc/neutron/rootwrap.conf',
 
542
                'ovs_use_veth': 'True',
 
543
                'handle_internal_only_routers': 'True'
 
544
            }
 
545
        else:
 
546
            conf = '/etc/quantum/l3_agent.ini'
 
547
            expected = {
 
548
                'interface_driver': 'quantum.agent.linux.interface.'
 
549
                                    'OVSInterfaceDriver',
 
550
                'auth_url': ep,
 
551
                'auth_region': 'RegionOne',
 
552
                'admin_tenant_name': 'services',
 
553
                'admin_user': 'quantum_s3_ec2_nova',
 
554
                'admin_password': nova_cc_relation['service_password'],
 
555
                'root_helper': 'sudo /usr/bin/quantum-rootwrap '
 
556
                               '/etc/quantum/rootwrap.conf'
 
557
            }
 
558
 
 
559
        ret = u.validate_config_data(unit, conf, 'DEFAULT', expected)
 
560
        if ret:
 
561
            message = "l3 agent config error: {}".format(ret)
 
562
            amulet.raise_status(amulet.FAIL, msg=message)
 
563
 
 
564
    def test_lbaas_agent_config(self):
 
565
        """Verify the data in the lbaas agent config file. This is only
 
566
           available since havana."""
 
567
        if self._get_openstack_release() < self.precise_havana:
 
568
            return
 
569
 
 
570
        unit = self.quantum_gateway_sentry
 
571
        conf = '/etc/neutron/lbaas_agent.ini'
 
572
        expected = {
 
573
            'DEFAULT': {
 
574
                'periodic_interval': '10',
 
575
                'interface_driver': 'neutron.agent.linux.interface.'
 
576
                                    'OVSInterfaceDriver',
 
577
                'ovs_use_veth': 'False',
 
578
                'device_driver': 'neutron.services.loadbalancer.drivers.'
 
579
                                 'haproxy.namespace_driver.HaproxyNSDriver'
 
580
            },
 
581
            'haproxy': {
 
582
                'loadbalancer_state_path': '$state_path/lbaas',
 
583
                'user_group': 'nogroup'
 
584
            }
 
585
        }
 
586
 
 
587
        for section, pairs in expected.iteritems():
 
588
            ret = u.validate_config_data(unit, conf, section, pairs)
 
589
            if ret:
 
590
                message = "lbaas agent config error: {}".format(ret)
 
591
                amulet.raise_status(amulet.FAIL, msg=message)
 
592
 
 
593
    def test_metadata_agent_config(self):
 
594
        """Verify the data in the metadata agent config file."""
 
595
        unit = self.quantum_gateway_sentry
 
596
        ep = self.keystone.service_catalog.url_for(service_type='identity',
 
597
                                                   endpoint_type='publicURL')
 
598
        quantum_gateway_relation = unit.relation('shared-db', 'mysql:shared-db')
 
599
        nova_cc_relation = self.nova_cc_sentry.relation(\
 
600
                                      'quantum-network-service',
 
601
                                      'quantum-gateway:quantum-network-service')
 
602
 
 
603
        if self._get_openstack_release() >= self.precise_havana:
 
604
            conf = '/etc/neutron/metadata_agent.ini'
 
605
            expected = {
 
606
                'auth_url': ep,
 
607
                'auth_region': 'RegionOne',
 
608
                'admin_tenant_name': 'services',
 
609
                'admin_user': 'quantum_s3_ec2_nova',
 
610
                'admin_password': nova_cc_relation['service_password'],
 
611
                'root_helper': 'sudo neutron-rootwrap '
 
612
                                 '/etc/neutron/rootwrap.conf',
 
613
                'state_path': '/var/lib/neutron',
 
614
                'nova_metadata_ip': quantum_gateway_relation['private-address'],
 
615
                'nova_metadata_port': '8775'
 
616
            }
 
617
        else:
 
618
            conf = '/etc/quantum/metadata_agent.ini'
 
619
            expected = {
 
620
                'auth_url': ep,
 
621
                'auth_region': 'RegionOne',
 
622
                'admin_tenant_name': 'services',
 
623
                'admin_user': 'quantum_s3_ec2_nova',
 
624
                'admin_password': nova_cc_relation['service_password'],
 
625
                'root_helper': 'sudo quantum-rootwrap '
 
626
                               '/etc/quantum/rootwrap.conf',
 
627
                'state_path': '/var/lib/quantum',
 
628
                'nova_metadata_ip': quantum_gateway_relation['private-address'],
 
629
                'nova_metadata_port': '8775'
 
630
            }
 
631
 
 
632
        ret = u.validate_config_data(unit, conf, 'DEFAULT', expected)
 
633
        if ret:
 
634
            message = "metadata agent config error: {}".format(ret)
 
635
            amulet.raise_status(amulet.FAIL, msg=message)
 
636
 
 
637
    def test_metering_agent_config(self):
 
638
        """Verify the data in the metering agent config file.  This is only
 
639
           available since havana."""
 
640
        if self._get_openstack_release() < self.precise_havana:
 
641
            return
 
642
 
 
643
        unit = self.quantum_gateway_sentry
 
644
        conf = '/etc/neutron/metering_agent.ini'
 
645
        expected = {
 
646
            'driver': 'neutron.services.metering.drivers.iptables.'
 
647
                      'iptables_driver.IptablesMeteringDriver',
 
648
            'measure_interval': '30',
 
649
            'report_interval': '300',
 
650
            'interface_driver': 'neutron.agent.linux.interface.'
 
651
                                'OVSInterfaceDriver',
 
652
            'use_namespaces': 'True'
 
653
        }
 
654
 
 
655
        ret = u.validate_config_data(unit, conf, 'DEFAULT', expected)
 
656
        if ret:
 
657
            message = "metering agent config error: {}".format(ret)
 
658
 
 
659
    def test_nova_config(self):
 
660
        """Verify the data in the nova config file."""
 
661
        unit = self.quantum_gateway_sentry
 
662
        conf = '/etc/nova/nova.conf'
 
663
        mysql_relation = self.mysql_sentry.relation('shared-db',
 
664
                                                    'quantum-gateway:shared-db')
 
665
        db_uri = "mysql://{}:{}@{}/{}".format('nova',
 
666
                                              mysql_relation['password'],
 
667
                                              mysql_relation['db_host'],
 
668
                                              'nova')
 
669
        rabbitmq_relation = self.rabbitmq_sentry.relation('amqp',
 
670
                                                         'quantum-gateway:amqp')
 
671
        nova_cc_relation = self.nova_cc_sentry.relation(\
 
672
                                      'quantum-network-service',
 
673
                                      'quantum-gateway:quantum-network-service')
 
674
        ep = self.keystone.service_catalog.url_for(service_type='identity',
 
675
                                                   endpoint_type='publicURL')
 
676
 
 
677
        if self._get_openstack_release() >= self.precise_havana:
 
678
            expected = {
 
679
                'logdir': '/var/log/nova',
 
680
                'state_path': '/var/lib/nova',
 
681
                'lock_path': '/var/lock/nova',
 
682
                'root_helper': 'sudo nova-rootwrap /etc/nova/rootwrap.conf',
 
683
                'verbose': 'False',
 
684
                'use_syslog': 'False',
 
685
                'api_paste_config': '/etc/nova/api-paste.ini',
 
686
                'enabled_apis': 'metadata',
 
687
                'multi_host': 'True',
 
688
                'sql_connection': db_uri,
 
689
                'service_neutron_metadata_proxy': 'True',
 
690
                'rabbit_userid': 'neutron',
 
691
                'rabbit_virtual_host': 'openstack',
 
692
                'rabbit_password': rabbitmq_relation['password'],
 
693
                'rabbit_host': rabbitmq_relation['hostname'],
 
694
                'network_api_class': 'nova.network.neutronv2.api.API',
 
695
                'neutron_auth_strategy': 'keystone',
 
696
                'neutron_url': nova_cc_relation['quantum_url'],
 
697
                'neutron_admin_tenant_name': 'services',
 
698
                'neutron_admin_username': 'quantum_s3_ec2_nova',
 
699
                'neutron_admin_password': nova_cc_relation['service_password'],
 
700
                'neutron_admin_auth_url': ep
 
701
 
 
702
            }
 
703
        else:
 
704
            expected = {
 
705
                'logdir': '/var/log/nova',
 
706
                'state_path': '/var/lib/nova',
 
707
                'lock_path': '/var/lock/nova',
 
708
                'root_helper': 'sudo nova-rootwrap /etc/nova/rootwrap.conf',
 
709
                'verbose': 'True',
 
710
                'api_paste_config': '/etc/nova/api-paste.ini',
 
711
                'enabled_apis': 'metadata',
 
712
                'multi_host': 'True',
 
713
                'sql_connection':  db_uri,
 
714
                'service_quantum_metadata_proxy': 'True',
 
715
                'rabbit_userid': 'neutron',
 
716
                'rabbit_virtual_host': 'openstack',
 
717
                'rabbit_password': rabbitmq_relation['password'],
 
718
                'rabbit_host': rabbitmq_relation['hostname'],
 
719
                'network_api_class': 'nova.network.quantumv2.api.API',
 
720
                'quantum_auth_strategy': 'keystone',
 
721
                'quantum_url': nova_cc_relation['quantum_url'],
 
722
                'quantum_admin_tenant_name': 'services',
 
723
                'quantum_admin_username': 'quantum_s3_ec2_nova',
 
724
                'quantum_admin_password': nova_cc_relation['service_password'],
 
725
                'quantum_admin_auth_url': ep
 
726
            }
 
727
 
 
728
        ret = u.validate_config_data(unit, conf, 'DEFAULT', expected)
 
729
        if ret:
 
730
            message = "nova config error: {}".format(ret)
 
731
            amulet.raise_status(amulet.FAIL, msg=message)
 
732
 
 
733
    def test_ovs_neutron_plugin_config(self):
 
734
        """Verify the data in the ovs neutron plugin config file. The ovs
 
735
           plugin is not used by default since icehouse."""
 
736
        if self._get_openstack_release() >= self.precise_icehouse:
 
737
            return
 
738
 
 
739
        unit = self.quantum_gateway_sentry
 
740
        quantum_gateway_relation = unit.relation('shared-db', 'mysql:shared-db')
 
741
 
 
742
        if self._get_openstack_release() >= self.precise_havana:
 
743
            conf = '/etc/neutron/plugins/openvswitch/ovs_neutron_plugin.ini'
 
744
            expected = {
 
745
                'ovs': {
 
746
                    'local_ip': quantum_gateway_relation['private-address'],
 
747
                    'tenant_network_type': 'gre',
 
748
                    'enable_tunneling': 'True',
 
749
                    'tunnel_id_ranges': '1:1000'
 
750
                }
 
751
            }
 
752
            if self._get_openstack_release() > self.precise_havana:
 
753
                expected_additional = {
 
754
                    'agent': {
 
755
                        'polling_interval': '10',
 
756
                        'root_helper': 'sudo /usr/bin/neutron-rootwrap '
 
757
                        '/etc/neutron/rootwrap.conf'
 
758
                    }
 
759
                }
 
760
                expected = dict(expected.items() + expected_additional.items())
 
761
        else:
 
762
            conf = '/etc/quantum/plugins/openvswitch/ovs_quantum_plugin.ini'
 
763
            expected = {
 
764
                'OVS': {
 
765
                    'local_ip': quantum_gateway_relation['private-address'],
 
766
                    'tenant_network_type': 'gre',
 
767
                    'enable_tunneling': 'True',
 
768
                    'tunnel_id_ranges': '1:1000'
 
769
                    },
 
770
                'AGENT': {
 
771
                    'polling_interval': '10',
 
772
                    'root_helper': 'sudo /usr/bin/quantum-rootwrap '
 
773
                                   '/etc/quantum/rootwrap.conf'
 
774
                    }
 
775
            }
 
776
 
 
777
        for section, pairs in expected.iteritems():
 
778
            ret = u.validate_config_data(unit, conf, section, pairs)
 
779
            if ret:
 
780
                message = "ovs neutron plugin config error: {}".format(ret)
 
781
                amulet.raise_status(amulet.FAIL, msg=message)
 
782
 
 
783
    def test_vpn_agent_config(self):
 
784
        """Verify the data in the vpn agent config file.  This isn't available
 
785
           prior to havana."""
 
786
        if self._get_openstack_release() < self.precise_havana:
 
787
            return
 
788
 
 
789
        unit = self.quantum_gateway_sentry
 
790
        conf = '/etc/neutron/vpn_agent.ini'
 
791
        expected = {
 
792
            'vpnagent': {
 
793
                'vpn_device_driver': 'neutron.services.vpn.device_drivers.'
 
794
                                     'ipsec.OpenSwanDriver'
 
795
            },
 
796
            'ipsec': {
 
797
                'ipsec_status_check_interval': '60'
 
798
            }
 
799
        }
 
800
 
 
801
        for section, pairs in expected.iteritems():
 
802
            ret = u.validate_config_data(unit, conf, section, pairs)
 
803
            if ret:
 
804
                message = "vpn agent config error: {}".format(ret)
 
805
                amulet.raise_status(amulet.FAIL, msg=message)
 
806
 
 
807
    def test_create_network(self):
 
808
        """Create a network, verify that it exists, and then delete it."""
 
809
        self.neutron.format = 'json'
 
810
        net_name = 'ext_net'
 
811
 
 
812
        #Verify that the network doesn't exist
 
813
        networks = self.neutron.list_networks(name=net_name)
 
814
        net_count = len(networks['networks'])
 
815
        if net_count != 0:
 
816
            msg = "Expected zero networks, found {}".format(net_count)
 
817
            amulet.raise_status(amulet.FAIL, msg=msg)
 
818
 
 
819
        # Create a network and verify that it exists
 
820
        network = {'name': net_name}
 
821
        self.neutron.create_network({'network':network})
 
822
 
 
823
        networks = self.neutron.list_networks(name=net_name)
 
824
        net_len = len(networks['networks'])
 
825
        if net_len != 1:
 
826
            msg = "Expected 1 network, found {}".format(net_len)
 
827
            amulet.raise_status(amulet.FAIL, msg=msg)
 
828
 
 
829
        network = networks['networks'][0]
 
830
        if network['name'] != net_name:
 
831
            amulet.raise_status(amulet.FAIL, msg="network ext_net not found")
 
832
 
 
833
        #Cleanup
 
834
        self.neutron.delete_network(network['id'])