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

Fix test_ssh_kwargs to not access /etc/salt/pki #61178

Merged
merged 1 commit into from Dec 16, 2021

Conversation

bdrung
Copy link
Contributor

@bdrung bdrung commented Nov 3, 2021

Running the SSH unit tests without root permission fails:

$ python3 -m pytest tests/pytests/unit/client/ssh/test_ssh.py
[...]
Traceback (most recent call last):
  File "salt/client/ssh/__init__.py", line 264, in __init__
    salt.client.ssh.shell.gen_key(priv)
  File "salt/client/ssh/shell.py", line 36, in gen_key
    os.makedirs(os.path.dirname(path))
  File "/usr/lib/python3.9/os.py", line 215, in makedirs
    makedirs(head, exist_ok=exist_ok)
  File "/usr/lib/python3.9/os.py", line 215, in makedirs
    makedirs(head, exist_ok=exist_ok)
  File "/usr/lib/python3.9/os.py", line 225, in makedirs
    mkdir(name, mode)
PermissionError: [Errno 13] Permission denied: '/etc/salt/pki'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "tests/pytests/unit/client/ssh/test_ssh.py", line 134, in test_ssh_kwargs
    ssh_obj = client._prep_ssh(**opts)
  File "salt/client/ssh/client.py", line 125, in _prep_ssh
    return salt.client.ssh.SSH(opts)
  File "salt/client/ssh/__init__.py", line 266, in __init__
    raise salt.exceptions.SaltClientError(
salt.exceptions.SaltClientError: salt-ssh could not be run because it could not generate keys.

Changing the accessed directories to temporary directories would be a solution:

    client.opts["pki_dir"] = tmpdir.join("pki").strpath
    client.opts["cachedir"] = tmpdir.join("cache").strpath

But running the 38 tests takes 130 seconds on an Intel Core i7-8850H CPU @ 2.60GHz. So mock all functions and methods that try to write to the pki or cache directory. Then the tests will succeed in a few seconds.

@bdrung bdrung requested a review from a team as a code owner November 3, 2021 12:59
@bdrung bdrung requested review from MKLeb and removed request for a team November 3, 2021 12:59
MKLeb
MKLeb previously approved these changes Nov 10, 2021
@bdrung
Copy link
Contributor Author

bdrung commented Nov 11, 2021

Just rebased on master.

Running the SSH unit tests without root permission fails:

```
$ python3 -m pytest tests/pytests/unit/client/ssh/test_ssh.py
[...]
Traceback (most recent call last):
  File "salt/client/ssh/__init__.py", line 264, in __init__
    salt.client.ssh.shell.gen_key(priv)
  File "salt/client/ssh/shell.py", line 36, in gen_key
    os.makedirs(os.path.dirname(path))
  File "/usr/lib/python3.9/os.py", line 215, in makedirs
    makedirs(head, exist_ok=exist_ok)
  File "/usr/lib/python3.9/os.py", line 215, in makedirs
    makedirs(head, exist_ok=exist_ok)
  File "/usr/lib/python3.9/os.py", line 225, in makedirs
    mkdir(name, mode)
PermissionError: [Errno 13] Permission denied: '/etc/salt/pki'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "tests/pytests/unit/client/ssh/test_ssh.py", line 134, in test_ssh_kwargs
    ssh_obj = client._prep_ssh(**opts)
  File "salt/client/ssh/client.py", line 125, in _prep_ssh
    return salt.client.ssh.SSH(opts)
  File "salt/client/ssh/__init__.py", line 266, in __init__
    raise salt.exceptions.SaltClientError(
salt.exceptions.SaltClientError: salt-ssh could not be run because it could not generate keys.
```

Changing the accessed directories to temporary directories would be a solution:

```python
    client.opts["pki_dir"] = tmpdir.join("pki").strpath
    client.opts["cachedir"] = tmpdir.join("cache").strpath
```

But running the 38 tests takes 130 seconds on an Intel Core i7-8850H CPU @
2.60GHz. So mock all functions and methods that try to write to the pki or
cache directory. Then the tests will succeed in a few seconds.

Signed-off-by: Benjamin Drung <benjamin.drung@ionos.com>
@bdrung
Copy link
Contributor Author

bdrung commented Dec 11, 2021

Rebased on master.

@Ch3LL Ch3LL merged commit fe9d285 into saltstack:master Dec 16, 2021
@bdrung bdrung deleted the fix-test_ssh_kwargs branch December 17, 2021 08:46
bdrung added a commit to bdrung/salt that referenced this pull request Apr 15, 2022
Running the SSH unit tests without root permission fails:

```
$ python3 -m pytest tests/pytests/unit/client/ssh/test_ssh.py
[...]
Traceback (most recent call last):
  File "salt/client/ssh/__init__.py", line 264, in __init__
    salt.client.ssh.shell.gen_key(priv)
  File "salt/client/ssh/shell.py", line 36, in gen_key
    os.makedirs(os.path.dirname(path))
  File "/usr/lib/python3.9/os.py", line 215, in makedirs
    makedirs(head, exist_ok=exist_ok)
  File "/usr/lib/python3.9/os.py", line 215, in makedirs
    makedirs(head, exist_ok=exist_ok)
  File "/usr/lib/python3.9/os.py", line 225, in makedirs
    mkdir(name, mode)
PermissionError: [Errno 13] Permission denied: '/etc/salt/pki'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "tests/pytests/unit/client/ssh/test_ssh.py", line 134, in test_ssh_kwargs
    ssh_obj = client._prep_ssh(**opts)
  File "salt/client/ssh/client.py", line 125, in _prep_ssh
    return salt.client.ssh.SSH(opts)
  File "salt/client/ssh/__init__.py", line 266, in __init__
    raise salt.exceptions.SaltClientError(
salt.exceptions.SaltClientError: salt-ssh could not be run because it could not generate keys.
```

Changing the accessed directories to temporary directories would be a solution:

```python
    client.opts["pki_dir"] = tmpdir.join("pki").strpath
    client.opts["cachedir"] = tmpdir.join("cache").strpath
```

But running the 38 tests takes 130 seconds on an Intel Core i7-8850H CPU @
2.60GHz. So mock all functions and methods that try to write to the pki or
cache directory. Then the tests will succeed in a few seconds.

Forwarded: saltstack#61178
Signed-off-by: Benjamin Drung <benjamin.drung@ionos.com>
bdrung added a commit to bdrung/salt that referenced this pull request Apr 16, 2022
Running the SSH unit tests without root permission fails:

```
$ python3 -m pytest tests/pytests/unit/client/ssh/test_ssh.py
[...]
Traceback (most recent call last):
  File "salt/client/ssh/__init__.py", line 264, in __init__
    salt.client.ssh.shell.gen_key(priv)
  File "salt/client/ssh/shell.py", line 36, in gen_key
    os.makedirs(os.path.dirname(path))
  File "/usr/lib/python3.9/os.py", line 215, in makedirs
    makedirs(head, exist_ok=exist_ok)
  File "/usr/lib/python3.9/os.py", line 215, in makedirs
    makedirs(head, exist_ok=exist_ok)
  File "/usr/lib/python3.9/os.py", line 225, in makedirs
    mkdir(name, mode)
PermissionError: [Errno 13] Permission denied: '/etc/salt/pki'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "tests/pytests/unit/client/ssh/test_ssh.py", line 134, in test_ssh_kwargs
    ssh_obj = client._prep_ssh(**opts)
  File "salt/client/ssh/client.py", line 125, in _prep_ssh
    return salt.client.ssh.SSH(opts)
  File "salt/client/ssh/__init__.py", line 266, in __init__
    raise salt.exceptions.SaltClientError(
salt.exceptions.SaltClientError: salt-ssh could not be run because it could not generate keys.
```

Changing the accessed directories to temporary directories would be a solution:

```python
    client.opts["pki_dir"] = tmpdir.join("pki").strpath
    client.opts["cachedir"] = tmpdir.join("cache").strpath
```

But running the 38 tests takes 130 seconds on an Intel Core i7-8850H CPU @
2.60GHz. So mock all functions and methods that try to write to the pki or
cache directory. Then the tests will succeed in a few seconds.

Forwarded: saltstack#61178
Signed-off-by: Benjamin Drung <benjamin.drung@ionos.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants