From 0cce5c44c2731cb611241e253d4b66f5eeffa99d Mon Sep 17 00:00:00 2001 From: Jessica Wang Date: Fri, 19 Aug 2011 15:04:39 -0700 Subject: [PATCH 1/5] bug 10790: cloudStack - Volume page - hide Storage from domain-admin as well. --- ui/scripts/cloud.core.volume.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ui/scripts/cloud.core.volume.js b/ui/scripts/cloud.core.volume.js index 7be56e135c5..84057143a79 100644 --- a/ui/scripts/cloud.core.volume.js +++ b/ui/scripts/cloud.core.volume.js @@ -433,7 +433,7 @@ function volumeJsonToDetailsTab(){ $thisTab.find("#vm_name").text(getVmName(jsonObj.vmname, jsonObj.vmdisplayname) + " (" + fromdb(jsonObj.vmstate) + ")"); setDateField(jsonObj.created, $thisTab.find("#created")); - if(isAdmin() || isDomainAdmin()) { + if(isAdmin()) { $thisTab.find("#storage").text(fromdb(jsonObj.storage)); $thisTab.find("#storage_container").show(); } From de25a63ba85e2cd0a84fd2c8722a93eddca89de3 Mon Sep 17 00:00:00 2001 From: Edison Su Date: Fri, 19 Aug 2011 16:06:10 -0700 Subject: [PATCH 2/5] release the check --- server/src/com/cloud/vm/UserVmManagerImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/src/com/cloud/vm/UserVmManagerImpl.java b/server/src/com/cloud/vm/UserVmManagerImpl.java index f36f70d5c22..c91ef0137f9 100755 --- a/server/src/com/cloud/vm/UserVmManagerImpl.java +++ b/server/src/com/cloud/vm/UserVmManagerImpl.java @@ -486,7 +486,7 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager } // Check that the volume is stored on shared storage - if (!_storageMgr.volumeOnSharedStoragePool(volume)) { + if (!(Volume.State.Allocated.equals(volume.getState()) && !_storageMgr.volumeOnSharedStoragePool(volume))) { throw new InvalidParameterValueException("Please specify a volume that has been created on a shared storage pool."); } From d9b0188d7e7437d4fad40244d9e41c9a22167ac8 Mon Sep 17 00:00:00 2001 From: Sheng Yang Date: Fri, 19 Aug 2011 15:34:02 -0700 Subject: [PATCH 3/5] Fix potential redundant router FAULT state by dnsmasq This message may show during redundant router start up: FAULT (Restarting DNS forwarder and DHCP server: dnsmasq failed!) This caused by edithost.sh is racy with keepalived process. They both want to restart dnsmasq. Even in normal condition, it's very hard to reproduce this bug. Add file lock for edithost.sh should solve it. --- .../systemvm/debian/config/root/edithosts.sh | 35 ++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/patches/systemvm/debian/config/root/edithosts.sh b/patches/systemvm/debian/config/root/edithosts.sh index 478ce4ba552..506c5e68b48 100755 --- a/patches/systemvm/debian/config/root/edithosts.sh +++ b/patches/systemvm/debian/config/root/edithosts.sh @@ -67,6 +67,33 @@ sed -i /"$2 "/d /etc/hosts sed -i /"$3"/d /etc/hosts echo "$2 $3" >> /etc/hosts +locked=0 +if [ $no_redundant -eq 0 ] +then +#for redundant router, grap the lock to prevent racy with keepalived process +LOCK=/tmp/rrouter.lock + +# Wait the lock +for i in `seq 1 5` +do + if [ ! -e $LOCK ] + then + touch $LOCK + locked=1 + break + fi + sleep 1 + logger -t cloud "edithosts: sleep 1 second wait for the redundant router lock" +done + +if [ $locked -eq 0 ] +then + logger -t cloud "edithosts: fail to get the redundant router lock" + logger -t cloud "edithosts: keepalived should able to handle the dnsmasq restart" + exit +fi +fi + # make dnsmasq re-read files pid=$(pidof dnsmasq) if [ "$pid" != "" ] @@ -81,4 +108,10 @@ else fi fi -exit $? +ret=$? +if [ $locked -eq 1 ] +then + rm $LOCK +fi + +exit $ret From eb72d340e219f0567bcbc8c0b560e6d469b19d39 Mon Sep 17 00:00:00 2001 From: Edison Su Date: Fri, 19 Aug 2011 16:15:13 -0700 Subject: [PATCH 4/5] fix typo --- server/src/com/cloud/vm/UserVmManagerImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/src/com/cloud/vm/UserVmManagerImpl.java b/server/src/com/cloud/vm/UserVmManagerImpl.java index c91ef0137f9..b343bc4fc59 100755 --- a/server/src/com/cloud/vm/UserVmManagerImpl.java +++ b/server/src/com/cloud/vm/UserVmManagerImpl.java @@ -486,7 +486,7 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager } // Check that the volume is stored on shared storage - if (!(Volume.State.Allocated.equals(volume.getState()) && !_storageMgr.volumeOnSharedStoragePool(volume))) { + if (!(Volume.State.Allocated.equals(volume.getState())) && !_storageMgr.volumeOnSharedStoragePool(volume)) { throw new InvalidParameterValueException("Please specify a volume that has been created on a shared storage pool."); } From 3466d3f63736712bc945a46bed692ba0f21fd8c6 Mon Sep 17 00:00:00 2001 From: Edison Su Date: Fri, 19 Aug 2011 16:21:16 -0700 Subject: [PATCH 5/5] add new testcase class, make testcase pydev friendly --- tools/testClient/cloudstackTestCase.py | 7 ++++ tools/testClient/cloudstackTestClient.py | 8 ++-- tools/testClient/testcase/test_1.py | 6 +-- tools/testClient/testcase/test_2.py | 6 +-- tools/testClient/testcase/test_3.py | 49 ++++++++++++++++++++++++ 5 files changed, 64 insertions(+), 12 deletions(-) create mode 100644 tools/testClient/cloudstackTestCase.py create mode 100644 tools/testClient/testcase/test_3.py diff --git a/tools/testClient/cloudstackTestCase.py b/tools/testClient/cloudstackTestCase.py new file mode 100644 index 00000000000..39696b2ca9f --- /dev/null +++ b/tools/testClient/cloudstackTestCase.py @@ -0,0 +1,7 @@ +from cloudstackAPI import * +import unittest +import cloudstackTestClient +class cloudstackTestCase(unittest.case.TestCase): + def __init__(self, args): + unittest.case.TestCase.__init__(self, args) + self.testClient = cloudstackTestClient.cloudstackTestClient() diff --git a/tools/testClient/cloudstackTestClient.py b/tools/testClient/cloudstackTestClient.py index 1c2aad5ee49..28aef44b4bd 100644 --- a/tools/testClient/cloudstackTestClient.py +++ b/tools/testClient/cloudstackTestClient.py @@ -4,7 +4,7 @@ import dbConnection from cloudstackAPI import * class cloudstackTestClient(object): - def __init__(self, mgtSvr, port=8096, apiKey = None, securityKey = None, asyncTimeout=3600, defaultWorkerThreads=10, logging=None): + def __init__(self, mgtSvr=None, port=8096, apiKey = None, securityKey = None, asyncTimeout=3600, defaultWorkerThreads=10, logging=None): self.connection = cloudstackConnection.cloudConnection(mgtSvr, port, apiKey, securityKey, asyncTimeout, logging) self.apiClient = cloudstackAPIClient.CloudStackAPIClient(self.connection) self.dbConnection = None @@ -15,7 +15,7 @@ class cloudstackTestClient(object): def dbConfigure(self, host="localhost", port=3306, user='cloud', passwd='cloud', db='cloud'): self.dbConnection = dbConnection.dbConnection(host, port, user, passwd, db) - self.asyncJobMgr = asyncJobMgr.asyncJobMgr(self.apiClient, self.dbConnection) + def getDbConnection(self): return self.dbConnection @@ -36,10 +36,10 @@ class cloudstackTestClient(object): def submitCmdsAndWait(self, cmds): if self.asyncJobMgr is None: - return None + self.asyncJobMgr = asyncJobMgr.asyncJobMgr(self.apiClient, self.dbConnection) return self.asyncJobMgr.submitCmdsAndWait(cmds) def submitJobs(self, job, ntimes=1, nums_threads=10, interval=1): if self.asyncJobMgr is None: - return None + self.asyncJobMgr = asyncJobMgr.asyncJobMgr(self.apiClient, self.dbConnection) self.asyncJobMgr.submitJobs(job, ntimes, nums_threads, interval) \ No newline at end of file diff --git a/tools/testClient/testcase/test_1.py b/tools/testClient/testcase/test_1.py index a2f7a0305fb..a97bbb3b916 100644 --- a/tools/testClient/testcase/test_1.py +++ b/tools/testClient/testcase/test_1.py @@ -1,8 +1,6 @@ -import unittest -import random -from cloudstackAPI import * +from cloudstackTestCase import * -class TestCase1(unittest.case.TestCase): +class TestCase1(cloudstackTestCase): def test_cloudstackapi(self): apiClient = self.testClient.getApiClient() diff --git a/tools/testClient/testcase/test_2.py b/tools/testClient/testcase/test_2.py index c86cf1158a9..f9937b83e72 100644 --- a/tools/testClient/testcase/test_2.py +++ b/tools/testClient/testcase/test_2.py @@ -1,7 +1,5 @@ -import unittest -import random -from cloudstackAPI import * -class TestCase2(unittest.case.TestCase): +from cloudstackTestCase import * +class TestCase2(cloudstackTestCase): def test_cloudstackapi1(self): apiClient = self.testClient.getApiClient() diff --git a/tools/testClient/testcase/test_3.py b/tools/testClient/testcase/test_3.py new file mode 100644 index 00000000000..676bf7a5fae --- /dev/null +++ b/tools/testClient/testcase/test_3.py @@ -0,0 +1,49 @@ +from cloudstackTestCase import * +import uuid +class TestCase1(cloudstackTestCase): + def setUp(self): + '''get a small service offering id''' + listsocmd = listServiceOfferings.listServiceOfferingsCmd() + listsocmd.name = "Small Instance" + listsocmd.issystem = "false" + sos = self.testClient.getApiClient().listServiceOfferings(listsocmd) + if sos is not None and len(sos) > 0: + self.svid = sos[0].id + listdiskovcmd = listDiskOfferings.listDiskOfferingsCmd() + listdiskovcmd.name = "Small" + disoov = self.testClient.getApiClient().listDiskOfferings(listdiskovcmd) + if disoov is not None and len(disoov) > 0: + self.diskov = disoov[0].id + + '''get user vm template id''' + listtmplcmd = listTemplates.listTemplatesCmd() + listtmplcmd.templatefilter = "featured" + tmpls = self.testClient.getApiClient().listTemplates(listtmplcmd) + if tmpls is not None: + for tmpl in tmpls: + if tmpl.isready == "true": + self.templateId = tmpl.id + self.zoneId = tmpl.zoneid + break + + def test_cloudstackapi(self): + apiClient = self.testClient.getApiClient() + + createvm = deployVirtualMachine.deployVirtualMachineCmd() + createvm.serviceofferingid = self.svid + createvm.templateid = self.templateId + createvm.zoneid = self.zoneId + vm = apiClient.deployVirtualMachine(createvm) + vmId = vm.id + + creatvolume = createVolume.createVolumeCmd() + creatvolume.name = "tetst" + str(uuid.uuid4()) + creatvolume.diskofferingid = self.diskov + creatvolume.zoneid = self.zoneId + createvolumeresponse = apiClient.createVolume(creatvolume) + volumeId = createvolumeresponse.id + attach = attachVolume.attachVolumeCmd() + + attach.id = volumeId + attach.virtualmachineid = vmId + apiClient.attachVolume(attach) \ No newline at end of file