[ https://issues.apache.org/jira/browse/CLOUDSTACK-8308?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14593371#comment-14593371 ]
ASF GitHub Bot commented on CLOUDSTACK-8308: -------------------------------------------- Github user pritisarap12 commented on a diff in the pull request: https://github.com/apache/cloudstack/pull/384#discussion_r32823312 --- Diff: test/integration/testpaths/testpath_delta_snapshots.py --- @@ -0,0 +1,516 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +""" Test cases for Delta Snapshots Test Path +""" + +from nose.plugins.attrib import attr +from marvin.cloudstackTestCase import cloudstackTestCase +from marvin.lib.utils import (cleanup_resources, + validateList, + is_snapshot_on_nfs) +from marvin.lib.base import (Account, + ServiceOffering, + Template, + VirtualMachine, + Volume, + Configurations, + Snapshot + ) +from marvin.lib.common import (get_domain, + get_zone, + get_template, + list_volumes, + createChecksum, + compareChecksum + ) +from marvin.sshClient import SshClient +from marvin.codes import (FAIL) +import time + + +def checkIntegrityOfSnapshot( + self, snapshotsToRestore, checksumToCompare, disk_type="root"): + + if disk_type == "root": + # Create template from snapshot + template_from_snapshot = Template.create_from_snapshot( + self.apiclient, + snapshotsToRestore, + self.testdata["template_2"]) + + self.assertNotEqual( + template_from_snapshot, + None, + "Check if result exists in list item call" + ) + + time.sleep(60) + + # Deploy VM + vm_from_temp = VirtualMachine.create( + self.apiclient, + self.testdata["small"], + templateid=template_from_snapshot.id, + accountid=self.account.name, + domainid=self.account.domainid, + serviceofferingid=self.service_offering.id, + zoneid=self.zone.id, + mode=self.zone.networktype + ) + + self.assertNotEqual( + vm_from_temp, + None, + "Check if result exists in list item call" + ) + time.sleep(60) + # Verify contents of ROOT disk match with snapshot + + compareChecksum( + self.apiclient, + service=self.testdata, + original_checksum=checksumToCompare, + disk_type="rootdiskdevice", + virt_machine=vm_from_temp + ) + + vm_from_temp.delete(self.apiclient) + template_from_snapshot.delete(self.apiclient) + else: + volumeFormSnap = Volume.create_from_snapshot( + self.apiclient, + snapshotsToRestore.id, + self.testdata["volume"], + account=self.account.name, + domainid=self.account.domainid, + zoneid=self.zone.id + ) + + temp_vm = VirtualMachine.create( + self.apiclient, + self.testdata["small"], + templateid=self.template.id, + accountid=self.account.name, + domainid=self.account.domainid, + serviceofferingid=self.service_offering.id, + zoneid=self.zone.id, + mode=self.zone.networktype + ) + temp_vm.attach_volume( + self.apiclient, + volumeFormSnap + ) + + temp_vm.reboot(self.apiclient) + + compareChecksum( + self.apiclient, + self.testdata, + checksumToCompare, + "datadiskdevice_1", + temp_vm + ) + + temp_vm.delete(self.apiclient) + volumeFormSnap.delete(self.apiclient) + + return + + +class TestDeltaSnapshots(cloudstackTestCase): + + @classmethod + def setUpClass(cls): + testClient = super(TestDeltaSnapshots, cls).getClsTestClient() + cls.apiclient = testClient.getApiClient() + cls.testdata = testClient.getParsedTestDataConfig() + cls.hypervisor = cls.testClient.getHypervisorInfo() + + # Get Zone, Domain and templates + cls.domain = get_domain(cls.apiclient) + cls.zone = get_zone(cls.apiclient, testClient.getZoneForTests()) + + cls.template = get_template( + cls.apiclient, + cls.zone.id, + cls.testdata["ostype"]) + + cls.snapshots_created = [] + cls._cleanup = [] + + cls.mgtSvrDetails = cls.config.__dict__["mgtSvr"][0].__dict__ + + try: + + # Create an account + cls.account = Account.create( + cls.apiclient, + cls.testdata["account"], + domainid=cls.domain.id + ) + cls._cleanup.append(cls.account) + + # Create user api client of the account + cls.userapiclient = testClient.getUserApiClient( + UserName=cls.account.name, + DomainName=cls.account.domain + ) + + # Create Service offering + cls.service_offering = ServiceOffering.create( + cls.apiclient, + cls.testdata["service_offering"], + ) + cls._cleanup.append(cls.service_offering) + + if cls.testdata["configurableData"][ + "restartManagementServerThroughTestCase"]: + # Set snapshot delta max value + Configurations.update(cls.apiclient, + name="snapshot.delta.max", + value="3" + ) + + # Restart management server + cls.RestartServer() + time.sleep(120) + + configs = Configurations.list( + cls.apiclient, + name="snapshot.delta.max") + cls.delta_max = configs[0].value + + cls.vm = VirtualMachine.create( + cls.apiclient, + cls.testdata["small"], + templateid=cls.template.id, + accountid=cls.account.name, + domainid=cls.account.domainid, + serviceofferingid=cls.service_offering.id, + zoneid=cls.zone.id, + mode=cls.zone.networktype + ) + + except Exception as e: + cls.tearDownClass() + raise e + return + + @classmethod + def tearDownClass(cls): + try: + cleanup_resources(cls.apiclient, cls._cleanup) + except Exception as e: + raise Exception("Warning: Exception during cleanup : %s" % e) + + def setUp(self): + self.apiclient = self.testClient.getApiClient() + self.dbclient = self.testClient.getDbConnection() + self.cleanup = [] + + def tearDown(self): + try: + for snapshot in self.snapshots_created: + snapshot.delete(self.apiclient) + cleanup_resources(self.apiclient, self.cleanup) + except Exception as e: + raise Exception("Warning: Exception during cleanup : %s" % e) + return + + @classmethod + def RestartServer(cls): + """Restart management server""" + + sshClient = SshClient( + cls.mgtSvrDetails["mgtSvrIp"], + 22, + cls.mgtSvrDetails["user"], + cls.mgtSvrDetails["passwd"] + ) + command = "service cloudstack-management restart" + sshClient.execute(command) + + return + + @attr(tags=["advanced", "basic"], required_hardware="true") + def test_02_delta_snapshots(self): + """ Delta Snapshots + 1. Create file on ROOT disk of deployed VM. + 2. Create Snapshot of ROOT disk. + 3. Verify secondary storage count. + 4. Check integrity of Full Snapshot. + 5. Delete delta snaphshot and check integrity of\ + remaining snapshots. + 6. Delete full snapshot and verify it is deleted from\ + secondary storage. + """ + + checksum_created = [] + full_snapshot_count = 0 + delta_snapshot_count = 0 + + # Mulitply delta max value by 2 to set loop counter + # to create 2 Snapshot chains + snapshot_loop_count = int(self.delta_max) * 2 + + # Get ROOT Volume + root_volumes_list = list_volumes( + self.apiclient, + virtualmachineid=self.vm.id, + type='ROOT', + listall=True + ) + + status = validateList(root_volumes_list) + self.assertEqual( + status[0], + FAIL, + "Check listVolumes response for ROOT Disk") + + root_volume = root_volumes_list[0] + + # Get Secondary Storage Value from Database + qryresult_before_snapshot = self.dbclient.execute( + " select id, account_name, secondaryStorageTotal\ + from account_view where account_name = '%s';" % + self.account.name) + + self.assertNotEqual( + len(qryresult_before_snapshot), + 0, + "Check sql query to return SecondaryStorageTotal of account") + + storage_qry_result_old = qryresult_before_snapshot[0] + secondary_storage_old = storage_qry_result_old[2] + + # Create Snapshots + + for i in range(snapshot_loop_count): + + # Step 1 + checksum_root = createChecksum( + self.testdata, + self.vm, + root_volume, + "rootdiskdevice") + + time.sleep(30) --- End diff -- Checksum is appended in a list immediately after creating it, and that checksum is used later to check integrity of snapshots. Since it takes a few seconds to create checksum, sleep is added. If sleep is not added, the integrity fails. > Add test cases for volume/VM snapshot test path > ----------------------------------------------- > > Key: CLOUDSTACK-8308 > URL: https://issues.apache.org/jira/browse/CLOUDSTACK-8308 > Project: CloudStack > Issue Type: Test > Security Level: Public(Anyone can view this level - this is the > default.) > Affects Versions: Future > Reporter: Priti Sarap > Labels: automation > Fix For: Future > > > Add test cases for volume/VM snapshot test path -- This message was sent by Atlassian JIRA (v6.3.4#6332)