summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorantima-gupta <agupta@msystechnologies.com>2020-05-14 16:06:31 +0530
committerantima-gupta <agupta@msystechnologies.com>2020-06-10 10:51:40 +0530
commitbe3fd874f98c6f973a41a97ccd061b6493982833 (patch)
treef36fd0c24895e5355f22cddb6e18bfd55bdb5e87
parent22d38547a8db55c1a579c1e939253ad526a158cd (diff)
downloadchef-be3fd874f98c6f973a41a97ccd061b6493982833.tar.gz
Moved all the constants together.
Removed unnecessary assignment for weekday_in_crontab. Removed pry. Removed converted to a string function from weekday validation. Added unified_mode in cron and cron_d resources. Signed-off-by: antima-gupta <agupta@msystechnologies.com>
-rw-r--r--lib/chef/resource/cron/_cron_shared.rb8
-rw-r--r--lib/chef/resource/cron/cron.rb8
-rw-r--r--lib/chef/resource/cron/cron_d.rb2
-rw-r--r--lib/chef/resource/helpers/cron_validations.rb4
-rw-r--r--spec/unit/provider/cron_spec.rb1
5 files changed, 10 insertions, 13 deletions
diff --git a/lib/chef/resource/cron/_cron_shared.rb b/lib/chef/resource/cron/_cron_shared.rb
index 06fc072528..4e2eb5428a 100644
--- a/lib/chef/resource/cron/_cron_shared.rb
+++ b/lib/chef/resource/cron/_cron_shared.rb
@@ -1,5 +1,7 @@
unified_mode true
+TIMEOUT_OPTS = %w{duration preserve-status foreground kill-after signal}.freeze
+TIMEOUT_REGEX = /\A\S+/.freeze
WEEKDAYS = {
sunday: "0", monday: "1", tuesday: "2", wednesday: "3", thursday: "4", friday: "5", saturday: "6",
sun: "0", mon: "1", tue: "2", wed: "3", thu: "4", fri: "5", sat: "6"
@@ -62,8 +64,6 @@ property :environment, Hash,
default: lazy { {} }
-TIMEOUT_OPTS = %w{duration preserve-status foreground kill-after signal}.freeze
-TIMEOUT_REGEX = /\A\S+/.freeze
property :time_out, Hash,
description: "A Hash of timeouts in the form of `({'OPTION' => 'VALUE'})`.
@@ -82,7 +82,7 @@ property :time_out, Hash,
raise Chef::Exceptions::ValidationFailed, error_msg
end
unless h.values.all? { |x| x =~ TIMEOUT_REGEX }
- error_msg = "Values of option time_out should be non-empty string without any leading whitespaces."
+ error_msg = "Values of option time_out should be non-empty strings without any leading whitespace."
raise Chef::Exceptions::ValidationFailed, error_msg
end
h
@@ -98,5 +98,5 @@ private
# @return [Integer, String] A weekday formed as per the user inputs.
def weekday_in_crontab(wday)
weekday = wday.to_s.downcase.to_sym
- weekday_in_crontab = WEEKDAYS[weekday] || wday
+ WEEKDAYS[weekday] || wday
end \ No newline at end of file
diff --git a/lib/chef/resource/cron/cron.rb b/lib/chef/resource/cron/cron.rb
index aeeef5624d..31d6efcfde 100644
--- a/lib/chef/resource/cron/cron.rb
+++ b/lib/chef/resource/cron/cron.rb
@@ -24,6 +24,8 @@ require_relative "../../provider/cron" # do not remove. we actually need this be
class Chef
class Resource
class Cron < Chef::Resource
+ unified_mode true
+
use "cron_shared"
provides :cron
@@ -35,12 +37,6 @@ class Chef
default_action :create
allowed_actions :create, :delete
- def initialize(name, run_context = nil)
- super
- @month = "*"
- @weekday = "*"
- end
-
property :time, Symbol,
description: "A time interval.",
equal_to: Chef::Provider::Cron::SPECIAL_TIME_VALUES
diff --git a/lib/chef/resource/cron/cron_d.rb b/lib/chef/resource/cron/cron_d.rb
index 39a811fdf8..3a913b22c3 100644
--- a/lib/chef/resource/cron/cron_d.rb
+++ b/lib/chef/resource/cron/cron_d.rb
@@ -23,6 +23,8 @@ require_relative "../../dist"
class Chef
class Resource
class CronD < Chef::Resource
+ unified_mode true
+
use "cron_shared"
provides :cron_d
diff --git a/lib/chef/resource/helpers/cron_validations.rb b/lib/chef/resource/helpers/cron_validations.rb
index c0da71acce..b801b7bf11 100644
--- a/lib/chef/resource/helpers/cron_validations.rb
+++ b/lib/chef/resource/helpers/cron_validations.rb
@@ -70,8 +70,8 @@ class Chef
spec = spec.to_s
spec == "*" ||
validate_numeric(spec, 0, 7) ||
- %w{sun mon tue wed thu fri sat}.include?(String(spec).downcase) ||
- %w{sunday monday tuesday wednesday thursday friday saturday}.include?(String(spec).downcase)
+ %w{sun mon tue wed thu fri sat}.include?(spec.downcase) ||
+ %w{sunday monday tuesday wednesday thursday friday saturday}.include?(spec.downcase)
end
# validate the day of the month is 1-31
diff --git a/spec/unit/provider/cron_spec.rb b/spec/unit/provider/cron_spec.rb
index 85060c07b7..76f170312e 100644
--- a/spec/unit/provider/cron_spec.rb
+++ b/spec/unit/provider/cron_spec.rb
@@ -15,7 +15,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
-require 'pry'
require "spec_helper"
describe Chef::Provider::Cron do