Skip to content

Commit 6d5ff62

Browse files
committed
Modified scale awareness from exception to warning
Signed-off-by: André Martins <martins@noironetworks.com>
1 parent 1344099 commit 6d5ff62

File tree

3 files changed

+5
-19
lines changed

3 files changed

+5
-19
lines changed

compose/cli/main.py

+2-10
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from .. import __version__
1414
from .. import legacy
1515
from ..project import NoSuchService, ConfigurationError
16-
from ..service import BuildError, CannotBeScaledError, NeedsBuildError
16+
from ..service import BuildError, NeedsBuildError
1717
from ..config import parse_environment
1818
from .command import Command
1919
from .docopt_command import NoSuchCommand
@@ -372,15 +372,7 @@ def scale(self, project, options):
372372
except ValueError:
373373
raise UserError('Number of containers for service "%s" is not a '
374374
'number' % service_name)
375-
try:
376-
project.get_service(service_name).scale(num)
377-
except CannotBeScaledError:
378-
raise UserError(
379-
'Service "%s" cannot be scaled because it specifies a port '
380-
'on the host. If multiple containers for this service were '
381-
'created, the port would clash.\n\nRemove the ":" from the '
382-
'port definition in docker-compose.yml so Docker can choose a random '
383-
'port for each container.' % service_name)
375+
project.get_service(service_name).scale(num)
384376

385377
def start(self, project, options):
386378
"""

compose/service.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,6 @@ def __init__(self, service, reason):
5555
self.reason = reason
5656

5757

58-
class CannotBeScaledError(Exception):
59-
pass
60-
6158

6259
class ConfigError(ValueError):
6360
pass
@@ -154,7 +151,9 @@ def scale(self, desired_num):
154151
- removes all stopped containers
155152
"""
156153
if not self.can_be_scaled():
157-
raise CannotBeScaledError()
154+
log.warn('Service %s only specifies a port on the host. If multiple '
155+
'containers for this service are created on a single host, '
156+
'the port will clash.' % self.name)
158157

159158
# Create enough containers
160159
containers = self.containers(stopped=True)

tests/integration/service_test.py

-5
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
LABEL_VERSION,
1818
)
1919
from compose.service import (
20-
CannotBeScaledError,
2120
ConfigError,
2221
Service,
2322
build_extra_hosts,
@@ -526,10 +525,6 @@ def test_scale(self):
526525
service.scale(0)
527526
self.assertEqual(len(service.containers()), 0)
528527

529-
def test_scale_on_service_that_cannot_be_scaled(self):
530-
service = self.create_service('web', ports=['8000:8000'])
531-
self.assertRaises(CannotBeScaledError, lambda: service.scale(1))
532-
533528
def test_scale_sets_ports(self):
534529
service = self.create_service('web', ports=['8000'])
535530
service.scale(2)

0 commit comments

Comments
 (0)