Пример #1
0
    def test_call_ensure_privilege_level_success(self, mock_start_shell):
        """
        test_call_ensure_privilege_level_success

        Note: The shell run function expects an array as a return value,
        and ensure_privilege_level() parse it to ensure the privilege.
        """

        mock_start_shell.return_value.run.return_value = [
            False,
            u'cli -c "show cli authorization"\r\r\nCurrent user: \'root        \' class \'super-user\'\r'
        ]

        plugin = JUNOS(equipment_access=self.mock_equipment_access)

        # Mock connection
        plugin.remote_conn = MagicMock()
        plugin.remote_conn.connected.return_value = True

        result = plugin.ensure_privilege_level()
        self.assertTrue(result)
Пример #2
0
 def test_call_ensure_privilege_level_fail(self):
     plugin = JUNOS(equipment_access=self.mock_equipment_access)
     with self.assertRaises(Exception):
         plugin.ensure_privilege_level()
log = logging.getLogger(__name__)
log_test_prefix = '[Junos Plugin]'
log.debug('%s Start sample' % log_test_prefix)

# Requirements (args, equipment and plugin)
host = 'HOSTNAME_OR_IP'
user = '******'
password = '******'

# Temporary equipment access object (defined above as EquipamentoAcesso)
equipment_access = EquipamentoAcesso(host, user, password)

# NetworkAPI junos plugin object
equip_plugin = JUNOS(equipment_access=equipment_access)
""" OPEN CONNECTION """
print("Open connection {}...".format(host))
print("Connection result: {}".format(equip_plugin.connect()))
""" CHECK PRIVILEGES """
print("Check privilege {}...".format(host))
print("Privilege result: {}".format(equip_plugin.ensure_privilege_level()))
""" EXECUTE CONFIGURATION """
print("Execute configuration file {}...".format(host))
# equip_plugin.exec_command(command='set interfaces gr-0/0/0 description "Some description teste3 for gr-0/0/0 at "')
print("Execute configuration result: {}".format(
    equip_plugin.copyScriptFileToConfig(
        filename="networkapi/plugins/Juniper/JUNOS/samples/sample_command.txt")
))
""" CLOSE CONNECTION """
print("Close connection {}...".format(host))
print("Close connection result: {}".format(equip_plugin.close()))