Best Python code snippet using tempest_python
numa_tests.py
Source:numa_tests.py
...274 logger.info("Now Cleaning up the resources for Test case 3")275 logger.info("Deleting Server")276 conn.delete_server('numa3_vm')277 logger.info("Deleting NUMA Flavor")278 conn.delete_flavor(data["numa_flavor"])279 logger.info("Resources are successfully deleted")280 except Exception as e:281 logger.info("Unable to run test case 3")282 logger.info("Deleting Server")283 ser = conn.get_server('numa3_vm')284 if ser is None:285 logger.info("Server doesn't exists")286 else:287 conn.delete_server('numa3_vm')288 logger.info("Server is deleted")289 logger.info("Deleting NUMA Flavor")290 flavor = conn.get_flavor(data["numa_flavor"])291 if flavor is None:292 logger.info("Flavor doesn't exists")293 else:294 conn.delete_flavor(data["numa_flavor"])295 logger.info("Flavor is deleted")296def test_case_5(conn):297 try:298 logger.info(" ")299 logger.info("##################################################")300 logger.info(" Executing Test Case 5 of NUMA ")301 logger.info("##################################################")302 logger.info(" ")303 os_flavor = create_numa_flavor(conn, name=data["numa_flavor"],304 ram=4096, vcpus=8, disk=40)305 vm_names = ["numa5_vm1", "numa5_vm2", "numa5_vm3", "numa5_vm4",306 "numa5_vm5", "numa5_vm6", "numa5_vm7", "numa5_vm8",307 "numa5_vm9", "numa5_vm10"]308 logger.info("Creating 10 instances using 8 vcpus flavor")309 for vm in vm_names:310 os_server = create_numa_instance(conn, server_name=vm, # noqa311 flavor_name=data["numa_flavor"], # noqa312 image_name=data["image_name"], # noqa313 network_name=data["net_name"], # noqa314 secgroup_name=data["sec_group_name"]) # noqa315 try:316 logger.info("Creaing 11th instance")317 os_server = create_numa_instance(conn, server_name='numa5_vm11', # noqa318 flavor_name=data["numa_flavor"], # noqa319 image_name=data["image_name"], # noqa320 network_name=data["net_name"], # noqa321 secgroup_name=data["sec_group_name"]) # noqa322 # logger.info("Instance 11 is successfully created")323 except Exception as e:324 logger.info("Cannot able to create Instance 11")325 logger.info("Test Case 5 is successfully verified")326 logger.info("Now Cleaning up the resources for Test case 5")327 logger.info("Deleting all the numa instances")328 for vm in vm_names:329 conn.delete_server(vm)330 logger.info("Instances are successfully deleted")331 logger.info("Deleting NUMA Flavor")332 conn.delete_flavor(data["numa_flavor"])333 logger.info("Flavor is successfully deleted")334 except Exception as e:335 logger.info("Unable to execute test_case_5")336 logger.info("Deleting all the NUMA instances")337 for vm in vm_names:338 ser = conn.get_server(vm)339 if ser is None:340 logger.info("Server doesn't exists")341 else:342 conn.delete_server(vm)343 logger.info("Instance: %s is deleted" % vm)344 logger.info("Deleting NUMA Flavor")345 flavor = conn.get_flavor(data["numa_flavor"])346 if flavor is None:347 logger.info("Flavor doesn't exists")348 else:349 conn.delete_flavor(data["numa_flavor"])350 logger.info("Flavor is deleted")351def test_case_6(conn):352 try:353 logger.info(" ")354 logger.info("##################################################")355 logger.info(" Executing Test Case 6 of NUMA ")356 logger.info("##################################################")357 logger.info(" ")358 os_flavor = create_numa_flavor(conn, name=data["numa_flavor"],359 ram=4096, vcpus=40, disk=40)360 instances = ["numa6_vm1", "numa6_vm2"]361 logger.info("Creating 2 instances with numa flavor")362 for vm in instances:363 os_server = create_numa_instance(conn, server_name=vm, # noqa364 flavor_name=data["numa_flavor"], # noqa365 image_name=data["image_name"], # noqa366 network_name=data["net_name"], # noqa367 secgroup_name=data["sec_group_name"]) # noqa368 logger.info("Instance: %s is Successfully created" % vm)369 try:370 logger.info("Creaing 3rd instance")371 os_server = create_numa_instance(conn, server_name='numa6_vm3', # noqa372 flavor_name=data["numa_flavor"], # noqa373 image_name=data["image_name"], # noqa374 network_name=data["net_name"], # noqa375 secgroup_name=data["sec_group_name"]) # noqa376 logger.info("Instance 3rd is successfully created")377 except Exception as e:378 logger.info("Cannot able to create 3rd Instance")379 logger.info("Test case 6 is successfully verified")380 # logger.info("Now, Deleting 3rd Instance")381 # conn.delete_server("numa6_vm3")382 logger.info("Now Cleaning up the resources for Test case 6")383 logger.info("Deleting all the numa instances")384 for vm in instances:385 conn.delete_server(vm)386 logger.info("Instances are successfully deleted")387 logger.info("Deleting NUMA Flavor")388 conn.delete_flavor(data["numa_flavor"])389 logger.info("Flavor is successfully deleted")390 except Exception as e:391 logger.info("Unable to execute test_case_6")392 logger.info("Deleting all the numa instances")393 for vm in instances:394 ser = conn.get_server(vm)395 if ser is None:396 logger.info("Server doesn't exists")397 else:398 conn.delete_server(vm)399 logger.info("Instance: %s is deleted" % vm)400 logger.info("Deleting NUMA Flavor")401 flavor = conn.get_flavor(data["numa_flavor"])402 if flavor is None:403 logger.info("Flavor doesn't exists")404 else:405 conn.delete_flavor(data["numa_flavor"])406 logger.info("Flavor is deleted")407def test_case_7(conn):408 try:409 logger.info(" ")410 logger.info("##################################################")411 logger.info(" Executing Test Case 7 of NUMA ")412 logger.info("##################################################")413 logger.info(" ")414 logger.info("Creating NUMA flavor with 4 vcpus")415 create_numa_flavor(conn, name=data["numa_flavor"],416 ram=4096, vcpus=4, disk=40)417 logger.info("Now creating instances using 4vcpus NUMA flavor")418 vm_names = ["numa7_vm1", "numa7_vm2"]419 for vm in vm_names:420 os_server = create_numa_instance(conn, server_name=vm, # noqa421 flavor_name=data["numa_flavor"], # noqa422 image_name=data["image_name"], # noqa423 network_name=data["net_name"], # noqa424 secgroup_name=data["sec_group_name"]) # noqa425 logger.info("Instance: %s is Successfully created" % vm)426 vm1_id = conn.get_server('numa7_vm1')427 vm2_id = conn.get_server('numa7_vm2')428 for i in range(1, 5):429 comm_1 = "sudo -i virsh dumpxml " + vm1_id + " | grep cpuset | gawk 'FNR == " + i + " {print $2}' FPAT='[0-9]+'" # noqa430 comm_2 = "sudo -i virsh dumpxml " + vm2_id + " | grep cpuset | gawk 'FNR == " + i + " {print $2}' FPAT='[0-9]+'" # noqa431 output_1 = ssh_into_compute_node(conn, command=comm_1)432 output_2 = ssh_into_compute_node(conn, command=comm_2)433 if output_1 != output_2:434 logger.info("Cpus are not equal: Test is going well")435 else:436 logger.info("Cpus are equal: Test is Failed")437 logger.info("Verification of Test case 7 is failed")438 logger.info("Exiting from loop")439 break440 logger.info("Now Cleaning up the resources for Test case 7")441 logger.info("Deleting all the numa instances")442 for vm in vm_names:443 conn.delete_server(vm)444 logger.info("Instance: %s is deleted" % vm)445 logger.info("Instances are successfully deleted")446 logger.info("Deleting NUMA Flavor")447 conn.delete_flavor(data["numa_flavor"])448 logger.info("Flavor is successfully deleted")449 except Exception as e:450 logger.info("Exception has occurred: Unable to Run Test Case 7")451 logger.info("Deleting all the numa instances")452 for vm in vm_names:453 ser = conn.get_server(vm)454 if ser is None:455 logger.info("Server doesn't exists")456 else:457 conn.delete_server(vm)458 logger.info("Instance: %s is deleted" % vm)459 logger.info("Deleting NUMA Flavor")460 flavor = conn.get_flavor(data["numa_flavor"])461 if flavor is None:462 logger.info("Flavor doesn't exists")463 else:464 conn.delete_flavor(data["numa_flavor"])465 logger.info("Flavor is deleted")466def test_case_8(conn):467 try:468 logger.info(" ")469 logger.info("##################################################")470 logger.info(" Executing Test Case 8 of NUMA ")471 logger.info("##################################################")472 logger.info(" ")473 logger.info("Creating NUMA flavor with 4 vcpus")474 create_numa_flavor(conn, name=data["numa_flavor"],475 ram=4096, vcpus=4, disk=40)476 logger.info("Now creating instances using 4vcpus NUMA flavor")477 vm_names = ["numa8_vm1", "numa8_vm2"]478 for vm in vm_names:479 os_server = create_numa_instance(conn, server_name=vm, # noqa480 flavor_name=data["numa_flavor"], # noqa481 image_name=data["image_name"], # noqa482 network_name=data["net_name"], # noqa483 secgroup_name=data["sec_group_name"]) # noqa484 logger.info("Instance: %s is Successfully created" % vm)485 vm_id = conn.get_server(vm).id486 try:487 for i in range(1, 5):488 comm = "sudo -i virsh dumpxml " + vm_id + " | grep cpuset | gawk 'FNR == " + i + " {print $2}' FPAT='[0-9]+'" # noqa489 output = ssh_into_compute_node(conn, command=comm)490 if output % 2 == 0:491 logger.info("Cpu is: %s and it is 'EVEN'" % output)492 else:493 logger.info("Cpu is: %s and is ODD" % output)494 logger.info("Test Verification is failed")495 break496 except Exception as e:497 logger.info("SSH Failed: Unable to execute commands in Compute Node for Test Verification") # noqa498 logger.info("Now Cleaning up the resources for Test case 8")499 logger.info("Deleting all the numa instances")500 for vm in vm_names:501 conn.delete_server(vm)502 logger.info("Instance: %s is deleted" % vm)503 logger.info("Instances are successfully deleted")504 logger.info("Deleting NUMA Flavor")505 conn.delete_flavor(data["numa_flavor"])506 logger.info("Flavor is successfully deleted")507 except Exception as e:508 logger.info("Exception has occurred: Unable to Run Test Case 8")509 logger.info("Deleting all the numa instances")510 for vm in vm_names:511 ser = conn.get_server(vm)512 if ser is None:513 logger.info("Server doesn't exists")514 else:515 conn.delete_server(vm)516 logger.info("Instance: %s is deleted" % vm)517 logger.info("Deleting NUMA Flavor")518 flavor = conn.get_flavor(data["numa_flavor"])519 if flavor is None:520 logger.info("Flavor doesn't exists")521 else:522 conn.delete_flavor(data["numa_flavor"])523 logger.info("Flavor is deleted")524 # even_odd_comm = "sudo -i virsh dumpxml 24c4e0d7-a2a7-4d2d-9826-58877ff49da3 | grep cpuset | gawk 'FNR == 1 {print $2}' FPAT='[0-9]+'"525 # output = ssh_into_compute_node(conn, server_name='numa_vm_tc_7', flavor_name=data["numa_name"], command=comm)526 # sudo -i virsh dumpxml 24c4e0d7-a2a7-4d2d-9826-58877ff49da3 | grep cpuset | gawk ' NR<5 {print $2}' FPAT='[0-9]+'527def test_case_9(conn):528 try:529 logger.info(" ")530 logger.info("##################################################")531 logger.info(" Executing Test Case 9 of NUMA ")532 logger.info("##################################################")533 logger.info(" ")534 logger.info("Creating NUMA flavor with 4 vcpus")535 create_numa_flavor(conn, name=data["numa_flavor"],536 ram=4096, vcpus=8, disk=40)537 logger.info("Executing test case 9 of NUMA")538 vm_names = ["numa9_vm1", "numa9_vm2", "numa9_vm3", "numa9_vm4",539 "numa9_vm5", "numa9_vm6", "numa9_vm7", "numa9_vm8",540 "numa9_vm9", "numa9_vm10"]541 logger.info("Creating 10 instances using 4 vcpus flavor")542 for vm in vm_names:543 os_server = create_numa_instance(conn, server_name=vm, # noqa544 flavor_name=data["numa_flavor"], # noqa545 image_name=data["image_name"], # noqa546 network_name=data["net_name"], # noqa547 secgroup_name=data["sec_group_name"]) # noqa548 # Stoping all the VMs549 for vm in vm_names:550 try:551 logger.info("Stopping all the NUMA instances")552 conn.stop_server(vm)553 logger.info("Server: %s has been stopped" % vm)554 except Exception as e:555 logger.info("Exception Occurred while stopping the instance")556 # Creating 11th Instance557 try:558 logger.info("Creaing 11th instance")559 os_server = create_numa_instance(conn, server_name='numa9_11', # noqa560 flavor_name=data["numa_flavor"], # noqa561 image_name=data["image_name"], # noqa562 network_name=data["net_name"], # noqa563 secgroup_name=data["sec_group_name"]) # noqa564 logger.info("Instance 11th is successfully created")565 except Exception as e:566 logger.info("Unable to create 11th Instance")567 logger.info("Test case 9 is successfully verified")568 logger.info("Now Cleaning up the resources for Test case 9")569 logger.info("Deleting all the numa instances")570 for vm in vm_names:571 conn.delete_server(vm)572 logger.info("Instance: %s is deleted" % vm)573 logger.info("Instances are successfully deleted")574 logger.info("Deleting NUMA Flavor")575 conn.delete_flavor(data["numa_flavor"])576 logger.info("Flavor is successfully deleted")577 except Exception as e:578 logger.info("Exception has occurred: Unable to Run Test Case 9")579 logger.info("Deleting all the numa instances")580 for vm in vm_names:581 ser = conn.get_server(vm)582 if ser is None:583 logger.info("Server doesn't exists")584 else:585 conn.delete_server(vm)586 logger.info("Instance: %s is deleted" % vm)587 logger.info("Deleting NUMA Flavor")588 flavor = conn.get_flavor(data["numa_flavor"])589 if flavor is None:590 logger.info("Flavor doesn't exists")591 else:592 conn.delete_flavor(data["numa_flavor"])593 logger.info("Flavor is deleted")594def test_case_10(conn):595 try:596 logger.info(" ")597 logger.info("##################################################")598 logger.info(" Executing Test Case 10 of NUMA ")599 logger.info("##################################################")600 logger.info(" ")601 logger.info("Creating two numa Flavors for test case 10")602 flavor_1 = 'numa_f1'603 flavor_2 = 'numa_f2'604 create_numa_flavor(conn, name=flavor_1,605 ram=4096, vcpus=4, disk=40)606 create_numa_flavor(conn, name=flavor_2,607 ram=4096, vcpus=8, disk=40)608 logger.info("Creaing an instance from First Flavor")609 os_server = create_numa_instance(conn, server_name='numa10_vm1', # noqa610 flavor_name=flavor_1, # noqa611 image_name=data["image_name"], # noqa612 network_name=data["net_name"], # noqa613 secgroup_name=data["sec_group_name"]) # noqa614 try:615 logger.info("Resizing Server to 2nd Flavor")616 conn.resize_server(server='numa10_vm1', flavor=flavor_2)617 logger.info("Server is successfully resized")618 except Exception as e:619 logger.info("Unable to resize a server")620 logger.info("Test case 10 is successfully verified")621 logger.info("Now Cleaning up the resources for Test case 10")622 logger.info("Deleting Server")623 conn.delete_server('numa10_vm1')624 logger.info("Server is Deleted")625 logger.info("Deleting NUMA Flavor")626 conn.delete_flavor('numa_f1')627 conn.delete_flavor('numa_f2')628 logger.info("Flavors are deleted")629 except Exception as e:630 logger.info("Unable to run Test case 10")631 logger.info("Deleting Instance")632 ser = conn.get_server('numa10_vm1')633 if ser is None:634 logger.info("Server doesn't Exists")635 else:636 conn.delete_server("numa10_vm1")637 logger.info("Deleting Flavors")638 f_1 = conn.get_flavor('numa_f1')639 if f_1 is None:640 logger.info("Flavor doesn't Exists")641 else:642 conn.delete_flavor('numa_f1')643 logger.info("Flavor is successfully deleted")644 f_2 = conn.get_flavor('numa_f2')645 if f_2 is None:646 logger.info("Flavor doesn't Exists")647 else:648 conn.delete_flavor('numa_f2')649 logger.info("Flavor is successfully deleted")650def test_case_11(conn):651 try:652 logger.info(" ")653 logger.info("##################################################")654 logger.info(" Executing Test Case 11 of NUMA ")655 logger.info("##################################################")656 logger.info(" ")657 logger.info("Creating Flavor for migarated Instance")658 create_numa_flavor(conn, name=data["numa_flavor"],659 ram=4096, vcpus=4, disk=40)660 logger.info("Now, Creating an Instance")661 os_server = create_numa_instance(conn, server_name='numa11_vm1', # noqa662 flavor_name=data["numa_flavor"], # noqa663 image_name=data["image_name"], # noqa664 network_name=data["net_name"], # noqa665 secgroup_name=data["sec_group_name"]) # noqa666 logger.info("Now migrating above created Server to another host")667 try:668 conn.live_migrate_server(server='numa11_vm1', host='r62-dell-compute-1.r62.nfv.lab') # noqa669 logger.info("Instance is successfully migrated to Zone: 'nova1'")670 except Exception as e:671 logger.info("Instance Migration is Failed")672 logger.info("Verification of Test Case 11 is Failed")673 logger.info("Now Cleaning up the resources for Test case 11")674 logger.info("Deleting Server")675 conn.delete_server('numa11_vm1')676 logger.info("Server is Deleted")677 logger.info("Deleting NUMA Flavor")678 conn.delete_flavor(data["numa_flavor"])679 logger.info("NUMA Flavor is deleted")680 except Exception as e:681 logger.info("Exception has occurred: Unable to Run Test Case 11")682 logger.info("Deleting Instance")683 ser = conn.get_server('numa11_vm1')684 if ser is None:685 logger.info("Server doesn't Exists")686 else:687 conn.delete_server("numa11_vm1")688 logger.info("Deleting Flavors")689 flavor = conn.get_flavor(data["numa_flavor"])690 if flavor is None:691 logger.info("Flavor doesn't Exists")692 else:693 conn.delete_flavor(data["numa_flavor"])694 logger.info("Flavor is successfully deleted")695# main function696def main():697 # Setting uo the enviornment on which Test Cases will run698 conn = create_connection("http://100.67.62.61:5000//v3", "admin",699 "admin",700 "6uJrRbyMVn7rc3RrnfeggbKe9", "Default")701 os_image = create_image_os(conn, image_name=data["image_name"],702 img_file="/home/osp_admin/usama/cirros-0.4.0-x86_64-disk.img") # noqa703 os_keypair = create_keypair_os(conn, name=data["pub_key"],704 file_name=data["pr_pem_key"])705 os_private_network = create_network_os(conn, net_name=data["net_name"],706 subnet_name=data["sub_name"],707 cidr=data["cidr"],...
test_flavors_rbac.py
Source:test_flavors_rbac.py
...58 @rbac_rule_validation.action(service="neutron",59 rules=["get_flavor",60 "delete_flavor"],61 expected_error_codes=[404, 403])62 def test_delete_flavor(self):63 """Delete flavor.64 RBAC test for the neutron "delete_flavor" policy65 """66 flavor = self.ntp_client.create_flavor(service_type=self.service_type)67 self.addCleanup(68 test_utils.call_and_ignore_notfound_exc,69 self.ntp_client.delete_flavor, flavor["flavor"]["id"])70 with self.override_role():71 self.ntp_client.delete_flavor(flavor["flavor"]["id"])72 @decorators.idempotent_id('c2baf35f-e6c1-4833-9114-aadd9b1f6aaa')73 @rbac_rule_validation.action(service="neutron",74 rules=["get_flavor"],75 expected_error_codes=[404])76 def test_show_flavor(self):77 """Show flavor.78 RBAC test for the neutron "get_flavor" policy79 """80 flavor = self.ntp_client.create_flavor(service_type=self.service_type)81 self.addCleanup(82 test_utils.call_and_ignore_notfound_exc,83 self.ntp_client.delete_flavor, flavor["flavor"]["id"])84 with self.override_role():85 self.ntp_client.show_flavor(flavor["flavor"]["id"])...
flavor.py
Source:flavor.py
1import kopf2import pykube3from open4k import utils4from open4k import kube5from open4k import client6from open4k import settings7from open4k import hooks8LOG = utils.get_logger(__name__)9kopf_on_args = ["open4k.amadev.ru", "v1alpha1", "flavors"]10class Flavor(pykube.objects.NamespacedAPIObject, kube.HelmBundleMixin):11 version = "open4k.amadev.ru/v1alpha1"12 endpoint = "flavors"13 kind = "Flavor"14 api = {15 "service": "compute",16 "objects": "flavors",17 "object": "flavor",18 "get_": "get_flavor",19 "list": "list_flavors",20 "create": "create_flavor",21 "delete": "delete_flavor",22 }23 @staticmethod24 def get_os_obj(c, obj_id, id_name=None):25 if not id_name:26 id_name = "flavor_id"27 os_obj = getattr(getattr(c, "flavors"), "get_flavor")(28 **{id_name: obj_id}29 )30 if {31 "service": "compute",32 "objects": "flavors",33 "object": "flavor",34 "get_": "get_flavor",35 "list": "list_flavors",36 "create": "create_flavor",37 "delete": "delete_flavor",38 }.get("object_envelope", True):39 os_obj = os_obj[list(os_obj)[0]]40 return os_obj41 def create_os_obj(c, body):42 os_obj = c.flavors.create_flavor(flavor=body)43 if {44 "service": "compute",45 "objects": "flavors",46 "object": "flavor",47 "get_": "get_flavor",48 "list": "list_flavors",49 "create": "create_flavor",50 "delete": "delete_flavor",51 }.get("object_envelope", True):52 os_obj = os_obj[list(os_obj)[0]]53 return os_obj54 def delete_os_obj(c, obj_id):55 getattr(getattr(c, "flavors"), "delete_flavor")(flavor_id=obj_id)56@kopf.on.create(*kopf_on_args)57@kopf.on.update(*kopf_on_args)58@kopf.on.resume(*kopf_on_args)59async def flavor_change_handler(body, name, namespace, **kwargs):60 LOG.info(f"Got Flavor change event {name}")61 if body["spec"].get("managed") == False:62 LOG.info(f"{name} is not managed")63 return64 c = client.get_client(65 settings.OPEN4K_NAMESPACE, body["spec"]["cloud"], "compute"66 )67 obj = kube.find(Flavor, name, namespace=namespace)68 klass = Flavor69 if body.get("status", {}).get("applied") == True:70 LOG.info(f"{name} exists, updating ...")71 obj_id = body["status"]["object"].get("id")72 id_name = None73 if not obj_id:74 id_name = "uuid"75 obj_id = body["status"]["object"].get("uuid")76 os_obj = klass.get_os_obj(c, obj_id, id_name)77 obj.patch(78 {"status": {"object": os_obj}},79 subresource="status",80 )81 return82 try:83 os_obj = klass.create_os_obj(c, body["spec"]["body"])84 except Exception as e:85 obj.patch(86 {"status": {"applied": False, "error": str(e)}},87 subresource="status",88 )89 raise90 obj.patch(91 {"status": {"applied": True, "error": "", "object": os_obj}},92 subresource="status",93 )94 await hooks.call("flavor", "post_create", c, klass, obj, os_obj)95@kopf.on.delete(*kopf_on_args)96async def flavor_delete_handler(body, name, namespace, **kwargs):97 LOG.info(f"Got Flavor delete event {name}")98 if body["spec"].get("managed") == False:99 LOG.info(f"{name} is not managed")100 return101 if not body.get("status", {}).get("applied"):102 LOG.info(f"{name} was not applied successfully")103 return104 klass = Flavor105 os_obj_id = body["status"].get("object", {}).get("id")106 if not os_obj_id:107 LOG.info(f"Cannot get id for {name}")108 return109 c = client.get_client(110 settings.OPEN4K_NAMESPACE, body["spec"]["cloud"], "compute"111 )...
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!!