Ejemplo n.º 1
0
    def test_cli_command(self, *args):
        set_module_args(
            dict(commands=["show sys version"],
                 server='localhost',
                 user='******',
                 password='******',
                 transport='cli'))

        module = AnsibleModule(
            argument_spec=self.spec.argument_spec,
            supports_check_mode=self.spec.supports_check_mode)
        mm = ModuleManager(module=module)
        mm._run_commands = Mock(return_value=[])
        mm.execute_on_device = Mock(return_value=[])

        results = mm.exec_module()

        assert results['changed'] is False

        # call count is two on CLI transport because we must first
        # determine if the remote CLI is in tmsh mode or advanced shell
        # (bash) mode.
        #
        # 1 call for the shell check
        # 1 call for the command in the "commands" list above
        #
        # Can we change this in the future by making the terminal plugin
        # find this out ahead of time?
        assert mm._run_commands.call_count == 2
        assert mm.execute_on_device.call_count == 0
Ejemplo n.º 2
0
    def test_command_with_commas(self, *args):
        set_module_args(dict(
            commands="""
              tmsh create /auth ldap system-auth {bind-dn uid=binduser,
              cn=users,dc=domain,dc=com bind-pw $ENCRYPTEDPW check-roles-group
              enabled search-base-dn cn=users,dc=domain,dc=com servers add {
              ldap.server.com } }"
            """,
            server='localhost',
            user='******',
            password='******'
        ))
        module = AnsibleModule(
            argument_spec=self.spec.argument_spec,
            supports_check_mode=self.spec.supports_check_mode
        )
        mm = ModuleManager(module=module)
        mm._run_commands = Mock(return_value=[])
        mm.execute_on_device = Mock(return_value=[])

        results = mm.exec_module()

        assert results['changed'] is True
        assert mm._run_commands.call_count == 0
        assert mm.execute_on_device.call_count == 1
Ejemplo n.º 3
0
 def test_cli_command(self, *args):
     set_module_args(
         dict(commands=["show sys version"],
              server='localhost',
              user='******',
              password='******',
              transport='cli'))
     client = AnsibleF5Client(
         argument_spec=self.spec.argument_spec,
         supports_check_mode=self.spec.supports_check_mode,
         f5_product_name=self.spec.f5_product_name)
     mm = ModuleManager(client)
     mm.exec_module()
     self.assertEqual(self.run_commands.call_count, 1)
     self.assertEqual(self.execute_on_device.call_count, 0)
Ejemplo n.º 4
0
    def test_run_single_modification_command(self, *args):
        set_module_args(
            dict(commands=["tmsh create ltm virtual foo"],
                 server='localhost',
                 user='******',
                 password='******'))

        client = AnsibleF5Client(
            argument_spec=self.spec.argument_spec,
            supports_check_mode=self.spec.supports_check_mode,
            f5_product_name=self.spec.f5_product_name)
        mm = ModuleManager(client)

        results = mm.exec_module()

        assert results['changed'] is True
        self.assertEqual(self.run_commands.call_count, 0)
        self.assertEqual(self.execute_on_device.call_count, 1)
    def test_run_single_command(self, *args):
        set_module_args(
            dict(commands=["tmsh show sys version"],
                 server='localhost',
                 user='******',
                 password='******'))

        client = AnsibleF5Client(
            argument_spec=self.spec.argument_spec,
            supports_check_mode=self.spec.supports_check_mode,
            f5_product_name=self.spec.f5_product_name)
        mm = ModuleManager(client)

        # Override methods to force specific logic in the module to happen
        mm.execute_on_device = Mock(return_value='foo')

        results = mm.exec_module()

        assert results['changed'] is True
Ejemplo n.º 6
0
    def test_run_single_modification_command(self, *args):
        set_module_args(
            dict(commands=["tmsh create ltm virtual foo"],
                 server='localhost',
                 user='******',
                 password='******'))

        module = AnsibleModule(
            argument_spec=self.spec.argument_spec,
            supports_check_mode=self.spec.supports_check_mode)
        mm = ModuleManager(module=module)
        mm._run_commands = Mock(return_value=[])
        mm.execute_on_device = Mock(return_value=[])

        results = mm.exec_module()

        assert results['changed'] is True
        assert mm._run_commands.call_count == 0
        assert mm.execute_on_device.call_count == 1
Ejemplo n.º 7
0
    def test_run_single_command(self, *args):
        set_module_args(
            dict(commands=["tmsh show sys version"],
                 server='localhost',
                 user='******',
                 password='******'))

        client = AnsibleF5Client(
            argument_spec=self.spec.argument_spec,
            supports_check_mode=self.spec.supports_check_mode,
            f5_product_name=self.spec.f5_product_name)
        mm = ModuleManager(client)
        mm._run_commands = Mock(return_value=[])
        mm.execute_on_device = Mock(return_value=[])

        results = mm.exec_module()

        assert results['changed'] is False
        assert mm._run_commands.call_count == 0
        assert mm.execute_on_device.call_count == 1
Ejemplo n.º 8
0
    def test_run_single_command(self, *args):
        set_module_args(dict(
            commands=[
                "tmsh show sys version"
            ],
            server='localhost',
            user='******',
            password='******'
        ))

        client = AnsibleF5Client(
            argument_spec=self.spec.argument_spec,
            supports_check_mode=self.spec.supports_check_mode,
            f5_product_name=self.spec.f5_product_name
        )
        mm = ModuleManager(client)

        # Override methods to force specific logic in the module to happen
        mm.execute_on_device = Mock(return_value='foo')

        results = mm.exec_module()

        assert results['changed'] is True
Ejemplo n.º 9
0
    def test_cli_command(self, *args):
        set_module_args(dict(
            commands=[
                "show sys version"
            ],
            server='localhost',
            user='******',
            password='******',
            transport='cli'
        ))

        module = AnsibleModule(
            argument_spec=self.spec.argument_spec,
            supports_check_mode=self.spec.supports_check_mode
        )
        mm = ModuleManager(module=module)
        mm._run_commands = Mock(return_value=[])
        mm.execute_on_device = Mock(return_value=[])

        results = mm.exec_module()

        assert results['changed'] is False
        assert mm._run_commands.call_count == 1
        assert mm.execute_on_device.call_count == 0