def test_iface_is_up(self, command, iface_state): iface_value = iter(('UP', ) * 3) iface_state.side_effect = lambda *args, **kwargs: next(iface_value) with utils.IfaceState('eth1') as iface: self.assertEqual(iface, 'eth1') self.assertEqual(iface_state.call_count, 2) self.assertEqual(command.call_count, 0)
def test_iface_is_down(self, command, iface_state): iface_value = iter(('DOWN', 'UP', 'DOWN')) iface_state.side_effect = lambda *args, **kwargs: next(iface_value) with utils.IfaceState('eth1') as iface: self.assertEqual(iface, 'eth1') self.assertEqual(iface_state.call_count, 3) self.assertEqual(command.call_count, 2) self.assertEqual(command.call_args_list, [call('ifconfig', 'eth1', 'up'), call('ifconfig', 'eth1', 'down')])
def test_dhcp_server_on_eth0_up(self): """Test verifies that if iface is up, it won't be touched """ manager = utils.IfaceState(self.iface_up) with manager as iface: response = api.check_dhcp_on_eth(iface, 2) self.assertEqual(len(response), 1) self.assertEqual(response[0]['server_ip'], '10.0.2.2') self.assertEqual(manager.pre_iface_state, 'UP') self.assertEqual(manager.iface_state, 'UP') self.assertEqual(manager.post_iface_state, 'UP')
def test_dhcp_server_on_eth1_down(self): """Test verifies that iface would be ifuped in case it's down and rolledback after """ manager = utils.IfaceState(self.iface_down) with manager as iface: response = api.check_dhcp_on_eth(iface, 2) self.assertEqual(len(response), 1) self.assertEqual(response[0]['server_ip'], '10.10.0.8') self.assertEqual(manager.pre_iface_state, 'DOWN') self.assertEqual(manager.iface_state, 'UP') self.assertEqual(manager.post_iface_state, 'DOWN')
def test_raises(): with utils.IfaceState('eth1', retry=4) as iface: self.assertEqual(iface, 'eth1')
def test_check(): manager = utils.IfaceState('eth10') with manager as iface: api.check_dhcp_on_eth(iface, 2)