Example #1
0
    def test_cmd_has_identifier_param(self):
        module = ModuleInfo(name="test_module")

        cmd = CommandInfo(name="command_with_identifier")
        param = ParamInfo(name=bindcmd.CFGITEM_IDENTIFIER_PARAM)
        cmd.add_param(param)
        module.add_command(cmd)

        cmd = CommandInfo(name="command_without_identifier")
        param = ParamInfo(name="some_argument")
        cmd.add_param(param)
        module.add_command(cmd)

        self.tool.add_module_info(module)

        cmd_parser = cmdparse.BindCmdParser('test_module '
                                            'command_with_identifier')
        self.assertTrue(self.tool._cmd_has_identifier_param(cmd_parser))

        cmd_parser = cmdparse.BindCmdParser('test_module '
                                            'command_without_identifier')
        self.assertFalse(self.tool._cmd_has_identifier_param(cmd_parser))

        cmd_parser = cmdparse.BindCmdParser('badmodule '
                                            'command_without_identifier')
        self.assertFalse(self.tool._cmd_has_identifier_param(cmd_parser))
Example #2
0
    def testCommandWithHelpParam(self):
        cmd_parser = cmdparse.BindCmdParser("zone add help")
        assert cmd_parser.params["help"] == "help"

        cmd_parser = cmdparse.BindCmdParser("zone add help *&)&)*&&$#$^%")
        assert cmd_parser.params["help"] == "help"
        self.assertEqual(len(cmd_parser.params), 1)
Example #3
0
    def testCommandWithParamters_2(self):
        '''Test whether the parameters in key=value can be parsed properly.'''
        cmd_parser = cmdparse.BindCmdParser('zone cmd name = 1:34::2')
        self.assertEqual(cmd_parser.params['name'], '1:34::2')

        cmd_parser = cmdparse.BindCmdParser('zone cmd name = 1\"\'34**&2'
                                            ' value=44\"\'\"')
        self.assertEqual(cmd_parser.params['name'], '1\"\'34**&2')
        self.assertEqual(cmd_parser.params['value'], '44\"\'\"')

        cmd_parser = cmdparse.BindCmdParser('zone cmd name = 1\"\'34**&2'
                                            ',value=  44\"\'\"')
        self.assertEqual(cmd_parser.params['name'], '1\"\'34**&2')
        self.assertEqual(cmd_parser.params['value'], '44\"\'\"')

        cmd_parser = cmdparse.BindCmdParser('zone cmd name =  1\'34**&2'
                                            'value=44\"\'\" value = '
                                            '\"==============\'')
        self.assertEqual(cmd_parser.params['name'], '1\'34**&2value=44\"\'\"')
        self.assertEqual(cmd_parser.params['value'], '==============')

        cmd_parser = cmdparse.BindCmdParser('zone cmd name =    \"1234, '
                                            '567890 \" value ==&*/')
        self.assertEqual(cmd_parser.params['name'], '1234, 567890 ')
        self.assertEqual(cmd_parser.params['value'], '=&*/')
Example #4
0
    def test_apply_cfg_command_int(self):
        self.tool.location = '/'

        self.assertEqual((1, MultiConfigData.DEFAULT),
                         self.tool.config_data.get_value("/foo/an_int"))

        cmd_parser = cmdparse.BindCmdParser('config set identifier='
                                            '"foo/an_int" value="5"')
        self.tool.apply_config_cmd(cmd_parser)
        self.assertEqual((5, MultiConfigData.LOCAL),
                         self.tool.config_data.get_value("/foo/an_int"))

        cmd_parser = cmdparse.BindCmdParser('config unset identifier='
                                            '"foo/an_int"')
        self.tool.apply_config_cmd(cmd_parser)

        self.assertEqual((1, MultiConfigData.DEFAULT),
                         self.tool.config_data.get_value("/foo/an_int"))

        # this should raise a NotFoundError
        cmd_parser = cmdparse.BindCmdParser('config set identifier='
                                            '"foo/bar" value="[]"')
        self.assertRaises(bundy.cc.data.DataNotFoundError,
                          self.tool.apply_config_cmd, cmd_parser)

        cmd_parser = cmdparse.BindCmdParser('config unset identifier='
                                            '"foo/bar"')
        self.assertRaises(bundy.cc.data.DataNotFoundError,
                          self.tool.apply_config_cmd, cmd_parser)

        # this should raise a TypeError
        cmd_parser = cmdparse.BindCmdParser('config set identifier='
                                            '"foo/an_int" value="[]"')
        self.assertRaises(bundy.cc.data.DataTypeError,
                          self.tool.apply_config_cmd, cmd_parser)
Example #5
0
    def test_apply_cfg_command_list(self):
        self.tool.location = '/'

        self.assertEqual(([], MultiConfigData.DEFAULT),
                         self.tool.config_data.get_value("/foo/a_list"))

        self.clt("config set identifier=\"foo/a_list\" value=[\"a\"]", "a")
        self.clt("config set identifier=\"foo/a_list\" value =[\"b\"]", "b")
        self.clt("config set identifier=\"foo/a_list\" value= [\"c\"]", "c")
        self.clt("config set identifier=\"foo/a_list\" value = [\"d\"]", "d")
        self.clt("config set identifier =\"foo/a_list\" value=[\"e\"]", "e")
        self.clt("config set identifier= \"foo/a_list\" value=[\"f\"]", "f")
        self.clt("config set identifier = \"foo/a_list\" value=[\"g\"]", "g")
        self.clt("config set identifier = \"foo/a_list\" value = [\"h\"]", "h")
        self.clt("config set identifier = \"foo/a_list\" value=[\"i\" ]", "i")
        self.clt("config set identifier = \"foo/a_list\" value=[ \"j\"]", "j")
        self.clt("config set identifier = \"foo/a_list\" value=[ \"k\" ]", "k")

        # this should raise a TypeError
        cmd_parser = cmdparse.BindCmdParser('config set identifier='
                                            '"foo/a_list" value="a"')
        self.assertRaises(bundy.cc.data.DataTypeError,
                          self.tool.apply_config_cmd, cmd_parser)

        cmd_parser = cmdparse.BindCmdParser('config set identifier='
                                            '"foo/a_list" value=[1]')
        self.assertRaises(bundy.cc.data.DataTypeError,
                          self.tool.apply_config_cmd, cmd_parser)
Example #6
0
    def testCommandWithParameters(self):
        lines = {
            "zone add zone_name = cnnic.cn, file = cnnic.cn.file master=1.1.1.1",
            "zone add zone_name = \"cnnic.cn\", file ='cnnic.cn.file' master=1.1.1.1  ",
            "zone add zone_name = 'cnnic.cn\", file ='cnnic.cn.file' master=1.1.1.1, "
        }

        for cmd_line in lines:
            cmd_parser = cmdparse.BindCmdParser(cmd_line)
            assert cmd_parser.module == "zone"
            assert cmd_parser.command == "add"
            assert cmd_parser.params["zone_name"] == "cnnic.cn"
            assert cmd_parser.params["file"] == "cnnic.cn.file"
            assert cmd_parser.params["master"] == '1.1.1.1'
Example #7
0
 def testCommandWithListParam(self):
     cmd_parser = cmdparse.BindCmdParser("zone set zone_name='cnnic.cn', "
                                         "master='1.1.1.1, 2.2.2.2'")
     assert cmd_parser.params["master"] == '1.1.1.1, 2.2.2.2'
Example #8
0
 def clt(self, full_cmd_string, item_value):
     cmd_parser = cmdparse.BindCmdParser(full_cmd_string)
     self.tool.apply_config_cmd(cmd_parser)
     self.assertEqual(([item_value], MultiConfigData.LOCAL),
                      self.tool.config_data.get_value("/foo/a_list"))
Example #9
0
 def testCommandWithoutParameter(self):
     cmd_parser = cmdparse.BindCmdParser("zone add")
     assert cmd_parser.module == "zone"
     assert cmd_parser.command == "add"
     self.assertEqual(len(cmd_parser.params), 0)
Example #10
0
 def my_assert_raise(self, exception_type, cmd_line):
     cmd_parser = cmdparse.BindCmdParser(cmd_line)
     self.assertRaises(exception_type, self.bindcmd._validate_cmd,
                       cmd_parser)
Example #11
0
 def no_assert_raise(self, cmd_line):
     cmd_parser = cmdparse.BindCmdParser(cmd_line)
     self.bindcmd._validate_cmd(cmd_parser)