Skip to content

Commit d361802

Browse files
AndreMarcel99Andre Marcel Gutierrez Benitez
andauthored
zos_copy mode is applied to the destination directory, a deviation from the communtiy module behavior. (#723)
* Verify coomand of ZOAU support the doble quotes and get better output of message * Verify coomand of ZOAU support the doble quotes and get better output of message * Restore to the one tyme function solving TypeError * Test about cases with quotes supported * Solve comments * Comments in the changelog * Adjust test for working accord the text * Solve the dest functional mode set for the applied to destination directory * Identation and spaces * To work well * To work well * To work well * To work well * Changelogs added * Solved the fragment test and separte the cases --------- Co-authored-by: Andre Marcel Gutierrez Benitez <andre@MacBook-Pro-de-Andre-2.local>
1 parent 413461f commit d361802

File tree

5 files changed

+25
-15
lines changed

5 files changed

+25
-15
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
minor_changes:
2+
- zos_copy - Fixed a bug where the module would change the mode for a directory when copying into it the contents of another.
3+
(https://github.com/ansible-collections/ibm_zos_core/pull/723)

plugins/module_utils/encode.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,25 @@ def uss_file_tag(self, file_path):
496496
except Exception:
497497
return None
498498

499+
def uss_tag_encoding(self, file_path, tag):
500+
"""Tag the file/directory specified with the given code set.
501+
If `file_path` is a directory, all of the files and subdirectories will
502+
be tagged recursively.
503+
504+
Arguments:
505+
file_path {str} -- Absolute file path to tag.
506+
tag {str} -- Code set to tag the file/directory.
507+
508+
Raises:
509+
TaggingError: When the chtag command fails.
510+
"""
511+
is_dir = os.path.isdir(file_path)
512+
513+
tag_cmd = "chtag -{0}c {1} {2}".format("R" if is_dir else "t", tag, file_path)
514+
rc, out, err = self.module.run_command(tag_cmd)
515+
if rc != 0:
516+
raise TaggingError(file_path, tag, rc, out, err)
517+
499518

500519
class EncodeError(Exception):
501520
def __init__(self, message):

plugins/modules/zos_blockinfile.py

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -197,13 +197,11 @@
197197
block: |
198198
MOUNT FILESYSTEM('SOME.DATA.SET') TYPE(ZFS) MODE(READ)
199199
MOUNTPOINT('/tmp/src/somedirectory')
200-
201200
- name: Remove a library as well as surrounding markers
202201
zos_blockinfile:
203202
state: absent
204203
src: SYS1.PARMLIB(PROG00)
205204
marker: "/* {mark} ANSIBLE MANAGED BLOCK FOR SOME.DATA.SET */"
206-
207205
- name: Add ZOAU path to PATH in /etc/profile
208206
zos_blockinfile:
209207
src: /etc/profile
@@ -212,7 +210,6 @@
212210
ZOAU=/path/to/zoau_dir/bin
213211
export ZOAU
214212
PATH=$ZOAU:$PATH
215-
216213
- name: Insert/Update HTML surrounded by custom markers after <body> line
217214
zos_blockinfile:
218215
path: /var/www/html/index.html
@@ -221,13 +218,11 @@
221218
block: |
222219
<h1>Welcome to {{ ansible_hostname }}</h1>
223220
<p>Last updated on {{ ansible_date_time.iso8601 }}</p>
224-
225221
- name: Remove HTML as well as surrounding markers
226222
zos_blockinfile:
227223
path: /var/www/html/index.html
228224
state: absent
229225
marker: "<!-- {mark} ANSIBLE MANAGED BLOCK -->"
230-
231226
- name: Add mappings to /etc/hosts
232227
zos_blockinfile:
233228
path: /etc/hosts
@@ -238,7 +233,6 @@
238233
- { name: host1, ip: 10.10.1.10 }
239234
- { name: host2, ip: 10.10.1.11 }
240235
- { name: host3, ip: 10.10.1.12 }
241-
242236
- name: Add a code block to a member using a predefined indentation.
243237
zos_blockinfile:
244238
path: SYS1.PARMLIB(BPXPRM00)
@@ -348,12 +342,10 @@
348342

349343
def transformBlock(block, indentation_char, indentation_spaces):
350344
"""Prepends the specified number of spaces to the block in all lines
351-
352345
Arguments:
353346
block: {str} -- The block text to be transformed.
354347
indentation_char: {str} -- The indentation char to be used.
355348
indentation_spaces: {int} -- Number of times the indentation char to prepend.
356-
357349
Returns:
358350
block: {str} -- The text block after applying the necessary transformations.
359351
"""
@@ -372,7 +364,6 @@ def present(src, block, marker, ins_aft, ins_bef, encoding, force):
372364
"""Replace a block with the matching regex pattern
373365
Insert a block before/after the matching pattern
374366
Insert a block at BOF/EOF
375-
376367
Arguments:
377368
src: {str} -- The z/OS USS file or data set to modify.
378369
block: {str} -- The block to insert/replace into the src.
@@ -387,7 +378,6 @@ def present(src, block, marker, ins_aft, ins_bef, encoding, force):
387378
- '*regex*'
388379
encoding: {str} -- Encoding of the src.
389380
force: {str} -- If not empty passes the -f option to dmod cmd.
390-
391381
Returns:
392382
str -- Information in JSON format. keys:
393383
cmd: {str} -- dmod shell command
@@ -399,13 +389,11 @@ def present(src, block, marker, ins_aft, ins_bef, encoding, force):
399389

400390
def absent(src, marker, encoding, force):
401391
"""Delete blocks with matching regex pattern
402-
403392
Arguments:
404393
src: {str} -- The z/OS USS file or data set to modify.
405394
marker: {str} -- Identifies the block to be removed.
406395
encoding: {str} -- Encoding of the src.
407396
force: {str} -- If not empty passes the -f option to dmod cmd.
408-
409397
Returns:
410398
str -- Information in JSON format. keys:
411399
cmd: {str} -- dmod shell command

plugins/modules/zos_copy.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1056,8 +1056,8 @@ def copy_to_uss(
10561056
group = self.common_file_args.get("group")
10571057
owner = self.common_file_args.get("owner")
10581058
if mode is not None:
1059-
self.module.set_mode_if_different(dest, mode, False)
1060-
1059+
if not os.path.isdir(dest):
1060+
self.module.set_mode_if_different(dest, mode, False)
10611061
if changed_files:
10621062
for filepath in changed_files:
10631063
self.module.set_mode_if_different(os.path.join(dest, filepath), mode, False)

tests/functional/modules/test_zos_blockinfile_func.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1545,4 +1545,4 @@ def test_ds_not_supported(ansible_zos_module, dstype):
15451545
DsNotSupportedHelper(
15461546
TEST_INFO["test_ds_block_insertafter_regex"]["test_name"], ansible_zos_module,
15471547
TEST_ENV, TEST_INFO["test_uss_block_insertafter_regex"]
1548-
)
1548+
)

0 commit comments

Comments
 (0)