Repository: Azure/WALinuxAgent
Pull request #2365 (2021-09-22 12:24:14)

Add support for Flatcar Container Linux
<!-- DO NOT DELETE THIS TEMPLATE -->

## Description

This adds support Flatcar Container Linux, which is a fork of CoreOS Container Linux, and is compatible with it. We currently [carry a patch in our wa-linux-agent package](https://github.com/flatcar-linux/coreos-overlay/blob/main/app-emulation/wa-linux-agent/files/0001-Support-flatcar.patch), and now I'm trying to upstream it.

I wasn't sure if I also need to update the code in `bin/waagent2.0`, which seems to be an older version of the project, so for now I left it alone. Please let me know if it needs updating too.

<!--
Please add an informative description that covers that changes made by the pull request. 
This checklist is used to make sure that common issues in a pull request are addressed.
This will expedite the process of getting your pull request merged and avoid extra work on your part to fix issues discovered during the review process.
-->

---

### PR information
- [x] The title of the PR is clear and informative.
- [x] There are a small number of commits, each of which has an informative message. This means that previously merged commits do not appear in the history of the PR. For information on cleaning up the commits in your pull request, [see this page](https://github.com/Azure/azure-powershell/blob/master/documentation/development-docs/cleaning-up-commits.md).
- [x] If applicable, the PR references the bug/issue that it fixes in the description.
- [x] New Unit tests were added for the changes made

### Quality of Code and Contribution Guidelines
- [x] I have read the [contribution guidelines](https://github.com/Azure/WALinuxAgent/blob/master/.github/CONTRIBUTING.md).

microsoft-cla[bot]: [![CLA assistant check](https://cla.opensource.microsoft.com/pull/badge/not_signed)](https://cla.opensource.microsoft.com/Azure/WALinuxAgent?pullRequest=2365) <br/>Thank you for your submission, we really appreciate it. Like many open source projects, we ask that you sign our [Contributor License Agreement](https://cla.opensource.microsoft.com/Azure/WALinuxAgent?pullRequest=2365) before we can accept your contribution.<br/><br/>:x: krnowak [sign now](https://cla.opensource.microsoft.com/Azure/WALinuxAgent?pullRequest=2365)<br/><sub>You have signed the CLA already but the status is still pending? Let us [recheck](https://cla.opensource.microsoft.com/check/Azure/WALinuxAgent?pullRequest=2365) it.</sub>
krnowak: Updated.
codecov[bot]: # [Codecov](https://codecov.io/gh/Azure/WALinuxAgent/pull/2365?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Azure) Report
> Merging [#2365](https://codecov.io/gh/Azure/WALinuxAgent/pull/2365?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Azure) (e627c88) into [develop](https://codecov.io/gh/Azure/WALinuxAgent/commit/ea4268f2c0bd86f646751d085748177d891d5180?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Azure) (ea4268f) will **increase** coverage by `0.04%`.
> The diff coverage is `50.00%`.

[![Impacted file tree graph](https://codecov.io/gh/Azure/WALinuxAgent/pull/2365/graphs/tree.svg?width=650&height=150&src=pr&token=ae90E2KYCw&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Azure)](https://codecov.io/gh/Azure/WALinuxAgent/pull/2365?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Azure)

```diff
@@             Coverage Diff             @@
##           develop    #2365      +/-   ##
===========================================
+ Coverage    70.86%   70.91%   +0.04%     
===========================================
  Files           97       97              
  Lines        14100    14100              
  Branches      2031     2031              
===========================================
+ Hits          9992     9999       +7     
+ Misses        3659     3654       -5     
+ Partials       449      447       -2     
```


| [Impacted Files](https://codecov.io/gh/Azure/WALinuxAgent/pull/2365?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Azure) | Coverage Δ | |
|---|---|---|
| [azurelinuxagent/pa/deprovision/factory.py](https://codecov.io/gh/Azure/WALinuxAgent/pull/2365/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Azure#diff-YXp1cmVsaW51eGFnZW50L3BhL2RlcHJvdmlzaW9uL2ZhY3RvcnkucHk=) | `57.89% <0.00%> (ø)` | |
| [azurelinuxagent/common/osutil/factory.py](https://codecov.io/gh/Azure/WALinuxAgent/pull/2365/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Azure#diff-YXp1cmVsaW51eGFnZW50L2NvbW1vbi9vc3V0aWwvZmFjdG9yeS5weQ==) | `94.80% <100.00%> (ø)` | |
| [azurelinuxagent/common/event.py](https://codecov.io/gh/Azure/WALinuxAgent/pull/2365/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Azure#diff-YXp1cmVsaW51eGFnZW50L2NvbW1vbi9ldmVudC5weQ==) | `85.97% <0.00%> (+0.67%)` | :arrow_up: |
| [azurelinuxagent/ga/collect\_telemetry\_events.py](https://codecov.io/gh/Azure/WALinuxAgent/pull/2365/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Azure#diff-YXp1cmVsaW51eGFnZW50L2dhL2NvbGxlY3RfdGVsZW1ldHJ5X2V2ZW50cy5weQ==) | `91.09% <0.00%> (+1.36%)` | :arrow_up: |

------

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

larohra: DCR ok - https://tuxgold.corp.microsoft.com/job/AzLinux/job/DungeonCrawler/job/DungeonCrawler.larohra3/217/artifact/results/

Patch:
diff --git a/azurelinuxagent/common/osutil/factory.py b/azurelinuxagent/common/osutil/factory.py
index 5918304d..b5ee0b09 100644
--- a/azurelinuxagent/common/osutil/factory.py
+++ b/azurelinuxagent/common/osutil/factory.py
@@ -81,7 +81,7 @@ def _get_osutil(distro_name, distro_code_name, distro_version, distro_full_name)
     if distro_name == "kali":
         return DebianOSBaseUtil()
 
-    if distro_name == "coreos" or distro_code_name == "coreos":
+    if distro_name in ("flatcar", "coreos") or distro_code_name in ("flatcar", "coreos"):
         return CoreOSUtil()
 
     if distro_name in ("suse", "sle_hpc", "sles", "opensuse"):
diff --git a/azurelinuxagent/pa/deprovision/factory.py b/azurelinuxagent/pa/deprovision/factory.py
index 6197fc6a..2caedc8d 100644
--- a/azurelinuxagent/pa/deprovision/factory.py
+++ b/azurelinuxagent/pa/deprovision/factory.py
@@ -35,7 +35,7 @@ def get_deprovision_handler(distro_name=DISTRO_NAME,
             return Ubuntu1804DeprovisionHandler()
         else:
             return UbuntuDeprovisionHandler()
-    if distro_name == "coreos":
+    if distro_name in ("flatcar", "coreos"):
         return CoreOSDeprovisionHandler()
     if "Clear Linux" in distro_full_name:
         return ClearLinuxDeprovisionHandler()  # pylint: disable=E1120
diff --git a/setup.py b/setup.py
index 3a9cba3b..5c66a44c 100755
--- a/setup.py
+++ b/setup.py
@@ -123,7 +123,7 @@ def get_data_files(name, version, fullname):  # pylint: disable=R0912
         set_udev_files(data_files)
         set_systemd_files(data_files, dest=systemd_dir_path,
                           src=["init/arch/waagent.service"])
-    elif name == 'coreos':
+    elif name in ('coreos', 'flatcar'):
         set_bin_files(data_files, dest=agent_bin_path)
         set_conf_files(data_files, dest="/usr/share/oem",
                        src=["config/coreos/waagent.conf"])


Test patch:
diff --git a/tests/common/osutil/test_factory.py b/tests/common/osutil/test_factory.py
index 74cf8363..64effdee 100644
--- a/tests/common/osutil/test_factory.py
+++ b/tests/common/osutil/test_factory.py
@@ -142,6 +142,12 @@ class TestOsUtilFactory(AgentTestCase):
                           distro_full_name="")
         self.assertTrue(isinstance(ret, CoreOSUtil))
         self.assertEqual(ret.get_service_name(), "waagent")
+        ret = _get_osutil(distro_name="flatcar",
+                          distro_code_name="",
+                          distro_version="",
+                          distro_full_name="")
+        self.assertTrue(isinstance(ret, CoreOSUtil))
+        self.assertEqual(ret.get_service_name(), "waagent")
 
     def test_get_osutil_it_should_return_suse(self):
         ret = _get_osutil(distro_name="suse",
diff --git a/tests/tools.py b/tests/tools.py
index 64f1862d..cd16c089 100644
--- a/tests/tools.py
+++ b/tests/tools.py
@@ -452,6 +452,7 @@ supported_distro = [
     ["ubuntu", "15.10", "Snappy Ubuntu Core"],
 
     ["coreos", "", ""],
+    ["flatcar", "", ""],
 
     ["suse", "12", "SUSE Linux Enterprise Server"],
     ["suse", "13.2", "openSUSE"],