def test_init_ssh_exits_keys_yes_to_all_confirm(self, mock_invoke, mock_start_service, mock_exists, mock_confirm, mock_rmfile, mock_status, mock_append): mock_exists.return_value = True bootstrap._context = mock.Mock(yes_to_all=True, no_overwrite_sshkey=False) mock_confirm.return_value = True bootstrap.init_ssh() mock_start_service.assert_called_once_with("sshd.service") mock_invoke.assert_has_calls([ mock.call("mkdir -m 700 -p /root/.ssh"), mock.call( "ssh-keygen -q -f /root/.ssh/id_rsa -C 'Cluster Internal' -N ''" ) ]) mock_exists.assert_called_once_with("/root/.ssh/id_rsa") mock_confirm.assert_called_once_with( "/root/.ssh/id_rsa already exists - overwrite?") mock_rmfile.assert_called_once_with("/root/.ssh/id_rsa") mock_status.assert_called_once_with("Generating SSH key") mock_append.assert_called_once_with("/root/.ssh/id_rsa.pub", "/root/.ssh/authorized_keys")
def test_init_ssh_no_overwrite(self, mock_start, mock_exists, mock_confirm): mock_exists.return_value = True mock_confirm.return_value = False bootstrap.init_ssh() mock_start.assert_called_once_with("sshd.service") mock_exists.assert_called_once_with(SSH_KEY_CRMSH) mock_confirm.assert_called_once_with( "{} already exists - overwrite?".format(SSH_KEY_CRMSH))
def test_init_ssh_exits_keys_no_overwrite(self, mock_invoke, mock_start_service, mock_exists, mock_confirm, mock_rmfile): mock_exists.return_value = True bootstrap._context = mock.Mock(yes_to_all=True, no_overwrite_sshkey=True) bootstrap.init_ssh() mock_start_service.assert_called_once_with("sshd.service") mock_invoke.assert_called_once_with("mkdir -m 700 -p /root/.ssh") mock_exists.assert_called_once_with("/root/.ssh/id_rsa") mock_confirm.assert_not_called() mock_rmfile.assert_not_called()
def test_init_ssh_no_exist_keys(self, mock_invoke, mock_start_service, mock_exists, mock_status, mock_append): mock_exists.return_value = False bootstrap.init_ssh() mock_start_service.assert_called_once_with("sshd.service") mock_invoke.assert_has_calls([ mock.call("mkdir -m 700 -p /root/.ssh"), mock.call( "ssh-keygen -q -f /root/.ssh/id_rsa -C 'Cluster Internal' -N ''" ) ]) mock_exists.assert_called_once_with("/root/.ssh/id_rsa") mock_status.assert_called_once_with("Generating SSH key") mock_append.assert_called_once_with("/root/.ssh/id_rsa.pub", "/root/.ssh/authorized_keys")
def test_init_ssh_overwrite(self, mock_start, mock_exists, mock_confirm, mock_rmfile, mock_invoke, mock_append): mock_exists.return_value = True mock_confirm.return_value = True bootstrap.init_ssh() mock_start.assert_called_once_with("sshd.service") mock_exists.assert_called_once_with(SSH_KEY_CRMSH) mock_confirm.assert_called_once_with( "{} already exists - overwrite?".format(SSH_KEY_CRMSH)) mock_rmfile.assert_called_once_with(SSH_KEY_CRMSH) mock_invoke.assert_has_calls([ mock.call("sed -i '/{}/d' /root/.ssh/authorized_keys".format( SSH_KEY_CRMSH_TAG)), mock.call("ssh-keygen -q -f {} -C '{}' -N ''".format( SSH_KEY_CRMSH, SSH_KEY_CRMSH_TAG)) ]) mock_append.assert_called_once_with("{}.pub".format(SSH_KEY_CRMSH), "/root/.ssh/authorized_keys")