コード例 #1
0
ファイル: test_init.py プロジェクト: P79N6A/cloud-init-1
 def test_wait_for_physdevs_no_raise_if_not_strict(self):
     physdevs = [
         ['aa:bb:cc:dd:ee:ff', 'eth0', 'virtio', '0x1000'],
         ['00:11:22:33:44:55', 'ens3', 'e1000', '0x1643'],
     ]
     netcfg = {
         'version': 2,
         'ethernets': {args[1]: _mk_v2_phys(*args)
                       for args in physdevs},
     }
     self.m_get_iface_mac.return_value = {}
     net.wait_for_physdevs(netcfg, strict=False)
     self.assertEqual(5 * len(physdevs), self.m_udev_settle.call_count)
コード例 #2
0
ファイル: test_init.py プロジェクト: P79N6A/cloud-init-1
    def test_wait_for_physdevs_raise_runtime_error_if_missing_and_strict(self):
        physdevs = [
            ['aa:bb:cc:dd:ee:ff', 'eth0', 'virtio', '0x1000'],
            ['00:11:22:33:44:55', 'ens3', 'e1000', '0x1643'],
        ]
        netcfg = {
            'version': 2,
            'ethernets': {args[1]: _mk_v2_phys(*args)
                          for args in physdevs},
        }
        self.m_get_iface_mac.return_value = {}
        with self.assertRaises(RuntimeError):
            net.wait_for_physdevs(netcfg)

        self.assertEqual(5 * len(physdevs), self.m_udev_settle.call_count)
コード例 #3
0
ファイル: test_init.py プロジェクト: P79N6A/cloud-init-1
 def test_wait_for_physdevs_skips_settle_if_all_present(self):
     physdevs = [
         ['aa:bb:cc:dd:ee:ff', 'eth0', 'virtio', '0x1000'],
         ['00:11:22:33:44:55', 'ens3', 'e1000', '0x1643'],
     ]
     netcfg = {
         'version': 2,
         'ethernets': {args[1]: _mk_v2_phys(*args)
                       for args in physdevs},
     }
     self.m_get_iface_mac.side_effect = iter([
         {
             'aa:bb:cc:dd:ee:ff': 'eth0',
             '00:11:22:33:44:55': 'ens3'
         },
     ])
     net.wait_for_physdevs(netcfg)
     self.assertEqual(0, self.m_udev_settle.call_count)
コード例 #4
0
    def apply_network_config(self, bring_up):
        # get a network config
        netcfg, src = self._find_networking_config()
        if netcfg is None:
            LOG.info("network config is disabled by %s", src)
            return

        # request an update if needed/available
        if self.datasource is not NULL_DATA_SOURCE:
            if not self.is_new_instance():
                if not self.datasource.update_metadata([EventType.BOOT]):
                    LOG.debug(
                        "No network config applied. Neither a new instance"
                        " nor datasource network update on '%s' event",
                        EventType.BOOT)
                    # nothing new, but ensure proper names
                    self._apply_netcfg_names(netcfg)
                    return
                else:
                    # refresh netcfg after update
                    netcfg, src = self._find_networking_config()

        # ensure all physical devices in config are present
        net.wait_for_physdevs(netcfg)

        # apply renames from config
        self._apply_netcfg_names(netcfg)

        # rendering config
        LOG.info("Applying network configuration from %s bringup=%s: %s", src,
                 bring_up, netcfg)
        try:
            return self.distro.apply_network_config(netcfg, bring_up=bring_up)
        except net.RendererNotFoundError as e:
            LOG.error(
                "Unable to render networking. Network config is "
                "likely broken: %s", e)
            return
        except NotImplementedError:
            LOG.warning(
                "distro '%s' does not implement apply_network_config. "
                "networking may not be configured properly.", self.distro)
            return
コード例 #5
0
ファイル: test_init.py プロジェクト: P79N6A/cloud-init-1
 def test_wait_for_physdevs_calls_udev_settle_on_missing(self):
     physdevs = [
         ['aa:bb:cc:dd:ee:ff', 'eth0', 'virtio', '0x1000'],
         ['00:11:22:33:44:55', 'ens3', 'e1000', '0x1643'],
     ]
     netcfg = {
         'version': 2,
         'ethernets': {args[1]: _mk_v2_phys(*args)
                       for args in physdevs},
     }
     self.m_get_iface_mac.side_effect = iter([
         {
             'aa:bb:cc:dd:ee:ff': 'eth0'
         },  # first call ens3 is missing
         {
             'aa:bb:cc:dd:ee:ff': 'eth0',
             '00:11:22:33:44:55': 'ens3'
         },  # second call has both
     ])
     net.wait_for_physdevs(netcfg)
     self.m_udev_settle.assert_called_with(exists=net.sys_dev_path('ens3'))
コード例 #6
0
 def wait_for_physdevs(self,
                       netcfg: NetworkConfig,
                       *,
                       strict: bool = True) -> None:
     return net.wait_for_physdevs(netcfg, strict=strict)