def test_0015_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.""" self.assertFalse(hasattr(subnet_participation, 'IpRanges'))
def test_0016_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_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_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_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 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 __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 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 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): """Add Firewall Rules in the gateway. Invokes the add_firewall_rule of the gateway. """ TestFirewallRules._org_client = Environment.get_client_in_default_org( TestFirewallRules._test_runner_role) TestFirewallRules._system_client = Environment.get_sys_admin_client() TestFirewallRules._config = Environment.get_config() gateway = Environment.get_test_gateway(TestFirewallRules._org_client) TestFirewallRules._gateway_obj = Gateway( TestFirewallRules._org_client, TestFirewallRules._name, href=gateway.get('href')) TestFirewallRules._external_network = Environment. \ get_test_external_network(TestFirewallRules._system_client) TestFirewallRules._gateway_obj.add_firewall_rule( TestFirewallRules._firewall_rule_name) firewall_rules_resource = \ TestFirewallRules._gateway_obj.get_firewall_rules() # Verify matchFound = False for firewallRule in firewall_rules_resource.firewallRules.firewallRule: if firewallRule['name'] == TestFirewallRules._firewall_rule_name: TestFirewallRules._rule_id = firewallRule.id matchFound = True break self.assertTrue(matchFound)
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_0010_add_ipsec_vpn(self): """Add Ip sec VPN in the gateway. Invokes the add_ipsec_vpn of the gateway. """ gateway = Environment.get_test_gateway(TestIpSecVpn._client) gateway_obj1 = Gateway(TestIpSecVpn._client, GatewayConstants.name, href=gateway.get('href')) gateway_obj2 = TestIpSecVpn._gateway_obj TestIpSecVpn._local_ip = self.__get_ip_address( gateway=gateway_obj1, ext_net_name=TestIpSecVpn._ext_net_name) TestIpSecVpn._peer_ip = self.__get_ip_address( gateway=gateway_obj2, ext_net_name=TestIpSecVpn._ext_net_name) gateway_obj1.add_ipsec_vpn(name=TestIpSecVpn._ipsec_vpn_name, peer_id=TestIpSecVpn._peer_id, peer_ip_address=TestIpSecVpn._peer_ip, local_id=TestIpSecVpn._local_id, local_ip_address=TestIpSecVpn._local_ip, local_subnet=TestIpSecVpn._local_subnet, peer_subnet=TestIpSecVpn._peer_subnet, shared_secret_encrypted=TestIpSecVpn._psk) gateway_obj1.reload() ipsec_vpn = gateway_obj1.get_ipsec_vpn() self.__validate_ip_sec_vpn(ipsec_vpn)
def get_gateway(self, gateway_name): gateway = self.vdc.get_gateway(gateway_name) if gateway is None: msg = "Gateway {0} not found".format(gateway_name) raise EntityNotFoundException(msg) extra_args = {"name": gateway_name, "href": gateway.get("href")} return Gateway(self.client, **extra_args)
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 get_gateway(self, gateway_name): gateway = self.vdc.get_gateway(gateway_name) if gateway is not None: for key, value in gateway.items(): if key == "href": return Gateway(self.client, name=gateway_name, href=value) msg = "Edge gateway {0} is not present" raise EntityNotFoundException(msg.format(gateway_name))
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 __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_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_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 __does_exist_gateway(self, gateway_name): vdc = VDC(TestIpSecVpn._client, resource=TestIpSecVpn._vdc_resource) gateway = vdc.get_gateway(TestIpSecVpn._gateway_name) if gateway: TestIpSecVpn._gateway_resource = gateway TestIpSecVpn._gateway_href = gateway.get('href') TestIpSecVpn._gateway_obj = Gateway( TestIpSecVpn._client, href=TestIpSecVpn._gateway_href) return True else: return False
def test_0022_enable_dns_relay_gateway(self): """enables the dns relay of the gateway. Invoke the configure_dns_default_gateway function of gateway. """ gateway_obj = Gateway(TestGateway._client, self._name, TestGateway._gateway.get('href')) task = gateway_obj.configure_dns_default_gateway('true') 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')) self.assertTrue(gateway_obj.get_resource().Configuration. UseDefaultRouteForDnsRelay) task = gateway_obj.configure_dns_default_gateway('false') 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_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_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 get_gateway(ctx, name): """Get the sdk's gateway resource. It will restore sessions if expired. It will read the client and vdc from context and make get_gateway call to VDC for gateway object. """ restore_session(ctx, vdc_required=True) client = ctx.obj['client'] vdc_href = ctx.obj['profiles'].get('vdc_href') vdc = VDC(client, href=vdc_href) gateway = vdc.get_gateway(name) gateway_resource = Gateway(client, href=gateway.get('href')) return gateway_resource
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)