Exemplo n.º 1
0
 def test_pause_on(self):
     """Check if pause 2 seconds operates correctly."""
     self.format['pause'] = 2
     yangexec.netconf_send = netconf_send
     n1 = time()
     log.info('Pausing 2 seconds before edit-config and 2 seconds after get-config')
     yangexec.run_netconf(
         'edit-config',
         self.device,
         None,  # steps
         {},  # datastore
         self.rpc_data,
         self.returns[0],
         format=self.format
     )
     self.assertGreater(time() - n1, 3)
Exemplo n.º 2
0
 def test_auto_validate_on(self):
     """Check if auto_validate True will try validation."""
     yangexec.netconf_send = netconf_send
     result = yangexec.run_netconf(
         'edit-config',
         self.device,
         None,  # steps
         {},  # datastore
         self.rpc_data,
         self.returns[0],
         format=self.format)
     self.assertFalse(result)
Exemplo n.º 3
0
 def test_get_negative_test_on(self):
     """Check if GET test will pass with failure."""
     self.format['negative_test'] = True
     yangexec.netconf_send = netconf_send
     result = yangexec.run_netconf(
         'get',
         self.device,
         None,  # steps
         {},  # datastore
         self.rpc_data,
         self.returns,
         format=self.format)
     self.assertTrue(result)
Exemplo n.º 4
0
 def test_auto_validate_off(self):
     """Check if auto_validate False does not try validation."""
     self.format['auto_validate'] = False
     yangexec.netconf_send = netconf_send
     result = yangexec.run_netconf(
         'edit-config',
         self.device,
         None,  # steps
         {},  # datastore
         self.rpc_data,
         self.returns[0],
         format=self.format
     )
     self.assertTrue(result)
Exemplo n.º 5
0
 def test_custom_rpc_bad_xml(self):
     """Send invalid custom RPC and make sure it fails."""
     self.rpc_data['operation'] = 'rpc'
     self.rpc_data['rpc'] = '<top><next>odusrej></next></top>'
     yangexec.netconf_send = netconf_send
     result = yangexec.run_netconf(
         'edit-config',
         self.device,
         None,  # steps
         {},  # datastore
         self.rpc_data,
         self.returns[0],
         format=self.format)
     self.assertFalse(result)
    def test_run_netconf_subscribe_raw(self, netconf_send_mock):
        """ Test run_netconf subscribe action with string rpc."""
        operation = 'subscribe'
        steps = "STEP 1: Starting action yang on device 'CSR1K-5'"
        datastore = {'lock': False, 'retry': 10, 'type': ''}
        returns = [{
            'id':
            1,
            'name':
            'address',
            'op':
            '==',
            'selected':
            True,
            'datatype':
            'string',
            'value':
            '10.24.69.26',
            'xpath':
            '/notification/push-update/datastore-contents-xml/mdt-oper-data/mdt-subscriptions/mdt-receivers/address'
        }, {
            'id':
            2,
            'name':
            'port',
            'op':
            'range',
            'selected':
            True,
            'datatype':
            'uint16',
            'value':
            '50000 - 60000',
            'xpath':
            '/notification/push-update/datastore-contents-xml/mdt-oper-data/mdt-subscriptions/mdt-receivers/port'
        }, {
            'id':
            3,
            'name':
            'protocol',
            'op':
            '==',
            'selected':
            True,
            'datatype':
            'string',
            'value':
            'netconf',
            'xpath':
            '/notification/push-update/datastore-contents-xml/mdt-oper-data/mdt-subscriptions/mdt-receivers/protocol'
        }, {
            'id':
            4,
            'name':
            'state',
            'op':
            '==',
            'selected':
            True,
            'datatype':
            'string',
            'value':
            'rcvr-state-connected',
            'xpath':
            '/notification/push-update/datastore-contents-xml/mdt-oper-data/mdt-subscriptions/mdt-receivers/state'
        }]
        format = {
            'request_mode': 'STREAM',
            'sub_mode': 'ON_CHANGE',
            'encoding': 'JSON',
            'sample_interval': 5,
            'stream_max': 15
        }

        rpc_data = {
            'operation':
            'subscribe',
            'rpc':
            """<rpc xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="101">
                    <establish-subscription xmlns="urn:ietf:params:xml:ns:yang:ietf-event-notifications">
                        <stream xmlns:yp="urn:ietf:params:xml:ns:yang:ietf-yang-push">yp:yang-push</stream>
                        <xpath-filter xmlns="urn:ietf:params:xml:ns:yang:ietf-yang-push">/mdt-oper:mdt-oper-data/mdt-subscriptions</xpath-filter>
                        <period xmlns="urn:ietf:params:xml:ns:yang:ietf-yang-push">1000</period>
                    </establish-subscription>
                </rpc>
            """
        }
        netconf_send_mock.return_value = [
            ('subscribe', '''<?xml version="1.0" encoding="UTF-8"?>\n
            <rpc-reply xmlns="urn:ietf:params:xml:ns:netconf:
            base:1.0" message-id="urn:uuid:60a40a42-987d-4159-
            89d6-c67252b20f42" xmlns:nc="urn:ietf:params:xml:
            ns:netconf:base:1.0"><subscription-result xmlns=\'
            urn:ietf:params:xml:ns:yang:ietf-event-notificati
            ons\' xmlns:notif-bis="urn:ietf:params:xml:ns:yang:
            ietf-event-notifications">notif-bis:ok</subscription
            -result>\n<subscription-id xmlns=\'urn:ietf:params:
            xml:ns:yang:ietf-event-notifications\'>2147483760
            </subscription-id>\n</rpc-reply>\'''')
        ]
        result = run_netconf(
            operation,  # operation
            self.netconf_device,  # device
            steps,  # steps
            datastore,  # datastore
            rpc_data,  # rpc_data
            returns,  # returns
            format=format  # format
        )

        self.assertEqual(result, True)