cloudstack-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sanju1010 <...@git.apache.org>
Subject [GitHub] cloudstack pull request: CLOUDSTACK-8308:Adding automation testcas...
Date Mon, 28 Dec 2015 12:27:02 GMT
Github user sanju1010 commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/384#discussion_r48476586
  
    --- Diff: test/integration/testpaths/testpath_delta_snapshots.py ---
    @@ -0,0 +1,539 @@
    +# 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 (PASS, FAIL, BACKED_UP, ROOT, DATA)
    +import time
    +
    +
    +def checkIntegrityOfSnapshot(
    +        self, snapshotsToRestore, checksumToCompare, disk_type=ROOT):
    +    """
    +    Check integrity of snapshot created of ROOT or DATA Disk:
    +
    +    If ROOT Disk: Deploy a Vm from a template created from the snapshot
    +                  and checking the contents of the ROOT disk.
    +    If DATA Disk: Users can create a volume from the snapshot.
    +                  The volume can then be mounted to a VM and files
    +                  recovered as needed.
    +
    +    Inputs:
    +    1. snapshotsToRestore: Snapshots whose integrity is
    +                           to be checked.
    +
    +    2. checksumToCompare:  The contents of ROOT Disk to be compared.
    +
    +    3. disk_type:          The type of disk - ROOT or DATA Disk
    +                           of which snapshot was created.
    +
    +    """
    +    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"
    +        )
    +
    +        # 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"
    +        )
    +
    +        # 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__
    +        cls.skiptest = False
    +
    +        if cls.hypervisor.lower() not in ["xenserver"]:
    +            cls.skiptest = True
    +
    +        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):
    +        if self.skiptest:
    +            self.skipTest(
    +                "Delta snapshot not supported on %s" %
    +                self.hypervisor)
    +        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_01_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],
    +            PASS,
    +            "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)
    +            checksum_created.append(checksum_root)
    +
    +            # Step 2
    +            root_vol_snapshot = Snapshot.create(
    +                self.apiclient,
    +                root_volume.id)
    +
    +            self.snapshots_created.append(root_vol_snapshot)
    --- End diff --
    
    before appending, we need to initialize it as a list


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message