mirror of https://github.com/docker/docker-py.git
				
				
				
			Add support for `uts_mode` parameter in `Client.create_host_config`.
This parameter allows to set the UTS namespace of the container, as in the `--uts=X` Docker CLI parameter: <https://docs.docker.com/engine/reference/run/#uts-settings---uts> The only allowed value, if set, is "host". Signed-off-by: Marco Trillo <martri@arantia.com> Signed-off-by: Diego Alvarez <dyako.developer@gmail.com>
This commit is contained in:
		
							parent
							
								
									101214e5de
								
							
						
					
					
						commit
						098318ad95
					
				|  | @ -547,6 +547,8 @@ class ContainerApiMixin(object): | ||||||
|             userns_mode (str): Sets the user namespace mode for the container |             userns_mode (str): Sets the user namespace mode for the container | ||||||
|                 when user namespace remapping option is enabled. Supported |                 when user namespace remapping option is enabled. Supported | ||||||
|                 values are: ``host`` |                 values are: ``host`` | ||||||
|  |             uts_mode (str): Sets the UTS namespace mode for the container. | ||||||
|  |                 Supported values are: ``host`` | ||||||
|             volumes_from (:py:class:`list`): List of container names or IDs to |             volumes_from (:py:class:`list`): List of container names or IDs to | ||||||
|                 get volumes from. |                 get volumes from. | ||||||
|             runtime (str): Runtime to use with this container. |             runtime (str): Runtime to use with this container. | ||||||
|  |  | ||||||
|  | @ -995,6 +995,7 @@ RUN_HOST_CONFIG_KWARGS = [ | ||||||
|     'tmpfs', |     'tmpfs', | ||||||
|     'ulimits', |     'ulimits', | ||||||
|     'userns_mode', |     'userns_mode', | ||||||
|  |     'uts_mode', | ||||||
|     'version', |     'version', | ||||||
|     'volumes_from', |     'volumes_from', | ||||||
|     'runtime' |     'runtime' | ||||||
|  |  | ||||||
|  | @ -115,11 +115,11 @@ class HostConfig(dict): | ||||||
|                  device_read_iops=None, device_write_iops=None, |                  device_read_iops=None, device_write_iops=None, | ||||||
|                  oom_kill_disable=False, shm_size=None, sysctls=None, |                  oom_kill_disable=False, shm_size=None, sysctls=None, | ||||||
|                  tmpfs=None, oom_score_adj=None, dns_opt=None, cpu_shares=None, |                  tmpfs=None, oom_score_adj=None, dns_opt=None, cpu_shares=None, | ||||||
|                  cpuset_cpus=None, userns_mode=None, pids_limit=None, |                  cpuset_cpus=None, userns_mode=None, uts_mode=None, | ||||||
|                  isolation=None, auto_remove=False, storage_opt=None, |                  pids_limit=None, isolation=None, auto_remove=False, | ||||||
|                  init=None, init_path=None, volume_driver=None, |                  storage_opt=None, init=None, init_path=None, | ||||||
|                  cpu_count=None, cpu_percent=None, nano_cpus=None, |                  volume_driver=None, cpu_count=None, cpu_percent=None, | ||||||
|                  cpuset_mems=None, runtime=None, mounts=None, |                  nano_cpus=None, cpuset_mems=None, runtime=None, mounts=None, | ||||||
|                  cpu_rt_period=None, cpu_rt_runtime=None, |                  cpu_rt_period=None, cpu_rt_runtime=None, | ||||||
|                  device_cgroup_rules=None): |                  device_cgroup_rules=None): | ||||||
| 
 | 
 | ||||||
|  | @ -392,6 +392,11 @@ class HostConfig(dict): | ||||||
|                 raise host_config_value_error("userns_mode", userns_mode) |                 raise host_config_value_error("userns_mode", userns_mode) | ||||||
|             self['UsernsMode'] = userns_mode |             self['UsernsMode'] = userns_mode | ||||||
| 
 | 
 | ||||||
|  |         if uts_mode: | ||||||
|  |             if uts_mode != "host": | ||||||
|  |                 raise host_config_value_error("uts_mode", uts_mode) | ||||||
|  |             self['UTSMode'] = uts_mode | ||||||
|  | 
 | ||||||
|         if pids_limit: |         if pids_limit: | ||||||
|             if not isinstance(pids_limit, int): |             if not isinstance(pids_limit, int): | ||||||
|                 raise host_config_type_error('pids_limit', pids_limit, 'int') |                 raise host_config_type_error('pids_limit', pids_limit, 'int') | ||||||
|  |  | ||||||
|  | @ -490,6 +490,16 @@ class CreateContainerTest(BaseAPIIntegrationTest): | ||||||
|         self.client.start(ctnr) |         self.client.start(ctnr) | ||||||
|         assert rule in self.client.logs(ctnr).decode('utf-8') |         assert rule in self.client.logs(ctnr).decode('utf-8') | ||||||
| 
 | 
 | ||||||
|  |     def test_create_with_uts_mode(self): | ||||||
|  |         container = self.client.create_container( | ||||||
|  |             BUSYBOX, ['echo'], host_config=self.client.create_host_config( | ||||||
|  |                 uts_mode='host' | ||||||
|  |             ) | ||||||
|  |         ) | ||||||
|  |         self.tmp_containers.append(container) | ||||||
|  |         config = self.client.inspect_container(container) | ||||||
|  |         assert config['HostConfig']['UTSMode'] == 'host' | ||||||
|  | 
 | ||||||
| 
 | 
 | ||||||
| @pytest.mark.xfail( | @pytest.mark.xfail( | ||||||
|     IS_WINDOWS_PLATFORM, reason='Test not designed for Windows platform' |     IS_WINDOWS_PLATFORM, reason='Test not designed for Windows platform' | ||||||
|  |  | ||||||
|  | @ -85,6 +85,12 @@ class HostConfigTest(unittest.TestCase): | ||||||
|         with pytest.raises(ValueError): |         with pytest.raises(ValueError): | ||||||
|             create_host_config(version='1.23', userns_mode='host12') |             create_host_config(version='1.23', userns_mode='host12') | ||||||
| 
 | 
 | ||||||
|  |     def test_create_host_config_with_uts(self): | ||||||
|  |         config = create_host_config(version='1.15', uts_mode='host') | ||||||
|  |         assert config.get('UTSMode') == 'host' | ||||||
|  |         with pytest.raises(ValueError): | ||||||
|  |             create_host_config(version='1.15', uts_mode='host12') | ||||||
|  | 
 | ||||||
|     def test_create_host_config_with_oom_score_adj(self): |     def test_create_host_config_with_oom_score_adj(self): | ||||||
|         config = create_host_config(version='1.22', oom_score_adj=100) |         config = create_host_config(version='1.22', oom_score_adj=100) | ||||||
|         assert config.get('OomScoreAdj') == 100 |         assert config.get('OomScoreAdj') == 100 | ||||||
|  |  | ||||||
|  | @ -95,6 +95,7 @@ class ContainerCollectionTest(unittest.TestCase): | ||||||
|             ulimits=[{"Name": "nofile", "Soft": 1024, "Hard": 2048}], |             ulimits=[{"Name": "nofile", "Soft": 1024, "Hard": 2048}], | ||||||
|             user='bob', |             user='bob', | ||||||
|             userns_mode='host', |             userns_mode='host', | ||||||
|  |             uts_mode='host', | ||||||
|             version='1.23', |             version='1.23', | ||||||
|             volume_driver='some_driver', |             volume_driver='some_driver', | ||||||
|             volumes=[ |             volumes=[ | ||||||
|  | @ -174,6 +175,7 @@ class ContainerCollectionTest(unittest.TestCase): | ||||||
|                 'Tmpfs': {'/blah': ''}, |                 'Tmpfs': {'/blah': ''}, | ||||||
|                 'Ulimits': [{"Name": "nofile", "Soft": 1024, "Hard": 2048}], |                 'Ulimits': [{"Name": "nofile", "Soft": 1024, "Hard": 2048}], | ||||||
|                 'UsernsMode': 'host', |                 'UsernsMode': 'host', | ||||||
|  |                 'UTSMode': 'host', | ||||||
|                 'VolumesFrom': ['container'], |                 'VolumesFrom': ['container'], | ||||||
|             }, |             }, | ||||||
|             healthcheck={'test': 'true'}, |             healthcheck={'test': 'true'}, | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue