Ejemplo n.º 1
0
    def test_remove_vlan_failed(self, send_mock, recv_mock, cb_mock, paramiko_mock):
        request = self.get_request()
        request['driverRequest']['actions'][0]['type'] = 'removeVlan'
        port = '1/1/14'
        vlan = '45'

        emu = CliEmulator([
            [r'^show port {} ethernet$'.format(port),
             '===============================================================================\n'
             'Ethernet Interface'
             '===============================================================================\n'
             'Description        : 10/100/Gig Ethernet SFP\n'
             'Interface          : 1/1/14                     Oper Speed       : N/A\n'
             'Link-level         : Ethernet                   Config Speed     : 1 Gbps\n'
             'Admin State        : down                       Oper Duplex      : N/A\n'
             'Oper State         : down                       Config Duplex    : full\n'
             'Physical Link      : No                         MTU              : 9212\n'
             'Single Fiber Mode  : No                         LoopBack Mode    : None\n'
             'Single Fiber Mode  :                            Decommissioned   : No\n'
             'IfIndex            : 36110336                   Hold time up     : 0 seconds\n'
             'Last State Change  : 02/20/2018 03:16:56        Hold time down   : 0 seconds\n'
             'Last Cleared Time  : N/A                        DDM Events       : Enabled\n'
             'Phys State Chng Cnt: 0'
             'Configured Mode    : hybrid                     Encap Type       : 802.1q\n'
             'Dot1Q Ethertype    : 0x8100                     QinQ Ethertype   : 0x8100\n'
             'PBB Ethertype      : 0x88e7\n'
             '{}'.format(DEFAULT_PROMPT),
             1],
            [r'^show router interface$',
             ['===============================================================================\n'
              'Interface Table (Router: Base)\n'
              '===============================================================================\n'
              'Interface-Name                   Adm         Opr(v4/v6)  Mode    Port/SapId\n'
              'IP-Address                                                    PfxState\n'
              '-------------------------------------------------------------------------------\n'
              'Loopback 0                       Up          Up/Down     Network loopback\n'
              '192.168.1.1/32                                               n/a\n'
              'p1/1/14:101.*                            Up          Down/Down   Network {0}:{1}.*\n'
              '-                                                             -\n'
              'p{0}:{1}                            Up          Down/Down   Network {0}:{1}\n'
              '-                                                             -\n'
              '-------------------------------------------------------------------------------\n'
              'Interfaces : 3\n'
              '===============================================================================\n'
              '*{2}'.format(port, vlan, DEFAULT_PROMPT)],
             1],
            [r'^configure router interface p{}:45 shutdown$'.format(port),
             '*{}'.format(DEFAULT_PROMPT),
             1],
            [r'^configure router no interface p{}:45$'.format(port),
             '*{}'.format(DEFAULT_PROMPT),
             1],
        ])
        send_mock.side_effect = emu.send_line
        recv_mock.side_effect = emu.receive_all

        resp = self.runner.apply_connectivity_changes(jsonpickle.encode(request))
        self.assertFalse(jsonpickle.decode(resp)['driverResponse']['actionResults'][0]['success'])

        emu.check_calls()
    def test_not_disabled_snmp_v2(self, send_mock, recv_mock, cb_mock,
                                  paramiko_mock, quali_snmp, autoload):
        self._setUp({
            'Enable SNMP': 'False',
            'Disable SNMP': 'True',
        })

        emu = CliEmulator(
            [[
                r'^configure system security snmp community \t$',
                '<community-string>\n'
                '"community1" "community2"\t"community3" "public"\n'
                '{0} configure system security snmp community\n'
                '                                                        ^\n'
                'Error: Missing parameter\n'
                '{0}'.format(DEFAULT_PROMPT), 1
            ],
             [
                 r'^configure system security snmp no community public',
                 '*{}'.format(DEFAULT_PROMPT), 1
             ]])
        send_mock.side_effect = emu.send_line
        recv_mock.side_effect = emu.receive_all

        self.assertRaises(Exception, self.runner.discover)

        emu.check_calls()
    def test_already_enabled_snmp_v2(self, send_mock, recv_mock, cb_mock,
                                     paramiko_mock, quali_snmp, autoload):
        self._setUp()

        emu = CliEmulator([
            [
                r'^configure system snmp no shutdown$',
                '{}'.format(DEFAULT_PROMPT), 1
            ],
            [
                r'^configure system security snmp community \t$',
                [
                    '<community-string>\n'
                    '"community1" "community2"\t"community3" "public"\n'
                    '{0} configure system security snmp community\n'
                    '                                                        ^\n'
                    'Error: Missing parameter\n'
                    '{0}'.format(DEFAULT_PROMPT)
                ], 1
            ],
        ])
        send_mock.side_effect = emu.send_line
        recv_mock.side_effect = emu.receive_all

        self.runner.discover()

        emu.check_calls()
    def test_restore_startup_override_without_additional_files(self, send_mock, recv_mock):
        ftp = 'ftp://test.url'
        file_name = 'Alcatel-startup-200218-133900'
        emu = CliEmulator([
            [r'^show bof$',
             '{0} show bof\n'
             '===============================================================================\n'
             'BOF (Memory)\n'
             '===============================================================================\n'
             'primary-image      cf1:/images/TiMOS-8.0.R4\n'
             'primary-config     cf1:/config.cfg\n'
             '===============================================================================\n'
             '{0}'''.format(DEFAULT_PROMPT),
             1],
            [r'^file copy {0}/{1} cf1:/{1}$'.format(ftp, file_name),
             'Copying file cf1:\{} ... OK\n1 file copied.\n{}'.format(file_name, DEFAULT_PROMPT),
             1],
            [r'^file copy {0}/{1}\.sdx cf1:/{1}\.sdx$'.format(ftp, file_name),
             Exception('Copy failed.'),
             1],
            [r'^bof primary-config cf1:/{}$'.format(file_name),
             '{}'.format(DEFAULT_PROMPT),
             1],
            ['^bof save$',
             'Writing BOF to cf1:/bof.cfg ... OK\nCompleted.\n{}'.format(DEFAULT_PROMPT),
             1],
        ])
        recv_mock.side_effect = emu.receive_all
        send_mock.side_effect = emu.send_line

        path = '{}/{}'.format(ftp, file_name)
        self.runner.restore(path, 'startup', 'override')

        emu.check_calls()
Ejemplo n.º 5
0
    def test_without_port_name(self, send_mock, recv_mock, cb_mock, paramiko_mock):
        request = self.get_request()
        request['driverRequest']['actions'][0]['actionTarget']['fullName'] = ''

        emu = CliEmulator()
        send_mock.side_effect = emu.send_line
        recv_mock.side_effect = emu.receive_all

        resp = self.runner.apply_connectivity_changes(jsonpickle.encode(request))
        self.assertFalse(jsonpickle.decode(resp)['driverResponse']['actionResults'][0]['success'])

        emu.check_calls()
Ejemplo n.º 6
0
    def test_add_vlan_range(self, send_mock, recv_mock, cb_mock, paramiko_mock):
        request = self.get_request()
        request['driverRequest']['actions'][0]['connectionParams']['vlanId'] = '10-12'

        emu = CliEmulator()
        send_mock.side_effect = emu.send_line
        recv_mock.side_effect = emu.receive_all

        resp = self.runner.apply_connectivity_changes(jsonpickle.encode(request))
        self.assertFalse(jsonpickle.decode(resp)['driverResponse']['actionResults'][0]['success'])

        emu.check_calls()
    def test_load_firmware_to_cf3(self, send_mock, recv_mock):
        ftp = 'ftp://test.url'
        file_name = 'both.tim'
        file_system = 'cf3:\\'

        emu = CliEmulator([
            [
                '^show system information$', '{0} show system information\n\n'
                '===============================================================================\n'
                'System Information\n'
                '===============================================================================\n'
                'System Name            : test\n'
                'System Type            : 7210 SAS-M-1\n'
                'System Version         : B-8.0.R4\n\n'
                'BOF Source             : cf3:\n'
                'Image Source           : primary\n'
                'Config Source          : primary\n'
                'Last Booted Config File: cf3:\\config.cfg\n'
                '{0}'
                ''.format(DEFAULT_PROMPT), 1
            ],
            [
                r'^file copy {0}/{1} {2}{1}$'.format(
                    *map(re.escape, (ftp, file_name, file_system))),
                'Copying file cf3:\\config.cfg ... OK\n1 file copied.\n{}'.
                format(DEFAULT_PROMPT), 1
            ],
            [
                r'^bof primary-image {}{}$'.format(
                    *map(re.escape, (file_system, file_name))),
                '{}'.format(DEFAULT_PROMPT), 1
            ],
            [
                r'^bof save$',
                'Writing BOF to cf3:/bof.cfg ... OK\nCompleted.\n{}'.format(
                    DEFAULT_PROMPT), 1
            ],
            [
                r'^admin reboot upgrade now$',
                [Exception(), '{}'.format(DEFAULT_PROMPT)], 2
            ],  # it called one time, but next time doesn't called send_line command
        ])
        send_mock.side_effect = emu.send_line
        recv_mock.side_effect = emu.receive_all

        path = '{}/{}'.format(ftp, file_name)
        self.runner.load_firmware(path)

        emu.check_calls()
Ejemplo n.º 8
0
    def test_save_running(self, send_mock, recv_mock, cb_mock, paramiko_mock):
        ftp = 'ftp://test.url'
        file_pattern = r'Alcatel-running-\d+-\d+'
        emu = CliEmulator([
            [
                r'^admin save {}/{}$'.format(ftp, file_pattern),
                'Completed.\n{}'.format(DEFAULT_PROMPT), 1
            ],
        ])
        recv_mock.side_effect = emu.receive_all
        send_mock.side_effect = emu.send_line

        self.runner.save(ftp, 'running')

        emu.check_calls()
Ejemplo n.º 9
0
    def test_save_to_default_location(self, send_mock, recv_mock, cb_mock,
                                      paramiko_mock):
        file_pattern = r'Alcatel-running-\d+-\d+'
        emu = CliEmulator([
            [
                r'^admin save {}//folder/{}'.format(self.runner.file_system,
                                                    file_pattern),
                'Completed.\n{}'.format(DEFAULT_PROMPT), 1
            ],
        ])
        recv_mock.side_effect = emu.receive_all
        send_mock.side_effect = emu.send_line

        self.runner.save(configuration_type='running')

        emu.check_calls()
Ejemplo n.º 10
0
    def test_enable_vlan_failed(self, send_mock, recv_mock, cb_mock, paramiko_mock):
        request = self.get_request()
        port = '1/1/14'
        vlan = '45'

        emu = CliEmulator([
            [r'^configure port {} shutdown$'.format(port),
             '*{}'.format(DEFAULT_PROMPT),
             1],
            [r'^configure port {} ethernet mode network$'.format(port),
             '*{}'.format(DEFAULT_PROMPT),
             1],
            [r'^configure port {} ethernet encap-type dot1q$'.format(port),
             '*{}'.format(DEFAULT_PROMPT),
             1],
            [r'^configure port {} no shutdown$'.format(port),
             '*{}'.format(DEFAULT_PROMPT),
             1],
            [r'^show router interface$',
             '===============================================================================\n'
             'Interface Table (Router: Base)\n'
             '===============================================================================\n'
             'Interface-Name                   Adm         Opr(v4/v6)  Mode    Port/SapId\n'
             'IP-Address                                                    PfxState\n'
             '-------------------------------------------------------------------------------\n'
             'Loopback 0                       Up          Up/Down     Network loopback\n'
             '192.168.1.1/32                                               n/a\n'
             'p1/1/13:100                             Up        Down/Down   Network 1/1/13:100.*\n'
             '-                                                             -\n'
             '-------------------------------------------------------------------------------\n'
             'Interfaces : 2\n'
             '===============================================================================\n'
             '*{}'.format(DEFAULT_PROMPT),
             2],
            [r'^configure router interface p{0}:{1} port {0}:{1}$'.format(port, vlan),
             '*{}'.format(DEFAULT_PROMPT),
             1],
        ])
        send_mock.side_effect = emu.send_line
        recv_mock.side_effect = emu.receive_all

        resp = self.runner.apply_connectivity_changes(jsonpickle.encode(request))
        self.assertFalse(jsonpickle.decode(resp)['driverResponse']['actionResults'][0]['success'])

        emu.check_calls()
Ejemplo n.º 11
0
    def test_save_startup(self, send_mock, recv_mock, cb_mock, paramiko_mock):
        ftp = 'ftp://test.url'
        file_pattern = r'Alcatel-startup-\d+-\d+'
        emu = CliEmulator([
            [
                '^show system information$', '{0} show system information\n\n'
                '===============================================================================\n'
                'System Information\n'
                '===============================================================================\n'
                'System Name            : test\n'
                'System Type            : 7210 SAS-M-1\n'
                'System Version         : B-8.0.R4\n\n'
                'BOF Source             : cf1:\n'
                'Image Source           : primary\n'
                'Config Source          : primary\n'
                'Last Booted Config File: cf1:\config.cfg\n'
                '{0}'
                ''.format(DEFAULT_PROMPT), 1
            ],
            [
                r'^file copy cf1:\\config.cfg {}/{}$'.format(
                    ftp, file_pattern),
                'Copying file cf1:\config.cfg ... OK\n1 file copied.\n{}'.
                format(DEFAULT_PROMPT), 1
            ],
            [
                r'^file copy cf1:\\config\.sdx {}/{}\.sdx$'.format(
                    ftp, file_pattern),
                'Copying file cf1:\config.cfg ... OK\n1 file copied.\n{}'.
                format(DEFAULT_PROMPT), 1
            ],
            [
                r'^file copy cf1:\\config\.ndx {}/{}\.ndx$'.format(
                    ftp, file_pattern),
                'Copying file cf1:\config.cfg ... OK\n1 file copied.\n{}'.
                format(DEFAULT_PROMPT), 1
            ],
        ])
        recv_mock.side_effect = emu.receive_all
        send_mock.side_effect = emu.send_line

        self.runner.save(ftp, 'startup')

        emu.check_calls()
    def test_restore_running_override(self, send_mock, recv_mock, cb_mock, paramiko_mock):
        ftp = 'ftp://test.url'
        file_name = 'Alcatel-startup-200218-133900'
        emu = CliEmulator([
            [r'^show bof$',
             '''{0} show bof\n
             ===============================================================================\n
             BOF (Memory)\n
             ===============================================================================\n
             primary-image      cf1:/images/TiMOS-8.0.R4\n
             primary-config     cf1:/config.cfg\n
             ===============================================================================\n
             {0}'''.format(DEFAULT_PROMPT),
             1],
            [r'^file copy {0}/{1} cf1:/{1}$'.format(ftp, file_name),
             'Copying file cf1:\{} ... OK\n1 file copied.\n{}'.format(file_name, DEFAULT_PROMPT),
             1],
            [r'^file copy {0}/{1}\.sdx cf1:/{1}\.sdx$'.format(ftp, file_name),
             'Copying file cf1:\{}.sdx ... OK\n1 file copied.\n{}'.format(file_name, DEFAULT_PROMPT),
             1],
            [r'^file copy {0}/{1}\.ndx cf1:/{1}\.ndx$'.format(ftp, file_name),
             'Copying file cf1:\{}.ndx ... OK\n1 file copied.\n{}'.format(file_name, DEFAULT_PROMPT),
             1],
            [r'^bof primary-config cf1:/{}$'.format(file_name),
             '{}'.format(DEFAULT_PROMPT),
             1],
            [r'^bof primary-config cf1:/config.cfg$',
             '{}'.format(DEFAULT_PROMPT),
             1],
            ['^bof save$',
             'Writing BOF to cf1:/bof.cfg ... OK\nCompleted.\n{}'.format(DEFAULT_PROMPT),
             2],
            ['^admin reboot now$',
             [Exception(),
              '{}'.format(DEFAULT_PROMPT)],
             2],  # it called one time, but next time doesn't called the send_line command
        ])
        recv_mock.side_effect = emu.receive_all
        send_mock.side_effect = emu.send_line

        path = '{}/{}'.format(ftp, file_name)
        self.runner.restore(path, 'running', 'override')

        emu.check_calls()
    def test_enable_snmp_v2_with_enable_admin(self, send_mock, recv_mock):
        self._setUp()

        emu = CliEmulator()

        for action in emu.actions:
            if action[0] == '^enable-admin$':
                action[1] = 'Password:'******'^configure system snmp no shutdown$',
                '{}'.format(DEFAULT_PROMPT), 1
            ],
            [
                r'^configure system security snmp community \t$',
                [
                    '<community-string>\n'
                    '"community1" "community2"\t"community3"\n'
                    '{0} configure system security snmp community\n'
                    '                                                        ^\n'
                    'Error: Missing parameter\n'
                    '{0}'.format(DEFAULT_PROMPT), '<community-string>\n'
                    '"community1" "community2"\t"community3" "public"\n'
                    '{0} configure system security snmp community\n'
                    '                                                        ^\n'
                    'Error: Missing parameter\n'
                    '{0}'.format(DEFAULT_PROMPT)
                ], 2
            ],
            [
                r'^configure system security snmp community public r version v2c$',
                '*{}'.format(DEFAULT_PROMPT), 1
            ]
        ])
        send_mock.side_effect = emu.send_line
        recv_mock.side_effect = emu.receive_all

        self.runner.discover()

        emu.check_calls()
Ejemplo n.º 14
0
    def test_save_copy_addition_files_raise_not_known_error(
            self, send_mock, recv_mock):
        ftp = 'ftp://test.url'
        file_pattern = r'Alcatel-startup-\d+-\d+'
        emu = CliEmulator([
            [
                '^show system information$', '{0} show system information\n\n'
                '===============================================================================\n'
                'System Information\n'
                '===============================================================================\n'
                'System Name            : test\n'
                'System Type            : 7210 SAS-M-1\n'
                'System Version         : B-8.0.R4\n\n'
                'BOF Source             : cf1:\n'
                'Image Source           : primary\n'
                'Config Source          : primary\n'
                'Last Booted Config File: cf1:\\config.cfg\n'
                '{0}'
                ''.format(DEFAULT_PROMPT), 1
            ],
            [
                r'^file copy cf1:\\config.cfg {}/{}$'.format(
                    ftp, file_pattern),
                'Copying file cf1:\\config.cfg ... OK\n1 file copied.\n{}'.
                format(DEFAULT_PROMPT), 1
            ],
            [
                r'^file copy cf1:\\config\.sdx {}/{}\.sdx$'.format(
                    ftp, file_pattern),
                Exception('Don\'t known exception'), 1
            ],
        ])
        recv_mock.side_effect = emu.receive_all
        send_mock.side_effect = emu.send_line

        with self.assertRaisesRegexp(Exception, 'Don\'t known exception'):
            self.runner.save(ftp, 'startup')

        emu.check_calls()
Ejemplo n.º 15
0
    def test_enable_vlan_trunk_qinq(self, send_mock, recv_mock, cb_mock, paramiko_mock):
        request = self.get_request()
        request['driverRequest']['actions'][0]['connectionParams']['mode'] = 'Trunk'
        request['driverRequest']['actions'][0]['connectionParams']['vlanServiceAttributes'][0][
            'attributeValue'] = 'True'
        port = '1/1/14'
        vlan = '45'

        emu = CliEmulator([
            [r'^configure port {} shutdown$'.format(port),
             '*{}'.format(DEFAULT_PROMPT),
             1],
            [r'^configure port {} ethernet mode hybrid'.format(port),
             '*{}'.format(DEFAULT_PROMPT),
             1],
            [r'^configure port {} ethernet encap-type qinq'.format(port),
             '*{}'.format(DEFAULT_PROMPT),
             1],
            [r'^configure port {} no shutdown$'.format(port),
             '*{}'.format(DEFAULT_PROMPT),
             1],
            [r'^show router interface$',
             ['===============================================================================\n'
              'Interface Table (Router: Base)\n'
              '===============================================================================\n'
              'Interface-Name                   Adm         Opr(v4/v6)  Mode    Port/SapId\n'
              'IP-Address                                                    PfxState\n'
              '-------------------------------------------------------------------------------\n'
              'Loopback 0                       Up          Up/Down     Network loopback\n'
              '192.168.1.1/32                                               n/a\n'
              'p1/1/13:100                             Up        Down/Down   Network 1/1/13:100.*\n'
              '-                                                             -\n'
              '-------------------------------------------------------------------------------\n'
              'Interfaces : 2\n'
              '===============================================================================\n'
              '*{}'.format(DEFAULT_PROMPT),

              '===============================================================================\n'
              'Interface Table (Router: Base)\n'
              '===============================================================================\n'
              'Interface-Name                   Adm         Opr(v4/v6)  Mode    Port/SapId\n'
              'IP-Address                                                    PfxState\n'
              '-------------------------------------------------------------------------------\n'
              'Loopback 0                       Up          Up/Down     Network loopback\n'
              '192.168.1.1/32                                               n/a\n'
              'p1/1/13:100                             Up        Down/Down   Network 1/1/13:100.*\n'
              '-                                                             -\n'
              'p{0}:{1}.*                             Up          Down/Down   Network {0}:{1}.*\n'
              '-                                                             -\n'
              '-------------------------------------------------------------------------------\n'
              'Interfaces : 3\n'
              '===============================================================================\n'
              '*{2}'.format(port, vlan, DEFAULT_PROMPT)],
             2],
            [r'^configure router interface p{0}:{1}\.\* port {0}:{1}\.\*$'.format(port, vlan),
             '*{}'.format(DEFAULT_PROMPT),
             1],
        ])
        send_mock.side_effect = emu.send_line
        recv_mock.side_effect = emu.receive_all

        resp = self.runner.apply_connectivity_changes(jsonpickle.encode(request))
        self.assertTrue(jsonpickle.decode(resp)['driverResponse']['actionResults'][0]['success'])

        emu.check_calls()