Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add in memswap_limit run option #1660

Merged
merged 1 commit into from
Jul 7, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions compose/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
'links',
'mac_address',
'mem_limit',
'memswap_limit',
'net',
'log_driver',
'pid',
Expand Down Expand Up @@ -61,6 +62,7 @@
'extra_host': 'extra_hosts',
'device': 'devices',
'link': 'links',
'memory_swap': 'memswap_limit',
'port': 'ports',
'privilege': 'privileged',
'priviliged': 'privileged',
Expand Down Expand Up @@ -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)

Expand Down
3 changes: 2 additions & 1 deletion docs/yml.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand Down
25 changes: 25 additions & 0 deletions tests/unit/config_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,31 @@ def test_remove_explicit_value(self):
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 = [
Expand Down
7 changes: 7 additions & 0 deletions tests/unit/service_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,13 @@ def test_split_domainname_none(self):
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',
Expand Down