Ejemplo n.º 1
0
        public async Task Terminate(uint seconds = 5)
        {
            Debug.Log("TCRunner: terminating containers");
            while (terminating)
            {
                await Task.Delay(1000);
            }

            try
            {
                terminating = true;
                var stopParams = new Docker.DotNet.Models.ContainerStopParameters
                {
                    WaitBeforeKillSeconds = seconds,
                };
                foreach (var containerId in containers.Keys)
                {
                    var data = containers[containerId];
                    Debug.Log($"Terminating container {containerId.Substring(0, 12)} {data.imageName}");
                    await dockerClient.Containers.StopContainerAsync(containerId, stopParams);
                }
            }
            catch (Exception ex)
            {
                Debug.LogError("failed to stop some containers");
                Debug.LogException(ex);
            }
            finally
            {
                terminating = false;
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Performs the playback of actions in this module.
        /// </summary>
        /// <remarks>You should not call this method directly, instead pass the module
        /// instance to the <see cref="TestModuleRunner.Run(ITestModule)"/> method
        /// that will in turn invoke this method.</remarks>
        void ITestModule.Run()
        {
            ServicePointManager.ServerCertificateValidationCallback += (o, c, ch, er) => true;

            DockerClient client = null;

            if (certFile.Length > 0)
            {
                var credentials = new CertificateCredentials(new X509Certificate2(certFile));
                client = new DockerClientConfiguration(new Uri(dockerURL), credentials).CreateClient();
            }
            else
            {
                client = new DockerClientConfiguration(new Uri(dockerURL)).CreateClient();
            }

            var id = TestSuite.CurrentTestContainer.Parameters["containerID"];

            var stopParams = new Docker.DotNet.Models.ContainerStopParameters()
            {
                WaitBeforeKillSeconds = 10
            };
            CancellationToken token = new CancellationToken();
            var stopTask            = client.Containers.StopContainerAsync(id, stopParams, token);

            stopTask.Wait();

            var remParams  = new Docker.DotNet.Models.ContainerRemoveParameters();
            var deleteTask = client.Containers.RemoveContainerAsync(id, remParams);

            deleteTask.Wait(new TimeSpan(0, 0, 15));
        }