Next-gen CLI tool for Katello (Katello-specific commands)
hammer-cli development docs for help
The easiest way to set up a hammer development environment is to use the hammer-devel-container.sh script.
- Clone this repo.
- Run the following commands
$ cd hammer-cli-katello
$ hammer-devel-container.shThis should start a container that points to your localhost foreman server
Alternately you can use the centos7-hammer-devel box in forklift.
If you don't want to use any of the automated setups above, you can always set hammer up to be used with Katello manually. The easiest way is to follow these steps:
- Clone the mandatory repos:
This is the core, but without any auth capabilities or commands.
git clone [email protected]:theforeman/hammer-cli.gitThis is a plugin with Foreman commands and auth capabilities.
git clone [email protected]:theforeman/hammer-cli-foreman.gitThis is a plugin with Katello commands.
git clone [email protected]:Katello/hammer-cli-katello.gitNote: you might want to add more plugins (e.g. foreman-virt-who-configure), the steps are the same.
- Create a local Gemfile to point to your plugins:
cd hammer-cli && touch Gemfile.localcat > Gemfile.local <<'PLUGINS'
path '../' do
gem "hammer_cli_foreman"
gem "hammer_cli_katello"
end
PLUGINSbundle install- Configure hammer and plugins:
Adjust cli_config.yml per your needs.
mkdir -p ~/.hammer && cp hammer-cli/config/cli_config.template.yml ~/.hammer/cli_config.ymlmkdir -p ~/.hammer/cli.modules.d && cp hammer-cli-foreman/config/foreman.yml ~/.hammer/cli.modules.d/foreman.ymlcp hammer-cli-katello/config/katello.yml ~/.hammer/cli.modules.d/katello.ymlIf you don't want to be prompted each time, you'd rather put values at least for :host:, :username: and :password:.
cat > ~/.hammer/cli.modules.d/foreman.yml <<'CONFIG'
:foreman:
:enable_module: true
:host: https://foreman.example.com:443
:username: 'admin'
:password: 'changeme'
CONFIG- Try running a command to see if hammer works:
cd hammer-cli && bundle exec ./bin/hammer ping- (Optional) Set up an alias for convenience:
# Add to your ~/.bashrc or ~/.bash_profile
alias hammer='BUNDLE_GEMFILE=/home/vagrant/hammer-cli/Gemfile bundle exec hammer'Note: You might encounter an SSL issue on first run and if so, there are two ways to fix that. There should also be a help message from hammer itself.
- Fetch the CA from the server:
hammer --fetch-ca-cert https://foreman.example.com- Or disable SSL verification either in
~/.hammer/cli_config.ymlor run a hammer command with--verify-sslfalse option.
Configuration files for all hammer plugins are found at
~/.hammer/cli.modules.d. The centos9-hammer-devel box configures hammer for
you, but you may change the configuration files directly as well.
The hammer-cli-katello configuration is located at
~/.hammer/cli.modules.d/katello.yml.
The overall hammer config is found at ~/.hammer/cli_config.yml.
The hammer-cli docs
provide more information on possible configuration values. One useful
configuration option is the Katello server to point to; that is found in
~/.hammer/cli.modules.d/foreman.yml.
Hammer is run as an executable from the root of the hammer-cli-katello repository.
bundle exec hammer -vhLook for any errors. If you see none, you should be good to go.
To run the tests with rubocop:
rakeTo run the tests only:
rake testTo run a specific test:
rake test TEST="test/functional/content_views/show_test.rb"There are both unit tests and functional tests. Unit tests are used for
supporting code, such as lib/hammer_cli_katello/id_resolver.rb. Functional
tests are used for testing the input/output interaction of hammer with the Katello API.
hammer-cli-foreman stubs the API for functional tests. See api_expectations.rb. To regenerate the stubbed API, refer to the test data Readme.
Each subcommand action is tested in its own test file. An example is hammer content-view update; it is stored in
test/functional/content_view/update_test.rb.
For most hammer sub-commands, there are common API calls that are used to
resolve database object IDs. These are usually accompanied with helpers to test
the common API calls. An example is the
OrganizationHelpers.
A typical functional test takes this form:
it 'allows minimal options' do
api_expects(:content_views, :update) do |p| # expect an API call to ContentViews#Update
p['id'] == 2 # expect the params to include {'id' => 2}
end
run_cmd(%w(content-view update --id 2)) # Run the hammer command to test
end