def test_0055_edit_rate_limit(self): """Edits existing rate limit of gateway. Invokes the edit_rate_limits of the gateway. """ gateway_obj = Gateway(TestGateway._client, self._name, TestGateway._gateway.get('href')) ip_allocations = gateway_obj.list_configure_ip_settings() ip_allocation = ip_allocations[0] ext_network = ip_allocation.get('external_network') config = dict() config[ext_network] = [self._rate_limit_start, self._rate_limit_end] task = gateway_obj.edit_rate_limits(config) result = TestGateway._client.get_task_monitor().wait_for_success( task=task) self.assertEqual(result.get('status'), TaskStatus.SUCCESS.value) gateway_obj = Gateway(TestGateway._client, self._name, TestGateway._gateway.get('href')) for gateway_inf in \ gateway_obj.get_resource()\ .Configuration.GatewayInterfaces.GatewayInterface: if gateway_inf.Name == ext_network: self.assertEqual(self._rate_limit_start, gateway_inf.InRateLimit.text) self.assertEqual(self._rate_limit_end, gateway_inf.OutRateLimit.text)
def test_0030_update_static_routes(self): """Update a static route. Invokes the update_static_route of the StaticRoute. """ static_object = StaticRoute(TestStaticRoute._client, TestStaticRoute._name, TestStaticRoute._network_id) static_object.update_static_route( next_hop=TestStaticRoute._new_next_hop, mtu=TestStaticRoute._new_mtu, description=TestStaticRoute._new_desc) gateway = Environment. \ get_test_gateway(TestStaticRoute._client) gateway_obj = Gateway(TestStaticRoute._client, TestStaticRoute._name, href=gateway.get('href')) static_route = gateway_obj.get_static_routes() # Verify match_found = False for route in static_route.staticRoutes.route: if route.nextHop == TestStaticRoute._new_next_hop and \ route.mtu == TestStaticRoute._new_mtu and \ route.description == TestStaticRoute._new_desc: match_found = True break self.assertTrue(match_found)
def test_0000_setup(self): self._config = Environment.get_config() TestFirewallRule._logger = Environment.get_default_logger() TestFirewallRule._client = Environment.get_sys_admin_client() TestFirewallRule._runner = CliRunner() default_org = self._config['vcd']['default_org_name'] TestFirewallRule._ext_nw = self._config['external_network']['name'] self._login() TestFirewallRule._runner.invoke(org, ['use', default_org]) result = TestFirewallRule._runner.invoke( gateway, args=[ 'services', 'firewall', 'create', TestFirewallRule.__name, '--name', TestFirewallRule.__firewall_rule_name, '--action', 'accept', '--type', 'User', '--enabled', '--logging-enabled' ]) self.assertEqual(0, result.exit_code) gateway_res = Environment.get_test_gateway(TestFirewallRule._client) gateway_obj = Gateway(TestFirewallRule._client, href=gateway_res.get('href')) firewall_rules = gateway_obj.get_firewall_rules() for rule in firewall_rules.firewallRules.firewallRule: if rule.name == TestFirewallRule.__firewall_rule_name: TestFirewallRule._rule_id = rule.id break
def test_0030_update_static_routes(self): """Update a static route. Invokes the update_static_route of the StaticRoute. """ static_object = StaticRoute( TestStaticRoute._client, TestStaticRoute._name, TestStaticRoute._network_id) static_object.update_static_route( next_hop=TestStaticRoute._new_next_hop, mtu=TestStaticRoute._new_mtu, description=TestStaticRoute._new_desc) gateway = Environment. \ get_test_gateway(TestStaticRoute._client) gateway_obj = Gateway(TestStaticRoute._client, TestStaticRoute._name, href=gateway.get('href')) static_route = gateway_obj.get_static_routes() # Verify match_found = False for route in static_route.staticRoutes.route: if route.nextHop == TestStaticRoute._new_next_hop and \ route.mtu == TestStaticRoute._new_mtu and \ route.description == TestStaticRoute._new_desc: match_found = True break self.assertTrue(match_found)
def test_0000_setup(self): self._config = Environment.get_config() TestFirewallRule._logger = Environment.get_default_logger() TestFirewallRule._client = Environment.get_sys_admin_client() TestFirewallRule._runner = CliRunner() default_org = self._config['vcd']['default_org_name'] TestFirewallRule._ext_nw = self._config['external_network']['name'] self._login() TestFirewallRule._runner.invoke(org, ['use', default_org]) result = TestFirewallRule._runner.invoke( gateway, args=[ 'services', 'firewall', 'create', TestFirewallRule.__name, '--name', TestFirewallRule.__firewall_rule_name, '--action', 'accept', '--type', 'User', '--enabled', '--logging-enabled' ]) self.assertEqual(0, result.exit_code) gateway_res = Environment.get_test_gateway(TestFirewallRule._client) gateway_obj = Gateway( TestFirewallRule._client, href=gateway_res.get('href')) firewall_rules = gateway_obj.get_firewall_rules() for rule in firewall_rules.firewallRules.firewallRule: if rule.name == TestFirewallRule.__firewall_rule_name: TestFirewallRule._rule_id = rule.id break
def test_0030_update_nat_rule(self): """Update a Nat Rule. Invokes the update_nat_rule of the NatRule. """ gateway = Environment. \ get_test_gateway(TestNatRule._client) gateway_obj = Gateway(TestNatRule._client, TestNatRule._name, href=gateway.get('href')) nat_rule = gateway_obj.get_nat_rules() rule_id = self.__get_snat_rule_id(nat_rule) nat_obj = NatRule(TestNatRule._client, self._name, rule_id) nat_obj.update_nat_rule( original_address=TestNatRule._new_snat_orig_addr, translated_address=TestNatRule._new_snat_trans_addr, description=TestNatRule._new_snat_desc) #Verify nat_rule = gateway_obj.get_nat_rules() match_found = False for natRule in nat_rule.natRules.natRule: if natRule.originalAddress == TestNatRule._new_snat_orig_addr and \ natRule.translatedAddress == TestNatRule._new_snat_trans_addr and \ natRule.description == TestNatRule._new_snat_desc: match_found = True self.assertTrue(match_found)
def test_0012_edit_config_ipaddress(self): """It edits the config ip settings of gateway. In this user can only modify Subnet participation and config Ip address of gateway's external network. Invokes the edit_config_ip_settings of the gateway. """ gateway_obj = Gateway(TestGateway._client, self._name, TestGateway._gateway.get('href')) ip_allocations = gateway_obj.list_configure_ip_settings() ip_allocation = ip_allocations[0] ipconfig = dict() subnet_participation = dict() subnet_participation_settings = dict() subnet_participation_settings['enable'] = True subnet_participation_settings['ip_address'] = ip_allocation.get( 'ip_address')[0] subnet_participation[ip_allocation.get('gateway')[0]] = \ subnet_participation_settings ipconfig[ip_allocation.get('external_network')] = subnet_participation task = gateway_obj.edit_config_ip_settings(ipconfig) result = TestGateway._client.get_task_monitor().wait_for_success( task=task) self.assertEqual(result.get('status'), TaskStatus.SUCCESS.value)
def update_gw(self): response = dict() response['changed'] = False gateway_name = self.params.get('gateway_name') new_gateway_name = self.params.get('new_gateway_name') description = self.params.get('description') ha_enabled = self.params.get('ha_enabled') edge_gateway_href = None try: gateway = self.get_gateway(gateway_name) for key, value in gateway.items(): if key == "href": edge_gateway_href = value break gateway = Gateway( self.client, name=gateway_name, href=edge_gateway_href) update_task = gateway.edit_gateway(newname=new_gateway_name, desc=description, ha=ha_enabled) self.execute_task(update_task) msg = "Edge Gateway {0} has been updated with {1}" response['msg'] = msg.format(gateway_name, new_gateway_name) response['changed'] = True except EntityNotFoundException: msg = 'Edge Gateway {0} is not present' response['warnings'] = msg.format(gateway_name) return response
def test_0050_remove_sub_allocated_ip_pools(self): """Remove the sub allocated ip pools of gateway. Invokes the remove_sub_allocated_ip_pools of the gateway. """ gateway_obj = Gateway(TestGateway._client, self._name, TestGateway._gateway.get('href')) ip_allocations = gateway_obj.list_configure_ip_settings() ip_allocation = ip_allocations[0] ext_network = ip_allocation.get('external_network') config = TestGateway._config['external_network'] gateway_sub_allocated_ip_range1 = \ config['new_gateway_sub_allocated_ip_range'] task = gateway_obj.remove_sub_allocated_ip_pools( ext_network, [gateway_sub_allocated_ip_range1]) result = TestGateway._client.get_task_monitor().wait_for_success( task=task) self.assertEqual(result.get('status'), TaskStatus.SUCCESS.value) gateway_obj = Gateway(TestGateway._client, self._name, TestGateway._gateway.get('href')) subnet_participation = self.__get_subnet_participation( gateway_obj.get_resource(), ext_network) """removed the IpRanges form subnet_participation.""" is_ip_range_found = False if hasattr(subnet_participation, 'IpRanges'): for ip_range in subnet_participation.IpRanges.IpRange: if gateway_sub_allocated_ip_range1 == \ ip_range.StartAddress.text+'-'+ip_range.EndAddress\ .text: is_ip_range_found = True break self.assertFalse(is_ip_range_found)
def test_0098_teardown(self): """Remove the sub allocated ip pools of gateway. Invokes the remove_sub_allocated_ip_pools of the gateway. """ gateway = Environment. \ get_test_gateway(TestNatRule._client) gateway_obj = Gateway(TestNatRule._client, TestNatRule._name, href=gateway.get('href')) ip_allocations = gateway_obj.list_configure_ip_settings() ip_allocation = ip_allocations[0] ext_network = ip_allocation.get('external_network') config = TestNatRule._config['external_network'] gateway_sub_allocated_ip_range1 = \ config['gateway_sub_allocated_ip_range'] task = gateway_obj.remove_sub_allocated_ip_pools(ext_network, [gateway_sub_allocated_ip_range1]) result = TestNatRule._client.get_task_monitor().wait_for_success( task=task) self.assertEqual(result.get('status'), TaskStatus.SUCCESS.value) gateway = Environment. \ get_test_gateway(TestNatRule._client) gateway_obj = Gateway(TestNatRule._client, TestNatRule._name, href=gateway.get('href')) subnet_participation = self.__get_subnet_participation( gateway_obj.get_resource(), ext_network) """removed the IpRanges form subnet_participation.""" self.assertFalse(hasattr(subnet_participation, 'IpRanges'))
def test_0085_list_configure_default_gateway(self): """list configured default gateway. Invoke the list_configure_default_gateway function of gateway. """ gateway_obj = Gateway(TestGateway._client, self._name, TestGateway._gateway.get('href')) default_gateways = gateway_obj.list_configure_default_gateway() self.assertTrue(len(default_gateways) > 0)
def test_0023_list_configure_default_gateway(self): """list configured default gateway. Invoke the list_configure_default_gateway function of gateway. """ gateway_obj = Gateway(TestGateway._client, self._name, TestGateway._gateway.get('href')) default_gateways = gateway_obj.list_configure_default_gateway() self.assertTrue(len(default_gateways) > 0)
def test_0004_list_external_network_ip_allocations(self): """List external network ip allocations. Invoke the list_external_network_ip_allocations of the gateway. """ for client in (TestGateway._client, TestGateway._org_client): gateway_obj = Gateway(client, self._name, TestGateway._gateway.get('href')) ip_allocations = gateway_obj.list_external_network_ip_allocations() self.assertTrue(bool(ip_allocations))
def test_0018_list_syslog_settings(self): """List Tenant syslog server of the gateway. Invoke the list_syslog_server_ip function of gateway. """ for client in (TestGateway._client, TestGateway._org_client): gateway_obj = Gateway(client, self._name, TestGateway._gateway.get('href')) tenant_syslog_server = gateway_obj.list_syslog_server_ip() self.assertEqual(len(tenant_syslog_server), 1)
def test_0065_list_rate_limit(self): """List rate limit of the gateway. Invoke the list_rate_limits function of gateway. """ for client in (TestGateway._client, TestGateway._org_client): gateway_obj = Gateway(client, self._name, TestGateway._gateway.get('href')) rate_limit = gateway_obj.list_rate_limits() self.assertTrue(len(rate_limit) > 0)
def __remove_sub_allocate_ip_pool(self): gateway = Environment. \ get_test_gateway(TestExtNet._sys_admin_client) gateway_obj = Gateway(TestExtNet._sys_admin_client, href=gateway.get('href')) ext_net = TestExtNet._config['external_network']['name'] task = gateway_obj.remove_sub_allocated_ip_pools( ext_net, [TestExtNet._gateway_sub_allocate_ip_pool_range]) TestExtNet._sys_admin_client.get_task_monitor(). \ wait_for_success(task=task)
def test_0019_list_rate_limit(self): """List rate limit of the gateway. Invoke the list_rate_limits function of gateway. """ for client in (TestGateway._client, TestGateway._org_client): gateway_obj = Gateway(client, self._name, TestGateway._gateway.get('href')) rate_limit = gateway_obj.list_rate_limits() self.assertTrue(len(rate_limit) > 0)
def test_0060_list_syslog_settings(self): """List Tenant syslog server of the gateway. Invoke the list_syslog_server_ip function of gateway. """ for client in (TestGateway._client, TestGateway._org_client): gateway_obj = Gateway(client, self._name, TestGateway._gateway.get('href')) tenant_syslog_server = gateway_obj.list_syslog_server_ip() self.assertGreaterEqual(len(tenant_syslog_server), 1)
def test_0024_disable_configure_gateway(self): """configures the gateway. Invoke the configure_default_gateway function of gateway. """ gateway_obj = Gateway(TestGateway._client, self._name, TestGateway._gateway.get('href')) ip_allocations = gateway_obj.list_configure_ip_settings() ip_allocation = ip_allocations[0] ext_network = ip_allocation.get('external_network') gateway = ip_allocation.get('gateway') gateway_ip = gateway[0].split('/') gateway_obj = Gateway(TestGateway._client, self._name, TestGateway._gateway.get('href')) task = gateway_obj.configure_default_gateway(ext_network, gateway_ip[0], 'false') result = TestGateway._client.get_task_monitor().wait_for_success( task=task) self.assertEqual(result.get('status'), TaskStatus.SUCCESS.value) # verification gateway_obj = Gateway(TestGateway._client, self._name, TestGateway._gateway.get('href')) gateway_interface = self.__get_gateway_interface( gateway_obj.get_resource(), ext_network) self.assertTrue(gateway_interface.UseForDefaultRoute.text == 'false')
def test_0001_convert_to_advanced(self): """Convert the legacy gateway to advance gateway. Invoke the convert_to_advanced method for gateway. """ gateway_obj = Gateway(TestGateway._client, self._name, TestGateway._gateway.get('href')) task = gateway_obj.convert_to_advanced() result = TestGateway._client.get_task_monitor().wait_for_success( task=task) self.assertEqual(result.get('status'), TaskStatus.SUCCESS.value)
def test_0002_enable_dr(self): """Enable the Distributed routing. Invoke the enable_distributed_routing method for the gateway. """ gateway_obj = Gateway(TestGateway._client, self._name, TestGateway._gateway.get('href')) task = gateway_obj.enable_distributed_routing(True) result = TestGateway._client.get_task_monitor().wait_for_success( task=task) self.assertEqual(result.get('status'), TaskStatus.SUCCESS.value)
def test_0005_redeploy(self): """Redeploy the gateway. Invoke the redeploy function of gateway. """ for client in (TestGateway._client, TestGateway._org_client): gateway_obj = Gateway(client, self._name, TestGateway._gateway.get('href')) task = gateway_obj.redeploy() result = TestGateway._client.get_task_monitor().wait_for_success( task=task) self.assertEqual(result.get('status'), TaskStatus.SUCCESS.value)
def test_0010_set_tenant_syslog_server_ip(self): """Set Tenant syslog server IP of the gateway. Invoke the set_tenant_syslog_server_ip function of gateway. """ gateway_obj = Gateway(TestGateway._client, self._name, TestGateway._gateway.get('href')) task = gateway_obj.set_tenant_syslog_server_ip('192.168.5.6') result = TestGateway._client.get_task_monitor().wait_for_success( task=task) self.assertEqual(result.get('status'), TaskStatus.SUCCESS.value)
def test_0006_sync_syslog_settings(self): """Sync syslog settings of the gateway. Invoke the sync_syslog_settings function of gateway. """ for client in (TestGateway._client, TestGateway._org_client): gateway_obj = Gateway(client, self._name, TestGateway._gateway.get('href')) task = gateway_obj.sync_syslog_settings() result = TestGateway._client.get_task_monitor().wait_for_success( task=task) self.assertEqual(result.get('status'), TaskStatus.SUCCESS.value)
def test_0003_modify_form_factor(self): """Modify form factor. Invoke the modify_form_factor method for the gateway. """ gateway_obj = Gateway(TestGateway._client, self._name, TestGateway._gateway.get('href')) task = gateway_obj.modify_form_factor( GatewayBackingConfigType.FULL.value) result = TestGateway._client.get_task_monitor().wait_for_success( task=task) self.assertEqual(result.get('status'), TaskStatus.SUCCESS.value)
def test_0020_list_nat_rules(self): """List all nat rules on a gateway. Invokes the list_nat_rules of the Gateway. """ gateway = Environment. \ get_test_gateway(TestNatRule._client) gateway_obj = Gateway(TestNatRule._client, TestNatRule._name, href=gateway.get('href')) nat_rule_list = gateway_obj.list_nat_rules() #Verify self.assertTrue(len(nat_rule_list) > 0)
def test_0001_list_static_routes(self): """List Static Routes of the gateway. Invokes the list_static_routes of the gateway. """ TestStaticRoute._config = Environment.get_config() gateway = Environment. \ get_test_gateway(TestStaticRoute._client) gateway_obj = Gateway(TestStaticRoute._client, TestStaticRoute._name, href=gateway.get('href')) static_route_list = gateway_obj.list_static_routes() # Verify self.assertTrue(len(static_route_list) > 0)
def test_0001_list_dhcp_pools(self): """List DHCP pools of the gateway. Invokes the list_dhcp_pools of the gateway. """ TestDhcp._config = Environment.get_config() gateway = Environment. \ get_test_gateway(TestDhcp._client) gateway_obj = Gateway(TestDhcp._client, TestDhcp._name, href=gateway.get('href')) dhcp_pool_list = gateway_obj.list_dhcp_pools() # Verify self.assertTrue(len(dhcp_pool_list) > 0)
def test_0001_convert_to_advanced(self): """Convert the legacy gateway to advance gateway. Invoke the convert_to_advanced method for gateway. """ if float(TestGateway._api_version) >= float( ApiVersion.VERSION_32.value): return gateway_obj = Gateway(TestGateway._org_client, self._name, TestGateway._gateway.get('href')) task = gateway_obj.convert_to_advanced() result = TestGateway._client.get_task_monitor().wait_for_success( task=task) self.assertEqual(result.get('status'), TaskStatus.SUCCESS.value)
def test_0000_setup(self): """Add the sub allocated ip pools to gateway. This sub allocated ip pools required by the Nat Rule Invokes the add_sub_allocated_ip_pools of the gateway. """ TestNatRule._client = Environment.get_sys_admin_client() TestNatRule._config = Environment.get_config() gateway = Environment. \ get_test_gateway(TestNatRule._client) gateway_obj = Gateway(TestNatRule._client, TestNatRule._name, href=gateway.get('href')) ip_allocations = gateway_obj.list_configure_ip_settings() ip_allocation = ip_allocations[0] ext_network = ip_allocation.get('external_network') config = TestNatRule._config['external_network'] gateway_sub_allocated_ip_range = \ config['gateway_sub_allocated_ip_range'] ip_range_list = [gateway_sub_allocated_ip_range] task = gateway_obj.add_sub_allocated_ip_pools(ext_network, ip_range_list) result = TestNatRule._client.get_task_monitor().wait_for_success( task=task) self.assertEqual(result.get('status'), TaskStatus.SUCCESS.value) gateway_obj = Gateway(TestNatRule._client, TestNatRule._name, href=gateway.get('href')) subnet_participation = self.__get_subnet_participation( gateway_obj.get_resource(), ext_network) ip_ranges = gateway_obj.get_sub_allocate_ip_ranges_element( subnet_participation) self.__validate_ip_range(ip_ranges, gateway_sub_allocated_ip_range)
def test_0015_list_external_network_config_ip_allocations(self): """List external network configure ip allocations. Invoke the list_gateways_configure_ip_settings of the gateway. """ for client in (TestGateway._client, TestGateway._org_client): gateway_obj = Gateway(client, self._name, TestGateway._gateway.get('href')) ip_allocations = gateway_obj.list_configure_ip_settings() platform = Platform(TestGateway._client) external_networks = platform.list_external_networks() self.assertTrue(bool(ip_allocations)) exnet = ip_allocations[0].get('external_network') self.assertEqual(external_networks[0].get('name'), exnet)
def test_0025_remove_external_network(self): """Remove an exernal netowrk from the gateway. Invoke the remove_external_network function of gateway. """ gateway_obj = Gateway(TestGateway._client, self._name, TestGateway._gateway.get('href')) task = gateway_obj.remove_external_network( TestGateway._external_network2.get('name')) result = TestGateway._client.get_task_monitor().wait_for_success( task=task) self.assertEqual(result.get('status'), TaskStatus.SUCCESS.value) self._delete_external_network(TestGateway._external_network2)
def test_0095_add_firewall_rule(self): """Add Firewall Rule's in the gateway.""" gateway_obj = Gateway(TestGateway._client, self._name, TestGateway._gateway.get('href')) gateway_obj.add_firewall_rule(TestGateway._firewall_rule_name) firewall_rule = gateway_obj.get_firewall_rules() # Verify matchFound = False for firewallRule in firewall_rule.firewallRules.firewallRule: if firewallRule['name'] == TestGateway._firewall_rule_name: matchFound = True break self.assertTrue(matchFound)
def test_0025_add_firewall_rule(self): """Add Firewall Rule's in the gateway.""" gateway_obj = Gateway(TestGateway._client, self._name, TestGateway._gateway.get('href')) gateway_obj.add_firewall_rule(TestGateway._firewall_rule_name) firewall_rule = gateway_obj.get_firewall_rules() # Verify matchFound = False for firewallRule in firewall_rule.firewallRules.firewallRule: if firewallRule['name'] == TestGateway._firewall_rule_name: matchFound = True break self.assertTrue(matchFound)
def test_0014_edit_sub_allocated_ip_pools(self): """It edits the sub allocated ip pools of gateway. Invokes the edit_sub_allocated_ip_pools of the gateway. """ gateway_obj = Gateway(TestGateway._client, self._name, TestGateway._gateway.get('href')) ip_allocations = gateway_obj.list_configure_ip_settings() ip_allocation = ip_allocations[0] ext_network = ip_allocation.get('external_network') config = TestGateway._config['external_network'] gateway_sub_allocated_ip_range = \ config['gateway_sub_allocated_ip_range'] gateway_sub_allocated_ip_range1 = \ config['new_gateway_sub_allocated_ip_range'] task = gateway_obj.edit_sub_allocated_ip_pools( ext_network, gateway_sub_allocated_ip_range, gateway_sub_allocated_ip_range1) result = TestGateway._client.get_task_monitor().wait_for_success( task=task) self.assertEqual(result.get('status'), TaskStatus.SUCCESS.value) gateway_obj = Gateway(TestGateway._client, self._name, TestGateway._gateway.get('href')) subnet_participation = self.__get_subnet_participation( gateway_obj.get_resource(), ext_network) ip_ranges = gateway_obj.get_sub_allocate_ip_ranges_element( subnet_participation) self.__validate_ip_range(ip_ranges, gateway_sub_allocated_ip_range)
def test_0009_remove_external_network(self): """Remove an exernal netowrk from the gateway. Invoke the remove_external_network function of gateway. """ gateway_obj = Gateway(TestGateway._client, self._name, TestGateway._gateway.get('href')) task = gateway_obj.remove_external_network( TestGateway._external_network2.get('name')) result = TestGateway._client.get_task_monitor().wait_for_success( task=task) self.assertEqual(result.get('status'), TaskStatus.SUCCESS.value) self._delete_external_network(TestGateway._external_network2)
def test_0001_list_firewall_rules(self): """List Firewall Rules of the gateway. Invokes the get_firewall_rules_list of the gateway. """ TestFirewallRules._config = Environment.get_config() gateway = Environment. \ get_test_gateway(TestFirewallRules._org_client) gateway_obj = Gateway(TestFirewallRules._org_client, TestFirewallRules._name, href=gateway.get('href')) firewall_rules_list = gateway_obj.get_firewall_rules_list() # Verify self.assertTrue(len(firewall_rules_list) > 0)
def test_0007_list_external_network_config_ip_allocations(self): """List external network configure ip allocations. Invoke the list_gateways_configure_ip_settings of the gateway. """ for client in (TestGateway._client, TestGateway._org_client): gateway_obj = Gateway(client, self._name, TestGateway._gateway.get('href')) ip_allocations = gateway_obj.list_configure_ip_settings() platform = Platform(TestGateway._client) external_networks = platform.list_external_networks() self.assertTrue(bool(ip_allocations)) exnet = ip_allocations[0].get('external_network') self.assertEqual(external_networks[0].get('name'), exnet)
def test_0001_list_firewall_rules(self): """List Firewall Rules of the gateway. Invokes the get_firewall_rules_list of the gateway. """ TestFirewallRules._config = Environment.get_config() gateway = Environment. \ get_test_gateway(TestFirewallRules._org_client) gateway_obj = Gateway( TestFirewallRules._org_client, TestFirewallRules._name, href=gateway.get('href')) firewall_rules_list = gateway_obj.get_firewall_rules_list() # Verify self.assertTrue(len(firewall_rules_list) > 0)
def __find_element(self, type, object_type, value, group_type): """Find element in the properties using group type. :param str type: It can be source/destination :param dict object_type: object types :param str value: value :param str group_type: group type. e.g., groupingObjectId """ gateway_res = Gateway(self.client, resource=self.parent) object_list = gateway_res.list_firewall_objects(type, object_type) for object in object_list: if object.get('name') == value: properties = object.get('prop') for prop in properties: if prop.get('name') == group_type: return create_element(group_type, prop.get('value'))
def test_0030_edit_gateway(self): """Edit the gateway name. Invokes the edit_gateway of the gateway. """ gateway_obj = Gateway(TestGateway._client, self._name, TestGateway._gateway.get('href')) task = gateway_obj.edit_gateway(newname='gateway2') result = TestGateway._client.get_task_monitor().wait_for_success( task=task) self.assertEqual(result.get('status'), TaskStatus.SUCCESS.value) '''resetting back to original gateway name''' task = gateway_obj.edit_gateway(TestGateway._name) result = TestGateway._client.get_task_monitor().wait_for_success( task=task) self.assertEqual(result.get('status'), TaskStatus.SUCCESS.value)
def test_0098_teardown(self): """Remove the DHCP ip pools of gateway. Invokes the delete_pool of the DhcpPool. """ gateway = Environment. \ get_test_gateway(TestDhcp._client) gateway_obj = Gateway(TestDhcp._client, TestDhcp._name, href=gateway.get('href')) dhcp_resource = gateway_obj.get_dhcp() for ip_pool in dhcp_resource.ipPools.ipPool: dhcp_pool_object = DhcpPool(TestDhcp._client, self._name, ip_pool.poolId) dhcp_pool_object.delete_pool() dhcp_resource = gateway_obj.get_dhcp() self.assertFalse(hasattr(dhcp_resource.ipPools, 'ipPool'))
def test_0010_edit_gateway_name(self): """Edit the gateway name. Invokes the edit_gateway_name of the gateway. """ gateway_obj = Gateway(TestGateway._client, self._name, TestGateway._gateway.get('href')) task = gateway_obj.edit_gateway_name('gateway2') result = TestGateway._client.get_task_monitor().wait_for_success( task=task) self.assertEqual(result.get('status'), TaskStatus.SUCCESS.value) '''resetting back to original gateway name''' task = gateway_obj.edit_gateway_name(TestGateway._name) result = TestGateway._client.get_task_monitor().wait_for_success( task=task) self.assertEqual(result.get('status'), TaskStatus.SUCCESS.value)
def __create_advanced_gateway(self): """Creates a gateway.""" ext_config = TestIpSecVpn._config['external_network'] vdc_reource = TestIpSecVpn._vdc_resource api_version = TestIpSecVpn._config['vcd']['api_version'] vdc = VDC(TestIpSecVpn._client, resource=vdc_reource) gateway = vdc.get_gateway(TestIpSecVpn._gateway_name) if self.__does_exist_gateway(TestIpSecVpn._gateway_name): return if float(api_version) <= float( ApiVersion.VERSION_30.value): gateway = vdc.create_gateway_api_version_30( TestIpSecVpn._gateway_name, [ext_config['name']]) elif float(api_version) == float(ApiVersion.VERSION_31.value): gateway = vdc.create_gateway_api_version_31( TestIpSecVpn._gateway_name, [ext_config['name']], should_create_as_advanced=True) elif float(api_version) >= float(ApiVersion.VERSION_32.value): gateway = vdc.create_gateway_api_version_32( TestIpSecVpn._gateway_name, [ext_config['name']], should_create_as_advanced=True) TestIpSecVpn._client.get_task_monitor(). \ wait_for_success(task=gateway.Tasks.Task[0]) TestIpSecVpn._gateway_href = gateway.get('href') TestIpSecVpn._gateway_obj = Gateway(TestIpSecVpn._client, href=TestIpSecVpn._gateway_href) TestIpSecVpn._gateway_resource = TestIpSecVpn. \ _gateway_obj.get_resource()
def update_firewall_rule_sequence(self, index): """Change firewall rule's sequence of gateway. :param int index: new sequence index of firewall rule. """ index = int(index) gateway_res = Gateway(self.client, resource=self.parent) firewall_rule = gateway_res.get_firewall_rules() resource = self._get_resource() for rule in firewall_rule.firewallRules.firewallRule: if rule.id == resource.id: firewall_rule.firewallRules.remove(rule) firewall_rule.firewallRules.insert(index, rule) break return self.client.put_resource(self._build_firewall_rules_href(), firewall_rule, EntityType.DEFAULT_CONTENT_TYPE.value)
def test_002_get_dhcp_pool_info(self): """Get the details of DHCP Pool. Invokes the get_pool_info of the DhcpPool. """ gateway = Environment. \ get_test_gateway(TestDhcp._client) gateway_obj = Gateway(TestDhcp._client, TestDhcp._name, href=gateway.get('href')) dhcp_pool_list = gateway_obj.list_dhcp_pools() pool_id = dhcp_pool_list[0]['ID'] pool_obj = DhcpPool(TestDhcp._client, self._name, pool_id) pool_info = pool_obj.get_pool_info() #Verify self.assertTrue(len(pool_info) > 0) self.assertEqual(pool_info['IPRange'], TestDhcp._pool_ip_range)
def test_0025_reorder_nat_rule(self): """Reorder the nat rule position on gateway. Invokes the reorder_nat_rule of the Gateway. """ gateway = Environment. \ get_test_gateway(TestNatRule._client) gateway_obj = Gateway(TestNatRule._client, TestNatRule._name, href=gateway.get('href')) nat_rule = gateway_obj.get_nat_rules() rule_id = self.__get_snat_rule_id(nat_rule) index1 = self.__get_snat_rule_index(nat_rule) new_index = 2 gateway_obj.reorder_nat_rule(rule_id, new_index) nat_rule = gateway_obj.get_nat_rules() index2 = self.__get_snat_rule_index(nat_rule) self.assertNotEqual(index1, index2)