Best Python code snippet using localstack_python
test_matching.py
Source:test_matching.py
...46 matcher.match()47 resources_matched = matcher.get_resources()48 for i, res in enumerate(resources_matched):49 for exp_deploy in expected_results[i]:50 assert exp_deploy in res.get_deployments()51def test_sat_matcher():52 expected_results = [53 [DeploymentEntity(name='test-deployment-1', memory=1024, cpu=1)],54 [55 DeploymentEntity(name='test-deployment-2', memory=512, cpu=2),56 DeploymentEntity(name='test-deployment-3', memory=256, cpu=0.5),57 ],58 []59 ]60 deployments = list()61 for node in expected_results:62 for deployment in node:63 deployments.append(deployment)64 matcher = Greedy(65 deployments,66 [67 ResourceEntity(name='test-node-1', memory=1024, cpu=1),68 ResourceEntity(name='test-node-2', memory=1024, cpu=3),69 ResourceEntity(name='test-node-3', memory=1024, cpu=1),70 ]71 )72 matcher.match()73 resources_matched = matcher.get_resources()74 for i, res in enumerate(resources_matched):75 for exp_deploy in expected_results[i]:76 assert exp_deploy in res.get_deployments()77def test_sat_matcher_with_labels():78 expected_results = [79 [DeploymentEntity(name='test-deployment-1', memory=1024, cpu=2)],80 [DeploymentEntity(name='test-deployment-2', memory=512, cpu=1), ],81 [DeploymentEntity(name='test-deployment-3', memory=256,82 cpu=0.5, labels={'node': '3'})]83 ]84 deployments = list()85 for node in expected_results:86 for deployment in node:87 deployments.append(deployment)88 matcher = Greedy(89 deployments,90 [91 ResourceEntity(name='test-node-1', memory=1024, cpu=8),92 ResourceEntity(name='test-node-2', memory=1024, cpu=3),93 ResourceEntity(name='test-node-3', memory=1024,94 cpu=1, labels={'node': '3'}),95 ]96 )97 matcher.match()98 resources_matched = matcher.get_resources()99 for i, res in enumerate(resources_matched):100 for exp_deploy in expected_results[i]:101 assert exp_deploy in res.get_deployments()102def test_greedy_matcher_with_labels():103 expected_results = [104 [105 DeploymentEntity(name='test-deployment-1', memory=1024, cpu=2),106 DeploymentEntity(name='test-deployment-2', memory=512, cpu=1)107 ],108 [],109 [DeploymentEntity(name='test-deployment-3', memory=256,110 cpu=0.5, labels={'node': '3'})]111 ]112 deployments = list()113 for node in expected_results:114 for deployment in node:115 deployments.append(deployment)116 matcher = Greedy(117 deployments,118 [119 ResourceEntity(name='test-node-1', memory=4096, cpu=8),120 ResourceEntity(name='test-node-2', memory=1024, cpu=3),121 ResourceEntity(name='test-node-3', memory=1024,122 cpu=1, labels={'node': '3'}),123 ]124 )125 matcher.match()126 resources_matched = matcher.get_resources()127 for i, res in enumerate(resources_matched):128 for exp_deploy in expected_results[i]:...
deployments.py
Source:deployments.py
...14 return "{0}".format(self.__dict__)15 def __getattr__(self, item):16 raise AttributeError17 def __len__(self):18 response = self.get_deployments()19 return len(response)20 def __iter__(self):21 response = self.get_deployments()22 return iter(response)23 def __contains__(self, item):24 try:25 deployments = self.get_deployments()26 for d in deployments:27 if d["ID"] == item:28 return True29 else:30 return False31 except nomad.api.exceptions.URLNotFoundNomadException:32 return False33 def __getitem__(self, item):34 try:35 deployments = self.get_deployments()36 for d in deployments:37 if d["ID"] == item:38 return d39 else:40 raise KeyError41 except nomad.api.exceptions.URLNotFoundNomadException:42 raise KeyError43 def get_deployments(self, prefix=""):44 """ This endpoint lists all deployments.45 https://www.nomadproject.io/docs/http/deployments.html46 optional_arguments:47 - prefix, (default "") Specifies a string to filter deployments on based on an index prefix.48 This is specified as a querystring parameter.49 returns: list of dicts50 raises:51 - nomad.api.exceptions.BaseNomadException52 - nomad.api.exceptions.URLNotFoundNomadException53 """54 params = {"prefix": prefix}...
main.py
Source:main.py
1import argparse2import json3import requests4from prettytable import PrettyTable5class KubernetesCLI(object):6 7 def get_Deployments(self,namespace, api_url='http://localhost:8080/apis/'):8 9 deployments_r = requests.get(api_url + 'apps/v1/namespaces/' + namespace + '/deployments') 10 deployments_json = json.loads(deployments_r.text)11 return deployments_json12 13if __name__ == '__main__':14 # Parse options15 #16 parser = argparse.ArgumentParser(description="Kubernetes CLI", 17 fromfile_prefix_chars='@')18 parser.add_argument("--namespace","-n",19 dest="namespace",20 required=True,21 help="R|\n"22 "Namespace to search")23 parser.add_argument("--apiurl",24 dest="apiurl",25 required=False,26 help="R|\n"27 "API URL") 28 args = parser.parse_args()29 instance = KubernetesCLI()30 if args.apiurl:31 deployments= instance.get_Deployments(args.namespace,args.apiurl)32 else:33 deployments= instance.get_Deployments(args.namespace)34 header = ['DeploymentName','Image','lastUpdateTime' ]35 table_values = PrettyTable(header) 36 for deployment in deployments['items']:37 container_image = [] 38 for container in (deployment['spec']['template']['spec']['containers']):39 container_image.append(container['image'])40 41 value = [deployment['metadata']['name'], ', '.join(container_image),deployment['status']['conditions'][-1]['lastUpdateTime']]42 table_values.add_row(value)43 44 print(table_values)45 46 47 48 49 ...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!