コード例 #1
0
 def setUp(self):
     self.conf = ConfigFacade([
         ConfigItem("site", "site1", []),
         ConfigItem("site", "site2", []),
         ConfigItem("arbitrator", "arbitrator1", []),
         ConfigItem("ticket", "ticketA", []),
     ])
コード例 #2
0
 def test_add_with_options(self):
     self.conf.add_ticket("ticketB", {"timeout": "10"})
     self.assertEqual(
         self.conf.config,
         self.conf_struct + [
             ConfigItem("ticket", "ticketB",
                        [ConfigItem("timeout", "10", [])]),
         ],
     )
コード例 #3
0
 def setUp(self):
     self.conf_struct_base = [
         ConfigItem("site", "site1", []),
         ConfigItem("site", "site2", []),
         ConfigItem("arbitrator", "arbitrator1", []),
     ]
     self.conf_struct_tickets = [
         ConfigItem("ticket", "ticketA", []),
         ConfigItem("ticket", "ticketB", []),
     ]
コード例 #4
0
    def create(cls, site_list, arbitrator_list):
        """
        Create a minimal config

        iterable site_list -- list of booth sites' addresses
        iterable arbitrator_list -- list of arbitrators' addresses
        """
        return cls(
            [ConfigItem("site", site) for site in site_list] +
            [ConfigItem("arbitrator", arbit) for arbit in arbitrator_list])
コード例 #5
0
 def test_change_authfile(self):
     conf = ConfigFacade(self.conf_struct_base + [
         ConfigItem("authfile", "/old/path/to/auth1.file", []),
         ConfigItem("authfile", "/old/path/to/auth2.file", []),
     ] + self.conf_struct_tickets)
     conf.set_authfile("/path/to/auth.file")
     self.assertEqual(
         conf.config,
         ([ConfigItem("authfile", "/path/to/auth.file", [])] +
          self.conf_struct_base + self.conf_struct_tickets),
     )
コード例 #6
0
    def add_ticket(self, ticket_name, ticket_options):
        """
        Add a booth ticket to the booth config

        string ticket_name -- the name of the ticket
        dict ticket_options -- ticket options
        """
        self._config.append(
            ConfigItem("ticket", ticket_name, [
                ConfigItem(key, value)
                for key, value in sorted(ticket_options.items())
            ]))
コード例 #7
0
 def setUp(self):
     self.conf_struct_base = [
         ConfigItem("site", "site1", []),
         ConfigItem("site", "site2", []),
         ConfigItem("arbitrator", "arbitrator1", []),
     ]
     self.conf_struct_ticket_a = [
         ConfigItem("ticket", "ticketA", []),
     ]
     self.conf_struct_ticket_b = [
         ConfigItem("ticket", "ticketB", []),
     ]
     self.conf_struct = (self.conf_struct_base + self.conf_struct_ticket_a +
                         self.conf_struct_ticket_b)
     self.conf = ConfigFacade(self.conf_struct[:])
コード例 #8
0
 def test_move_non_ticket_config_keys_above_tickets(self):
     self.assertEqual(
         [
             ConfigItem("site", "1.1.1.1"),
             ConfigItem('site', '2.2.2.2'),
             ConfigItem('arbitrator', '3.3.3.3'),
             ConfigItem("ticket", "TA"),
         ],
         # testing a function which should not be used outside of the module
         # pylint: disable=protected-access
         config_parser._organize_lines([
             ("site", "1.1.1.1"),
             ("ticket", "TA"),
             ('site', '2.2.2.2'),
             ('arbitrator', '3.3.3.3'),
         ]))
コード例 #9
0
 def test_add_no_options(self):
     self.conf.add_ticket("ticketB", {})
     self.assertEqual(
         self.conf.config,
         self.conf_struct + [
             ConfigItem("ticket", "ticketB", []),
         ],
     )
コード例 #10
0
    def set_authfile(self, auth_file):
        """
        Set the path to a booth authfile to the booth config

        string auth_file -- the path to a booth authfile
        """
        self._config = ([ConfigItem("authfile", auth_file)] +
                        self.__filter_out_by_key("authfile"))
コード例 #11
0
ファイル: test_config_parser.py プロジェクト: zht750808/pcs
 def test_build_file_content_from_parsed_structure(self):
     self.assertEqual(
         "\n".join(
             [
                 "authfile = /path/to/auth.file",
                 "site = 1.1.1.1",
                 "site = 2.2.2.2",
                 "arbitrator = 3.3.3.3",
                 'ticket = "TA"',
                 'ticket = "TB"',
                 "  timeout = 10",
                 "",  # newline at the end
             ]
         ).encode("utf-8"),
         config_parser.Exporter.export(
             [
                 ConfigItem("authfile", "/path/to/auth.file"),
                 ConfigItem("site", "1.1.1.1"),
                 ConfigItem("site", "2.2.2.2"),
                 ConfigItem("arbitrator", "3.3.3.3"),
                 ConfigItem("ticket", "TA"),
                 ConfigItem("ticket", "TB", [ConfigItem("timeout", "10")]),
             ]
         ),
     )
コード例 #12
0
 def setUp(self):
     self.conf_struct = [
         ConfigItem("site", "site1", []),
         ConfigItem("site", "site2", []),
         ConfigItem("arbitrator", "arbitrator1", []),
         ConfigItem("ticket", "ticketA", []),
         ConfigItem("ticket", "ticketB", [ConfigItem("timeout", "10", [])]),
     ]
     self.conf = ConfigFacade(self.conf_struct[:])
コード例 #13
0
 def test_add_authfile(self):
     conf = ConfigFacade(
         self.conf_struct_base
         +
         self.conf_struct_tickets
     )
     conf.set_authfile("/path/to/auth.file")
     self.assertEqual(
         conf.config,
         (
             [ConfigItem("authfile", "/path/to/auth.file", [])]
             +
             self.conf_struct_base
             +
             self.conf_struct_tickets
         )
     )
コード例 #14
0
 def test_use_ticket_key_as_ticket_detail(self):
     # pylint: disable=invalid-name
     self.maxDiff = None
     self.assertEqual(
         [
             ConfigItem("site", "1.1.1.1"),
             ConfigItem('expire', '300'),
             ConfigItem('site', '2.2.2.2'),
             ConfigItem('arbitrator', '3.3.3.3'),
             ConfigItem("ticket", "TA", [
                 ConfigItem("timeout", "10"),
                 ConfigItem('--nonexistent', 'value'),
                 ConfigItem("expire", "300"),
             ]),
             ConfigItem("ticket", "TB", [
                 ConfigItem("timeout", "20"),
                 ConfigItem("renewal-freq", "40"),
             ]),
         ],
         # testing a function which should not be used outside of the module
         # pylint: disable=protected-access
         config_parser._organize_lines([
             ("site", "1.1.1.1"),
             ("expire", "300"),  # out of ticket content is kept global
             ("ticket", "TA"),
             ("site", "2.2.2.2"),  # move to global
             ("timeout", "10"),
             ("--nonexistent", "value"),  # no global is kept under ticket
             ("expire", "300"),
             ("ticket", "TB"),
             ('arbitrator', '3.3.3.3'),
             ("timeout", "20"),
             ("renewal-freq", "40"),
         ]))