def create_pod_config(self, sleep_time, dynamic_factor, host_limit_1=False): container_spec = pod.ContainerSpec( resource=pod.ResourceSpec( cpu_limit=0.1, mem_limit_mb=32, disk_limit_mb=32, ), command=mesos.CommandInfo( shell=True, value="echo %s && sleep %s" % (str(dynamic_factor), str(sleep_time)), ), ) instance_label = v1alpha_peloton.Label( key="peloton/instance", value="instance-label" ) host_limit_1_constraint = None if host_limit_1: host_limit_1_constraint = pod.Constraint( type=1, # Label constraint label_constraint=pod.LabelConstraint( kind=1, # Label condition=2, # Equal requirement=0, label=instance_label, ), ) containers = [container_spec] return pod.PodSpec(containers=containers, labels=[instance_label], constraint=host_limit_1_constraint)
def create_pod_config(self, sleep_time, dynamic_factor): container_spec = pod.ContainerSpec( resource=pod.ResourceSpec( cpu_limit=0.1, mem_limit_mb=32, disk_limit_mb=32 ), command=mesos.CommandInfo( shell=True, value="echo %s && sleep %s" % (str(dynamic_factor), str(sleep_time)), ), ) containers = [container_spec] return pod.PodSpec(containers=containers)
def test__launch_kill(self): resource_constraint = self.new_resource_constraint(3.0) host_filter = v1hostmgr.HostFilter( resource_constraint=resource_constraint, max_hosts=1, ) request = v1hostmgr_svc.AcquireHostsRequest(filter=host_filter) resp = self.client.v1hostmgr_svc.AcquireHosts(request, metadata=self.metadata, timeout=20) assert len(resp.hosts) == 1 pod_spec = pod.PodSpec( pod_name=v1alpha.PodName(value='test-123'), containers=[ pod.ContainerSpec( name='c1', image='alpine:3.6', entrypoint=pod.CommandSpec( value='/bin/sh', arguments=[ '-c', 'while true; do echo OK && sleep 3; done', ], ), ), ], ) pod_obj = v1hostmgr.LaunchablePod( pod_id=v1alpha.PodID(value='test-123'), spec=pod_spec, ) req = v1hostmgr_svc.LaunchPodsRequest( lease_id=resp.hosts[0].lease_id, hostname=resp.hosts[0].host_summary.hostname, pods=[pod_obj], ) self.client.v1hostmgr_svc.LaunchPods( req, metadata=self.metadata, timeout=20, ) # the second launch pods call should fail. with pytest.raises(Exception): self.client.v1hostmgr_svc.LaunchPods( req, metadata=self.metadata, timeout=20, ) req = v1hostmgr_svc.KillPodsRequest(pod_ids=[ v1alpha.PodID(value='test-123'), ], ) self.client.v1hostmgr_svc.KillPods( req, metadata=self.metadata, timeout=20, )