summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTim Rozet <trozet@redhat.com>2018-05-23 16:51:48 -0400
committerTim Rozet <trozet@redhat.com>2018-05-31 17:52:54 +0000
commita4589fcbd106fa06555b1d83ba314029ff438e6a (patch)
treefdf57db778080c991ccfae67b371da674dd8244f
parentfd7f3285fa0d872f3eb23ded248e45bf720ebda7 (diff)
Configure NAT with baremetal when necessary
We currently only enable NAT on undercloud for virtual deployments. However, there could be a case where a baremetal deployment also needs NAT as it is not using an interface on the overcloud nodes with external access. Therefore this patch changes the behavior to configure NAT when the gateway of either the external or admin (when external is disabled) network matches an IP assigned to the undercloud. JIRA: APEX-605 Change-Id: I9c79af371913e6e5f0d39b433f68205bc7e106c5 Signed-off-by: Tim Rozet <trozet@redhat.com> (cherry picked from commit d0f4951e914cacd99c750cb04a332cd7251b9de8)
-rw-r--r--apex/tests/test_apex_undercloud.py100
-rw-r--r--apex/undercloud/undercloud.py13
-rw-r--r--lib/ansible/playbooks/configure_undercloud.yml2
3 files changed, 113 insertions, 2 deletions
diff --git a/apex/tests/test_apex_undercloud.py b/apex/tests/test_apex_undercloud.py
index fce7a55..9bc91e5 100644
--- a/apex/tests/test_apex_undercloud.py
+++ b/apex/tests/test_apex_undercloud.py
@@ -24,6 +24,7 @@ from nose.tools import (
assert_regexp_matches,
assert_raises,
assert_true,
+ assert_false,
assert_equal)
@@ -118,6 +119,105 @@ class TestUndercloud(unittest.TestCase):
@patch.object(Undercloud, 'generate_config', return_value={})
@patch.object(Undercloud, '_get_vm', return_value=None)
@patch.object(Undercloud, 'create')
+ def test_detect_nat_with_external(self, mock_create, mock_get_vm,
+ mock_generate_config, mock_utils):
+ ns = MagicMock()
+ ns.enabled_network_list = ['admin', 'external']
+ ns_dict = {
+ 'apex': MagicMock(),
+ 'dns-domain': 'dns',
+ 'networks': {'admin':
+ {'cidr': ipaddress.ip_network('192.0.2.0/24'),
+ 'installer_vm': {'ip': '192.0.2.1',
+ 'vlan': 'native'},
+ 'dhcp_range': ['192.0.2.15', '192.0.2.30'],
+ 'gateway': '192.1.1.1',
+ },
+ 'external':
+ [{'enabled': True,
+ 'cidr': ipaddress.ip_network('192.168.0.0/24'),
+ 'installer_vm': {'ip': '192.168.0.1',
+ 'vlan': 'native'},
+ 'gateway': '192.168.0.1'
+ }]
+ }
+ }
+ ns.__getitem__.side_effect = ns_dict.__getitem__
+ ns.__contains__.side_effect = ns_dict.__contains__
+
+ uc = Undercloud('img_path', 'tplt_path', external_network=True)
+ assert_true(uc.detect_nat(ns))
+
+ @patch('apex.undercloud.undercloud.utils')
+ @patch.object(Undercloud, 'generate_config', return_value={})
+ @patch.object(Undercloud, '_get_vm', return_value=None)
+ @patch.object(Undercloud, 'create')
+ def test_detect_nat_no_external(self, mock_create, mock_get_vm,
+ mock_generate_config, mock_utils):
+ ns = MagicMock()
+ ns.enabled_network_list = ['admin', 'external']
+ ns_dict = {
+ 'apex': MagicMock(),
+ 'dns-domain': 'dns',
+ 'networks': {'admin':
+ {'cidr': ipaddress.ip_network('192.0.2.0/24'),
+ 'installer_vm': {'ip': '192.0.2.1',
+ 'vlan': 'native'},
+ 'dhcp_range': ['192.0.2.15', '192.0.2.30'],
+ 'gateway': '192.0.2.1',
+ },
+ 'external':
+ [{'enabled': False,
+ 'cidr': ipaddress.ip_network('192.168.0.0/24'),
+ 'installer_vm': {'ip': '192.168.0.1',
+ 'vlan': 'native'},
+ 'gateway': '192.168.1.1'
+ }]
+ }
+ }
+ ns.__getitem__.side_effect = ns_dict.__getitem__
+ ns.__contains__.side_effect = ns_dict.__contains__
+
+ uc = Undercloud('img_path', 'tplt_path', external_network=False)
+ assert_true(uc.detect_nat(ns))
+
+ @patch('apex.undercloud.undercloud.utils')
+ @patch.object(Undercloud, 'generate_config', return_value={})
+ @patch.object(Undercloud, '_get_vm', return_value=None)
+ @patch.object(Undercloud, 'create')
+ def test_detect_no_nat_no_external(self, mock_create, mock_get_vm,
+ mock_generate_config, mock_utils):
+ ns = MagicMock()
+ ns.enabled_network_list = ['admin', 'external']
+ ns_dict = {
+ 'apex': MagicMock(),
+ 'dns-domain': 'dns',
+ 'networks': {'admin':
+ {'cidr': ipaddress.ip_network('192.0.2.0/24'),
+ 'installer_vm': {'ip': '192.0.2.1',
+ 'vlan': 'native'},
+ 'dhcp_range': ['192.0.2.15', '192.0.2.30'],
+ 'gateway': '192.0.2.3',
+ },
+ 'external':
+ [{'enabled': False,
+ 'cidr': ipaddress.ip_network('192.168.0.0/24'),
+ 'installer_vm': {'ip': '192.168.0.1',
+ 'vlan': 'native'},
+ 'gateway': '192.168.1.1'
+ }]
+ }
+ }
+ ns.__getitem__.side_effect = ns_dict.__getitem__
+ ns.__contains__.side_effect = ns_dict.__contains__
+
+ uc = Undercloud('img_path', 'tplt_path', external_network=False)
+ assert_false(uc.detect_nat(ns))
+
+ @patch('apex.undercloud.undercloud.utils')
+ @patch.object(Undercloud, 'generate_config', return_value={})
+ @patch.object(Undercloud, '_get_vm', return_value=None)
+ @patch.object(Undercloud, 'create')
def test_configure(self, mock_create, mock_get_vm,
mock_generate_config, mock_utils):
uc = Undercloud('img_path', 'tplt_path', external_network=True)
diff --git a/apex/undercloud/undercloud.py b/apex/undercloud/undercloud.py
index d76174b..d466e2e 100644
--- a/apex/undercloud/undercloud.py
+++ b/apex/undercloud/undercloud.py
@@ -125,6 +125,16 @@ class Undercloud:
"Unable to find IP for undercloud. Check if VM booted "
"correctly")
+ def detect_nat(self, net_settings):
+ if self.external_net:
+ net = net_settings['networks'][constants.EXTERNAL_NETWORK][0]
+ else:
+ net = net_settings['networks'][constants.ADMIN_NETWORK]
+ if net['gateway'] == net['installer_vm']['ip']:
+ return True
+ else:
+ return False
+
def configure(self, net_settings, deploy_settings,
playbook, apex_temp_dir, virtual_oc=False):
"""
@@ -142,7 +152,8 @@ class Undercloud:
ansible_vars = Undercloud.generate_config(net_settings,
deploy_settings)
ansible_vars['apex_temp_dir'] = apex_temp_dir
- ansible_vars['virtual_overcloud'] = virtual_oc
+
+ ansible_vars['nat'] = self.detect_nat(net_settings)
try:
utils.run_ansible(ansible_vars, playbook, host=self.ip,
user='stack')
diff --git a/lib/ansible/playbooks/configure_undercloud.yml b/lib/ansible/playbooks/configure_undercloud.yml
index fbac6ee..adf463a 100644
--- a/lib/ansible/playbooks/configure_undercloud.yml
+++ b/lib/ansible/playbooks/configure_undercloud.yml
@@ -174,7 +174,7 @@
become: yes
when:
- not nat_network_ipv6
- - virtual_overcloud
+ - nat
- name: fetch storage environment file
fetch:
src: /usr/share/openstack-tripleo-heat-templates/environments/storage-environment.yaml