def testWithNoBackends(self): """ A backend service has no backend Expectation: the backend service itself will be migrated """ ### create test resources backend_service_name = 'end-to-end-test-backend-service' operation = self.test_resource_creator.create_regional_backend_service( 'sample_internal_backend_service.json', backend_service_name, []) original_backend_service_configs = self.google_api_interface.get_regional_backend_service_configs( backend_service_name) backend_service_selfLink = operation['targetLink'] ### start migration selfLink_executor = SelfLinkExecutor( self.compute, backend_service_selfLink, self.test_resource_creator.network_name, self.test_resource_creator.subnetwork_name, ) migration_handler = selfLink_executor.build_migration_handler() migration_handler.network_migration() ### check migration result new_backend_service_configs = self.google_api_interface.get_regional_backend_service_configs( backend_service_name) # check backend service config self.assertTrue( check_selfLink_equal(new_backend_service_configs['network'], self.test_resource_creator.network_selfLink)) self.assertTrue( resource_config_is_unchanged_except_for_network( original_backend_service_configs, new_backend_service_configs)) print('Pass the current test')
def testWithNoBackend(self): """ A backend service has no backend Expectation: the backend service itself will be migrated """ ### create test resources backend_service_name = 'end-to-end-test-backend-service' backend_service_selfLink = \ self.test_resource_creator.create_global_backend_service( 'sample_internal_self_managed_backend_service.json', backend_service_name, [])['targetLink'] original_backend_service_configs = self.google_api_interface.get_global_backend_service_configs( backend_service_name) ### start migration selfLink_executor = SelfLinkExecutor( self.compute, backend_service_selfLink, self.test_resource_creator.network_name, self.test_resource_creator.subnetwork_name, ) migration_handler = selfLink_executor.build_migration_handler() migration_handler.network_migration() ### check migration result # check backend service config # an internal backend service doesn't have a network config new_backend_service_configs = self.google_api_interface.get_global_backend_service_configs( backend_service_name) self.assertTrue( resource_config_is_unchanged_except_for_network( original_backend_service_configs, new_backend_service_configs))
def testWithoutAutoscalerAttached(self): ### create test resources group_name = 'end-to-end-test-managed-instance-group-1' operation = self.test_resource_creator.create_regional_managed_instance_group( self.test_resource_creator.legacy_instance_template_selfLink, group_name, 'sample_multi_zone_managed_instance_group.json') instance_group_selfLink = operation['targetLink'] original_instance_template_configs = self.google_api_interface.get_multi_zone_instance_template_configs( group_name) ### start migration selfLink_executor = SelfLinkExecutor( self.compute, instance_group_selfLink, self.test_resource_creator.network_name, self.test_resource_creator.subnetwork_name, ) migration_handler = selfLink_executor.build_migration_handler() migration_handler.network_migration() ### check migration result new_instance_template_configs = self.google_api_interface.get_multi_zone_instance_template_configs( group_name) self.assertTrue( instance_template_config_is_unchanged_except_for_network_and_name( original_instance_template_configs, new_instance_template_configs)) # network changed self.assertTrue( check_instance_template_network( new_instance_template_configs, self.test_resource_creator.network_selfLink, self.test_resource_creator.subnetwork_selfLink)) print('Pass the current test')
def testWithNoInstanceInTheGroup(self): ### create test resources unmanaged_instance_group_name = 'end-to-end-test-unmanaged-instance-group-1' self.test_resource_creator.create_unmanaged_instance_group( unmanaged_instance_group_name, []) original_config = self.google_api_interface.get_unmanaged_instance_group_configs( unmanaged_instance_group_name) ### start migration selfLink_executor = SelfLinkExecutor( self.compute, original_config['selfLink'], self.test_resource_creator.network_name, self.test_resource_creator.subnetwork_name, False) migration_handler = selfLink_executor.build_migration_handler() migration_handler.network_migration() ### check migration result new_config = self.google_api_interface.get_unmanaged_instance_group_configs( unmanaged_instance_group_name) self.assertTrue( resource_config_is_unchanged_except_for_network( original_config, new_config)) # network changed self.assertTrue( check_selfLink_equal(new_config['network'], self.test_resource_creator.network_selfLink)) print('Pass the current test')
def testWithInstancesFromAnUnmanagedInstanceGroup(self): """ The target pool is served by an instance which is a member of an unmanaged instance group Expectation: the migration will not start. """ ### create resources instance_name_1 = 'end-to-end-test-instance-1' operation = self.test_resource_creator.create_instance_using_template( instance_name_1, self.test_resource_creator.legacy_instance_template_selfLink) instance_selfLink_1 = operation['targetLink'] instance_name_2 = 'end-to-end-test-instance-2' operation = self.test_resource_creator.create_instance_using_template( instance_name_2, self.test_resource_creator.legacy_instance_template_selfLink) instance_selfLink_2 = operation['targetLink'] unmanaged_instance_group_name = 'end-to-end-test-unmanaged-instance-group-1' original_instances_in_group = [instance_name_1, instance_name_2] self.test_resource_creator.create_unmanaged_instance_group( unmanaged_instance_group_name, original_instances_in_group) original_group_config = self.google_api_interface.get_unmanaged_instance_group_configs( unmanaged_instance_group_name) target_pool_name = 'end-to-end-test-target-pool' operation = self.test_resource_creator.create_target_pool_with_health_check( 'sample_target_pool_with_no_instance.json', target_pool_name, [], [instance_selfLink_1, instance_selfLink_2], health_check_selfLink=None) target_pool_selfLink = operation['targetLink'] original_target_pool_config = self.google_api_interface.get_target_pool_config( target_pool_name) ### start migration selfLink_executor = SelfLinkExecutor( self.compute, target_pool_selfLink, self.test_resource_creator.network_name, self.test_resource_creator.subnetwork_name, ) # the migration will not start, and raise an error with self.assertRaises(AmbiguousTargetResource): migration_handler = selfLink_executor.build_migration_handler() migration_handler.network_migration() ### check migration result # unmanaged instance group doesn't change new_group_config = self.google_api_interface.get_unmanaged_instance_group_configs( unmanaged_instance_group_name) self.assertEqual(original_group_config, new_group_config) # target pool is unchanged new_target_pool_config = self.google_api_interface.get_target_pool_config( target_pool_name) self.assertEqual(original_target_pool_config, new_target_pool_config) print('Pass the current test')
def testAttachingAnInternalForwardingRule(self): """ A targetInstance is in use by the forwarding rule Expectation: both the targetInstance and the forwarding rule will be migrated """ ### create test resources forwarding_rule_name = 'end-to-end-test-forwarding-rule' target_instance_name = 'end-to-end-test-instance' operation = self.test_resource_creator.create_instance_using_template( target_instance_name, self.test_resource_creator.legacy_instance_template_selfLink) instance_selfLink = operation['targetLink'] target_instance_selfLink = \ self.test_resource_creator.create_a_target_instance( target_instance_name, instance_selfLink)['targetLink'] original_instance_config = self.google_api_interface.get_instance_configs( target_instance_name) forwarding_rule_selfLink = \ self.test_resource_creator.create_regional_forwarding_rule_with_target( 'sample_tcp_regional_forwarding_rule_internal.json', forwarding_rule_name, target_instance_selfLink)['targetLink'] original_forwarding_rule_config = self.google_api_interface.get_regional_forwarding_rule_config( forwarding_rule_name) ### start migration selfLink_executor = SelfLinkExecutor( self.compute, target_instance_selfLink, self.test_resource_creator.network_name, self.test_resource_creator.subnetwork_name, ) migration_handler = selfLink_executor.build_migration_handler() migration_handler.network_migration() ### check migration result new_forwarding_rule_config = self.google_api_interface.get_regional_forwarding_rule_config( forwarding_rule_name) self.assertTrue( resource_config_is_unchanged_including_network( original_forwarding_rule_config, new_forwarding_rule_config)) # check instance network new_instance_config = self.google_api_interface.get_instance_configs( target_instance_name) self.assertTrue( resource_config_is_unchanged_except_for_network( new_instance_config, original_instance_config)) # network changed self.assertTrue( check_instance_network( new_instance_config, self.test_resource_creator.network_selfLink, self.test_resource_creator.subnetwork_selfLink)) print('Pass the current test')
def testOnlyInstancesAsBackend(self): """ The target pool has single instances as its backends, no instance groups """ ### create test resources instance_name_1 = 'end-to-end-test-instance-1' operation = self.test_resource_creator.create_instance_using_template( instance_name_1, self.test_resource_creator.legacy_instance_template_selfLink) instance_selfLink_1 = operation['targetLink'] instance_name_2 = 'end-to-end-test-instance-2' operation = self.test_resource_creator.create_instance_using_template( instance_name_2, self.test_resource_creator.legacy_instance_template_selfLink) instance_selfLink_2 = operation['targetLink'] target_pool_name = 'end-to-end-test-target-pool' operation = self.test_resource_creator.create_target_pool_with_health_check( 'sample_target_pool_with_no_instance.json', target_pool_name, [], [instance_selfLink_1, instance_selfLink_2], health_check_selfLink=None) target_pool_selfLink = operation['targetLink'] original_target_pool_instance_list = \ self.google_api_interface.get_target_pool_config(target_pool_name)[ 'instances'] ### start migration selfLink_executor = SelfLinkExecutor( self.compute, target_pool_selfLink, self.test_resource_creator.network_name, self.test_resource_creator.subnetwork_name, ) migration_handler = selfLink_executor.build_migration_handler() migration_handler.network_migration() ### check migration result new_target_pool_instance_list = \ self.google_api_interface.get_target_pool_config(target_pool_name)[ 'instances'] # target pool's instances unchanged self.assertTrue( compare_two_list(new_target_pool_instance_list, original_target_pool_instance_list)) # instances' network changed new_instance_1_config = self.google_api_interface.get_instance_configs( instance_name_1) self.assertTrue( check_instance_network( new_instance_1_config, self.test_resource_creator.network_selfLink, self.test_resource_creator.subnetwork_selfLink)) new_instance_2_config = self.google_api_interface.get_instance_configs( instance_name_2) self.assertTrue( check_instance_network( new_instance_2_config, self.test_resource_creator.network_selfLink, self.test_resource_creator.subnetwork_selfLink)) print('Pass the current test')
def testAsBackendOfTargetPool(self): """ The unmanaged instance group serves a target pool, which means the instances in this instance group serve the target pool. Expectation: The migration can still succeed. But the instances might be detached from the target pool after the migration. """ ### create test resources instance_name_1 = 'end-to-end-test-instance-1' operation = self.test_resource_creator.create_instance_using_template( instance_name_1, self.test_resource_creator.legacy_instance_template_selfLink) instance_selfLink_1 = operation['targetLink'] original_instance_config = self.google_api_interface.get_instance_configs( instance_name_1) unmanaged_instance_group_name = 'end-to-end-test-unmanaged-instance-group-1' original_instances_in_group = [instance_name_1] unmanaged_instance_group_selfLink = \ self.test_resource_creator.create_unmanaged_instance_group( unmanaged_instance_group_name, original_instances_in_group)['targetLink'] original_instance_group_config = self.google_api_interface.get_unmanaged_instance_group_configs( unmanaged_instance_group_name) target_pool_name = 'end-to-end-test-target-pool' self.test_resource_creator.create_target_pool_with_health_check( 'sample_target_pool_with_no_instance.json', target_pool_name, [], [instance_selfLink_1], health_check_selfLink=None) ### start migration selfLink_executor = SelfLinkExecutor( self.compute, unmanaged_instance_group_selfLink, self.test_resource_creator.network_name, self.test_resource_creator.subnetwork_name, ) migration_handler = selfLink_executor.build_migration_handler() migration_handler.network_migration() ### check migration result # the migration is successful new_instance_config = self.google_api_interface.get_instance_configs( instance_name_1) new_instance_group_config = self.google_api_interface.get_unmanaged_instance_group_configs( unmanaged_instance_group_name) self.assertTrue( resource_config_is_unchanged_except_for_network( original_instance_config, new_instance_config)) self.assertTrue( resource_config_is_unchanged_except_for_network( original_instance_group_config, new_instance_group_config)) # network changed self.assertTrue( check_instance_network( new_instance_config, self.test_resource_creator.network_selfLink, self.test_resource_creator.subnetwork_selfLink)) print('Pass the current test')
def testWithBackends(self): """ A backend service has backends Expectation: all the backends will be migrated """ ### create test resources backend_service_name = 'end-to-end-test-backend-service' group_name_1 = 'end-to-end-test-managed-instance-group-1' operation = self.test_resource_creator.create_regional_managed_instance_group( self.test_resource_creator.legacy_instance_template_selfLink, group_name_1, 'sample_multi_zone_managed_instance_group.json', ) instance_group_1_selfLink = operation['targetLink'].replace( '/instanceGroupManagers/', '/instanceGroups/') original_instance_template_1_configs = self.google_api_interface.get_multi_zone_instance_template_configs( group_name_1) original_backend_selfLinks = [instance_group_1_selfLink] backend_service_selfLink = \ self.test_resource_creator.create_global_backend_service( 'sample_internal_self_managed_backend_service.json', backend_service_name, original_backend_selfLinks)['targetLink'] original_backend_service_configs = self.google_api_interface.get_global_backend_service_configs( backend_service_name) ### start migration selfLink_executor = SelfLinkExecutor( self.compute, backend_service_selfLink, self.test_resource_creator.network_name, self.test_resource_creator.subnetwork_name, ) migration_handler = selfLink_executor.build_migration_handler() migration_handler.network_migration() ### check migration result # check backend service config new_backend_service_configs = self.google_api_interface.get_global_backend_service_configs( backend_service_name) self.assertTrue( resource_config_is_unchanged_except_for_network( original_backend_service_configs, new_backend_service_configs)) # check its backends new_instance_template_1_configs = self.google_api_interface.get_multi_zone_instance_template_configs( group_name_1) self.assertTrue( instance_template_config_is_unchanged_except_for_network_and_name( original_instance_template_1_configs, new_instance_template_1_configs)) # network changed self.assertTrue( check_instance_template_network( new_instance_template_1_configs, self.test_resource_creator.network_selfLink, self.test_resource_creator.subnetwork_selfLink))
def network_migration(self): """ Network migration for an internal forwarding rule. The forwarding rule will be deleted first. Then, the tool will migrate the backend service. Finally, recreate the forwarding rule in the target subnet. Returns: """ if self.forwarding_rule.compare_original_network_and_target_network(): print('The backend service %s is already using target subnet.' % (self.forwarding_rule_name)) return backends_selfLinks = self.forwarding_rule.backends_selfLinks for backends_selfLink in backends_selfLinks: selfLink_executor = SelfLinkExecutor( self.compute, backends_selfLink, self.network_name, self.subnetwork_name, self.preserve_instance_external_ip) # the backends can be a target instance or an internal backend service try: backends_migration_handler = selfLink_executor.build_migration_handler( ) except UnsupportedBackendService: warnings.warn( 'The load balancing scheme of (%s) is not supported. ' 'Continue migrating other backends.' % (backends_selfLink)) continue if backends_migration_handler != None: self.backends_migration_handlers.append( backends_migration_handler) if isinstance(backends_migration_handler, BackendServiceMigration): backend_service = backends_migration_handler.backend_service if backend_service != None and backend_service.count_forwarding_rules( ) > 1: print( 'The backend service is associated with two or more forwarding rules, \n' 'so it can not be migrated. \n' 'Terminating. ') return self.migration_status = MigrationStatus(1) print('Deleting: %s.' % (self.forwarding_rule_name)) self.forwarding_rule.delete_forwarding_rule() self.migration_status = MigrationStatus(2) print('Migrating the backends of %s.' % (self.forwarding_rule_name)) for backends_migration_handler in self.backends_migration_handlers: backends_migration_handler.network_migration() self.migration_status = MigrationStatus(3) print('Recreating the forwarding rule (%s) in the target subnet.' % (self.forwarding_rule_name)) self.forwarding_rule.insert_forwarding_rule( self.forwarding_rule.new_forwarding_rule_configs) self.migration_status = MigrationStatus(4)
def testSharingBackendWithAnotherBackendService(self): """ The internal backend service A shares the same backend with another backend service B Expectation: rollback """ ### create test resources backend_service_1_name = 'end-to-end-test-backend-service-1' backend_service_2_name = 'end-to-end-test-backend-service-2' group_name_1 = 'end-to-end-test-managed-instance-group-1' operation = self.test_resource_creator.create_regional_managed_instance_group( self.test_resource_creator.legacy_instance_template_selfLink, group_name_1, 'sample_multi_zone_managed_instance_group.json', ) instance_group_1_selfLink = operation['targetLink'].replace( '/instanceGroupManagers/', '/instanceGroups/') original_instance_group_config = self.google_api_interface.get_multi_zone_managed_instance_group_configs( group_name_1) backend_service_1_selfLink = \ self.test_resource_creator.create_regional_backend_service( 'sample_internal_backend_service.json', backend_service_1_name, [instance_group_1_selfLink])[ 'targetLink'] original_backend_service_1_configs = self.google_api_interface.get_regional_backend_service_configs( backend_service_1_name) self.test_resource_creator.create_regional_backend_service( 'sample_internal_backend_service.json', backend_service_2_name, [instance_group_1_selfLink]) ### start migration selfLink_executor = SelfLinkExecutor( self.compute, backend_service_1_selfLink, self.test_resource_creator.network_name, self.test_resource_creator.subnetwork_name, ) with self.assertRaises(MigrationFailed): migration_handler = selfLink_executor.build_migration_handler() migration_handler.network_migration() ### check migration result new_backend_service_1_configs = self.google_api_interface.get_regional_backend_service_configs( backend_service_1_name) # check backend service config self.assertTrue( resource_config_is_unchanged_including_network( original_backend_service_1_configs, new_backend_service_1_configs)) # check its backends new_instance_group_config = self.google_api_interface.get_multi_zone_managed_instance_group_configs( group_name_1) self.assertTrue( instance_template_config_is_unchanged( original_instance_group_config, new_instance_group_config)) print('Pass the current test')
def testAsBackendOfBackendService(self): """ The instance group is serving a backend service Expectation: The migration will fail and rollback to the legacy network. """ ### create test resources instance_name_1 = 'end-to-end-test-instance-1' operation = self.test_resource_creator.create_instance_using_template( instance_name_1, self.test_resource_creator.legacy_instance_template_selfLink) original_instance_config = self.google_api_interface.get_instance_configs( instance_name_1) unmanaged_instance_group_name = 'end-to-end-test-unmanaged-instance-group-1' original_instances_in_group = [instance_name_1] unmanaged_instance_group_selfLink = \ self.test_resource_creator.create_unmanaged_instance_group( unmanaged_instance_group_name, original_instances_in_group)['targetLink'] original_instance_group_config = self.google_api_interface.get_unmanaged_instance_group_configs( unmanaged_instance_group_name) backend_service_name = 'end-to-end-test-backend-service' original_backend_selfLinks = [unmanaged_instance_group_selfLink] self.test_resource_creator.create_regional_backend_service( 'sample_internal_backend_service.json', backend_service_name, original_backend_selfLinks) ### start migration selfLink_executor = SelfLinkExecutor( self.compute, unmanaged_instance_group_selfLink, self.test_resource_creator.network_name, self.test_resource_creator.subnetwork_name, ) with self.assertRaises(MigrationFailed): migration_handler = selfLink_executor.build_migration_handler() migration_handler.network_migration() ### check migration result # the migration is failed and the resources are rolled back new_instance_config = self.google_api_interface.get_instance_configs( instance_name_1) new_instance_group_config = self.google_api_interface.get_unmanaged_instance_group_configs( unmanaged_instance_group_name) self.assertTrue( resource_config_is_unchanged_including_network( original_instance_config, new_instance_config)) self.assertTrue( resource_config_is_unchanged_including_network( original_instance_group_config, new_instance_group_config)) print('Pass the current test')
def network_migration(self): """ Network migration for a external forwarding rule. The tool will migrate its backend services one by one. The forwarding rule itself will not be deleted or recreated. """ if self.forwarding_rule.compare_original_network_and_target_network(): print('The backend service %s is already using target subnet.' % ( self.forwarding_rule_name)) return backends_selfLinks = self.forwarding_rule.backends_selfLinks if backends_selfLinks == []: print( 'No backend service needs to be migrated. Terminating the migration.') return for backends_selfLink in backends_selfLinks: selfLink_executor = SelfLinkExecutor(self.compute, backends_selfLink, self.network_name, self.subnetwork_name, self.preserve_instance_external_ip) try: backends_migration_handler = selfLink_executor.build_migration_handler() except UnsupportedBackendService: warnings.warn( 'The load balancing scheme of (%s) is not supported. ' 'Continue migrating other backends.' % (backends_selfLink)) continue # Save handlers for rollback purpose if backends_migration_handler != None: if isinstance(backends_migration_handler, BackendServiceMigration): backend_service = backends_migration_handler.backend_service if backend_service != None and backend_service.count_forwarding_rules() > 1: print( 'The backend service is associated with two or more forwarding rules, \n' 'so it can not be migrated. \n' 'Terminating. ') # this backend service will be ignored and will continue migrate other backend services continue self.backends_migration_handlers.append( backends_migration_handler) backends_migration_handler.network_migration()
def network_migration(self): """ Migrate the network of an unmanaged instance group. The instances belonging to this instance group will be migrated one by one. """ self.migration_status = 0 if self.instance_group.compare_original_network_and_target_network(): print('The instance group %s is already using the target subnet.' % (self.instance_group_name)) return self.migration_status = 1 for instance_selfLink in self.instance_group.instance_selfLinks: selfLink_executor = SelfLinkExecutor(self.compute, instance_selfLink, self.network_name, self.subnetwork_name, self.preserve_external_ip) instance_migration_handler = selfLink_executor.build_migration_handler( ) if instance_migration_handler != None: self.instance_migration_handlers.append( instance_migration_handler) # print('Detaching the instance %s.' %(instance_selfLink)) # self.instance_group.remove_an_instance(instance_selfLink) instance_migration_handler.network_migration(force=True) self.migration_status = 2 print('Deleting: %s.' % (self.instance_group_name)) self.instance_group.delete_instance_group() self.migration_status = 3 print( 'Recreating the instance group using the same configuration in the new network.' ) self.instance_group.create_instance_group( self.instance_group.new_instance_group_configs) self.migration_status = 4 print('Adding the instances back to the instance group: %s.' % (self.instance_group_name)) self.instance_group.add_all_instances() self.migration_status = 5
def migrate_backends(self): """ Migrate the backends of the backend service one by one Args: backend_service_configs: the configs of the backend service """ if 'backends' not in self.backend_service.backend_service_configs: return None backends = self.backend_service.backend_service_configs['backends'] for backend in backends: selfLink_executor = SelfLinkExecutor( self.compute, backend['group'], self.network, self.subnetwork, self.preserve_instance_external_ip) backend_migration_handler = selfLink_executor.build_migration_handler( ) if backend_migration_handler != None: backend_migration_handler.network_migration() self.backend_migration_handlers.append( backend_migration_handler)
def testAsBackendOfBackendService(self): """ The managed instance group serves a backend service. Expectation: The migration will fail and rollback. """ ### create test resources group_name = 'end-to-end-test-managed-instance-group-1' instance_group_selfLink = \ self.test_resource_creator.create_regional_managed_instance_group( self.test_resource_creator.legacy_instance_template_selfLink, group_name, 'sample_multi_zone_managed_instance_group.json')[ 'targetLink'].replace('/instanceGroupManagers/', '/instanceGroups/') original_instance_group_config = self.google_api_interface.get_multi_zone_managed_instance_group_configs( group_name) backend_service_name = 'end-to-end-test-backend-service' self.test_resource_creator.create_regional_backend_service( 'sample_internal_backend_service.json', backend_service_name, [instance_group_selfLink]) ### start migration selfLink_executor = SelfLinkExecutor( self.compute, instance_group_selfLink, self.test_resource_creator.network_name, self.test_resource_creator.subnetwork_name, ) with self.assertRaises(MigrationFailed): migration_handler = selfLink_executor.build_migration_handler() migration_handler.network_migration() ### check migration result # the migration is failed and the resources are rolled back new_instance_group_config = self.google_api_interface.get_multi_zone_managed_instance_group_configs( group_name) self.assertTrue( resource_config_is_unchanged_including_network( original_instance_group_config, new_instance_group_config)) print('Pass the current test')
def testAsBackendOfTargetPool(self): """ The managed instance group serves a target pool. Expectation: The migration will not start. """ ### create test resources group_name = 'end-to-end-test-managed-instance-group-1' instance_group_selfLink = \ self.test_resource_creator.create_regional_managed_instance_group( self.test_resource_creator.legacy_instance_template_selfLink, group_name, 'sample_multi_zone_managed_instance_group.json')[ 'targetLink'] original_instance_template_configs = self.google_api_interface.get_multi_zone_instance_template_configs( group_name) target_pool_name = 'end-to-end-test-target-pool' self.test_resource_creator.create_target_pool_with_health_check( 'sample_target_pool_with_no_instance.json', target_pool_name, [group_name], [], health_check_selfLink=None) ### start migration selfLink_executor = SelfLinkExecutor( self.compute, instance_group_selfLink, self.test_resource_creator.network_name, self.test_resource_creator.subnetwork_name, ) with self.assertRaises(MigrationFailed): migration_handler = selfLink_executor.build_migration_handler() migration_handler.network_migration() ### check migration result # the migration didn't start new_instance_template_configs = self.google_api_interface.get_multi_zone_instance_template_configs( group_name) self.assertTrue( resource_config_is_unchanged_including_network( new_instance_template_configs, new_instance_template_configs)) print('Pass the current test')
def testWithForwardingRuleAttached(self): """ A forwaring rule is using the external backend service. Try to migrate the external backend service directly. Expectation: still can migrate """ ### create test resources backend_service_name = 'end-to-end-test-backend-service' original_backend_selfLinks = [] operation = self.test_resource_creator.create_regional_backend_service( 'sample_internal_backend_service.json', backend_service_name, original_backend_selfLinks) original_backend_service_configs = self.google_api_interface.get_regional_backend_service_configs( backend_service_name) backend_service_selfLink = operation['targetLink'] self.test_resource_creator.create_regional_forwarding_rule_with_backend_service( 'sample_tcp_regional_forwarding_rule_internal.json', backend_service_name, backend_service_selfLink) ### start migration selfLink_executor = SelfLinkExecutor( self.compute, backend_service_selfLink, self.test_resource_creator.network_name, self.test_resource_creator.subnetwork_name, ) with self.assertRaises(MigrationFailed): migration_handler = selfLink_executor.build_migration_handler() migration_handler.network_migration() ### check migration result # migration didn't start new_backend_service_configs = self.google_api_interface.get_regional_backend_service_configs( backend_service_name) self.assertTrue( resource_config_is_unchanged_including_network( original_backend_service_configs, new_backend_service_configs)) print('Pass the current test')
def testWithNoBackendsAttached(self): backend_service_name = 'end-to-end-test-backend-service' operation = self.test_resource_creator.create_global_backend_service( 'sample_external_backend_service.json', backend_service_name, []) original_backend_service_configs = self.google_api_interface.get_global_backend_service_configs( backend_service_name) backend_service_selfLink = operation['targetLink'] # start migration selfLink_executor = SelfLinkExecutor( self.compute, backend_service_selfLink, self.test_resource_creator.network_name, self.test_resource_creator.subnetwork_name, ) migration_handler = selfLink_executor.build_migration_handler() migration_handler.network_migration() ### check migration result new_backend_service_configs = self.google_api_interface.get_global_backend_service_configs( backend_service_name) self.assertTrue( resource_config_is_unchanged_except_for_network( original_backend_service_configs, new_backend_service_configs)) print('Pass the current test')
def testWithBackendServiceAttached(self): """ A backend service is in use by this forwarding rule Expectation: both the forwarding rule and the backend service will be migrated. """ ### create test resources forwarding_rule_name = 'end-to-end-test-forwarding-rule' backend_service_name = 'end-to-end-test-backend-service' group_name_1 = 'end-to-end-test-managed-instance-group-1' operation = self.test_resource_creator.create_regional_managed_instance_group( self.test_resource_creator.legacy_instance_template_selfLink, group_name_1, 'sample_multi_zone_managed_instance_group.json', ) instance_group_1_selfLink = operation['targetLink'].replace( '/instanceGroupManagers/', '/instanceGroups/') original_instance_template_1_configs = self.google_api_interface.get_multi_zone_instance_template_configs( group_name_1) backend_service_selfLink = \ self.test_resource_creator.create_regional_backend_service( 'sample_internal_backend_service.json', backend_service_name, [instance_group_1_selfLink])['targetLink'] original_backend_service_configs = self.google_api_interface.get_regional_backend_service_configs( backend_service_name) forwarding_rule_selfLink = \ self.test_resource_creator.create_regional_forwarding_rule_with_backend_service( 'sample_tcp_regional_forwarding_rule_internal.json', forwarding_rule_name, backend_service_selfLink)['targetLink'] original_forwarding_rule_config = self.google_api_interface.get_regional_forwarding_rule_config( forwarding_rule_name) ### start migration selfLink_executor = SelfLinkExecutor(self.compute, forwarding_rule_selfLink, self.test_resource_creator.network_name, self.test_resource_creator.subnetwork_name, ) migration_handler = selfLink_executor.build_migration_handler() migration_handler.network_migration() ### check migration result # check internal forwarding rule new_forwarding_rule_config = self.google_api_interface.get_regional_forwarding_rule_config( forwarding_rule_name) self.assertTrue(resource_config_is_unchanged_except_for_network( original_forwarding_rule_config, new_forwarding_rule_config)) self.assertTrue( check_selfLink_equal(new_forwarding_rule_config['network'], self.test_resource_creator.network_selfLink)) # check backend service config new_backend_service_configs = self.google_api_interface.get_regional_backend_service_configs( backend_service_name) self.assertTrue(resource_config_is_unchanged_except_for_network( original_backend_service_configs, new_backend_service_configs)) self.assertEqual(new_backend_service_configs['network'], self.test_resource_creator.network_selfLink) # check its backends new_instance_template_1_configs = self.google_api_interface.get_multi_zone_instance_template_configs \ ( group_name_1) self.assertTrue( instance_template_config_is_unchanged_except_for_network_and_name( original_instance_template_1_configs, new_instance_template_1_configs) ) self.assertTrue( check_instance_template_network(new_instance_template_1_configs, self.test_resource_creator.network_selfLink, self.test_resource_creator.subnetwork_selfLink)) print('Pass the current test')
def testAutomodeSubnetworkExistsInBothRegions(self): """ A backend service has two instance groups from two regions as backends. The network is an auto-mode network, and it has subnet with the same name in all regions. Expectation: all the backends will be migrated """ ### create test resources auto_subnetwork_name = 'end-to-end-test-auto-subnetwork' try: target_network_selfLink = \ self.google_api_interface_region_1.get_network( auto_subnetwork_name)['selfLink'] except: target_network_selfLink = \ self.google_api_interface_region_1.create_auto_subnetwork( auto_subnetwork_name)[ 'targetLink'] group_name_1 = 'end-to-end-test-managed-instance-group-1' operation = self.test_resource_creator_region_1.create_regional_managed_instance_group( self.test_resource_creator_region_1. legacy_instance_template_selfLink, group_name_1, 'sample_multi_zone_managed_instance_group.json', ) instance_group_1_selfLink = operation['targetLink'].replace( '/instanceGroupManagers/', '/instanceGroups/') original_instance_template_1_configs = self.google_api_interface_region_1.get_multi_zone_instance_template_configs( group_name_1) group_name_2 = 'end-to-end-test-managed-instance-group-2' operation = self.test_resource_creator_region_2.create_regional_managed_instance_group( self.test_resource_creator_region_2. legacy_instance_template_selfLink, group_name_2, 'sample_multi_zone_managed_instance_group.json', ) instance_group_2_selfLink = operation['targetLink'].replace( '/instanceGroupManagers/', '/instanceGroups/') original_instance_template_2_configs = self.google_api_interface_region_2.get_multi_zone_instance_template_configs( group_name_2) backend_service_name = 'end-to-end-test-backend-service' operation = self.test_resource_creator_region_1.create_global_backend_service( 'sample_external_backend_service.json', backend_service_name, [instance_group_2_selfLink, instance_group_1_selfLink]) original_backend_service_configs = self.google_api_interface_region_1.get_global_backend_service_configs( backend_service_name) backend_service_selfLink = operation['targetLink'] ### start migration selfLink_executor = SelfLinkExecutor(self.compute, backend_service_selfLink, auto_subnetwork_name, auto_subnetwork_name) migration_handler = selfLink_executor.build_migration_handler() migration_handler.network_migration() ### check migration result new_backend_service_configs = self.google_api_interface_region_1.get_global_backend_service_configs( backend_service_name) # check backend service config self.assertTrue( resource_config_is_unchanged_including_network( original_backend_service_configs, new_backend_service_configs)) # check its backends new_instance_template_1_configs = self.google_api_interface_region_1.get_multi_zone_instance_template_configs( group_name_1) new_instance_template_2_configs = self.google_api_interface_region_2.get_multi_zone_instance_template_configs( group_name_2) self.assertTrue( instance_template_config_is_unchanged_except_for_network_and_name( original_instance_template_1_configs, new_instance_template_1_configs)) self.assertTrue( instance_template_config_is_unchanged_except_for_network_and_name( original_instance_template_2_configs, new_instance_template_2_configs)) # network changed self.assertTrue( check_instance_template_network(new_instance_template_1_configs, target_network_selfLink)) self.assertTrue( check_instance_template_network(new_instance_template_2_configs, target_network_selfLink)) print('Pass the current test')
def testCustomSubnetworkExistsInOnlyOneRegion(self): """ A backend service has two instance groups from two regions as backends. Expectation: rollback will happen """ ### create test resources target_subnetwork_name = 'subnetwork-only-in-region-1' target_subnetwork_selfLink = \ self.google_api_interface_region_1.create_subnetwork_using_random_ip_range( target_subnetwork_name, self.test_resource_creator_region_1.network_selfLink )['targetLink'] group_name_1 = 'end-to-end-test-managed-instance-group-1' operation = self.test_resource_creator_region_1.create_regional_managed_instance_group( self.test_resource_creator_region_1. legacy_instance_template_selfLink, group_name_1, 'sample_multi_zone_managed_instance_group.json', ) instance_group_1_selfLink = operation['targetLink'].replace( '/instanceGroupManagers/', '/instanceGroups/') original_instance_template_1_configs = self.google_api_interface_region_1.get_multi_zone_instance_template_configs( group_name_1) group_name_2 = 'end-to-end-test-managed-instance-group-2' operation = self.test_resource_creator_region_2.create_regional_managed_instance_group( self.test_resource_creator_region_2. legacy_instance_template_selfLink, group_name_2, 'sample_multi_zone_managed_instance_group.json', ) instance_group_2_selfLink = operation['targetLink'].replace( '/instanceGroupManagers/', '/instanceGroups/') original_instance_template_2_configs = self.google_api_interface_region_2.get_multi_zone_instance_template_configs( group_name_2) backend_service_name = 'end-to-end-test-backend-service' operation = self.test_resource_creator_region_1.create_global_backend_service( 'sample_external_backend_service.json', backend_service_name, [instance_group_2_selfLink, instance_group_1_selfLink]) original_backend_service_configs = self.google_api_interface_region_1.get_global_backend_service_configs( backend_service_name) backend_service_selfLink = operation['targetLink'] ### start migration selfLink_executor = SelfLinkExecutor( self.compute, backend_service_selfLink, self.test_resource_creator_region_1.network_name, target_subnetwork_name) with self.assertRaises(MigrationFailed): migration_handler = selfLink_executor.build_migration_handler() migration_handler.network_migration() ### check migration result new_backend_service_configs = self.google_api_interface_region_1.get_global_backend_service_configs( backend_service_name) # check backend service config self.assertTrue( resource_config_is_unchanged_including_network( original_backend_service_configs, new_backend_service_configs)) # check its backends new_instance_template_1_configs = self.google_api_interface_region_1.get_multi_zone_instance_template_configs( group_name_1) new_instance_template_2_configs = self.google_api_interface_region_2.get_multi_zone_instance_template_configs( group_name_2) # configs are unchanged including network self.assertTrue( instance_template_config_is_unchanged( original_instance_template_1_configs, new_instance_template_1_configs)) self.assertTrue( instance_template_config_is_unchanged( original_instance_template_2_configs, new_instance_template_2_configs)) print('Pass the current test')
'--preserve_instance_external_ip', default=False, help= 'Preserve the external IP addresses of the instances serving this forwarding rule' ) args = parser.parse_args() if args.preserve_instance_external_ip == 'True': args.preserve_instance_external_ip = True else: args.preserve_instance_external_ip = False if args.preserve_instance_external_ip: warnings.warn( 'You choose to preserve the external IP. If the original instance ' 'has an ephemeral IP, it will be reserved as a static external IP after the ' 'execution.', Warning) continue_execution = input( 'Do you still want to preserve the external IP? y/n: ') if continue_execution == 'n': args.preserve_instance_external_ip = False selfLink_executor = SelfLinkExecutor(compute, args.selfLink, args.network, args.subnetwork, args.preserve_instance_external_ip) migration_handler = selfLink_executor.build_migration_handler() if migration_handler == None: raise InvalidSelfLink('Unable to parse the selfLink.') migration_handler.network_migration()
def testWithTargetHttpProxy(self): ### create test resources forwarding_rule_name = 'end-to-end-test-forwarding-rule' group_name_1 = 'end-to-end-test-managed-instance-group-1' operation = self.test_resource_creator.create_regional_managed_instance_group( self.test_resource_creator.legacy_instance_template_selfLink, group_name_1, 'sample_multi_zone_managed_instance_group.json', ) instance_group_1_selfLink = operation['targetLink'].replace( '/instanceGroupManagers/', '/instanceGroups/') original_instance_template_1_configs = self.google_api_interface.get_multi_zone_instance_template_configs( group_name_1) backend_service_name = 'end-to-end-test-backend-service' original_backend_selfLinks = [instance_group_1_selfLink] operation = self.test_resource_creator.create_global_backend_service( 'sample_http_backend_service.json', backend_service_name, original_backend_selfLinks) original_backend_service_configs = self.google_api_interface.get_global_backend_service_configs( backend_service_name) backend_service_selfLink = operation['targetLink'] urlmap_selfLink = \ self.test_resource_creator.create_urlmapping(backend_service_name, backend_service_selfLink)[ 'targetLink'] proxy_selfLink = self.test_resource_creator.create_http_target_proxy( backend_service_name, urlmap_selfLink)['targetLink'] forwarding_rule_selfLink = \ self.test_resource_creator.create_global_forwarding_rule_with_target( 'sample_global_forwarding_rule.json', forwarding_rule_name, proxy_selfLink)['targetLink'] original_forwarding_rule_config = self.google_api_interface.get_global_forwarding_rule_config( forwarding_rule_name) ### start migration selfLink_executor = SelfLinkExecutor( self.compute, forwarding_rule_selfLink, self.test_resource_creator.network_name, self.test_resource_creator.subnetwork_name, ) migration_handler = selfLink_executor.build_migration_handler() migration_handler.network_migration() ### check migration result # check forwarding rule config new_forwarding_rule_config = self.google_api_interface.get_global_forwarding_rule_config( forwarding_rule_name) self.assertTrue( resource_config_is_unchanged_except_for_network( original_forwarding_rule_config, new_forwarding_rule_config)) # check backend service config new_backend_service_configs = self.google_api_interface.get_global_backend_service_configs( backend_service_name) self.assertTrue( resource_config_is_unchanged_except_for_network( original_backend_service_configs, new_backend_service_configs)) # check its backends new_instance_template_1_configs = self.google_api_interface.get_multi_zone_instance_template_configs( group_name_1) self.assertTrue( instance_template_config_is_unchanged_except_for_network_and_name( original_instance_template_1_configs, new_instance_template_1_configs)) # network changed self.assertTrue( check_instance_template_network( new_instance_template_1_configs, self.test_resource_creator.network_selfLink, self.test_resource_creator.subnetwork_selfLink)) print('Pass the current test')
def testWithTargetHttpProxyRelatedToMultipleBackendServices(self): """ The urlMapping is related to two backend service. All the backend services will be migrated. """ ### create test resrouces forwarding_rule_name = 'end-to-end-test-forwarding-rule' group_name_1 = 'end-to-end-test-managed-instance-group-1' operation = self.test_resource_creator.create_regional_managed_instance_group( self.test_resource_creator.legacy_instance_template_selfLink, group_name_1, 'sample_multi_zone_managed_instance_group.json', ) instance_group_1_selfLink = operation['targetLink'].replace( '/instanceGroupManagers/', '/instanceGroups/') original_instance_template_1_configs = self.google_api_interface.get_multi_zone_instance_template_configs( group_name_1) group_name_2 = 'end-to-end-test-managed-instance-group-2' operation = self.test_resource_creator.create_regional_managed_instance_group( self.test_resource_creator.legacy_instance_template_selfLink, group_name_2, 'sample_multi_zone_managed_instance_group.json', ) instance_group_2_selfLink = operation['targetLink'].replace( '/instanceGroupManagers/', '/instanceGroups/') original_instance_template_2_configs = self.google_api_interface.get_multi_zone_instance_template_configs( group_name_2) backend_service_name_1 = 'end-to-end-test-backend-service-1' original_backend_selfLinks_1 = [instance_group_1_selfLink] backend_service_selfLink_1 = \ self.test_resource_creator.create_global_backend_service( 'sample_http_backend_service.json', backend_service_name_1, original_backend_selfLinks_1)[ 'targetLink'] backend_service_name_2 = 'end-to-end-test-backend-service-2' original_backend_selfLinks_2 = [instance_group_2_selfLink] backend_service_selfLink_2 = \ self.test_resource_creator.create_global_backend_service( 'sample_http_backend_service.json', backend_service_name_2, original_backend_selfLinks_2)[ 'targetLink'] backend_service_selfLinks = [ backend_service_selfLink_1, backend_service_selfLink_2 ] urlmap_name = 'end-to-ent-test-urlmapping' urlmap_selfLink = \ self.test_resource_creator.create_urlmapping_using_two_backend_service( urlmap_name, backend_service_selfLinks)[ 'targetLink'] proxy_selfLink = self.test_resource_creator.create_http_target_proxy( urlmap_name, urlmap_selfLink)['targetLink'] forwarding_rule_selfLink = \ self.test_resource_creator.create_global_forwarding_rule_with_target( 'sample_global_forwarding_rule.json', forwarding_rule_name, proxy_selfLink)['targetLink'] original_backend_service_configs_1 = self.google_api_interface.get_global_backend_service_configs( backend_service_name_1) original_backend_service_configs_2 = self.google_api_interface.get_global_backend_service_configs( backend_service_name_2) ### start migration selfLink_executor = SelfLinkExecutor( self.compute, forwarding_rule_selfLink, self.test_resource_creator.network_name, self.test_resource_creator.subnetwork_name, ) migration_handler = selfLink_executor.build_migration_handler() migration_handler.network_migration() ### check migration result new_backend_service_configs_1 = self.google_api_interface.get_global_backend_service_configs( backend_service_name_1) new_backend_service_configs_2 = self.google_api_interface.get_global_backend_service_configs( backend_service_name_2) self.assertTrue( resource_config_is_unchanged_except_for_network( original_backend_service_configs_1, new_backend_service_configs_1)) self.assertTrue( resource_config_is_unchanged_except_for_network( original_backend_service_configs_2, new_backend_service_configs_2)) # check its backends new_instance_template_1_configs = self.google_api_interface.get_multi_zone_instance_template_configs( group_name_1) new_instance_template_2_configs = self.google_api_interface.get_multi_zone_instance_template_configs( group_name_2) self.assertTrue( instance_template_config_is_unchanged_except_for_network_and_name( original_instance_template_1_configs, new_instance_template_1_configs)) self.assertTrue( instance_template_config_is_unchanged_except_for_network_and_name( original_instance_template_2_configs, new_instance_template_2_configs)) # network changed self.assertTrue( check_instance_template_network( new_instance_template_1_configs, self.test_resource_creator.network_selfLink, self.test_resource_creator.subnetwork_selfLink)) self.assertTrue( check_instance_template_network( new_instance_template_2_configs, self.test_resource_creator.network_selfLink, self.test_resource_creator.subnetwork_selfLink)) print('Pass the current test')
def testAForwardingRuleAttached(self): """ A forwaring rule is using the external backend service. Try to migrate the external backend service directly. Expectation: still can migrate """ group_name_1 = 'end-to-end-test-managed-instance-group-1' operation = self.test_resource_creator.create_regional_managed_instance_group( self.test_resource_creator.legacy_instance_template_selfLink, group_name_1, 'sample_multi_zone_managed_instance_group.json', ) instance_group_1_selfLink = operation['targetLink'].replace( '/instanceGroupManagers/', '/instanceGroups/') original_instance_template_1_configs = self.google_api_interface.get_multi_zone_instance_template_configs( group_name_1) group_name_2 = 'end-to-end-test-managed-instance-group-2' operation = self.test_resource_creator.create_regional_managed_instance_group( self.test_resource_creator.legacy_instance_template_selfLink, group_name_2, 'sample_multi_zone_managed_instance_group.json', ) instance_group_2_selfLink = operation['targetLink'].replace( '/instanceGroupManagers/', '/instanceGroups/') original_instance_template_2_configs = self.google_api_interface.get_multi_zone_instance_template_configs( group_name_2) backend_service_name = 'end-to-end-test-backend-service' original_backend_selfLinks = [ instance_group_2_selfLink, instance_group_1_selfLink ] operation = self.test_resource_creator.create_global_backend_service( 'sample_http_backend_service.json', backend_service_name, original_backend_selfLinks) backend_service_selfLink = operation['targetLink'] urlmap_selfLink = \ self.test_resource_creator.create_urlmapping(backend_service_name, backend_service_selfLink)[ 'targetLink'] proxy_selfLink = self.test_resource_creator.create_http_target_proxy( backend_service_name, urlmap_selfLink)['targetLink'] self.test_resource_creator.create_global_forwarding_rule_with_target( 'sample_global_forwarding_rule.json', backend_service_name, proxy_selfLink) # start migration selfLink_executor = SelfLinkExecutor( self.compute, backend_service_selfLink, self.test_resource_creator.network_name, self.test_resource_creator.subnetwork_name, ) migration_handler = selfLink_executor.build_migration_handler() migration_handler.network_migration() ### check migration result new_backend_service_configs = self.google_api_interface.get_global_backend_service_configs( backend_service_name) new_backend_selfLinks = self.google_api_interface.get_backends_links_from_backend_service_configs( new_backend_service_configs) # check backend service config self.assertTrue( compare_two_list(original_backend_selfLinks, new_backend_selfLinks)) # check its backends new_instance_template_1_configs = self.google_api_interface.get_multi_zone_instance_template_configs( group_name_1) new_instance_template_2_configs = self.google_api_interface.get_multi_zone_instance_template_configs( group_name_2) self.assertTrue( instance_template_config_is_unchanged_except_for_network_and_name( original_instance_template_1_configs, new_instance_template_1_configs)) self.assertTrue( instance_template_config_is_unchanged_except_for_network_and_name( original_instance_template_2_configs, new_instance_template_2_configs)) # network changed self.assertTrue( check_instance_template_network( new_instance_template_1_configs, self.test_resource_creator.network_selfLink, self.test_resource_creator.subnetwork_selfLink)) self.assertTrue( check_instance_template_network( new_instance_template_2_configs, self.test_resource_creator.network_selfLink, self.test_resource_creator.subnetwork_selfLink)) print('Pass the current test')
def testSharingBackendWithATargetPool(self): """ backend_service_1 share the same backend with a target pool. Try to migrate backend_service_1. Expectation: rollback will happen """ group_name_1 = 'end-to-end-test-managed-instance-group-1' operation = self.test_resource_creator.create_regional_managed_instance_group( self.test_resource_creator.legacy_instance_template_selfLink, group_name_1, 'sample_multi_zone_managed_instance_group.json', ) instance_group_1_selfLink = operation['targetLink'].replace( '/instanceGroupManagers/', '/instanceGroups/') original_instance_template_1_configs = self.google_api_interface.get_multi_zone_instance_template_configs( group_name_1) original_instance_group_config = self.google_api_interface.get_multi_zone_managed_instance_group_configs( group_name_1) backend_service_1_name = 'end-to-end-test-backend-service-1' backend_service_1_selfLink = \ self.test_resource_creator.create_global_backend_service( 'sample_external_backend_service.json', backend_service_1_name, [instance_group_1_selfLink])[ 'targetLink'] original_backend_service_1_configs = self.google_api_interface.get_global_backend_service_configs( backend_service_1_name) target_pool_name = 'end-to-end-test-target-pool' target_pool_selfLink = \ self.test_resource_creator.create_target_pool_with_health_check( 'sample_target_pool_with_no_instance.json', target_pool_name, [group_name_1], [], health_check_selfLink=None)['targetLink'] # start migration selfLink_executor = SelfLinkExecutor( self.compute, backend_service_1_selfLink, self.test_resource_creator.network_name, self.test_resource_creator.subnetwork_name, ) with self.assertRaises(MigrationFailed): migration_handler = selfLink_executor.build_migration_handler() migration_handler.network_migration() ### check migration result new_backend_service_1_configs = self.google_api_interface.get_global_backend_service_configs( backend_service_1_name) # check backend service config self.assertTrue( resource_config_is_unchanged_including_network( original_backend_service_1_configs, new_backend_service_1_configs)) # check its backends new_instance_template_1_configs = self.google_api_interface.get_multi_zone_instance_template_configs( group_name_1) self.assertTrue( instance_template_config_is_unchanged( original_instance_template_1_configs, new_instance_template_1_configs)) new_instance_group_config = self.google_api_interface.get_multi_zone_managed_instance_group_configs( group_name_1) self.assertTrue( managed_instance_group_config_is_unchanged_except_for_instance_template( original_instance_group_config, new_instance_group_config)) print('Pass the current test')
def testInstancesAndManagedInstanceGroupsMixedBackends(self): """ The target pool served by both instances and managed instance groups """ ### create test resources group_name_1 = 'end-to-end-test-managed-instance-group-1' self.test_resource_creator.create_regional_managed_instance_group( self.test_resource_creator.legacy_instance_template_selfLink, group_name_1, 'sample_multi_zone_managed_instance_group.json', ) original_instance_template_1_configs = self.google_api_interface.get_multi_zone_instance_template_configs( group_name_1) instance_name_1 = 'end-to-end-test-instance-1' operation = self.test_resource_creator.create_instance_using_template( instance_name_1, self.test_resource_creator.legacy_instance_template_selfLink) instance_1_selfLink = operation['targetLink'] original_instance_1_config = self.google_api_interface.get_instance_configs( instance_name_1) target_pool_name = 'end-to-end-test-target-pool' operation = self.test_resource_creator.create_target_pool_with_health_check( 'sample_target_pool_with_no_instance.json', target_pool_name, [group_name_1], [instance_1_selfLink], health_check_selfLink=None) target_pool_selfLink = operation['targetLink'] # time allowance to let the instance groups create instances time.sleep(10) ### start migration selfLink_executor = SelfLinkExecutor( self.compute, target_pool_selfLink, self.test_resource_creator.network_name, self.test_resource_creator.subnetwork_name, ) migration_handler = selfLink_executor.build_migration_handler() migration_handler.network_migration() ### check migration result new_instance_template_1_configs = self.google_api_interface.get_multi_zone_instance_template_configs( group_name_1) self.assertTrue( instance_template_config_is_unchanged_except_for_network_and_name( original_instance_template_1_configs, new_instance_template_1_configs)) new_instance_1_config = self.google_api_interface.get_instance_configs( instance_name_1) self.assertTrue( resource_config_is_unchanged_except_for_network( original_instance_1_config, new_instance_1_config)) # network changed self.assertTrue( check_instance_template_network( new_instance_template_1_configs, self.test_resource_creator.network_selfLink, self.test_resource_creator.subnetwork_selfLink)) self.assertTrue( check_instance_network( new_instance_1_config, self.test_resource_creator.network_selfLink, self.test_resource_creator.subnetwork_selfLink)) print('Pass the current test')
def testEmptyManagedInstanceGroupAsBackend(self): """ The target pool is served by an empty managed instance groups (no instances in the group) Expectation: the instance group which has no instance will not be migrated to the target subnet. The instance group which has instances will be migrated to the target subnet. """ ### create resources group_name_1 = 'end-to-end-test-managed-instance-group-1' self.test_resource_creator.create_regional_managed_instance_group( self.test_resource_creator.legacy_instance_template_selfLink, group_name_1, 'sample_multi_zone_managed_instance_group_with_zero_instance.json', ) original_instance_template_1_configs = self.google_api_interface.get_multi_zone_instance_template_configs( group_name_1) group_name_2 = 'end-to-end-test-managed-instance-group-2' self.test_resource_creator.create_regional_managed_instance_group( self.test_resource_creator.legacy_instance_template_selfLink, group_name_2, 'sample_multi_zone_managed_instance_group.json', ) original_instance_template_2_configs = self.google_api_interface.get_multi_zone_instance_template_configs( group_name_2) target_pool_name = 'end-to-end-test-target-pool' operation = self.test_resource_creator.create_target_pool_with_health_check( 'sample_target_pool_with_no_instance.json', target_pool_name, [group_name_2, group_name_1], [], health_check_selfLink=None) target_pool_selfLink = operation['targetLink'] # time allowance to let the instance groups create instances time.sleep(20) ### start migration selfLink_executor = SelfLinkExecutor( self.compute, target_pool_selfLink, self.test_resource_creator.network_name, self.test_resource_creator.subnetwork_name, ) migration_handler = selfLink_executor.build_migration_handler() migration_handler.network_migration() ### check migration result new_instance_template_1_configs = self.google_api_interface.get_multi_zone_instance_template_configs( group_name_1) new_instance_template_2_configs = self.google_api_interface.get_multi_zone_instance_template_configs( group_name_2) # group 1 didn't migrate self.assertTrue( instance_template_config_is_unchanged( original_instance_template_1_configs, new_instance_template_1_configs)) self.assertTrue( instance_template_config_is_unchanged_except_for_network_and_name( original_instance_template_2_configs, new_instance_template_2_configs)) # group 2 network changed self.assertTrue( check_instance_template_network( new_instance_template_2_configs, self.test_resource_creator.network_selfLink, self.test_resource_creator.subnetwork_selfLink)) print('Pass the current test')
def testWithMultipleBackends(self): """ A backend service has multiple backends Expectation: all the backends will be migrated """ ### create test resources backend_service_name = 'end-to-end-test-backend-service' group_name_1 = 'end-to-end-test-managed-instance-group-1' operation = self.test_resource_creator.create_regional_managed_instance_group( self.test_resource_creator.legacy_instance_template_selfLink, group_name_1, 'sample_multi_zone_managed_instance_group.json', ) instance_group_1_selfLink = operation['targetLink'].replace( '/instanceGroupManagers/', '/instanceGroups/') original_instance_template_1_configs = self.google_api_interface.get_multi_zone_instance_template_configs( group_name_1) group_name_2 = 'end-to-end-test-managed-instance-group-2' operation = self.test_resource_creator.create_regional_managed_instance_group( self.test_resource_creator.legacy_instance_template_selfLink, group_name_2, 'sample_multi_zone_managed_instance_group.json', ) instance_group_2_selfLink = operation['targetLink'].replace( '/instanceGroupManagers/', '/instanceGroups/') original_instance_template_2_configs = self.google_api_interface.get_multi_zone_instance_template_configs( group_name_2) original_backend_selfLinks = [ instance_group_2_selfLink, instance_group_1_selfLink ] operation = self.test_resource_creator.create_regional_backend_service( 'sample_internal_backend_service.json', backend_service_name, original_backend_selfLinks) backend_service_selfLink = operation['targetLink'] ### start migration selfLink_executor = SelfLinkExecutor( self.compute, backend_service_selfLink, self.test_resource_creator.network_name, self.test_resource_creator.subnetwork_name, ) migration_handler = selfLink_executor.build_migration_handler() migration_handler.network_migration() ### check migration result new_backend_service_configs = self.google_api_interface.get_regional_backend_service_configs( backend_service_name) new_backend_selfLinks = self.google_api_interface.get_backends_links_from_backend_service_configs( new_backend_service_configs) # check backend service config self.assertTrue( check_selfLink_equal(new_backend_service_configs['network'], self.test_resource_creator.network_selfLink)) self.assertTrue( compare_two_list(original_backend_selfLinks, new_backend_selfLinks)) # check its backends new_instance_template_1_configs = self.google_api_interface.get_multi_zone_instance_template_configs( group_name_1) new_instance_template_2_configs = self.google_api_interface.get_multi_zone_instance_template_configs( group_name_2) self.assertTrue( instance_template_config_is_unchanged_except_for_network_and_name( original_instance_template_1_configs, new_instance_template_1_configs)) self.assertTrue( instance_template_config_is_unchanged_except_for_network_and_name( original_instance_template_2_configs, new_instance_template_2_configs)) # network changed self.assertTrue( check_instance_template_network( new_instance_template_1_configs, self.test_resource_creator.network_selfLink, self.test_resource_creator.subnetwork_selfLink)) self.assertTrue( check_instance_template_network( new_instance_template_2_configs, self.test_resource_creator.network_selfLink, self.test_resource_creator.subnetwork_selfLink)) print('Pass the current test')