diff --git a/lustre/tests/conf-sanity.sh b/lustre/tests/conf-sanity.sh index 6c3978ec323ac10e74843ff7fbe8eaaab6fb0c05..ea574417c25c0f19632b61d0357e560a9781594e 100644 --- a/lustre/tests/conf-sanity.sh +++ b/lustre/tests/conf-sanity.sh @@ -385,4 +385,54 @@ test_12() { } run_test 12 "lmc --batch, with single/double quote, backslash in batchfile" +test_13() { + OLDXMLCONFIG=$XMLCONFIG + XMLCONFIG="conf13-1.xml" + SECONDXMLCONFIG="conf13-2.xml" + + # check long uuid will be truncated properly and uniquely + echo "To generate XML configuration file(with long ost name): $XMLCONFIG" + [ -f "$XMLCONFIG" ] && rm -f $XMLCONFIG + do_lmc --add net --node localhost --nid localhost.localdomain --nettype tcp + do_lmc --add mds --node localhost --mds mds1_name_longer_than_31characters + do_lmc --add mds --node localhost --mds mds2_name_longer_than_31characters + if [ ! -f "$XMLCONFIG" ]; then + echo "Error:no file $XMLCONFIG created!" + return 1 + fi + EXPECTEDMDS1UUID="e_longer_than_31characters_UUID" + EXPECTEDMDS2UUID="longer_than_31characters_UUID_2" + FOUNDMDS1UUID=`awk -F"'" '/<mds uuid=/{print $2}' $XMLCONFIG | sed -n '1p'` + FOUNDMDS2UUID=`awk -F"'" '/<mds uuid=/{print $2}' $XMLCONFIG | sed -n '2p'` + if [ $EXPECTEDMDS1UUID != $FOUNDMDS1UUID ]; then + echo "Error:expected uuid for mds1: $EXPECTEDMDS1UUID; found: $FOUNDMDS1UUID" + return 1 + fi + if [ $EXPECTEDMDS2UUID != $FOUNDMDS2UUID ]; then + echo "Error:expected uuid for mds2: $EXPECTEDMDS2UUID; found: $FOUNDMDS2UUID" + return 1 + fi + echo "Success:long uuid truncated successfully and being unique." + + # check multiple invocations for lmc generate same XML configuration file + rm -f $XMLCONFIG + echo "Generate the first XML configuration file" + gen_config + echo "mv $XMLCONFIG to $SECONDXMLCONFIG" + mv $XMLCONFIG $SECONDXMLCONFIG || return $? + echo "Generate the second XML configuration file" + gen_config + if [ `diff $XMLCONFIG $SECONDXMLCONFIG | wc -l` -eq 0 ]; then + echo "Success:multiple invocations for lmc generate same XML file" + else + echo "Error: multiple invocations for lmc generate different XML file" + return 1 + fi + + rm -f $XMLCONFIG + rm -f $SECONDXMLCONFIG + XMLCONFIG=$OLDXMLCONFIG +} +run_test 13 "check new_uuid of lmc operating correctly" + equals_msg "Done" diff --git a/lustre/utils/lmc b/lustre/utils/lmc index 79ed60f2a4507065f5fdc5ad05977e3169fd79d4..f8dabf4854d6c280290030c51134d3778ef8f221 100755 --- a/lustre/utils/lmc +++ b/lustre/utils/lmc @@ -25,7 +25,7 @@ lmc - lustre configuration data manager """ -import sys, os, getopt, string, exceptions, random, re +import sys, os, getopt, string, exceptions, re import xml.dom.minidom from xml.dom.ext import PrettyPrint @@ -46,6 +46,7 @@ DEFAULT_PORT = 988 DEFAULT_STRIPE_SZ = 65536 DEFAULT_STRIPE_CNT = 1 DEFAULT_STRIPE_PATTERN = 0 +UUID_MAX_LENGTH = 31 def reference(): print """usage: lmc --add object [object parameters] @@ -226,11 +227,18 @@ def new_name(base): return ret def new_uuid(name): - ret_uuid = '%05x_%.19s_%05x%05x' % (int(random.random() * 1048576), - name, - int(random.random() * 1048576), - int(random.random() * 1048576)) - return ret_uuid[:36] + ctr = 2 + ret = "%s_UUID" % (name) + if len(ret) > UUID_MAX_LENGTH: + ret = ret[-UUID_MAX_LENGTH:] + while uuids.has_key(ret): + ret = "%s_UUID_%d" % (name, ctr) + ctr = 1 + ctr + if len(ret) > UUID_MAX_LENGTH: + ret = ret[-UUID_MAX_LENGTH:] + uuids[ret] = 1 + return ret + ldlm_name = 'ldlm' ldlm_uuid = 'ldlm_UUID' @@ -1124,15 +1132,6 @@ def main(): gen = GenConfig(doc) - # the PRNG is normally seeded with time(), which is not so good for starting # time-synchronized clusters - input = open('/dev/urandom', 'r') - if not input: - print 'Unable to open /dev/urandom!' - sys.exit(1) - seed = input.read(32) - input.close() - random.seed(seed) - if options.batch: fp = open(options.batch) batchCommands = fp.readlines()