def test_load(): k = KubernetesCluster() k.load_dir(TEST_CLUSTER_FOLDER) k._build_state() objects = filter(lambda x: isinstance(x, DaemonSet), k.state_objects) for p in objects: if p.metadata_name == "fluentd-elasticsearch": assert p.cpuRequest._get_value( ) == util.cpuConvertToAbstractProblem("400m") assert p.memRequest._get_value( ) == util.memConvertToAbstractProblem("400Mi") assert p.memLimit._get_value() == util.memConvertToAbstractProblem( "400Mi") return raise ValueError("Could not find service loded")
def test_load_create(): k = KubernetesCluster() k.load_dir(TEST_CLUSTER_FOLDER) k.apply_resource(open(TEST_DAEMONSET_APPLY).read()) k._build_state() objects = filter(lambda x: isinstance(x, DaemonSet), k.state_objects) for p in objects: if p.metadata_name == "fluentd-elasticsearch": assert len(util.objDeduplicatorByName(p.podList._get_value())) == 2 assert p.cpuRequest._get_value( ) == util.cpuConvertToAbstractProblem("10m") assert p.memRequest._get_value( ) == util.memConvertToAbstractProblem("10Mi") assert p.memLimit._get_value() == util.memConvertToAbstractProblem( "10Mi") return raise ValueError("Could not find service loded")
def spec_containers__resources_requests_cpu(self, res): if self.cpuRequest == -1: self.cpuRequest = 0 self.cpuRequest += cpuConvertToAbstractProblem(res)
def spec_template_spec_containers__resources_limits_cpu(self, res): if self.cpuLimit == -1: self.cpuLimit = 0 self.cpuLimit += cpuConvertToAbstractProblem(res)
def status_allocatable_cpu(self, value): self.cpuCapacity = cpuConvertToAbstractProblem(value)
def test_convert_cpu_toobig(): try: x = cpuConvertToAbstractProblem("100000000000m") except AssertionError: pass
def test_convert_cpu_toosmall(): try: x = cpuConvertToAbstractProblem("-1") except AssertionError: pass
def test_convert_cpu_normal(): x = cpuConvertToAbstractProblem("500m") assert x == int(500 / util.CPU_DIVISOR)