Skip to content

Commit f507366

Browse files
committed
Don't delete symlinks in test mode
1 parent 8597828 commit f507366

2 files changed

Lines changed: 15 additions & 10 deletions

File tree

changelog/69895.fixed.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fixed `x509_v2.certificate_managed` deleting symlinks in test mode if `follow_symlinks` was explicitly set to `false`

salt/states/x509_v2.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -466,8 +466,9 @@ def certificate_managed(
466466
if file_args.get("follow_symlinks", True):
467467
real_name = os.path.realpath(name)
468468
else:
469-
# workaround https://github.com/saltstack/salt/issues/31802
470-
__salt__["file.remove"](name)
469+
if not __opts__["test"]:
470+
# workaround https://github.com/saltstack/salt/issues/31802
471+
__salt__["file.remove"](name)
471472
replace = True
472473

473474
if __salt__["file.file_exists"](real_name):
@@ -871,8 +872,9 @@ def crl_managed(
871872
if file_args.get("follow_symlinks", True):
872873
real_name = os.path.realpath(name)
873874
else:
874-
# workaround https://github.com/saltstack/salt/issues/31802
875-
__salt__["file.remove"](name)
875+
if not __opts__["test"]:
876+
# workaround https://github.com/saltstack/salt/issues/31802
877+
__salt__["file.remove"](name)
876878
replace = True
877879

878880
if __salt__["file.file_exists"](real_name):
@@ -1106,8 +1108,9 @@ def csr_managed(
11061108
if file_args.get("follow_symlinks", True):
11071109
real_name = os.path.realpath(name)
11081110
else:
1109-
# workaround https://github.com/saltstack/salt/issues/31802
1110-
__salt__["file.remove"](name)
1111+
if not __opts__["test"]:
1112+
# workaround https://github.com/saltstack/salt/issues/31802
1113+
__salt__["file.remove"](name)
11111114
replace = True
11121115

11131116
if __salt__["file.file_exists"](real_name):
@@ -1382,13 +1385,14 @@ def private_key_managed(
13821385
if file_args.get("follow_symlinks", True):
13831386
real_name = os.path.realpath(name)
13841387
else:
1385-
# workaround https://github.com/saltstack/salt/issues/31802
1386-
__salt__["file.remove"](name)
1388+
if not __opts__["test"]:
1389+
# workaround https://github.com/saltstack/salt/issues/31802
1390+
__salt__["file.remove"](name)
13871391
replace = True
13881392

13891393
file_exists = __salt__["file.file_exists"](real_name)
13901394

1391-
if file_exists and not new:
1395+
if file_exists and not (new or replace):
13921396
try:
13931397
current, current_encoding, _ = x509util.load_privkey(
13941398
real_name, passphrase=passphrase, get_encoding=True
@@ -1445,7 +1449,7 @@ def private_key_managed(
14451449
changes["keysize"] = check_keysize
14461450
if encoding != current_encoding:
14471451
changes["encoding"] = encoding
1448-
elif file_exists and new:
1452+
elif (file_exists and new) or replace:
14491453
changes["replaced"] = name
14501454
else:
14511455
changes["created"] = name

0 commit comments

Comments
 (0)