summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Smith <tsmith@chef.io>2018-11-16 11:15:07 -0800
committerTim Smith <tsmith@chef.io>2018-11-16 16:34:31 -0800
commitfe2bd538e5ca6e8f61d46a036cc69eeca29ca2b0 (patch)
tree1f659f129af38dba1c9d6c286c7e5ce1e9aa7808
parent8d775f39f480a3f64aa15207c400a78d3b12c9ec (diff)
downloadchef-fe2bd538e5ca6e8f61d46a036cc69eeca29ca2b0.tar.gz
Fully convert remote_directory to use propertiesproperties2
Also add descriptions, default_descriptions, and expand the tests a bit. Signed-off-by: Tim Smith <tsmith@chef.io>
-rw-r--r--lib/chef/resource/remote_directory.rb79
-rw-r--r--spec/unit/resource/remote_directory_spec.rb31
2 files changed, 60 insertions, 50 deletions
diff --git a/lib/chef/resource/remote_directory.rb b/lib/chef/resource/remote_directory.rb
index b9f701ee6d..dd7077b9ae 100644
--- a/lib/chef/resource/remote_directory.rb
+++ b/lib/chef/resource/remote_directory.rb
@@ -1,7 +1,7 @@
#
# Author:: Adam Jacob (<adam@chef.io>)
# Author:: Tyler Cloke (<tyler@chef.io>)
-# Copyright:: Copyright 2008-2016, Chef Software Inc.
+# Copyright:: Copyright 2008-2018, Chef Software Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -26,62 +26,59 @@ class Chef
class RemoteDirectory < Chef::Resource::Directory
include Chef::Mixin::Securable
- description "Use the remote_directory resource to incrementally transfer a directory"\
- " from a cookbook to a node. The director that is copied from the cookbook"\
- " should be located under COOKBOOK_NAME/files/default/REMOTE_DIRECTORY. The"\
- " remote_directory resource will obey file specificity."
-
- identity_attr :path
-
- state_attrs :files_owner, :files_group, :files_mode
+ description "Use the remote_directory resource to incrementally transfer a directory from a cookbook to a node. The director that is copied from the cookbook should be located under COOKBOOK_NAME/files/default/REMOTE_DIRECTORY. The remote_directory resource will obey file specificity."
default_action :create
allowed_actions :create, :create_if_missing, :delete
def initialize(name, run_context = nil)
super
- @path = name
@delete = false
- @recursive = true
- @files_owner = nil
- @files_group = nil
- @files_mode = 0644 unless Chef::Platform.windows?
end
if Chef::Platform.windows?
- # create a second instance of the 'rights' attribute
+ # create a second instance of the 'rights' attribute (property)
rights_attribute(:files_rights)
end
- property :source, String, default: lazy { ::File.basename(path) }
- property :files_backup, [ Integer, FalseClass ], default: 5, desired_state: false
- property :purge, [ TrueClass, FalseClass ], default: false, desired_state: false
- property :overwrite, [ TrueClass, FalseClass ], default: true, desired_state: false
- property :cookbook, String, desired_state: false
+ # This same property exists in the directory resource, but we need to change the default to true here.
+ property :recursive, [ TrueClass, FalseClass ],
+ description: "Create or delete parent directories recursively. For the owner, group, and mode properties, the value of this attribute applies only to the leaf directory.",
+ default: true, desired_state: false
- def files_group(arg = nil)
- set_or_return(
- :files_group,
- arg,
- regex: Chef::Config[:group_valid_regex]
- )
- end
+ property :source, String,
+ description: "The base name of the source file (and inferred from the path property).",
+ default_description: "The base portion of the 'path' property. For example '/some/path/' would be 'path'.",
+ default: lazy { ::File.basename(path) }, desired_state: false
- def files_mode(arg = nil)
- set_or_return(
- :files_mode,
- arg,
- regex: /^\d{3,4}$/
- )
- end
+ property :files_backup, [ Integer, FalseClass ],
+ description: "The number of backup copies to keep for files in the directory.",
+ default: 5, desired_state: false
- def files_owner(arg = nil)
- set_or_return(
- :files_owner,
- arg,
- regex: Chef::Config[:user_valid_regex]
- )
- end
+ property :purge, [ TrueClass, FalseClass ],
+ description: "Purge extra files found in the target directory.",
+ default: false, desired_state: false
+
+ property :overwrite, [ TrueClass, FalseClass ],
+ description: "Overwrite a file when it is different.",
+ default: true, desired_state: false
+
+ property :cookbook, String,
+ description: "The cookbook in which a file is located (if it is not located in the current cookbook). The default value is the current cookbook.",
+ desired_state: false
+
+ property :files_group, [String, Integer],
+ description: "Configure group permissions for files. A string or ID that identifies the group owner by group name, including fully qualified group names such as domain\\group or group@domain. If this value is not specified, existing groups remain unchanged and new group assignments use the default POSIX group (if available).",
+ regex: Chef::Config[:group_valid_regex]
+
+ property :files_mode, [String, Integer, nil],
+ description: "The octal mode for a file.\n UNIX- and Linux-based systems: A quoted 3-5 character string that defines the octal mode that is passed to chmod. For example: '755', '0755', or 00755. If the value is specified as a quoted string, it works exactly as if the chmod command was passed. If the value is specified as an integer, prepend a zero (0) to the value to ensure that it is interpreted as an octal number. For example, to assign read, write, and execute rights for all users, use '0777' or '777'; for the same rights, plus the sticky bit, use 01777 or '1777'.\n Microsoft Windows: A quoted 3-5 character string that defines the octal mode that is translated into rights for Microsoft Windows security. For example: '755', '0755', or 00755. Values up to '0777' are allowed (no sticky bits) and mean the same in Microsoft Windows as they do in UNIX, where 4 equals GENERIC_READ, 2 equals GENERIC_WRITE, and 1 equals GENERIC_EXECUTE. This property cannot be used to set :full_control. This property has no effect if not specified, but when it and rights are both specified, the effects are cumulative.",
+ default_description: "0644 on *nix systems",
+ regex: /^\d{3,4}$/, default: lazy { 0644 unless Chef::Platform.windows? }
+
+ property :files_owner, [String, Integer],
+ description: "Configure owner permissions for files. A string or ID that identifies the group owner by user name, including fully qualified user names such as domain\\user or user@domain. If this value is not specified, existing owners remain unchanged and new owner assignments use the current user (when necessary).",
+ regex: Chef::Config[:user_valid_regex]
end
end
end
diff --git a/spec/unit/resource/remote_directory_spec.rb b/spec/unit/resource/remote_directory_spec.rb
index f010ebdf96..9eab495f77 100644
--- a/spec/unit/resource/remote_directory_spec.rb
+++ b/spec/unit/resource/remote_directory_spec.rb
@@ -36,51 +36,64 @@ describe Chef::Resource::RemoteDirectory do
expect { resource.action :delete }.not_to raise_error
end
- it "accepts a string for the remote directory source" do
+ it "accepts a String for the cookbook property" do
+ resource.cookbook "foo"
+ expect(resource.cookbook).to eql("foo")
+ end
+
+ it "accepts a String for the source property" do
resource.source "foo"
expect(resource.source).to eql("foo")
end
- it "has the basename of the remote directory resource as the default source" do
+ it "uses the basename of the pat property as the default value of the source property" do
resource.path "/foo/bar"
expect(resource.source).to eql("bar")
end
- it "accepts a number for the remote files backup" do
+ it "files_backup property defaults to 5" do
+ expect(resource.files_backup).to eql(5)
+ end
+
+ it "accepts an Integer for the files_backup property" do
resource.files_backup 1
expect(resource.files_backup).to eql(1)
end
- it "accepts false for the remote files backup" do
+ it "accepts false for the files_backup property" do
resource.files_backup false
expect(resource.files_backup).to eql(false)
end
- it "accepts 3 or 4 digits for the files_mode" do
+ it "accepts 3 or 4 digits for the files_mode property" do
resource.files_mode 100
expect(resource.files_mode).to eql(100)
resource.files_mode 1000
expect(resource.files_mode).to eql(1000)
end
- it "accepts a string or number for the files group" do
+ it "accepts a String or number for the files_group property" do
resource.files_group "heart"
expect(resource.files_group).to eql("heart")
resource.files_group 1000
expect(resource.files_group).to eql(1000)
end
- it "accepts a string or number for the files owner" do
+ it "accepts a String or number for the files_owner property" do
resource.files_owner "heart"
expect(resource.files_owner).to eql("heart")
resource.files_owner 1000
expect(resource.files_owner).to eql(1000)
end
- it "overwrites by default" do
+ it "overwrite property has the default value of true" do
expect(resource.overwrite).to be true
end
+ it "recursive property has the default value of true" do
+ expect(resource.recursive).to be true
+ end
+
describe "when it has cookbook, files owner, files mode, and source" do
before do
resource.path("/var/path/")
@@ -98,7 +111,7 @@ describe Chef::Resource::RemoteDirectory do
expect(state[:files_mode]).to eq("0664")
end
- it "returns the path as its identity" do
+ it "returns the path as its identity" do
expect(resource.identity).to eq("/var/path/")
end
end