def test_marathon_lb_domains_multiple(): """ When a domains string with multiple domains is passed to marathon_lb_domains, it returns a comma-separated list of domains. """ domains = 'abc.com def.co.za ghi.co.ng' assert marathon_lb_domains(domains) == 'abc.com,def.co.za,ghi.co.ng'
def test_marathon_lb_domains_single(): """ When a domains string with a single domain is passed to marathon_lb_domains, it returns the domain unchanged. """ domains = 'abc.com' assert marathon_lb_domains(domains) == 'abc.com'
def test_get_marathon_app_data_with_postgres_db_needed(self): controller = DockerController.objects.create( name='Test App', owner=self.user, marathon_cmd='ping', docker_image='docker/image', postgres_db_needed=True, ) self.mock_create_postgres_db( 200, { 'result': { 'name': 'joes_db', 'user': '******', 'password': '******', 'host': 'localhost' } }) domain_label = "{}.{}".format(controller.app_id, settings.HUB_DOMAIN) self.assertEquals( controller.get_marathon_app_data(), { "id": controller.app_id, "cpus": 0.1, "mem": 128.0, "instances": 1, "cmd": "ping", "backoffFactor": settings.MESOS_DEFAULT_BACKOFF_FACTOR, "backoffSeconds": settings.MESOS_DEFAULT_BACKOFF_SECONDS, "env": { "DATABASE_URL": u"postgres://*****:*****@localhost/joes_db" }, "labels": { "domain": domain_label, "HAPROXY_GROUP": "external", "HAPROXY_0_VHOST": marathon_lb_domains(domain_label), "traefik.frontend.rule": traefik_domains(domain_label), "name": "Test App", "org": "", }, "container": { "type": "DOCKER", "docker": { "image": "docker/image", "forcePullImage": True, "network": "BRIDGE", "parameters": [{ "key": "memory-swappiness", "value": "0" }], }, }, })
def test_get_marathon_app_data_with_app_labels(self): controller = DockerController.objects.create( name='Test App', owner=self.user, marathon_cmd='ping', docker_image='docker/image', ) self.mk_env_variable(controller) self.mk_labels_variable(controller) domain_label = "{}.{}".format(controller.app_id, settings.HUB_DOMAIN) self.assertEquals( controller.get_marathon_app_data(), { "id": controller.app_id, "cpus": 0.1, "mem": 128.0, "instances": 1, "cmd": "ping", "backoffFactor": settings.MESOS_DEFAULT_BACKOFF_FACTOR, "backoffSeconds": settings.MESOS_DEFAULT_BACKOFF_SECONDS, "env": { "TEST_KEY": "a test value" }, "labels": { "domain": domain_label, "HAPROXY_GROUP": "external", "HAPROXY_0_VHOST": marathon_lb_domains(domain_label), "traefik.frontend.rule": traefik_domains(domain_label), "name": "Test App", "TEST_LABELS_NAME": 'a test label value', "org": "", }, "container": { "type": "DOCKER", "docker": { "image": "docker/image", "forcePullImage": True, "network": "BRIDGE", "parameters": [{ "key": "memory-swappiness", "value": "0" }], }, }, })
def test_get_marathon_app_data_using_health_cmd(self): controller = DockerController.objects.create( name='Test App', owner=self.user, marathon_cmd='ping', docker_image='docker/image', marathon_health_check_cmd='cmd ping', port=1234, ) custom_urls = "testing.com url.com" controller.domain_urls += custom_urls with self.settings(MESOS_DEFAULT_GRACE_PERIOD_SECONDS='600', MESOS_DEFAULT_INTERVAL_SECONDS='100', MESOS_DEFAULT_TIMEOUT_SECONDS='200'): domain_label = "{}.{} {}".format(controller.app_id, settings.HUB_DOMAIN, custom_urls) self.assertEquals( controller.get_marathon_app_data(), { "id": controller.app_id, "cpus": 0.1, "mem": 128.0, "instances": 1, "cmd": "ping", "backoffFactor": settings.MESOS_DEFAULT_BACKOFF_FACTOR, "backoffSeconds": settings.MESOS_DEFAULT_BACKOFF_SECONDS, "labels": { "domain": domain_label, "HAPROXY_GROUP": "external", "HAPROXY_0_VHOST": marathon_lb_domains(domain_label), "traefik.frontend.rule": traefik_domains(domain_label), "name": "Test App", "org": "", }, "container": { "type": "DOCKER", "docker": { "image": "docker/image", "forcePullImage": True, "network": "BRIDGE", "portMappings": [{ "containerPort": 1234, "hostPort": 0 }], "parameters": [{ "key": "memory-swappiness", "value": "0" }], }, }, "healthChecks": [{ "gracePeriodSeconds": 600, "intervalSeconds": 100, "maxConsecutiveFailures": 3, "command": { 'value': 'cmd ping' }, "protocol": "COMMAND", "timeoutSeconds": 200 }] })
def test_get_marathon_app_data(self): controller = DockerController.objects.create( name='Test App', owner=self.user, marathon_cmd='ping', docker_image='docker/image', ) org = Organization.objects.create(name="Test Org", slug="test-org") OrganizationUserRelation.objects.create(user=self.user, organization=org) controller.organization = org controller.save() custom_urls = "testing.com url.com" controller.domain_urls += custom_urls domain_label = "{}.{} {}".format(controller.app_id, settings.HUB_DOMAIN, custom_urls) self.assertEquals( controller.get_marathon_app_data(), { "id": controller.app_id, "cpus": 0.1, "mem": 128.0, "instances": 1, "cmd": "ping", "backoffFactor": settings.MESOS_DEFAULT_BACKOFF_FACTOR, "backoffSeconds": settings.MESOS_DEFAULT_BACKOFF_SECONDS, "labels": { "domain": domain_label, "HAPROXY_GROUP": "external", "HAPROXY_0_VHOST": marathon_lb_domains(domain_label), "traefik.frontend.rule": traefik_domains(domain_label), "name": "Test App", "org": "test-org", }, "container": { "type": "DOCKER", "docker": { "image": "docker/image", "forcePullImage": True, "network": "BRIDGE", "parameters": [{ "key": "memory-swappiness", "value": "0" }], }, }, }) controller.port = 1234 controller.save() domain_label = "{}.{} {}".format(controller.app_id, settings.HUB_DOMAIN, custom_urls) self.assertEquals( controller.get_marathon_app_data(), { "id": controller.app_id, "cpus": 0.1, "mem": 128.0, "instances": 1, "cmd": "ping", "backoffFactor": settings.MESOS_DEFAULT_BACKOFF_FACTOR, "backoffSeconds": settings.MESOS_DEFAULT_BACKOFF_SECONDS, "labels": { "domain": domain_label, "HAPROXY_GROUP": "external", "HAPROXY_0_VHOST": marathon_lb_domains(domain_label), "traefik.frontend.rule": traefik_domains(domain_label), "name": "Test App", "org": "test-org", }, "container": { "type": "DOCKER", "docker": { "image": "docker/image", "forcePullImage": True, "network": "BRIDGE", "portMappings": [{ "containerPort": 1234, "hostPort": 0 }], "parameters": [{ "key": "memory-swappiness", "value": "0" }], }, }, }) controller.marathon_health_check_path = '/health/path/' controller.save() domain_label = "{}.{} {}".format(controller.app_id, settings.HUB_DOMAIN, custom_urls) self.assertEquals( controller.get_marathon_app_data(), { "id": controller.app_id, "cpus": 0.1, "mem": 128.0, "instances": 1, "cmd": "ping", "backoffFactor": settings.MESOS_DEFAULT_BACKOFF_FACTOR, "backoffSeconds": settings.MESOS_DEFAULT_BACKOFF_SECONDS, "labels": { "domain": domain_label, "HAPROXY_GROUP": "external", "HAPROXY_0_VHOST": marathon_lb_domains(domain_label), "traefik.frontend.rule": traefik_domains(domain_label), "name": "Test App", "org": "test-org", }, "container": { "type": "DOCKER", "docker": { "image": "docker/image", "forcePullImage": True, "network": "BRIDGE", "portMappings": [{ "containerPort": 1234, "hostPort": 0 }], "parameters": [{ "key": "memory-swappiness", "value": "0" }], } }, "ports": [0], "healthChecks": [{ "gracePeriodSeconds": 60, "intervalSeconds": 10, "maxConsecutiveFailures": 3, "path": '/health/path/', "portIndex": 0, "protocol": "HTTP", "timeoutSeconds": 20 }] }) controller.volume_needed = True controller.volume_path = "/deploy/media/" controller.save() domain_label = "{}.{} {}".format(controller.app_id, settings.HUB_DOMAIN, custom_urls) self.assertEquals( controller.get_marathon_app_data(), { "id": controller.app_id, "cpus": 0.1, "mem": 128.0, "instances": 1, "cmd": "ping", "backoffFactor": settings.MESOS_DEFAULT_BACKOFF_FACTOR, "backoffSeconds": settings.MESOS_DEFAULT_BACKOFF_SECONDS, "labels": { "domain": domain_label, "HAPROXY_GROUP": "external", "HAPROXY_0_VHOST": marathon_lb_domains(domain_label), "traefik.frontend.rule": traefik_domains(domain_label), "name": "Test App", "org": "test-org", }, "container": { "type": "DOCKER", "docker": { "image": "docker/image", "forcePullImage": True, "network": "BRIDGE", "portMappings": [{ "containerPort": 1234, "hostPort": 0 }], "parameters": [{ "key": "memory-swappiness", "value": "0" }, { "key": "volume-driver", "value": "xylem" }, { "key": "volume", "value": "%s_media:/deploy/media/" % controller.app_id }] } }, "ports": [0], "healthChecks": [{ "gracePeriodSeconds": 60, "intervalSeconds": 10, "maxConsecutiveFailures": 3, "path": '/health/path/', "portIndex": 0, "protocol": "HTTP", "timeoutSeconds": 20 }] }) controller.volume_path = "" controller.save() domain_label = "{}.{} {}".format(controller.app_id, settings.HUB_DOMAIN, custom_urls) self.assertEquals( controller.get_marathon_app_data(), { "id": controller.app_id, "cpus": 0.1, "mem": 128.0, "instances": 1, "cmd": "ping", "backoffFactor": settings.MESOS_DEFAULT_BACKOFF_FACTOR, "backoffSeconds": settings.MESOS_DEFAULT_BACKOFF_SECONDS, "labels": { "domain": domain_label, "HAPROXY_GROUP": "external", "HAPROXY_0_VHOST": marathon_lb_domains(domain_label), "traefik.frontend.rule": traefik_domains(domain_label), "name": "Test App", "org": "test-org", }, "container": { "type": "DOCKER", "docker": { "image": "docker/image", "forcePullImage": True, "network": "BRIDGE", "portMappings": [{ "containerPort": 1234, "hostPort": 0 }], "parameters": [{ "key": "memory-swappiness", "value": "0" }, { "key": "volume-driver", "value": "xylem" }, { "key": "volume", "value": "%s_media:%s" % (controller.app_id, settings.MARATHON_DEFAULT_VOLUME_PATH) }] } }, "ports": [0], "healthChecks": [{ "gracePeriodSeconds": 60, "intervalSeconds": 10, "maxConsecutiveFailures": 3, "path": '/health/path/', "portIndex": 0, "protocol": "HTTP", "timeoutSeconds": 20 }] })