summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Church <chris@ninemoreminutes.com>2015-09-16 16:46:01 -0400
committerChris Church <chris@ninemoreminutes.com>2015-09-16 16:46:01 -0400
commit43b15ab9a4c668f06b967213529d3d4637423303 (patch)
treec70310ca7a3459713eb91865021d76c3cfb6f8b0
parent93af0b327fdd91de19311031403f581ac5039039 (diff)
parent6ab4cff7dba82d407549ece5c9ab2ef98d3b1d3d (diff)
downloadansible-43b15ab9a4c668f06b967213529d3d4637423303.tar.gz
Merge pull request #12385 from cchurch/winrm_put_empty_file
Enable winrm put_file to upload an empty file.
-rw-r--r--lib/ansible/plugins/connection/winrm.py2
-rw-r--r--test/integration/roles/test_win_copy/files/empty.txt0
-rw-r--r--test/integration/roles/test_win_copy/tasks/main.yml35
3 files changed, 36 insertions, 1 deletions
diff --git a/lib/ansible/plugins/connection/winrm.py b/lib/ansible/plugins/connection/winrm.py
index c5f1f81d44..1ad5e6b244 100644
--- a/lib/ansible/plugins/connection/winrm.py
+++ b/lib/ansible/plugins/connection/winrm.py
@@ -224,7 +224,7 @@ class Connection(ConnectionBase):
# windows command length), divide by 2.67 (UTF16LE base64 command
# encoding), then by 1.35 again (data base64 encoding).
buffer_size = int(((8190 - len(cmd)) / 2.67) / 1.35)
- for offset in xrange(0, in_size, buffer_size):
+ for offset in xrange(0, in_size or 1, buffer_size):
try:
out_data = in_file.read(buffer_size)
if offset == 0:
diff --git a/test/integration/roles/test_win_copy/files/empty.txt b/test/integration/roles/test_win_copy/files/empty.txt
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/test/integration/roles/test_win_copy/files/empty.txt
diff --git a/test/integration/roles/test_win_copy/tasks/main.yml b/test/integration/roles/test_win_copy/tasks/main.yml
index 48df427380..3d29775894 100644
--- a/test/integration/roles/test_win_copy/tasks/main.yml
+++ b/test/integration/roles/test_win_copy/tasks/main.yml
@@ -19,6 +19,41 @@
- name: record the output directory
set_fact: output_file={{win_output_dir}}/foo.txt
+- name: copy an empty file
+ win_copy:
+ src: empty.txt
+ dest: "{{win_output_dir}}/empty.txt"
+ register: copy_empty_result
+
+- name: check copy empty result
+ assert:
+ that:
+ - copy_empty_result|changed
+ - copy_empty_result.checksum == 'da39a3ee5e6b4b0d3255bfef95601890afd80709'
+
+- name: stat the empty file
+ win_stat:
+ path: "{{win_output_dir}}/empty.txt"
+ register: stat_empty_result
+
+- name: check that empty file really was created
+ assert:
+ that:
+ - stat_empty_result.stat.exists
+ - stat_empty_result.stat.size == 0
+
+- name: copy an empty file again
+ win_copy:
+ src: empty.txt
+ dest: "{{win_output_dir}}/empty.txt"
+ register: copy_empty_again_result
+
+- name: check copy empty again result
+ assert:
+ that:
+ - not copy_empty_again_result|changed
+ - copy_empty_again_result.checksum == 'da39a3ee5e6b4b0d3255bfef95601890afd80709'
+
- name: initiate a basic copy
#- name: initiate a basic copy, and also test the mode
# win_copy: src=foo.txt dest={{output_file}} mode=0444