~therve/landscape-client/sysinfo-network-disks

« back to all changes in this revision

Viewing changes to landscape/tests/test_configuration.py

  • Committer: Kevin McDermott
  • Date: 2010-01-20 20:03:51 UTC
  • mfrom: (171.2.14 fix-ALL-users-bug)
  • Revision ID: kevin@canonical.com-20100120200351-i1wpk8ytc4dkrgki
Commit changes in this branch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
455
455
                          "FooPlugin, ScriptExecution")
456
456
 
457
457
    def test_query_script_users_defined_on_command_line(self):
 
458
        """
 
459
        Confirm with the user for users specified for the ScriptPlugin.
 
460
        """
458
461
        self.config.include_manager_plugins = "FooPlugin"
459
462
        self.mocker.order()
460
463
        script_mock = self.mocker.patch(self.script)
462
465
        script_mock.prompt_yes_no("Enable script execution?", default=False)
463
466
        self.mocker.result(True)
464
467
        script_mock.show_help(ANY)
465
 
        raw_input_mock = self.mocker.replace(raw_input, passthrough=False)
466
 
        self.expect(raw_input_mock(ANY)).count(0)
 
468
        script_mock.prompt_get_input(
 
469
            "Script users [root, nobody, landscape]: ", False)
467
470
        self.mocker.replay()
468
471
 
469
472
        self.config.load_command_line(
472
475
        self.assertEquals(self.config.script_users,
473
476
                          "root, nobody, landscape")
474
477
 
 
478
    def test_query_script_users_defined_on_command_line_with_unknown_user(self):
 
479
        """
 
480
        If several users are provided on the command line, we verify the users
 
481
        and raise a ConfigurationError if any are unknown on this system.
 
482
        """
 
483
        pwnam_mock = self.mocker.replace("pwd.getpwnam")
 
484
        pwnam_mock("root")
 
485
        self.mocker.result(None)
 
486
        pwnam_mock("nobody")
 
487
        self.mocker.result(None)
 
488
        pwnam_mock("landscape")
 
489
        self.mocker.result(None)
 
490
        pwnam_mock("unknown")
 
491
        self.mocker.throw(KeyError())
 
492
        self.mocker.replay()
 
493
 
 
494
        self.config.load_command_line(
 
495
            ["--script-users", "root, nobody, landscape, unknown",
 
496
            "--include-manager-plugins", "ScriptPlugin"])
 
497
        self.assertRaises(ConfigurationError, self.script.query_script_plugin)
 
498
 
 
499
    def test_query_script_users_defined_on_command_line_with_all_user(self):
 
500
        """
 
501
        We shouldn't accept all as a synonym for ALL
 
502
        """
 
503
        self.config.load_command_line(
 
504
            ["--script-users", "all",
 
505
            "--include-manager-plugins", "ScriptPlugin"])
 
506
        self.assertRaises(ConfigurationError, self.script.query_script_plugin)
 
507
 
 
508
    def test_query_script_users_defined_on_command_line_with_ALL_user(self):
 
509
        """
 
510
        ALL is the special marker for all users.
 
511
        """
 
512
        self.config.load_command_line(
 
513
            ["--script-users", "ALL",
 
514
             "--include-manager-plugins", "ScriptPlugin"])
 
515
        self.script.query_script_plugin()
 
516
        self.assertEquals(self.config.script_users,
 
517
                          "ALL")
 
518
 
 
519
    def test_query_script_users_defined_on_command_line_with_ALL_and_extra_user(self):
 
520
        """
 
521
        If ALL and additional users are provided as the users on the command
 
522
        line, this should raise an appropriate ConfigurationError.
 
523
        """
 
524
        self.config.load_command_line(
 
525
            ["--script-users", "ALL, kevin",
 
526
            "--include-manager-plugins", "ScriptPlugin"])
 
527
        self.assertRaises(ConfigurationError, self.script.query_script_plugin)
 
528
 
 
529
    def test_invalid_user_entered_by_user(self):
 
530
        """
 
531
        If an invalid user is entered on the command line the user should be
 
532
        informed and prompted again.
 
533
        """
 
534
        help_snippet = "Landscape has a feature which enables administrators"
 
535
        self.mocker.order()
 
536
        script_mock = self.mocker.patch(self.script)
 
537
        script_mock.show_help(self.get_matcher(help_snippet))
 
538
        script_mock.prompt_yes_no("Enable script execution?", default=False)
 
539
        self.mocker.result(True)
 
540
        script_mock.show_help(
 
541
            self.get_matcher("By default, scripts are restricted"))
 
542
        script_mock.prompt_get_input("Script users: ", False)
 
543
        self.mocker.result(u"nonexistent")
 
544
        script_mock.show_help("Unknown system users: nonexistent")
 
545
        script_mock.prompt_get_input("Script users: ", False)
 
546
        self.mocker.result(u"root")
 
547
        self.mocker.replay()
 
548
        self.script.query_script_plugin()
 
549
        self.assertEquals(self.config.script_users,
 
550
                          "root")
 
551
 
475
552
    def test_tags_not_defined_on_command_line(self):
476
553
        """
477
554
        If tags are not provided, the user should be prompted for them.
689
766
account_name = account
690
767
""")
691
768
 
 
769
    def test_silent_script_users_with_all_user(self):
 
770
        """
 
771
        In silent mode, we shouldn't accept invalid users, it should raise a
 
772
        configuration error.
 
773
        """
 
774
        sysvconfig_mock = self.mocker.patch(SysVConfig)
 
775
        sysvconfig_mock.set_start_on_boot(True)
 
776
        self.mocker.replay()
 
777
 
 
778
        config = self.get_config(
 
779
            ["--script-users", "all",
 
780
             "--include-manager-plugins", "ScriptPlugin",
 
781
             "-a", "account",
 
782
             "-t", "rex",
 
783
             "--silent"])
 
784
        self.assertRaises(ConfigurationError, setup, config)
 
785
 
692
786
    def test_silent_setup_with_ping_url(self):
693
787
        sysvconfig_mock = self.mocker.patch(SysVConfig)
694
788
        sysvconfig_mock.set_start_on_boot(True)