From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Daniel P. Berrange" Subject: Re: PATCH: Fix name uniqueness check Date: Mon, 1 Oct 2007 23:12:16 +0100 Message-ID: <20071001221216.GA5866@redhat.com> References: <20070927204023.GQ17433@redhat.com> <20071001135718.GA11414@redhat.com> <20071001181811.GH11414@redhat.com> Reply-To: "Daniel P. Berrange" Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="AqsLC8rIMeq19msA" Return-path: Content-Disposition: inline In-Reply-To: <20071001181811.GH11414@redhat.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: Keir Fraser Cc: Jim Fehlig , xen-devel@lists.xensource.com, Masaki Kanno List-Id: xen-devel@lists.xenproject.org --AqsLC8rIMeq19msA Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Mon, Oct 01, 2007 at 07:18:11PM +0100, Daniel P. Berrange wrote: > There are 6 basic test cases: > > a. same name + same UUID: > b. diff name + same UUID: > c. same name + diff UUID: > d. diff name + diff UUID: > e. same name + no UUID: > f. diff name + no UUID: > > These need to be tested with 'xm create' and 'xm new', and all tests need to > be done with the pre-existing VM both inactive, and active. So, to 6 tests under 4 scenarios, gives 24 combinations. NB in the list above from my previous mail I flipped some letters compared to my actual testsuite - so pay attention to the letters used below, not the ones above. UUID is the primary unique key for VMs. Name is the secondary unique key. The former takes priority, eg redefining with existing UUID, but different name causes a rename in the config stored. - Scenario 1: xm new + existing inactive vm a. same name + same UUID: ALLOW (redefine) b. same name + diff UUID: REJECT (clashing name) c. diff name + same UUID: ALLOW (redefine+rename) d. diff name + diff UUID: ALLOW (define) e. same name + no UUID: REJECT (clashing name) f. diff name + no UUID: ALLOW (define) - Scenario 2: xm create + existing inactive vm a. same name + same UUID: ALLOW (create) b. same name + diff UUID: REJECT (clashing name) c. diff name + same UUID: ALLOW (create) d. diff name + diff UUID: ALLOW (create) e. same name + no UUID: REJECT (clashing name) f. diff name + no UUID: ALLOW (create) - Scenario 3: xm new + existing active vm a. same name + same UUID: ALLOW (redefine) b. same name + diff UUID: REJECT (clashing name) c. diff name + same UUID: ALLOW (redefine+rename) d. diff name + diff UUID: ALLOW (define) e. same name + no UUID: REJECT (clashing name) f. diff name + no UUID: ALLOW (define) - Scenario 4: xm create + existing active vm a. same name + same UUID: REJECT (clashing name/uuid) b. same name + diff UUID: REJECT (clashing name) c. diff name + same UUID: REJECT (clashing uuid) d. diff name + diff UUID: REJECT (disk image in use) e. same name + no UUID: REJECT (clashing name) f. diff name + no UUID: REJECT (disk image in use) Basically the allow/reject rules at the same for the first 3 scenarios. The reject scnarios are dealt with by the _checkName() function in the XendDomainInfo class. Only in the last one do we have to reject all combos more aggressively. This is because if you 'xm create' the same VM with identical details it wouldn't be stopped by the hotplug disk checks in all cases. This is not possible to validate from _checkName() since it does not have enough context to know that the new VM is about to be started. So we have to make extra checks in the 'create()' function in XendDomainInfo I am attaching a file 'test.sh' which creates a test VM & configs and runs through all these 24 scenarios. Feel free to add this to XenD's regression test suite if practical. So the actual patches needed... In 3.1-testing - Revert 15168:a717cb2fac90 (aka pull in 15973:8817a53c030f from xen-unstable.hg). This addresses scenarios 1-3 above - Apply the 'xen-create-name-uniqueness.patch' which adds a check to XendDomainInfo.create() to deal with special needs of scenario 4 In xen-unstable - Revert 15642:207582c8d88b (this patch is now bogus since 15168:a717cb2fac90 is already reverted by 15973:8817a53c030f). It only covered 'xm new' where as proposed patches cover 'xm new' and 'xm create' together - Apply the 'xen-create-name-uniqueness.patch' which adds a check to XendDomainInfo.create() to deal with special needs of scenario 4 I don't have a xen-unstable.hg box currently, so my testing of these patches has been against the 3.1-testing.hg tree. The 'test.sh' script should be able to validate them for unstable. BTW, run test.sh with /etc/xen as CWD. Signed-off-by: Daniel P. Berrange Regards, Dan. -- |=- Red Hat, Engineering, Emerging Technologies, Boston. +1 978 392 2496 -=| |=- Perl modules: http://search.cpan.org/~danberr/ -=| |=- Projects: http://freshmeat.net/~danielpb/ -=| |=- GnuPG: 7D3B9505 F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 -=| --AqsLC8rIMeq19msA Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="xen-create-name-uniqueness.patch" diff -r 687ce253a0f4 tools/python/xen/xend/XendDomainInfo.py --- a/tools/python/xen/xend/XendDomainInfo.py Wed Sep 26 10:05:02 2007 +0100 +++ b/tools/python/xen/xend/XendDomainInfo.py Mon Oct 01 17:07:43 2007 -0400 @@ -74,9 +74,15 @@ def create(config): @return: An up and running XendDomainInfo instance @raise VmError: Invalid configuration or failure to start. """ - + from xen.xend import XendDomain + domconfig = XendConfig.XendConfig(sxp_obj = config) + othervm = XendDomain.instance().domain_lookup_nr(domconfig["name_label"]) + if othervm is None or othervm.domid is None: + othervm = XendDomain.instance().domain_lookup_nr(domconfig["uuid"]) + if othervm is not None and othervm.domid is not None: + raise VmError("Domain '%s' already exists with ID '%d'" % (domconfig["name_label"], othervm.domid)) log.debug("XendDomainInfo.create(%s)", scrub_password(config)) - vm = XendDomainInfo(XendConfig.XendConfig(sxp_obj = config)) + vm = XendDomainInfo(domconfig) try: vm.start() except: --AqsLC8rIMeq19msA Content-Type: application/x-sh Content-Disposition: attachment; filename="test.sh" Content-Transfer-Encoding: quoted-printable =0AQUIET=3D1=0AUUID=3D"1112222-3333-4444-5555-666677778888"=0ANAME=3D"testn= ame"=0ABOOTLOADER=3D"/usr/bin/pygrub"=0ADISK=3D"/var/lib/xen/images/$NAME.i= mg"=0AMEM=3D"500"=0A=0A# base config=0Acat < $NAME=0Amemory=3D"$MEM"= =0Aname=3D"$NAME"=0Auuid=3D"0$UUID"=0Abootloader=3D"$BOOTLOADER"=0Adisk=3D[= "file:$DISK,xvda,w"]=0AEOF=0A=0A# a. same name + same uuid=0Acat < $N= AME-a=0Amemory=3D"$MEM"=0Aname=3D"$NAME"=0Auuid=3D"0$UUID"=0Abootloader=3D"= $BOOTLOADER"=0Adisk=3D["file:$DISK,xvda,w"]=0AEOF=0A=0A# b. same name + dif= f uuid=0Acat < $NAME-b=0Amemory=3D"$MEM"=0Aname=3D"$NAME"=0Auuid=3D"b= $UUID"=0Abootloader=3D"$BOOTLOADER"=0Adisk=3D["file:$DISK,xvda,w"]=0AEOF=0A= =0A=0A# c. diff name + same uuid=0Acat < $NAME-c=0Amemory=3D"$MEM"=0A= name=3D"$NAME-c"=0Auuid=3D"0$UUID"=0Abootloader=3D"$BOOTLOADER"=0Adisk=3D["= file:$DISK,xvda,w"]=0AEOF=0A=0A# d. diff name + diff uuid=0Acat < $NA= ME-d=0Amemory=3D"$MEM"=0Aname=3D"$NAME-d"=0Auuid=3D"d$UUID"=0Abootloader=3D= "$BOOTLOADER"=0Adisk=3D["file:$DISK,xvda,w"]=0AEOF=0A=0A# e. same name + no= uuid=0Acat < $NAME-e=0Amemory=3D"$MEM"=0Aname=3D"$NAME"=0Abootloader= =3D"$BOOTLOADER"=0Adisk=3D["file:$DISK,xvda,w"]=0AEOF=0A=0A# f. diff name += no uuid=0Acat < $NAME-f=0Amemory=3D"$MEM"=0Aname=3D"$NAME"=0Auuid=3D= "0$UUID"=0Abootloader=3D"$BOOTLOADER"=0Adisk=3D["file:$DISK,xvda,w"]=0AEOF= =0A=0Afunction invoke=0A{=0A # Either new or create to setup base VM state= =0A INITIAL=3D$1=0A # Either new or create to detail test state=0A ACTIO= N=3D$2=0A # Name postfix for test config=0A POSTFIX=3D$3=0A=0A # Setup t= he pre-existing base VM=0A if [ $QUIET -eq 1 ]=0A then=0A xm $INITIAL = $NAME 1>/dev/null 2>&1=0A else=0A xm $INITIAL $NAME=0A fi=0A sleep 1= =0A=0A # Try our test action=0A if [ $QUIET -eq 1 ]=0A then=0A xm $AC= TION $NAME-$POSTFIX 1>/dev/null 2>&1=0A else=0A xm $ACTION $NAME-$POSTF= IX=0A fi=0A RET=3D$?=0A=0A # Cleanup taking account of possible unexpect= ed behaviours=0A xm destroy $NAME 1>/dev/null 2>&1=0A xm destroy $NAME-$P= OSTFIX 1>/dev/null 2>&1=0A xm delete $NAME 1>/dev/null 2>&1=0A xm delete = $NAME-$POSTFIX 1>/dev/null 2>&1=0A # Hack - XenD sometimes takes a while t= o notice a VM has done=0A # Running 'list' makes it notice quicker it seem= s...=0A xm list 1>/dev/null 2>&1=0A sleep 1=0A}=0A=0Afunction allow=0A{= =0A echo -n "Allow xm $2 $NAME-$3 "=0A invoke $1 $2 $3=0A if [ $RET -eq = 0 ]=0A then=0A echo "[OK]"=0A else=0A echo "[FAIL]"=0A fi=0A}=0A= =0Afunction reject=0A{=0A echo -n "Reject xm $2 $NAME-$3 "=0A invoke $1 $= 2 $3=0A if [ $RET -ne 0 ]=0A then=0A echo "[OK]"=0A else=0A echo "= [FAIL]"=0A fi=0A}=0A=0A=0A# xm new + vm not runnning=0Afunction part1=0A{= =0A echo=0A echo "Part 1: xm new + inactive VM"=0A echo=0A allow new ne= w a=0A # Fail due to dup name + diff uuid=0A reject new new b=0A allow n= ew new c=0A allow new new d=0A # Fail due to dup name + diff uuid=0A rej= ect new new e=0A allow new new f=0A}=0A=0Afunction part2=0A{=0A echo=0A = echo "Part 2: xm create + inactive VM"=0A echo=0A allow new create a=0A = # Fail due to dup name + diff uuid=0A reject new create b=0A allow new cr= eate c=0A allow new create d=0A # Fail due to dup name + diff uuid=0A re= ject new create e=0A allow new create f=0A}=0A=0Afunction part3=0A{=0A ec= ho=0A echo "Part 3: xm new + active VM"=0A echo=0A allow create new a=0A= # Fail due to dup name + diff uuid=0A reject create new b=0A allow crea= te new c=0A allow create new d=0A # Fail due to dup name + diff uuid=0A = reject create new e=0A allow create new f=0A}=0A=0Afunction part4=0A{=0A = echo=0A echo "Part 4: xm create + active VM"=0A echo=0A # Fail due to du= p name + dup UUID=0A reject create create a=0A # Fail due to dup name + d= iff uuid=0A reject create create b=0A # Fail due to diff name + dup uuid= =0A reject create create c=0A # Fail due to disk re-use=0A reject create= create d=0A # Fail due to dup name + diff uuid=0A reject create create e= =0A # Fail due to disk re-use=0A reject create create f=0A}=0A=0A# xm new= + vm not runnning=0Apart1=0A# xm create + vm not runnning=0Apart2=0A# xm n= ew + vm runnning=0Apart3=0A# xm create + vm runnning=0Apart4=0A=0Arm -f $NA= ME $NAME-? --AqsLC8rIMeq19msA Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel --AqsLC8rIMeq19msA--