Beispiel #1
0
    def test_netconf_delete_container(self):
        # Build loopback configuration
        address = Native.Interface.Loopback.Ipv4.Address()
        address.ip = "2.2.2.2"
        address.netmask = "255.255.255.255"

        loopback = Native.Interface.Loopback()
        loopback.name = 2222
        loopback.ipv4.address.append(address)

        native = Native()
        native.interface.loopback.append(loopback)

        ns = NetconfService()
        result = ns.edit_config(self.ncc, Datastore.candidate, native)
        self.assertTrue(result)

        # Read ipv4 configuration
        native = Native()
        loopback = Native.Interface.Loopback()
        loopback.name = 2222
        native.interface.loopback.append(loopback)
        ipv4_config = ns.get_config(self.ncc, Datastore.candidate, loopback.ipv4)
        self.assertIsNotNone(ipv4_config)
        self.assertEqual(ipv4_config.address['2.2.2.2'].netmask, "255.255.255.255")

        # Delete configuration
        result = ns.discard_changes(self.ncc)
        self.assertEqual(result, True)
Beispiel #2
0
class SanityNetconf(unittest.TestCase):
    @classmethod
    def setUpClass(self):
        self.ncc = NetconfServiceProvider(address='127.0.0.1',
                                          username='******',
                                          password='******',
                                          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)

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

    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, YPYDataValidationError)

    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)

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

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

        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_config(self):
        op = self.netconf_service.copy_config(self.ncc, Datastore.candidate,
                                              Datastore.running)
        self.assertIn('ok', op)
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='******',
                                                    password='******',
                                                    protocol='ssh',
                                                    port=12022)
        else:
            self.ncc = NetconfServiceProvider(address='127.0.0.1',
                                              username='******',
                                              password='******',
                                              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)

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

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

        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_config(self):
        op = self.netconf_service.copy_config(self.ncc, Datastore.candidate, Datastore.running)
        self.assertIn('ok', op)
Beispiel #4
0
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='******',
                                                    password='******',
                                                    protocol='ssh',
                                                    port=12022)
        else:
            self.ncc = NetconfServiceProvider(address='127.0.0.1',
                                              username='******',
                                              password='******',
                                              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.assertEqual(None, 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.assertEqual(None, op)

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

    def test_lock_unlock(self):
        op = self.netconf_service.lock(self.ncc, Datastore.running)
        self.assertEqual(None, op)

        op = self.netconf_service.unlock(self.ncc, Datastore.running)
        self.assertEqual(None, op)

    def test_lock_unlock_fail(self):
        op = self.netconf_service.lock(self.ncc, Datastore.candidate)
        self.assertEqual(None, 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.assertEqual(None, op)

        runner = ysanity.Runner()
        runner.one.number = 1
        runner.one.name = 'runner:one:name'
        op = self.netconf_service.validate(self.ncc, source=runner)
        self.assertEqual(None, op)

    def test_validate_fail(self):
        # should have been handled by YDK local validation
        pass

    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.assertEqual(None, op)

        op = self.netconf_service.discard_changes(self.ncc)
        self.assertEqual(None, op)

        op = self.netconf_service.edit_config(self.ncc, Datastore.candidate,
                                              runner)
        self.assertEqual(None, op)

        op = self.netconf_service.commit(self.ncc)
        self.assertEqual(None, op)

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

    def test_confirmed_commit(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.assertEqual(None, op)

        op = self.netconf_service.commit(self.ncc,
                                         confirmed=True,
                                         confirm_timeout=120)
        self.assertEqual(None, op)

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

        op = self.netconf_service.cancel_commit(self.ncc)
        self.assertEqual(None, op)

    def test_copy_config(self):
        op = self.netconf_service.copy_config(self.ncc, Datastore.candidate,
                                              Datastore.running)
        self.assertEqual(None, op)

        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.assertEqual(None, op)

        op = self.netconf_service.copy_config(self.ncc, Datastore.running,
                                              Datastore.candidate)
        self.assertEqual(None, op)

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

        runner.two.name += 'modified'

        op = self.netconf_service.copy_config(self.ncc, Datastore.running,
                                              runner)
        self.assertEqual(None, op)

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

    def test_delete_config(self):
        pass
        # startup and candidate cannot be both enabled in ConfD
        # op = self.netconf_service.delete_config(self.ncc, Datastore.startup)
        # self.assertEqual(None, op)

    def test_delete_config_fail(self):
        self.assertRaises(YPYServiceError, self.netconf_service.delete_config,
                          self.ncc, Datastore.running)
        self.assertRaises(YPYServiceError, self.netconf_service.delete_config,
                          self.ncc, Datastore.candidate)

    def test_copy_config_fail(self):
        self.assertRaises(YPYServiceError,
                          self.netconf_service.copy_config,
                          self.ncc,
                          target=123,
                          source=456)

    def test_edit_config_fail(self):
        self.assertRaises(YPYServiceError, self.netconf_service.edit_config,
                          self.ncc, Datastore.startup, Datastore.candidate)

    def test_get_config_fail(self):
        runner = ysanity.Runner()
        self.assertRaises(YPYServiceError, self.netconf_service.get_config,
                          self.ncc, "invalid-input", runner)

    def test_lock_fail(self):
        self.assertRaises(YPYServiceError, self.netconf_service.lock, self.ncc,
                          "invalid-input")

    def test_unlock_fail(self):
        self.assertRaises(YPYServiceError, self.netconf_service.unlock,
                          self.ncc, "invalid-input")
class SanityNetconf(unittest.TestCase):
    PROVIDER_TYPE = "non-native"

    @classmethod
    def setUpClass(self):
        from ydk.providers import NetconfServiceProvider
        from ydk.services import NetconfService

        if SanityNetconf.PROVIDER_TYPE == "native":
            self.ncc = NativeNetconfServiceProvider(address='127.0.0.1',
                                                    username='******',
                                                    password='******',
                                                    protocol='ssh',
                                                    port=12022)
        else:
            self.ncc = NetconfServiceProvider(address='127.0.0.1',
                                              username='******',
                                              password='******',
                                              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 _create_runner(self):
        runner = ysanity.Runner()
        runner.one.number = 1
        runner.one.name = 'runner:one:name'
        return runner

    def test_copy_config_invalid_1(self):
        try:
            from ydk.services import Datastore
            op = self.netconf_service.copy_config(self.ncc, target=None, source=Datastore.running)
        except YPYServiceError as err:
            expected_msg = "'target' and 'source' cannot be None"
            self.assertEqual(err.message, expected_msg)
        else:
            raise Exception('YPYServiceError not raised')

    def test_copy_config_invalid_2(self):
        try:
            from ydk.services import Datastore
            op = self.netconf_service.copy_config(self.ncc, target=Datastore.candidate, source=None)
        except YPYServiceError as err:
            expected_msg = "'target' and 'source' cannot be None"
            self.assertEqual(err.message, expected_msg)
        else:
            raise Exception('YPYServiceError not raised')

    def test_copy_config_invalid_3(self):
        try:
            op = self.netconf_service.copy_config(self.ncc, target=None, source=None)
        except YPYServiceError as err:
            expected_msg = "'target' and 'source' cannot be None"
            self.assertEqual(err.message, expected_msg)
        else:
            raise Exception('YPYServiceError not raised')

    def test_copy_config_invalid_4(self):
        try:
            from ydk.services import Datastore
            op = self.netconf_service.copy_config(
                self.ncc, target=Datastore.candidate, source=Datastore.running, with_defaults_option=1)
        except YPYServiceError as err:
            expected_msg = "optional arg 'with_defaults_option' must be of type ietf_netconf_with_defaults.WithDefaultsModeEnum"
            self.assertEqual(err.message, expected_msg)
        else:
            raise Exception('YPYServiceError not raised')

    def test_delete_config_invalid(self):
        try:
            op = self.netconf_service.delete_config(self.ncc, target=None)
        except YPYServiceError as err:
            expected_msg = "'target' cannot be None"
            self.assertEqual(err.message, expected_msg)
        else:
            raise Exception('YPYServiceError not raised')

    def test_edit_config_invalid_1(self):
        try:
            runner = self._create_runner()
            op = self.netconf_service.edit_config(self.ncc, None, runner)
        except YPYServiceError as err:
            expected_msg = "'target' and 'config' cannot be None"
            self.assertEqual(err.message, expected_msg)
        else:
            raise Exception('YPYServiceError not raised')

    def test_edit_config_invalid_2(self):
        try:
            from ydk.services import Datastore
            op = self.netconf_service.edit_config(self.ncc, Datastore.candidate, None)
        except YPYServiceError as err:
            expected_msg = "'target' and 'config' cannot be None"
            self.assertEqual(err.message, expected_msg)
        else:
            raise Exception('YPYServiceError not raised')

    def test_edit_config_invalid_3(self):
        try:
            op = self.netconf_service.edit_config(self.ncc, None, None)
        except YPYServiceError as err:
            expected_msg = "'target' and 'config' cannot be None"
            self.assertEqual(err.message, expected_msg)
        else:
            raise Exception('YPYServiceError not raised')

    def test_edit_config_invalid_4(self):
        try:
            from ydk.services import Datastore
            runner = self._create_runner()
            op = self.netconf_service.edit_config(self.ncc, Datastore.candidate, runner, default_operation=1)
        except YPYServiceError as err:
            expected_msg = "optional arg 'default_operation' must be of type ietf_netconf.EditConfigRpc.Input.DefaultOperationEnum"
            self.assertEqual(err.message, expected_msg)
        else:
            raise Exception('YPYServiceError not raised')

    def test_edit_config_invalid_5(self):
        try:
            from ydk.services import Datastore
            runner = self._create_runner()
            op = self.netconf_service.edit_config(self.ncc, Datastore.candidate, runner, error_option=1)
        except YPYServiceError as err:
            expected_msg = "optional arg 'error_option' must be of type ietf_netconf.EditConfigRpc.Input.ErrorOptionEnum"
            self.assertEqual(err.message, expected_msg)
        else:
            raise Exception('YPYServiceError not raised')

    def test_edit_config_invalid_6(self):
        try:
            from ydk.services import Datastore
            runner = self._create_runner()
            op = self.netconf_service.edit_config(self.ncc, Datastore.candidate, runner, test_option=1)
        except YPYServiceError as err:
            expected_msg = "optional arg 'test_option' must be of type ietf_netconf.EditConfigRpc.Input.TestOptionEnum"
            self.assertEqual(err.message, expected_msg)
        else:
            raise Exception('YPYServiceError not raised')

    def test_get_config_invalid_1(self):
        try:
            from ydk.services import Datastore
            runner = self._create_runner()
            get_filter = ysanity.Runner()

            op = self.netconf_service.edit_config(self.ncc, Datastore.candidate, runner)
            result = self.netconf_service.get_config(self.ncc, None, get_filter)
        except YPYServiceError as err:
            expected_msg = "'source' cannot be None"
            self.assertEqual(err.message, expected_msg)
        else:
            raise Exception('YPYServiceError not raised')

    def test_get_config_invalid_2(self):
        try:
            from ydk.services import Datastore
            runner = self._create_runner()
            get_filter = ysanity.Runner()

            op = self.netconf_service.edit_config(self.ncc, Datastore.candidate, runner)
            result = self.netconf_service.get_config(self.ncc, Datastore.candidate, get_filter, with_defaults_option=1)
        except YPYServiceError as err:
            expected_msg = "optional arg 'with_defaults_option' must be of type ietf_netconf_with_defaults.WithDefaultsModeEnum"
            self.assertEqual(err.message, expected_msg)
        else:
            raise Exception('YPYServiceError not raised')

    def test_get_invalid(self):
        try:
            from ydk.services import Datastore
            runner = self._create_runner()
            get_filter = ysanity.Runner()

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

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

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

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

            result = self.netconf_service.get(self.ncc, get_filter, with_defaults_option=1)
            self.assertEqual(is_equal(runner, result), True)
        except YPYServiceError as err:
            expected_msg = "optional arg 'with_defaults_option' must be of type ietf_netconf_with_defaults.WithDefaultsModeEnum"
            self.assertEqual(err.message, expected_msg)
        else:
            raise Exception('YPYServiceError not raised')

    def test_lock_invalid(self):
        try:
            op = self.netconf_service.lock(self.ncc, None)
        except YPYServiceError as err:
            expected_msg = "'target' cannot be None"
            self.assertEqual(err.message, expected_msg)
        else:
            raise Exception('YPYServiceError not raised')

    def test_unlock_invalid(self):
        try:
            from ydk.services import Datastore
            op = self.netconf_service.lock(self.ncc, Datastore.candidate)
            op = self.netconf_service.unlock(self.ncc, None)
        except YPYServiceError as err:
            expected_msg = "'target' cannot be None"
            self.assertEqual(err.message, expected_msg)
        else:
            raise Exception('YPYServiceError not raised')

    def test_validate_invalid(self):
        try:
            op = self.netconf_service.validate(self.ncc)
        except YPYServiceError as err:
            expected_msg = "'source' cannot be None"
            self.assertEqual(err.message, expected_msg)
        else:
            raise Exception('YPYServiceError not raised')