def test_01_public_ip_admin_account(self): """Test for Associate/Disassociate public IP address for admin account""" # Validate the following: # 1. listPubliIpAddresses API returns the list of acquired addresses # 2. the returned list should contain our acquired IP address ip_address = PublicIPAddress.create(self.apiclient, self.account.name, self.zone.id, self.account.domainid) list_pub_ip_addr_resp = list_public_ip(self.apiclient, id=ip_address.ipaddress.id) self.assertEqual(isinstance(list_pub_ip_addr_resp, list), True, "Check list response returns a valid list") # listPublicIpAddresses should return newly created public IP self.assertNotEqual(len(list_pub_ip_addr_resp), 0, "Check if new IP Address is associated") self.assertEqual( list_pub_ip_addr_resp[0].id, ip_address.ipaddress.id, "Check Correct IP Address is returned in the List Cacls") ip_address.delete(self.apiclient) time.sleep(30) # Validate the following: # 1.listPublicIpAddresses should no more return the released address list_pub_ip_addr_resp = list_public_ip(self.apiclient, id=ip_address.ipaddress.id) if list_pub_ip_addr_resp is None: return if (list_pub_ip_addr_resp) and (isinstance( list_pub_ip_addr_resp, list)) and (len(list_pub_ip_addr_resp) > 0): self.fail("list public ip response is not empty") return
def test_02_public_ip_user_account(self): """Test for Associate/Disassociate public IP address for user account""" # Validate the following: # 1. listPublicIpAddresses API returns the list of acquired addresses # 2. the returned list should contain our acquired IP address ip_address = PublicIPAddress.create(self.apiclient, self.user.name, self.zone.id, self.user.domainid) # listPublicIpAddresses should return newly created public IP list_pub_ip_addr_resp = list_public_ip(self.apiclient, id=ip_address.ipaddress.id) self.assertEqual(isinstance(list_pub_ip_addr_resp, list), True, "Check list response returns a valid list") self.assertNotEqual(len(list_pub_ip_addr_resp), 0, "Check if new IP Address is associated") self.assertEqual( list_pub_ip_addr_resp[0].id, ip_address.ipaddress.id, "Check Correct IP Address is returned in the List Call") ip_address.delete(self.apiclient) list_pub_ip_addr_resp = list_public_ip(self.apiclient, id=ip_address.ipaddress.id) self.assertEqual( list_pub_ip_addr_resp, None, "Check if disassociated IP Address is no longer available") return
def test_01_release_ip(self): """Test for release public IP address""" self.logger.debug("Deleting Public IP : %s" % self.ip_addr.id) self.ip_address.delete(self.apiclient) retriesCount = 10 isIpAddressDisassociated = False while retriesCount > 0: listResponse = list_public_ip( self.apiclient, id=self.ip_addr.id ) if listResponse is None: isIpAddressDisassociated = True break retriesCount -= 1 time.sleep(60) # End while self.assertTrue( isIpAddressDisassociated, "Failed to disassociate IP address") # ListPortForwardingRules should not list # associated rules with Public IP address try: list_nat_rule = list_nat_rules( self.apiclient, id=self.nat_rule.id ) self.logger.debug("List NAT Rule response" + str(list_nat_rule)) except CloudstackAPIException: self.logger.debug("Port Forwarding Rule is deleted") # listLoadBalancerRules should not list # associated rules with Public IP address try: list_lb_rule = list_lb_rules( self.apiclient, id=self.lb_rule.id ) self.logger.debug("List LB Rule response" + str(list_lb_rule)) except CloudstackAPIException: self.logger.debug("Port Forwarding Rule is deleted") # SSH Attempt though public IP should fail with self.assertRaises(Exception): SshClient( self.ip_addr.ipaddress, self.services["natrule"]["publicport"], self.virtual_machine.username, self.virtual_machine.password, retries=2, delay=0 ) return
def setUp(self): self.logger = MarvinLog(MarvinLog.LOGGER_TEST).get_logger() self.apiclient = self.testClient.getApiClient() self.services = self.testClient.getParsedTestDataConfig() # Get Zone, Domain and templates self.domain = get_domain(self.apiclient) self.zone = get_zone(self.apiclient, self.testClient.getZoneForTests()) template = get_template(self.apiclient, self.zone.id) self.services["virtual_machine"]["zoneid"] = self.zone.id # Create an account, network, VM, Port forwarding rule, LB rules self.account = Account.create(self.apiclient, self.services["account"], admin=True, domainid=self.domain.id) self.service_offering = get_default_virtual_machine_offering( self.apiclient) self.virtual_machine = VirtualMachine.create( self.apiclient, self.services["virtual_machine"], templateid=template.id, accountid=self.account.name, domainid=self.account.domainid, serviceofferingid=self.service_offering.id) self.ip_address = PublicIPAddress.create(self.apiclient, self.account.name, self.zone.id, self.account.domainid) ip_addrs = list_public_ip(self.apiclient, account=self.account.name, domainid=self.account.domainid, issourcenat=False) try: self.ip_addr = ip_addrs[0] except Exception as e: raise Exception( "Failed: During acquiring source NAT for account: %s, :%s" % (self.account.name, e)) self.nat_rule = NATRule.create(self.apiclient, self.virtual_machine, self.services["natrule"], self.ip_addr.id) self.lb_rule = LoadBalancerRule.create(self.apiclient, self.services["lbrule"], self.ip_addr.id, accountid=self.account.name) self.cleanup = [self.virtual_machine, self.account] return
def setUp(self): self.logger = MarvinLog(MarvinLog.LOGGER_TEST).get_logger() self.apiclient = self.testClient.getApiClient() self.services = self.testClient.getParsedTestDataConfig() # Get Zone, Domain and templates self.domain = get_domain(self.apiclient) self.zone = get_zone(self.apiclient, self.testClient.getZoneForTests()) template = get_template(self.apiclient, self.zone.id) self.services["virtual_machine"]["zoneid"] = self.zone.id # Create an account, network, VM and IP addresses self.account = Account.create(self.apiclient, self.services["account"], admin=True, domainid=self.domain.id) self.service_offering = get_default_virtual_machine_offering( self.apiclient) self.vm_1 = VirtualMachine.create( self.apiclient, self.services["virtual_machine"], templateid=template.id, accountid=self.account.name, domainid=self.account.domainid, serviceofferingid=self.service_offering.id) src_nat_ip_addrs = list_public_ip(self.apiclient, account=self.account.name, domainid=self.account.domainid) try: src_nat_ip_addr = src_nat_ip_addrs[0] except Exception as e: self.fail("SSH failed for VM with IP: %s %s" % (src_nat_ip_addr.ipaddress, e)) self.lb_rule = LoadBalancerRule.create(self.apiclient, self.services["lbrule"], src_nat_ip_addr.id, self.account.name) self.lb_rule.assign(self.apiclient, [self.vm_1]) self.nat_rule = NATRule.create(self.apiclient, self.vm_1, self.services["natrule"], src_nat_ip_addr.id) self.cleanup = [] return
def test_01_release_ip(self): """Test for release public IP address""" self.logger.debug("Deleting Public IP : %s" % self.ip_addr.id) self.ip_address.delete(self.apiclient) retriesCount = 10 isIpAddressDisassociated = False while retriesCount > 0: listResponse = list_public_ip(self.apiclient, id=self.ip_addr.id) if listResponse is None: isIpAddressDisassociated = True break retriesCount -= 1 time.sleep(60) # End while self.assertTrue(isIpAddressDisassociated, "Failed to disassociate IP address") # ListPortForwardingRules should not list # associated rules with Public IP address try: list_nat_rule = list_nat_rules(self.apiclient, id=self.nat_rule.id) self.logger.debug("List NAT Rule response" + str(list_nat_rule)) except CloudstackAPIException: self.logger.debug("Port Forwarding Rule is deleted") # listLoadBalancerRules should not list # associated rules with Public IP address try: list_lb_rule = list_lb_rules(self.apiclient, id=self.lb_rule.id) self.logger.debug("List LB Rule response" + str(list_lb_rule)) except CloudstackAPIException: self.logger.debug("Port Forwarding Rule is deleted") # SSH Attempt though public IP should fail with self.assertRaises(Exception): SshClient(self.ip_addr.ipaddress, self.services["natrule"]["publicport"], self.virtual_machine.username, self.virtual_machine.password, retries=2, delay=0) return
def test_01_RVR_Network_FW_PF_SSH_default_routes_egress_true(self): """ Test redundant router internals """ self.logger.debug( "Starting test_01_RVR_Network_FW_PF_SSH_default_routes_egress_true..." ) network_offering_egress_true = get_default_redundant_isolated_network_offering_with_egress( self.apiclient) self.logger.debug("Creating network with network offering: %s" % network_offering_egress_true.id) network = Network.create( self.apiclient, self.services["network"], accountid=self.account.name, domainid=self.account.domainid, networkofferingid=network_offering_egress_true.id, zoneid=self.zone.id) self.logger.debug("Created network with ID: %s" % network.id) networks = Network.list(self.apiclient, id=network.id, listall=True) self.assertEqual( isinstance(networks, list), True, "List networks should return a valid response for created network") self.logger.debug("Deploying VM in account: %s" % self.account.name) virtual_machine = VirtualMachine.create( self.apiclient, self.services["virtual_machine"], templateid=self.template.id, accountid=self.account.name, domainid=self.account.domainid, serviceofferingid=self.service_offering.id, networkids=[str(network.id)]) self.logger.debug("Deployed VM in network: %s" % network.id) self.cleanup.insert(0, network) self.cleanup.insert(0, virtual_machine) vms = VirtualMachine.list(self.apiclient, id=virtual_machine.id, listall=True) self.assertEqual(isinstance(vms, list), True, "List Vms should return a valid list") vm = vms[0] self.assertEqual(vm.state, "Running", "VM should be in running state after deployment") self.logger.debug("Listing routers for network: %s" % network.name) routers = Router.list(self.apiclient, networkid=network.id, listall=True) self.assertEqual( isinstance(routers, list), True, "list router should return Master and backup routers") self.assertEqual( len(routers), 2, "Length of the list router should be 2 (Backup & master)") public_ips = list_public_ip(self.apiclient, account=self.account.name, domainid=self.account.domainid, zoneid=self.zone.id) public_ip = public_ips[0] self.assertEqual( isinstance(public_ips, list), True, "Check for list public IPs response return valid data") self.logger.debug("Creating Firewall rule for VM ID: %s" % virtual_machine.id) FireWallRule.create( self.apiclient, ipaddressid=public_ip.id, protocol=self.services["natrule_ssh"]["protocol"], cidrlist=['0.0.0.0/0'], startport=self.services["natrule_ssh"]["publicport"], endport=self.services["natrule_ssh"]["publicport"]) self.logger.debug("Creating NAT rule for VM ID: %s" % virtual_machine.id) nat_rule = NATRule.create(self.apiclient, virtual_machine, self.services["natrule_ssh"], public_ip.id) # Test SSH after closing port 22 expected = 1 ssh_command = "ping -c 3 8.8.8.8" check_string = "3 packets received" result = self.check_router_command(virtual_machine, nat_rule.ipaddress, ssh_command, check_string, self) self.assertEqual( result, expected, "Ping to outside world from VM should be successful!") expected = 1 ssh_command = self.HTTP_COMMAND check_string = self.HTTP_CHECK_STRING result = self.check_router_command(virtual_machine, nat_rule.ipaddress, ssh_command, check_string, self) self.assertEqual(result, expected, self.HTTP_ASSERT_SUCCESS_MESSAGE) EgressFireWallRule.create( self.apiclient, networkid=network.id, protocol=self.services["egress_443"]["protocol"], startport=self.services["egress_443"]["startport"], endport=self.services["egress_443"]["endport"], cidrlist=self.services["egress_443"]["cidrlist"]) expected = 0 result = self.check_router_command(virtual_machine, nat_rule.ipaddress, ssh_command, check_string, self) self.assertEqual(result, expected, self.HTTP_ASSERT_FAILURE_MESSAGE) return
def test_01_isolate_network_FW_PF_default_routes_egress_true(self): """ Test redundant router internals """ self.logger.debug( "Starting test_01_isolate_network_FW_PF_default_routes_egress_true..." ) network_offering_egress_true = get_default_isolated_network_offering_with_egress( self.apiclient) self.logger.debug("Creating Network with Network Offering ID %s" % network_offering_egress_true.id) network = Network.create( self.apiclient, self.services["network"], accountid=self.account.name, domainid=self.account.domainid, networkofferingid=network_offering_egress_true.id, zoneid=self.zone.id) self.logger.debug("Deploying Virtual Machine on Network %s" % network.id) virtual_machine = VirtualMachine.create( self.apiclient, self.services["virtual_machine"], templateid=self.template.id, accountid=self.account.name, domainid=self.domain.id, serviceofferingid=self.service_offering.id, networkids=[str(network.id)]) self.logger.debug("Deployed VM in network: %s" % network.id) self.cleanup.insert(0, network) self.cleanup.insert(0, virtual_machine) self.logger.debug( "Starting test_isolate_network_FW_PF_default_routes...") routers = list_routers(self.apiclient, account=self.account.name, domainid=self.account.domainid) self.assertEqual(isinstance(routers, list), True, "Check for list routers response return valid data") self.assertNotEqual(len(routers), 0, "Check list router response") router = routers[0] self.assertEqual(router.state, 'Running', "Check list router response for router state") public_ips = list_public_ip(self.apiclient, account=self.account.name, domainid=self.account.domainid, zoneid=self.zone.id) self.assertEqual( isinstance(public_ips, list), True, "Check for list public IPs response return valid data") public_ip = public_ips[0] self.logger.debug("Creating Firewall rule for VM ID: %s" % virtual_machine.id) FireWallRule.create( self.apiclient, ipaddressid=public_ip.id, protocol=self.services["natrule_ssh"]["protocol"], cidrlist=['0.0.0.0/0'], startport=self.services["natrule_ssh"]["publicport"], endport=self.services["natrule_ssh"]["publicport"]) self.logger.debug("Creating NAT rule for VM ID: %s" % virtual_machine.id) # Create NAT rule nat_rule = NATRule.create(self.apiclient, virtual_machine, self.services["natrule_ssh"], public_ip.id) nat_rules = list_nat_rules(self.apiclient, id=nat_rule.id) self.assertEqual( isinstance(nat_rules, list), True, "Check for list NAT rules response return valid data") self.assertEqual(nat_rules[0].state, 'Active', "Check list port forwarding rules") # Test SSH after closing port 22 expected = 1 ssh_command = "ping -c 3 8.8.8.8" check_string = "3 packets received" result = self.check_router_command(virtual_machine, nat_rule.ipaddress, ssh_command, check_string, self) self.assertEqual( result, expected, "Ping to outside world from VM should be successful!") expected = 1 ssh_command = self.HTTP_COMMAND check_string = self.HTTP_CHECK_STRING result = self.check_router_command(virtual_machine, nat_rule.ipaddress, ssh_command, check_string, self) self.assertEqual(result, expected, self.HTTP_ASSERT_SUCCESS_MESSAGE) EgressFireWallRule.create( self.apiclient, networkid=network.id, protocol=self.services["egress_443"]["protocol"], startport=self.services["egress_443"]["startport"], endport=self.services["egress_443"]["endport"], cidrlist=self.services["egress_443"]["cidrlist"]) expected = 0 result = self.check_router_command(virtual_machine, nat_rule.ipaddress, ssh_command, check_string, self) self.assertEqual(result, expected, self.HTTP_ASSERT_FAILURE_MESSAGE) return
def test_01_port_fwd_on_src_nat(self): """Test for port forwarding on source NAT""" # Validate the following: # 1. listPortForwarding rules API should return the added PF rule # 2. attempt to do an ssh into the user VM through the sourceNAT src_nat_ip_addrs = list_public_ip(self.apiclient, account=self.account.name, domainid=self.account.domainid) self.assertEqual(isinstance(src_nat_ip_addrs, list), True, "Check list response returns a valid list") src_nat_ip_addr = src_nat_ip_addrs[0] # Check if VM is in Running state before creating NAT rule vm_response = VirtualMachine.list(self.apiclient, id=self.virtual_machine.id) self.assertEqual(isinstance(vm_response, list), True, "Check list VM returns a valid list") self.assertNotEqual(len(vm_response), 0, "Check Port Forwarding Rule is created") self.assertEqual( vm_response[0].state, 'Running', "VM state should be Running before creating a NAT rule.") # Open up firewall port for SSH FireWallRule.create( self.apiclient, ipaddressid=src_nat_ip_addr.id, protocol=self.services["natrule_ssh"]["protocol"], cidrlist=['0.0.0.0/0'], startport=self.services["natrule_ssh"]["publicport"], endport=self.services["natrule_ssh"]["publicport"]) # Create NAT rule nat_rule = NATRule.create(self.apiclient, self.virtual_machine, self.services["natrule_ssh"], src_nat_ip_addr.id) list_nat_rule_response = list_nat_rules(self.apiclient, id=nat_rule.id) self.assertEqual(isinstance(list_nat_rule_response, list), True, "Check list response returns a valid list") self.assertNotEqual(len(list_nat_rule_response), 0, "Check Port Forwarding Rule is created") self.assertEqual(list_nat_rule_response[0].id, nat_rule.id, "Check Correct Port forwarding Rule is returned") # SSH virtual machine to test port forwarding try: self.logger.debug( "SSHing into VM with IP address %s with NAT IP %s" % (self.virtual_machine.ipaddress, src_nat_ip_addr.ipaddress)) self.virtual_machine.get_ssh_client(src_nat_ip_addr.ipaddress) vm_response = VirtualMachine.list(self.apiclient, id=self.virtual_machine.id) if vm_response[0].state != 'Running': self.fail("State of VM : %s is not found to be Running" % str(self.virtual_machine.ipaddress)) except Exception as e: self.fail("SSH Access failed for %s: %s" % (self.virtual_machine.ipaddress, e)) try: nat_rule.delete(self.apiclient) except Exception as e: self.fail("NAT Rule Deletion Failed: %s" % e) # NAT rule listing should fail as the nat rule does not exist with self.assertRaises(Exception): list_nat_rules(self.apiclient, id=nat_rule.id) # Check if the Public SSH port is inaccessible with self.assertRaises(Exception): self.logger.debug( "SSHing into VM with IP address %s after NAT rule deletion" % self.virtual_machine.ipaddress) SshClient(src_nat_ip_addr.ipaddress, self.virtual_machine.ssh_port, self.virtual_machine.username, self.virtual_machine.password, retries=2, delay=0) return
def setUp(self): self.logger = MarvinLog(MarvinLog.LOGGER_TEST).get_logger() self.apiclient = self.testClient.getApiClient() self.services = self.testClient.getParsedTestDataConfig() # Get Zone, Domain and templates self.domain = get_domain(self.apiclient) self.zone = get_zone(self.apiclient, self.testClient.getZoneForTests()) template = get_template( self.apiclient, self.zone.id ) self.services["virtual_machine"]["zoneid"] = self.zone.id # Create an account, network, VM and IP addresses self.account = Account.create( self.apiclient, self.services["account"], admin=True, domainid=self.domain.id ) self.vpc_offering = get_default_vpc_offering(self.apiclient) self.logger.debug("VPC Offering '%s' selected", self.vpc_offering.name) self.network_offering = get_default_network_offering(self.apiclient) self.logger.debug("Network Offering '%s' selected", self.network_offering.name) self.virtual_machine_offering = get_default_virtual_machine_offering(self.apiclient) self.logger.debug("Virtual Machine Offering '%s' selected", self.virtual_machine_offering.name) self.default_allow_acl = get_network_acl(self.apiclient, 'default_allow') self.logger.debug("ACL '%s' selected", self.default_allow_acl.name) self.template = get_template(self.apiclient, self.zone.id) self.logger.debug("Template '%s' selected" % self.template.name) self.vpc1 = VPC.create(self.apiclient, self.services['vpcs']['vpc1'], vpcofferingid=self.vpc_offering.id, zoneid=self.zone.id, domainid=self.domain.id, account=self.account.name) self.logger.debug("VPC '%s' created, CIDR: %s", self.vpc1.name, self.vpc1.cidr) self.network1 = Network.create(self.apiclient, self.services['networks']['network1'], networkofferingid=self.network_offering.id, aclid=self.default_allow_acl.id, vpcid=self.vpc1.id, zoneid=self.zone.id, domainid=self.domain.id, accountid=self.account.name) self.logger.debug("Network '%s' created, CIDR: %s, Gateway: %s", self.network1.name, self.network1.cidr, self.network1.gateway) self.vm1 = VirtualMachine.create(self.apiclient, self.services['vms']['vm1'], templateid=self.template.id, serviceofferingid=self.virtual_machine_offering.id, networkids=[self.network1.id], zoneid=self.zone.id, domainid=self.domain.id, accountid=self.account.name) self.logger.debug("VM '%s' created, Network: %s, IP %s", self.vm1.name, self.network1.name, self.vm1.nic[0].ipaddress) src_nat_ip_addrs = list_public_ip( self.apiclient, account=self.account.name, domainid=self.account.domainid ) try: src_nat_ip_addr = src_nat_ip_addrs[0] except Exception as e: self.fail("SSH failed for VM with IP: %s %s" % (src_nat_ip_addr.ipaddress, e)) self.lb_rule = LoadBalancerRule.create( self.apiclient, self.services["lbrule"], src_nat_ip_addr.id, self.account.name, self.network1.id, self.vpc1.id ) self.lb_rule.assign(self.apiclient, [self.vm1]) self.nat_rule = NATRule.create( self.apiclient, self.vm1, self.services["natrule"], src_nat_ip_addr.id ) self.cleanup = [] return
def test_01_router_dhcphosts(self): """Check that the /etc/dhcphosts.txt doesn't contain duplicate IPs""" self.logger.debug("Starting test_router_dhcphosts...") routers = list_routers(self.apiclient, account=self.account.name, domainid=self.account.domainid) self.assertEqual(isinstance(routers, list), True, "Check for list routers response return valid data") self.assertNotEqual(len(routers), 0, "Check list router response") router = routers[0] self.assertEqual(router.state, 'Running', "Check list router response for router state") public_ips = list_public_ip(self.apiclient, account=self.account.name, domainid=self.account.domainid, zoneid=self.zone.id) self.assertEqual( isinstance(public_ips, list), True, "Check for list public IPs response return valid data") public_ip = public_ips[0] self.logger.debug("Creating Firewall rule for VM ID: %s" % self.vm_1.id) FireWallRule.create(self.apiclient, ipaddressid=public_ip.id, protocol=self.services["natrule1"]["protocol"], cidrlist=['0.0.0.0/0'], startport=self.services["natrule1"]["publicport"], endport=self.services["natrule1"]["publicport"]) self.logger.debug("Creating NAT rule for VM ID: %s" % self.vm_1.id) # Create NAT rule nat_rule1 = NATRule.create(self.apiclient, self.vm_1, self.services["natrule1"], public_ip.id) self.logger.debug("Creating Firewall rule for VM ID: %s" % self.vm_2.id) FireWallRule.create(self.apiclient, ipaddressid=public_ip.id, protocol=self.services["natrule2"]["protocol"], cidrlist=['0.0.0.0/0'], startport=self.services["natrule2"]["publicport"], endport=self.services["natrule2"]["publicport"]) self.logger.debug("Creating NAT rule for VM ID: %s" % self.vm_2.id) # Create NAT rule nat_rule2 = NATRule.create(self.apiclient, self.vm_2, self.services["natrule2"], public_ip.id) nat_rules = list_nat_rules(self.apiclient, id=nat_rule1.id) self.assertEqual( isinstance(nat_rules, list), True, "Check for list NAT rules response return valid data") self.assertEqual(nat_rules[0].state, 'Active', "Check list port forwarding rules") nat_rules = list_nat_rules(self.apiclient, id=nat_rule2.id) self.assertEqual( isinstance(nat_rules, list), True, "Check for list NAT rules response return valid data") self.assertEqual(nat_rules[0].state, 'Active', "Check list port forwarding rules") self.logger.debug("Testing SSH to VMs %s and %s" % (self.vm_1.id, self.vm_2.id)) self.test_ssh_command(self.vm_1, nat_rule1, "natrule1") self.test_ssh_command(self.vm_2, nat_rule2, "natrule2") self.logger.debug("Testing DHCP hosts for VMs %s and %s" % (self.vm_1.id, self.vm_2.id)) self.test_dhcphosts(self.vm_1, router) self.test_dhcphosts(self.vm_2, router) self.logger.debug("Deleting and Expunging VM %s with ip %s" % (self.vm_1.id, self.vm_1.nic[0].ipaddress)) self.vm_1.delete(self.apiclient) self.logger.debug( "Creating new VM using the same IP as the one which was deleted => IP 10.1.1.50" ) self.vm_1 = VirtualMachine.create( self.apiclient, self.services["virtual_machine"], templateid=self.template.id, accountid=self.account.name, domainid=self.domain.id, serviceofferingid=self.service_offering.id, networkids=[str(self.network.id)], ipaddress="10.1.1.50") self.cleanup.append(self.vm_1) self.logger.debug("Testing DHCP hosts for VMs %s and %s" % (self.vm_1.id, self.vm_2.id)) self.test_dhcphosts(self.vm_1, router) self.test_dhcphosts(self.vm_2, router) return
def setUp(self): self.logger = MarvinLog(MarvinLog.LOGGER_TEST).get_logger() self.apiclient = self.testClient.getApiClient() self.services = self.testClient.getParsedTestDataConfig() self.vpc_offering = get_default_vpc_offering(self.apiclient) self.network_offering = get_default_network_offering(self.apiclient) # Get Zone, Domain and templates self.domain = get_domain(self.apiclient) self.zone = get_zone(self.apiclient, self.testClient.getZoneForTests()) template = get_template( self.apiclient, self.zone.id ) self.services["virtual_machine"]["zoneid"] = self.zone.id # Create an account, network, VM, Port forwarding rule, LB rules self.account = Account.create( self.apiclient, self.services["account"], admin=True, domainid=self.domain.id ) self.service_offering = get_default_virtual_machine_offering(self.apiclient) self.vpc = VPC.create( self.apiclient, self.services["vpc"], vpcofferingid=self.vpc_offering.id, zoneid=self.zone.id, account=self.account.name, domainid=self.account.domainid) ntwk = Network.create( api_client=self.apiclient, services=self.services["network_1"], accountid=self.account.name, domainid=self.domain.id, networkofferingid=self.network_offering.id, zoneid=self.zone.id, vpcid=self.vpc.id ) networkids = [] networkids.append(ntwk.id) self.virtual_machine = VirtualMachine.create( self.apiclient, self.services["virtual_machine"], templateid=template.id, accountid=self.account.name, domainid=self.account.domainid, serviceofferingid=self.service_offering.id, networkids=networkids ) self.ip_address = PublicIPAddress.create( self.apiclient, self.account.name, self.zone.id, self.account.domainid, vpcid=self.vpc.id ) ip_addrs = list_public_ip( self.apiclient, account=self.account.name, domainid=self.account.domainid, issourcenat=False ) try: self.ip_addr = ip_addrs[0] except Exception as e: raise Exception( "Failed: During acquiring source NAT for account: %s, :%s" % (self.account.name, e)) self.nat_rule = NATRule.create( self.apiclient, self.virtual_machine, self.services["natrule"], self.ip_addr.id, networkid=ntwk.id ) self.lb_rule = LoadBalancerRule.create( self.apiclient, self.services["lbrule"], self.ip_addr.id, accountid=self.account.name, networkid=ntwk.id ) self.cleanup = [ self.virtual_machine, self.account ] return