Merge pull request #1660 from mnowster/754-add-option-memswap-limit

Add in memswap_limit run option
This commit is contained in:
Aanand Prasad 2015-07-07 10:09:49 +01:00
commit e9da790f76
4 changed files with 39 additions and 1 deletions

View File

@ -31,6 +31,7 @@ DOCKER_CONFIG_KEYS = [
'links',
'mac_address',
'mem_limit',
'memswap_limit',
'net',
'log_driver',
'pid',
@ -61,6 +62,7 @@ DOCKER_CONFIG_HINTS = {
'extra_host': 'extra_hosts',
'device': 'devices',
'link': 'links',
'memory_swap': 'memswap_limit',
'port': 'ports',
'privilege': 'privileged',
'priviliged': 'privileged',
@ -244,6 +246,9 @@ def process_container_options(service_dict, working_dir=None):
service_dict = service_dict.copy()
if 'memswap_limit' in service_dict and 'mem_limit' not in service_dict:
raise ConfigurationError("Invalid 'memswap_limit' configuration for %s service: when defining 'memswap_limit' you must set 'mem_limit' as well" % service_dict['name'])
if 'volumes' in service_dict:
service_dict['volumes'] = resolve_volume_paths(service_dict['volumes'], working_dir=working_dir)

View File

@ -312,7 +312,7 @@ Override the default labeling scheme for each container.
- label:user:USER
- label:role:ROLE
### working\_dir, entrypoint, user, hostname, domainname, mac\_address, mem\_limit, privileged, restart, stdin\_open, tty, cpu\_shares, cpuset, read\_only
### working\_dir, entrypoint, user, hostname, domainname, mac\_address, mem\_limit, memswap\_limit, privileged, restart, stdin\_open, tty, cpu\_shares, cpuset, read\_only
Each of these is a single value, analogous to its
[docker run](https://docs.docker.com/reference/run/) counterpart.
@ -330,6 +330,7 @@ Each of these is a single value, analogous to its
mac_address: 02:42:ac:11:65:43
mem_limit: 1000000000
memswap_limit: 2000000000
privileged: true
restart: always

View File

@ -260,6 +260,31 @@ class MergeLabelsTest(unittest.TestCase):
self.assertEqual(service_dict['labels'], {'foo': '1', 'bar': ''})
class MemoryOptionsTest(unittest.TestCase):
def test_validation_fails_with_just_memswap_limit(self):
"""
When you set a 'memswap_limit' it is invalid config unless you also set
a mem_limit
"""
with self.assertRaises(config.ConfigurationError):
make_service_dict(
'foo', {
'memswap_limit': 2000000,
},
'tests/'
)
def test_validation_with_correct_memswap_values(self):
service_dict = make_service_dict(
'foo', {
'mem_limit': 1000000,
'memswap_limit': 2000000,
},
'tests/'
)
self.assertEqual(service_dict['memswap_limit'], 2000000)
class EnvTest(unittest.TestCase):
def test_parse_environment_as_list(self):
environment = [

View File

@ -155,6 +155,13 @@ class ServiceTest(unittest.TestCase):
self.assertEqual(opts['hostname'], 'name', 'hostname')
self.assertFalse('domainname' in opts, 'domainname')
def test_memory_swap_limit(self):
service = Service(name='foo', image='foo', hostname='name', client=self.mock_client, mem_limit=1000000000, memswap_limit=2000000000)
self.mock_client.containers.return_value = []
opts = service._get_container_create_options({'some': 'overrides'}, 1)
self.assertEqual(opts['memswap_limit'], 2000000000)
self.assertEqual(opts['mem_limit'], 1000000000)
def test_split_domainname_fqdn(self):
service = Service(
'foo',