cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gau...@apache.org
Subject [1/2] git commit: updated refs/heads/master to 628dde7
Date Tue, 05 May 2015 15:14:31 GMT
Repository: cloudstack
Updated Branches:
  refs/heads/master a380be608 -> 628dde7fd


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/628dde7f/test/integration/testpaths/testpath_volume_recurring_snap.py
----------------------------------------------------------------------
diff --git a/test/integration/testpaths/testpath_volume_recurring_snap.py b/test/integration/testpaths/testpath_volume_recurring_snap.py
new file mode 100644
index 0000000..23e0b3a
--- /dev/null
+++ b/test/integration/testpaths/testpath_volume_recurring_snap.py
@@ -0,0 +1,1043 @@
+# 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 VM/Volume recurring snapshot Test Path
+"""
+from nose.plugins.attrib import attr
+from marvin.cloudstackTestCase import cloudstackTestCase, unittest
+from marvin.lib.utils import (cleanup_resources,
+                              is_snapshot_on_nfs,
+                              validateList
+                              )
+from marvin.lib.base import (Account,
+                             ServiceOffering,
+                             DiskOffering,
+                             VirtualMachine,
+                             SnapshotPolicy,
+                             Snapshot,
+                             Configurations
+                             )
+from marvin.lib.common import (get_domain,
+                               get_zone,
+                               get_template,
+                               list_volumes,
+                               list_snapshots,
+                               list_snapshot_policy
+                               )
+
+from marvin.codes import PASS
+
+import time
+
+
+class TestVolumeRecurringSnapshot(cloudstackTestCase):
+
+    @classmethod
+    def setUpClass(cls):
+        testClient = super(TestVolumeRecurringSnapshot, 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._cleanup = []
+
+        if cls.hypervisor.lower() not in [
+                "vmware",
+                "kvm",
+                "xenserver"]:
+            raise unittest.SkipTest(
+                "Storage migration not supported on %s" %
+                cls.hypervisor)
+
+        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)
+            # Create Disk offering
+            cls.disk_offering = DiskOffering.create(
+                cls.apiclient,
+                cls.testdata["disk_offering"],
+            )
+            cls._cleanup.append(cls.disk_offering)
+            # Deploy A VM
+            cls.vm_1 = VirtualMachine.create(
+                cls.userapiclient,
+                cls.testdata["small"],
+                templateid=cls.template.id,
+                accountid=cls.account.name,
+                domainid=cls.account.domainid,
+                serviceofferingid=cls.service_offering.id,
+                zoneid=cls.zone.id,
+                diskofferingid=cls.disk_offering.id,
+                mode=cls.zone.networktype
+            )
+
+            cls.volume = list_volumes(
+                cls.apiclient,
+                virtualmachineid=cls.vm_1.id,
+                type='ROOT',
+                listall=True
+            )
+
+            cls.data_volume = list_volumes(
+                cls.apiclient,
+                virtualmachineid=cls.vm_1.id,
+                type='DATADISK',
+                listall=True
+            )
+
+        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:
+            cleanup_resources(self.apiclient, self.cleanup)
+        except Exception as e:
+            raise Exception("Warning: Exception during cleanup : %s" % e)
+        return
+
+    @attr(tags=["advanced", "basic"],required_hardware="true")
+    def test_01_volume_snapshot(self):
+        """ Test Volume (root) Snapshot
+        # 1. Create Hourly, Daily,Weekly recurring snapshot policy for ROOT disk and 
+                    Verify the presence of the corresponding snapshots on the Secondary Storage
+        # 2. Delete the snapshot policy and verify the entry as Destroyed in snapshot_schedule
+        # 3. Verify that maxsnaps should not consider manual snapshots for deletion
+        # 4. Snapshot policy should reflect the correct timezone
+        # 5. Verify that listSnapshotPolicies() should return all snapshot policies
+                that belong to the account (both manual and recurring snapshots)
+        # 6. Verify that listSnapshotPolicies() should not return snapshot 
+                policies that have been deleted
+        # 7. Verify that snapshot should not be created for VM in Destroyed state
+        # 8. Verify that snapshot should get created after resuming the VM
+        # 9. Verify that All the recurring policies associated with the VM should be 
+                deleted after VM get destroyed.
+        """
+        # Step 1
+        self.testdata["recurring_snapshot"]["intervaltype"] = 'HOURLY'
+
+        recurring_snapshot = SnapshotPolicy.create(
+            self.apiclient,
+            self.volume[0].id,
+            self.testdata["recurring_snapshot"]
+        )
+        # ListSnapshotPolicy should return newly created policy
+        list_snapshots_policy = list_snapshot_policy(
+            self.apiclient,
+            id=recurring_snapshot.id,
+            volumeid=self.volume[0].id
+        )
+        list_validation = validateList(list_snapshots_policy)
+
+        self.assertEqual(
+            list_validation[0],
+            PASS,
+            "snapshot list validation failed due to %s" %
+            list_validation[2])
+
+        timeout = self.testdata["timeout"]
+        while True:
+            snapshots = list_snapshots(
+                self.apiclient,
+                volumeid=self.volume[0].id,
+                intervaltype=self.testdata[
+                    "recurring_snapshot"]["intervaltype"],
+                snapshottype='RECURRING',
+                listall=True
+            )
+
+            if isinstance(snapshots, list):
+                break
+
+            elif timeout == 0:
+                raise Exception("List snapshots API call failed.")
+
+        for snapshot in snapshots:
+            self.assertEqual(
+                self.dbclient.execute(
+                    "select type_description from snapshots where name='%s'" %
+                    snapshot.name)[0][0],
+                "HOURLY"
+            )
+
+        time.sleep(180)
+
+        for snapshot in snapshots:
+            self.assertTrue(
+                is_snapshot_on_nfs(
+                    self.apiclient,
+                    self.dbclient,
+                    self.config,
+                    self.zone.id,
+                    snapshot.id))
+
+        recurring_snapshot.delete(self.apiclient)
+
+        self.assertEqual(
+            self.dbclient.execute(
+                "select * from snapshot_policy where uuid='%s'" %
+                recurring_snapshot.id),
+            []
+        )
+
+        self.testdata["recurring_snapshot"]["intervaltype"] = 'DAILY'
+        self.testdata["recurring_snapshot"]["schedule"] = '00:00'
+        recurring_snapshot_daily = SnapshotPolicy.create(
+            self.apiclient,
+            self.volume[0].id,
+            self.testdata["recurring_snapshot"]
+        )
+
+        list_snapshots_policy_daily = list_snapshot_policy(
+            self.apiclient,
+            id=recurring_snapshot_daily.id,
+            volumeid=self.volume[0].id
+        )
+
+        list_validation = validateList(list_snapshots_policy_daily)
+
+        self.assertEqual(
+            list_validation[0],
+            PASS,
+            "snapshot list validation failed due to %s" %
+            list_validation[2])
+
+        snap_db_daily = self.dbclient.execute(
+            "select * from snapshot_policy where uuid='%s'" %
+            recurring_snapshot_daily.id)
+
+        validation_result_1 = validateList(snap_db_daily)
+
+        self.assertEqual(
+            validation_result_1[0],
+            PASS,
+            "snapshot_policy list validation failed due to %s" %
+            validation_result_1[2])
+
+        self.assertNotEqual(
+            len(snap_db_daily),
+            0,
+            "Check DB Query result set"
+        )
+
+        recurring_snapshot_daily.delete(self.apiclient)
+
+        self.assertEqual(
+            self.dbclient.execute(
+                "select * from snapshot_policy where uuid='%s'" %
+                recurring_snapshot_daily.id),
+            []
+        )
+    
+        self.testdata["recurring_snapshot"]["intervaltype"] = 'WEEKLY'
+        self.testdata["recurring_snapshot"]["schedule"] = '00:00:1'
+        recurring_snapshot_weekly = SnapshotPolicy.create(
+            self.apiclient,
+            self.volume[0].id,
+            self.testdata["recurring_snapshot"]
+        )
+
+        list_snapshots_policy_weekly = list_snapshot_policy(
+            self.apiclient,
+            id=recurring_snapshot_weekly.id,
+            volumeid=self.volume[0].id
+        )
+
+        list_validation = validateList(list_snapshots_policy_weekly)
+
+        self.assertEqual(
+            list_validation[0],
+            PASS,
+            "snapshot list validation failed due to %s" %
+            list_validation[2])
+
+        snap_sch_2 = self.dbclient.execute(
+            "select * from snapshot_policy where uuid='%s'" %
+            recurring_snapshot_weekly.id)
+
+        validation_result_2 = validateList(snap_sch_2)
+
+        self.assertEqual(
+            validation_result_2[0],
+            PASS,
+            "snapshot_policy list validation failed due to %s" %
+            validation_result_2[2])
+
+        self.assertNotEqual(
+            len(snap_sch_2),
+            0,
+            "Check DB Query result set"
+        )
+
+        recurring_snapshot_weekly.delete(self.apiclient)
+
+        self.assertEqual(
+            self.dbclient.execute(
+                "select * from snapshot_policy where uuid='%s'" %
+                recurring_snapshot_weekly.id),
+            []
+        )
+
+        self.testdata["recurring_snapshot"]["intervaltype"] = 'MONTHLY'
+        self.testdata["recurring_snapshot"]["schedule"] = '00:00:1'
+        recurring_snapshot_monthly = SnapshotPolicy.create(
+            self.apiclient,
+            self.volume[0].id,
+            self.testdata["recurring_snapshot"]
+        )
+
+        list_snapshots_policy_monthly = list_snapshot_policy(
+            self.apiclient,
+            id=recurring_snapshot_monthly.id,
+            volumeid=self.volume[0].id
+        )
+
+        list_validation = validateList(list_snapshots_policy_monthly)
+
+        self.assertEqual(
+            list_validation[0],
+            PASS,
+            "snapshot list validation failed due to %s" %
+            list_validation[2])
+
+        snap_sch_3 = self.dbclient.execute(
+            "select * from snapshot_policy where uuid='%s'" %
+            recurring_snapshot_monthly.id)
+
+        validation_result = validateList(snap_sch_3)
+
+        self.assertEqual(
+            validation_result[0],
+            PASS,
+            "snapshot_policy list validation failed due to %s" %
+            validation_result[2])
+
+        self.assertNotEqual(
+            len(snap_sch_3),
+            0,
+            "Check DB Query result set"
+        )
+
+        recurring_snapshot_monthly.delete(self.apiclient)
+
+        self.assertEqual(
+            self.dbclient.execute(
+                "select * from snapshot_policy where uuid='%s'" %
+                recurring_snapshot_weekly.id),
+            []
+        )
+
+        snapshots = list_snapshots(
+            self.apiclient,
+            volumeid=self.volume[0].id,
+            intervaltype=self.testdata["recurring_snapshot"]["intervaltype"],
+            snapshottype='RECURRING',
+            listall=True
+        )
+
+        # Step 3
+        self.testdata["recurring_snapshot"]["intervaltype"] = 'HOURLY'
+        self.testdata["recurring_snapshot"]["schedule"] = 1
+        recurring_snapshot_1 = SnapshotPolicy.create(
+            self.apiclient,
+            self.volume[0].id,
+            self.testdata["recurring_snapshot"]
+        )
+        # ListSnapshotPolicy should return newly created policy
+        list_snapshots_policy = list_snapshot_policy(
+            self.apiclient,
+            id=recurring_snapshot_1.id,
+            volumeid=self.volume[0].id
+        )
+        list_validation = validateList(list_snapshots_policy)
+
+        self.assertEqual(
+            list_validation[0],
+            PASS,
+            "snapshot list validation failed due to %s" %
+            list_validation[2])
+
+        timeout = self.testdata["timeout"]
+        while True:
+            snapshots = list_snapshots(
+                self.apiclient,
+                volumeid=self.volume[0].id,
+                intervaltype=self.testdata[
+                    "recurring_snapshot"]["intervaltype"],
+                snapshottype='RECURRING',
+                listall=True
+            )
+
+            if isinstance(snapshots, list):
+                break
+
+            elif timeout == 0:
+                raise Exception("List snapshots API call failed.")
+
+        snap_to_delete = snapshots[0]
+
+        time.sleep(
+            (self.testdata["recurring_snapshot"]["maxsnaps"]) * 3600
+        )
+
+        snapshots_1 = list_snapshots(
+            self.apiclient,
+            volumeid=self.volume[0].id,
+            intervaltype=self.testdata["recurring_snapshot"]["intervaltype"],
+            snapshottype='RECURRING',
+            listall=True
+        )
+
+        self.assertTrue(snap_to_delete not in snapshots_1)
+
+        time.sleep(360)
+
+        self.assertEqual(
+            self.dbclient.execute(
+                "select status  from snapshots where uuid='%s'" %
+                snap_to_delete.id)[0][0],
+            "Destroyed"
+        )
+
+        self.assertFalse(
+            is_snapshot_on_nfs(
+                self.apiclient,
+                self.dbclient,
+                self.config,
+                self.zone.id,
+                snap_to_delete.id))
+
+        # Step 4
+        recurring_snapshot = SnapshotPolicy.create(
+            self.apiclient,
+            self.volume[0].id,
+            self.testdata["recurring_snapshot"]
+        )
+        # ListSnapshotPolicy should return newly created policy
+        list_snapshots_policy = list_snapshot_policy(
+            self.apiclient,
+            id=recurring_snapshot.id,
+            volumeid=self.volume[0].id
+        )
+        list_validation = validateList(list_snapshots_policy)
+
+        self.assertEqual(
+            list_validation[0],
+            PASS,
+            "snapshot list validation failed due to %s" %
+            list_validation[2])
+
+        time.sleep(180)
+        snap_time_hourly = self.dbclient.execute(
+            "select scheduled_timestamp from \
+            snapshot_schedule where uuid='%s'" %
+            recurring_snapshot.id)
+
+        self.debug("Timestamp for hourly snapshot %s" % snap_time_hourly)
+        recurring_snapshot.delete(self.apiclient)
+
+        self.testdata["recurring_snapshot"]["intervaltype"] = 'DAILY'
+        self.testdata["recurring_snapshot"]["schedule"] = '00:00'
+        recurring_snapshot_daily = SnapshotPolicy.create(
+            self.apiclient,
+            self.volume[0].id,
+            self.testdata["recurring_snapshot"]
+        )
+
+        list_snapshots_policy_daily = list_snapshot_policy(
+            self.apiclient,
+            id=recurring_snapshot_daily.id,
+            volumeid=self.volume[0].id
+        )
+
+        list_validation = validateList(list_snapshots_policy_daily)
+
+        self.assertEqual(
+            list_validation[0],
+            PASS,
+            "snapshot list validation failed due to %s" %
+            list_validation[2])
+
+        time.sleep(180)
+        snap_time_daily = self.dbclient.execute(
+            "select scheduled_timestamp from \
+                    snapshot_schedule where uuid='%s'" %
+            recurring_snapshot_daily.id)
+
+        self.debug("Timestamp for daily snapshot %s" % snap_time_daily)
+        recurring_snapshot_daily.delete(self.apiclient)
+
+        self.testdata["recurring_snapshot"]["intervaltype"] = 'WEEKLY'
+        self.testdata["recurring_snapshot"]["schedule"] = '00:00:1'
+        recurring_snapshot_weekly = SnapshotPolicy.create(
+            self.apiclient,
+            self.volume[0].id,
+            self.testdata["recurring_snapshot"]
+        )
+
+        list_snapshots_policy_weekly = list_snapshot_policy(
+            self.apiclient,
+            id=recurring_snapshot_weekly.id,
+            volumeid=self.volume[0].id
+        )
+
+        list_validation = validateList(list_snapshots_policy_weekly)
+
+        self.assertEqual(
+            list_validation[0],
+            PASS,
+            "snapshot list validation failed due to %s" %
+            list_validation[2])
+
+        time.sleep(180)
+        snap_time_weekly = self.dbclient.execute(
+            "select scheduled_timestamp from \
+                    snapshot_schedule where uuid='%s'" %
+            recurring_snapshot_weekly.id)
+
+        self.debug("Timestamp for monthly snapshot %s" % snap_time_weekly)
+        recurring_snapshot_weekly.delete(self.apiclient)
+
+        self.testdata["recurring_snapshot"]["intervaltype"] = 'MONTHLY'
+        self.testdata["recurring_snapshot"]["schedule"] = '00:00:1'
+        recurring_snapshot_monthly = SnapshotPolicy.create(
+            self.apiclient,
+            self.volume[0].id,
+            self.testdata["recurring_snapshot"]
+        )
+
+        list_snapshots_policy_monthly = list_snapshot_policy(
+            self.apiclient,
+            id=recurring_snapshot_monthly.id,
+            volumeid=self.volume[0].id
+        )
+
+        list_validation = validateList(list_snapshots_policy_monthly)
+
+        self.assertEqual(
+            list_validation[0],
+            PASS,
+            "snapshot list validation failed due to %s" %
+            list_validation[2])
+
+        time.sleep(180)
+        snap_time_monthly = self.dbclient.execute(
+            "select scheduled_timestamp from \
+                    snapshot_schedule where uuid='%s'" %
+            recurring_snapshot_monthly.id)
+
+        self.debug("Timestamp for monthly snapshot %s" % snap_time_monthly)
+
+        recurring_snapshot_monthly.delete(self.apiclient)
+
+        # Step 5
+        self.testdata["recurring_snapshot"]["intervaltype"] = 'HOURLY'
+        self.testdata["recurring_snapshot"]["schedule"] = 1
+        recurring_snapshot_hourly = SnapshotPolicy.create(
+            self.apiclient,
+            self.volume[0].id,
+            self.testdata["recurring_snapshot"]
+        )
+        self.testdata["recurring_snapshot"]["intervaltype"] = 'MONTHLY'
+        self.testdata["recurring_snapshot"]["schedule"] = '00:00:1'
+        recurring_snapshot_monthly = SnapshotPolicy.create(
+            self.apiclient,
+            self.volume[0].id,
+            self.testdata["recurring_snapshot"]
+        )
+
+        list_snapshots_policy = list_snapshot_policy(
+            self.apiclient,
+            volumeid=self.volume[0].id
+        )
+
+        list_validation = validateList(list_snapshots_policy)
+
+        self.assertEqual(
+            list_validation[0],
+            PASS,
+            "snapshot list validation failed due to %s" %
+            list_validation[2])
+
+        for rec in [recurring_snapshot_hourly, recurring_snapshot_monthly]:
+            self.assertTrue(
+                rec.id in any(
+                    policy['id']) for policy in list_snapshots_policy)
+
+        recurring_snapshot_hourly.delete(self.apiclient)
+        recurring_snapshot_monthly.delete(self.apiclient)
+
+        # Step 6
+        self.testdata["recurring_snapshot"]["intervaltype"] = 'HOURLY'
+        self.testdata["recurring_snapshot"]["schedule"] = 1
+        recurring_snapshot_hourly = SnapshotPolicy.create(
+            self.apiclient,
+            self.volume[0].id,
+            self.testdata["recurring_snapshot"]
+        )
+
+        self.testdata["recurring_snapshot"]["intervaltype"] = 'MONTHLY'
+        self.testdata["recurring_snapshot"]["schedule"] = '00:00:1'
+        recurring_snapshot_monthly = SnapshotPolicy.create(
+            self.apiclient,
+            self.volume[0].id,
+            self.testdata["recurring_snapshot"]
+        )
+
+        recurring_snapshot_monthly.delete(self.apiclient)
+
+        list_snapshots_policy = list_snapshot_policy(
+            self.apiclient,
+            volumeid=self.volume[0].id
+        )
+
+        list_validation = validateList(list_snapshots_policy)
+
+        self.assertEqual(
+            list_validation[0],
+            PASS,
+            "snapshot list validation failed due to %s" %
+            list_validation[2])
+
+        self.assertTrue(
+            recurring_snapshot_hourly.id in any(
+                policy['id']) for policy in list_snapshots_policy)
+
+        self.assertTrue(
+            recurring_snapshot_monthly.id not in any(
+                policy['id']) for policy in list_snapshots_policy)
+
+        # Step 7
+        self.testdata["recurring_snapshot"]["intervaltype"] = 'HOURLY'
+        self.testdata["recurring_snapshot"]["schedule"] = 1
+        recurring_snapshot = SnapshotPolicy.create(
+            self.apiclient,
+            self.volume[0].id,
+            self.testdata["recurring_snapshot"]
+        )
+        # ListSnapshotPolicy should return newly created policy
+        list_snapshots_policy = list_snapshot_policy(
+            self.apiclient,
+            id=recurring_snapshot.id,
+            volumeid=self.volume[0].id
+        )
+        list_validation = validateList(list_snapshots_policy)
+
+        self.assertEqual(
+            list_validation[0],
+            PASS,
+            "snapshot list validation failed due to %s" %
+            list_validation[2])
+
+        timeout = self.testdata["timeout"]
+        while True:
+            snapshots = list_snapshots(
+                self.apiclient,
+                volumeid=self.volume[0].id,
+                intervaltype=self.testdata[
+                    "recurring_snapshot"]["intervaltype"],
+                snapshottype='RECURRING',
+                listall=True
+            )
+
+            if isinstance(snapshots, list):
+                break
+
+            elif timeout == 0:
+                raise Exception("List snapshots API call failed.")
+
+        self.vm_1.delete(self.apiclient, expunge=False)
+
+        time.sleep(3600)
+        snapshot_list = Snapshot.list(
+            self.apiclient,
+            volumeid=self.volume[0].id
+        )
+
+        list_validation = validateList(snapshot_list)
+
+        self.assertEqual(
+            list_validation[0],
+            PASS,
+            "snapshot list validation failed due to %s" %
+            list_validation[2])
+
+        self.assertEqual(len(snapshot_list),
+                         1,
+                         "Verify that snapsot is not created after VM deletion"
+                         )
+        # Step 8
+        self.vm_1.recover(self.apiclient)
+        time.sleep(3600)
+
+        snapshot_list = Snapshot.list(
+            self.apiclient,
+            volumeid=self.volume[0].id
+        )
+
+        self.assertEqual(len(snapshot_list),
+                         2,
+                         "Verify that snapsot is not created after VM deletion"
+                         )
+        # Step 9
+        self.vm_1.delete(self.apiclient)
+        time.sleep(180)
+        with self.assertRaises(Exception):
+            list_snapshots_policy = list_snapshot_policy(
+                self.apiclient,
+                volumeid=self.volume[0].id
+            )
+
+    @attr(tags=["advanced", "basic"], required_hardware="true")
+    def test_02_volume_max_snapshot(self):
+        """ Test Volume Snapshot
+        # 1. Create Hourly reccuring snapshot policy with maxsnaps=2 
+                verify that when 3rd snapshot is taken first snapshot gets deleted
+        """
+
+        if self.hypervisor.lower() not in ["kvm", "vmware"]:
+            self.skipTest("Skip test for hypervisor other than KVM and VMWare")
+
+        # Step 1
+        self.testdata["recurring_snapshot"]["intervaltype"] = 'HOURLY'
+        self.testdata["recurring_snapshot"]["schedule"] = 1
+        recurring_snapshot_1 = SnapshotPolicy.create(
+            self.apiclient,
+            self.volume[0].id,
+            self.testdata["recurring_snapshot"]
+        )
+        # ListSnapshotPolicy should return newly created policy
+        list_snapshots_policy = list_snapshot_policy(
+            self.apiclient,
+            id=recurring_snapshot_1.id,
+            volumeid=self.volume[0].id
+        )
+        list_validation = validateList(list_snapshots_policy)
+
+        self.assertEqual(
+            list_validation[0],
+            PASS,
+            "snapshot list validation failed due to %s" %
+            list_validation[2])
+
+        timeout = self.testdata["timeout"]
+        while True:
+            snapshots = list_snapshots(
+                self.apiclient,
+                volumeid=self.volume[0].id,
+                intervaltype=self.testdata[
+                    "recurring_snapshot"]["intervaltype"],
+                snapshottype='RECURRING',
+                listall=True
+            )
+
+            if isinstance(snapshots, list):
+                break
+
+            elif timeout == 0:
+                raise Exception("List snapshots API call failed.")
+
+        snap_to_delete = snapshots[0]
+
+        time.sleep(
+            (self.testdata["recurring_snapshot"]["maxsnaps"]) * 3600
+        )
+        
+        snapshots_1 = list_snapshots(
+            self.apiclient,
+            volumeid=self.volume[0].id,
+            intervaltype=self.testdata["recurring_snapshot"]["intervaltype"],
+            snapshottype='RECURRING',
+            listall=True
+        )
+
+        self.assertTrue(snap_to_delete not in snapshots_1)
+
+        time.sleep(360)
+
+        self.assertEqual(
+            self.dbclient.execute(
+                "select status  from snapshots where uuid='%s'" %
+                snap_to_delete.id)[0][0],
+            "Destroyed"
+        )
+
+        self.assertFalse(
+            is_snapshot_on_nfs(
+                self.apiclient,
+                self.dbclient,
+                self.config,
+                self.zone.id,
+                snap_to_delete.id))
+
+        # DATA DISK
+        recurring_snapshot_data = SnapshotPolicy.create(
+            self.apiclient,
+            self.data_volume[0].id,
+            self.testdata["recurring_snapshot"]
+        )
+        # ListSnapshotPolicy should return newly created policy
+        list_snapshots_policy = list_snapshot_policy(
+            self.apiclient,
+            id=recurring_snapshot_data.id,
+            volumeid=self.data_volume[0].id
+        )
+
+        list_validation = validateList(list_snapshots_policy)
+
+        self.assertEqual(
+            list_validation[0],
+            PASS,
+            "snapshot list validation failed due to %s" %
+            list_validation[2])
+
+        timeout = self.testdata["timeout"]
+        while True:
+            snapshots = list_snapshots(
+                self.apiclient,
+                volumeid=self.volume[0].id,
+                intervaltype=self.testdata[
+                    "recurring_snapshot"]["intervaltype"],
+                snapshottype='RECURRING',
+                listall=True
+            )
+
+            if isinstance(snapshots, list):
+                break
+
+            elif timeout == 0:
+                raise Exception("List snapshots API call failed.")
+
+        data_snap_to_delete = snapshots[0]
+
+        time.sleep(
+            (self.testdata["recurring_snapshot"]["maxsnaps"]) * 3600
+        )
+
+        data_snapshots_1 = list_snapshots(
+            self.apiclient,
+            volumeid=self.volume[0].id,
+            intervaltype=self.testdata["recurring_snapshot"]["intervaltype"],
+            snapshottype='RECURRING',
+            listall=True
+        )
+
+        self.assertTrue(data_snap_to_delete not in data_snapshots_1)
+
+        time.sleep(360)
+
+        self.assertEqual(
+            self.dbclient.execute(
+                "select status  from snapshots where uuid='%s'" %
+                snap_to_delete.id)[0][0],
+            "Destroyed"
+        )
+
+        self.assertFalse(
+            is_snapshot_on_nfs(
+                self.apiclient,
+                self.dbclient,
+                self.config,
+                self.zone.id,
+                data_snap_to_delete.id))
+
+    @attr(tags=["advanced", "basic"],required_hardware="true")
+    def test_03_volume_rec_snapshot(self):
+        """ Test Volume (root) Snapshot
+        # 1. For snapshot.delta.max > maxsnaps verify that when number of snapshot exceeds 
+                maxsnaps value previous snapshot should get deleted from database but remain 
+                on secondary storage and when the value exceeds snapshot.delta.max the 
+                snapshot should get deleted from secondary storage
+        """
+
+        if self.hypervisor.lower() != "xenserver":
+            self.skipTest("Skip test for hypervisor other than Xenserver")
+
+        # Step 1
+        self.testdata["recurring_snapshot"]["intervaltype"] = 'HOURLY'
+        self.testdata["recurring_snapshot"]["schedule"] = 1
+        recurring_snapshot_root = SnapshotPolicy.create(
+            self.apiclient,
+            self.volume[0].id,
+            self.testdata["recurring_snapshot"]
+        )
+
+        Configurations.update(self.apiclient,
+                              name="snapshot.delta.max",
+                              value="3"
+                              )
+
+        list_snapshots_policy = list_snapshot_policy(
+            self.apiclient,
+            id=recurring_snapshot_root.id,
+            volumeid=self.volume[0].id
+        )
+        list_validation = validateList(list_snapshots_policy)
+
+        self.assertEqual(
+            list_validation[0],
+            PASS,
+            "snapshot list validation failed due to %s" %
+            list_validation[2])
+
+        timeout = self.testdata["timeout"]
+        while True:
+            snapshots = list_snapshots(
+                self.apiclient,
+                volumeid=self.volume[0].id,
+                intervaltype=self.testdata[
+                    "recurring_snapshot"]["intervaltype"],
+                snapshottype='RECURRING',
+                listall=True
+            )
+
+            if isinstance(snapshots, list):
+                break
+
+            elif timeout == 0:
+                raise Exception("List snapshots API call failed.")
+
+        time.sleep(3600 * 2)
+
+        snapshots_2 = list_snapshots(
+            self.apiclient,
+            volumeid=self.volume[0].id,
+            intervaltype=self.testdata["recurring_snapshot"]["intervaltype"],
+            snapshottype='RECURRING',
+            listall=True
+        )
+
+        self.assertTrue(snapshots[0] not in snapshots_2)
+
+        for snapshot in snapshots_2:
+            snapshots.append(snapshot)
+
+        time.sleep(360)
+        self.assertEqual(
+            self.dbclient.execute(
+                "select status  from snapshots where uuid='%s'" %
+                snapshots[0].id)[0][0],
+            "Destroyed"
+        )
+
+        self.assertTrue(
+            is_snapshot_on_nfs(
+                self.apiclient,
+                self.dbclient,
+                self.config,
+                self.zone.id,
+                snapshots[0].id))
+
+        time.sleep(3600)
+
+        snapshots_3 = list_snapshots(
+            self.apiclient,
+            volumeid=self.volume[0].id,
+            intervaltype=self.testdata["recurring_snapshot"]["intervaltype"],
+            snapshottype='RECURRING',
+            listall=True
+        )
+
+        self.assertTrue(snapshots[1] not in snapshots_3)
+        snapshots.append(snapshots_3[1])
+        time.sleep(180)
+
+        self.assertEqual(
+            self.dbclient.execute(
+                "select status  from snapshots where uuid='%s'" %
+                snapshots[1].id)[0][0],
+            "Destroyed"
+        )
+
+        for snapshot in [snapshots[0], snapshots[1]]:
+            self.assertTrue(
+                is_snapshot_on_nfs(
+                    self.apiclient,
+                    self.dbclient,
+                    self.config,
+                    self.zone.id,
+                    snapshot.id))
+
+        time.sleep(3600)
+
+        snapshots_4 = list_snapshots(
+            self.apiclient,
+            volumeid=self.volume[0].id,
+            intervaltype=self.testdata["recurring_snapshot"]["intervaltype"],
+            snapshottype='RECURRING',
+            listall=True
+        )
+
+        self.assertTrue(snapshots[2] not in snapshots_4)
+
+        snapshots.append(snapshots_4[1])
+        time.sleep(180)
+
+        self.assertEqual(
+            self.dbclient.execute(
+                "select status  from snapshots where uuid='%s'" %
+                snapshots[2].id)[0][0],
+            "Destroyed"
+        )
+
+        for snapshot in [snapshots[0], snapshots[1], snapshots[2]]:
+            self.assertFalse(
+                is_snapshot_on_nfs(
+                    self.apiclient,
+                    self.dbclient,
+                    self.config,
+                    self.zone.id,
+                    snapshot.id))
+
+        return

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/628dde7f/test/integration/testpaths/testpath_volume_snapshot.py
----------------------------------------------------------------------
diff --git a/test/integration/testpaths/testpath_volume_snapshot.py b/test/integration/testpaths/testpath_volume_snapshot.py
new file mode 100644
index 0000000..1115968
--- /dev/null
+++ b/test/integration/testpaths/testpath_volume_snapshot.py
@@ -0,0 +1,972 @@
+# 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 VM/Volume snapshot Test Path
+"""
+from nose.plugins.attrib import attr
+from marvin.cloudstackTestCase import cloudstackTestCase, unittest
+from marvin.lib.utils import (cleanup_resources,
+                              is_snapshot_on_nfs,
+                              validateList)
+from marvin.lib.base import (Account,
+                             ServiceOffering,
+                             DiskOffering,
+                             Template,
+                             VirtualMachine,
+                             Snapshot,
+                             Volume
+                             )
+from marvin.lib.common import (get_domain,
+                               get_zone,
+                               get_template,
+                               list_volumes,
+                               list_snapshots,
+                               list_events,
+                               createChecksum,
+                               compareChecksum
+                               )
+
+from marvin.codes import PASS
+from threading import Thread
+
+
+class TestVolumeSnapshot(cloudstackTestCase):
+
+    @classmethod
+    def setUpClass(cls):
+        testClient = super(TestVolumeSnapshot, 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._cleanup = []
+
+        if cls.hypervisor.lower() not in [
+                "vmware",
+                "kvm",
+                "xenserver"]:
+            raise unittest.SkipTest(
+                "Storage migration not supported on %s" %
+                cls.hypervisor)
+
+        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)
+            # Create Disk offering
+            cls.disk_offering = DiskOffering.create(
+                cls.apiclient,
+                cls.testdata["disk_offering"],
+            )
+            cls._cleanup.append(cls.disk_offering)
+            #Create VM_1 and  VM_2   
+            cls.vm_1 = VirtualMachine.create(
+                cls.userapiclient,
+                cls.testdata["small"],
+                templateid=cls.template.id,
+                accountid=cls.account.name,
+                domainid=cls.account.domainid,
+                serviceofferingid=cls.service_offering.id,
+                zoneid=cls.zone.id,
+                diskofferingid=cls.disk_offering.id,
+                mode=cls.zone.networktype
+            )
+
+            cls.vm_2 = VirtualMachine.create(
+                cls.userapiclient,
+                cls.testdata["small"],
+                templateid=cls.template.id,
+                accountid=cls.account.name,
+                domainid=cls.account.domainid,
+                serviceofferingid=cls.service_offering.id,
+                zoneid=cls.zone.id,
+                diskofferingid=cls.disk_offering.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:
+            root_volume = list_volumes(
+                    self.apiclient,
+                    virtualmachineid=self.vm_1.id,
+                    type='ROOT',
+                    listall=True
+                    )
+
+            self.vm_1.stop(self.apiclient)
+            snaps = []
+            for i in range(2):
+
+                root_vol_snap = Snapshot.create(
+                    self.apiclient,
+                    root_volume[0].id)
+
+               
+                self.assertEqual(
+                    root_vol_snap.state,
+                    "BackedUp",
+                    "Check if the data vol snapshot state is correct "
+                )
+
+                snaps.append(root_vol_snap)
+
+            for snap in snaps:
+
+                self.assertNotEqual(
+                        self.dbclient.execute(
+                            "select status from snapshots where name='%s'" %
+                            snap.name),
+                        "Destroyed"
+                        )
+
+            for snap in snaps:
+                self.assertTrue(
+                       is_snapshot_on_nfs(
+                           self.apiclient,
+                           self.dbclient,
+                           self.config,
+                           self.zone.id,
+                           snap.id))
+            
+            self.account.delete(self.apiclient)
+
+            for snap in snaps:
+                self.assertEqual(
+                        self.dbclient.execute(
+                            "select status from snapshots where name='%s'" %
+                            snap.name)[0][0],
+                        "Destroyed"
+                        )
+
+            for snap in snaps:
+                self.assertFalse(
+                       is_snapshot_on_nfs(
+                           self.apiclient,
+                           self.dbclient,
+                           self.config,
+                           self.zone.id,
+                           snap.id))
+
+            cleanup_resources(self.apiclient, self.cleanup)
+        except Exception as e:
+            raise Exception("Warning: Exception during cleanup : %s" % e)
+        return
+
+    @attr(tags=["advanced", "basic"], required_hardware="true")
+    def test_01_volume_snapshot(self):
+        """ Test Volume (root) Snapshot
+        # 1. Deploy a VM on primary storage and .
+        # 2. Take snapshot on root disk
+        # 3. Verify the snapshot's entry in the "snapshots" table 
+                and presence of the corresponding 
+                snapshot on the Secondary Storage
+        # 4. Create Template from the Snapshot and Deploy a 
+                VM using the Template
+        # 5. Log in to the VM from template and make verify 
+                the contents of the ROOT disk matches with the snapshot.
+        # 6. Delete Snapshot and Deploy a Linux VM from the 
+             Template and verify the successful deployment of the VM.
+        # 7. Create multiple snapshots on the same volume and 
+                Check the integrity of all the snapshots by creating 
+                a template from the snapshot and deploying a Vm from it 
+                and delete one of the snapshots
+        # 8. Verify that the original checksum matches with the checksum 
+                of VM's created from remaning snapshots
+        # 9. Make verify the contents of the ROOT disk 
+                matches with the snapshot
+        # 10.Verify that Snapshot of both DATA and ROOT volume should 
+                succeed when snapshot of Data disk of a VM is taken 
+                when snapshot of ROOT volume of VM is in progress
+        # 11.Create snapshot of data disk and verify the original checksum 
+                matches with the volume created from snapshot
+        # 12.Verify that volume's state should not change when snapshot of 
+                a DATA volume is taken that is attached to a VM
+        # 13.Verify that volume's state should not change when snapshot of 
+                a DATA volume is taken that is not attached to a VM
+        # 14.Verify that create Snapshot with quiescevm=True should succeed
+        # 15.revertSnapshot() to revert VM to a specified 
+                Volume snapshot for root volume
+        """
+
+        # Step 1
+        # Get ROOT Volume Id
+        root_volumes_cluster_list = list_volumes(
+            self.apiclient,
+            virtualmachineid=self.vm_1.id,
+            type='ROOT',
+            listall=True
+        )
+
+        root_volume_cluster = root_volumes_cluster_list[0]
+
+        disk_volumes_cluster_list = list_volumes(
+            self.apiclient,
+            virtualmachineid=self.vm_1.id,
+            type='DATADISK',
+            listall=True
+        )
+
+        data_disk = disk_volumes_cluster_list[0]
+
+        root_vol_state = root_volume_cluster.state
+
+        ckecksum_random_root_cluster = createChecksum(
+            service=self.testdata,
+            virtual_machine=self.vm_1,
+            disk=root_volume_cluster,
+            disk_type="rootdiskdevice")
+
+        self.vm_1.stop(self.apiclient)
+        root_vol_snap = Snapshot.create(
+            self.apiclient,
+            root_volume_cluster.id)
+
+        self.assertEqual(
+            root_vol_snap.state,
+            "BackedUp",
+            "Check if the snapshot state is correct "
+        )
+
+        self.assertEqual(
+            root_vol_state,
+            root_volume_cluster.state,
+            "Check if volume state has changed"
+        )
+
+        self.vm_1.start(self.apiclient)
+        # Step 2
+        snapshot_list = list_snapshots(
+            self.apiclient,
+            id=root_vol_snap.id
+        )
+
+        self.assertNotEqual(
+            snapshot_list,
+            None,
+            "Check if result exists in list item call"
+        )
+        self.assertEqual(
+            snapshot_list[0].id,
+            root_vol_snap.id,
+            "Check resource id in list resources call"
+        )
+
+        self.assertTrue(
+            is_snapshot_on_nfs(
+                self.apiclient,
+                self.dbclient,
+                self.config,
+                self.zone.id,
+                root_vol_snap.id))
+
+        events = list_events(
+            self.apiclient,
+            account=self.account.name,
+            domainid=self.account.domainid,
+            type='SNAPSHOT.CREATE')
+
+        event_list_validation_result = validateList(events)
+
+        self.assertEqual(
+            event_list_validation_result[0],
+            PASS,
+            "event list validation failed due to %s" %
+            event_list_validation_result[2])
+        self.debug("Events list contains event SNAPSHOT.CREATE")
+
+        qresultset = self.dbclient.execute(
+            "select * from event where type='SNAPSHOT.CREATE' AND \
+                    description like '%%%s%%' AND state='Completed';" %
+            root_volume_cluster.id)
+
+        event_validation_result = validateList(qresultset)
+
+        self.assertEqual(
+            event_validation_result[0],
+            PASS,
+            "event list validation failed due to %s" %
+            event_validation_result[2])
+
+        self.assertNotEqual(
+            len(qresultset),
+            0,
+            "Check DB Query result set"
+        )
+
+        qresult = str(qresultset)
+        self.assertEqual(
+            qresult.count('SNAPSHOT.CREATE') > 0,
+            True,
+            "Check SNAPSHOT.CREATE event in events table"
+        )
+
+        #Usage_Event
+        qresultset = self.dbclient.execute(
+                "select * from usage_event where type='SNAPSHOT.CREATE' AND \
+                        resource_name='%s'" %
+                root_vol_snap.name)
+
+        usage_event_validation_result = validateList(qresultset)
+
+        self.assertEqual(
+               usage_event_validation_result[0],
+               PASS,
+               "event list validation failed due to %s" %
+               usage_event_validation_result[2])
+
+        self.assertNotEqual(
+               len(qresultset),
+               0,
+               "Check DB Query result set"
+              )
+
+        self.assertEqual(
+            self.dbclient.execute("select size from usage_event where type='SNAPSHOT.CREATE' AND \
+            resource_name='%s'" %
+            root_vol_snap.name)[0][0],
+            root_vol_snap.physicalsize)
+
+        # Step 3
+        # create template from snapshot root_vol_snap
+        templateFromSnapshot = Template.create_from_snapshot(
+            self.apiclient,
+            root_vol_snap,
+            self.testdata["template_2"])
+
+        self.assertNotEqual(
+            templateFromSnapshot,
+            None,
+            "Check if result exists in list item call"
+        )
+
+        vm_from_temp = VirtualMachine.create(
+            self.apiclient,
+            self.testdata["small"],
+            templateid=templateFromSnapshot.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"
+        )
+
+        compareChecksum(
+            self.apiclient,
+            service=self.testdata,
+            original_checksum=ckecksum_random_root_cluster,
+            disk_type="rootdiskdevice",
+            virt_machine=vm_from_temp
+        )
+        vm_from_temp.delete(self.apiclient)
+        # Step 4
+        root_vol_snap.delete(self.userapiclient)
+
+        self.assertEqual(
+            list_snapshots(
+                self.apiclient,
+                volumeid=root_volume_cluster.id,
+            ), None, "Snapshot list should be empty")
+
+        events = list_events(
+            self.apiclient,
+            account=self.account.name,
+            domainid=self.account.domainid,
+            type='SNAPSHOT.DELETE')
+
+        event_list_validation_result = validateList(events)
+
+        self.assertEqual(
+            event_list_validation_result[0],
+            PASS,
+            "event list validation failed due to %s" %
+            event_list_validation_result[2])
+
+        self.debug("Events list contains event SNAPSHOT.DELETE")
+
+        self.debug("select id from account where uuid = '%s';"
+                   % self.account.id)
+
+        qresultset = self.dbclient.execute(
+            "select id from account where uuid = '%s';"
+            % self.account.id
+        )
+
+        account_validation_result = validateList(qresultset)
+
+        self.assertEqual(
+            account_validation_result[0],
+            PASS,
+            "event list validation failed due to %s" %
+            account_validation_result[2])
+
+        self.assertNotEqual(
+            len(qresultset),
+            0,
+            "Check DB Query result set"
+        )
+        qresult = qresultset[0]
+
+        account_id = qresult[0]
+
+        qresultset = self.dbclient.execute(
+            "select * from event where type='SNAPSHOT.DELETE' AND \
+                    account_id='%s' AND state='Completed';" %
+            account_id)
+
+        delete_snap_validation_result = validateList(qresultset)
+
+        self.assertEqual(
+            delete_snap_validation_result[0],
+            PASS,
+            "event list validation failed due to %s" %
+            delete_snap_validation_result[2])
+
+        self.assertNotEqual(
+            len(qresultset),
+            0,
+            "Check DB Query result set"
+        )
+
+        qresult = str(qresultset)
+        self.assertEqual(
+            qresult.count('SNAPSHOT.DELETE') > 0,
+            True,
+            "Check SNAPSHOT.DELETE event in events table"
+        )
+
+        # Step 5
+        # delete snapshot and deploy vm from snapshot
+        vm_from_temp_2 = VirtualMachine.create(
+            self.apiclient,
+            self.testdata["small"],
+            templateid=templateFromSnapshot.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_2,
+            None,
+            "Check if result exists in list item call"
+        )
+
+        # Step 6:
+        compareChecksum(
+            self.apiclient,
+            service=self.testdata,
+            original_checksum=ckecksum_random_root_cluster,
+            disk_type="rootdiskdevice",
+            virt_machine=vm_from_temp_2
+        )
+
+        vm_from_temp_2.delete(self.apiclient)
+        # Step 7
+        # Multiple Snapshots
+        self.vm_1.stop(self.apiclient)
+        snaps = []
+        for i in range(2):
+
+            root_vol_snap = Snapshot.create(
+                self.apiclient,
+                root_volume_cluster.id)
+
+            self.assertEqual(
+                root_vol_snap.state,
+                "BackedUp",
+                "Check if the data vol snapshot state is correct "
+            )
+
+            snaps.append(root_vol_snap)
+
+            templateFromSnapshot = Template.create_from_snapshot(
+                self.apiclient,
+                root_vol_snap,
+                self.testdata["template_2"])
+
+            self.assertNotEqual(
+                templateFromSnapshot,
+                None,
+                "Check if result exists in list item call"
+            )
+
+            vm_from_temp = VirtualMachine.create(
+                self.apiclient,
+                self.testdata["small"],
+                templateid=templateFromSnapshot.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"
+            )
+
+            compareChecksum(
+                self.apiclient,
+                service=self.testdata,
+                original_checksum=ckecksum_random_root_cluster,
+                disk_type="rootdiskdevice",
+                virt_machine=vm_from_temp
+            )
+            vm_from_temp.delete(self.apiclient)
+            templateFromSnapshot.delete(self.apiclient)
+
+        self.vm_1.start(self.apiclient)
+
+        delete_snap = snaps.pop(1)
+        delete_snap.delete(self.apiclient)
+
+        self.assertEqual(
+            Snapshot.list(
+                self.apiclient,
+                id=delete_snap.id
+            ), None, "Snapshot list should be empty")
+
+        # Step 8
+        for snap in snaps:
+
+            templateFromSnapshot = Template.create_from_snapshot(
+                self.apiclient,
+                snap,
+                self.testdata["template_2"])
+
+            self.assertNotEqual(
+                templateFromSnapshot,
+                None,
+                "Check if result exists in list item call"
+            )
+
+            vm_from_temp = VirtualMachine.create(
+                self.apiclient,
+                self.testdata["small"],
+                templateid=templateFromSnapshot.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"
+            )
+
+            compareChecksum(
+                self.apiclient,
+                service=self.testdata,
+                original_checksum=ckecksum_random_root_cluster,
+                disk_type="rootdiskdevice",
+                virt_machine=vm_from_temp
+            )
+
+            templateFromSnapshot.delete(self.apiclient)
+            vm_from_temp.delete(self.apiclient)
+
+        for snap in snaps:
+            snap.delete(self.apiclient)
+
+        # Step 9
+        ckecksum_root_cluster = createChecksum(
+            service=self.testdata,
+            virtual_machine=self.vm_1,
+            disk=root_volume_cluster,
+            disk_type="rootdiskdevice")
+
+        self.vm_1.stop(self.apiclient)
+
+        root_vol_snap_2 = Snapshot.create(
+            self.apiclient,
+            root_volume_cluster.id)
+
+        self.assertEqual(
+            root_vol_snap_2.state,
+            "BackedUp",
+            "Check if the data vol snapshot state is correct "
+        )
+        snap_list_validation_result = validateList(events)
+
+        self.assertEqual(
+            snap_list_validation_result[0],
+            PASS,
+            "snapshot list validation failed due to %s" %
+            snap_list_validation_result[2])
+
+        self.assertNotEqual(
+            snapshot_list,
+            None,
+            "Check if result exists in list item call"
+        )
+
+        templateFromSnapshot = Template.create_from_snapshot(
+            self.apiclient,
+            root_vol_snap_2,
+            self.testdata["template_2"])
+
+        self.debug(
+            "create template event comlites with template %s name" %
+            templateFromSnapshot.name)
+
+        self.assertNotEqual(
+            templateFromSnapshot,
+            None,
+            "Check if result exists in list item call"
+        )
+
+        vm_from_temp_2 = VirtualMachine.create(
+            self.apiclient,
+            self.testdata["small"],
+            templateid=templateFromSnapshot.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_2,
+            None,
+            "Check if result exists in list item call"
+        )
+
+        compareChecksum(
+            self.apiclient,
+            service=self.testdata,
+            original_checksum=ckecksum_root_cluster,
+            disk_type="rootdiskdevice",
+            virt_machine=vm_from_temp_2
+        )
+
+        vm_from_temp_2.delete(self.apiclient)
+
+        # Step 10
+        # Take snapshot of Data disk of a VM , when snapshot of ROOT volume of 
+        # VM is in progress
+        try:
+            self.vm_1.stop(self.apiclient)
+
+            t1 = Thread(
+                target=Snapshot.create,
+                args=(
+                    self.apiclient,
+                    root_volume_cluster.id
+                ))
+
+            t2 = Thread(
+                target=Snapshot.create,
+                args=(
+                    self.apiclient,
+                    data_disk.id
+                ))
+
+            t1.start()
+            t2.start()
+            t1.join()
+            t2.join()
+
+        except:
+            self.debug("Error: unable to start thread")
+
+        # Step 11
+        # Data Disk
+        self.vm_1.start(self.apiclient)
+        ckecksum_data_disk = createChecksum(
+            service=self.testdata,
+            virtual_machine=self.vm_1,
+            disk=data_disk,
+            disk_type="datadiskdevice_1")
+
+        data_vol_state = data_disk.state
+
+        self.vm_1.stop(self.apiclient)
+
+        data_vol_snap = Snapshot.create(
+            self.apiclient,
+            data_disk.id)
+
+        self.assertEqual(
+            data_vol_snap.state,
+            "BackedUp",
+            "Check if the data vol snapshot state is correct "
+        )
+
+        self.assertEqual(
+            data_vol_state,
+            data_disk.state,
+            "Check if volume state has changed"
+        )
+
+        data_snapshot_list = list_snapshots(
+            self.apiclient,
+            id=data_vol_snap.id
+        )
+
+        self.assertNotEqual(
+            data_snapshot_list,
+            None,
+            "Check if result exists in list item call"
+        )
+        self.assertEqual(
+            data_snapshot_list[0].id,
+            data_vol_snap.id,
+            "Check resource id in list resources call"
+        )
+
+        self.assertTrue(
+            is_snapshot_on_nfs(
+                self.apiclient,
+                self.dbclient,
+                self.config,
+                self.zone.id,
+                data_vol_snap.id))
+
+        events = list_events(
+            self.apiclient,
+            account=self.account.name,
+            domainid=self.account.domainid,
+            type='SNAPSHOT.CREATE')
+
+        event_list_validation_result = validateList(events)
+
+        self.assertEqual(
+            event_list_validation_result[0],
+            PASS,
+            "event list validation failed due to %s" %
+            event_list_validation_result[2])
+        self.debug("Events list contains event SNAPSHOT.CREATE")
+
+        volumeFromSnap = Volume.create_from_snapshot(
+            self.apiclient,
+            data_vol_snap.id,
+            self.testdata["volume"],
+            account=self.account.name,
+            domainid=self.account.domainid,
+            zoneid=self.zone.id
+        )
+
+        self.assertTrue(
+            is_snapshot_on_nfs(
+                self.apiclient,
+                self.dbclient,
+                self.config,
+                self.zone.id,
+                data_vol_snap.id))
+
+        new_vm = VirtualMachine.create(
+            self.userapiclient,
+            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
+        )
+
+        new_vm.attach_volume(
+            self.apiclient,
+            volumeFromSnap
+        )
+
+        new_vm.reboot(self.apiclient)
+
+        compareChecksum(
+            self.apiclient,
+            service=self.testdata,
+            original_checksum=ckecksum_data_disk,
+            disk_type="datadiskdevice_1",
+            virt_machine=new_vm
+        )
+
+        # Step 12
+        data_volume_2 = Volume.create(
+            self.apiclient,
+            self.testdata["volume"],
+            zoneid=self.zone.id,
+            account=self.account.name,
+            domainid=self.account.domainid,
+            diskofferingid=self.disk_offering.id
+        )
+
+        self.vm_1.start(self.apiclient)
+        self.vm_1.attach_volume(
+            self.userapiclient,
+            data_volume_2
+        )
+
+        self.vm_1.reboot(self.apiclient)       
+        self.vm_1.stop(self.apiclient)
+
+        data_vol_snap_1 = Snapshot.create(
+            self.apiclient,
+            data_volume_2.id)
+
+        self.assertEqual(
+            data_vol_snap_1.state,
+            "BackedUp",
+            "Check if the snapshot state is correct "
+        )
+
+        data_disk_2_list = Volume.list(
+            self.userapiclient,
+            listall=self.testdata["listall"],
+            id=data_volume_2.id
+        )
+
+        self.vm_1.start(self.apiclient)
+
+        checksum_data_2 = createChecksum(
+            service=self.testdata,
+            virtual_machine=self.vm_1,
+            disk=data_disk_2_list[0],
+            disk_type="datadiskdevice_2")
+
+        # Step 13
+        self.vm_1.detach_volume(self.apiclient,
+                           data_volume_2)
+
+        self.vm_1.reboot(self.apiclient)
+
+        prev_state = data_volume_2.state
+
+        data_vol_snap_2 = Snapshot.create(
+            self.apiclient,
+            data_volume_2.id)
+
+        self.assertEqual(
+            data_vol_snap_2.state,
+            prev_state,
+            "Check if the volume state is correct "
+        )
+
+        data_snapshot_list_2 = list_snapshots(
+            self.apiclient,
+            id=data_vol_snap_2.id
+        )
+
+        self.assertNotEqual(
+            data_snapshot_list_2,
+            None,
+            "Check if result exists in list item call"
+        )
+
+        self.assertEqual(
+            data_snapshot_list_2[0].id,
+            data_vol_snap_2.id,
+            "Check resource id in list resources call"
+        )
+
+        volumeFromSnap_2 = Volume.create_from_snapshot(
+            self.apiclient,
+            data_vol_snap_2.id,
+            self.testdata["volume"],
+            account=self.account.name,
+            domainid=self.account.domainid,
+            zoneid=self.zone.id
+        )
+
+        self.vm_2.attach_volume(
+            self.userapiclient,
+            volumeFromSnap_2
+        )
+
+        self.vm_2.reboot(self.apiclient)
+
+        data_disk_2_list = Volume.list(
+            self.userapiclient,
+            listall=self.testdata["listall"],
+            id=volumeFromSnap_2.id
+        )
+
+        compareChecksum(
+            self.apiclient,
+            service=self.testdata,
+            original_checksum=checksum_data_2,
+            disk_type="datadiskdevice_2",
+            virt_machine=self.vm_2
+        )
+
+        # Step 14
+        self.vm_1.stop(self.apiclient)
+        with self.assertRaises(Exception):
+            root_vol_snap.revertVolToSnapshot(self.apiclient)
+
+        # Step 15
+        root_snap = Snapshot.create(
+            self.apiclient,
+            root_volume_cluster.id)
+
+        with self.assertRaises(Exception):
+            root_snap.revertVolToSnapshot(self.apiclient)
+
+        return

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/628dde7f/tools/marvin/marvin/lib/common.py
----------------------------------------------------------------------
diff --git a/tools/marvin/marvin/lib/common.py b/tools/marvin/marvin/lib/common.py
index ca9d9e8..b1efb62 100644
--- a/tools/marvin/marvin/lib/common.py
+++ b/tools/marvin/marvin/lib/common.py
@@ -64,9 +64,11 @@ from marvin.codes import (PASS, FAILED, ISOLATED_NETWORK, VPC_NETWORK,
                           RESOURCE_CPU, RESOURCE_MEMORY, PUBLIC_TRAFFIC,
                           GUEST_TRAFFIC, MANAGEMENT_TRAFFIC, STORAGE_TRAFFIC,
                           VMWAREDVS)
-from marvin.lib.utils import (validateList,
-                              xsplit,
-                              get_process_status)
+from marvin.lib.utils import (validateList, 
+                              xsplit, 
+                              get_process_status,
+                              random_gen,
+                              format_volume_to_ext3)
 from marvin.lib.base import (PhysicalNetwork,
                              PublicIPAddress,
                              NetworkOffering,
@@ -93,6 +95,9 @@ from netaddr import IPAddress
 import random
 import re
 import itertools
+import random
+import hashlib
+
 # Import System modules
 import time
 
@@ -1402,6 +1407,149 @@ def isNetworkDeleted(apiclient, networkid, timeout=600):
     #end while
     return networkDeleted
 
+
+def createChecksum(service=None, 
+                   virtual_machine=None, 
+                   disk=None, 
+                   disk_type=None):
+
+    """ Calculate the MD5 checksum of the disk by writing \
+		data on the disk where disk_type is either root disk or data disk 
+	@return: returns the calculated checksum"""
+
+    random_data_0 = random_gen(size=100)
+    # creating checksum(MD5)
+    m = hashlib.md5()
+    m.update(random_data_0)
+    ckecksum_random_data_0 = m.hexdigest()
+    try:
+        ssh_client = SshClient(
+            virtual_machine.ssh_ip,
+            virtual_machine.ssh_port,
+            virtual_machine.username,
+            virtual_machine.password
+        )
+    except Exception: 
+        raise Exception("SSH access failed for server with IP address: %s" %
+                    virtual_machine.ssh_ip)
+
+    # Format partition using ext3
+
+    format_volume_to_ext3(
+        ssh_client,
+        service["volume_write_path"][
+            virtual_machine.hypervisor][disk_type]
+    )
+    cmds = ["fdisk -l",
+            "mkdir -p %s" % service["data_write_paths"]["mount_dir"],
+            "mount -t ext3 %s1 %s" % (
+                service["volume_write_path"][
+                    virtual_machine.hypervisor][disk_type],
+                service["data_write_paths"]["mount_dir"]
+            ),
+            "mkdir -p %s/%s/%s " % (
+                service["data_write_paths"]["mount_dir"],
+                service["data_write_paths"]["sub_dir"],
+                service["data_write_paths"]["sub_lvl_dir1"],
+            ),
+            "echo %s > %s/%s/%s/%s" % (
+                random_data_0,
+                service["data_write_paths"]["mount_dir"],
+                service["data_write_paths"]["sub_dir"],
+                service["data_write_paths"]["sub_lvl_dir1"],
+                service["data_write_paths"]["random_data"]
+            ),
+            "cat %s/%s/%s/%s" % (
+                service["data_write_paths"]["mount_dir"],
+                service["data_write_paths"]["sub_dir"],
+                service["data_write_paths"]["sub_lvl_dir1"],
+                service["data_write_paths"]["random_data"]
+            )
+            ]
+
+    for c in cmds:
+        ssh_client.execute(c)
+
+    # Unmount the storage
+    cmds = [
+        "umount %s" % (service["data_write_paths"]["mount_dir"]),
+    ]
+
+    for c in cmds:
+        ssh_client.execute(c)
+
+    return ckecksum_random_data_0
+
+
+def compareChecksum(
+        apiclient,
+        service=None,
+        original_checksum=None,
+        disk_type=None,
+        virt_machine=None
+        ):
+    """
+    Create md5 checksum of the data present on the disk and compare
+    it with the given checksum
+    """
+    if virt_machine.state != "Running":
+        virt_machine.start(apiclient)
+
+    try:
+        # Login to VM to verify test directories and files
+        ssh = SshClient(
+            virt_machine.ssh_ip,
+            virt_machine.ssh_port,
+            virt_machine.username,
+            virt_machine.password
+        )
+    except Exception:
+        raise Exception("SSH access failed for server with IP address: %s" %
+                    virt_machine.ssh_ip)
+
+    # Mount datadiskdevice_1 because this is the first data disk of the new
+    # virtual machine
+    cmds = ["blkid",
+            "fdisk -l",
+            "mkdir -p %s" % service["data_write_paths"]["mount_dir"],
+            "mount -t ext3 %s1 %s" % (
+                service["volume_write_path"][
+                    virt_machine.hypervisor][disk_type],
+                service["data_write_paths"]["mount_dir"]
+            ),
+            ]
+
+    for c in cmds:
+        ssh.execute(c)
+
+    returned_data_0 = ssh.execute(
+        "cat %s/%s/%s/%s" % (
+            service["data_write_paths"]["mount_dir"],
+            service["data_write_paths"]["sub_dir"],
+            service["data_write_paths"]["sub_lvl_dir1"],
+            service["data_write_paths"]["random_data"]
+        ))
+
+    n = hashlib.md5()
+    n.update(returned_data_0[0])
+    ckecksum_returned_data_0 = n.hexdigest()
+
+    # Verify returned data
+    assert original_checksum == ckecksum_returned_data_0, \
+        "Cheskum does not match with checksum of original data"
+
+    # Unmount the Sec Storage
+    cmds = [
+        "umount %s" % (service["data_write_paths"]["mount_dir"]),
+    ]
+
+    for c in cmds:
+        ssh.execute(c)
+
+    return
+
+
+
 def verifyRouterState(apiclient, routerid, state, listall=True):
     """List router and check if the router state matches the given state"""
     retriesCount = 10


Mime
View raw message