Repository: Azure/WALinuxAgent
Pull request #1949 (2020-07-17 16:38:21)

Convert owner uid to string
Convert owner uid to string before passing it to popen

codecov[bot]: # [Codecov](https://codecov.io/gh/Azure/WALinuxAgent/pull/1949?src=pr&el=h1) Report
> Merging [#1949](https://codecov.io/gh/Azure/WALinuxAgent/pull/1949?src=pr&el=desc) into [develop](https://codecov.io/gh/Azure/WALinuxAgent/commit/7e3eac100eb40baffb39a2510c36b66238948488&el=desc) will **increase** coverage by `0.02%`.
> The diff coverage is `100.00%`.

[![Impacted file tree graph](https://codecov.io/gh/Azure/WALinuxAgent/pull/1949/graphs/tree.svg?width=650&height=150&src=pr&token=ae90E2KYCw)](https://codecov.io/gh/Azure/WALinuxAgent/pull/1949?src=pr&el=tree)

```diff
@@             Coverage Diff             @@
##           develop    #1949      +/-   ##
===========================================
+ Coverage    69.62%   69.65%   +0.02%     
===========================================
  Files           85       85              
  Lines        11929    11925       -4     
  Branches      1667     1666       -1     
===========================================
  Hits          8306     8306              
+ Misses        3254     3251       -3     
+ Partials       369      368       -1     
```


| [Impacted Files](https://codecov.io/gh/Azure/WALinuxAgent/pull/1949?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [azurelinuxagent/common/osutil/default.py](https://codecov.io/gh/Azure/WALinuxAgent/pull/1949/diff?src=pr&el=tree#diff-YXp1cmVsaW51eGFnZW50L2NvbW1vbi9vc3V0aWwvZGVmYXVsdC5weQ==) | `59.19% <100.00%> (+0.27%)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/Azure/WALinuxAgent/pull/1949?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/Azure/WALinuxAgent/pull/1949?src=pr&el=footer). Last update [7e3eac1...bffae30](https://codecov.io/gh/Azure/WALinuxAgent/pull/1949?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


Patch:
diff --git a/azurelinuxagent/common/osutil/default.py b/azurelinuxagent/common/osutil/default.py
index 3ef6be17..161543ea 100644
--- a/azurelinuxagent/common/osutil/default.py
+++ b/azurelinuxagent/common/osutil/default.py
@@ -74,7 +74,7 @@ def _get_iptables_version_command():
 
 
 def _get_firewall_accept_command(wait, command, destination, owner_uid):
-    return _add_wait(wait, ["iptables", "-t", "security", command, "OUTPUT", "-d", destination, "-p", "tcp", "-m", "owner", "--uid-owner", owner_uid, "-j" "ACCEPT"])
+    return _add_wait(wait, ["iptables", "-t", "security", command, "OUTPUT", "-d", destination, "-p", "tcp", "-m", "owner", "--uid-owner", str(owner_uid), "-j" "ACCEPT"])
 
 
 def _get_firewall_drop_command(wait, command, destination):
@@ -96,7 +96,7 @@ def _get_firewall_delete_conntrack_accept_command(wait, destination):
 
 
 def _get_firewall_delete_owner_accept_command(wait, destination, owner_uid):
-    return _add_wait(wait, ["iptables", "-t", "security", "-D", "OUTPUT", "-d", destination, "-p", "tcp", "-m", "owner", "--uid-owner", owner_uid, "-j", "ACCEPT"])
+    return _add_wait(wait, ["iptables", "-t", "security", "-D", "OUTPUT", "-d", destination, "-p", "tcp", "-m", "owner", "--uid-owner", str(owner_uid), "-j", "ACCEPT"])
 
 def _get_firewall_delete_conntrack_drop_command(wait, destination):
     return _add_wait(wait, ["iptables", "-t", "security", "-D", "OUTPUT", "-d", destination, "-p", "tcp", "-m", "conntrack", "--ctstate", "INVALID,NEW", "-j", "DROP"])
@@ -203,18 +203,13 @@ class DefaultOSUtil(object):
                 if e.returncode == 2:
                     raise Exception("invalid firewall deletion rule '{0}'".format(rule))
 
-    def remove_firewall(self, dst_ip=None, uid=None):
+    def remove_firewall(self, dst_ip, uid):
         # If a previous attempt failed, do not retry
         global _enable_firewall
         if not _enable_firewall:
             return False
 
         try:
-            if dst_ip is None or uid is None:
-                msg = "Missing arguments to enable_firewall"
-                logger.warn(msg)
-                raise Exception(msg)
-
             wait = self.get_firewall_will_wait()
 
             # This rule was <= 2.2.25 only, and may still exist on some VMs.  Until 2.2.25


Test patch:
diff --git a/tests/common/osutil/test_default.py b/tests/common/osutil/test_default.py
index 100ff128..ecada3b5 100644
--- a/tests/common/osutil/test_default.py
+++ b/tests/common/osutil/test_default.py
@@ -636,7 +636,7 @@ Match host 192.168.1.2\n\
 
     @staticmethod
     def _command_to_string(command):
-        return " ".join([str(c) for c in command]) if isinstance(command, list) else command
+        return " ".join(command) if isinstance(command, list) else command
 
     @staticmethod
     @contextlib.contextmanager