def test_sat_matcher_with_labels(): expected_results = [[ DeploymentEntity(name='test-deployment-1', memory=1024, cpu=2) ], [ DeploymentEntity(name='test-deployment-2', memory=512, cpu=1), ], [ DeploymentEntity(name='test-deployment-3', memory=256, cpu=0.5, labels={'node': '3'}) ]] deployments = list() for node in expected_results: for deployment in node: deployments.append(deployment) matcher = Greedy(deployments, [ ResourceEntity(name='test-node-1', memory=1024, cpu=8), ResourceEntity(name='test-node-2', memory=1024, cpu=3), ResourceEntity( name='test-node-3', memory=1024, cpu=1, labels={'node': '3'}), ]) matcher.match() resources_matched = matcher.get_resources() for i, res in enumerate(resources_matched): for exp_deploy in expected_results[i]: assert exp_deploy in res.get_deployments()
def test_upper_bound_cpu_detection(): matcher = Solver( [DeploymentEntity(name='test-deployment', memory=1024, cpu=2)], [ResourceEntity(name='test-node', memory=512, cpu=1)]) with pytest.raises(SolverError) as e: matcher.match() assert e.type == SolverError
def parse(self, definition): """Parses the given resource definitions to the internal object structure :param definition: str with plain YAML resource definitions :type definition: str """ # see default loader deprecation # https://github.com/yaml/pyyaml/wiki/PyYAML-yaml.load(input)-Deprecation nodes = yaml.load(definition, Loader=yaml.SafeLoader)['resources'] for node in nodes: self.check_mandatory_fields(node) _resource = ResourceEntity() _resource.name = node.get('name') _resource.memory = node.get('memory') _resource.cpu = node.get('cpu') _resource.labels = node.get('labels', None) self.resources.append(_resource)