Example #1
0
    def test_005_handle_multiple_set_path(self):
        server_ph = YANGPathHelper()
        s = simple_device(path_helper=server_ph)

        c = simple_device()
        c.system.config.hostname = "rtr0.lhr.uk"
        c.system.ntp.config.enabled = True
        operations = [
            PyNMSConfigOperation(c.system.config),
            PyNMSConfigOperation(c.system.ntp)
        ]
        set_msg = PyNMSClientGRPCMethods.generate_set_message(operations,
                                                              request_id=42)
        ret_msg = PyNMSServerGRPCMethods.service_set_request(
            set_msg, server_ph)

        self.assertEqual(ret_msg.request_id, 42)
        self.assertEqual(ret_msg.response_code, 0)
        self.assertEqual(pynms_rpc_pb2.RPCResponse.Name(ret_msg.response_code),
                         'OK')
        self.assertEqual(ret_msg.message, "")

        self.assertEqual(s.system.config.hostname, "rtr0.lhr.uk")
        self.assertEqual(s.system.ntp.config.enabled, True)

        del server_ph
Example #2
0
    def test_007_handle_failed_transaction(self):
        server_ph = YANGPathHelper()
        s = simple_device(path_helper=server_ph)

        set_msg = self._build_invalid_set_message(42, [{
            "path": "/system/config/hostname",
            "json": "'rtr0.lhr.uk'"
        }, {
            "path": "/system/ntp/config",
            "json": {
                "config": {
                    "enabled": 42
                }
            }
        }])
        ret_msg = PyNMSServerGRPCMethods.service_set_request(
            set_msg, server_ph)

        self.assertEqual(ret_msg.request_id, 42)
        self.assertEqual(ret_msg.response_code, 4)
        self.assertEqual(pynms_rpc_pb2.RPCResponse.Name(ret_msg.response_code),
                         'INVALID_CONFIGURATION')

        self.assertEqual(s.system.config.hostname, '')

        del server_ph
Example #3
0
    def test_002_replace_interfaces(self):
        server_ph = YANGPathHelper()
        s = openconfig_interfaces(path_helper=server_ph)

        logger = logging.getLogger('PyNMSGPRC_OCMessageTests_Interfaces')
        logger.addHandler(logging.NullHandler())

        gi0 = s.interfaces.interface.add("gi0/0/0")
        subint0 = gi0.subinterfaces.subinterface.add(0)
        ip4 = subint0.ipv4.addresses.address.add("192.0.2.1")
        ip4.config.prefix_length = 24

        ocif = openconfig_interfaces()

        gi0 = ocif.interfaces.interface.add("gi0/0/0")
        subint0 = gi0.subinterfaces.subinterface.add(0)
        ip6 = subint0.ipv6.addresses.address.add("2001:db8::1")
        ip6.config.prefix_length = 64

        transaction = [PyNMSConfigOperation(ocif.interfaces, 'REPLACE_CONFIG')]
        set_msg = PyNMSClientGRPCMethods.generate_set_message(transaction)
        ret_msg = PyNMSServerGRPCMethods.service_set_request(set_msg,
                                                             server_ph,
                                                             logger=logger)

        print s.interfaces.get(filter=True)
  def test_007_handle_failed_transaction(self):
    server_ph = YANGPathHelper()
    s = simple_device(path_helper=server_ph)

    set_msg = self._build_invalid_set_message(42, [{"path": "/system/config/hostname", "json": "'rtr0.lhr.uk'"},
                                                   {"path": "/system/ntp/config", "json": {"config": {"enabled": 42}}}])
    ret_msg = PyNMSServerGRPCMethods.service_set_request(set_msg, server_ph)

    self.assertEqual(ret_msg.request_id, 42)
    self.assertEqual(ret_msg.response_code, 4)
    self.assertEqual(pynms_rpc_pb2.RPCResponse.Name(ret_msg.response_code), 'INVALID_CONFIGURATION')

    self.assertEqual(s.system.config.hostname, '')

    del server_ph
  def test_006_handle_scalar_set_operation(self):
    server_ph = YANGPathHelper()
    s = simple_device(path_helper=server_ph)

    c = simple_device()
    c.system.config.hostname = "rtr0.lhr.uk"

    operations = [PyNMSConfigOperation(c.system.config.hostname)]
    set_msg = PyNMSClientGRPCMethods.generate_set_message(operations, request_id=42)
    ret_msg = PyNMSServerGRPCMethods.service_set_request(set_msg, server_ph)

    self.assertEqual(ret_msg.request_id, 42)
    self.assertEqual(ret_msg.response_code, 0)
    self.assertEqual(pynms_rpc_pb2.RPCResponse.Name(ret_msg.response_code), 'OK')
    self.assertEqual(ret_msg.message, "")

    self.assertEqual(s.system.config.hostname, "rtr0.lhr.uk")

    del server_ph
  def test_004_handle_one_set_path(self):
    server_ph = YANGPathHelper()
    s = simple_device(path_helper=server_ph)

    c = simple_device()
    c.system.config.hostname = "rtr0.lhr.uk"
    c.system.config.domain_name = "test.jiveip.net"

    set_msg = PyNMSClientGRPCMethods.generate_set_message([PyNMSConfigOperation(c.system)])
    ret_msg = PyNMSServerGRPCMethods.service_set_request(set_msg, server_ph)

    self.assertEqual(ret_msg.request_id, 0)
    self.assertEqual(ret_msg.response_code, 0)
    self.assertEqual(pynms_rpc_pb2.RPCResponse.Name(ret_msg.response_code), 'OK')
    self.assertEqual(ret_msg.message, "")

    self.assertEqual(s.system.config.hostname, "rtr0.lhr.uk")
    self.assertEqual(s.system.config.domain_name, "test.jiveip.net")

    del server_ph
Example #7
0
    def test_004_handle_one_set_path(self):
        server_ph = YANGPathHelper()
        s = simple_device(path_helper=server_ph)

        c = simple_device()
        c.system.config.hostname = "rtr0.lhr.uk"
        c.system.config.domain_name = "test.jiveip.net"

        set_msg = PyNMSClientGRPCMethods.generate_set_message(
            [PyNMSConfigOperation(c.system)])
        ret_msg = PyNMSServerGRPCMethods.service_set_request(
            set_msg, server_ph)

        self.assertEqual(ret_msg.request_id, 0)
        self.assertEqual(ret_msg.response_code, 0)
        self.assertEqual(pynms_rpc_pb2.RPCResponse.Name(ret_msg.response_code),
                         'OK')
        self.assertEqual(ret_msg.message, "")

        self.assertEqual(s.system.config.hostname, "rtr0.lhr.uk")
        self.assertEqual(s.system.config.domain_name, "test.jiveip.net")

        del server_ph
Example #8
0
  def test_003_delete_interface(self):
    server_ph = YANGPathHelper()
    s = openconfig_interfaces(path_helper=server_ph)

    logger = logging.getLogger('PyNMSGPRC_OCMessageTests_Interfaces')
    logger.addHandler(logging.NullHandler())

    gi0 = s.interfaces.interface.add(u"gi0/0/0")
    subint0 = gi0.subinterfaces.subinterface.add(0)
    ip4 = subint0.ipv4.addresses.address.add(u"192.0.2.1")
    ip4.config.prefix_length = 24

    logger = logging.getLogger('PyNMSGPRC_OCMessageTests_Interfaces')
    logger.addHandler(logging.NullHandler())

    ocif = openconfig_interfaces()
    gi0 = ocif.interfaces.interface.add(u"gi0/0/0")
    transaction = [PyNMSConfigOperation(gi0, 'DELETE_CONFIG')]
    set_msg = PyNMSClientGRPCMethods.generate_set_message(transaction)
    print set_msg
    ret_msg = PyNMSServerGRPCMethods.service_set_request(set_msg, server_ph, logger=logger)

    print s.interfaces.get(filter=True)
Example #9
0
  def test_000_set_interfaces(self):
    server_ph = YANGPathHelper()
    s = openconfig_interfaces(path_helper=server_ph)

    ocif = openconfig_interfaces()

    gi0 = ocif.interfaces.interface.add("gi0/0/0")
    subint0 = gi0.subinterfaces.subinterface.add(0)
    ip4 = subint0.ipv4.addresses.address.add("192.0.2.1")
    ip4.config.prefix_length = 24

    ip6 = subint0.ipv6.addresses.address.add("2001:db8::1")
    ip6.config.prefix_length = 64

    transaction = [PyNMSConfigOperation(ocif.interfaces, 'UPDATE_CONFIG')]
    logger = logging.getLogger('PyNMSGPRC_OCMessageTests_Interfaces')
    logger.addHandler(logging.NullHandler())

    set_msg = PyNMSClientGRPCMethods.generate_set_message(transaction)
    ret_msg = PyNMSServerGRPCMethods.service_set_request(set_msg, server_ph, logger=logger)

    # TODO assertions

    del server_ph
Example #10
0
 def Set(self, request, context):
     self._logger.debug("Got set request: %s" % str(request))
     response_msg = PyNMSServerGRPCMethods.service_set_request(
         request, self._path_helper, logger=self._logger)
     self._logger.debug("SENDING: %s" % response_msg)
     return response_msg
Example #11
0
 def Set(self, request, context):
   self._logger.debug("Got set request: %s" % str(request))
   response_msg = PyNMSServerGRPCMethods.service_set_request(request, self._path_helper, logger=self._logger)
   self._logger.debug("SENDING: %s" % response_msg)
   return response_msg