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
Fixes #24894 - Support for cron expressions #584
Conversation
Issues: #24894 |
@akofink : What does the label Requires katello PR you added mean? Also, I think sync-plans is not covered well in general in hammer..I will try to add some tests around that with this PR.. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we need more Katello changes.
@@ -9,6 +9,7 @@ class ListCommand < HammerCLIKatello::ListCommand | |||
field :sync_date, _("Start Date"), Fields::Date | |||
field :interval, _("Interval") | |||
field :enabled, _("Enabled"), Fields::Boolean | |||
field :cron_expression, _("Cron Expression") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's no validation in Katello for this. i.e. require interval to be 'custom cron'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right..So my intent is to display the cron expression..Should we not do that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This hammer change is correct, but I feel we should add validation in Katello for this field, as it's only valid when interval == 'custom cron'
lib/hammer_cli_katello/sync_plan.rb
Outdated
@@ -32,9 +33,11 @@ class InfoCommand < HammerCLIKatello::InfoCommand | |||
class CreateCommand < HammerCLIKatello::CreateCommand | |||
option "--interval", "INTERVAL", _("how often synchronization should run"), | |||
:format => HammerCLI::Options::Normalizers::Enum.new( | |||
%w(hourly daily weekly) | |||
["hourly", "daily", "weekly", "custom cron"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we need added validation for cron_expression, I think we can also remove this Enum format completely and validate the interval in Katello. Right now, there is validation, but it's not clear what the options are from the error message (note, I removed this format to achieve the following output):
$ hammer sync-plan create --name foo3 --organization-id 1 --interval weeklys --sync-date 2018-09-11 --enabled 1
Could not create the sync plan:
Interval not set correctly
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will go ahead and remove the enum format.. Are you suggesting a change in validation message somewhere to prompt the hammer user of valid options?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not only hammer users, but API users in general. Almost all of our error messages are generated by the API; this is a special case for some reason, and I don't think it needs to be.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we change the name of 'custom cron' to 'custom-cron'.
Reasons :
- Autocomplete is hammer shell show 'custom cron', if you see hammer shell whenever there are two names are joined using '-' e.g. 'sync-plan', 'organization-id'
below example explains more too
hammer> sync-plan create --name 'test1' --interval custom cron --organization-id 1 --enabled 1 --sync-date '2016-10-01 01:00:00'
Could not create the sync plan:
Error: Option '--interval': Value must be one of 'hourly', 'daily', 'weekly', 'custom cron'..
See: ' sync-plan create --help'.
hammer> sync-plan create --name 'test1' --interval daily --organization-id 1 --enabled 1 --sync-date '2016-10-01 01:00:00'Sync plan created.
- As per above example the for daily get autocomplete no need to user to convert it to 'daily', same we can do custom-cron instread of 'custom cron'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we should change it. Hyphens are used for subcommands and options (i.e. --organization-id), but not for values (i.e. 'Default Organization'). Values with spaces may use quotes or escape the space (i.e. 'Default Organization'
or Default\ Organization
). This is common throughout the different hammer resources.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, make sense
@sjha4 The label means that this hammer PR requires the Katello PR I put in the description. It's mostly helpful for testing and packaging. |
You will need to update the apipie cache to test this new |
@akofink : Wondering if the api cache merged 4 days ago for 3.9 would be enough for this? |
I think it's sufficient. |
Failed Scenarios:
3 .Failed should give an error message as weekly interval should not have cron expression (looks like should be fixed by this PR Katello/katello#7700)
|
@omkarkhatavkar : Ready to retest.. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can still create invalid sync plans:
$ hammer sync-plan create --name foo3 --organization-id 1 --interval weekly --sync-date 2018-09-11 --enabled 1 --cron-expression "foo"
Sync plan created.
Add validations to prevent --cron-expression
when interval != 'custom cron'
Scenario_1 got passed now
as @akofink said, yes the sceanario_3 (validation) is still failing. |
@akofink, @omkarkhatavkar : Scenario 3 should give an error now that Katello/katello#7700 is merged.. |
Still erroring on scenario 3 (and yes, I tested this with Katello/katello#7700 checked out before it was merged): $ hammer sync-plan create --name foo4 --organization-id 1 --interval weekly --sync-date 2018-09-11 --enabled 1 --cron-expression "foo"
Sync plan created. |
Maybe @omkarkhatavkar can confirm this behavior..I spun up a new hammer-devel box and pulled my changes..Works for me on a fresh setup.. 😕 |
👍 @sjha4 @akofink
Scenario 2 is pending now, I'm thinking it actually not related to this PR if we want we can raise separate issue/bug for that. please let me know the thoughts. |
I figured out why mine wasn't working! Once you generate an apipie cache on your Foreman instance, it uses that for all apidoc requests, even with @sjha4 You should add a test or two for this (there are no sync_plan create tests currently). |
As for scenario 2, let's file a new issue and address it in a separate PR. |
@akofink: Added some tests.. |
Forgot about rubocop.. |
include SyncPlanHelpers | ||
|
||
it 'create with organization ID,name,interval,date and enabled' do | ||
api_expects(:sync_plans, :create, 'create a sync plan') do |par| |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sjha4 sorry, should have mentioned, there's a new syntax (.with_params
) which makes the test failures much easier to understand. i.e.
with_params('name' => env_name, |
@@ -0,0 +1,53 @@ | |||
require_relative '../test_helper' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't need to add tests here. Just for create, since that's what this PR is about.
@@ -0,0 +1,45 @@ | |||
require_relative '../test_helper' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here. You're off the hook for update.
@@ -0,0 +1,61 @@ | |||
require_relative '../test_helper' | |||
require 'hammer_cli_katello/sync_plan' | |||
require_relative 'sync_plan_helpers' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're not using this helper in any of the create tests.
@akofink : Updated the tests to use the with_params..I can remove the update and delete tests if you have any concerns there.. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tests look good. Thanks @sjha4! Great work! And thanks for the free update/delete tests. :)
let(:org_name) { "org1" } | ||
let(:desc) { "New Description" } | ||
|
||
it 'with organization id and sync plan ID' do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a bit weird, but I'll accept it. :) The --organization-id
isn't really useful with --id
. It's only used to look up the ID using the sync plan name, but I guess it could make sense to test that organization ID isn't being sent to the API, which is one thing this test does.
(cherry picked from commit 3ca2dda)
Adds support for custom cron expressions in sync plans.
Requires Katello/katello#7644 , Katello/katello#7700