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
This commit is contained in:
Alexander Gordeev 2014-11-28 19:27:03 +03:00
parent 3ab2a665b5
commit 9da0b2b0b8
6 changed files with 9 additions and 11 deletions

View File

@ -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

View File

@ -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

View File

@ -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']
)

View File

@ -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):

View File

@ -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)

View File

@ -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",