Merge branch '21535-multi-wf-delete'
[arvados.git] / services / dockercleaner / tests / test_cleaner.py
index 9fbd3e3014ecd0038d789d64ce3660d872268f6c..cd03538fcd07f2181b44abef3ed91fb0bb64e8f1 100644 (file)
@@ -1,15 +1,19 @@
 #!/usr/bin/env python3
+# Copyright (C) The Arvados Authors. All rights reserved.
+#
+# SPDX-License-Identifier: AGPL-3.0
 
 import collections
 import itertools
 import json
+import os
 import random
 import tempfile
 import time
 import unittest
 
 import docker
-import mock
+from unittest import mock
 
 from arvados_docker import cleaner
 
@@ -390,7 +394,7 @@ class RunTestCase(unittest.TestCase):
         self.assertEqual(event_kwargs[0]['until'], event_kwargs[1]['since'])
 
 
-@mock.patch('docker.Client', name='docker_client')
+@mock.patch('docker.APIClient', name='docker_client')
 @mock.patch('arvados_docker.cleaner.run', name='cleaner_run')
 class MainTestCase(unittest.TestCase):
 
@@ -400,11 +404,9 @@ class MainTestCase(unittest.TestCase):
             cf.flush()
             cleaner.main(['--config', cf.name])
         self.assertEqual(1, docker_client.call_count)
-        # 1.14 is the first version that's well defined, going back to
-        # Docker 1.2, and still supported up to at least Docker 1.9.
-        # See
-        # <https://docs.docker.com/engine/reference/api/docker_remote_api/>.
-        self.assertEqual('1.14',
+        # We are standardized on Docker API version 1.35.
+        # See DockerAPIVersion in lib/crunchrun/docker.go.
+        self.assertEqual('1.35',
                          docker_client.call_args[1].get('version'))
         self.assertEqual(1, run_mock.call_count)
         self.assertIs(run_mock.call_args[0][1], docker_client())
@@ -437,6 +439,11 @@ class ConfigTestCase(unittest.TestCase):
         self.assertEqual('never', config['RemoveStoppedContainers'])
         self.assertEqual(1, config['Verbose'])
 
+    def test_args_no_config(self):
+        self.assertEqual(False, os.path.exists(cleaner.DEFAULT_CONFIG_FILE))
+        config = cleaner.load_config(['--quota', '1G'])
+        self.assertEqual(1 << 30, config['Quota'])
+
 
 class ContainerRemovalTestCase(unittest.TestCase):
     LIFECYCLE = ['create', 'attach', 'start', 'resize', 'die', 'destroy']