~james-page/charms/trusty/nova-cloud-controller/lp1531102-trunk

« back to all changes in this revision

Viewing changes to tests/basic_deployment.py

  • Committer: james.page at ubuntu
  • Date: 2015-08-10 16:36:50 UTC
  • Revision ID: james.page@ubuntu.com-20150810163650-bpjo4l0dru4txcji
Tags: 15.07
[gnuoy] 15.07 Charm release

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#!/usr/bin/python
2
2
 
3
3
import amulet
 
4
import os
 
5
import yaml
4
6
 
5
7
from charmhelpers.contrib.openstack.amulet.deployment import (
6
8
    OpenStackAmuletDeployment
19
21
class NovaCCBasicDeployment(OpenStackAmuletDeployment):
20
22
    """Amulet tests on a basic nova cloud controller deployment."""
21
23
 
22
 
    def __init__(self, series=None, openstack=None, source=None, stable=True):
 
24
    def __init__(self, series=None, openstack=None, source=None, git=False,
 
25
                 stable=False):
23
26
        """Deploy the entire test environment."""
24
27
        super(NovaCCBasicDeployment, self).__init__(series, openstack, source, stable)
 
28
        self.git = git
25
29
        self._add_services()
26
30
        self._add_relations()
27
31
        self._configure_services()
62
66
 
63
67
    def _configure_services(self):
64
68
        """Configure all of the services."""
 
69
        nova_cc_config = nova_config = {}
 
70
        if self.git:
 
71
            amulet_http_proxy = os.environ.get('AMULET_HTTP_PROXY')
 
72
 
 
73
            reqs_repo = 'git://github.com/openstack/requirements'
 
74
            neutron_repo = 'git://github.com/openstack/neutron'
 
75
            nova_repo = 'git://github.com/openstack/nova'
 
76
            if self._get_openstack_release() == self.trusty_icehouse:
 
77
                reqs_repo = 'git://github.com/coreycb/requirements'
 
78
                neutron_repo = 'git://github.com/coreycb/neutron'
 
79
                nova_repo = 'git://github.com/coreycb/nova'
 
80
 
 
81
            branch = 'stable/' + self._get_openstack_release_string()
 
82
 
 
83
            openstack_origin_git = {
 
84
                'repositories': [
 
85
                    {'name': 'requirements',
 
86
                     'repository': reqs_repo,
 
87
                     'branch': branch},
 
88
                    {'name': 'neutron',
 
89
                     'repository': neutron_repo,
 
90
                     'branch': branch},
 
91
                    {'name': 'nova',
 
92
                     'repository': nova_repo,
 
93
                     'branch': branch},
 
94
                ],
 
95
                'directory': '/mnt/openstack-git',
 
96
                'http_proxy': amulet_http_proxy,
 
97
                'https_proxy': amulet_http_proxy,
 
98
            }
 
99
            nova_cc_config['openstack-origin-git'] = yaml.dump(openstack_origin_git)
 
100
            nova_config['openstack-origin-git'] = yaml.dump(openstack_origin_git)
65
101
        keystone_config = {'admin-password': 'openstack',
66
102
                           'admin-token': 'ubuntutesting'}
67
 
        configs = {'keystone': keystone_config}
 
103
        configs = {'nova-cloud-controller': nova_cc_config,
 
104
                   'keystone': keystone_config, 'nova-compute': nova_config}
68
105
        super(NovaCCBasicDeployment, self)._configure_services(configs)
69
106
 
70
107
    def _initialize_tests(self):
149
186
        if self._get_openstack_release() >= self.precise_folsom:
150
187
            endpoint_vol['id'] = u.not_null
151
188
            endpoint_id['id'] = u.not_null
152
 
        expected = {'s3': [endpoint_vol], 'compute': [endpoint_vol],
153
 
                    'ec2': [endpoint_vol], 'identity': [endpoint_id]}
 
189
        if self._get_openstack_release() >= self.trusty_kilo:
 
190
            expected = {'compute': [endpoint_vol], 'identity': [endpoint_id]}
 
191
        else:
 
192
            expected = {'s3': [endpoint_vol], 'compute': [endpoint_vol],
 
193
                        'ec2': [endpoint_vol], 'identity': [endpoint_id]}
154
194
        actual = self.keystone_demo.service_catalog.get_endpoints()
155
195
 
156
196
        ret = u.validate_svc_catalog_endpoint_data(expected, actual)
176
216
 
177
217
    def test_ec2_api_endpoint(self):
178
218
        """Verify the EC2 api endpoint data."""
 
219
        if self._get_openstack_release() >= self.trusty_kilo:
 
220
            return
 
221
 
179
222
        endpoints = self.keystone.endpoints.list()
180
223
        admin_port = internal_port = public_port = '8773'
181
224
        expected = {'id': u.not_null,
193
236
 
194
237
    def test_s3_api_endpoint(self):
195
238
        """Verify the S3 api endpoint data."""
 
239
        if self._get_openstack_release() >= self.trusty_kilo:
 
240
            return
 
241
 
196
242
        endpoints = self.keystone.endpoints.list()
197
243
        admin_port = internal_port = public_port = '3333'
198
244
        expected = {'id': u.not_null,
246
292
        expected = {
247
293
            'nova_internal_url': u.valid_url,
248
294
            'nova_public_url': u.valid_url,
249
 
            's3_public_url': u.valid_url,
250
 
            's3_service': 's3',
251
 
            'ec2_admin_url': u.valid_url,
252
 
            'ec2_internal_url': u.valid_url,
253
295
            'nova_service': 'nova',
254
 
            's3_region': 'RegionOne',
255
296
            'private-address': u.valid_ip,
256
297
            'nova_region': 'RegionOne',
257
 
            'ec2_public_url': u.valid_url,
258
 
            'ec2_region': 'RegionOne',
259
 
            's3_internal_url': u.valid_url,
260
 
            's3_admin_url': u.valid_url,
261
298
            'nova_admin_url': u.valid_url,
262
 
            'ec2_service': 'ec2'
263
299
        }
 
300
        if self._get_openstack_release() < self.trusty_kilo:
 
301
            expected['s3_admin_url'] = u.valid_url
 
302
            expected['s3_internal_url'] = u.valid_url
 
303
            expected['s3_public_url'] = u.valid_url
 
304
            expected['s3_region'] = 'RegionOne'
 
305
            expected['s3_service'] = 's3'
 
306
            expected['ec2_admin_url'] = u.valid_url
 
307
            expected['ec2_internal_url'] = u.valid_url
 
308
            expected['ec2_public_url'] = u.valid_url
 
309
            expected['ec2_region'] = 'RegionOne'
 
310
            expected['ec2_service'] = 'ec2'
264
311
 
265
312
        ret = u.validate_relation_data(unit, relation, expected)
266
313
        if ret:
286
333
            'service_tenant_id': u.not_null,
287
334
            'service_host': u.valid_ip
288
335
        }
 
336
        if self._get_openstack_release() >= self.trusty_kilo:
 
337
            expected['service_username'] = 'nova'
289
338
 
290
339
        ret = u.validate_relation_data(unit, relation, expected)
291
340
        if ret:
434
483
                                                      endpoint_type='publicURL')
435
484
        keystone_ec2 = "{}/ec2tokens".format(keystone_ep)
436
485
 
437
 
        expected = {'dhcpbridge_flagfile': '/etc/nova/nova.conf',
438
 
                    'dhcpbridge': '/usr/bin/nova-dhcpbridge',
439
 
                    'logdir': '/var/log/nova',
440
 
                    'state_path': '/var/lib/nova',
441
 
                    'lock_path': '/var/lock/nova',
442
 
                    'force_dhcp_release': 'True',
443
 
                    'iscsi_helper': 'tgtadm',
444
 
                    'libvirt_use_virtio_for_bridges': 'True',
445
 
                    'connection_type': 'libvirt',
446
 
                    'root_helper': 'sudo nova-rootwrap /etc/nova/rootwrap.conf',
447
 
                    'verbose': 'False',
448
 
                    'debug': 'False',
449
 
                    'ec2_private_dns_show_ip': 'True',
450
 
                    'api_paste_config': '/etc/nova/api-paste.ini',
451
 
                    'volumes_path': '/var/lib/nova/volumes',
452
 
                    'enabled_apis': 'ec2,osapi_compute,metadata',
453
 
                    'auth_strategy': 'keystone',
454
 
                    'compute_driver': 'libvirt.LibvirtDriver',
455
 
                    'keystone_ec2_url': keystone_ec2,
456
 
                    'rabbit_userid': 'nova',
457
 
                    'rabbit_virtual_host': 'openstack',
458
 
                    'rabbit_password': rabbitmq_relation['password'],
459
 
                    'rabbit_host': rabbitmq_relation['hostname'],
460
 
                    'glance_api_servers': glance_relation['glance-api-server'],
461
 
                    'network_manager': 'nova.network.manager.FlatDHCPManager',
462
 
                    's3_listen_port': '3323',
463
 
                    'osapi_compute_listen_port': '8764',
464
 
                    'ec2_listen_port': '8763'}
465
 
 
466
 
        # This has been moved to [database] for I and above
467
 
        if self._get_openstack_release() < self.precise_icehouse:
468
 
            mysql_relation = self.mysql_sentry.relation('shared-db',
469
 
                                            'nova-cloud-controller:shared-db')
470
 
            db_uri = "mysql://{}:{}@{}/{}".format('nova',
471
 
                                              mysql_relation['nova_password'],
472
 
                                              mysql_relation['db_host'],
473
 
                                              'nova')
474
 
            expected['sql_connection'] = db_uri
475
 
 
476
 
        ret = u.validate_config_data(unit, conf, 'DEFAULT', expected)
477
 
        if ret:
478
 
            message = "nova config error: {}".format(ret)
479
 
            amulet.raise_status(amulet.FAIL, msg=message)
480
 
 
481
 
    def test_nova_database_config(self):
482
 
        """Verify the data in the nova config file's database section."""
483
 
        # NOTE(hopem): this is >= Icehouse only
484
 
        if self._get_openstack_release() < self.precise_icehouse:
485
 
            return
486
 
 
487
 
        unit = self.nova_cc_sentry
488
 
        conf = '/etc/nova/nova.conf'
489
 
        mysql_relation = self.mysql_sentry.relation('shared-db',
490
 
                                              'nova-cloud-controller:shared-db')
491
 
        db_uri = "mysql://{}:{}@{}/{}".format('nova',
492
 
                                              mysql_relation['nova_password'],
493
 
                                              mysql_relation['db_host'],
494
 
                                              'nova')
495
 
 
496
 
        # For >= icehouse we move away from deprecated sql_connection
497
 
        expected = {'connection': db_uri}
498
 
 
499
 
        ret = u.validate_config_data(unit, conf, 'database', expected)
500
 
        if ret:
501
 
            message = "nova config error: {}".format(ret)
502
 
            amulet.raise_status(amulet.FAIL, msg=message)
503
 
 
504
 
    def test_nova_keystone_authtoken_config(self):
505
 
        """Verify the data in the nova config file's keystone_authtoken
506
 
           section. This data only exists since icehouse."""
507
 
        if self._get_openstack_release() < self.precise_icehouse:
508
 
            return
509
 
 
510
 
        unit = self.nova_cc_sentry
511
 
        conf = '/etc/nova/nova.conf'
512
486
        keystone_relation = self.keystone_sentry.relation('identity-service',
513
487
                                       'nova-cloud-controller:identity-service')
514
488
        keystone_uri = "http://{}:{}/".format(keystone_relation['service_host'],
515
489
                                              keystone_relation['service_port'])
516
 
        expected = {'auth_uri': keystone_uri,
517
 
                    'auth_host': keystone_relation['service_host'],
518
 
                    'auth_port': keystone_relation['auth_port'],
519
 
                    'auth_protocol': keystone_relation['auth_protocol'],
 
490
        identity_uri = "{}://{}:{}/".format(keystone_relation['auth_protocol'],
 
491
                                            keystone_relation['service_host'],
 
492
                                            keystone_relation['auth_port'])
 
493
 
 
494
        mysql_relation = self.mysql_sentry.relation('shared-db',
 
495
                                              'nova-cloud-controller:shared-db')
 
496
        db_uri = "mysql://{}:{}@{}/{}".format('nova',
 
497
                                              mysql_relation['nova_password'],
 
498
                                              mysql_relation['db_host'],
 
499
                                              'nova')
 
500
 
 
501
        expected = {
 
502
            'DEFAULT': {
 
503
                'dhcpbridge_flagfile': '/etc/nova/nova.conf',
 
504
                'dhcpbridge': '/usr/bin/nova-dhcpbridge',
 
505
                'logdir': '/var/log/nova',
 
506
                'state_path': '/var/lib/nova',
 
507
                'force_dhcp_release': 'True',
 
508
                'iscsi_helper': 'tgtadm',
 
509
                'libvirt_use_virtio_for_bridges': 'True',
 
510
                'connection_type': 'libvirt',
 
511
                'root_helper': 'sudo nova-rootwrap /etc/nova/rootwrap.conf',
 
512
                'verbose': 'False',
 
513
                'debug': 'False',
 
514
                'ec2_private_dns_show_ip': 'True',
 
515
                'api_paste_config': '/etc/nova/api-paste.ini',
 
516
                'volumes_path': '/var/lib/nova/volumes',
 
517
                'enabled_apis': 'ec2,osapi_compute,metadata',
 
518
                'auth_strategy': 'keystone',
 
519
                'compute_driver': 'libvirt.LibvirtDriver',
 
520
                'keystone_ec2_url': keystone_ec2,
 
521
                'network_manager': 'nova.network.manager.FlatDHCPManager',
 
522
                's3_listen_port': '3323',
 
523
                'osapi_compute_listen_port': '8764',
 
524
                'ec2_listen_port': '8763'
 
525
            }
 
526
        }
 
527
        if self._get_openstack_release() < self.trusty_kilo:
 
528
            d = 'DEFAULT'
 
529
            if self._get_openstack_release() < self.precise_icehouse:
 
530
                expected[d]['sql_connection'] = db_uri
 
531
            else:
 
532
                database = {
 
533
                    'database': {
 
534
                        'connection': db_uri
 
535
                    }
 
536
                }
 
537
                keystone_authtoken = {
 
538
                    'keystone_authtoken': {
 
539
                        'auth_uri': keystone_uri,
 
540
                        'auth_host': keystone_relation['service_host'],
 
541
                        'auth_port': keystone_relation['auth_port'],
 
542
                        'auth_protocol': keystone_relation['auth_protocol'],
 
543
                        'admin_tenant_name': keystone_relation['service_tenant'],
 
544
                        'admin_user': keystone_relation['service_username'],
 
545
                        'admin_password': keystone_relation['service_password'],
 
546
                    }
 
547
                }
 
548
                expected.update(database)
 
549
                expected.update(keystone_authtoken)
 
550
            expected[d]['lock_path'] = '/var/lock/nova'
 
551
            expected[d]['libvirt_use_virtio_for_bridges'] = 'True'
 
552
            expected[d]['compute_driver'] = 'libvirt.LibvirtDriver'
 
553
            expected[d]['rabbit_userid'] = 'nova'
 
554
            expected[d]['rabbit_virtual_host'] = 'openstack'
 
555
            expected[d]['rabbit_password'] = rabbitmq_relation['password']
 
556
            expected[d]['rabbit_host'] = rabbitmq_relation['hostname']
 
557
            expected[d]['glance_api_servers'] = glance_relation['glance-api-server']
 
558
 
 
559
        else:
 
560
            database = {
 
561
                'database': {
 
562
                    'connection': db_uri,
 
563
                    'max_pool_size': '2',
 
564
                }
 
565
            }
 
566
            glance = {
 
567
                'glance': {
 
568
                    'api_servers': glance_relation['glance-api-server'],
 
569
                }
 
570
            }
 
571
            keystone_authtoken = {
 
572
                'keystone_authtoken': {
 
573
                    'identity_uri': identity_uri,
 
574
                    'auth_uri': keystone_uri,
520
575
                    'admin_tenant_name': keystone_relation['service_tenant'],
521
576
                    'admin_user': keystone_relation['service_username'],
522
 
                    'admin_password': keystone_relation['service_password']}
 
577
                    'admin_password': keystone_relation['service_password'],
 
578
                    'signing_dir': '/var/cache/nova',
 
579
                }
 
580
            }
 
581
            osapi_v3 = {
 
582
                'osapi_v3': {
 
583
                    'enabled': 'True',
 
584
                }
 
585
            }
 
586
            conductor = {
 
587
                'conductor': {
 
588
                    'workers': '2',
 
589
                }
 
590
            }
 
591
            oslo_messaging_rabbit = {
 
592
                'oslo_messaging_rabbit': {
 
593
                    'rabbit_userid': 'nova',
 
594
                    'rabbit_virtual_host': 'openstack',
 
595
                    'rabbit_password': rabbitmq_relation['password'],
 
596
                    'rabbit_host': rabbitmq_relation['hostname'],
 
597
                }
 
598
            }
 
599
            oslo_concurrency = {
 
600
                'oslo_concurrency': {
 
601
                    'lock_path': '/var/lock/nova',
 
602
                }
 
603
            }
 
604
            expected.update(database)
 
605
            expected.update(glance)
 
606
            expected.update(keystone_authtoken)
 
607
            expected.update(osapi_v3)
 
608
            expected.update(conductor)
 
609
            expected.update(oslo_messaging_rabbit)
 
610
            expected.update(oslo_concurrency)
523
611
 
524
 
        ret = u.validate_config_data(unit, conf, 'keystone_authtoken', expected)
525
 
        if ret:
526
 
            message = "nova config error: {}".format(ret)
527
 
            amulet.raise_status(amulet.FAIL, msg=message)
 
612
        for section, pairs in expected.iteritems():
 
613
            ret = u.validate_config_data(unit, conf, section, pairs)
 
614
            if ret:
 
615
                message = "nova config error: {}".format(ret)
 
616
                amulet.raise_status(amulet.FAIL, msg=message)
528
617
 
529
618
    def test_image_instance_create(self):
530
619
        """Create an image/instance, verify they exist, and delete them."""