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

Plugins: Test harness, test fixture, docs, and local-type example #356

Merged
merged 17 commits into from
Sep 27, 2018

Conversation

clintoncwolfe
Copy link
Contributor

@clintoncwolfe clintoncwolfe commented Sep 27, 2018

This PR contains few changes to Train itself, but adds many things to the source tree.

  • A complete (docs, tests, Rakefile, gemspec, implementation) Train plugin example, heavily commented for teaching. This is train-local-rot13; it may make sense to make an additional (but less commented) example for talking to an API.
  • Under test/fixtures, a test fixture plugin, which responds with fixed responses. It can be used to verify transport loading in Train, or plugin installation capability in InSpec.
  • Docs under docs/plugins.md, which gives a very high level overview of Train plugin development.
  • A test support file, lib/train/plugin_test_helper.rb, which helps plugin authors develop against train when writing outside the Train source tree.
  • Updates the rubocop.yml to permit linting of examples.

Related: inspec/inspec#3444
Related: inspec/inspec#3421

attn: @chris-rock

NOTE: until this is merged (and a gem is built), you will need to check out this branch, then locally edit examples/plugins/train-local-rot13/Gemfile to add this line:

# Force bundler to use your source checkout, NOT the rubygems train gem
# TEMPORARY
gem 'train', path: '../path/to/train/source/root'
gemspec

Without this, the example plugin's tests will not be able to find the lib/train/plugin_test_helper.rb (which exists on this branch, not yet in a gem).

Signed-off-by: Clinton Wolfe <clintoncwolfe@gmail.com>
…ection setup

Signed-off-by: Clinton Wolfe <clintoncwolfe@gmail.com>
Signed-off-by: Clinton Wolfe <clintoncwolfe@gmail.com>
Signed-off-by: Clinton Wolfe <clintoncwolfe@gmail.com>
Signed-off-by: Clinton Wolfe <clintoncwolfe@gmail.com>
Signed-off-by: Clinton Wolfe <clintoncwolfe@gmail.com>
Signed-off-by: Clinton Wolfe <clintoncwolfe@gmail.com>
Signed-off-by: Clinton Wolfe <clintoncwolfe@gmail.com>
Signed-off-by: Clinton Wolfe <clintoncwolfe@gmail.com>
Signed-off-by: Clinton Wolfe <clintoncwolfe@gmail.com>
Signed-off-by: Clinton Wolfe <clintoncwolfe@gmail.com>
Copy link
Contributor

@jquick jquick left a comment

Choose a reason for hiding this comment

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

Thanks @clintoncwolfe ! Nice examples here

docs/plugins.md Outdated

Required. Use the `name` call to register your plugin. Pass a String, which should have the 'train-' portion removed.

#### option
Copy link
Contributor

@jquick jquick Sep 27, 2018

Choose a reason for hiding this comment

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

These still need filled out I think.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I need help on this - I don't know what is needed. I've filled out a skeleton, with TODOs.

Copy link
Contributor

@jerryaldrichiii jerryaldrichiii left a comment

Choose a reason for hiding this comment

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

Looks great @clintoncwolfe, just a few spelling/grammatical things.

You can probably ignore the train-test-fixture feedback...not sure where to put it.

docs/plugins.md Outdated Show resolved Hide resolved
docs/plugins.md Outdated Show resolved Hide resolved
docs/plugins.md Outdated Show resolved Hide resolved

### Installing Train Plugins outside of InSpec

If you need a train plugin installed, and `inspec plugin` is not available to you, you can install a train plugin like any other gem. Just be sure to use the `gem` binary that comes with the application you wish to extend. For example, to add a Train Plugin to a ChefDK installation, use:
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure we support adding gems to ChefDK. It is intended to be a bundled distribution.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

ChefDK should always have train but the example is fine imo.

Copy link
Contributor

Choose a reason for hiding this comment

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

I only worry that a user will add a gem and pull in a dep that will break ChefDK in some way.

Copy link
Contributor

Choose a reason for hiding this comment

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

If deps have issues it should not install and error just like a bundle but retain functionality. If they want to install a new Train on their DevKit that is their call.

docs/plugins.md Outdated Show resolved Hide resolved
lib/train/plugin_test_helper.rb Show resolved Hide resolved
clintoncwolfe and others added 3 commits September 27, 2018 15:38
Signed-off-by: Clinton Wolfe <clintoncwolfe@gmail.com>
Signed-off-by: Clinton Wolfe <clintoncwolfe@gmail.com>
Signed-off-by: Jared Quick <jquick@chef.io>
docs/plugins.md Outdated

#### local?

TODO
This flag helps Train decide what detection to use for OS based platforms. This should be set to `true` if your transport target resides in the same instance you are running train from. This setting is not needed for API transports or transports who do not use platform detection.
Copy link
Contributor

Choose a reason for hiding this comment

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

I love the anthropomorphism, but might go with that do not use here.

docs/plugins.md Outdated
Platform detection is used if you do not specify a platform method for your transport. Currently it is only used for OS (Unix, Windows) platforms. The detection system will run a series of commands on your target to try and determine what platform it is. This information can be found here [OS Specifications](https://github.com/inspec/train/blob/master/lib/train/platforms/detect/specifications/os.rb).

When using a API or a fixed platform for your transport its suggested you skip the detection process and specify a direct platform. Here is an example:
Copy link
Contributor

@jerryaldrichiii jerryaldrichiii Sep 27, 2018

Choose a reason for hiding this comment

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

an API? EDIT: Actually I'm not even sure here...English is hard.

Copy link
Contributor

Choose a reason for hiding this comment

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

it's though I'm sure of 😄

Signed-off-by: Jared Quick <jquick@chef.io>
Copy link
Contributor

@jquick jquick left a comment

Choose a reason for hiding this comment

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

Signed-off-by: Jared Quick <jquick@chef.io>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants