def testBasicCommands(self): self.Run('compute networks create {0} --subnet-mode custom'.format( self.network_name)) self.Run( 'compute routers create {0} --network {1} --region {2}'.format( self.router_name, self.network_name, self.region)) self.Run('compute routers nats create {0} --router {1} --region {2} ' '--nat-all-subnet-ip-ranges --auto-allocate-nat-external-ips'. format(self.nat_name, self.router_name, self.region)) self.Run('compute routers nats describe {0} --router {1} --region {2}'. format(self.nat_name, self.router_name, self.region)) self.AssertNewOutputContains('name: {0}'.format(self.nat_name)) self.Run('compute routers get-status {0} --region {1}'.format( self.router_name, self.region)) self.AssertNewOutputContains(self.nat_name) self.Run('compute routers nats list --router {0} --region {1}'.format( self.router_name, self.region)) self.AssertNewOutputContains(self.nat_name) # Retry deletion in case resource was not ready yet. cmd = 'compute routers nats delete {0} --router {1} --region {2}'.format( self.nat_name, self.router_name, self.region) Retry(lambda: self.Run(cmd)) cmd = 'compute routers delete {0} --region {1}'.format( self.router_name, self.region) Retry(lambda: self.Run(cmd)) cmd = 'compute networks delete {0}'.format(self.network_name) Retry(lambda: self.Run(cmd))
def testAddBgpPeerWithAdvertisements(self): self.Run('compute networks create {0} --subnet-mode custom'.format( self.network_name)) self.Run('compute routers create {0} --network {1} --region {2} ' '--asn 65000 '.format(self.router_name, self.network_name, self.region)) self.Run('compute routers add-interface {0} --region {1} ' '--interface-name my-interface --vpn-tunnel vpn'.format( self.router_name, self.region)) self.Run( 'compute routers add-bgp-peer {0} --region {1} --peer-name {2} ' '--peer-asn 65100 --interface my-interface ' '--advertisement-mode CUSTOM ' '--set-advertisement-groups ALL_SUBNETS ' '--set-advertisement-ranges 10.0.10.0/30'.format( self.router_name, self.region, self.peer_name)) result = self.Run( 'compute routers describe {0} --region {1} --format disable'. format(self.router_name, self.region)) self.assertEqual(result.bgpPeers[0].advertiseMode.name, 'CUSTOM') self.assertEqual(result.bgpPeers[0].advertisedGroups[0].name, 'ALL_SUBNETS') self.assertEqual(result.bgpPeers[0].advertisedIpRanges[0].range, '10.0.10.0/30') # Retry deletion in case resource was not ready yet. cmd = 'compute routers delete {0} --region {1}'.format( self.router_name, self.region) Retry(lambda: self.Run(cmd)) cmd = 'compute networks delete {0}'.format(self.network_name) Retry(lambda: self.Run(cmd))
def testCreateWithAdvertisements(self): self.Run('compute networks create {0} --subnet-mode custom'.format( self.network_name)) self.Run('compute routers create {0} --network {1} --region {2} ' '--asn 65000 ' '--advertisement-mode CUSTOM ' '--set-advertisement-groups ALL_SUBNETS ' '--set-advertisement-ranges 10.0.10.0/30'.format( self.router_name, self.network_name, self.region)) result = self.Run('compute routers describe {0} --region {1} --format ' 'disable'.format(self.router_name, self.region)) self.assertEqual(result.bgp.advertiseMode.name, 'CUSTOM') self.assertEqual(result.bgp.advertisedGroups[0].name, 'ALL_SUBNETS') self.assertEqual(result.bgp.advertisedIpRanges[0].range, '10.0.10.0/30') # Retry deletion in case resource was not ready yet. cmd = 'compute routers delete {0} --region {1}'.format( self.router_name, self.region) Retry(lambda: self.Run(cmd)) cmd = 'compute networks delete {0}'.format(self.network_name) Retry(lambda: self.Run(cmd))
def testUpdatePeerAdvertisementsIncremental(self): self.Run('compute networks create {0} --subnet-mode custom'.format( self.network_name)) self.Run('compute routers create {0} --network {1} --region {2} ' '--asn 65000'.format(self.router_name, self.network_name, self.region)) self.Run('compute routers add-interface {0} --region {1} ' '--interface-name my-interface --vpn-tunnel vpn'.format( self.router_name, self.region)) self.Run( 'compute routers add-bgp-peer {0} --region {1} --peer-name {2} ' '--peer-asn 65100 --interface my-interface'.format( self.router_name, self.region, self.peer_name)) self.Run( 'compute routers update-bgp-peer {0} --region {1} --peer-name {2} ' '--advertisement-mode CUSTOM'.format(self.router_name, self.region, self.peer_name)) self.Run( 'compute routers update-bgp-peer {0} --region {1} --peer-name {2} ' '--add-advertisement-groups ALL_SUBNETS'.format( self.router_name, self.region, self.peer_name)) self.Run( 'compute routers update-bgp-peer {0} --region {1} --peer-name {2} ' '--add-advertisement-ranges 10.0.10.0/30'.format( self.router_name, self.region, self.peer_name)) self.Run('compute routers describe {0} --region {1}'.format( self.router_name, self.region)) self.AssertNewOutputContainsAll( ['CUSTOM', 'ALL_SUBNETS', '10.0.10.0/30'], reset=True, normalize_space=True) # Test clearing custom advertisements via incremental remove commands. self.Run( 'compute routers update-bgp-peer {0} --region {1} --peer-name {2} ' '--remove-advertisement-groups ALL_SUBNETS'.format( self.router_name, self.region, self.peer_name)) self.Run( 'compute routers update-bgp-peer {0} --region {1} --peer-name {2} ' '--remove-advertisement-ranges 10.0.10.0/30'.format( self.router_name, self.region, self.peer_name)) self.Run('compute routers describe {0} --region {1}'.format( self.router_name, self.region)) self.AssertNewOutputNotContains('ALL_SUBNETS', reset=False, normalize_space=True) self.AssertNewOutputNotContains('10.0.10.0/30', reset=False, normalize_space=True) cmd = 'compute routers delete {0} --region {1}'.format( self.router_name, self.region) Retry(lambda: self.Run(cmd)) cmd = 'compute networks delete {0}'.format(self.network_name) Retry(lambda: self.Run(cmd))
def testBasicCommands(self): # TODO(b/62286653) Add a context manager to handle test resource creation. self.Run('compute networks create {0} --subnet-mode custom'.format( self.network_name)) self.Run('compute routers create {0} --network {1} --region {2} ' '--asn 65000'.format(self.router_name, self.network_name, self.region)) self.AssertNewOutputContains(self.router_name) self.Run('compute routers describe {0} --region {1}'.format( self.router_name, self.region)) self.AssertNewOutputContains('name: {0}'.format(self.router_name)) self.Run('compute routers get-status {} --region {}'.format( self.router_name, self.region)) self.AssertNewOutputContains('kind: compute#routerStatusResponse') self.Run('compute routers add-interface {0} --region {1} ' '--interface-name my-interface --vpn-tunnel vpn'.format( self.router_name, self.region)) self.Run('compute routers describe {0} --region {1}'.format( self.router_name, self.region)) self.AssertNewOutputContains('my-interface') self.Run('compute routers remove-interface {0} --region {1} ' '--interface-name my-interface'.format( self.router_name, self.region)) self.Run('compute routers describe {0} --region {1}'.format( self.router_name, self.region)) self.AssertNewOutputNotContains('my-interface') self.Run( 'compute routers add-bgp-peer {0} --region {1} ' '--peer-name {2} --peer-asn 65100 --interface my-interface'.format( self.router_name, self.region, self.peer_name)) self.Run('compute routers describe {0} --region {1}'.format( self.router_name, self.region)) self.AssertNewOutputContains(self.peer_name) self.Run('compute routers remove-bgp-peer {0} --region {1} ' '--peer-name {2}'.format(self.router_name, self.region, self.peer_name)) self.Run('compute routers describe {0} --region {1}'.format( self.router_name, self.region)) self.AssertNewOutputNotContains(self.peer_name) # Retry deletion in case resource was not ready yet. cmd = 'compute routers delete {0} --region {1}'.format( self.router_name, self.region) Retry(lambda: self.Run(cmd)) cmd = 'compute networks delete {0}'.format(self.network_name) Retry(lambda: self.Run(cmd))
def testWithStaticIps(self): self.Run('compute networks create {0} --subnet-mode custom'.format( self.network_name)) self.Run( 'compute routers create {0} --network {1} --region {2}'.format( self.router_name, self.network_name, self.region)) self.Run('compute addresses create {0} {1} --region {2}'.format( self.address_name_1, self.address_name_2, self.region)) self.Run('compute addresses describe {0} --region {1}'.format( self.address_name_1, self.region)) output = self.GetNewOutput() # Output contains a line of the form "address: 10.1.2.3" ip_address_1 = [st for st in output.split('\n') if 'address' in st][0].split()[1] self.Run('compute addresses describe {0} --region {1}'.format( self.address_name_2, self.region)) output = self.GetNewOutput() ip_address_2 = [st for st in output.split('\n') if 'address' in st][0].split()[1] self.Run( 'compute routers nats create {0} --router {1} --region {2} ' '--nat-all-subnet-ip-ranges --nat-external-ip-pool {3},{4}'.format( self.nat_name, self.router_name, self.region, self.address_name_1, self.address_name_2)) self.Run('compute routers nats describe {0} --router {1} --region {2}'. format(self.nat_name, self.router_name, self.region)) self.AssertNewOutputContains('name: {0}'.format(self.nat_name)) self.Run('compute routers get-status {0} --region {1}'.format( self.router_name, self.region)) output = self.GetNewOutput() self.assertIn(self.nat_name, output) self.assertIn(ip_address_1, output) self.assertIn(ip_address_2, output) # Retry deletion in case resource was not ready yet. cmd = 'compute routers nats delete {0} --router {1} --region {2}'.format( self.nat_name, self.router_name, self.region) Retry(lambda: self.Run(cmd)) cmd = 'compute routers delete {0} --region {1}'.format( self.router_name, self.region) Retry(lambda: self.Run(cmd)) cmd = 'compute networks delete {0}'.format(self.network_name) Retry(lambda: self.Run(cmd)) cmd = 'compute addresses delete {0} {1} --region {2}'.format( self.address_name_1, self.address_name_2, self.region) Retry(lambda: self.Run(cmd))
def testSubnetworksPrivateIpGoogleAccess(self): self.Run('compute networks create {0} --subnet-mode custom'.format( self.network_name)) self.AssertNewOutputContains(self.network_name) # First create a subnetwork without privateIpGoogleAccess enabled. self.Run('beta compute networks subnets create {0} --network {1} ' '--region {2} --range 10.11.12.0/24'.format( self.subnetwork_name, self.network_name, self.region)) self.AssertNewOutputContains(self.subnetwork_name) self.Run( 'beta compute networks subnets describe {0} --region {1}'.format( self.subnetwork_name, self.region)) self.AssertNewOutputContains('privateIpGoogleAccess: false') # Set --enable-private-ip-google-access. self.Run('beta compute networks subnets update {0} --region {1} ' '--enable-private-ip-google-access'.format( self.subnetwork_name, self.region)) self.Run( 'beta compute networks subnets describe {0} --region {1}'.format( self.subnetwork_name, self.region)) self.AssertNewOutputContains('privateIpGoogleAccess: true') # Turn it off again. self.Run('beta compute networks subnets update {0} --region {1} ' '--no-enable-private-ip-google-access'.format( self.subnetwork_name, self.region)) self.Run( 'beta compute networks subnets describe {0} --region {1}'.format( self.subnetwork_name, self.region)) self.AssertNewOutputContains('privateIpGoogleAccess: false') # Delete the subnet. self.Run('compute networks subnets delete {0} --region {1}'.format( self.subnetwork_name, self.region)) # Create the subnet again but with --private-ip-google-access enabled this # time. self.Run('beta compute networks subnets create {0} --network {1} ' '--region {2} --range 10.11.12.0/24 ' '--enable-private-ip-google-access'.format( self.subnetwork_name, self.network_name, self.region)) self.AssertNewOutputContains(self.subnetwork_name) self.Run( 'beta compute networks subnets describe {0} --region {1}'.format( self.subnetwork_name, self.region)) self.AssertNewOutputContains('privateIpGoogleAccess: true') # Delete the subnet. self.Run('compute networks subnets delete {0} --region {1}'.format( self.subnetwork_name, self.region)) cmd = 'compute networks delete {0}'.format(self.network_name) Retry(lambda: self.Run(cmd))
def testLogging(self): self.Run('compute networks create {0} --subnet-mode custom'.format( self.network_name)) self.Run( 'compute routers create {0} --network {1} --region {2}'.format( self.router_name, self.network_name, self.region)) self.Run('compute routers nats create {0} --router {1} --region {2} ' '--nat-all-subnet-ip-ranges --auto-allocate-nat-external-ips ' '--enable-logging '.format(self.nat_name, self.router_name, self.region)) self.Run('compute routers nats describe {0} --router {1} --region {2}'. format(self.nat_name, self.router_name, self.region)) self.AssertNewOutputContainsAll([ 'name: {0}'.format(self.nat_name), 'logConfig:', 'enable: true', # Default filter should be ALL. 'filter: ALL' ]) # Change the log filter, verify that it's reflected on describe self.Run('compute routers nats update {0} --router {1} --region {2} ' '--log-filter TRANSLATIONS_ONLY'.format( self.nat_name, self.router_name, self.region)) self.Run('compute routers nats describe {0} --router {1} --region {2}'. format(self.nat_name, self.router_name, self.region)) self.AssertNewOutputContains('filter: TRANSLATIONS_ONLY') # Retry deletion in case resource was not ready yet. cmd = 'compute routers nats delete {0} --router {1} --region {2}'.format( self.nat_name, self.router_name, self.region) Retry(lambda: self.Run(cmd)) cmd = 'compute routers delete {0} --region {1}'.format( self.router_name, self.region) Retry(lambda: self.Run(cmd)) cmd = 'compute networks delete {0}'.format(self.network_name) Retry(lambda: self.Run(cmd))
def testSubnetworks(self): self.Run('compute networks create {0} --subnet-mode custom'.format( self.network_name)) self.AssertNewOutputContains(self.network_name) self.Run('compute networks subnets create {0} --network {1} ' '--region {2} --range 10.11.12.0/24'.format( self.subnetwork_name, self.network_name, self.region)) self.AssertNewOutputContains(self.subnetwork_name) self.Run('compute networks subnets describe {0} --region {1}'.format( self.subnetwork_name, self.region)) self.AssertNewOutputContains('name: {0}'.format(self.subnetwork_name)) # Do not assert the output to avoid flakiness, because it depends on Ncon # index for the result, which sometimes has a long delay but is out of # control of Arcus. self.Run('alpha compute networks subnets list-usable') self.Run('compute networks subnets delete {0} --region {1}'.format( self.subnetwork_name, self.region)) cmd = 'compute networks delete {0}'.format(self.network_name) Retry(lambda: self.Run(cmd))
def testSubnetworksAddRemoveSecondaryRange(self): self.Run('compute networks create {0} --subnet-mode custom'.format( self.network_name)) self.AssertNewOutputContains(self.network_name) # First create a subnetwork with no secondary ranges. self.Run('compute networks subnets create {0} --network {1} ' '--region {2} --range 10.11.12.0/24'.format( self.subnetwork_name, self.network_name, self.region)) self.AssertNewOutputContains(self.subnetwork_name) self.Run('compute networks subnets describe {0} --region {1}'.format( self.subnetwork_name, self.region)) self.AssertNewOutputContains('privateIpGoogleAccess: false') self.AssertNewOutputNotContains('10.11.13.0/24') # Add a secondary range. self.Run('compute networks subnets update {0} --region {1} ' '--add-secondary-ranges range1=10.11.13.0/24'.format( self.subnetwork_name, self.region)) self.ClearOutput() self.Run('compute networks subnets describe {0} --region {1}'.format( self.subnetwork_name, self.region)) self.AssertNewOutputContains('10.11.13.0/24') # Remove it. self.Run('compute networks subnets update {0} --region {1} ' '--remove-secondary-ranges range1'.format( self.subnetwork_name, self.region)) self.ClearOutput() self.Run('compute networks subnets describe {0} --region {1}'.format( self.subnetwork_name, self.region)) self.AssertNewOutputNotContains('10.11.13.0/24') # Delete the subnet. self.Run('compute networks subnets delete {0} --region {1}'.format( self.subnetwork_name, self.region)) cmd = 'compute networks delete {0}'.format(self.network_name) Retry(lambda: self.Run(cmd))
def testUpdatePeerAdvertisements(self): # TODO(b/62286653) Add a context manager to handle test resource creation. self.Run('compute networks create {0} --subnet-mode custom'.format( self.network_name)) self.Run('compute routers create {0} --network {1} --region {2} ' '--asn 65000'.format(self.router_name, self.network_name, self.region)) self.Run('compute routers add-interface {0} --region {1} ' '--interface-name my-interface --vpn-tunnel vpn'.format( self.router_name, self.region)) self.Run( 'compute routers add-bgp-peer {0} --region {1} --peer-name {2} ' '--peer-asn 65100 --interface my-interface'.format( self.router_name, self.region, self.peer_name)) self.Run( 'compute routers update-bgp-peer {0} --region {1} --peer-name {2} ' '--advertisement-mode CUSTOM ' '--set-advertisement-groups ALL_SUBNETS ' '--set-advertisement-ranges 10.0.10.0/30'.format( self.router_name, self.region, self.peer_name)) self.Run('compute routers describe {0} --region {1}'.format( self.router_name, self.region)) self.AssertNewOutputContainsAll( ['CUSTOM', 'ALL_SUBNETS', '10.0.10.0/30'], reset=True, normalize_space=True) # Test clearing custom advertisements via explicit Patch. self.Run( 'compute routers update-bgp-peer {0} --region {1} --peer-name {2} ' '--set-advertisement-groups= ' '--set-advertisement-ranges='.format(self.router_name, self.region, self.peer_name)) self.Run('compute routers describe {0} --region {1}'.format( self.router_name, self.region)) self.AssertNewOutputNotContains('ALL_SUBNETS', reset=False, normalize_space=True) self.AssertNewOutputNotContains('10.0.10.0/30', reset=True, normalize_space=True) # Test clearing custom advertisements via switching to DEFAULT mode. self.Run( 'compute routers update-bgp-peer {0} --region {1} --peer-name {2} ' '--advertisement-mode CUSTOM ' '--set-advertisement-groups ALL_SUBNETS ' '--set-advertisement-ranges 10.0.10.0/30'.format( self.router_name, self.region, self.peer_name)) self.WriteInput('y\n') self.Run( 'compute routers update-bgp-peer {0} --region {1} --peer-name {2} ' '--advertisement-mode DEFAULT'.format(self.router_name, self.region, self.peer_name)) self.Run('compute routers describe {0} --region {1}'.format( self.router_name, self.region)) self.AssertNewOutputContains('advertiseMode: DEFAULT', reset=False, normalize_space=True) self.AssertNewOutputNotContains('ALL_SUBNETS', reset=False, normalize_space=True) self.AssertNewOutputNotContains('10.0.10.0/30', reset=False, normalize_space=True) cmd = 'compute routers delete {0} --region {1}'.format( self.router_name, self.region) Retry(lambda: self.Run(cmd)) cmd = 'compute networks delete {0}'.format(self.network_name) Retry(lambda: self.Run(cmd))
def testUpdateAdvertisements(self): self.Run('compute networks create {0} --subnet-mode custom'.format( self.network_name)) self.Run('compute routers create {0} --network {1} --region {2} ' '--asn 65000'.format(self.router_name, self.network_name, self.region)) self.Run('compute routers update {0} --region {1} ' '--advertisement-mode CUSTOM ' '--set-advertisement-groups ALL_SUBNETS ' '--set-advertisement-ranges 10.0.10.0/30'.format( self.router_name, self.region)) self.Run('compute routers describe {0} --region {1}'.format( self.router_name, self.region)) self.AssertNewOutputContainsAll( ['CUSTOM', 'ALL_SUBNETS', '10.0.10.0/30'], reset=True, normalize_space=True) # Test clearing custom advertisements via explicit Patch. self.Run('compute routers update {0} --region {1} ' '--set-advertisement-groups= ' '--set-advertisement-ranges='.format(self.router_name, self.region)) self.Run('compute routers describe {0} --region {1}'.format( self.router_name, self.region)) self.AssertNewOutputNotContains('ALL_SUBNETS', reset=False, normalize_space=True) self.AssertNewOutputNotContains('10.0.10.0/30', reset=True, normalize_space=True) # Test clearing custom advertisements via switching to DEFAULT mode. self.Run('compute routers update {0} --region {1} ' '--advertisement-mode CUSTOM ' '--set-advertisement-groups ALL_SUBNETS ' '--set-advertisement-ranges 10.0.10.0/30'.format( self.router_name, self.region)) self.WriteInput('y\n') self.Run('compute routers update {0} --region {1} ' '--advertisement-mode DEFAULT'.format(self.router_name, self.region)) self.Run('compute routers describe {0} --region {1}'.format( self.router_name, self.region)) self.AssertNewOutputContains('advertiseMode: DEFAULT', reset=False, normalize_space=True) self.AssertNewOutputNotContains('ALL_SUBNETS', reset=False, normalize_space=True) self.AssertNewOutputNotContains('10.0.10.0/30', reset=False, normalize_space=True) cmd = 'compute routers delete {0} --region {1}'.format( self.router_name, self.region) Retry(lambda: self.Run(cmd)) cmd = 'compute networks delete {0}'.format(self.network_name) Retry(lambda: self.Run(cmd))
def testSubnetworksFlowLogs(self): self.Run('compute networks create {0} --subnet-mode custom'.format( self.network_name)) self.AssertNewOutputContains(self.network_name) # First create a subnetwork with flow logs disabled. self.Run('compute networks subnets create {0} --network {1} ' '--region {2} --range 10.11.12.0/24'.format( self.subnetwork_name, self.network_name, self.region)) self.AssertNewOutputContains(self.subnetwork_name) self.Run('compute networks subnets describe {0} --region {1}'.format( self.subnetwork_name, self.region)) self.AssertNewOutputNotContains('logConfig') # Enable flow logs and set aggregation and sampling options. self.Run('compute networks subnets update {0} --region {1} ' '--enable-flow-logs ' '--logging-aggregation-interval interval-10-min ' '--logging-flow-sampling 0.7 ' '--logging-metadata exclude-all'.format( self.subnetwork_name, self.region)) self.ClearOutput() self.Run('compute networks subnets describe {0} --region {1}'.format( self.subnetwork_name, self.region)) self.AssertNewOutputContains('logConfig:', reset=False) self.AssertNewOutputContains(' enable: true', reset=False) self.AssertNewOutputContains(' aggregationInterval: INTERVAL_10_MIN', reset=False) self.AssertNewOutputContains(' flowSampling: 0.7', reset=False) self.AssertNewOutputContains(' metadata: EXCLUDE_ALL_METADATA', reset=False) # Disable flow logs. self.Run('compute networks subnets update {0} --region {1} ' '--no-enable-flow-logs'.format(self.subnetwork_name, self.region)) self.ClearOutput() self.Run('compute networks subnets describe {0} --region {1}'.format( self.subnetwork_name, self.region)) self.AssertNewOutputContains('logConfig:', reset=False) self.AssertNewOutputContains(' enable: false', reset=False) self.AssertNewOutputContains(' aggregationInterval: INTERVAL_10_MIN', reset=False) self.AssertNewOutputContains(' flowSampling: 0.7', reset=False) self.AssertNewOutputContains(' metadata: EXCLUDE_ALL_METADATA', reset=False) # Delete the subnet. self.Run('compute networks subnets delete {0} --region {1}'.format( self.subnetwork_name, self.region)) # Create the subnetwork again with flow logs enabled. self.Run('compute networks subnets create {0} --network {1} ' '--region {2} --range 10.11.12.0/24 ' '--enable-flow-logs'.format(self.subnetwork_name, self.network_name, self.region)) self.AssertNewOutputContains(self.subnetwork_name) self.Run('compute networks subnets describe {0} --region {1}'.format( self.subnetwork_name, self.region)) self.AssertNewOutputContains('logConfig:', reset=False) self.AssertNewOutputContains(' enable: true') # Delete the subnet. self.Run('compute networks subnets delete {0} --region {1}'.format( self.subnetwork_name, self.region)) cmd = 'compute networks delete {0}'.format(self.network_name) Retry(lambda: self.Run(cmd))