def test_002_handle_get_one_path(self): server_ph = YANGPathHelper() s = simple_device(path_helper=server_ph) s.system.config.hostname = "rtr0.lhr.uk" s.system.config.domain_name = "test.jiveip.net" get_msg = PyNMSClientGRPCMethods.generate_get_message(["/system"], 0) ret_msg = PyNMSServerGRPCMethods.service_get_request(get_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(len(ret_msg.response), 1) self.assertEqual(ret_msg.response[0].path, "/system") err = None try: json_returned = json.loads(ret_msg.response[0].value) except Exception as e: err = e self.assertIsNone(err) self.assertEqual(json_returned, {u'simple-device:ntp': {u'state': {u'enabled': False}, u'config': {u'enabled': False}}, u'simple-device:config': {u'domain-name': u'test.jiveip.net', u'hostname': u'rtr0.lhr.uk'}, u'simple-device:state': {u'domain-name': u'', u'hostname': u''}}) del server_ph
def test_001_get_interfaces(self): server_ph = YANGPathHelper() s = openconfig_interfaces(path_helper=server_ph) 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 ip6 = subint0.ipv6.addresses.address.add(u"2001:db8::1") ip6.config.prefix_length = 64 logger = logging.getLogger('PyNMSGPRC_OCMessageTests_Interfaces') logger.addHandler(logging.NullHandler()) get_msg = PyNMSClientGRPCMethods.generate_get_message(["/interfaces"], 42) ret_msg = PyNMSServerGRPCMethods.service_get_request(get_msg, server_ph, logger=logger) print ret_msg # # TODO: assertions # del server_ph
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_003_handle_get_multiple_paths(self): server_ph = YANGPathHelper() s = simple_device(path_helper=server_ph) s.system.config.hostname = "rtr0.lhr.uk" s.system.config.domain_name = "test.jiveip.net" s.system.ntp.config.enabled = True get_msg = PyNMSClientGRPCMethods.generate_get_message(["/system/config", "/system/config/hostname"], 0) ret_msg = PyNMSServerGRPCMethods.service_get_request(get_msg, server_ph) self.assertEqual(ret_msg.request_id, 0) self.assertEqual(ret_msg.response_code, 0) self.assertEqual(len(ret_msg.response), 2) expected_results = [ ("/system/config", {u'simple-device:hostname': u'rtr0.lhr.uk', u'simple-device:domain-name': u'test.jiveip.net'}), ("/system/config/hostname", u'rtr0.lhr.uk') ] for returned,expected in zip(ret_msg.response, expected_results): self.assertEqual(returned.path, expected[0]) err = None try: json_returned = json.loads(returned.value) except Exception as e: err = e self.assertIsNone(err) self.assertEqual(json_returned, expected[1]) del server_ph
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
def test_003_handle_get_multiple_paths(self): server_ph = YANGPathHelper() s = simple_device(path_helper=server_ph) s.system.config.hostname = "rtr0.lhr.uk" s.system.config.domain_name = "test.jiveip.net" s.system.ntp.config.enabled = True get_msg = PyNMSClientGRPCMethods.generate_get_message( ["/system/config", "/system/config/hostname"], 0) ret_msg = PyNMSServerGRPCMethods.service_get_request( get_msg, server_ph) self.assertEqual(ret_msg.request_id, 0) self.assertEqual(ret_msg.response_code, 0) self.assertEqual(len(ret_msg.response), 2) expected_results = [("/system/config", { u'simple-device:hostname': u'rtr0.lhr.uk', u'simple-device:domain-name': u'test.jiveip.net' }), ("/system/config/hostname", u'rtr0.lhr.uk')] for returned, expected in zip(ret_msg.response, expected_results): self.assertEqual(returned.path, expected[0]) err = None try: json_returned = json.loads(returned.value) except Exception as e: err = e self.assertIsNone(err) self.assertEqual(json_returned, expected[1]) del server_ph
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_002_handle_get_one_path(self): server_ph = YANGPathHelper() s = simple_device(path_helper=server_ph) s.system.config.hostname = "rtr0.lhr.uk" s.system.config.domain_name = "test.jiveip.net" get_msg = PyNMSClientGRPCMethods.generate_get_message(["/system"], 0) ret_msg = PyNMSServerGRPCMethods.service_get_request( get_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(len(ret_msg.response), 1) self.assertEqual(ret_msg.response[0].path, "/system") err = None try: json_returned = json.loads(ret_msg.response[0].value) except Exception as e: err = e self.assertIsNone(err) self.assertEqual( json_returned, { u'simple-device:ntp': { u'state': { u'enabled': False }, u'config': { u'enabled': False } }, u'simple-device:config': { u'domain-name': u'test.jiveip.net', u'hostname': u'rtr0.lhr.uk' }, u'simple-device:state': { u'domain-name': u'', u'hostname': u'' } }) 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
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
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)
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
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
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