Exemplo n.º 1
0
 def test_unsupported_subsystem(self, mocks):
     with pytest.raises(
             Exception,
             match='cannot handle events for subsystem: not_real'):
         handle_hotplug(hotplug_init=mocks.m_init,
                        devpath='/dev/fake',
                        subsystem='not_real',
                        udevaction='add')
Exemplo n.º 2
0
 def test_unsupported_udevaction(self, mocks):
     with pytest.raises(ValueError, match='Unknown action: not_real'):
         handle_hotplug(
             hotplug_init=mocks.m_init,
             devpath='/dev/fake',
             udevaction='not_real',
             subsystem='net'
         )
Exemplo n.º 3
0
 def test_unsupported_udevaction(self, mocks):
     with pytest.raises(ValueError, match="Unknown action: not_real"):
         handle_hotplug(
             hotplug_init=mocks.m_init,
             devpath="/dev/fake",
             udevaction="not_real",
             subsystem="net",
         )
Exemplo n.º 4
0
 def test_apply_failed_on_remove(self, mocks):
     mocks.m_network_state.iter_interfaces.return_value = [{}]
     mocks.m_activator.bring_down_interface.return_value = False
     with pytest.raises(RuntimeError,
                        match='Failed to bring down device: /dev/fake'):
         handle_hotplug(hotplug_init=mocks.m_init,
                        devpath='/dev/fake',
                        udevaction='remove',
                        subsystem='net')
Exemplo n.º 5
0
 def test_detect_hotplugged_device_not_detected_on_add(self, mocks):
     mocks.m_network_state.iter_interfaces.return_value = [{}]
     with pytest.raises(
             RuntimeError,
             match='Failed to detect {} in updated metadata'.format(
                 FAKE_MAC)):
         handle_hotplug(hotplug_init=mocks.m_init,
                        devpath='/dev/fake',
                        udevaction='add',
                        subsystem='net')
Exemplo n.º 6
0
 def test_update_metadata_failed(self, mocks):
     mocks.m_init.datasource.update_metadata_if_supported.return_value = \
         False
     with pytest.raises(
             RuntimeError,
             match='Datasource .* not updated for event hotplug'):
         handle_hotplug(hotplug_init=mocks.m_init,
                        devpath='/dev/fake',
                        udevaction='remove',
                        subsystem='net')
Exemplo n.º 7
0
 def test_unsupported_subsystem(self, mocks):
     with pytest.raises(
             Exception,
             match="cannot handle events for subsystem: not_real"):
         handle_hotplug(
             hotplug_init=mocks.m_init,
             devpath="/dev/fake",
             subsystem="not_real",
             udevaction="add",
         )
Exemplo n.º 8
0
 def test_retry(self, mocks):
     with pytest.raises(RuntimeError):
         handle_hotplug(hotplug_init=mocks.m_init,
                        devpath='/dev/fake',
                        udevaction='add',
                        subsystem='net')
     assert mocks.m_sleep.call_count == 5
     assert mocks.m_sleep.call_args_list == [
         call(1), call(3), call(5),
         call(10), call(30)
     ]
Exemplo n.º 9
0
 def test_detect_hotplugged_device_detected_on_remove(self, mocks):
     mocks.m_network_state.iter_interfaces.return_value = [{
         'mac_address':
         FAKE_MAC,
     }]
     with pytest.raises(RuntimeError,
                        match='Failed to detect .* in updated metadata'):
         handle_hotplug(hotplug_init=mocks.m_init,
                        devpath='/dev/fake',
                        udevaction='remove',
                        subsystem='net')
Exemplo n.º 10
0
 def test_apply_failed_on_add(self, mocks):
     mocks.m_network_state.iter_interfaces.return_value = [{
         'mac_address':
         FAKE_MAC,
     }]
     mocks.m_activator.bring_up_interface.return_value = False
     with pytest.raises(RuntimeError,
                        match='Failed to bring up device: /dev/fake'):
         handle_hotplug(hotplug_init=mocks.m_init,
                        devpath='/dev/fake',
                        udevaction='add',
                        subsystem='net')
Exemplo n.º 11
0
 def test_successful_remove(self, mocks):
     init = mocks.m_init
     mocks.m_network_state.iter_interfaces.return_value = [{}]
     handle_hotplug(hotplug_init=init,
                    devpath='/dev/fake',
                    udevaction='remove',
                    subsystem='net')
     init.datasource.update_metadata_if_supported.assert_called_once_with(
         [EventType.HOTPLUG])
     mocks.m_activator.bring_down_interface.assert_called_once_with('fake')
     mocks.m_activator.bring_up_interface.assert_not_called()
     init._write_to_cache.assert_called_once_with()
Exemplo n.º 12
0
 def test_update_metadata_failed(self, mocks):
     mocks.m_init.datasource.update_metadata_if_supported.return_value = (
         False)
     with pytest.raises(
             RuntimeError,
             match="Datasource .* not updated for event hotplug"):
         handle_hotplug(
             hotplug_init=mocks.m_init,
             devpath="/dev/fake",
             udevaction="remove",
             subsystem="net",
         )
Exemplo n.º 13
0
 def test_update_event_disabled(self, mocks, caplog):
     init = mocks.m_init
     with mock.patch('cloudinit.stages.update_event_enabled',
                     return_value=False):
         handle_hotplug(hotplug_init=init,
                        devpath='/dev/fake',
                        udevaction='remove',
                        subsystem='net')
     assert 'hotplug not enabled for event of type' in caplog.text
     init.datasource.update_metadata_if_supported.assert_not_called()
     mocks.m_activator.bring_up_interface.assert_not_called()
     mocks.m_activator.bring_down_interface.assert_not_called()
     init._write_to_cache.assert_not_called()
Exemplo n.º 14
0
 def test_succcessful_add(self, mocks):
     init = mocks.m_init
     mocks.m_network_state.iter_interfaces.return_value = [{
         "mac_address":
         FAKE_MAC,
     }]
     handle_hotplug(
         hotplug_init=init,
         devpath="/dev/fake",
         udevaction="add",
         subsystem="net",
     )
     init.datasource.update_metadata_if_supported.assert_called_once_with(
         [EventType.HOTPLUG])
     mocks.m_activator.bring_up_interface.assert_called_once_with("fake")
     mocks.m_activator.bring_down_interface.assert_not_called()
     init._write_to_cache.assert_called_once_with()