Esempio n. 1
0
    def test_run_expect_with_actionable_error(remote_connection):
        expected_id = 15
        expected_message = 'Some message'

        response = libs_pb2.RunExpectResponse()
        response.error.actionable_error.id = expected_id
        response.error.actionable_error.message = expected_message

        with mock.patch('dlpx.virtualization._engine.libs.run_expect',
                        return_value=response, create=True):
            with pytest.raises(LibraryError) as err_info:
                libs.run_expect(remote_connection, 'command')

        assert err_info.value._id == expected_id
        assert err_info.value.message == expected_message
Esempio n. 2
0
    def test_run_expect_bad_variables(remote_connection):
        command = 'command'
        #
        # Set the value inside the varibles dict to be an int instead of a
        # string.
        #
        variables = {'test0': 'yes', 'test1': 10}

        with pytest.raises(IncorrectArgumentTypeError) as err_info:
            libs.run_expect(remote_connection, command, variables)

        assert err_info.value.message == (
            "The function run_expect's argument 'variables' was"
            " a dict of {type 'str':type 'int', type 'str':type 'str'}"
            " but should be of"
            " type 'dict of basestring:basestring' if defined.")
Esempio n. 3
0
    def test_run_expect_check_true_exitcode_success(remote_connection):
        expected_run_expect_response = libs_pb2.RunPowerShellResponse()
        expected_run_expect_response.return_value.exit_code = 0
        expected_run_expect_response.return_value.stdout = "stdout"
        expected_run_expect_response.return_value.stderr = "stderr"

        expected_command = "command"
        expected_variables = None

        def mock_run_expect(actual_run_expect_request):
            assert actual_run_expect_request.command == expected_command
            assert (actual_run_expect_request.remote_connection.environment.
                    name == remote_connection.environment.name)
            assert (actual_run_expect_request.remote_connection.environment.
                    reference == remote_connection.environment.reference)
            return expected_run_expect_response

        with mock.patch("dlpx.virtualization._engine.libs.run_expect",
                        side_effect=mock_run_expect,
                        create=True):
            actual_run_expect_result = libs.run_expect(remote_connection,
                                                       expected_command,
                                                       expected_variables,
                                                       check=True)

            assert actual_run_expect_result.exit_code == expected_run_expect_response.return_value.exit_code
            assert actual_run_expect_result.stdout == expected_run_expect_response.return_value.stdout
            assert actual_run_expect_result.stderr == expected_run_expect_response.return_value.stderr
Esempio n. 4
0
    def test_run_expect(remote_connection):
        expected_run_expect_response = libs_pb2.RunExpectResponse()
        expected_run_expect_response.return_value.exit_code = 0
        expected_run_expect_response.return_value.stdout = 'stdout'
        expected_run_expect_response.return_value.stderr = 'stderr'

        expected_command = 'command'
        expected_variables = None

        def mock_run_expect(actual_run_expect_request):
            assert actual_run_expect_request.command == expected_command

            actual_environment = (
                actual_run_expect_request.remote_connection.environment)
            assert (
                actual_environment.name == remote_connection.environment.name)
            assert (actual_environment.reference ==
                    remote_connection.environment.reference)
            return expected_run_expect_response

        with mock.patch('dlpx.virtualization._engine.libs.run_expect',
                        side_effect=mock_run_expect,
                        create=True):
            actual_run_expect_result = libs.run_expect(remote_connection,
                                                       expected_command,
                                                       expected_variables)

        expected = expected_run_expect_response.return_value
        assert actual_run_expect_result.exit_code == expected.exit_code
        assert actual_run_expect_result.stdout == expected.stdout
        assert actual_run_expect_result.stderr == expected.stderr
Esempio n. 5
0
    def test_run_expect_check_true_exitcode_failed(remote_connection):
        expected_message = ('The script failed with exit code 1.'
                            ' stdout : stdout and  stderr : stderr')

        response = libs_pb2.RunExpectResponse()
        response.return_value.exit_code = 1
        response.return_value.stdout = "stdout"
        response.return_value.stderr = "stderr"

        with mock.patch("dlpx.virtualization._engine.libs.run_expect",
                        return_value=response,
                        create=True):
            with pytest.raises(PluginScriptError) as info:
                response = libs.run_expect(remote_connection,
                                           "test_command",
                                           check=True)
            assert info.value.message == expected_message