Skip to content

Drop support of *-sk keys in cc_ssh.#1451

Merged
TheRealFalcon merged 2 commits into
canonical:mainfrom
aciba90:cc_ssh_drop_sk_keys_support
May 13, 2022
Merged

Drop support of *-sk keys in cc_ssh.#1451
TheRealFalcon merged 2 commits into
canonical:mainfrom
aciba90:cc_ssh_drop_sk_keys_support

Conversation

@aciba90
Copy link
Copy Markdown
Contributor

@aciba90 aciba90 commented May 13, 2022

  • Delete *-sk keys from cloud-init-schema.json under
    cc_ssh.{ssh_keys,ssh_genkeytypes}
  • Log a warning if some given key is unsupported or unknown.
  • Port tests to Pytests, add some types and increase unittest
    coverage.

Proposed Commit Message

Drop support of *-sk keys in cc_ssh.

- Delete *-sk keys from cloud-init-schema.json under
cc_ssh.{ssh_keys,ssh_genkeytypes}
- Log a warning if some given key is unsupported or unknown.
- Port tests to Pytests, add some types and increase unittest
coverage.

Additional Context

SC-908

After the discussions in #cloud-init we decided to drop the support
of *-sk key types because:

  1. In the autogeneration case, user interaction with the device is needed,
    which does not fit with a cloud-context.
  2. This type of keys are user-based, not hostkeys.

About the integration tests, without the need to support these key types,
I think is sufficient with the existent tests:

Checklist:

  • My code follows the process laid out in the documentation
  • I have updated or added any unit tests accordingly
  • I have updated or added any documentation accordingly

Delete *-sk keys from cloud-init-schema.json under
cc_ssh.{ssh_keys,ssh_genkeytypes}

Log a warning if some given key is unsupported or unknown.

Port tests to Pytests, add some types and increase unittest
coverage.
@aciba90 aciba90 marked this pull request as draft May 13, 2022 09:24
@aciba90 aciba90 marked this pull request as ready for review May 13, 2022 12:14
Copy link
Copy Markdown
Contributor

@TheRealFalcon TheRealFalcon left a comment

Choose a reason for hiding this comment

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

Overall looks good. Really nice test changes, though I have some comments inline.

Comment thread tests/unittests/config/test_cc_ssh.py Outdated
[mock.call(set(keys), "root", options=options)],
m_setup_keys.call_args_list,
cc_ssh.apply_credentials(
keys, user, *args, disable_root_opts, options, **kwargs
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm a little confused about this call. apply_credentials takes 4 arguments: keys, user, disable_root, and disable_root_opts. Why are you passing an *args and **kwargs too?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I started the parametrization without knowing if the number of positional args for cc_ssh.apply_credential was variable along the set of tests. After finishing, I should have checked it. Simplified.

Comment thread tests/unittests/config/test_cc_ssh.py Outdated
args,
kwargs,
):
keys, user, *args, disable_root_opts = args
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why the *args here? I think this call should just be keys, user, disable_root = args

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Same as in r872517535. Simplified.

Comment thread tests/unittests/config/test_cc_ssh.py Outdated
keys = ["key1"]
user = None
@pytest.mark.parametrize(
"args,kwargs",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why kwargs? It's an empty dict in all of these definitions, so we shouldn't need it at all.

Copy link
Copy Markdown
Contributor Author

@aciba90 aciba90 May 13, 2022

Choose a reason for hiding this comment

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

I started parametrizing the tests with args and kwargs to be flexible because I did not know how they would be in subsequent tests, but I forgot to remove the redundant things. Simplified!

@mock.patch(MODPATH + "os.path.exists")
def test_handle_cfg_without_disable_root(
self, m_path_exists, m_nug, m_glob, m_setup_keys
def test_handle_default_root(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nit: I'd rename this to something like test_cfg_disable_root

Comment thread tests/unittests/config/test_cc_ssh.py Outdated
class TestHandleSsh(CiTestCase):
"""Test cc_ssh handling of ssh config."""
@pytest.fixture(scope="function")
def _publish_hostkey_test_setup(tmpdir):
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nit: I don't think we need to preprend local fixtures with an underscore.

Copy link
Copy Markdown
Contributor Author

@aciba90 aciba90 left a comment

Choose a reason for hiding this comment

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

Thank you @TheRealFalcon for pointing out the unneeded flexibility (args, kwargs) and the rest. I have simplified it. Ready to review after the build passes.

Comment thread tests/unittests/config/test_cc_ssh.py Outdated
keys = ["key1"]
user = None
@pytest.mark.parametrize(
"args,kwargs",
Copy link
Copy Markdown
Contributor Author

@aciba90 aciba90 May 13, 2022

Choose a reason for hiding this comment

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

I started parametrizing the tests with args and kwargs to be flexible because I did not know how they would be in subsequent tests, but I forgot to remove the redundant things. Simplified!

Comment thread tests/unittests/config/test_cc_ssh.py Outdated
args,
kwargs,
):
keys, user, *args, disable_root_opts = args
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Same as in r872517535. Simplified.

Comment thread tests/unittests/config/test_cc_ssh.py Outdated
[mock.call(set(keys), "root", options=options)],
m_setup_keys.call_args_list,
cc_ssh.apply_credentials(
keys, user, *args, disable_root_opts, options, **kwargs
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I started the parametrization without knowing if the number of positional args for cc_ssh.apply_credential was variable along the set of tests. After finishing, I should have checked it. Simplified.

Copy link
Copy Markdown
Contributor

@TheRealFalcon TheRealFalcon left a comment

Choose a reason for hiding this comment

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

Thanks!

@TheRealFalcon TheRealFalcon merged commit 2db1c58 into canonical:main May 13, 2022
@aciba90 aciba90 deleted the cc_ssh_drop_sk_keys_support branch May 23, 2022 09:36
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.

2 participants