From 9da0b2b0b8fe273fab3836663c0f2cba1b075270 Mon Sep 17 00:00:00 2001 From: Alexander Gordeev Date: Fri, 28 Nov 2014 19:27:03 +0300 Subject: [PATCH] Handle arbitrary gw for node in fuel-agent Add what was missing. Default gateway could be not only equal to master IP. Closes-Bug: #1405664 Change-Id: I8f8a7a4a69ada5898a66b6211c185ad30b84a7e7 --- cloud-init-templates/boothook_centos.jinja2 | 8 ++------ cloud-init-templates/boothook_ubuntu.jinja2 | 4 +--- fuel_agent/drivers/nailgun.py | 1 + fuel_agent/objects/configdrive.py | 4 +++- fuel_agent/tests/test_configdrive.py | 2 +- fuel_agent/tests/test_nailgun.py | 1 + 6 files changed, 9 insertions(+), 11 deletions(-) diff --git a/cloud-init-templates/boothook_centos.jinja2 b/cloud-init-templates/boothook_centos.jinja2 index 11719a0..13f5ab3 100644 --- a/cloud-init-templates/boothook_centos.jinja2 +++ b/cloud-init-templates/boothook_centos.jinja2 @@ -21,17 +21,13 @@ cloud-init-per instance disable_selinux sed -i 's/^SELINUX=.*/SELINUX=disabled/g # udev persistent net cloud-init-per instance udev_persistent_net1 service network stop -DEFAULT_GW={{ common.master_ip }} ADMIN_MAC={{ common.admin_mac }} ADMIN_IF=$(echo {{ common.udevrules }} | sed 's/[,=]/\n/g' | grep "$ADMIN_MAC" | cut -d_ -f2 | head -1) -#NOTE: it will be broken, once ifconfig (net-tools) 2.0 or higher version of package be used -INSTALL_IF=$(ifconfig -a | grep "$ADMIN_MAC" | head -1 | cut -d' ' -f1) -NETADDR=( $(ifconfig $INSTALL_IF | grep -oP "[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}") ) if [ ! -z "$(grep $ADMIN_IF /etc/sysconfig/network-scripts/ifcfg-$ADMIN_IF | grep dhcp)" ] ; then - echo -e "# FROM COBBLER SNIPPET\nDEVICE=$ADMIN_IF\nIPADDR=${NETADDR[0]}\nNETMASK=${NETADDR[2]}\nBOOTPROTO=none\nONBOOT=yes\nUSERCTL=no\n" > /etc/sysconfig/network-scripts/ifcfg-"$ADMIN_IF" + echo -e "# FROM COBBLER SNIPPET\nDEVICE=$ADMIN_IF\nIPADDR={{ common.admin_ip }}\nNETMASK={{ common.admin_mask }}\nBOOTPROTO=none\nONBOOT=yes\nUSERCTL=no\n" > /etc/sysconfig/network-scripts/ifcfg-"$ADMIN_IF" fi -cloud-init-per instance set_gateway /bin/sh -c 'echo GATEWAY="{{ common.master_ip }}" | tee -a /etc/sysconfig/network' +cloud-init-per instance set_gateway /bin/sh -c 'echo GATEWAY="{{ common.gw }}" | tee -a /etc/sysconfig/network' cloud-init-per instance udev_persistent_net5 service network start diff --git a/cloud-init-templates/boothook_ubuntu.jinja2 b/cloud-init-templates/boothook_ubuntu.jinja2 index 3914d3c..74e8eb9 100644 --- a/cloud-init-templates/boothook_ubuntu.jinja2 +++ b/cloud-init-templates/boothook_ubuntu.jinja2 @@ -19,15 +19,13 @@ cloud-init-per instance udev_persistent_net1 /etc/init.d/networking stop ADMIN_MAC={{ common.admin_mac }} ADMIN_IF=$(echo {{ common.udevrules }} | sed 's/[,=]/\n/g' | grep "$ADMIN_MAC" | cut -d_ -f2 | head -1) -#NOTE: it will be broken, once ifconfig (net-tools) 2.0 or higher version of package be used -INSTALL_IF=$(ifconfig -a | grep "$ADMIN_MAC" | head -1 | cut -d' ' -f1) # Check if we do not already have static config (or interface seems unconfigured) if [ ! -d "/etc/network/interfaces.d" ]; then mkdir -p /etc/network/interfaces.d echo 'source /etc/network/interfaces.d/*' > /etc/network/interfaces fi if [ ! -e "/etc/network/interfaces.d/ifcfg-$ADMIN_IF" ]; then - echo -e "auto $ADMIN_IF\niface $ADMIN_IF inet static\n\taddress {{ common.admin_ip }}\n\tnetmask {{ common.admin_mask }}" > /etc/network/interfaces.d/ifcfg-"$ADMIN_IF" + echo -e "auto $ADMIN_IF\niface $ADMIN_IF inet static\n\taddress {{ common.admin_ip }}\n\tnetmask {{ common.admin_mask }}\n\tgateway {{ common.gw }}" > /etc/network/interfaces.d/ifcfg-"$ADMIN_IF" fi cloud-init-per instance udev_persistent_net5 /etc/init.d/networking start diff --git a/fuel_agent/drivers/nailgun.py b/fuel_agent/drivers/nailgun.py index ef723c5..060be84 100644 --- a/fuel_agent/drivers/nailgun.py +++ b/fuel_agent/drivers/nailgun.py @@ -321,6 +321,7 @@ class Nailgun(object): admin_mask=admin_interface['netmask'], admin_iface_name=admin_interface['name'], timezone=data['ks_meta'].get('timezone', 'America/Los_Angeles'), + gw=data['ks_meta']['gw'], ks_repos=data['ks_meta']['repo_setup']['repos'] ) diff --git a/fuel_agent/objects/configdrive.py b/fuel_agent/objects/configdrive.py index 3a67252..7336a8a 100644 --- a/fuel_agent/objects/configdrive.py +++ b/fuel_agent/objects/configdrive.py @@ -18,7 +18,8 @@ from fuel_agent import errors class ConfigDriveCommon(object): def __init__(self, ssh_auth_keys, hostname, fqdn, name_servers, search_domain, master_ip, master_url, udevrules, admin_mac, - admin_ip, admin_mask, admin_iface_name, timezone, ks_repos): + admin_ip, admin_mask, admin_iface_name, timezone, ks_repos, + gw): self.ssh_auth_keys = ssh_auth_keys self.hostname = hostname self.fqdn = fqdn @@ -33,6 +34,7 @@ class ConfigDriveCommon(object): self.admin_iface_name = admin_iface_name self.timezone = timezone self.ks_repos = ks_repos + self.gw = gw class ConfigDrivePuppet(object): diff --git a/fuel_agent/tests/test_configdrive.py b/fuel_agent/tests/test_configdrive.py index d474142..445b68a 100644 --- a/fuel_agent/tests/test_configdrive.py +++ b/fuel_agent/tests/test_configdrive.py @@ -45,7 +45,7 @@ class TestConfigDriveScheme(test_base.BaseTestCase): ['auth_key1', 'auth_key2'], 'hostname', 'fqdn', 'name_servers', 'search_domain', 'master_ip', 'master_url', 'udevrules', 'admin_mac', 'admin_ip', 'admin_mask', 'admin_iface_name', - 'timezone', {'repo1': 'repo1_url', 'repo2': 'repo2_url'}) + 'timezone', {'repo1': 'repo1_url', 'repo2': 'repo2_url'}, 'gw') cd_puppet = configdrive.ConfigDrivePuppet('master', 0) cd_mcollective = configdrive.ConfigDriveMcollective( 'pskey', 'vhost', 'host', 'user', 'password', 'connector', 1) diff --git a/fuel_agent/tests/test_nailgun.py b/fuel_agent/tests/test_nailgun.py index 2797024..b8b79c2 100644 --- a/fuel_agent/tests/test_nailgun.py +++ b/fuel_agent/tests/test_nailgun.py @@ -84,6 +84,7 @@ PROVISION_SAMPLE_DATA = { "power_address": "10.20.0.253", "name_servers": "\"10.20.0.2\"", "ks_meta": { + "gw": "10.20.0.1", "image_data": { "/": { "uri": "http://fake_image_url",