Example #1
0
 def test_utils_dict_merge(self):
     r1 = {'relations': ['m1', 'x1']}
     r2 = {'relations': ['m2', 'x2']}
     combined = {'relations': ['m1', 'm2', 'x1', 'x2']}
     test_result = utils.dict_merge(r1, r2)
     self.assertEqual(sorted(combined['relations']),
                      sorted(test_result['relations']))
Example #2
0
    def probe(self):
        results = {}
        self._if_flags.clear()
        for device in self.context.list_devices(subsystem='net'):
            iface = device['INTERFACE']
            results[iface] = {
                'type': self._get_iface_type(iface),
                'bond': self._get_bonding(iface),
                'bridge': self._get_bridging(iface),
                'flags': self._iface_flags(iface),
            }

            if results[iface]['type'] == 'wlan':
                results[iface]['essid'] = self._get_essid(iface)

            hardware = dict(device)
            hardware.update({
                'attrs':
                dict([(key, udev_get_attribute(device, key))
                      for key in device.attributes.available_attributes])
            })
            results = dict_merge(results, {iface: {'hardware': hardware}})

            ip = self._get_ips(iface)
            log.debug('IP res: {}'.format(ip))
            sources = {}
            sources[netifaces.AF_INET] = []
            sources[netifaces.AF_INET6] = []
            for i in range(len(ip[netifaces.AF_INET])):
                sources[netifaces.AF_INET].append(
                    self._get_ip_source(iface, ip[netifaces.AF_INET][i]))
            for i in range(len(ip[netifaces.AF_INET6])):
                sources[netifaces.AF_INET6].append(
                    self._get_ip_source(iface, ip[netifaces.AF_INET6][i]))
            ip.update({'sources': sources})
            results = dict_merge(results, {iface: {'ip': ip}})

        self.results = results
        log.debug('probe results: {}'.format(results))
        return results
Example #3
0
 def test_utils_dict_merge_dicts(self):
     r1 = {'storage': {'/dev/sda': {'DEVTYPE': 'disk'}}}
     r2 = {'storage': {'/dev/sda': {'ID_MODEL': 'AWESOME'}}}
     combined = {
         'storage': {
             '/dev/sda': {
                 'DEVTYPE': 'disk',
                 'ID_MODEL': 'AWESOME',
             }
         }
     }
     test_result = utils.dict_merge(r1, r2)
     self.assertEqual(sorted(combined), sorted(test_result))
Example #4
0
 def test_utils_dict_merge_lists(self):
     r1 = ['m1', 'x1']
     r2 = ['m2', 'x2']
     combined = ['m1', 'm2', 'x1', 'x2']
     test_result = utils.dict_merge(r1, r2)
     self.assertEqual(sorted(combined), sorted(test_result))