Beispiel #1
0
    def test_call_close_success(self, mock_device):
        """
        test_call_close_success - Test if the plugin junos plugin close a connection with the expected asserts
        """

        # Mocking
        mock_device.connected = False
        plugin = JUNOS(equipment_access=self.mock_equipment_access)
        plugin.remote_conn = mock_device

        # Close to a real test:
        close_response = plugin.close()

        # Asserts
        plugin.remote_conn.close.assert_called_once_with()
        self.assertTrue(close_response, True)
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()))