~free.ekanayaka/landscape-client/facade-set-datadir

« back to all changes in this revision

Viewing changes to landscape/manager/tests/test_customgraph.py

Merge customgraph-unicode-user [r=jkakar,bigkevmcd] [f=406388]

Handle unicode username in custom graphs, and also report missing user to the
server properly.

Show diffs side-by-side

added added

removed removed

Lines of Context:
344
344
        username = info.pw_name
345
345
        self.manager.config.script_users = "foo"
346
346
 
347
 
        filename = self.makeFile("some content")
348
 
        self.store.add_graph(123, filename, username)
 
347
        self.store.add_graph(123, "filename", username)
349
348
        factory = StubProcessFactory()
350
349
        self.graph_manager.process_factory = factory
351
350
        result = self.graph_manager.run()
360
359
                      {"error":
361
360
                       u"ProhibitedUserError: Custom graph cannot be run as "
362
361
                        "user %s" % (username,),
363
 
                       "script-hash": "9893532233caff98cd083a116b013c0b",
 
362
                       "script-hash": "",
364
363
                       "values": []}},
365
364
                  "type": "custom-graph"}])
366
365
 
374
373
 
375
374
        self.manager.config.script_users = "foo"
376
375
 
377
 
        filename = self.makeFile("some content")
378
 
        self.store.add_graph(123, filename, "foo")
 
376
        self.store.add_graph(123, "filename", "foo")
379
377
        factory = StubProcessFactory()
380
378
        self.graph_manager.process_factory = factory
381
379
        result = self.graph_manager.run()
388
386
                self.broker_service.message_store.get_pending_messages(),
389
387
                [{"data": {123:
390
388
                      {"error": u"UnknownUserError: Unknown user 'foo'",
391
 
                       "script-hash": "9893532233caff98cd083a116b013c0b",
 
389
                       "script-hash": "",
392
390
                       "values": []}},
393
391
                  "type": "custom-graph"}])
394
392
 
426
424
    def test_run_removed_file(self):
427
425
        """
428
426
        If run is called on a script file that has been removed, it doesn't try
429
 
        to run it, and remove the graph from the store.
 
427
        to run it, but report it with an empty hash value.
430
428
        """
431
429
        self.store.add_graph(123, "/nonexistent", None)
432
430
        factory = StubProcessFactory()
438
436
        self.graph_manager.exchange()
439
437
        self.assertMessages(
440
438
            self.broker_service.message_store.get_pending_messages(),
441
 
            [{"data": {},
 
439
            [{"data": {123: {"error": u"", "script-hash": "", "values": []}},
442
440
              "type": "custom-graph"}])
443
 
        self.assertIdentical(self.store.get_graph(123), None)
444
441
 
445
442
    def test_send_message_add_stored_graph(self):
446
443
        """
466
463
              "timestamp": 0,
467
464
              "type": "custom-graph"}])
468
465
 
469
 
    def test_send_message_remove_not_present_graph(self):
470
 
        """
471
 
        C{send_message} checks the presence of the custom-graph script, and
472
 
        remove the graph if the file is not present anymore.
473
 
        """
 
466
    def test_send_message_check_not_present_graph(self):
 
467
        """C{send_message} checks the presence of the custom-graph script."""
474
468
        uid = os.getuid()
475
469
        info = pwd.getpwuid(uid)
476
470
        username = info.pw_name
489
483
              "data": {},
490
484
              "timestamp": 0,
491
485
              "type": "custom-graph"}])
492
 
        self.assertIdentical(self.store.get_graph(123), None)
493
486
 
494
487
    def test_send_message_dont_rehash(self):
495
488
        """
596
589
                self.broker_service.message_store.get_pending_messages(),
597
590
                [{"api": API,
598
591
                  "data": {123: {"error": u"",
599
 
                                 "script-hash": "991e15a81929c79fe1d243b2afd99c62",
 
592
                                 "script-hash":
 
593
                                    "991e15a81929c79fe1d243b2afd99c62",
600
594
                                 "values": []}},
601
595
                  "timestamp": 0,
602
596
                  "type": "custom-graph"}])
679
673
        self.assertEquals(len(factory.spawns), 0)
680
674
 
681
675
        return result.addCallback(self.assertEquals, [])
 
676
 
 
677
    def test_run_unknown_user_with_unicode(self):
 
678
        """
 
679
        Using a non-existent user containing unicode characters fails with the
 
680
        appropriate error message.
 
681
        """
 
682
        username = u"non-existent-f\N{LATIN SMALL LETTER E WITH ACUTE}e"
 
683
 
 
684
        self.manager.config.script_users = "ALL"
 
685
 
 
686
        filename = self.makeFile("some content")
 
687
        self.store.add_graph(123, filename, username)
 
688
        factory = StubProcessFactory()
 
689
        self.graph_manager.process_factory = factory
 
690
        result = self.graph_manager.run()
 
691
 
 
692
        self.assertEquals(len(factory.spawns), 0)
 
693
 
 
694
        def check(ignore):
 
695
            self.graph_manager.exchange()
 
696
            self.assertMessages(
 
697
                self.broker_service.message_store.get_pending_messages(),
 
698
                [{"data": {123:
 
699
                      {"error":
 
700
                           u"UnknownUserError: Unknown user '%s'" % username,
 
701
                       "script-hash": "9893532233caff98cd083a116b013c0b",
 
702
                       "values": []}},
 
703
                  "type": "custom-graph"}])
 
704
 
 
705
        return result.addCallback(check)