def testOperationsWaitExceptionMessage(self): self.StartPatch('googlecloudsdk.core.util.retry.Retryer.RetryOnResult', side_effect=retry.WaitException('forced timeout', False, None)) with self.assertRaisesRegex( exceptions.OperationError, 'Operation .* is taking longer than expected. You can continue waiting ' 'for the operation by running `gcloud beta sql operations wait .*`'): self.Run('sql operations wait 1cb8a924-898d-41ec-b695-39a6dc018d16')
def testWithPollingTimeout(self, test_instance_key): self.poller_poll.side_effect = retry.WaitException( 'msg', 'result', 'state') project_resource = self.messages.Project(name='my-project', ) test_instance = self.instances[test_instance_key] self.make_requests.side_effect = iter([ [test_instance], [project_resource], [], ]) with self.AssertRaisesExceptionMatches( ssh_utils.NetworkError, 'Could not SSH into the instance'): self.Run('compute scp hapoo@{}:~/remote-file ~/local-dir ' '--zone zone-1 --tunnel-through-iap'.format( test_instance.name)) self.CheckRequests( [(self.compute.instances, 'Get', self.messages.ComputeInstancesGetRequest( instance=test_instance.name, project='my-project', zone='zone-1'))], [(self.compute.projects, 'Get', self.messages.ComputeProjectsGetRequest(project='my-project'))], [(self.compute.projects, 'SetCommonInstanceMetadata', self.messages.ComputeProjectsSetCommonInstanceMetadataRequest( metadata=self.messages.Metadata(items=[ self.messages.Metadata.ItemsValueListEntry( key='ssh-keys', value='hapoo:' + self.public_key_material), ]), project='my-project'))], ) expected_tunnel_args = iap_tunnel.SshTunnelArgs() expected_tunnel_args.track = self.track.prefix expected_tunnel_args.project = 'my-project' expected_tunnel_args.zone = 'zone-1' expected_tunnel_args.instance = test_instance.name # Polling remote = ssh.Remote.FromArg('hapoo@compute.%s' % test_instance.id) self.poller_init.assert_called_once_with( mock_matchers.TypeMatcher(ssh.SSHPoller), remote=remote, identity_file=self.private_key_file, max_wait_ms=ssh_utils.SSH_KEY_PROPAGATION_TIMEOUT_MS, options=dict(self.options, HostKeyAlias='compute.%s' % test_instance.id), extra_flags=None, iap_tunnel_args=expected_tunnel_args) self.poller_poll.assert_called_once() self.scp_run.assert_not_called()
def testWithPollingTimeout(self): self.poller_poll.side_effect = retry.WaitException( 'msg', 'result', 'state') project_resource = self.messages.Project(name='my-project', ) self.make_requests.side_effect = iter([ [self.instance], [project_resource], [], ]) with self.AssertRaisesExceptionMatches( ssh_utils.NetworkError, 'Could not SSH into the instance'): self.Run("""\ compute scp hapoo@instance-1:~/remote-file ~/local-dir --zone zone-1 """) self.CheckRequests( [(self.compute.instances, 'Get', self.messages.ComputeInstancesGetRequest(instance='instance-1', project='my-project', zone='zone-1'))], [(self.compute.projects, 'Get', self.messages.ComputeProjectsGetRequest(project='my-project'))], [(self.compute.projects, 'SetCommonInstanceMetadata', self.messages.ComputeProjectsSetCommonInstanceMetadataRequest( metadata=self.messages.Metadata(items=[ self.messages.Metadata.ItemsValueListEntry( key='ssh-keys', value='hapoo:' + self.public_key_material), ]), project='my-project'))], ) remote = ssh.Remote(self.remote.host, user='******') # Polling self.poller_init.assert_called_once_with( mock_matchers.TypeMatcher(ssh.SSHPoller), remote=remote, identity_file=self.private_key_file, max_wait_ms=ssh_utils.SSH_KEY_PROPAGATION_TIMEOUT_MS, options=dict(self.options, HostKeyAlias='compute.11111'), extra_flags=None, iap_tunnel_args=None) self.poller_poll.assert_called_once() self.scp_run.assert_not_called()
def testSSHTimeout(self): args = SSHTest.Args('fake-name', 'central2-a', True) instance = self._makeFakeInstance('fake-instance') # Polling the instance leads to an unreachable instance. self.poller_poll.side_effect = retry.WaitException( 'msg', 'last', 'state') self.make_requests.side_effect = iter([ [self._makeFakeProjectResource()], [self._makeFakeProjectResource()], [self._makeFakeProjectResource()], ]) ssh_util = tpu_utils.SSH(self.track) with self.AssertRaisesExceptionRegexp( ssh_utils.NetworkError, 'Could not SSH into the instance. It is possible that ' 'your SSH key has not propagated to the instance yet. ' 'Try running this command again. If you still cannot connect, ' 'verify that the firewall and instance are set to accept ' 'ssh traffic.'): ssh_util.SSHToInstance(args, instance) self.AssertErrContains('Updating project ssh metadata')
def testWithPollingTimeout(self, test_instance_key): # Polling the instance leads to an unreachable instance. self.poller_poll.side_effect = retry.WaitException( 'msg', 'last', 'state') test_instance = self.instances[test_instance_key] self.make_requests.side_effect = iter([ [test_instance], [self.project_resource_without_metadata], [None], [None], ]) with self.AssertRaisesExceptionRegexp( ssh_utils.NetworkError, 'Could not SSH into the instance. It is possible that ' 'your SSH key has not propagated to the instance yet. ' 'Try running this command again. If you still cannot connect, ' 'verify that the firewall and instance are set to accept ' 'ssh traffic.'): self.Run('compute ssh hapoo@{} --zone zone-1 --tunnel-through-iap'. format(test_instance.name)) self.CheckRequests( [(self.compute.instances, 'Get', self.messages.ComputeInstancesGetRequest( instance=test_instance.name, project='my-project', zone='zone-1'))], [(self.compute.projects, 'Get', self.messages.ComputeProjectsGetRequest(project='my-project'))], [(self.compute.projects, 'SetCommonInstanceMetadata', self.messages.ComputeProjectsSetCommonInstanceMetadataRequest( metadata=self.messages.Metadata(items=[ self.messages.Metadata.ItemsValueListEntry( key='ssh-keys', value='hapoo:' + self.public_key_material), ]), project='my-project'))], ) # Require SSH keys self.ensure_keys.assert_called_once_with(self.keys, None, allow_passphrase=True) expected_tunnel_args = iap_tunnel.SshTunnelArgs() expected_tunnel_args.track = self.track.prefix expected_tunnel_args.project = 'my-project' expected_tunnel_args.zone = 'zone-1' expected_tunnel_args.instance = test_instance.name # Polling remote = ssh.Remote.FromArg('hapoo@compute.%s' % test_instance.id) self.poller_init.assert_called_once_with( mock_matchers.TypeMatcher(ssh.SSHPoller), remote=remote, identity_file=self.private_key_file, extra_flags=[], max_wait_ms=ssh_utils.SSH_KEY_PROPAGATION_TIMEOUT_MS, options=dict(self.options, HostKeyAlias='compute.%s' % test_instance.id), iap_tunnel_args=expected_tunnel_args) self.poller_poll.assert_called_once_with(mock_matchers.TypeMatcher( ssh.SSHPoller), self.env, force_connect=True) self.ssh_run.assert_not_called() self.AssertErrContains('Updating project ssh metadata')