def test_base_task(self, system_paasta_config): service_name = "service_name" instance_name = "instance_name" cluster = "cluster" service_config = NativeServiceConfig( service=service_name, instance=instance_name, cluster=cluster, config_dict={ "cpus": 0.1, "mem": 50, "instances": 3, "cmd": 'sleep 50', "drain_method": "test", "extra_volumes": [{ "containerPath": "/foo", "hostPath": "/bar", "mode": "RW" }] }, branch_dict={ 'docker_image': 'busybox', 'desired_state': 'start', 'force_bounce': '0', }, ) task = service_config.base_task(system_paasta_config) assert task.container.type == 'DOCKER' assert task.container.docker.image == "fake/busybox" parameters = [(p.key, p.value) for p in task.container.docker.parameters] assert parameters == [ ("memory-swap", mock.ANY), ("cpu-period", mock.ANY), ("cpu-quota", mock.ANY), ("label", mock.ANY), # service ("label", mock.ANY), # instance ] assert task.container.docker.network == 'BRIDGE' assert len(task.container.volumes) == 1 assert task.container.volumes[0].mode == 'RW' assert task.container.volumes[0].container_path == "/foo" assert task.container.volumes[0].host_path == "/bar" assert len(task.container.docker.port_mappings) == 1 assert task.container.docker.port_mappings[0].container_port == 8888 assert task.container.docker.port_mappings[0].host_port == 0 assert task.container.docker.port_mappings[0].protocol == "tcp" assert task.command.value == "sleep 50" assert len(task.resources) == 3 for resource in task.resources: if resource.name == "cpus": assert resource.scalar.value == 0.1 elif resource.name == "mem": assert resource.scalar.value == 50 elif resource.name == 'ports': pass else: raise AssertionError('Unreachable: {}'.format(resource.name)) assert task.name.startswith( "service_name.instance_name.gitbusybox.config") assert task.command.uris[ 0].value == system_paasta_config.get_dockercfg_location()
def test_base_task(self, system_paasta_config): service_name = "service_name" instance_name = "instance_name" cluster = "cluster" service_config = NativeServiceConfig( service=service_name, instance=instance_name, cluster=cluster, config_dict={ "cpus": 0.1, "mem": 50, "instances": 3, "cmd": 'sleep 50', "drain_method": "test", "extra_volumes": [{ "containerPath": "/foo", "hostPath": "/bar", "mode": "RW" }], }, branch_dict={ 'docker_image': 'busybox', 'desired_state': 'start', 'force_bounce': '0', }, soa_dir='/nail/etc/services', ) with mock.patch( 'paasta_tools.utils.load_system_paasta_config', autospec=True, return_value=system_paasta_config, ): task = service_config.base_task(system_paasta_config) assert task == { 'container': { 'type': 'DOCKER', 'docker': { 'image': 'fake/busybox', 'parameters': [ { "key": "memory-swap", "value": mock.ANY }, { "key": "cpu-period", "value": mock.ANY }, { "key": "cpu-quota", "value": mock.ANY }, { "key": "label", "value": mock.ANY }, # service { "key": "label", "value": mock.ANY }, # instance ], 'network': 'BRIDGE', 'port_mappings': [{ 'container_port': 8888, 'host_port': 0, 'protocol': "tcp", }], }, 'volumes': [{ 'mode': 'RW', 'container_path': "/foo", 'host_path': "/bar", }], }, 'command': { 'value': 'sleep 50', 'uris': [ { 'value': system_paasta_config.get_dockercfg_location(), 'extract': False }, ], }, 'resources': [ { 'name': 'cpus', 'scalar': { 'value': 0.1 }, 'type': 'SCALAR' }, { 'name': 'mem', 'scalar': { 'value': 50 }, 'type': 'SCALAR' }, { 'name': 'ports', 'ranges': mock.ANY, 'type': 'RANGES' }, ], 'name': mock.ANY, 'agent_id': { 'value': '' }, 'task_id': { 'value': '' }, } assert task['name'].startswith( "service_name.instance_name.gitbusybox.config")
def test_base_task(self, system_paasta_config): service_name = "service_name" instance_name = "instance_name" cluster = "cluster" service_config = NativeServiceConfig( service=service_name, instance=instance_name, cluster=cluster, config_dict={ "cpus": 0.1, "mem": 50, "instances": 3, "cmd": "sleep 50", "drain_method": "test", "extra_volumes": [ {"containerPath": "/foo", "hostPath": "/bar", "mode": "RW"} ], }, branch_dict={ "docker_image": "busybox", "desired_state": "start", "force_bounce": "0", }, soa_dir="/nail/etc/services", ) with mock.patch( "paasta_tools.utils.load_system_paasta_config", autospec=True, return_value=system_paasta_config, ), mock.patch( "paasta_tools.utils.InstanceConfig.use_docker_disk_quota", autospec=True, return_value=True, ): task = service_config.base_task(system_paasta_config) assert task == { "container": { "type": "DOCKER", "docker": { "image": "fake/busybox", "parameters": [ {"key": "memory-swap", "value": mock.ANY}, {"key": "cpu-period", "value": mock.ANY}, {"key": "cpu-quota", "value": mock.ANY}, {"key": "storage-opt", "value": mock.ANY}, {"key": "label", "value": mock.ANY}, # service {"key": "label", "value": mock.ANY}, # instance {"key": "init", "value": "true"}, {"key": "cap-drop", "value": "SETPCAP"}, {"key": "cap-drop", "value": "MKNOD"}, {"key": "cap-drop", "value": "AUDIT_WRITE"}, {"key": "cap-drop", "value": "CHOWN"}, {"key": "cap-drop", "value": "NET_RAW"}, {"key": "cap-drop", "value": "DAC_OVERRIDE"}, {"key": "cap-drop", "value": "FOWNER"}, {"key": "cap-drop", "value": "FSETID"}, {"key": "cap-drop", "value": "KILL"}, {"key": "cap-drop", "value": "SETGID"}, {"key": "cap-drop", "value": "SETUID"}, {"key": "cap-drop", "value": "NET_BIND_SERVICE"}, {"key": "cap-drop", "value": "SYS_CHROOT"}, {"key": "cap-drop", "value": "SETFCAP"}, ], "network": "BRIDGE", "port_mappings": [ {"container_port": 8888, "host_port": 0, "protocol": "tcp"} ], }, "volumes": [ {"mode": "RW", "container_path": "/foo", "host_path": "/bar"} ], }, "command": { "value": "sleep 50", "uris": [ { "value": system_paasta_config.get_dockercfg_location(), "extract": False, } ], }, "resources": [ {"name": "cpus", "scalar": {"value": 0.1}, "type": "SCALAR"}, {"name": "mem", "scalar": {"value": 50}, "type": "SCALAR"}, {"name": "ports", "ranges": mock.ANY, "type": "RANGES"}, ], "name": mock.ANY, "agent_id": {"value": ""}, "task_id": {"value": ""}, } assert task["name"].startswith("service_name.instance_name.gitbusybox.config")