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

Add new "pdk console" command #758

Merged
merged 2 commits into from
Oct 8, 2019
Merged

Add new "pdk console" command #758

merged 2 commits into from
Oct 8, 2019

Conversation

logicminds
Copy link
Contributor

@logicminds logicminds commented Sep 20, 2019

Adds a new command called console that invokes the puppet debugger console from within a module. This command respects the puppet-version, puppet-dev, and pe-version options but has to parse them manually due to how CRI works and becoming a broker to the puppet debugger command. Otherwise the pdk console command works just like the puppet debugger command and can be passed the same exact options. In fact using pdk console -h will actually return the help info from the puppet debugger command. This is the reason why I had to skip option parsing.

At the moment this only works inside a module due to some limitations of the PDK and external gems. However, working inside a module allows for a scoped invocation of the puppet debugger scoped for the module. This allows for users to easily test out their module code, facts, datatypes and more without having to supply the modulepath.

pdk console
pdk (INFO): Console can only be run from inside a valid module directory

This also relies on the user having the puppet-debugger gem in their Gemfile. The following PR should ensure the user has this already. Otherwise the user would need to add puppet-debugger to the .sync.yml file. If the user does not have the puppet-debugger gem they will get the following error. Once solution to work around this is to figure out if they have the gem present already, but this procedure slows down the console command and was removed from the PR.

pdk console
Error: Unknown Puppet subcommand 'debugger'
See 'puppet help' for help on available puppet subcommands

This PR also relies on #753 and #755 and I have included them as separate PRs and also in this branch.

The demo below shows several invocations with different puppet versions which is quite handy. The delay you may notice is PDK::Util::Bundler.ensure_bundle!(puppet_env[:gemset]) being run to ensure the correct puppet version is installed.

pdk console demo

@logicminds logicminds requested a review from a team as a code owner September 20, 2019 20:49
@coveralls
Copy link

coveralls commented Sep 20, 2019

Coverage Status

Coverage increased (+0.003%) to 91.719% when pulling 131aa75 on nwops:console into e25f01b on puppetlabs:master.

@glennsarti
Copy link
Contributor

@logicminds I assume this relates to puppetlabs-toy-chest/pdk-planning#44

May need to update the RFC with the new name of console

@@ -105,6 +105,20 @@ This command runs all available unit tests.

## Experimental features

### `pdk console` command
Copy link
Contributor

@glennsarti glennsarti Sep 23, 2019

Choose a reason for hiding this comment

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

@jbondpdx Can you give these docs a quick look.

  • To use just execute avoid just and easy

  • ~/modules/ntp $ ... Avoid shell specific things e.g. a PowerShell user would see this prefixed differently.

Copy link
Contributor Author

@logicminds logicminds Sep 24, 2019

Choose a reason for hiding this comment

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

I updated the README with the fixes and also added some extra bits I thought were important.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry I didn't see this sooner, @glennsarti , @logicminds ... I think it got lost in a mass of GitHub emails. Thank you for both for these docs!

@logicminds
Copy link
Contributor Author

logicminds commented Sep 24, 2019

Added another commit that helps the user if the puppet-debugger gem is missing.

pdk console
pdk (FATAL): Your Gemfile is missing the puppet-debugger gem.  You can add the missing gem
by updating your /modules/ntp/.sync.yml file with the following
and running pdk update.

Gemfile:
  required:
    ":development":
      - gem: puppet-debugger
        version: "~> 0.14"

@logicminds logicminds force-pushed the console branch 14 times, most recently from 82932e4 to 68d9167 Compare September 27, 2019 14:19
@logicminds
Copy link
Contributor Author

@rodjek @glennsarti I spent some time refactoring my tests and they no longer run the debugger and instead just validate the args being passed through to the debugger. We know the debugger works so there is no need to test it's functionality. Not running the debugger speeds up the tests greatly and removes the need for the dependency as well. This strategy might be something we can do with other pdk commands as well.

Anyways, this is ready to go.

Gemfile Outdated Show resolved Hide resolved
README.md Show resolved Hide resolved
@logicminds logicminds force-pushed the console branch 3 times, most recently from 75a8f7b to 5d34bfc Compare October 2, 2019 13:19
@glennsarti
Copy link
Contributor

glennsarti commented Oct 4, 2019

Hrmm the environmentpath is breaking on my laptop

pdk (DEBUG): Executing 'bundle.bat exec puppet debugger --basemodulepath=C:/Source/tmp/pdkmodule/spec/fixtures/modules:C:/Source/tmp/pdkmodule/modules --environmentpath=C:/Source/tmp/pdkmodule/spec/fixtures/modules:C:/Source/tmp/pdkmodule/modules --modulepath=C:/Source/tmp/pdkmodule/spec/fixtures/modules:C:/Source/tmp/pdkmodule/modules' interactively
Traceback (most recent call last):
        7: from C:/Users/glenn.sarti/AppData/Local/PDK/cache/ruby/2.5.0/bin/puppet:23:in `<main>'
        6: from C:/Users/glenn.sarti/AppData/Local/PDK/cache/ruby/2.5.0/bin/puppet:23:in `load'
        5: from C:/Users/glenn.sarti/AppData/Local/PDK/cache/ruby/2.5.0/gems/puppet-6.10.0-x64-mingw32/bin/puppet:5:in `<top (required)>'
        4: from C:/Users/glenn.sarti/AppData/Local/PDK/cache/ruby/2.5.0/gems/puppet-6.10.0-x64-mingw32/lib/puppet/util/command_line.rb:77:in `execute'
        3: from C:/Users/glenn.sarti/AppData/Local/PDK/cache/ruby/2.5.0/gems/puppet-6.10.0-x64-mingw32/lib/puppet/util/command_line.rb:143:in `run'
        2: from C:/Users/glenn.sarti/AppData/Local/PDK/cache/ruby/2.5.0/gems/puppet-6.10.0-x64-mingw32/lib/puppet/application.rb:370:in `run'
        1: from C:/Users/glenn.sarti/AppData/Local/PDK/cache/ruby/2.5.0/gems/puppet-6.10.0-x64-mingw32/lib/puppet/application_support.rb:34:in `push_application_context'
C:/Users/glenn.sarti/AppData/Local/PDK/cache/ruby/2.5.0/gems/puppet-6.10.0-x64-mingw32/lib/puppet/environments.rb:38:in `get!': Could not find a directory environment named 'workstation_production' anywhere in the path: C:/Source/tmp/pdkmodule/spec/fixtures/modules:C:/Source/tmp/pdkmodule/modules. Does the directory exist? (Puppet::Environments::EnvironmentNotFound)
pdk (DEBUG): Execution of 'bundle.bat exec puppet debugger --basemodulepath=C:/Source/tmp/pdkmodule/spec/fixtures/modules:C:/Source/tmp/pdkmodule/modules --environmentpath=C:/Source/tmp/pdkmodule/spec/fixtures/modules:C:/Source/tmp/pdkmodule/modules --modulepath=C:/Source/tmp/pdkmodule/spec/fixtures/modules:C:/Source/tmp/pdkmodule/modules' complete (duration:                               16.243607s; exit code: 1)
C:\Source\tmp\pdkmodule>

Removing that setting I get a pdk console prompt

pdk (DEBUG): Executing 'bundle.bat exec puppet debugger --basemodulepath=C:/Source/tmp/pdkmodule/spec/fixtures/modules:C:/Source/tmp/pdkmodule/modules --modulepath=C:/Source/tmp/pdkmodule/spec/fixtures/modules:C:/Source/tmp/pdkmodule/modules' interactively
Ruby Version: 2.5.1
Puppet Version: 6.10.0
Puppet Debugger Version: 0.15.1
Created by: NWOps <[email protected]>
Type "commands" for a list of debugger commands
or "help" to show the help screen.


1:>>

Makes sense as the environment layout is different to a modulepath

glennsarti added a commit to glennsarti/pdk that referenced this pull request Oct 4, 2019
This commit updates the console command to lazy load the required libraries.
glennsarti added a commit to glennsarti/pdk that referenced this pull request Oct 4, 2019
Previously when using the PDK as a gem, the lockfile used to detect the debugger
would use the PDK's lock file, not the module context.  This commit changes
the lock file location to be that of the module.
glennsarti added a commit to glennsarti/pdk that referenced this pull request Oct 4, 2019
Previously the debugger reset the environment path to that of the modulepath
however, on a configured Puppet Agent this is incorrect. The puppet-debugger
should really use the default environment path.
@glennsarti
Copy link
Contributor

I don't have rights on your branch but here are my changes -

nwops/pdk@console...glennsarti:corey-console

@logicminds
Copy link
Contributor Author

@glennsarti added your changes and updated my tests.

I also added a new check to ensure the user has fixtures downloaded. Currently this is just a warning message as it only impacts the modules the debugger has access too.

pdk console
pdk (WARN): Module fixtures not found, please run pdk bundle exec rake spec_prep.

   * Add a new command called console that is a pass through
     to the puppet debugger console.

   * Only allows for use within a module at this time.
@glennsarti
Copy link
Contributor

Confirmed changes at commit 2be8a94 work as expected on Windows and Linux. As it's experimental edge cases can be dealt with later.

@rodjek Unless you have any other thoughts I'll merge soon.

  * previously if the user was not inside the module and had
    a lib folder present the console command would dump a stack
    trace.  This fixes that by also performing a deep inspection
    of the module first.
@rodjek rodjek merged commit 46cd813 into puppetlabs:master Oct 8, 2019
@glennsarti
Copy link
Contributor

🎉🎉🎉🎉

@logicminds logicminds deleted the console branch October 8, 2019 05:47
@rodjek rodjek added the feature label Oct 9, 2019
@rodjek rodjek changed the title Console command Add new "pdk console" command Oct 9, 2019
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.

5 participants