From a6c56c6647fbf14f68ecbceec1b5fc70423a1314 Mon Sep 17 00:00:00 2001 From: Pierre Riteau Date: Mon, 19 Oct 2020 22:52:27 +0200 Subject: [PATCH] Force local connection for localhost Starting with Ansible 2.9.10, the "Collecting node facts" task in bifrost-configdrives-dynamic can fail because it tries to SSH to localhost, which may not be possible in some environments, such as Bifrost deployed as a container by Kolla. Change-Id: I1ed19e325db9396ff6b250e14c967ce90c785201 Story: 2008260 Task: 41118 --- bifrost/inventory.py | 2 +- bifrost/tests/functional/test_inventory_functional.py | 2 ++ bifrost/tests/unit/test_inventory.py | 3 ++- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/bifrost/inventory.py b/bifrost/inventory.py index 100fba494..1b785e28f 100755 --- a/bifrost/inventory.py +++ b/bifrost/inventory.py @@ -164,7 +164,7 @@ def _parse_config(): def _prepare_inventory(): - hostvars = {} + hostvars = {"127.0.0.1": {"ansible_connection": "local"}} groups = {} groups.update({'baremetal': {'hosts': []}}) groups.update({'localhost': {'hosts': ["127.0.0.1"]}}) diff --git a/bifrost/tests/functional/test_inventory_functional.py b/bifrost/tests/functional/test_inventory_functional.py index a0c775d33..7548a9905 100644 --- a/bifrost/tests/functional/test_inventory_functional.py +++ b/bifrost/tests/functional/test_inventory_functional.py @@ -53,6 +53,7 @@ class TestBifrostInventoryFunctional(base.TestCase): "host_groups": ["baremetal", "nova"]}}""".replace('\n', '') (groups, hostvars) = utils.bifrost_data_conversion( yaml.safe_dump(json.loads(str(expected_hostvars)))) + del hostvars['127.0.0.1'] self.assertDictEqual(json.loads(str(expected_hostvars)), hostvars) def test_minimal_json(self): @@ -66,4 +67,5 @@ ipmi_password":"ADMIN"}},"driver":"ipmi"}}""".replace('\n', '') ipmi_password":"ADMIN"}},"driver":"ipmi","addressing_mode": "dhcp","host_groups": ["baremetal"]}}""".replace('\n', '') (groups, hostvars) = utils.bifrost_data_conversion(input_json) + del hostvars['127.0.0.1'] self.assertDictEqual(json.loads(str(expected_json)), hostvars) diff --git a/bifrost/tests/unit/test_inventory.py b/bifrost/tests/unit/test_inventory.py index e685de281..dfefd2615 100644 --- a/bifrost/tests/unit/test_inventory.py +++ b/bifrost/tests/unit/test_inventory.py @@ -33,7 +33,8 @@ class TestBifrostInventoryUnit(base.TestCase): (groups, hostvars) = inventory._prepare_inventory() self.assertIn("baremetal", groups) self.assertIn("localhost", groups) - self.assertDictEqual(hostvars, {}) + self.assertDictEqual( + hostvars, {'127.0.0.1': {'ansible_connection': 'local'}}) localhost_value = dict(hosts=["127.0.0.1"]) self.assertDictEqual(localhost_value, groups['localhost'])