~ionutbalutoiu/charms/trusty/neutron-api/next

« back to all changes in this revision

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

  • Committer: Liam Young
  • Date: 2015-10-19 06:36:41 UTC
  • mfrom: (152.1.5 trunk)
  • Revision ID: liam.young@canonical.com-20151019063641-r81lhgo9q9yjvlf2
[1chb1n, r=gnuoy] Update amulet tests for Trusty-Liberty, Wily-Liberty.

Sync charmhelpers.

Add service and relations to satisfy workload status ready state.

Add new logic to wait for extended status message to confirm deploy is ready, before testing.

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 glob
17
18
import json
18
19
import os
19
20
import re
951
952
                    'config': config}
952
953
        return ovs_ctxt
953
954
 
 
955
    def midonet_ctxt(self):
 
956
        driver = neutron_plugin_attribute(self.plugin, 'driver',
 
957
                                          self.network_manager)
 
958
        midonet_config = neutron_plugin_attribute(self.plugin, 'config',
 
959
                                                  self.network_manager)
 
960
        mido_ctxt = {'core_plugin': driver,
 
961
                     'neutron_plugin': 'midonet',
 
962
                     'neutron_security_groups': self.neutron_security_groups,
 
963
                     'local_ip': unit_private_ip(),
 
964
                     'config': midonet_config}
 
965
 
 
966
        return mido_ctxt
 
967
 
954
968
    def __call__(self):
955
969
        if self.network_manager not in ['quantum', 'neutron']:
956
970
            return {}
972
986
            ctxt.update(self.nuage_ctxt())
973
987
        elif self.plugin == 'plumgrid':
974
988
            ctxt.update(self.pg_ctxt())
 
989
        elif self.plugin == 'midonet':
 
990
            ctxt.update(self.midonet_ctxt())
975
991
 
976
992
        alchemy_flags = config('neutron-alchemy-flags')
977
993
        if alchemy_flags:
1104
1120
 
1105
1121
        ctxt = {
1106
1122
            ... other context ...
1107
 
            'subordinate_config': {
 
1123
            'subordinate_configuration': {
1108
1124
                'DEFAULT': {
1109
1125
                    'key1': 'value1',
1110
1126
                },
1145
1161
                    try:
1146
1162
                        sub_config = json.loads(sub_config)
1147
1163
                    except:
1148
 
                        log('Could not parse JSON from subordinate_config '
1149
 
                            'setting from %s' % rid, level=ERROR)
 
1164
                        log('Could not parse JSON from '
 
1165
                            'subordinate_configuration setting from %s'
 
1166
                            % rid, level=ERROR)
1150
1167
                        continue
1151
1168
 
1152
1169
                    for service in self.services:
1153
1170
                        if service not in sub_config:
1154
 
                            log('Found subordinate_config on %s but it contained'
1155
 
                                'nothing for %s service' % (rid, service),
1156
 
                                level=INFO)
 
1171
                            log('Found subordinate_configuration on %s but it '
 
1172
                                'contained nothing for %s service'
 
1173
                                % (rid, service), level=INFO)
1157
1174
                            continue
1158
1175
 
1159
1176
                        sub_config = sub_config[service]
1160
1177
                        if self.config_file not in sub_config:
1161
 
                            log('Found subordinate_config on %s but it contained'
1162
 
                                'nothing for %s' % (rid, self.config_file),
1163
 
                                level=INFO)
 
1178
                            log('Found subordinate_configuration on %s but it '
 
1179
                                'contained nothing for %s'
 
1180
                                % (rid, self.config_file), level=INFO)
1164
1181
                            continue
1165
1182
 
1166
1183
                        sub_config = sub_config[self.config_file]
1363
1380
            normalized.update({port: port for port in resolved
1364
1381
                               if port in ports})
1365
1382
            if resolved:
1366
 
                return {bridge: normalized[port] for port, bridge in
 
1383
                return {normalized[port]: bridge for port, bridge in
1367
1384
                        six.iteritems(portmap) if port in normalized.keys()}
1368
1385
 
1369
1386
        return None
1374
1391
    def __call__(self):
1375
1392
        ctxt = {}
1376
1393
        mappings = super(PhyNICMTUContext, self).__call__()
1377
 
        if mappings and mappings.values():
1378
 
            ports = mappings.values()
 
1394
        if mappings and mappings.keys():
 
1395
            ports = sorted(mappings.keys())
1379
1396
            napi_settings = NeutronAPIContext()()
1380
1397
            mtu = napi_settings.get('network_device_mtu')
 
1398
            all_ports = set()
 
1399
            # If any of ports is a vlan device, its underlying device must have
 
1400
            # mtu applied first.
 
1401
            for port in ports:
 
1402
                for lport in glob.glob("/sys/class/net/%s/lower_*" % port):
 
1403
                    lport = os.path.basename(lport)
 
1404
                    all_ports.add(lport.split('_')[1])
 
1405
 
 
1406
            all_ports = list(all_ports)
 
1407
            all_ports.extend(ports)
1381
1408
            if mtu:
1382
 
                ctxt["devs"] = '\\n'.join(ports)
 
1409
                ctxt["devs"] = '\\n'.join(all_ports)
1383
1410
                ctxt['mtu'] = mtu
1384
1411
 
1385
1412
        return ctxt