当前位置: 首页>>代码示例>>Python>>正文


Python providers.NetconfServiceProvider类代码示例

本文整理汇总了Python中ydk.providers.NetconfServiceProvider的典型用法代码示例。如果您正苦于以下问题:Python NetconfServiceProvider类的具体用法?Python NetconfServiceProvider怎么用?Python NetconfServiceProvider使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了NetconfServiceProvider类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: SanityTest

class SanityTest(unittest.TestCase):

    @classmethod
    def setUpClass(self):
        self.ncc = NetconfServiceProvider(address='127.0.0.1', port=12022)
        self.crud = CRUDService()

    @classmethod
    def tearDownClass(self):
        self.ncc.close()

    def setUp(self):
        pass
        # print "\nIn method", self._testMethodName
        # bgp_cfg = bgp.Bgp()
        # self.crud.delete(self.ncc, bgp_cfg)

    def tearDown(self):
        pass

    def test_bgp(self):
        # Bgp.Global.AfiSafis.AfiSafi.ApplyPolicy is not supported
        bgp_cfg = bgp.Bgp()
        ipv4_afsf = bgp_cfg.global_.afi_safis.AfiSafi()
        ipv4_afsf.afi_safi_name = 'ipv4-unicast'
        ipv4_afsf.apply_policy.config.default_export_policy = \
            DefaultPolicyTypeEnum.ACCEPT_ROUTE
        bgp_cfg.global_.afi_safis.afi_safi.append(ipv4_afsf)

        self.assertRaises(YPYDataValidationError,
            self.crud.create, self.ncc, bgp_cfg)
开发者ID:josearsenio,项目名称:ydk-gen,代码行数:31,代码来源:test_sanity_deviation_bgp.py

示例2: SanityYang

class SanityYang(unittest.TestCase):

    @classmethod
    def setUpClass(self):
        self.ncc = NetconfServiceProvider(address='127.0.0.1',
                                          username='admin',
                                          password='admin',
                                          protocol='ssh',
                                          port=12022)
        self.crud = CRUDService()

    @classmethod
    def tearDownClass(self):
        self.ncc.close()

    def setUp(self):
        self.crud.delete(self.ncc, ietf_aug_base_1.Cpython())
        self.crud.delete(self.ncc, ietf_aug_base_2.Cpython())

    def tearDown(self):
        self.crud.delete(self.ncc, ietf_aug_base_1.Cpython())
        self.crud.delete(self.ncc, ietf_aug_base_2.Cpython())

    def test_aug_base_1(self):
        cpython = ietf_aug_base_1.Cpython()
        cpython.doc.ydktest_aug_1.aug_one = 'aug one'
        cpython.doc.ydktest_aug_2.aug_two = 'aug two'
        cpython.doc.ydktest_aug_4.aug_four = 'aug four'
        cpython.lib.ydktest_aug_1.ydktest_aug_nested_1.aug_one = 'aug one'
        cpython.lib.ydktest_aug_2.ydktest_aug_nested_2.aug_two = 'aug two'
        cpython.lib.ydktest_aug_4.ydktest_aug_nested_4.aug_four = 'aug four'
        cpython.doc.disutils.four_aug_list.enabled = True

        item1 = cpython.doc.disutils.four_aug_list.Ldata()
        item2 = cpython.doc.disutils.four_aug_list.Ldata()

        item1.name, item1.number = 'one', 1
        item2.name, item1.number = 'two', 2

        self.crud.create(self.ncc, cpython)
        cpython_read = self.crud.read(self.ncc, ietf_aug_base_1.Cpython())

        self.assertEqual(is_equal(cpython, cpython_read), True)

    def test_aug_base_2(self):
        cpython = ietf_aug_base_2.Cpython()
        cpython.tools.aug_four = 'aug four'

        self.crud.create(self.ncc, cpython)
        cpython_read = self.crud.read(self.ncc, ietf_aug_base_2.Cpython())

        self.assertEqual(is_equal(cpython, cpython_read), True)
开发者ID:manradhaCisco,项目名称:ydk-gen,代码行数:52,代码来源:test_sanity_bundle_aug.py

示例3: setUpClass

 def setUpClass(self):
     if SanityYang.PROVIDER_TYPE == "native":
         self.ncc = NativeNetconfServiceProvider(address='127.0.0.1',
                                                 username='admin',
                                                 password='admin',
                                                 protocol='ssh',
                                                 port=12022)
     else:
         self.ncc = NetconfServiceProvider(address='127.0.0.1',
                                           username='admin',
                                           password='admin',
                                           protocol='ssh',
                                           port=12022)
     self.crud = CRUDService()
开发者ID:manradhaCisco,项目名称:ydk-gen,代码行数:14,代码来源:test_sanity_levels.py

示例4: setUpClass

 def setUpClass(self):
     self.ncc = NetconfServiceProvider(address='127.0.0.1',
                                       username='admin',
                                       password='admin',
                                       protocol='ssh',
                                       port=12022)
     self.crud = CRUDService()
开发者ID:manradhaCisco,项目名称:ydk-gen,代码行数:7,代码来源:test_sanity_bundle_aug.py

示例5: setUpClass

 def setUpClass(self):
     if SanityYang.PROVIDER_TYPE == "native":
         self.ncc = NativeNetconfServiceProvider(address='127.0.0.1',
                                                 username='admin',
                                                 password='admin',
                                                 protocol='ssh',
                                                 port=12022)
     else:
         self.ncc = NetconfServiceProvider(address='127.0.0.1',
                                           username='admin',
                                           password='admin',
                                           protocol='ssh',
                                           port=12022)
     self.crud = CRUDService()
     # config device with entity a
     a = self.getInitEntity()
     self.crud.delete(self.ncc, a)
     self.crud.create(self.ncc, a)
开发者ID:manradhaCisco,项目名称:ydk-gen,代码行数:18,代码来源:test_sanity_filter_read.py

示例6: test_keybase_auth

    def test_keybase_auth(self):
        dir_path = os.path.dirname(os.path.realpath(__file__))

        private = "%s/ssh_host_rsa_key" % dir_path
        public = "%s/ssh_host_rsa_key.pub" % dir_path
        provider = NetconfServiceProvider(
            address = self.hostname,
            username = self.username,
            private_key_path = private,
            public_key_path = public,
            port = self.port)

        session = provider.get_session()
        self.assertEqual(session is not None, True)

        encoding = provider.get_encoding()
        self.assertEqual(encoding is not None, True)

        capabilities = provider.get_capabilities()
        self.assertEqual(capabilities is not None, True)
开发者ID:111pontes,项目名称:ydk-gen,代码行数:20,代码来源:test_netconf_provider.py

示例7: setUpClass

 def setUpClass(self):
     self.ncc = NetconfServiceProvider(
         address='127.0.0.1',
         username='admin',
         password='admin',
         protocol='ssh',
         port=12022)
     self.crud = CRUDService()
     a = self.getInitEntity()
     self.crud.delete(self.ncc, a)
     self.crud.create(self.ncc, a)
开发者ID:ReignInChaos,项目名称:ydk-gen,代码行数:11,代码来源:test_sanity_filter_read.py

示例8: SanityTest

class SanityTest(unittest.TestCase):
    PROVIDER_TYPE = "non-native"

    @classmethod
    def setUpClass(self):
        if SanityTest.PROVIDER_TYPE == "native":
            self.ncc = NativeNetconfServiceProvider(address='127.0.0.1',
                                                    username='admin',
                                                    password='admin',
                                                    protocol='ssh',
                                                    port=12022)
        else:
            self.ncc = NetconfServiceProvider(address='127.0.0.1',
                                              username='admin',
                                              password='admin',
                                              protocol='ssh',
                                              port=12022)
        self.crud = CRUDService()

    @classmethod
    def tearDownClass(self):
        self.ncc.close()

    def setUp(self):
        pass

    def tearDown(self):
        pass

    def test_bgp(self):
        # Bgp.Global.AfiSafis.AfiSafi.ApplyPolicy is not supported
        bgp_cfg = bgp.Bgp()
        ipv4_afsf = bgp_cfg.global_.afi_safis.AfiSafi()
        ipv4_afsf.afi_safi_name = 'ipv4-unicast'
        ipv4_afsf.apply_policy.config.default_export_policy = \
            DefaultPolicyTypeEnum.ACCEPT_ROUTE
        bgp_cfg.global_.afi_safis.afi_safi.append(ipv4_afsf)

        self.assertRaises(YPYModelError,
                          self.crud.create, self.ncc, bgp_cfg)
开发者ID:manradhaCisco,项目名称:ydk-gen,代码行数:40,代码来源:test_sanity_deviation_bgp.py

示例9: SanityRpc

class SanityRpc(unittest.TestCase):
    @classmethod
    def setUpClass(self):
        self.ncc = NetconfServiceProvider(address='127.0.0.1', username='admin', password='admin', protocol='ssh', port=12022)
        self.executor = ExecutorService()

    @classmethod
    def tearDownClass(self):
        self.ncc.close()

    def setUp(self):
        from ydk.services import CRUDService
        crud = CRUDService()
        runner = ysanity.Runner()
        crud.delete(self.ncc, runner)

        print '\nIn method', self._testMethodName + ':'

    def tearDown(self):
        pass

    def test_execute_edit_commit_get_rpc(self):
        runner = ysanity.Runner()
        runner.one.number = 1
        runner.one.name = 'runner:one:name'

        edit_rpc = ietf_netconf.EditConfigRpc()
        edit_rpc.input.target.candidate = Empty()
        edit_rpc.input.config = runner
        op = self.executor.execute_rpc(self.ncc, edit_rpc)
        self.assertIn('ok', op)

        commit_rpc = ietf_netconf.CommitRpc()
        op = self.executor.execute_rpc(self.ncc, commit_rpc)
        self.assertIn('ok', op)

        get_rpc = ietf_netconf.GetRpc()
        get_rpc.input.filter = ysanity.Runner()
        op = self.executor.execute_rpc(self.ncc, get_rpc)
        self.assertIn(runner.one.name, op)

    def test_execute_get_config_rpc(self):
        get_config_rpc = ietf_netconf.GetConfigRpc()
        get_config_rpc.input.source.candidate = Empty()
        initial_candidate_data = self.executor.execute_rpc(self.ncc, get_config_rpc)

        runner = ysanity.Runner()
        runner.two.number = 2
        runner.two.name = 'runner:two:name'

        edit_rpc = ietf_netconf.EditConfigRpc()
        edit_rpc.input.target.candidate = Empty()
        edit_rpc.input.config = runner
        op = self.executor.execute_rpc(self.ncc, edit_rpc)
        self.assertIn('ok', op)

        final_candidate_data = self.executor.execute_rpc(self.ncc, get_config_rpc)

        self.assertNotEqual(initial_candidate_data, final_candidate_data)
        self.assertNotIn(runner.two.name, initial_candidate_data)
        self.assertIn(runner.two.name, final_candidate_data)

    def test_execute_validate_rpc(self):
        validate_rpc = ietf_netconf.ValidateRpc()
        validate_rpc.input.source.candidate = Empty()
        op = self.executor.execute_rpc(self.ncc, validate_rpc)
        self.assertIn('ok', op)

    def test_execute_lock_unlock_rpc(self):
        lock_rpc = ietf_netconf.LockRpc()
        lock_rpc.input.target.candidate = Empty()
        op = self.executor.execute_rpc(self.ncc, lock_rpc)
        self.assertIn('ok', op)

        unlock_rpc = ietf_netconf.UnlockRpc()
        unlock_rpc.input.target.candidate = Empty()
        op = self.executor.execute_rpc(self.ncc, unlock_rpc)
        self.assertIn('ok', op)

    def test_execute_lock_unlock_rpc_fail(self):
        lock_rpc = ietf_netconf.LockRpc()
        lock_rpc.input.target.candidate = Empty()
        op = self.executor.execute_rpc(self.ncc, lock_rpc)
        self.assertIn('ok', op)

        unlock_rpc = ietf_netconf.UnlockRpc()
        unlock_rpc.input.target.running = Empty()
        try:
            op = self.executor.execute_rpc(self.ncc, unlock_rpc)
        except Exception as e:
            self.assertIsInstance(e, YPYError)

    def test_execute_non_rpc_fail(self):
        runner = ysanity.Runner()
        try:
            self.executor.execute_rpc(self.ncc, runner)
        except Exception as e:
            self.assertIsInstance(e, YPYError)
            self.assertEqual(e.error_code, YPYErrorCode.INVALID_RPC)

#.........这里部分代码省略.........
开发者ID:josearsenio,项目名称:ydk-gen,代码行数:101,代码来源:test_sanity_rpc.py

示例10: SanityTest

class SanityTest(unittest.TestCase):

	@classmethod
	def setUpClass(self):
		self.ncc = NetconfServiceProvider(address='127.0.0.1', 
			username='admin', password='admin', port=12022)
		self.crud = CRUDService()

	@classmethod
	def tearDownClass(self):
		self.ncc.close()

	def setUp(self):
		print "\nIn method", self._testMethodName
		runner = ysanity.Runner()
		self.crud.delete(self.ncc, runner)

	def tearDown(self):
		runner = ysanity.Runner()
		self.crud.delete(self.ncc, runner)

	def _create_runner(self):
		runner = ysanity.Runner()
		runner.ytypes = runner.Ytypes()
		runner.ytypes.built_in_t = runner.ytypes.BuiltInT()

		return runner

	# def test_invalids(self):
	# 	runner = self._create_runner()  
	# 	runner.ytypes.built_in_t.name = []
	# 	runner.ytypes.built_in_t.u_number8 = -1
	# 	runner.ytypes.built_in_t.enum_value = ''
		
	# 	self.crud.create(self.ncc, runner)
	# 	with self.assertRaises(YPYDataValidationError):
	# 	self.crud.create(self.ncc, runner)

	def test_int8(self):
		# Create Runner
		runner = self._create_runner()
		runner.ytypes.built_in_t.number8 = 0
		self.crud.create(self.ncc, runner)

		# Read into Runner2
		runner1 = ysanity.Runner()
		runner1 = self.crud.read(self.ncc, runner1)

		# Compare runners
		result = is_equal(runner, runner1)
		self.assertEqual(result, True)

	@unittest.skip('skip till validation in place')
	def test_int8_invalid(self):
		runner = self._create_runner()
		runner.ytypes.built_in_t.number8 = 8.5
		# self.crud.create(self.ncc, runner)
		self.assertRaises(YPYDataValidationError, 
			self.crud.create, self.ncc, runner)

		# OLD
		# runner1 = ysanity.Runner()
		# runner1 = self.crud.read(self.ncc, runner1)

		# # invalid object is not equal
		# result = is_equal(runner, runner1)
		# self.assertEqual(result, False)

	def test_int16(self):
		runner = self._create_runner()
		runner.ytypes.built_in_t.number16 = 126	
		self.crud.create(self.ncc, runner)

		# Read into Runner2
		runner1 = ysanity.Runner()
		runner1 = self.crud.read(self.ncc, runner1)

		# Compare runners
		result = is_equal(runner, runner1)
		self.assertEqual(result, True)
		
	@unittest.skip('skip till validation in place')
	def test_int16_invalid(self):
		runner = self._create_runner()
		runner.ytypes.built_in_t.number16 = {}	
		# self.crud.create(self.ncc, runner)
		self.assertRaises(YPYDataValidationError, 
			self.crud.create, self.ncc, runner)

		# OLD
		# # Read into Runner2
		# runner1 = ysanity.Runner()
		# runner1 = self.crud.read(self.ncc, runner1)

		# # Compare runners
		# result = is_equal(runner, runner1)
		# self.assertEqual(result, False)

	def test_int32(self):
		runner = self._create_runner()
#.........这里部分代码省略.........
开发者ID:gnanam336,项目名称:ydk-gen,代码行数:101,代码来源:test_sanity_types.py

示例11: SanityYang

class SanityYang(unittest.TestCase):
    PROVIDER_TYPE = "non-native"

    @classmethod
    def setUpClass(self):
        if SanityYang.PROVIDER_TYPE == "native":
            self.ncc = NativeNetconfServiceProvider(address='127.0.0.1',
                                                    username='admin',
                                                    password='admin',
                                                    protocol='ssh',
                                                    port=12022)
        else:
            self.ncc = NetconfServiceProvider(address='127.0.0.1',
                                              username='admin',
                                              password='admin',
                                              protocol='ssh',
                                              port=12022)
        self.crud = CRUDService()

    @classmethod
    def tearDownClass(self):
        self.ncc.close()

    def setUp(self):
        runner = ysanity.Runner()
        self.crud.delete(self.ncc, runner)

    def tearDown(self):
        runner = ysanity.Runner()
        self.crud.delete(self.ncc, runner)

    def test_one_level_pos(self):
        # READ
        r_1, r_2 = ysanity.Runner(), ysanity.Runner()
        r_1.one.number, r_1.one.name = 1, 'runner:one:name'
        self.crud.create(self.ncc, r_1)
        r_2 = self.crud.read(self.ncc, r_2)
        self.assertEqual(is_equal(r_1, r_2), True)
        # UPDATE
        r_1, r_2 = ysanity.Runner(), ysanity.Runner()
        r_1.one.number, r_1.one.name = 10, 'runner/one/name'
        self.crud.update(self.ncc, r_1)
        r_2 = self.crud.read(self.ncc, r_2)
        self.assertEqual(is_equal(r_1, r_2), True)
        # DELETE
        r_1 = ysanity.Runner()
        self.crud.delete(self.ncc, r_1)
        r_2 = self.crud.read(self.ncc, r_1)
        self.assertEqual(r_2._has_data(), False)

    def test_two_level_pos(self):
        # READ
        r_1 = ysanity.Runner()
        r_1.two.number, r_1.two.name, r_1.two.sub1.number = 2, 'runner:two:name', 21
        self.crud.create(self.ncc, r_1)
        r_2 = ysanity.Runner()
        r_2 = self.crud.read(self.ncc, r_2)
        self.assertEqual(is_equal(r_1, r_2), True)
        # UPDATE
        r_1, r_2 = ysanity.Runner(), ysanity.Runner()
        r_1.two.number, r_1.two.name, r_1.two.sub1.number = 20, 'runner/two/name', 210
        self.crud.update(self.ncc, r_1)
        r_2 = self.crud.read(self.ncc, r_2)
        self.assertEqual(is_equal(r_1, r_2), True)
        # DELETE
        r_1 = ysanity.Runner()
        self.crud.delete(self.ncc, r_1)
        r_2 = self.crud.read(self.ncc, r_1)
        self.assertEqual(r_2._has_data(), False)

    def test_three_level_pos(self):
        # READ
        r_1 = ysanity.Runner()
        r_1.three.number, r_1.three.name, \
            r_1.three.sub1.number, r_1.three.sub1.sub2.number = 3, 'runner:three:name', 31, 311
        self.crud.create(self.ncc, r_1)
        r_2 = ysanity.Runner()
        r_2 = self.crud.read(self.ncc, r_2)
        self.assertEqual(is_equal(r_1, r_2), True)
        # UPDATE
        r_1, r_2 = ysanity.Runner(), ysanity.Runner()
        r_1.three.number, r_1.three.name, \
            r_1.three.sub1.number, r_1.three.sub1.sub2.number = 30, 'runner/three/name', 310, 3110
        self.crud.update(self.ncc, r_1)
        r_2 = self.crud.read(self.ncc, r_2)
        self.assertEqual(is_equal(r_1, r_2), True)
        # DELETE
        r_1 = ysanity.Runner()
        self.crud.delete(self.ncc, r_1)
        r_2 = self.crud.read(self.ncc, r_1)
        self.assertEqual(r_2._has_data(), False)


    def test_onelist_neg_dupkey(self):
        # netsim/enxr not complaining
        r_1, r_2 = ysanity.Runner(), ysanity.Runner()
        e_1, e_2 = ysanity.Runner.OneList.Ldata(), ysanity.Runner.OneList.Ldata()
        e_1.number = 1
        e_2.name = 'foo'
        e_2.number = 1
#.........这里部分代码省略.........
开发者ID:manradhaCisco,项目名称:ydk-gen,代码行数:101,代码来源:test_sanity_levels.py

示例12: SanityYang

class SanityYang(unittest.TestCase):
    @classmethod
    def setUpClass(self):
        self.ncc = NetconfServiceProvider(address='127.0.0.1', username='admin', password='admin', protocol='ssh', port=12022)
        self.crud = CRUDService()

    @classmethod
    def tearDownClass(self):
        self.ncc.close()

    def setUp(self):
        runner = ysanity.Runner()
        self.crud.delete(self.ncc, runner)
        print '\nIn method', self._testMethodName + ':'

    def tearDown(self):
        runner = ysanity.Runner()
        self.crud.delete(self.ncc, runner)

    def test_read_on_ref_class(self):
        r_1 = ysanity.Runner()
        r_1.one.number, r_1.one.name = 1, 'runner:one:name'
        self.crud.create(self.ncc, r_1)
        r_2 = ysanity.Runner()

        r_2.one = READ()
        r_2 = self.crud.read(self.ncc, r_2)
        self.assertEqual(is_equal(r_1, r_2), True)

    def test_read_on_leaf(self):
        r_1 = ysanity.Runner()
        r_1.one.number, r_1.one.name = 1, 'runner:one:name'
        self.crud.create(self.ncc, r_1)
        r_2 = ysanity.Runner()
        r_2.one.number = READ()
        r_2 = self.crud.read(self.ncc, r_2)        
        self.assertEqual(r_2.one.number, r_1.one.number)

        # this will also read r_2.one.name, not able to read only one of them
        r_2 = ysanity.Runner()
        r_2.one.number = 1
        r_2 = self.crud.read(self.ncc, r_2)        
        self.assertEqual(r_2.one.number, r_1.one.number)

        # no such value, will return empty data
        r_2 = ysanity.Runner()
        r_2.one.number = 2
        r_2 = self.crud.read(self.ncc, r_2)        
        self.assertNotEqual(r_2.one.number, r_1.one.number)

    def test_read_on_ref_enum_class(self):
        from ydk.models.ydktest.ydktest_sanity import YdkEnumTestEnum
        r_1 = ysanity.Runner.Ytypes.BuiltInT()
        r_1.enum_value = YdkEnumTestEnum.LOCAL
        self.crud.create(self.ncc, r_1)

        r_2 = ysanity.Runner.Ytypes.BuiltInT()
        r_2.enum_value = READ()
        r_2 = self.crud.read(self.ncc, r_2)
        self.assertEqual(is_equal(r_1, r_2), True)

        r_2 = ysanity.Runner.Ytypes.BuiltInT()
        r_2.enum_value = YdkEnumTestEnum.LOCAL
        r_2 = self.crud.read(self.ncc, r_2)
        self.assertEqual(is_equal(r_1, r_2), True)

        # no such value, nothing returned
        r_2 = ysanity.Runner.Ytypes.BuiltInT()
        r_2.enum_value = YdkEnumTestEnum.REMOTE
        r_2 = self.crud.read(self.ncc, r_2)
        self.assertNotEqual(is_equal(r_1, r_2), True)

    def test_read_on_ref_list(self):
        r_1 = ysanity.Runner.OneList()
        l_1, l_2 = ysanity.Runner.OneList.Ldata(), ysanity.Runner.OneList.Ldata()
        l_1.number, l_2.number = 1, 2
        r_1.ldata.extend([l_1, l_2])
        self.crud.create(self.ncc, r_1)

        r_2 = ysanity.Runner.OneList()
        r_2.ldata = READ()
        r_2 = self.crud.read(self.ncc, r_2)

        self.assertEqual(is_equal(r_1, r_2), True)


    def test_read_on_list_with_key(self):
        r_1 = ysanity.Runner.OneList()
        l_1, l_2 = ysanity.Runner.OneList.Ldata(), ysanity.Runner.OneList.Ldata()
        l_1.number, l_2.number = 1, 2
        r_1.ldata.extend([l_1, l_2])
        self.crud.create(self.ncc, r_1)

        r_2 = ysanity.Runner.OneList()
        r_2.ldata.extend([l_1])
        r_2 = self.crud.read(self.ncc, r_2)

        r_3 = ysanity.Runner.OneList()
        r_3.ldata.extend([l_1])
        self.assertEqual(is_equal(r_2, r_3), True)
#.........这里部分代码省略.........
开发者ID:josearsenio,项目名称:ydk-gen,代码行数:101,代码来源:test_sanity_filters.py

示例13: setUpClass

 def setUpClass(self):
     self.ncc = NetconfServiceProvider(address='127.0.0.1', port=12022)
     self.crud = CRUDService()
开发者ID:josearsenio,项目名称:ydk-gen,代码行数:3,代码来源:test_sanity_deviation_bgp.py

示例14: SanityYang

class SanityYang(unittest.TestCase):


    @classmethod
    def setUpClass(self):
        self.ncc = NetconfServiceProvider(address='127.0.0.1', username='admin', password='admin', protocol='ssh', port=12022)
        self.crud = CRUDService()
        a = self.getInitEntity()
        self.crud.delete(self.ncc, a)
        self.crud.create(self.ncc, a)

    @classmethod
    def tearDownClass(self):
        self.ncc.close()

    def setUp(self):
        print '\nIn method', self._testMethodName + ':'

    def tearDown(self):
        pass

    @classmethod
    def getInitEntity(self):
        """ set and return entity with XML:
        <a>
          <a1>some value</a1>
          <a2>value of a2</a2>
          <a3>value of a3</a3>
          <b>
            <b1>some value</b1>
            <b2>value of b2</b2>
            <b3>value of b3</b3>
            <c/>
            <d>
              <d1>some value d1</d1>
              <d2>value of d2</d2>
              <d3>value of d3</d3>
              <e>
                <e1>some value e1</e1>
                <e2>value of e2</e2>
              </e>
            </d>
          </b>
          <lst>
            <number>1</number>
            <value>one</value>
          </lst>
          <lst>
            <number>2</number>
            <value>two</value>
          </lst>
          <lst>
            <number>3</number>
            <value>three</value>
          </lst>
        </a>        
        """          
        a = ysanity.A()
        a.a1, a.a2, a.a3 = "some value", "value of a2", "value of a3"
        a.b.b1, a.b.b2, a.b.b3 = "some value", "value of b2", "value of b3"
        a.b.c = a.b.C()
        a.b.d.d1, a.b.d.d2, a.b.d.d3 = "some value d1", "value of d2", "value of d3"
        a.b.d.e.e1, a.b.d.e.e2 = "some value e1", "value of e2"
        l1, l2, l3 = a.Lst(), a.Lst(), a.Lst()
        l1.number, l1.value = 1, "one"
        l2.number, l2.value = 2, "two"
        l3.number, l3.value = 3, "three"
        a.lst.extend([l1,l2,l3])
        return a

    def test_CASE1(self):
        a = ysanity.A()
        a = self.crud.read(self.ncc, a)
        # the whole thing
        _a = self.getInitEntity()
        self.assertEqual(is_equal(a, _a), True)

    def test_CASE2(self):
        a = ysanity.A()
        a.a1 = "some value"
        a = self.crud.read(self.ncc, a)
        # the whole thing        
        _a = self.getInitEntity()
        self.assertEqual(is_equal(a, _a), True)

    def test_CASE3(self):
        a = ysanity.A()
        a.a1 = READ()
        a = self.crud.read(self.ncc, a)
        _a = ysanity.A()
        _a.a1 = "some value"
        self.assertEqual(is_equal(a, _a), True)

    def test_CASE4(self):
        a = ysanity.A()
        a.b.b1 = "some value"
        a = self.crud.read(self.ncc, a)
        _a = self.getInitEntity()
        _a.lst, _a.a1, _a.a2, _a.a3 = YList(), None, None, None
        self.assertEqual(is_equal(a, _a), True)
#.........这里部分代码省略.........
开发者ID:josearsenio,项目名称:ydk-gen,代码行数:101,代码来源:test_sanity_filter_read.py

示例15: SanityNetconf

class SanityNetconf(unittest.TestCase):
    PROVIDER_TYPE = "non-native"

    @classmethod
    def setUpClass(self):
        if SanityNetconf.PROVIDER_TYPE == "native":
            self.ncc = NativeNetconfServiceProvider(address='127.0.0.1',
                                                    username='admin',
                                                    password='admin',
                                                    protocol='ssh',
                                                    port=12022)
        else:
            self.ncc = NetconfServiceProvider(address='127.0.0.1',
                                              username='admin',
                                              password='admin',
                                              protocol='ssh',
                                              port=12022)
        self.netconf_service = NetconfService()

    @classmethod
    def tearDownClass(self):
        self.ncc.close()

    def setUp(self):
        from ydk.services import CRUDService
        crud = CRUDService()
        runner = ysanity.Runner()
        crud.delete(self.ncc, runner)


    def tearDown(self):
        pass

    def test_edit_commit_get(self):
        runner = ysanity.Runner()
        runner.one.number = 1
        runner.one.name = 'runner:one:name'

        get_filter = ysanity.Runner()

        op = self.netconf_service.edit_config(self.ncc, Datastore.candidate, runner)
        self.assertIn('ok', op)

        result = self.netconf_service.get_config(self.ncc, Datastore.candidate, get_filter)
        self.assertEqual(is_equal(runner, result), True)

        op = self.netconf_service.commit(self.ncc)
        self.assertIn('ok', op)

        result = self.netconf_service.get(self.ncc, get_filter)
        self.assertEqual(is_equal(runner, result), True)

    def test_copy(self):
        op = self.netconf_service.copy_config(self.ncc, target=Datastore.candidate, source=Datastore.running)
        self.assertIn('ok', op)

    def test_lock_unlock(self):
        op = self.netconf_service.lock(self.ncc, Datastore.running)
        self.assertIn('ok', op)

        op = self.netconf_service.unlock(self.ncc, Datastore.running)
        self.assertIn('ok', op)

    def test_lock_unlock_fail(self):
        op = self.netconf_service.lock(self.ncc, Datastore.candidate)
        self.assertIn('ok', op)

        try:
            op = self.netconf_service.unlock(self.ncc, Datastore.running)
        except Exception as e:
            self.assertIsInstance(e, YPYError)

    def test_validate(self):
        op = self.netconf_service.validate(self.ncc, source=Datastore.candidate)
        self.assertIn('ok', op)

        runner = ysanity.Runner()
        runner.one.number = 1
        runner.one.name = 'runner:one:name'
        op = self.netconf_service.validate(self.ncc, config=runner)
        self.assertIn('ok', op)

    def test_validate_fail(self):
        runner = ysanity.Runner()
        runner.one.number = 1
        runner.one.name = 2
        try:
            self.netconf_service.validate(self.ncc, config=runner)
        except Exception as e:
            self.assertIsInstance(e, YPYModelError)

    def test_commit_discard(self):
        runner = ysanity.Runner()
        runner.two.number = 2
        runner.two.name = 'runner:two:name'
        get_filter = ysanity.Runner()

        op = self.netconf_service.edit_config(self.ncc, Datastore.candidate, runner)
        self.assertIn('ok', op)

#.........这里部分代码省略.........
开发者ID:manradhaCisco,项目名称:ydk-gen,代码行数:101,代码来源:test_sanity_netconf.py


注:本文中的ydk.providers.NetconfServiceProvider类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。