diff --git a/src/pyinfra/operations/selinux.py b/src/pyinfra/operations/selinux.py index e0a9104f2..104f1a9b5 100644 --- a/src/pyinfra/operations/selinux.py +++ b/src/pyinfra/operations/selinux.py @@ -169,7 +169,7 @@ def port(protocol: Protocol | str, port_num: int, se_type: str | None = None, pr current = host.get_fact(SEPort, protocol=protocol, port=port_num) else: port_info = host.get_fact(SEPorts) - current = port_info.get(protocol, {}).get(str(port_num), "") + current = port_info.get(protocol, {}).get(port_num, "") if present: option = "-a" if current == "" else ("-m" if current != se_type else "") @@ -187,4 +187,4 @@ def port(protocol: Protocol | str, port_num: int, se_type: str | None = None, pr if not direct_get: if protocol not in port_info: port_info[protocol] = {} - port_info[protocol][str(port_num)] = new_type + port_info[protocol][port_num] = new_type diff --git a/tests/operations/selinux.port/add_different.json b/tests/operations/selinux.port/add_different.json deleted file mode 100644 index e126cc763..000000000 --- a/tests/operations/selinux.port/add_different.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "args": ["tcp", 22, "ssh_port_t"], - "kwargs": { - "present":true - }, - "facts": { - "selinux.SEPorts": { - "tcp": { - "22": "xray_port_t" - } - }, - "server.Which": { - "command=sepolicy": null - } - }, - "commands": [ - "semanage port -m -t ssh_port_t -p tcp 22" - ] -} diff --git a/tests/operations/selinux.port/add_different.yaml b/tests/operations/selinux.port/add_different.yaml new file mode 100644 index 000000000..46a24e116 --- /dev/null +++ b/tests/operations/selinux.port/add_different.yaml @@ -0,0 +1,14 @@ +args: + - tcp + - 22 + - ssh_port_t +kwargs: + present: true +facts: + selinux.SEPorts: + tcp: + 22: xray_port_t + server.Which: + command=sepolicy: null +commands: + - semanage port -m -t ssh_port_t -p tcp 22 diff --git a/tests/operations/selinux.port/add_not_existing.json b/tests/operations/selinux.port/add_not_existing.json deleted file mode 100644 index ac8d04244..000000000 --- a/tests/operations/selinux.port/add_not_existing.json +++ /dev/null @@ -1,17 +0,0 @@ -{ - "args": ["tcp", 22, "ssh_port_t"], - "kwargs": { - "present":true - }, - "facts": { - "selinux.SEPorts": { - "tcp": {"22": ""} - }, - "server.Which": { - "command=sepolicy": null - } - }, - "commands": [ - "semanage port -a -t ssh_port_t -p tcp 22" - ] -} diff --git a/tests/operations/selinux.port/add_not_existing.yaml b/tests/operations/selinux.port/add_not_existing.yaml new file mode 100644 index 000000000..3ab554207 --- /dev/null +++ b/tests/operations/selinux.port/add_not_existing.yaml @@ -0,0 +1,14 @@ +args: + - tcp + - 22 + - ssh_port_t +kwargs: + present: true +facts: + selinux.SEPorts: + tcp: + 22: "" + server.Which: + command=sepolicy: null +commands: + - semanage port -a -t ssh_port_t -p tcp 22 diff --git a/tests/operations/selinux.port/add_not_existing_protocol.json b/tests/operations/selinux.port/add_not_existing_protocol.json deleted file mode 100644 index b8d0184b6..000000000 --- a/tests/operations/selinux.port/add_not_existing_protocol.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "args": ["tcp", 22, "ssh_port_t"], - "kwargs": { - "present":true - }, - "facts": { - "selinux.SEPorts": { - "udp": {"53": "dns_port_t"} - }, - "server.Which": { - "command=sepolicy": null - } - }, - "commands": ["semanage port -a -t ssh_port_t -p tcp 22"] -} diff --git a/tests/operations/selinux.port/add_not_existing_protocol.yaml b/tests/operations/selinux.port/add_not_existing_protocol.yaml new file mode 100644 index 000000000..9c36891c4 --- /dev/null +++ b/tests/operations/selinux.port/add_not_existing_protocol.yaml @@ -0,0 +1,14 @@ +args: + - tcp + - 22 + - ssh_port_t +kwargs: + present: true +facts: + selinux.SEPorts: + udp: + 53: dns_port_t + server.Which: + command=sepolicy: null +commands: + - semanage port -a -t ssh_port_t -p tcp 22 diff --git a/tests/operations/selinux.port/add_same.json b/tests/operations/selinux.port/add_same.json deleted file mode 100644 index 4d85b56af..000000000 --- a/tests/operations/selinux.port/add_same.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "args": ["tcp", 22, "ssh_port_t"], - "kwargs": { - "present":true - }, - "facts": { - "selinux.SEPorts": { - "tcp": {"22": "ssh_port_t"} - }, - "server.Which": { - "command=sepolicy": null - } - }, - "commands": [], - "noop_description": "setype for 'tcp/22' is already 'ssh_port_t'" -} diff --git a/tests/operations/selinux.port/add_same.yaml b/tests/operations/selinux.port/add_same.yaml new file mode 100644 index 000000000..2a605031e --- /dev/null +++ b/tests/operations/selinux.port/add_same.yaml @@ -0,0 +1,14 @@ +args: + - tcp + - 22 + - ssh_port_t +kwargs: + present: true +facts: + selinux.SEPorts: + tcp: + 22: ssh_port_t + server.Which: + command=sepolicy: null +commands: [] +noop_description: "setype for 'tcp/22' is already 'ssh_port_t'" diff --git a/tests/operations/selinux.port/remove_existing.json b/tests/operations/selinux.port/remove_existing.json deleted file mode 100644 index 416c2404a..000000000 --- a/tests/operations/selinux.port/remove_existing.json +++ /dev/null @@ -1,17 +0,0 @@ -{ - "args": ["tcp", 22, "ssh_port_t"], - "kwargs": { - "present":false - }, - "facts": { - "selinux.SEPorts": { - "tcp": {"22": "ssh_port_t"} - }, - "server.Which": { - "command=sepolicy": null - } - }, - "commands": [ - "semanage port -d -p tcp 22" - ] -} diff --git a/tests/operations/selinux.port/remove_existing.yaml b/tests/operations/selinux.port/remove_existing.yaml new file mode 100644 index 000000000..7bf3861ef --- /dev/null +++ b/tests/operations/selinux.port/remove_existing.yaml @@ -0,0 +1,14 @@ +args: + - tcp + - 22 + - ssh_port_t +kwargs: + present: false +facts: + selinux.SEPorts: + tcp: + 22: ssh_port_t + server.Which: + command=sepolicy: null +commands: + - semanage port -d -p tcp 22 diff --git a/tests/operations/selinux.port/remove_not_existing.json b/tests/operations/selinux.port/remove_not_existing.json deleted file mode 100644 index 118fe3252..000000000 --- a/tests/operations/selinux.port/remove_not_existing.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "args": ["tcp", 22, "ssh_port_t"], - "kwargs": { - "present": false - }, - "facts": { - "selinux.SEPorts": { - "port=22, protocol=tcp": {"22": ""} - }, - "server.Which": { - "command=sepolicy": null - } - }, - "commands": [], - "noop_description": "setype for 'tcp/22' is already unset" -} diff --git a/tests/operations/selinux.port/remove_not_existing.yaml b/tests/operations/selinux.port/remove_not_existing.yaml new file mode 100644 index 000000000..70fba09a8 --- /dev/null +++ b/tests/operations/selinux.port/remove_not_existing.yaml @@ -0,0 +1,14 @@ +args: + - tcp + - 22 + - ssh_port_t +kwargs: + present: false +facts: + selinux.SEPorts: + port=22, protocol=tcp: + 22: "" + server.Which: + command=sepolicy: null +commands: [] +noop_description: "setype for 'tcp/22' is already unset"