Merge pull request #1466 from noironetworks/changing-scale-to-warning

Modified scale awareness from exception to warning
(cherry picked from commit 7d2a89427c59774a8cbf503a57cb9f3b0d47d1fe)

Signed-off-by: Aanand Prasad <aanand.prasad@gmail.com>
This commit is contained in:
Aanand Prasad 2015-06-04 16:21:01 +01:00
parent b7e8770c4f
commit cd7f67018e
3 changed files with 5 additions and 20 deletions

View File

@ -12,7 +12,7 @@ import dockerpty
from .. import legacy from .. import legacy
from ..project import NoSuchService, ConfigurationError from ..project import NoSuchService, ConfigurationError
from ..service import BuildError, CannotBeScaledError, NeedsBuildError from ..service import BuildError, NeedsBuildError
from ..config import parse_environment from ..config import parse_environment
from .command import Command from .command import Command
from .docopt_command import NoSuchCommand from .docopt_command import NoSuchCommand
@ -371,15 +371,7 @@ class TopLevelCommand(Command):
except ValueError: except ValueError:
raise UserError('Number of containers for service "%s" is not a ' raise UserError('Number of containers for service "%s" is not a '
'number' % service_name) 'number' % service_name)
try:
project.get_service(service_name).scale(num) project.get_service(service_name).scale(num)
except CannotBeScaledError:
raise UserError(
'Service "%s" cannot be scaled because it specifies a port '
'on the host. If multiple containers for this service were '
'created, the port would clash.\n\nRemove the ":" from the '
'port definition in docker-compose.yml so Docker can choose a random '
'port for each container.' % service_name)
def start(self, project, options): def start(self, project, options):
""" """

View File

@ -55,10 +55,6 @@ class BuildError(Exception):
self.reason = reason self.reason = reason
class CannotBeScaledError(Exception):
pass
class ConfigError(ValueError): class ConfigError(ValueError):
pass pass
@ -154,7 +150,9 @@ class Service(object):
- removes all stopped containers - removes all stopped containers
""" """
if not self.can_be_scaled(): if not self.can_be_scaled():
raise CannotBeScaledError() log.warn('Service %s specifies a port on the host. If multiple containers '
'for this service are created on a single host, the port will clash.'
% self.name)
# Create enough containers # Create enough containers
containers = self.containers(stopped=True) containers = self.containers(stopped=True)

View File

@ -17,7 +17,6 @@ from compose.const import (
LABEL_VERSION, LABEL_VERSION,
) )
from compose.service import ( from compose.service import (
CannotBeScaledError,
ConfigError, ConfigError,
Service, Service,
build_extra_hosts, build_extra_hosts,
@ -526,10 +525,6 @@ class ServiceTest(DockerClientTestCase):
service.scale(0) service.scale(0)
self.assertEqual(len(service.containers()), 0) self.assertEqual(len(service.containers()), 0)
def test_scale_on_service_that_cannot_be_scaled(self):
service = self.create_service('web', ports=['8000:8000'])
self.assertRaises(CannotBeScaledError, lambda: service.scale(1))
def test_scale_sets_ports(self): def test_scale_sets_ports(self):
service = self.create_service('web', ports=['8000']) service = self.create_service('web', ports=['8000'])
service.scale(2) service.scale(2)