From fcef114eb5749d9978c15712a4c50ef84ce698e4 Mon Sep 17 00:00:00 2001 From: Rawan Herzallah Date: Tue, 3 May 2016 06:38:41 +0000 Subject: [PATCH] Enhanced create_mellanox_bootstrap script Added arg parser, changed script name and removed adding intel_iommu parameter as plugin forces user to add it now. Change-Id: I4a15ca4a67290ebdb764cedc543ca2afe8f158af --- metadata.yaml | 2 +- post_install.sh | 4 +- ...pi_bootstrap => create_mellanox_bootstrap} | 51 +++++++++---------- uninstall.sh | 17 +++---- 4 files changed, 34 insertions(+), 40 deletions(-) rename scripts/{create_mellanox_vpi_bootstrap => create_mellanox_bootstrap} (70%) diff --git a/metadata.yaml b/metadata.yaml index 03fdb20..6b25f3d 100644 --- a/metadata.yaml +++ b/metadata.yaml @@ -5,7 +5,7 @@ name: mellanox-plugin title: Mellanox ConnectX-4 Openstack Features # Plugin version -version: 3.1.1 +version: 3.1.4 # Description description: Enable features over Mellanox ConnectX-4 Adapters diff --git a/post_install.sh b/post_install.sh index f1d5a9e..b758bc8 100644 --- a/post_install.sh +++ b/post_install.sh @@ -7,12 +7,12 @@ if [ -d $FUEL_BOOTSTRAP_DIR ]; then # Add bootstrap scripts to Fuel Master \cp $PLUGIN_SCRIPTS_DIR/reboot_bootstrap_nodes \ - $PLUGIN_SCRIPTS_DIR/create_mellanox_vpi_bootstrap \ + $PLUGIN_SCRIPTS_DIR/create_mellanox_bootstrap \ /sbin/ # Print post install message echo " `tput bold`In order to create Bootstrap discovery image for detecting Mellanox Infiniband HW:" - echo " 1. Please build a new bootstrap ('create_mellanox_vpi_bootstrap can be used')." + echo " 1. Please build a new bootstrap ('create_mellanox_bootstrap [--link_type] [-h, --help] can be used')." echo " 2. Please reboot your old bootstrap nodes" echo " ('reboot_bootstrap_nodes [-e environment_id] [-a] [-h]' can be used).`tput sgr0`" diff --git a/scripts/create_mellanox_vpi_bootstrap b/scripts/create_mellanox_bootstrap similarity index 70% rename from scripts/create_mellanox_vpi_bootstrap rename to scripts/create_mellanox_bootstrap index 4733e1f..8165c6f 100755 --- a/scripts/create_mellanox_vpi_bootstrap +++ b/scripts/create_mellanox_bootstrap @@ -19,26 +19,30 @@ import os import time import subprocess import sys +import argparse +import textwrap -# Verify input -if len(sys.argv) > 1 and (sys.argv[1] == 'eth' or sys.argv[1] == 'ib' or \ - sys.argv[1] == 'default_link_type' ): - if 'default_link_type' in sys.argv[1]: - link_type = 'eth' - else: - link_type = "_%s" % sys.argv[1] -elif len(sys.argv) == 1: - link_type = "" +parser = argparse.ArgumentParser( + prog='PROG', + formatter_class=argparse.RawDescriptionHelpFormatter, + description=textwrap.dedent('''\ + Available link_type values are: + ------------------------------- + - eth for changing link type to Ethernet + - ib for changing link type to Infiniband + - current for leaving link type as is + ''')) +parser.add_argument("--link_type", choices=['eth', 'ib', 'current']) + +args = parser.parse_args() +if not args.link_type: + parser.print_help() + sys.exit(1) else: - basename = os.path.basename(sys.argv[0]) - print "Wrong usage." - print "Usage: %s " % basename - print " Valid link type: eth,ib" - print " option 1: %s" % basename - print " option 2: %s eth" % basename - print " option 3: %s ib" % basename - print " option 4: %s default_link_type" % basename - exit(1) + if 'current' in args.link_type: + link_type="" + else: + link_type = "_{0}".format(args.link_type) # Set variables plugin = subprocess.Popen("echo /var/www/nailgun/plugins/mellanox-plugin-*/ " + @@ -61,16 +65,7 @@ with open("/etc/fuel-bootstrap-cli/fuel_bootstrap_cli.yaml", 'r') as stream: 'section': None, 'type': 'deb', 'uri': plugin_uri}) - override = True - - # Verify SR-IOV capabilities - if 'intel_iommu=on' not in fuel_bootstrap_config['extend_kopts']: - fuel_bootstrap_config['extend_kopts'] = fuel_bootstrap_config['extend_kopts'] \ - + ' intel_iommu=on' - override = True - - # Override fuel bootstrap yaml if needed - if override: + # Override fuel bootstrap yaml with open("/etc/fuel-bootstrap-cli/fuel_bootstrap_cli.yaml", "w") as f: yaml.dump(fuel_bootstrap_config, f) diff --git a/uninstall.sh b/uninstall.sh index d584e2e..8becd81 100644 --- a/uninstall.sh +++ b/uninstall.sh @@ -1,3 +1,5 @@ +EXTRA_SCRIPTS="/sbin/reboot_bootstrap_node + /sbin/create_mellanox_bootstrap" # Verify run is over Fuel Master and we are not During upgrade if [ -d $FUEL_BOOTSTRAP_DIR ] && [ $1 -eq 0 ]; then @@ -16,13 +18,10 @@ if [ -d $FUEL_BOOTSTRAP_DIR ] && [ $1 -eq 0 ]; then mv $ORIG_BOOTSTRAP_CLI_YAML $BOOTSTRAP_CLI_YAML fi - # Remove extra scripts - if [ -f "/sbin/reboot_bootstrap_nodes" ]; then - \rm /sbin/reboot_bootstrap_nodes - fi - - if [ -f "/sbin/create_mellanox_vpi_bootstrap" ]; then - \rm /sbin/create_mellanox_vpi_bootstrap - fi - + for script in $EXTRA_SCRIPTS; do + # Remove extra scripts + if [ -e $script ]; then + \rm $script + fi + done fi