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

« back to all changes in this revision

Viewing changes to landscape/broker/tests/test_ping.py

  • Committer: Andreas Hasenack
  • Date: 2011-07-22 15:41:23 UTC
  • Revision ID: andreas@canonical.com-20110722154123-1vie9nnqgpiubx6j
* Try to load the old persist file if the current one doesn't exist or is
  empty (LP: #809210).
* Fallback to gethostname to get something interesting out of get_fqdn.
* Fix wrong ownership and permissions when the reporter is run as a result
  of applying a repository profile (LP: #804008).
* Keep original sources.list ownership (LP: #804548).
* Refactored tests (LP: #805746).
* Preserve permissions of sources.list (LP: #804548).
* Added a broker command line option (--record) that saves exchanges with the
  server to the filesystem 
* Detect if running in a vmware guest (LP: #795794).
* Report VM type when run in the cloud (LP: #797069).
* Report VM type in non-cloud registration (LP: #795752).
* Report the package reporter result even in case of success, not just in
  case of failure (LP: #780406).
* Report package reporter errors (LP: #732490).
* Fix dependencies for hardy removing references to python 2.4 packages for
  pycurl and dbus (LP: #759764).
* The landscape client now reports whether it is running on a virtual machine
  or not.
* Add a plugin which manages APT sources.list and the associated GPG keys
  (LP: #758928).
* Limit the number of items in a network message to 200, to prevent problems
  when communication is interrupted with the server and the client
  accumulates too many network items, thus overloading the server when it's
  available again (LP: #760486).
* Updated version number in __init__.py so that the client reports the
  correct one in its user-agent string.

Show diffs side-by-side

added added

removed removed

Lines of Context:
60
60
                            self.broker_service.identity,
61
61
                            get_page=client.get_page)
62
62
        pinger.ping()
63
 
        self.assertEquals(
 
63
        self.assertEqual(
64
64
            client.fetches,
65
65
            [(url, True, {"Content-Type": "application/x-www-form-urlencoded"},
66
66
              "insecure_id=10")])
77
77
                            get_page=client.get_page)
78
78
        d = pinger.ping()
79
79
        d.addCallback(self.assertEqual, False)
80
 
        self.assertEquals(client.fetches, [])
 
80
        self.assertEqual(client.fetches, [])
81
81
 
82
82
    def test_respond(self):
83
83
        """
105
105
                            get_page=client.failing_get_page)
106
106
        d = pinger.ping()
107
107
        failures = []
 
108
 
108
109
        def errback(failure):
109
110
            failures.append(failure)
110
111
        d.addErrback(errback)
111
 
        self.assertEquals(len(failures), 1)
112
 
        self.assertEquals(failures[0].getErrorMessage(), "That's a failure!")
113
 
        self.assertEquals(failures[0].type, AssertionError)
 
112
        self.assertEqual(len(failures), 1)
 
113
        self.assertEqual(failures[0].getErrorMessage(), "That's a failure!")
 
114
        self.assertEqual(failures[0].type, AssertionError)
114
115
 
115
116
 
116
117
class PingerTest(LandscapeTest):
126
127
        super(PingerTest, self).setUp()
127
128
        self.url = "http://localhost:8081/whatever"
128
129
        self.page_getter = FakePageGetter(None)
 
130
 
129
131
        def factory(reactor, url, insecure_id):
130
132
            return PingClient(reactor, url, insecure_id,
131
133
                              get_page=self.page_getter.get_page)
152
154
        self.pinger.start()
153
155
        self.broker_service.identity.insecure_id = 23
154
156
        self.broker_service.reactor.advance(9)
155
 
        self.assertEquals(len(self.page_getter.fetches), 0)
 
157
        self.assertEqual(len(self.page_getter.fetches), 0)
156
158
        self.broker_service.reactor.advance(1)
157
 
        self.assertEquals(len(self.page_getter.fetches), 1)
 
159
        self.assertEqual(len(self.page_getter.fetches), 1)
158
160
 
159
161
    def test_load_insecure_id(self):
160
162
        """
177
179
        # 70 = ping delay + urgent exchange delay
178
180
        self.broker_service.reactor.advance(70)
179
181
 
180
 
        self.assertEquals(len(self.broker_service.transport.payloads), 1)
 
182
        self.assertEqual(len(self.broker_service.transport.payloads), 1)
181
183
 
182
184
    def test_negative_response(self):
183
185
        """
187
189
        self.broker_service.identity.insecure_id = 42
188
190
        self.page_getter.response = {"messages": False}
189
191
        self.broker_service.reactor.advance(10)
190
 
        self.assertEquals(len(self.broker_service.transport.payloads), 0)
 
192
        self.assertEqual(len(self.broker_service.transport.payloads), 0)
191
193
 
192
194
    def test_ping_error(self):
193
195
        """
200
202
        class BadPingClient(object):
201
203
            def __init__(self, *args, **kwargs):
202
204
                pass
 
205
 
203
206
            def ping(self):
204
207
                return fail(ZeroDivisionError("Couldn't fetch page"))
 
208
 
205
209
        pinger = Pinger(self.broker_service.reactor, "http://foo.com/",
206
210
                        self.broker_service.identity,
207
211
                        self.broker_service.exchanger,
218
222
        self.assertTrue("Couldn't fetch page" in log)
219
223
 
220
224
    def test_get_interval(self):
221
 
        self.assertEquals(self.pinger.get_interval(), 10)
 
225
        self.assertEqual(self.pinger.get_interval(), 10)
222
226
 
223
227
    def test_set_intervals_handling(self):
224
228
        self.pinger.start()
225
229
 
226
230
        self.broker_service.reactor.fire("message",
227
231
                                         {"type": "set-intervals", "ping": 73})
228
 
        self.assertEquals(self.pinger.get_interval(), 73)
 
232
        self.assertEqual(self.pinger.get_interval(), 73)
229
233
 
230
234
        # The server may set specific intervals only, not including the ping.
231
235
        self.broker_service.reactor.fire("message", {"type": "set-intervals"})
232
 
        self.assertEquals(self.pinger.get_interval(), 73)
 
236
        self.assertEqual(self.pinger.get_interval(), 73)
233
237
 
234
238
        self.broker_service.identity.insecure_id = 23
235
239
        self.broker_service.reactor.advance(72)
236
 
        self.assertEquals(len(self.page_getter.fetches), 0)
 
240
        self.assertEqual(len(self.page_getter.fetches), 0)
237
241
        self.broker_service.reactor.advance(1)
238
 
        self.assertEquals(len(self.page_getter.fetches), 1)
 
242
        self.assertEqual(len(self.page_getter.fetches), 1)
239
243
 
240
244
    def test_get_url(self):
241
 
        self.assertEquals(self.pinger.get_url(),
242
 
                          "http://localhost:8081/whatever")
 
245
        self.assertEqual(self.pinger.get_url(),
 
246
                         "http://localhost:8081/whatever")
243
247
 
244
248
    def test_set_url(self):
245
249
        url = "http://example.com/mysuperping"
247
251
        self.pinger.start()
248
252
        self.broker_service.identity.insecure_id = 23
249
253
        self.broker_service.reactor.advance(10)
250
 
        self.assertEquals(self.page_getter.fetches[0][0], url)
 
254
        self.assertEqual(self.page_getter.fetches[0][0], url)
251
255
 
252
256
    def test_set_url_after_start(self):
253
257
        url = "http://example.com/mysuperping"
255
259
        self.pinger.set_url(url)
256
260
        self.broker_service.identity.insecure_id = 23
257
261
        self.broker_service.reactor.advance(10)
258
 
        self.assertEquals(self.page_getter.fetches[0][0], url)
 
262
        self.assertEqual(self.page_getter.fetches[0][0], url)