Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Libbeat test fixes for Python 3 #15726

Conversation

andrewkroh
Copy link
Member

@andrewkroh andrewkroh commented Jan 21, 2020

This has a few fixes to python system tests under libbeat/tests/system.

assert_docs_written_to_alias had an invalid assertion ever since Elasticsearch
changed the format of the hits count to allow for track_total_hits false. Many
tests were using this assertion even when not indexing any events so the hit
count would always be zero so I removed the assertion from those tests.

In other tests I was getting spurious failures because _search was being called
before the index was refreshed to allow the documents to be search able. So I
added an explicit /_refresh to fix the issue.

I changed create_kibana_space to allow a 409 response code so you can run the
tests more than once against a Kibana instance.

I fixed an assertion on the mode bits of a file since the format of octal numbers is
always prefixed with '0o' now.

And I fixed the libbeat keystore tests by encoding the secret string to binary
before calling os.write. This fixed this error:

======================================================================
ERROR: Add a secret to the store using stdin
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/akroh/go/src/github.com/elastic/beats/libbeat/tests/system/test_cmd_keystore.py", line 130, in test_keystore_add_secret_from_stdin
    exit_code = self.add_secret("willnotdelete")
  File "/Users/akroh/go/src/github.com/elastic/beats/libbeat/tests/system/keystore.py", line 29, in add_secret
    os.write(proc.stdin_write, value)
TypeError: a bytes-like object is required, not 'str'

This has a few fixes to python system tests under libbeat/tests/system.

assert_docs_written_to_alias had an invalid assertion ever since Elasticsearch
changed the format of the hits count to allow for track_total_hits false. Many
tests were using this assertion even when not indexing any events so the hit
count would always be zero so I removed the assertion from those tests.

In other tests I was getting spurious failures because _search was being called
before the index was refreshed to allow the documents to be search able. So I
added an explicit /_refresh to fix the issue.

I changed create_kibana_space to allow a 409 response code so you can run the
tests more than once against a Kibana instance.

I fixed an assertion on the mode bits of a file since the format of octal numbers is
always prefixed with '0o' now.

And I fixed the libbeat keystore tests by encoding the secret string to binary
before calling os.write. This fixed this error:

```
======================================================================
ERROR: Add a secret to the store using stdin
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/akroh/go/src/github.com/elastic/beats/libbeat/tests/system/test_cmd_keystore.py", line 130, in test_keystore_add_secret_from_stdin
    exit_code = self.add_secret("willnotdelete")
  File "/Users/akroh/go/src/github.com/elastic/beats/libbeat/tests/system/keystore.py", line 29, in add_secret
    os.write(proc.stdin_write, value)
TypeError: a bytes-like object is required, not 'str'
```
@andrewkroh andrewkroh changed the title Libbeat test fixes Libbeat test fixes for Python 3 Jan 21, 2020


class IdxMgmt(object):
class IdxMgmt(unittest.TestCase):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder why this didn't appear when we run the automatic conversion scripts 🤔

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This wasn't strictly a python3 issue, I wanted to have a more descriptive assertion error by using unittest.assertEqual rather than assert which doesn't provide much in the way of understanding why the assertion failed.

@andrewkroh andrewkroh merged commit 40bac68 into elastic:feature/python3 Jan 23, 2020
leweafan pushed a commit to leweafan/beats that referenced this pull request Apr 28, 2023
This has a few fixes to python system tests under libbeat/tests/system.

assert_docs_written_to_alias had an invalid assertion ever since Elasticsearch
changed the format of the hits count to allow for track_total_hits false. Many
tests were using this assertion even when not indexing any events so the hit
count would always be zero so I removed the assertion from those tests.

In other tests I was getting spurious failures because _search was being called
before the index was refreshed to allow the documents to be search able. So I
added an explicit /_refresh to fix the issue.

I changed create_kibana_space to allow a 409 response code so you can run the
tests more than once against a Kibana instance.

I fixed an assertion on the mode bits of a file since the format of octal numbers is
always prefixed with '0o' now.

And I fixed the libbeat keystore tests by encoding the secret string to binary
before calling os.write. This fixed this error:

```
======================================================================
ERROR: Add a secret to the store using stdin
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/akroh/go/src/github.com/elastic/beats/libbeat/tests/system/test_cmd_keystore.py", line 130, in test_keystore_add_secret_from_stdin
    exit_code = self.add_secret("willnotdelete")
  File "/Users/akroh/go/src/github.com/elastic/beats/libbeat/tests/system/keystore.py", line 29, in add_secret
    os.write(proc.stdin_write, value)
TypeError: a bytes-like object is required, not 'str'
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants