def test_dns_as_list_option(self): service = entities.Service('foo', 'stackbrew/ubuntu', env={}) container = entities.Container('foo1', entities.Ship('ship', 'shipip'), service, config={'dns': ['8.8.8.8', '8.8.4.4']}) self.assertEqual(container.dns, ['8.8.8.8', '8.8.4.4'])
def test_no_dns_option(self): service = entities.Service('foo', 'stackbrew/ubuntu', env={}) container = entities.Container('foo1', entities.Ship('ship', 'shipip'), service, config={}) self.assertIsNone(container.dns)
def _cntr(service_name=SERVICE, service_env=None, image=IMAGE, ship_name=SHIP, ship_ip=SHIP_IP, container_name=CONTAINER, config=None, schema=SCHEMA): service = entities.Service(service_name, image, schema, service_env) return entities.Container(container_name, entities.Ship(ship_name, ship_ip), service, config=config, schema=schema)
def _get_container(self): ship = entities.Ship('ship', 'ship.ip') service = entities.Service('foo', 'stackbrew/ubuntu') return entities.Container( 'foo1', ship, service, config={'ports': {'server': '4242/tcp', 'data': '4243/udp'}, 'env': {'foo': 'bar', 'wid': 42}})
def test_swap_limit_string_with_suffix(self): config = {'limits': {'swap': '42k'}} service = entities.Service('foo', 'stackbrew/ubuntu', env={}) container = entities.Container('foo1', entities.Ship('ship', 'shipip'), service, config=config) self.assertEqual(container.memswap_limit, 42 * 1024)
def test_swap_limit_number(self): config = {'limits': {'swap': 42}} service = entities.Service('foo', 'stackbrew/ubuntu', env={}) container = entities.Container('foo1', entities.Ship('ship', 'shipip'), service, config=config) self.assertEqual(container.memswap_limit, 42)
def test_restart_policy_wrong_name(self): config = {'restart': 'noclue'} service = entities.Service('foo', 'stackbrew/ubuntu', env={}) self.assertRaises( exceptions.InvalidRestartPolicyConfigurationException, lambda: entities.Container('foo1', entities.Ship('ship', 'shipip'), service, config=config))
def _cntr(service_name=SERVICE, service_env=None, image=IMAGE, ship_name=SHIP, ship_ip=SHIP_IP, container_name=CONTAINER, config=None, schema=SCHEMA, api_version=DOCKER_VERSION): service = entities.Service(service_name, image, schema=schema, env=service_env) return entities.Container(container_name, entities.Ship(ship_name, ship_ip, api_version=api_version), service, config=config, schema=schema)
def test_restart_policy_missing_retries(self): config = {'restart': {'name': 'on-failure'}} service = entities.Service('foo', 'stackbrew/ubuntu', env={}) container = entities.Container('foo1', entities.Ship('ship', 'shipip'), service, config=config) self.assertEqual(container.restart_policy, { 'Name': 'on-failure', 'MaximumRetryCount': 0 })
def test_restart_policy_wrong_type(self): config = {'restart': []} service = entities.Service('foo', 'stackbrew/ubuntu', env={}) container = entities.Container('foo1', entities.Ship('ship', 'shipip'), service, config=config) self.assertEqual(container.restart_policy, { 'Name': 'no', 'MaximumRetryCount': 0 })
def test_env_propagates_from_service(self): service_env = {'ENV_VAR': 'value'} container_env = {'OTHER_ENV_VAR': 'other-value'} service = entities.Service('foo', 'stackbrew/ubuntu', service_env) container = entities.Container('foo1', entities.Ship('ship', 'shipip'), service, config={'env': container_env}) for k, v in service_env.items(): self.assertIn(k, container.env) self.assertEqual(v, container.env[k]) for k, v in container_env.items(): self.assertIn(k, container.env) self.assertEqual(v, container.env[k])
def _cntr(service_name=SERVICE, service_env=None, image=IMAGE, ship_name=SHIP, ship_ip=SHIP_IP, container_name=CONTAINER, config=None, schema=SCHEMA, api_version=DOCKER_VERSION, ports=PORTS): service = entities.Service(name=service_name, image=image, maestro_schema=schema, env=service_env, ports=ports) ship = entities.Ship(ship_name, ship_ip, api_version=api_version) cfg = {'ship': ship.name} if config: cfg.update(config) return entities.Container({ship_name: ship}, container_name, service, config=cfg, maestro_schema=schema)