Skip to content

Commit

Permalink
Remove useless try except blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelaferreira committed Aug 15, 2016
1 parent 9a35090 commit 7e3f013
Showing 1 changed file with 57 additions and 78 deletions.
135 changes: 57 additions & 78 deletions cosmic-core/test/integration/smoke/test_vpc_vpn.py
Original file line number Diff line number Diff line change
Expand Up @@ -497,115 +497,94 @@ def test_01_vpc_remote_access_vpn(self):
vpc_offering = VpcOffering.list(self.apiclient, isdefault=True)
self.assertTrue(vpc_offering is not None and len(vpc_offering) > 0, "No VPC offerings found")

try:
vpc = VPC.create(
apiclient=self.apiclient,
services=self.services["vpc"],
networkDomain="vpc.vpn",
vpcofferingid=vpc_offering[0].id,
zoneid=self.zone.id,
account=self.account.name,
domainid=self.domain.id
)
except Exception as e:
self.fail(e)
vpc = VPC.create(
apiclient=self.apiclient,
services=self.services["vpc"],
networkDomain="vpc.vpn",
vpcofferingid=vpc_offering[0].id,
zoneid=self.zone.id,
account=self.account.name,
domainid=self.domain.id
)

self.assertIsNotNone(vpc, "VPC creation failed")
self.logger.debug("VPC %s created" % (vpc.id))

self.cleanup.append(vpc)

try:
# 2) Create network in VPC
ntwk = Network.create(
apiclient=self.apiclient,
services=self.services["network_1"],
accountid=self.account.name,
domainid=self.domain.id,
networkofferingid=self.network_offerings[0].id,
zoneid=self.zone.id,
vpcid=vpc.id
)
except Exception as e:
self.fail(e)
# 2) Create network in VPC
ntwk = Network.create(
apiclient=self.apiclient,
services=self.services["network_1"],
accountid=self.account.name,
domainid=self.domain.id,
networkofferingid=self.network_offerings[0].id,
zoneid=self.zone.id,
vpcid=vpc.id
)

self.assertIsNotNone(ntwk, "Network failed to create")
self.logger.debug("Network %s created in VPC %s" % (ntwk.id, vpc.id))

self.cleanup.append(ntwk)

try:
# 3) Deploy a vm
vm = VirtualMachine.create(self.apiclient, services=self.services["virtual_machine"],
templateid=self.template.id,
zoneid=self.zone.id,
accountid=self.account.name,
domainid=self.domain.id,
serviceofferingid=self.compute_offering.id,
networkids=ntwk.id,
hypervisor=self.hypervisor
)
self.assertIsNotNone(vm, "VM failed to deploy")
self.assertEquals(vm.state, 'Running', "VM is not running")
self.debug("VM %s deployed in VPC %s" % (vm.id, vpc.id))
except Exception as e:
self.fail(e)
# 3) Deploy a vm
vm = VirtualMachine.create(self.apiclient, services=self.services["virtual_machine"],
templateid=self.template.id,
zoneid=self.zone.id,
accountid=self.account.name,
domainid=self.domain.id,
serviceofferingid=self.compute_offering.id,
networkids=ntwk.id,
hypervisor=self.hypervisor
)
self.assertIsNotNone(vm, "VM failed to deploy")
self.assertEquals(vm.state, 'Running', "VM is not running")
self.debug("VM %s deployed in VPC %s" % (vm.id, vpc.id))

self.logger.debug("Deployed virtual machine: OK")
self.cleanup.append(vm)

try:
# 4) Enable VPN for VPC
src_nat_list = PublicIPAddress.list(
self.apiclient,
account=self.account.name,
domainid=self.account.domainid,
listall=True,
issourcenat=True,
vpcid=vpc.id
)
ip = src_nat_list[0]
except Exception as e:
self.fail(e)
# 4) Enable VPN for VPC
src_nat_list = PublicIPAddress.list(
self.apiclient,
account=self.account.name,
domainid=self.account.domainid,
listall=True,
issourcenat=True,
vpcid=vpc.id
)
ip = src_nat_list[0]

self.logger.debug("Acquired public ip address: OK")

try:
vpn = Vpn.create(self.apiclient,
publicipid=ip.id,
account=self.account.name,
domainid=self.account.domainid,
iprange=self.services["vpn"]["iprange"],
fordisplay=self.services["vpn"]["fordisplay"]
)
except Exception as e:
self.fail(e)
vpn = Vpn.create(self.apiclient,
publicipid=ip.id,
account=self.account.name,
domainid=self.account.domainid,
iprange=self.services["vpn"]["iprange"],
fordisplay=self.services["vpn"]["fordisplay"]
)

self.assertIsNotNone(vpn, "Failed to create Remote Access VPN")
self.logger.debug("Created Remote Access VPN: OK")

vpn_user = None
# 5) Add VPN user for VPC
try:
vpn_user = VpnUser.create(self.apiclient,
account=self.account.name,
domainid=self.account.domainid,
username=self.services["vpn"]["vpn_user"],
password=self.services["vpn"]["vpn_pass"]
)
except Exception as e:
self.fail(e)
vpn_user = VpnUser.create(self.apiclient,
account=self.account.name,
domainid=self.account.domainid,
username=self.services["vpn"]["vpn_user"],
password=self.services["vpn"]["vpn_pass"]
)

self.assertIsNotNone(vpn_user, "Failed to create Remote Access VPN User")
self.logger.debug("Created VPN User: OK")

# TODO: Add an actual remote vpn connection test from a remote vpc

try:
# 9) Disable VPN for VPC
vpn.delete(self.apiclient)
except Exception as e:
self.fail(e)
# 9) Disable VPN for VPC
vpn.delete(self.apiclient)

self.logger.debug("Deleted the Remote Access VPN: OK")

Expand Down

0 comments on commit 7e3f013

Please sign in to comment.