~ahasenack/landscape-client/landscape-client-11.07.1.1-0ubuntu0.11.10.0

« back to all changes in this revision

Viewing changes to landscape/monitor/tests/test_networkactivity.py

  • Committer: Bazaar Package Importer
  • Author(s): Andreas Hasenack
  • Date: 2010-09-08 15:34:09 UTC
  • mto: This revision was merged to the branch mainline in revision 32.
  • Revision ID: james.westby@ubuntu.com-20100908153409-cuhirosnil6hk1f9
Tags: upstream-1.5.5
ImportĀ upstreamĀ versionĀ 1.5.5

Show diffs side-by-side

added added

removed removed

Lines of Context:
10
10
    stats_template = """\
11
11
Inter-|   Receive                           |  Transmit
12
12
 face |bytes    packets compressed multicast|bytes    packets errs drop fifo
13
 
    lo:%(lo_in)d   0       0         0       %(lo_out)d 3321049    0    0    0
 
13
    lo:%(lo_in)d   %(lo_in_p)d       0         0       %(lo_out)d %(lo_out_p)d    0    0    0
14
14
    eth0: %(eth0_in)d   12539      0     62  %(eth0_out)d   12579    0    0   0
15
15
    %(extra)s
16
16
"""
29
29
        super(NetworkActivityTest, self).tearDown()
30
30
 
31
31
    def write_activity(self, lo_in=0, lo_out=0, eth0_in=0, eth0_out=0,
32
 
                        extra="", **kw):
 
32
                        extra="", lo_in_p=0, lo_out_p=0, **kw):
33
33
        kw.update(dict(
34
34
            lo_in = lo_in,
35
35
            lo_out = lo_out,
 
36
            lo_in_p = lo_in_p,
 
37
            lo_out_p = lo_out_p,
36
38
            eth0_in = eth0_in,
37
39
            eth0_out = eth0_out,
38
40
            extra=extra))
80
82
                          [(300, 10, 99)])
81
83
        self.assertNotIn("eth0", message["activities"])
82
84
 
 
85
    def test_proc_rollover(self):
 
86
        """
 
87
        If /proc/net/dev rollovers, the network plugin handles the value and
 
88
        gives a positive value instead.
 
89
        """
 
90
        self.plugin._rollover_maxint = 10000
 
91
        self.write_activity(lo_in=2000, lo_out=1900)
 
92
        self.plugin.run()
 
93
        self.reactor.advance(self.monitor.step_size)
 
94
        self.write_activity(lo_in=1010, lo_out=999)
 
95
        self.plugin.run()
 
96
        message = self.plugin.create_message()
 
97
        self.assertTrue(message)
 
98
        self.assertTrue("type" in message)
 
99
        self.assertEquals(message["type"], "network-activity")
 
100
        self.assertEquals(message["activities"]["lo"],
 
101
                          [(300, 9010, 9099)])
 
102
        self.assertNotIn("eth0", message["activities"])
 
103
 
83
104
    def test_no_message_without_traffic_delta(self):
84
105
        """
85
106
        If no traffic delta is detected between runs, no message will be