CLOUDSTACK-4098: Fix the test which deploys a VM from password enabled template.

Signed-off-by: Prasanna Santhanam <tsp@apache.org>
This commit is contained in:
SrikanteswaraRao Talluri 2013-08-06 16:54:26 +05:30 committed by Prasanna Santhanam
parent fa094a5d2c
commit 64591e65be
2 changed files with 93 additions and 7 deletions

View File

@ -45,6 +45,25 @@ class Services:
# ensure unique username generated each time
"password": "password",
},
"small":
# Create a small virtual machine instance with disk offering
{
"displayname": "testserver",
"username": "root", # VM creds for SSH
"password": "password",
"ssh_port": 22,
"hypervisor": 'XenServer',
"privateport": 22,
"publicport": 22,
"protocol": 'TCP',
},
"egress": {
"name": 'web',
"protocol": 'TCP',
"startport": 80,
"endport": 80,
"cidrlist": '0.0.0.0/0',
},
"service_offerings":
{
"small":
@ -89,8 +108,8 @@ class TestVMPasswordEnabled(cloudstackTestCase):
cls.services["ostype"]
)
# Set Zones and disk offerings
cls.services["service_offerings"]["small"]["zoneid"] = zone.id
cls.services["service_offerings"]["small"]["template"] = template.id
cls.services["small"]["zoneid"] = zone.id
cls.services["small"]["template"] = template.id
# Create VMs, NAT Rules etc
cls.account = Account.create(
@ -112,6 +131,34 @@ class TestVMPasswordEnabled(cloudstackTestCase):
serviceofferingid=cls.small_offering.id,
mode=cls.services["mode"]
)
networkid = cls.virtual_machine.nic[0].networkid
# create egress rule to allow wget of my butt-set-guest-password script
EgressFireWallRule.create(cls.api_client,
networkid=networkid,
protocol=cls.services["egress"]["protocol"],
startport=cls.services["egress"]["startport"],
endport=cls.services["egress"]["endport"],
cidrlist=cls.services["egress"]["cidrlist"])
cls.virtual_machine.password = cls.services["small"]["password"]
ssh = cls.virtual_machine.get_ssh_client()
#below steps are required to get the new password from VR(reset password)
#http://cloudstack.org/dl/cloud-set-guest-password
#Copy this file to /etc/init.d
#chmod +x /etc/init.d/cloud-set-guest-password
#chkconfig --add cloud-set-guest-password
cmds = [
"cd /etc/init.d;wget http://10.147.40.145/cloud-set-guest-password",
"chmod +x /etc/init.d/cloud-set-guest-password",
"chkconfig --add cloud-set-guest-password",
]
for c in cmds:
result = ssh.execute(c)
#Stop virtual machine
cls.virtual_machine.stop(cls.api_client)
@ -134,7 +181,7 @@ class TestVMPasswordEnabled(cloudstackTestCase):
if timeout == 0:
raise Exception(
"Failed to stop VM (ID: %s) in change service offering" %
"Failed to stop VM (ID: %s) " %
vm.id)
timeout = timeout - 1
@ -149,7 +196,7 @@ class TestVMPasswordEnabled(cloudstackTestCase):
cls.volume = list_volume[0]
else:
raise Exception(
"Exception: Unable to find root volume foe VM: %s" %
"Exception: Unable to find root volume for VM: %s" %
cls.virtual_machine.id)
cls.services["template"]["ostype"] = cls.services["ostype"]
@ -224,7 +271,7 @@ class TestVMPasswordEnabled(cloudstackTestCase):
self.assertEqual(
isinstance(vms, list),
True,
"List VMs should retun valid response for VM: %s" % self.vm.name
"List VMs should return valid response for VM: %s" % self.vm.name
)
virtual_machine = vms[0]

View File

@ -555,8 +555,8 @@ class VirtualMachine:
response = apiclient.resetPasswordForVirtualMachine(cmd)
except Exception as e:
raise Exception("Reset Password failed! - %s" % e)
if isinstance(response, list):
return response[0].password
if response is not None:
return response.password
def assign_virtual_machine(self, apiclient, account, domainid):
"""Move a user VM to another user under same domain."""
@ -1260,6 +1260,45 @@ class StaticNATRule:
return
class EgressFireWallRule:
"""Manage Egress Firewall rule"""
def __init__(self, items):
self.__dict__.update(items)
@classmethod
def create(cls, apiclient, networkid, protocol, cidrlist=None,
startport=None, endport=None):
"""Create Egress Firewall Rule"""
cmd = createEgressFirewallRule.createEgressFirewallRuleCmd()
cmd.networkid = networkid
cmd.protocol = protocol
if cidrlist:
cmd.cidrlist = cidrlist
if startport:
cmd.startport = startport
if endport:
cmd.endport = endport
return EgressFireWallRule(apiclient.createEgressFirewallRule(cmd).__dict__)
def delete(self, apiclient):
"""Delete Egress Firewall rule"""
cmd = deleteEgressFirewallRule.deleteEgressFirewallRuleCmd()
cmd.id = self.id
apiclient.deleteEgressFirewallRule(cmd)
return
@classmethod
def list(cls, apiclient, **kwargs):
"""List all Egress Firewall Rules matching criteria"""
cmd = listEgressFirewallRules.listEgressFirewallRulesCmd()
[setattr(cmd, k, v) for k, v in kwargs.items()]
return(apiclient.listEgressFirewallRules(cmd))
class FireWallRule:
"""Manage Firewall rule"""