How to use test01 method in green

Best Python code snippet using green

testcase_03_clouddisk.py

Source:testcase_03_clouddisk.py Github

copy

Full Screen

1import time2import sys3import os4import re5from avocado import Test6REALPATH = os.path.split(os.path.realpath(__file__))[0]7sys.path.append(os.path.join(os.path.dirname(REALPATH)))8from api.setup import Setup9class CloudDiskTest(Test):10 def setUp(self):11 self.cloud_disk_limit = 1612 prep = Setup(self.params)13 prep.selected_case(self.name)14 self.project = prep.project15 self.vm_test01 = prep.vm_test0116 self.vm_params = prep.vm_params17 args = []18 if "offline" in self.name.name:19 args.append("pre-stop")20 if "ecs.i" in self.vm_params["InstanceType"] or "ecs.d" in self.vm_params["InstanceType"]:21 self.disk_count = self.params.get('disk_count', '*/{0}/*'.format(self.vm_params["InstanceType"]))22 else:23 self.disk_count = 024 prep.vm_prepare(args)25 prep.disk_prepare(disk_count=self.cloud_disk_limit)26 def test_online_attach_cloud_disks(self):27 self.log.info("Online attach a cloud disk to VM")28 for disk_id in self.vm_params.get("AttachDiskIds"):29 self.vm_test01.attach_disk(diskid=disk_id)30 while True:31 output = self.vm_test01.describe_disks(self.vm_params, diskid=disk_id.encode("ascii"))32 status = output.get("Disks").get("Disk")[0].get("Status")33 if status == u"In_use":34 break35 else:36 time.sleep(1)37 for i in xrange(1, self.cloud_disk_limit + 1):38 delta = self.disk_count + i39 if delta <= 25:40 idx = chr(97 + delta)41 else:42 idx = 'a' + chr(97 - 1 + delta % 25)43 cmd = "fdisk -l /dev/vd%s | grep '/dev/vd%s' | cut -d ',' -f 1 | cut -d ' ' -f 4"44 output = self.vm_test01.get_output(cmd % (idx, idx))45 self.assertEqual(output, "GB",46 "Attach disk size is not as expected.\n {0}".format(output))47 cmd = "fdisk -l /dev/vd%s | grep '/dev/vd%s' | cut -d ',' -f 1 | cut -d ' ' -f 3"48 output = self.vm_test01.get_output(cmd % (idx, idx))49 self.assertTrue(22 > float(output) >= 20,50 "Attach disk size is not as expected.\n {0}".format(output))51 cmd = "[[ -d /mnt/vd%s ]] || mkdir /mnt/vd%s"52 self.vm_test01.get_output(cmd % (idx, idx))53 cmd = "mkfs.ext4 /dev/vd%s && mount /dev/vd%s /mnt/vd%s && echo 'test_content' > /mnt/vd%s/test_file"54 self.vm_test01.get_output(cmd % (idx, idx, idx, idx))55 cmd = "cat /mnt/vd%s/test_file"56 output = self.vm_test01.get_output(cmd % idx)57 self.assertEqual(output, "test_content",58 "Cannot write files on attached disk.\n {0}".format(output))59 cmd = "umount /mnt/vd%s"60 self.vm_test01.get_output(cmd % idx)61 def test_online_detach_cloud_disks(self):62 self.log.info("Online detach a cloud disk to VM")63 for disk_id in self.vm_params.get("AttachDiskIds"):64 self.vm_test01.detach_disk(diskid=disk_id)65 while True:66 output = self.vm_test01.describe_disks(self.vm_params, diskid=disk_id.encode("ascii"))67 status = output.get("Disks").get("Disk")[0].get("Status")68 if status == u"Available":69 break70 else:71 time.sleep(1)72 for i in xrange(1, self.cloud_disk_limit + 1):73 delta = self.disk_count + i74 if delta <= 25:75 idx = chr(97 + delta)76 else:77 idx = 'a' + chr(97 - 1 + delta % 25)78 cmd = "fdisk -l | grep '/dev/vd%s'"79 output = self.vm_test01.get_output(cmd % idx)80 self.assertEqual(output, "",81 "Disk not detached.\n {0}".format(output))82 def test_offline_attach_cloud_disks(self):83 self.log.info("Offline attach a cloud disk to VM")84 for disk_id in self.vm_params.get("AttachDiskIds"):85 self.vm_test01.attach_disk(diskid=disk_id)86 while True:87 output = self.vm_test01.describe_disks(self.vm_params, diskid=disk_id.encode("ascii"))88 status = output.get("Disks").get("Disk")[0].get("Status")89 if status == u"In_use":90 break91 else:92 time.sleep(1)93 self.vm_test01.start()94 self.vm_test01.wait_for_running()95 self.assertTrue(self.vm_test01.wait_for_login(),96 "Fail to ssh login after offline attach disks")97 for i in xrange(1, self.cloud_disk_limit + 1):98 delta = self.disk_count + i99 if delta <= 25:100 idx = chr(97 + delta)101 else:102 idx = 'a' + chr(97 - 1 + delta % 25)103 cmd = "fdisk -l /dev/vd%s | grep '/dev/vd%s' | cut -d ',' -f 1 | cut -d ' ' -f 4"104 output = self.vm_test01.get_output(cmd % (idx, idx))105 self.assertEqual(output, "GB",106 "Attach disk size is not as expected.\n {0}".format(output))107 cmd = "fdisk -l /dev/vd%s | grep '/dev/vd%s' | cut -d ',' -f 1 | cut -d ' ' -f 3"108 output = self.vm_test01.get_output(cmd % (idx, idx))109 self.assertTrue(22 > float(output) >= 20,110 "Attach disk size is not as expected.\n {0}".format(output))111 cmd = "[[ -d /mnt/vd%s ]] || mkdir /mnt/vd%s"112 self.vm_test01.get_output(cmd % (idx, idx))113 cmd = "mkfs.ext4 /dev/vd%s && mount /dev/vd%s /mnt/vd%s && echo 'test_content' > /mnt/vd%s/test_file"114 self.vm_test01.get_output(cmd % (idx, idx, idx, idx))115 cmd = "cat /mnt/vd%s/test_file"116 output = self.vm_test01.get_output(cmd % idx)117 self.assertEqual(output, "test_content",118 "Cannot write files on attached disk.\n {0}".format(output))119 cmd = "umount /mnt/vd%s"120 self.vm_test01.get_output(cmd % idx)121 def test_offline_detach_cloud_disks(self):122 self.log.info("Offline detach a cloud disk to VM")123 for disk_id in self.vm_params.get("AttachDiskIds"):124 self.vm_test01.detach_disk(diskid=disk_id)125 while True:126 output = self.vm_test01.describe_disks(self.vm_params, diskid=disk_id.encode("ascii"))127 status = output.get("Disks").get("Disk")[0].get("Status")128 if status == u"Available":129 break130 else:131 time.sleep(1)132 self.vm_test01.start()133 self.vm_test01.wait_for_running()134 self.assertTrue(self.vm_test01.wait_for_login(),135 "Fail to ssh login after offline attach disks")136 for i in xrange(1, self.cloud_disk_limit + 1):137 delta = self.disk_count + i138 if delta <= 25:139 idx = chr(97 + delta)140 else:141 idx = 'a' + chr(97 - 1 + delta % 25)142 cmd = "fdisk -l | grep '/dev/vd%s'"143 output = self.vm_test01.get_output(cmd % idx)144 self.assertEqual(output, "",145 "Disk not detached.\n {0}".format(output))146 def tearDown(self):...

Full Screen

Full Screen

testcase_01_lifecycle.py

Source:testcase_01_lifecycle.py Github

copy

Full Screen

1import time2import sys3import os4import re5from avocado import Test6REALPATH = os.path.split(os.path.realpath(__file__))[0]7sys.path.append(os.path.join(os.path.dirname(REALPATH)))8from api.setup import Setup9class LifeCycleTest(Test):10 def setUp(self):11 prep = Setup(self.params)12 prep.selected_case(self.name)13 self.project = prep.project14 self.vm_test01 = prep.vm_test0115 self.vm_params = prep.vm_params16 args = []17 if "password" in self.name.name:18 args.append("password")19 if "create_ecs" in self.name.name:20 args.append("pre-delete")21 if "test_start_ecs" in self.name.name or \22 "test_modify_instance_type" in self.name.name:23 args.append("pre-stop")24 prep.vm_prepare(args)25 def test_password_create_ecs(self):26 self.log.info("Create ECS with password")27 self.vm_test01.create(self.vm_params, authentication="password")28 self.vm_test01.wait_for_created()29 self.vm_test01.allocate_public_address()30 self.assertIsNotNone(self.vm_test01.get_public_address(),31 "Fail to allocate public ip address")32 def test_password_start_ecs(self):33 self.log.info("Start ECS")34 self.vm_test01.start()35 self.vm_test01.wait_for_running()36 self.assertTrue(self.vm_test01.wait_for_login(authentication="password"),37 "Fail to ssh login")38 def test_reset_password_ecs(self):39 self.log.info("Reset password for ECS")40 self.vm_test01.reset_password(new_password="Redhat123$")41 self.vm_test01.password="Redhat123$"42 self.vm_params["Password"]="Redhat123$"43 self.vm_test01.restart()44 self.vm_test01.wait_for_running()45 self.assertTrue(self.vm_test01.wait_for_login(authentication="password"),46 "Fail to ssh login")47 def test_create_ecs(self):48 self.log.info("Create ECS with keypair")49 self.vm_test01.create(self.vm_params)50 self.vm_test01.wait_for_created()51 self.vm_test01.allocate_public_address()52 self.assertIsNotNone(self.vm_test01.get_public_address(),53 "Fail to allocate public ip address")54 def test_start_ecs(self):55 self.log.info("Start ECS")56 self.vm_test01.start()57 self.vm_test01.wait_for_running()58 self.assertTrue(self.vm_test01.wait_for_login(),59 "Fail to ssh login")60 def test_stop_ecs(self):61 """62 Stop ECS63 1. Stop ECS64 2. Force stop ECS65 """66 self.log.info("Stop ECS")67 self.log.info("1. Stop ECS")68 self.vm_test01.stop()69 self.vm_test01.wait_for_stopped()70 self.assertFalse(self.vm_test01.wait_for_login(timeout=10),71 "Should not be able to login when ECS is stopped")72 # Recovery: Start VM73 self.vm_test01.start()74 self.vm_test01.wait_for_running()75 self.vm_test01.wait_for_login()76 self.log.info("2. Force stop ECS")77 self.vm_test01.stop(force=True)78 self.vm_test01.wait_for_stopped()79 self.assertFalse(self.vm_test01.wait_for_login(timeout=10),80 "Should not be able to login when ECS is force stopped")81 def test_restart_ecs(self):82 """83 Restart ECS84 1. Restart ECS85 2. Force restart ECS86 """87 self.log.info("Restart ECS")88 self.log.info("1. Restart ECS")89 self.vm_test01.wait_for_login()90 before = self.vm_test01.get_output("who -b")91 time.sleep(60)92 self.vm_test01.restart()93 self.vm_test01.wait_for_running()94 self.vm_test01.wait_for_login()95 after = self.vm_test01.get_output("who -b")96 self.assertNotEqual(before, after,97 "Restart error: ECS is not restarted")98 self.log.info("2. Force restart ECS")99 before = after100 time.sleep(60)101 self.vm_test01.restart(force=True)102 self.vm_test01.wait_for_running()103 self.vm_test01.wait_for_login()104 after = self.vm_test01.get_output("who -b")105 self.assertNotEqual(before, after,106 "Force restart error: ECS is not restarted")107 def test_reboot_inside_vm(self):108 self.log.info("Reboot inside VM")109 self.vm_test01.wait_for_login()110 before = self.vm_test01.get_output("who -b")111 time.sleep(60)112 self.vm_test01.send_line("reboot")113 self.vm_test01.wait_for_running()114 self.vm_test01.wait_for_login()115 after = self.vm_test01.get_output("who -b")116 self.assertNotEqual(before, after,117 "Restart error: ECS is not restarted")118 def test_modify_instance_type(self):119 self.log.info("Modify ECS instance type")120 self.vm_test01.modify_instance_type(new_type="ecs.n1.medium")121 self.vm_test01.start()122 self.vm_test01.wait_for_running()123 self.vm_test01.wait_for_login()124 cpu = self.vm_test01.get_output("cat /proc/cpuinfo|grep processor|wc -l")125 memory = self.vm_test01.get_output("cat /proc/meminfo|grep MemTotal")126 cpu_std = self.params.get("cpu")127 def test_delete_ecs(self):128 self.log.info("Delete ECS")129 self.vm_test01.delete()130 self.vm_test01.wait_for_deleted()131 def tearDown(self):...

Full Screen

Full Screen

function01.py

Source:function01.py Github

copy

Full Screen

1#测试函数的定义和调用2def test01():3 print("*"*10)4 print("@"*10)5print(id(test01))6print(type(test01))7print(test01)8test01()9test01()10test01()11for i in range(10): ...

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run green automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful