~openstack-charmers-archive/charms/trusty/neutron-gateway/trunk

« back to all changes in this revision

Viewing changes to hooks/charmhelpers/contrib/openstack/amulet/deployment.py

  • Committer: James Page
  • Date: 2015-10-22 13:23:58 UTC
  • Revision ID: james.page@ubuntu.com-20151022132358-qin1nvlnqn4aezaz
Tags: 15.10
15.10 Charm release

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
# You should have received a copy of the GNU Lesser General Public License
15
15
# along with charm-helpers.  If not, see <http://www.gnu.org/licenses/>.
16
16
 
 
17
import re
17
18
import six
18
19
from collections import OrderedDict
19
20
from charmhelpers.contrib.amulet.deployment import (
44
45
           Determine if the local branch being tested is derived from its
45
46
           stable or next (dev) branch, and based on this, use the corresonding
46
47
           stable or next branches for the other_services."""
47
 
        base_charms = ['mysql', 'mongodb']
 
48
 
 
49
        # Charms outside the lp:~openstack-charmers namespace
 
50
        base_charms = ['mysql', 'mongodb', 'nrpe']
 
51
 
 
52
        # Force these charms to current series even when using an older series.
 
53
        # ie. Use trusty/nrpe even when series is precise, as the P charm
 
54
        # does not possess the necessary external master config and hooks.
 
55
        force_series_current = ['nrpe']
48
56
 
49
57
        if self.series in ['precise', 'trusty']:
50
58
            base_series = self.series
51
59
        else:
52
60
            base_series = self.current_next
53
61
 
54
 
        if self.stable:
55
 
            for svc in other_services:
 
62
        for svc in other_services:
 
63
            if svc['name'] in force_series_current:
 
64
                base_series = self.current_next
 
65
            # If a location has been explicitly set, use it
 
66
            if svc.get('location'):
 
67
                continue
 
68
            if self.stable:
56
69
                temp = 'lp:charms/{}/{}'
57
70
                svc['location'] = temp.format(base_series,
58
71
                                              svc['name'])
59
 
        else:
60
 
            for svc in other_services:
 
72
            else:
61
73
                if svc['name'] in base_charms:
62
74
                    temp = 'lp:charms/{}/{}'
63
75
                    svc['location'] = temp.format(base_series,
66
78
                    temp = 'lp:~openstack-charmers/charms/{}/{}/next'
67
79
                    svc['location'] = temp.format(self.current_next,
68
80
                                                  svc['name'])
 
81
 
69
82
        return other_services
70
83
 
71
84
    def _add_services(self, this_service, other_services):
77
90
 
78
91
        services = other_services
79
92
        services.append(this_service)
 
93
 
 
94
        # Charms which should use the source config option
80
95
        use_source = ['mysql', 'mongodb', 'rabbitmq-server', 'ceph',
81
96
                      'ceph-osd', 'ceph-radosgw']
82
 
        # Most OpenStack subordinate charms do not expose an origin option
83
 
        # as that is controlled by the principle.
84
 
        ignore = ['cinder-ceph', 'hacluster', 'neutron-openvswitch']
 
97
 
 
98
        # Charms which can not use openstack-origin, ie. many subordinates
 
99
        no_origin = ['cinder-ceph', 'hacluster', 'neutron-openvswitch', 'nrpe']
85
100
 
86
101
        if self.openstack:
87
102
            for svc in services:
88
 
                if svc['name'] not in use_source + ignore:
 
103
                if svc['name'] not in use_source + no_origin:
89
104
                    config = {'openstack-origin': self.openstack}
90
105
                    self.d.configure(svc['name'], config)
91
106
 
92
107
        if self.source:
93
108
            for svc in services:
94
 
                if svc['name'] in use_source and svc['name'] not in ignore:
 
109
                if svc['name'] in use_source and svc['name'] not in no_origin:
95
110
                    config = {'source': self.source}
96
111
                    self.d.configure(svc['name'], config)
97
112
 
100
115
        for service, config in six.iteritems(configs):
101
116
            self.d.configure(service, config)
102
117
 
 
118
    def _auto_wait_for_status(self, message=None, exclude_services=None,
 
119
                              timeout=1800):
 
120
        """Wait for all units to have a specific extended status, except
 
121
        for any defined as excluded.  Unless specified via message, any
 
122
        status containing any case of 'ready' will be considered a match.
 
123
 
 
124
        Examples of message usage:
 
125
 
 
126
          Wait for all unit status to CONTAIN any case of 'ready' or 'ok':
 
127
              message = re.compile('.*ready.*|.*ok.*', re.IGNORECASE)
 
128
 
 
129
          Wait for all units to reach this status (exact match):
 
130
              message = 'Unit is ready'
 
131
 
 
132
          Wait for all units to reach any one of these (exact match):
 
133
              message = re.compile('Unit is ready|OK|Ready')
 
134
 
 
135
          Wait for at least one unit to reach this status (exact match):
 
136
              message = {'ready'}
 
137
 
 
138
        See Amulet's sentry.wait_for_messages() for message usage detail.
 
139
        https://github.com/juju/amulet/blob/master/amulet/sentry.py
 
140
 
 
141
        :param message: Expected status match
 
142
        :param exclude_services: List of juju service names to ignore
 
143
        :param timeout: Maximum time in seconds to wait for status match
 
144
        :returns: None.  Raises if timeout is hit.
 
145
        """
 
146
 
 
147
        if not message:
 
148
            message = re.compile('.*ready.*', re.IGNORECASE)
 
149
 
 
150
        if not exclude_services:
 
151
            exclude_services = []
 
152
 
 
153
        services = list(set(self.d.services.keys()) - set(exclude_services))
 
154
        service_messages = {service: message for service in services}
 
155
        self.d.sentry.wait_for_messages(service_messages, timeout=timeout)
 
156
 
103
157
    def _get_openstack_release(self):
104
158
        """Get openstack release.
105
159