| # |
| # Licensed under the Apache License, Version 2.0 (the "License"); |
| # you may not use this file except in compliance with the License. |
| # You may obtain a copy of the License at |
| # |
| # http://www.apache.org/licenses/LICENSE-2.0 |
| # |
| # Unless required by applicable law or agreed to in writing, software |
| # distributed under the License is distributed on an "AS IS" BASIS, |
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| # See the License for the specific language governing permissions and |
| # limitations under the License. |
| # |
| |
| import getpass |
| |
| class DefaultProfile(Struct): |
| role=Default(String, getpass.getuser()) |
| cmd=Default(String, 'cp /vagrant/src/test/sh/org/apache/aurora/e2e/http_example.py .') |
| gpu=Default(Integer, 0) |
| instances=Default(Integer, 1) |
| |
| |
| ContainerProfile = DefaultProfile( |
| cmd = 'cp /tmp/http_example.py .' |
| ) |
| |
| GpuProfile = DefaultProfile( |
| gpu=1 |
| ) |
| |
| echo_ports = Process( |
| name = 'echo_ports', |
| cmdline = 'echo "tcp port: {{thermos.ports[tcp]}}; http port: {{thermos.ports[http]}}; alias: {{thermos.ports[alias]}}; health: {{thermos.ports[health]}}"' |
| ) |
| |
| run_server = Process( |
| name = 'run_server', |
| cmdline = 'python http_example.py {{thermos.ports[http]}} {{thermos.ports[health]}}') |
| |
| stage_server = Process( |
| name = 'stage_server', |
| cmdline = '{{profile.cmd}}' |
| ) |
| |
| setup_env = Process( |
| name = 'setup_env', |
| cmdline='''cat <<EOF > .thermos_profile |
| export IT_WORKED=hello |
| EOF''' |
| ) |
| |
| read_env = Process( |
| name = 'read_env', |
| cmdline = 'echo "$IT_WORKED"' |
| ) |
| |
| verify_file_mount = Process( |
| name = 'verify_file_mount', |
| cmdline = 'cat /home/vagrant/aurora/.auroraversion' |
| ) |
| |
| # Regression test for quotation mark usage (AURORA-1782) |
| verify_command_escaping = Process( |
| name = 'verify_command_escaping', |
| cmdline = """ |
| python -c 'import sys |
| |
| if __name__ == "__main__": |
| sys.exit(0)' |
| """ |
| ) |
| |
| verify_file_system = Process( |
| name = 'check_fs', |
| cmdline = 'check-fs.sh' |
| ) |
| |
| test_task = SequentialTask( |
| name = 'http_example', |
| resources = Resources(cpu=0.5, ram=32*MB, disk=64*MB, gpu='{{profile.gpu}}'), |
| processes = [ |
| setup_env, |
| read_env, |
| echo_ports, |
| verify_command_escaping, |
| stage_server, |
| run_server |
| ] |
| ) |
| |
| no_python_task = SequentialTask( |
| name = 'http_example_no_python', |
| resources = Resources(cpu=0.4, ram=32*MB, disk=64*MB), |
| processes = [ |
| setup_env, |
| read_env, |
| echo_ports, |
| verify_command_escaping, |
| verify_file_mount, |
| verify_file_system, |
| Process(name='run_server', cmdline='run-server.sh {{thermos.ports[http]}}'), |
| ] |
| ) |
| |
| update_config = UpdateConfig(watch_secs=0, batch_size=2) |
| update_config_watch_secs = UpdateConfig(watch_secs=10, batch_size=2) |
| update_config_var_batch = UpdateConfig(update_strategy = VariableBatchUpdateStrategy(batch_sizes = [1,2])) |
| health_check_config = HealthCheckConfig(initial_interval_secs=5, interval_secs=1) |
| shell_health_check_config = HealthCheckConfig( |
| health_checker = HealthCheckerConfig( |
| shell = ShellHealthChecker(shell_command='stat /usr/local/bin/run-server.sh')), |
| initial_interval_secs=5, |
| interval_secs=1, |
| min_consecutive_successes=5 |
| ) |
| |
| job = Service( |
| cluster = 'devcluster', |
| instances = '{{profile.instances}}', |
| update_config = update_config, |
| health_check_config = health_check_config, |
| task = test_task, |
| role = '{{profile.role}}', |
| environment = 'test', |
| contact = '{{profile.role}}@localhost', |
| announce = Announcer( |
| portmap={'alias': 'http'}, |
| ), |
| ) |
| |
| volumes = [ |
| Volume(container_path="etc/rsyslog.d.container", host_path="/etc/rsyslog.d", mode=Mode("RO")), |
| Volume(container_path="etc/w3m.container", host_path="/etc/X11", mode=Mode("RO")) |
| ] |
| |
| jobs = [ |
| job( |
| name = 'http_example' |
| ).bind(profile=DefaultProfile()), |
| job( |
| name = 'http_example_maintenance' |
| ).bind(profile=DefaultProfile()), |
| job( |
| name = 'http_example_watch_secs', |
| update_config = update_config_watch_secs |
| ).bind(profile=DefaultProfile()), |
| job( |
| name = 'http_example_var_batch_update', |
| update_config = update_config_var_batch |
| ).bind(profile=DefaultProfile()), |
| job( |
| name = 'http_example_revocable', |
| tier = 'revocable' |
| ).bind(profile=DefaultProfile()), |
| job( |
| name = 'http_example_docker', |
| container = Docker(image='{{docker.image[http_example][latest]}}') |
| ).bind(profile=ContainerProfile), |
| job( |
| name = 'http_example_gpu' |
| ).bind(profile=GpuProfile), |
| job( |
| name = 'http_example_unified_appc', |
| container = Mesos(image=AppcImage(name='http_example_netcat', image_id='{{appc_image_id}}'), volumes=volumes), |
| task = no_python_task, |
| health_check_config=shell_health_check_config |
| ).bind(profile=DefaultProfile()), |
| job( |
| name = 'http_example_unified_docker', |
| container = Mesos(image=DockerImage(name='http_example_netcat', tag='latest'), volumes=volumes), |
| task = no_python_task, |
| health_check_config=shell_health_check_config |
| ).bind(profile=DefaultProfile()) |
| ] |