~midokura/charms/trusty/midonet-api/trunk

« back to all changes in this revision

Viewing changes to tests/basic_deployment.py

  • Committer: Antoni Segura Puimedon
  • Date: 2015-10-19 03:50:11 UTC
  • mfrom: (13.1.1 trunk)
  • Revision ID: toni@midokura.com-20151019035011-ogd06dnxmovkhn8j
Update amulet tests for latests deployment conf from Lucas

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python3
 
2
# vim: tabstop=4 shiftwidth=4 softtabstop=4 filetype=python
 
3
#
 
4
# Copyright (c) 2015 Midokura Europe SARL, All Rights Reserved.
 
5
# All Rights Reserved
 
6
#
 
7
# Licensed under the Apache License, Version 2.0 (the "License"); you may
 
8
# not use this file except in compliance with the License. You may obtain
 
9
# a copy of the License at
 
10
#
 
11
# http://www.apache.org/licenses/LICENSE-2.0
 
12
#
 
13
# Unless required by applicable law or agreed to in writing, software
 
14
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 
15
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 
16
# License for the specific language governing permissions and limitations
 
17
# under the License.
 
18
import amulet
 
19
 
 
20
from charmhelpers.contrib.openstack.amulet.utils import (
 
21
    OpenStackAmuletUtils,
 
22
    DEBUG,  # flake8: noqa
 
23
    ERROR
 
24
)
 
25
 
 
26
# Use DEBUG to turn on debug logging
 
27
u = OpenStackAmuletUtils(DEBUG)
 
28
 
 
29
SETUP_TIMEOUT = 9600
 
30
 
 
31
 
 
32
class MidonetBasicDeployment():
 
33
    def __init__(self, ubuntu_series, openstack=None, midonet_release=None):
 
34
        self.os_release = openstack
 
35
        self.series = ubuntu_series
 
36
        self.midonet_release = midonet_release
 
37
        self.d = amulet.Deployment(series=self.series)
 
38
        self._add_services()
 
39
        self._add_relations()
 
40
        self._configure_services()
 
41
        self._deploy()
 
42
        self._initialize_tests()
 
43
 
 
44
    def _add_services(self):
 
45
        self.d.add('mysql', charm='cs:trusty/mysql', units=1,
 
46
                   series=self.series)
 
47
        self.d.add('rabbitmq-server', charm='cs:trusty/rabbitmq-server',
 
48
                   units=1, series=self.series)
 
49
        self.d.add('cassandra', charm='cassandra', units=1,
 
50
                   branch='lp:charms/cassandra', series=self.series)
 
51
        self.d.add('keystone', charm='keystone', units=1, series=self.series,
 
52
                    branch='lp:~celebdor/charms/trusty/keystone/trunk')
 
53
        self.d.add('nova-compute', charm='nova-compute', units=1,
 
54
                   branch='lp:~celebdor/charms/trusty/nova-compute/trunk',
 
55
                   series=self.series)
 
56
        self.d.add('neutron-api', charm='neutron-api', units=1,
 
57
                   branch='lp:~celebdor/charms/trusty/neutron-api/trunk',
 
58
                   series=self.series)
 
59
        self.d.add('nova-cloud-controller', charm='nova-cloud-controller',
 
60
               branch='lp:~celebdor/charms/trusty/nova-cloud-controller/trunk',
 
61
               units=1, series=self.series)
 
62
        self.d.add('zookeeper', charm='cs:trusty/zookeeper', units=1,
 
63
                   series=self.series)
 
64
        self.d.add('midonet-api', charm='midonet-api', units=1,
 
65
                   branch='lp:~celebdor/charms/trusty/midonet-api/trunk',
 
66
                   series=self.series)
 
67
        self.d.add('midonet-agent', charm='midonet-agent', units=1,
 
68
                   branch='lp:~celebdor/charms/trusty/midonet-agent/trunk',
 
69
                   series=self.series)
 
70
        self.d.add('neutron-agents-midonet', charm='neutron-agents-midonet',
 
71
              branch='lp:~celebdor/charms/trusty/neutron-agents-midonet/trunk',
 
72
              series='trusty')
 
73
 
 
74
    def _add_relations(self):
 
75
        self.d.relate('mysql:shared-db', 'keystone:shared-db')
 
76
        self.d.relate('mysql:shared-db', 'nova-cloud-controller:shared-db')
 
77
        self.d.relate('rabbitmq-server:amqp', 'nova-compute:amqp')
 
78
        self.d.relate('rabbitmq-server:amqp', 'nova-cloud-controller:amqp')
 
79
        self.d.relate('rabbitmq-server:amqp', 'neutron-api:amqp')
 
80
        self.d.relate('nova-cloud-controller:identity-service',
 
81
                      'keystone:identity-service')
 
82
 
 
83
        self.d.relate('neutron-api:identity-service',
 
84
                      'keystone:identity-service')
 
85
        self.d.relate('nova-compute:cloud-compute',
 
86
                      'nova-cloud-controller:cloud-compute')
 
87
        self.d.relate('neutron-api:neutron-api',
 
88
                      'nova-cloud-controller:neutron-api')
 
89
 
 
90
        self.d.relate('keystone:identity-service', 'midonet-api:keystone')
 
91
        self.d.relate('zookeeper:zookeeper', 'midonet-api:zookeeper')
 
92
        self.d.relate('midonet-agent:host', 'midonet-api:host')
 
93
        self.d.relate('neutron-api:midonet', 'midonet-api:midonet-api')
 
94
 
 
95
        self.d.relate('neutron-agents-midonet:neutron_agents',
 
96
                      'nova-cloud-controller:quantum-network-service')
 
97
 
 
98
        self.d.relate('neutron-agents-midonet:neutron-plugin-api',
 
99
                      'neutron-api:neutron-plugin-api')
 
100
 
 
101
        self.d.relate('midonet-agent:neutron-plugin',
 
102
                      'nova-compute:neutron-plugin')
 
103
 
 
104
        self.d.relate('midonet-agent:host', 'neutron-api:midonet-host')
 
105
        self.d.relate('midonet-agent:cassandra', 'cassandra:database')
 
106
        self.d.relate('midonet-agent:zookeeper', 'zookeeper:zookeeper')
 
107
 
 
108
    def _configure_services(self):
 
109
        self.d.configure('keystone', {
 
110
                         'enable-pki': 'false',
 
111
                         'openstack-origin': self.os_release})
 
112
 
 
113
        self.d.configure('cassandra', {
 
114
            'allow-single-node': True,
 
115
            'cluster-name': 'midonet',
 
116
            'apt-repo-key': '7E41C00F85BFC1706C4FFFB3350200F2B999A372',
 
117
            'apt-repo-spec':
 
118
            'deb http://debian.datastax.com/community 2.0 main',
 
119
            'extra_packages': 'openjdk-7-jre-headless dsc20'})
 
120
 
 
121
        self.d.configure('mysql', {'max-connections': 2000})
 
122
 
 
123
        self.d.configure('nova-compute', {
 
124
                         'openstack-origin': self.os_release,
 
125
                         'virt-type': 'qemu',
 
126
                         'flat-interface': 'eth0',
 
127
                         'manage-neutron-plugin-legacy-mode': 'false'})
 
128
 
 
129
        self.d.configure('nova-cloud-controller', {
 
130
                         'openstack-origin': self.os_release,
 
131
                         'network-manager': 'Neutron',
 
132
                         'shared_secret': 'secret'})
 
133
 
 
134
        self.d.configure('neutron-api', {
 
135
                         'neutron-plugin': 'midonet',
 
136
                         'neutron-security-groups': 'True',
 
137
                         'neutron-external-network': 'Public_Network',
 
138
                         'l2-population': 'False',
 
139
                         'openstack-origin': self.os_release,
 
140
                         'midonet-release': self.midonet_release})
 
141
 
 
142
        self.d.configure('midonet-api',
 
143
                         {'midonet-release': self.midonet_release})
 
144
 
 
145
        self.d.configure('neutron-agents-midonet',
 
146
                         {'shared_secret': 'secret'})
 
147
 
 
148
        self.d.configure('midonet-agent',
 
149
                         {'midonet-release': self.midonet_release})
 
150
 
 
151
    def _deploy(self):
 
152
        try:
 
153
            self.d.setup(timeout=SETUP_TIMEOUT)
 
154
            self.d.sentry.wait(timeout=SETUP_TIMEOUT)
 
155
        except amulet.helpers.TimeoutError:
 
156
            amulet.raise_status(amulet.SKIP,
 
157
                                msg="Environment wasn't stood up in time")
 
158
 
 
159
    def _initialize_tests(self):
 
160
        self.zookeeper_sentry = self.d.sentry.unit['zookeeper/0']
 
161
        self.keystone_sentry = self.d.sentry.unit['keystone/0']
 
162
        self.cassandra_sentry = self.d.sentry.unit['cassandra/0']
 
163
        self.nova_compute_sentry = self.d.sentry.unit['nova-compute/0']
 
164
        self.mn_api_sentry = self.d.sentry.unit['midonet-api/0']
 
165
        self.mn_agent_sentry = self.d.sentry.unit['midonet-agent/0']
 
166
        self.agents_mn_sentry = self.d.sentry.unit['neutron-agents-midonet/0']
 
167
 
 
168
        self.keystone_api_relation = self.keystone_sentry.relation(
 
169
             'identity-service', 'midonet-api:keystone')
 
170
        self.zookeeper_api_relation = self.zookeeper_sentry.relation(
 
171
             'zookeeper', 'midonet-api:zookeeper')
 
172
        self.zk_host_relation = self.zookeeper_sentry.relation(
 
173
                                'zookeeper', 'midonet-agent:zookeeper')
 
174
        self.cs_host_relation = self.cassandra_sentry.relation(
 
175
            'database', 'midonet-agent:cassandra')
 
176
        self.api_host_relation = self.mn_api_sentry.relation(
 
177
            'host', 'midonet-agent:host')
 
178
 
 
179
    def run_tests(self):
 
180
        for test in dir(self):
 
181
            if test.startswith('test_'):
 
182
                getattr(self, test)()
 
183
 
 
184
    def test_mn_api(self):
 
185
        u.log.debug('Checking if the repo key has been correctly fetched...')
 
186
        apt_key_out, apt_key_exit = self.mn_agent_sentry.run(
 
187
                                    'apt-key list | grep Midokura')
 
188
        if 'Midokura' not in apt_key_out:
 
189
            message = ("error, Midokura repository key is not installed")
 
190
            amulet.raise_status(amulet.FAIL, msg=message)
 
191
 
 
192
        u.log.debug('Checking if midonet-api package has been installed...')
 
193
        dpkg_api_out, dpkg_exit = self.mn_api_sentry.run(
 
194
                                  'dpkg -l | grep midonet-api')
 
195
        if 'midonet-api' not in dpkg_api_out:
 
196
            message = ("error: midonet-api package is not installed")
 
197
            amulet.raise_status(amulet.FAIL, msg=message)
 
198
 
 
199
        u.log.debug('Checking if midonetclient package has been installed...')
 
200
        dpkg_client_out, dpkg_exit = self.mn_api_sentry.run(
 
201
                                     'dpkg -l | grep midonetclient')
 
202
        if 'python-midonetclient' not in dpkg_client_out:
 
203
            message = ("error: python-midonetclient package is not installed")
 
204
            amulet.raise_status(amulet.FAIL, msg=message)
 
205
 
 
206
        u.log.debug('Checking if tomcat7 is installed and running...')
 
207
        tomcat7_out, tomcat7_exit = self.mn_api_sentry.run(
 
208
                                    'service tomcat7 status')
 
209
        if tomcat7_exit == 1:
 
210
            message = ("midonet-api setup error, tomcat7 is not installed")
 
211
            amulet.raise_status(amulet.FAIL, msg=message)
 
212
        if tomcat7_exit == 0:
 
213
            if 'running' not in tomcat7_out:
 
214
                message = ("midonet-api setup error, tomcat7 is not running")
 
215
                amulet.raise_status(amulet.FAIL, msg=message)
 
216
 
 
217
        u.log.debug('Checking if midonetrc exists...')
 
218
        mn_rc_out, mn_rc_exit = self.mn_api_sentry.run(
 
219
                  '[ -f /root/.midonetrc ] && echo \"True\" || echo \"False\"')
 
220
        if 'True' not in mn_rc_out:
 
221
            message = ("error: .midonetrc not found")
 
222
            amulet.raise_status(amulet.FAIL, msg=message)
 
223
 
 
224
        u.log.debug('Checking midonet-cli...')
 
225
        cli_out, mn_exit = self.mn_api_sentry.run(
 
226
                           'midonet-cli -e create bridge name test')
 
227
        if mn_exit != 0:
 
228
            message = ("midonet-cli error: %s" % cli_out)
 
229
            amulet.raise_status(amulet.FAIL, msg=message)
 
230
 
 
231
        u.log.debug('Checking if the bridge has been successfully created...')
 
232
        cli_out, mn_exit = self.mn_api_sentry.run('midonet-cli -e bridge list')
 
233
        if 'test' not in cli_out:
 
234
            message = ("midonet-cli error: %s" % cli_out)
 
235
            amulet.raise_status(amulet.FAIL, msg=message)