~niedbalski/charms/trusty/rabbitmq-server/fix-1537893

« back to all changes in this revision

Viewing changes to hooks/charmhelpers/contrib/openstack/utils.py

  • Committer: James Page
  • Date: 2016-01-12 05:53:12 UTC
  • mfrom: (126.1.1 rabbitmq-server)
  • Revision ID: james.page@ubuntu.com-20160112055312-m856r7yl4pi0ev0i
Resync helpers

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
 
27
27
import six
28
28
import traceback
 
29
import uuid
29
30
import yaml
30
31
 
31
32
from charmhelpers.contrib.network import ip
41
42
    log as juju_log,
42
43
    charm_dir,
43
44
    INFO,
 
45
    related_units,
44
46
    relation_ids,
45
47
    relation_set,
46
48
    status_set,
84
86
    ('utopic', 'juno'),
85
87
    ('vivid', 'kilo'),
86
88
    ('wily', 'liberty'),
 
89
    ('xenial', 'mitaka'),
87
90
])
88
91
 
89
92
 
97
100
    ('2014.2', 'juno'),
98
101
    ('2015.1', 'kilo'),
99
102
    ('2015.2', 'liberty'),
 
103
    ('2016.1', 'mitaka'),
100
104
])
101
105
 
102
106
# The ugly duckling
127
131
# >= Liberty version->codename mapping
128
132
PACKAGE_CODENAMES = {
129
133
    'nova-common': OrderedDict([
130
 
        ('12.0.0', 'liberty'),
 
134
        ('12.0', 'liberty'),
 
135
        ('13.0', 'mitaka'),
131
136
    ]),
132
137
    'neutron-common': OrderedDict([
133
 
        ('7.0.0', 'liberty'),
 
138
        ('7.0', 'liberty'),
 
139
        ('8.0', 'mitaka'),
134
140
    ]),
135
141
    'cinder-common': OrderedDict([
136
 
        ('7.0.0', 'liberty'),
 
142
        ('7.0', 'liberty'),
 
143
        ('8.0', 'mitaka'),
137
144
    ]),
138
145
    'keystone': OrderedDict([
139
 
        ('8.0.0', 'liberty'),
 
146
        ('8.0', 'liberty'),
 
147
        ('9.0', 'mitaka'),
140
148
    ]),
141
149
    'horizon-common': OrderedDict([
142
 
        ('8.0.0', 'liberty'),
 
150
        ('8.0', 'liberty'),
 
151
        ('9.0', 'mitaka'),
143
152
    ]),
144
153
    'ceilometer-common': OrderedDict([
145
 
        ('5.0.0', 'liberty'),
 
154
        ('5.0', 'liberty'),
 
155
        ('6.0', 'mitaka'),
146
156
    ]),
147
157
    'heat-common': OrderedDict([
148
 
        ('5.0.0', 'liberty'),
 
158
        ('5.0', 'liberty'),
 
159
        ('6.0', 'mitaka'),
149
160
    ]),
150
161
    'glance-common': OrderedDict([
151
 
        ('11.0.0', 'liberty'),
 
162
        ('11.0', 'liberty'),
 
163
        ('12.0', 'mitaka'),
152
164
    ]),
153
165
    'openstack-dashboard': OrderedDict([
154
 
        ('8.0.0', 'liberty'),
 
166
        ('8.0', 'liberty'),
 
167
        ('9.0', 'mitaka'),
155
168
    ]),
156
169
}
157
170
 
238
251
        error_out(e)
239
252
 
240
253
    vers = apt.upstream_version(pkg.current_ver.ver_str)
241
 
    match = re.match('^(\d+)\.(\d+)\.(\d+)', vers)
 
254
    if 'swift' in pkg.name:
 
255
        # Fully x.y.z match for swift versions
 
256
        match = re.match('^(\d+)\.(\d+)\.(\d+)', vers)
 
257
    else:
 
258
        # x.y match only for 20XX.X
 
259
        # and ignore patch level for other packages
 
260
        match = re.match('^(\d+)\.(\d+)', vers)
 
261
 
242
262
    if match:
243
263
        vers = match.group(0)
244
264
 
250
270
        # < Liberty co-ordinated project versions
251
271
        try:
252
272
            if 'swift' in pkg.name:
253
 
                swift_vers = vers[:5]
254
 
                if swift_vers not in SWIFT_CODENAMES:
255
 
                    # Deal with 1.10.0 upward
256
 
                    swift_vers = vers[:6]
257
 
                return SWIFT_CODENAMES[swift_vers]
 
273
                return SWIFT_CODENAMES[vers]
258
274
            else:
259
 
                vers = vers[:6]
260
275
                return OPENSTACK_CODENAMES[vers]
261
276
        except KeyError:
262
277
            if not fatal:
375
390
            'liberty': 'trusty-updates/liberty',
376
391
            'liberty/updates': 'trusty-updates/liberty',
377
392
            'liberty/proposed': 'trusty-proposed/liberty',
 
393
            'mitaka': 'trusty-updates/mitaka',
 
394
            'mitaka/updates': 'trusty-updates/mitaka',
 
395
            'mitaka/proposed': 'trusty-proposed/mitaka',
378
396
        }
379
397
 
380
398
        try:
575
593
    return yaml.load(projects_yaml)
576
594
 
577
595
 
578
 
def git_clone_and_install(projects_yaml, core_project, depth=1):
 
596
def git_clone_and_install(projects_yaml, core_project):
579
597
    """
580
598
    Clone/install all specified OpenStack repositories.
581
599
 
625
643
    for p in projects['repositories']:
626
644
        repo = p['repository']
627
645
        branch = p['branch']
 
646
        depth = '1'
 
647
        if 'depth' in p.keys():
 
648
            depth = p['depth']
628
649
        if p['name'] == 'requirements':
629
650
            repo_dir = _git_clone_and_install_single(repo, branch, depth,
630
651
                                                     parent_dir, http_proxy,
669
690
    """
670
691
    Clone and install a single git repository.
671
692
    """
672
 
    dest_dir = os.path.join(parent_dir, os.path.basename(repo))
673
 
 
674
693
    if not os.path.exists(parent_dir):
675
694
        juju_log('Directory already exists at {}. '
676
695
                 'No need to create directory.'.format(parent_dir))
677
696
        os.mkdir(parent_dir)
678
697
 
679
 
    if not os.path.exists(dest_dir):
680
 
        juju_log('Cloning git repo: {}, branch: {}'.format(repo, branch))
681
 
        repo_dir = install_remote(repo, dest=parent_dir, branch=branch,
682
 
                                  depth=depth)
683
 
    else:
684
 
        repo_dir = dest_dir
 
698
    juju_log('Cloning git repo: {}, branch: {}'.format(repo, branch))
 
699
    repo_dir = install_remote(repo, dest=parent_dir, branch=branch, depth=depth)
685
700
 
686
701
    venv = os.path.join(parent_dir, 'venv')
687
702
 
859
874
        if charm_state != 'active' and charm_state != 'unknown':
860
875
            state = workload_state_compare(state, charm_state)
861
876
            if message:
862
 
                message = "{} {}".format(message, charm_message)
 
877
                charm_message = charm_message.replace("Incomplete relations: ",
 
878
                                                      "")
 
879
                message = "{}, {}".format(message, charm_message)
863
880
            else:
864
881
                message = charm_message
865
882
 
976
993
            action_set({'outcome': 'no upgrade available.'})
977
994
 
978
995
    return ret
 
996
 
 
997
 
 
998
def remote_restart(rel_name, remote_service=None):
 
999
    trigger = {
 
1000
        'restart-trigger': str(uuid.uuid4()),
 
1001
    }
 
1002
    if remote_service:
 
1003
        trigger['remote-service'] = remote_service
 
1004
    for rid in relation_ids(rel_name):
 
1005
        # This subordinate can be related to two seperate services using
 
1006
        # different subordinate relations so only issue the restart if
 
1007
        # the principle is conencted down the relation we think it is
 
1008
        if related_units(relid=rid):
 
1009
            relation_set(relation_id=rid,
 
1010
                         relation_settings=trigger,
 
1011
                         )