예제 #1
0
    def test_config_engine_rpc(self):
        '''
        rpc function of config engine
        '''
        dh = MagicMock()
        #dh.commit = MagicMock()
        dh.commit.return_value = Response(status=True, response='test')
        cfg._get_dev_handle.return_value = dh
        kwargs = {'rpc':'test', 'commit_timeout':60}
        cfg._process_cv.return_value=kwargs
        rpc_cmd = '<edit-config><target><candidate/></target><config><configuration><system><host-name>tobybbb</host-name></system></configuration></config></edit-config>'

        # load rpc without device_list
        cfg._load_rpc = MagicMock()
        try:
            config.config_engine(cfg, rpc=rpc_cmd)
        except Exception as err:
            self.assertEqual(str(err), "missing device_list for rpc")

        # run rpc:
        self.assertTrue(config.config_engine(cfg, rpc=rpc_cmd, device_list='r0', commit=True, commit_timeout=60))

        dh.commit.return_value = Response(status=False, response='test')

        #self.assertRaises(Exception, config.config_engine(cfg, rpc=rpc_cmd, device_list='r0', commit=True, commit_timeout=60))

        cfg._process_cv.return_value = {'rpc':'test', 'timeout':60}
        try:
            config.config_engine(cfg, rpc=rpc_cmd, device_list='r0', commit=True, commit_timeout=60)
        except Exception as err:
            self.assertRaises(Exception)
예제 #2
0
    def test_config_set(self):

        #without_device_list
        kwargs = {'cmd_list':'set hello abc', 'load_timeout':60}
        try:
            config.config_engine(cfg,**kwargs)
        except Exception as err:
            self.assertEqual(str(err), "missing device_list for cmd_list")

        #with device_list 
        self.assertTrue(config.config_engine(cfg, cmd_list='set mystr', device_list='r0', load_timeout=60))
        kwargs = {'device_list':'r0','cmd_list':['set mycfg','set mycfg1'],'timeout':60}
        self.assertTrue(config.config_engine(cfg, **kwargs))
예제 #3
0
    def test_config_engine_load_file(self, read_yaml):

        # load_file_without_device_list
        try:
            config.config_engine(cfg, load_file='myfile')
        except Exception as err:
            self.assertEqual(str(err), "missing device_list for load_file")
        # load file
        kwargs = {'load_timeout':60}
        cfg._process_cv = MagicMock(return_value=kwargs)
        self.assertTrue(config.config_engine(cfg, load_file='local:myfile', device_list='r0', load_timeout=60))
        kwargs = {'timeout':60}
        cfg._process_cv.return_value=kwargs
        self.assertTrue(config.config_engine(cfg, load_file='myfile', device_list='r0', timeout=60))
예제 #4
0
    def test_config_engine_kwargs_templates(self, mock_file, find_file, read_yaml):
        self.find_file = MagicMock()
        kwargs = {'template_files': mock_file, 'templates':'test2', 'commit_timeout':60}
        cfg._process_cv.return_value=kwargs
        self.assertTrue(config.config_engine(cfg, device_list='r0', **kwargs))

        # template read_yaml exception
        read_yaml.side_effect =Exception
        kwargs = {'templates':'test2'}
        cfg._process_cv.return_value=kwargs
        try:
            config.config_engine(cfg, device_list='r0', **kwargs)
        except:
            self.assertRaises(Exception)
예제 #5
0
    def test_config_engine_load_string(self):

        # load_file_without_device_list
        kwargs = {'load_string': 'mycfg', 'load_timeout':60}
        cfg._process_cv.return_value=kwargs
        try:
            config.config_engine(cfg, load_string='myfstr')
        except Exception as err:
            self.assertEqual(str(err), "missing device_list for load_string")

        # load file
        self.assertTrue(config.config_engine(cfg, load_string='set mystr', device_list='r0', load_timeout=60))
        kwargs = {'load_string': 'set mycfg', 'timeout':60}
        cfg._process_cv.return_value=kwargs
        self.assertTrue(config.config_engine(cfg, load_string='set mystr', device_list='r0', timeout=60))
예제 #6
0
    def test_config_engine_cmd_list(self):

        # load_file_without_device_list

        # load file
        kwargs = {'load_timeout':60}
        cfg._process_cv.return_value=kwargs

        self.assertTrue(config.config_engine(cfg, cmd_list='set this', device_list='r0'))
        self.assertTrue(config.config_engine(cfg, cmd_list=['set this', 'set that'], device_list='r0'))

        # no device_list
        try:
            config.config_engine(cfg, cmd_list='mycfg')
        except:
            self.assertRaises(Exception)
예제 #7
0
    def test_config_engine_config_file(self, read_yaml):

        # load_file_without_device_list

        # load file
        kwargs = {'load_timeout':60}
        cfg._process_cv.return_value=kwargs
        self.assertTrue(config.config_engine(cfg, config_file='myfile', load_timeout=60))
        kwargs = {'timeout':60}
        cfg._process_cv.return_value=kwargs
#        self.assertTrue(config.config_engine(cfg, config_file='myfile', device_list='r0', timeout=60))

        # config_data
        self.assertTrue(config.config_engine(cfg, config_data='mycfg', load_timeout=60))
        read_yaml.side_effect =Exception
        try:
            config.config_engine(cfg, config_data='mycfg', load_timeout=60)
        except:
            self.assertRaises(Exception)
예제 #8
0
    def test_config_engine_device_list(self):
        # load file
        kwargs = {'load_timeout':60}
        cfg._process_cv.return_value=kwargs
        dh = MagicMock()
        dh.current_node.current_controller.os = 'JunOS'
        dh.current_node.current_controller.host = '1.1.1.1'
       # dh.execute_rpc.return_value = Response(status=True, response='test')
        cfg._get_dev_handle.return_value = dh
        #self.assertTrue(config.config_engine(cfg, cmd_list='set this', device_list='tetra'))
        # device_list has a name that does not exist
        try:
            config.config_engine(cfg, cmd_list='set this', device_list='noname')
        except:
            self.assertRaises(Exception)

        # device _list has a handle:
        self.assertTrue(config.config_engine(cfg, cmd_list='set this', device_list=dh))
        try:
            config.config_engine(cfg, cmd_list='set this', device_list=dict())
        except:
            self.assertRaises(Exception)