Ejemplo n.º 1
0
 def test_tc_empty(self):
     """
     There is a validation in the command() method that makes sure
     that if the reorder command is given that the delay is supplied as well.
     This test makes sure that this works as designed.
     """
     tc_obj = Tc()
     expected_output = 'tc qdisc del dev eth0 root;'
     self.assertEqual(tc_obj.command(), expected_output)
Ejemplo n.º 2
0
    def build_tc_command(commands, filter_ip=None):
        tc = Tc()
        command_dispatch = {
            "limit": tc.limit,
            "delay": tc.delay,
            "loss_random": tc.loss_random,
            "loss_state": tc.loss_state,
            "corrupt": tc.corrupt,
            "duplicate": tc.duplicate,
            "reorder": tc.reorder,
            "rate": tc.rate
        }

        # If all values are None, then we should clean.

        if all([value is None for value in commands.values()]):
            return tc.clean()

        tc = tc.filter(filter_ip)
        for key in commands:
            if commands[key] is not None:
                tc = command_dispatch[key](**commands[key])

        return tc.command()