You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by ts...@apache.org on 2013/06/20 16:12:21 UTC

[2/4] Split out snapshot tests for speedup

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/82c75c7f/test/integration/smoke/test_snapshots.py
----------------------------------------------------------------------
diff --git a/test/integration/smoke/test_snapshots.py b/test/integration/smoke/test_snapshots.py
new file mode 100644
index 0000000..06777e4
--- /dev/null
+++ b/test/integration/smoke/test_snapshots.py
@@ -0,0 +1,345 @@
+# 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.
+
+from nose.plugins.attrib import attr
+from marvin.cloudstackTestCase import *
+from marvin.cloudstackAPI import *
+from marvin.integration.lib.utils import *
+from marvin.integration.lib.base import *
+from marvin.integration.lib.common import *
+
+class Services:
+    """Test Snapshots Services
+    """
+
+    def __init__(self):
+        self.services = {
+                        "account": {
+                                    "email": "test@test.com",
+                                    "firstname": "Test",
+                                    "lastname": "User",
+                                    "username": "test",
+                                    # Random characters are appended for unique
+                                    # username
+                                    "password": "password",
+                         },
+                         "service_offering": {
+                                    "name": "Tiny Instance",
+                                    "displaytext": "Tiny Instance",
+                                    "cpunumber": 1,
+                                    "cpuspeed": 200,    # in MHz
+                                    "memory": 256,      # In MBs
+                        },
+                        "disk_offering": {
+                                    "displaytext": "Small Disk",
+                                    "name": "Small Disk",
+                                    "disksize": 1
+                        },
+                        "server_with_disk":
+                                    {
+                                        "displayname": "Test VM -With Disk",
+                                        "username": "root",
+                                        "password": "password",
+                                        "ssh_port": 22,
+                                        "hypervisor": 'XenServer',
+                                        "privateport": 22,
+                                        "publicport": 22,
+                                        "protocol": 'TCP',
+                                },
+
+                        "server_without_disk":
+                                    {
+                                        "displayname": "Test VM-No Disk",
+                                        "username": "root",
+                                        "password": "password",
+                                        "ssh_port": 22,
+                                        "hypervisor": 'XenServer',
+                                        "privateport": 22,
+                                        # For NAT rule creation
+                                        "publicport": 22,
+                                        "protocol": 'TCP',
+                                },
+                        "server": {
+                                    "displayname": "TestVM",
+                                    "username": "root",
+                                    "password": "password",
+                                    "ssh_port": 22,
+                                    "hypervisor": 'XenServer',
+                                    "privateport": 22,
+                                    "publicport": 22,
+                                    "protocol": 'TCP',
+                                },
+                         "mgmt_server": {
+                                    "ipaddress": '192.168.100.21',
+                                    "username": "root",
+                                    "password": "password",
+                                    "port": 22,
+                                },
+                        "recurring_snapshot": {
+                                    "intervaltype": 'HOURLY',
+                                    # Frequency of snapshots
+                                    "maxsnaps": 1,  # Should be min 2
+                                    "schedule": 1,
+                                    "timezone": 'US/Arizona',
+                                    # Timezone Formats - http://cloud.mindtouch.us/CloudStack_Documentation/Developer's_Guide%3A_CloudStack
+                                },
+                        "templates": {
+                                    "displaytext": 'Template',
+                                    "name": 'Template',
+                                    "ostype": "CentOS 5.3 (64-bit)",
+                                    "templatefilter": 'self',
+                                },
+                        "volume": {
+                                   "diskname": "APP Data Volume",
+                                   "size": 1,   # in GBs
+                                   "diskdevice": ['/dev/xvdb', '/dev/sdb', '/dev/hdb', '/dev/vdb' ],   # Data Disk
+                        },
+                        "paths": {
+                                    "mount_dir": "/mnt/tmp",
+                                    "sub_dir": "test",
+                                    "sub_lvl_dir1": "test1",
+                                    "sub_lvl_dir2": "test2",
+                                    "random_data": "random.data",
+                        },
+                        "ostype": "CentOS 5.3 (64-bit)",
+                        # Cent OS 5.3 (64 bit)
+                        "sleep": 60,
+                        "timeout": 10,
+                    }
+
+
+class TestSnapshotRootDisk(cloudstackTestCase):
+
+    @classmethod
+    def setUpClass(cls):
+        cls.api_client = super(TestSnapshotRootDisk, cls).getClsTestClient().getApiClient()
+        cls.services = Services().services
+        # Get Zone, Domain and templates
+        cls.domain = get_domain(cls.api_client, cls.services)
+        cls.zone = get_zone(cls.api_client, cls.services)
+        cls.services['mode'] = cls.zone.networktype
+
+        template = get_template(
+                            cls.api_client,
+                            cls.zone.id,
+                            cls.services["ostype"]
+                            )
+        cls.services["domainid"] = cls.domain.id
+        cls.services["server_without_disk"]["zoneid"] = cls.zone.id
+        cls.services["templates"]["ostypeid"] = template.ostypeid
+        cls.services["zoneid"] = cls.zone.id
+
+        # Create VMs, NAT Rules etc
+        cls.account = Account.create(
+                            cls.api_client,
+                            cls.services["account"],
+                            domainid=cls.domain.id
+                            )
+
+        cls.services["account"] = cls.account.name
+
+        cls.service_offering = ServiceOffering.create(
+                                            cls.api_client,
+                                            cls.services["service_offering"]
+                                            )
+        cls.virtual_machine = cls.virtual_machine_with_disk = \
+                    VirtualMachine.create(
+                                cls.api_client,
+                                cls.services["server_without_disk"],
+                                templateid=template.id,
+                                accountid=cls.account.name,
+                                domainid=cls.account.domainid,
+                                serviceofferingid=cls.service_offering.id,
+                                mode=cls.services["mode"]
+                                )
+        cls._cleanup = [
+                        cls.service_offering,
+                        cls.account,
+                        ]
+        return
+
+    @classmethod
+    def tearDownClass(cls):
+        try:
+            #Cleanup resources used
+            cleanup_resources(cls.api_client, cls._cleanup)
+        except Exception as e:
+            raise Exception("Warning: Exception during cleanup : %s" % e)
+        return
+
+    def setUp(self):
+        self.apiclient = self.testClient.getApiClient()
+        self.dbclient = self.testClient.getDbConnection()
+        self.cleanup = []
+        return
+
+    def tearDown(self):
+        try:
+            #Clean up, terminate the created instance, volumes and snapshots
+            cleanup_resources(self.apiclient, self.cleanup)
+        except Exception as e:
+            raise Exception("Warning: Exception during cleanup : %s" % e)
+        return
+
+    @attr(speed = "slow")
+    @attr(tags = ["advanced", "advancedns", "smoke"])
+    def test_01_snapshot_root_disk(self):
+        """Test Snapshot Root Disk
+        """
+
+        # Validate the following
+        # 1. listSnapshots should list the snapshot that was created.
+        # 2. verify that secondary storage NFS share contains
+        #    the reqd volume under
+        #    /secondary/snapshots//$account_id/$volumeid/$snapshot_uuid
+        # 3. verify backup_snap_id was non null in the `snapshots` table
+
+        volumes = list_volumes(
+                            self.apiclient,
+                            virtualmachineid=self.virtual_machine_with_disk.id,
+                            type='ROOT',
+                            listall=True
+                            )
+
+        snapshot = Snapshot.create(
+                                   self.apiclient,
+                                   volumes[0].id,
+                                   account=self.account.name,
+                                   domainid=self.account.domainid
+                                   )
+        self.debug("Snapshot created: ID - %s" % snapshot.id)
+
+        snapshots = list_snapshots(
+                                  self.apiclient,
+                                  id=snapshot.id
+                                  )
+        self.assertEqual(
+                            isinstance(snapshots, list),
+                            True,
+                            "Check list response returns a valid list"
+                        )
+
+        self.assertNotEqual(
+                            snapshots,
+                            None,
+                            "Check if result exists in list item call"
+                            )
+        self.assertEqual(
+                            snapshots[0].id,
+                            snapshot.id,
+                            "Check resource id in list resources call"
+                        )
+        self.debug(
+            "select backup_snap_id, account_id, volume_id from snapshots where uuid = '%s';" \
+            % str(snapshot.id)
+            )
+        qresultset = self.dbclient.execute(
+                        "select backup_snap_id, account_id, volume_id from snapshots where uuid = '%s';" \
+                        % str(snapshot.id)
+                        )
+        self.assertNotEqual(
+                            len(qresultset),
+                            0,
+                            "Check DB Query result set"
+                            )
+
+        qresult = qresultset[0]
+
+        snapshot_uuid = qresult[0]      # backup_snap_id = snapshot UUID
+        account_id = qresult[1]
+        volume_id = qresult[2]
+
+        self.assertNotEqual(
+                            str(snapshot_uuid),
+                            'NULL',
+                            "Check if backup_snap_id is not null"
+                        )
+
+        # Get the Secondary Storage details from  list Hosts
+        hosts = list_hosts(
+                                 self.apiclient,
+                                 type='SecondaryStorage',
+                                 zoneid=self.zone.id
+                                 )
+        self.assertEqual(
+                            isinstance(hosts, list),
+                            True,
+                            "Check list response returns a valid list"
+                        )
+        uuids = []
+        for host in hosts:
+            # hosts[0].name = "nfs://192.168.100.21/export/test"
+            parse_url = (host.name).split('/')
+            # parse_url = ['nfs:', '', '192.168.100.21', 'export', 'test']
+
+            # Split IP address and export path from name
+            sec_storage_ip = parse_url[2]
+            # Sec Storage IP: 192.168.100.21
+
+            export_path = '/'.join(parse_url[3:])
+            # Export path: export/test
+
+            try:
+                # Login to VM to check snapshot present on sec disk
+                ssh_client = self.virtual_machine_with_disk.get_ssh_client()
+
+                cmds = [
+                    "mkdir -p %s" % self.services["paths"]["mount_dir"],
+                    "mount %s/%s %s" % (
+                                         sec_storage_ip,
+                                         export_path,
+                                         self.services["paths"]["mount_dir"]
+                                         ),
+                    "ls %s/snapshots/%s/%s" % (
+                                               self.services["paths"]["mount_dir"],
+                                               account_id,
+                                               volume_id
+                                               ),
+                    ]
+
+                for c in cmds:
+                    self.debug(c)
+                    result = ssh_client.execute(c)
+                    self.debug(result)
+
+            except Exception:
+                self.fail("SSH failed for Virtual machine: %s" %
+                                self.virtual_machine_with_disk.ipaddress)
+
+            uuids.append(result)
+            # Unmount the Sec Storage
+            cmds = [
+                    "umount %s" % (self.services["mount_dir"]),
+                    ]
+            try:
+                for c in cmds:
+                    self.debug(c)
+                    result = ssh_client.execute(c)
+                    self.debug(result)
+
+            except Exception as e:
+                self.fail("SSH failed for Virtual machine: %s" %
+                                self.virtual_machine_with_disk.ipaddress)
+
+        res = str(uuids)
+        # Check snapshot UUID in secondary storage and database
+        self.assertEqual(
+                        res.count(snapshot_uuid),
+                        1,
+                        "Check snapshot UUID in secondary storage and database"
+                        )
+        return
\ No newline at end of file