Beispiel #1
0
    def run(self):
        """Main function for test case execution"""
        log = logger.get_log()

        try:
            log.info("Started executing {0} testcase".format(self.id))

            log.info(
                "-------------------Initialize helper objects------------------------------------"
            )
            auto_commcell = VirtualServerHelper.AutoVSACommcell(
                self.commcell, self.csdb)
            auto_client = VirtualServerHelper.AutoVSAVSClient(
                auto_commcell, self.client)
            auto_instance = VirtualServerHelper.AutoVSAVSInstance(
                auto_client, self.agent, self.instance)
            auto_backupset = VirtualServerHelper.AutoVSABackupset(
                auto_instance, self.backupset)
            auto_subclient = VirtualServerHelper.AutoVSASubclient(
                auto_backupset, self.subclient)

            # """
            log.info(
                "----------------------------------------Backup-----------------------------------"
            )
            backup_options = OptionsHelper.BackupOptions(auto_subclient)
            auto_subclient.backup(backup_options)

            # """
            # """
            log.info(
                "----------------------------------------FULL VM out of Place restores------------"
            )
            vm_restore_options = OptionsHelper.FullVMRestoreOptions(
                auto_subclient, self)
            vm_restore_options.unconditional_overwrite = True
            auto_subclient.virtual_machine_restore(vm_restore_options)

            # """

            difference = list(
                set(auto_subclient.source_obj.disk_list) -
                set(auto_subclient.restore_obj.disk_list))
            if difference:
                raise Exception("Disk Level Filtering failed")

        except Exception as exp:
            log.error('Failed with error: ' + str(exp))
            self.result_string = str(exp)
            self.status = constants.FAILED
Beispiel #2
0
    def run(self):
        """Main function for test case execution"""
        log = logger.get_log()

        try:
            log.info("Started executing {0} testcase".format(self.id))
            log.info("-" * 25 + " Initialize helper objects " + "-" * 25)
            auto_commcell = VirtualServerHelper.AutoVSACommcell(
                self.commcell, self.csdb)
            auto_client = VirtualServerHelper.AutoVSAVSClient(
                auto_commcell, self.client)
            auto_instance = VirtualServerHelper.AutoVSAVSInstance(
                auto_client, self.agent, self.instance)
            auto_instance.vm_user_name = self.tcinputs['VMUserName']
            auto_instance.vm_password = self.tcinputs['VMPassword']
            auto_backupset = VirtualServerHelper.AutoVSABackupset(
                auto_instance, self.backupset)
            auto_subclient = VirtualServerHelper.AutoVSASubclient(
                auto_backupset, self.subclient)

            log.info("-" * 25 + " Backup " + "-" * 25)
            backup_options = OptionsHelper.BackupOptions(auto_subclient)
            auto_subclient.backup(backup_options)

            log.info("-" * 25 + " Files restores " + "-" * 25)
            file_restore_options = OptionsHelper.FileLevelRestoreOptions(
                auto_subclient)
            auto_subclient.guest_file_restore(file_restore_options)

            log.info("-" * 25 + " Disk restores " + "-" * 25)
            disk_restore_options = OptionsHelper.DiskRestoreOptions(
                auto_subclient)
            #auto_subclient.disk_restore(disk_restore_options)

            log.info("-" * 15 + " FULL VM out of Place restores " + "-" * 15)
            vm_restore_options = OptionsHelper.FullVMRestoreOptions(
                auto_subclient, self)
            #auto_subclient.disk_restore(vm_restore_options)

        except Exception as exp:
            log.error('Failed with error: ' + str(exp))
            self.result_string = str(exp)
            self.status = constants.FAILED
Beispiel #3
0
    def run(self):
        """Main function for test case execution"""
        log = logger.get_log()

        try:
            log.info("Started executing {0} testcase".format(self.id))

            log.info(
                "-------------------Initialize helper objects------------------------------------"
            )
            auto_commcell = VirtualServerHelper.AutoVSACommcell(
                self.commcell, self.csdb)
            auto_client = VirtualServerHelper.AutoVSAVSClient(
                auto_commcell, self.client)
            auto_instance = VirtualServerHelper.AutoVSAVSInstance(
                auto_client, self.agent, self.instance)
            auto_backupset = VirtualServerHelper.AutoVSABackupset(
                auto_instance, self.backupset)
            auto_subclient = VirtualServerHelper.AutoVSASubclient(
                auto_backupset, self.subclient)

            # """
            log.info(
                "----------------------------------------Backup-----------------------------------"
            )
            backup_options = OptionsHelper.BackupOptions(auto_subclient)
            auto_subclient.backup(backup_options)

            # """

            # """

            log.info(
                "----------------------------------------VMConversion to VMware---------------------"
            )

            #create SDK and vshelper objects
            vclient = self.tcinputs["Destination_Virtualization_client"]
            self.client = self._commcell_object.clients.get(vclient)
            self.agent = self.client.agents.get('Virtual Server')
            instancekeys = next(iter(self.agent.instances._instances))
            self.instance = self.agent.instances.get(instancekeys)
            backupsetkeys = next(iter(self.instance.backupsets._backupsets))
            self.backupset = self.instance.backupsets.get(backupsetkeys)
            sckeys = next(iter(self.backupset.subclients._subclients))
            self.subclient = self.backupset.subclients.get(sckeys)
            dest_auto_commcell = VirtualServerHelper.AutoVSACommcell(
                self.commcell, self.csdb)
            dest_auto_client = VirtualServerHelper.AutoVSAVSClient(
                dest_auto_commcell, self.client)
            dest_auto_instance = VirtualServerHelper.AutoVSAVSInstance(
                dest_auto_client, self.agent, self.instance)
            dest_auto_backupset = VirtualServerHelper.AutoVSABackupset(
                dest_auto_instance, self.backupset)
            dest_auto_subclient = VirtualServerHelper.AutoVSASubclient(
                dest_auto_backupset, self.subclient)

            #perform VMConversion
            vm_restore_options = OptionsHelper.FullVMRestoreOptions(
                dest_auto_subclient, self)
            vm_restore_options.power_on_after_restore = True
            vm_restore_options.in_place_overwrite = True
            auto_subclient.subclient.full_vm_conversion_vmware(
                vclient,
                esx_host=vm_restore_options._host,
                datastore=vm_restore_options._datastore,
                overwrite=vm_restore_options.in_place_overwrite,
                power_on=vm_restore_options.power_on)

            #perform vmconversion validation
            for each_vm in auto_subclient.vm_list:
                auto_subclient.vm_restore_validation(auto_subclient)

            fs_restore_options = OptionsHelper.FileLevelRestoreOptions(
                auto_subclient)
            fs_restore_options.fbr_ma = self.tcinputs["FBRMA"]
            auto_subclient.guest_file_restore(fs_restore_options)

            # """

        except Exception as exp:
            log.error('Failed with error: ' + str(exp))
            self.result_string = str(exp)
            self.status = constants.FAILED
Beispiel #4
0
    def run(self):
        """Main function for test case execution"""
        log = logger.get_log()
        auto_subclient = None
        backup_options= None

        try:
            log.info("Started executing {0} testcase".format(self.id))

            log.info(
                "-------------------Initialize helper objects------------------------------------"
                )
            auto_commcell = VirtualServerHelper.AutoVSACommcell(self.commcell, self.csdb)
            auto_client = VirtualServerHelper.AutoVSAVSClient(auto_commcell, self.client)
            auto_instance = VirtualServerHelper.AutoVSAVSInstance(
                                                        auto_client, self.agent, self.instance)
            auto_backupset = VirtualServerHelper.AutoVSABackupset(auto_instance, self.backupset)
            auto_subclient = VirtualServerHelper.AutoVSASubclient(auto_backupset, self.subclient)

            # """
            log.info(
                "----------------------------------------Backup-----------------------------------"
                )
            backup_options = OptionsHelper.BackupOptions(auto_subclient)
            backup_options.backup_type = "INCREMENTAL"
            auto_subclient.backup(backup_options)

            # """
            #"""

            log.info(
                "----------------------------------------File Level restores---------------------")
            fs_restore_options = OptionsHelper.FileLevelRestoreOptions(auto_subclient)
            fs_restore_options.fbr_ma = "VSALINMA1"
            fs_restore_options.browse_ma = "fusionpro"
            auto_subclient.guest_file_restore(fs_restore_options)

            # """
            #"""

            log.info(
                "----------------------------------------FULL VM out of Place restores------------"
                )
            vm_restore_options = OptionsHelper.FullVMRestoreOptions(auto_subclient, self)
            vm_restore_options.unconditional_overwrite = True
            auto_subclient.virtual_machine_restore(vm_restore_options)

            # """
            # """
            log.info(
                "----------------------------------------FULL VM in  Place restores---------------"
                )
            vm_restore_options = OptionsHelper.FullVMRestoreOptions(auto_subclient, self)
            vm_restore_options.proxy_client = "fusionctrl"
            vm_restore_options.power_on_after_restore = True
            vm_restore_options.in_place_overwrite = True
            auto_subclient.virtual_machine_restore(vm_restore_options)

            # """

        except Exception as exp:
            log.error('Failed with error: ' + str(exp))
            self.result_string = str(exp)
            self.status = constants.FAILED

        #"""
        finally:
            if auto_subclient and backup_options:
                auto_subclient.cleanup_testdata(backup_options)
Beispiel #5
0
    def run(self):
        """Main function for test case execution"""
        self.log = logger.get_log()

        try:
            self.log.info("Started executing {0} testcase".format(self.id))
            subcontent = []
            tcdir = None

            self.log.info(
                "-------------------Initialize helper objects------------------------------------"
            )
            auto_commcell = VirtualServerHelper.AutoVSACommcell(
                self.commcell, self.csdb)
            auto_client = VirtualServerHelper.AutoVSAVSClient(
                auto_commcell, self.client)
            auto_instance = VirtualServerHelper.AutoVSAVSInstance(
                auto_client, self.agent, self.instance)
            # auto_instance.FBRMA = "fbrhv"
            auto_backupset = VirtualServerHelper.AutoVSABackupset(
                auto_instance, self.backupset)
            auto_subclient = VirtualServerHelper.AutoVSASubclient(
                auto_backupset, self.subclient)

            # """

            self.log.info(
                "--------------------SQL Discovery----------------------------------------------"
            )

            for vm in auto_subclient.vm_list:

                self.log.info("starting SQL discovery")

                auto_subclient.hvobj.VMs[vm].update_vm_info("All", True)
                sqluser = "******".format(
                    vm, auto_subclient.hvobj.VMs[vm].user_name)
                sqlpass = auto_subclient.hvobj.VMs[vm].password
                sqlmachine = Machine(vm, username=sqluser, password=sqlpass)
                sqlhelper = SQLHelper(self, vm, vm, sqluser, sqlpass)

                # """
                ransum = ""
                for i in range(1, 7):
                    ransum = ransum + random.choice(
                        "abcdefghijklmnopqrstuvwxyz")
                    dbname = ransum

                sqldump_file1 = "before_backup_full.txt"
                sqldump_file2 = "after_restore.txt"
                _drive = list(
                    auto_subclient.hvobj.VMs[vm].drive_list.keys())[0]
                testdata_path = "{0}:\\DumpData".format(_drive)
                tcdir = os.path.normpath(
                    os.path.join(testdata_path + '-' + ransum))

                noofdbs = 5
                nooffilegroupsforeachdb = 3
                nooffilesforeachfilegroup = 4
                nooftablesforeachfilegroup = 10
                noofrowsforeachtable = 50
                randomization = 100

                self.log.info("Started executing {0} testcase".format(self.id))
                if not sqlmachine.create_directory(tcdir):
                    raise Exception("Failed to create staging directory. ")

                for i in range(1, noofdbs + 1):
                    db = dbname + repr(i)
                    subcontent.append(db)

                # perform database check if exists, if so, drop it first.

                if sqlhelper.dbinit.check_database(dbname):
                    if not sqlhelper.dbinit.drop_databases(dbname):
                        raise Exception("Unable to drop the database")

                # """
                # create databases
                self.log.info("*" * 10 +
                              " Creating database [{0}] ".format(dbname) +
                              "*" * 10)
                if not sqlhelper.dbinit.db_new_create(
                        dbname, noofdbs, nooffilegroupsforeachdb,
                        nooffilesforeachfilegroup, nooftablesforeachfilegroup,
                        noofrowsforeachtable):
                    raise Exception("Failed to create databases.")

                # get table shuffled list
                returnstring, list1, list2, list3 = sqlhelper.dbvalidate.get_random_dbnames_and_filegroups(
                    randomization, noofdbs, nooffilegroupsforeachdb,
                    nooftablesforeachfilegroup)
                if not returnstring:
                    raise Exception(
                        "Error in while generating the random number.")

                # write the original database to file for comparison
                controller_machine = Machine(socket.getfqdn(),
                                             auto_commcell.commcell)
                controller_machine.create_directory(tcdir)
                if not sqlhelper.dbvalidate.dump_db_to_file(
                        os.path.join(tcdir, sqldump_file1), dbname, list1,
                        list2, list3, 'FULL'):
                    raise Exception("Failed to write database to file.")

                    # """

            self.log.info(
                "----------------------------------------Backup-----------------------------------"
            )
            backup_options = OptionsHelper.BackupOptions(auto_subclient)
            backup_options.Application_aware = True
            auto_subclient.backup(backup_options)

            #"""
            self.log.info(
                "---------------------------------------- VSA FULL VM out of Place restores------------"
            )
            vm_restore_options = OptionsHelper.FullVMRestoreOptions(
                auto_subclient, self)
            vm_restore_options.unconditional_overwrite = True
            auto_subclient.virtual_machine_restore(vm_restore_options)

            # """

            self.log.info(
                "---------------------------------------- Run SQL Restore and Validate it ------------"
            )

            # run restore in place job
            client = auto_commcell.commcell.clients.get(vm)
            agent = client.agents.get('SQL Server')
            _instance_keys = next(iter(agent.instances._instances))
            instance = agent.instances.get(_instance_keys)
            subclient = instance.subclients.get("default")
            self.instance = instance
            self.subclient = subclient

            sqlhelper_client = SQLHelper(self, client.client_name,
                                         instance.instance_name, sqluser,
                                         sqlpass)

            self.log.info("*" * 10 + " Run Restore in place " + "*" * 10)
            if not sqlhelper_client.sql_restore(subclient.content):
                raise Exception("Restore was not successful!")

            # write the restored database to file for comparison
            if not sqlhelper_client.dbvalidate.dump_db_to_file(
                    os.path.join(tcdir, sqldump_file2), dbname, list1, list2,
                    list3, 'FULL'):
                raise Exception("Failed to write database to file.")

            # compare original and restored databases
            self.log.info("*" * 10 + " Validating content " + "*" * 10)
            if not sqlhelper_client.dbvalidate.db_compare(
                    os.path.join(tcdir, sqldump_file1),
                    os.path.join(tcdir, sqldump_file2)):
                raise Exception("Failed to compare both files.")

        except Exception as exp:
            self.log.error('Failed with error: ' + str(exp))
            self.result_string = str(exp)
            self.status = constants.FAILED

        finally:
            if not tcdir:
                if controller_machine.check_directory_exists(tcdir):
                    controller_machine.remove_directory(tcdir)

            if not subcontent:
                for i in range(len(subcontent)):
                    sqlhelper.drop_databases(subcontent[i])
Beispiel #6
0
    def run(self):
        """Main function for test case execution"""
        log = logger.get_log()

        try:
            log.info("Started executing {0} testcase".format(self.id))

            log.info(
                "-------------------Initialize helper objects------------------------------------"
            )
            auto_commcell = VirtualServerHelper.AutoVSACommcell(
                self.commcell, self.csdb)
            auto_client = VirtualServerHelper.AutoVSAVSClient(
                auto_commcell, self.client)
            auto_instance = VirtualServerHelper.AutoVSAVSInstance(
                auto_client, self.agent, self.instance)
            auto_backupset = VirtualServerHelper.AutoVSABackupset(
                auto_instance, self.backupset)
            auto_subclient = VirtualServerHelper.AutoVSASubclient(
                auto_backupset, self.subclient)

            # """
            log.info(
                "----------------------------------------Backup-----------------------------------"
            )
            backup_options = OptionsHelper.BackupOptions(auto_subclient)
            auto_subclient.backup(backup_options)

            # """

            # """

            log.info(
                "----------------------------------------File Level restores---------------------"
            )
            fs_restore_options = OptionsHelper.FileLevelRestoreOptions(
                auto_subclient)
            fs_restore_options.fbr_ma = self.tcinputs["FBRMA"]
            auto_subclient.guest_file_restore(fs_restore_options)

            # """
            # """
            log.info(
                "----------------------------------------Disk restores----------------------------"
            )
            disk_restore_options = OptionsHelper.DiskRestoreOptions(
                auto_subclient)
            auto_subclient.disk_restore(disk_restore_options)

            # """
            # """
            log.info(
                "----------------------------------------FULL VM out of Place restores------------"
            )
            vm_restore_options = OptionsHelper.FullVMRestoreOptions(
                auto_subclient, self)
            vm_restore_options.unconditional_overwrite = True
            auto_subclient.virtual_machine_restore(vm_restore_options)

            # """
            # """
            log.info(
                "----------------------------------------FULL VM in  Place restores---------------"
            )
            vm_restore_options = OptionsHelper.FullVMRestoreOptions(
                auto_subclient, self)
            vm_restore_options.power_on_after_restore = True
            vm_restore_options.in_place_overwrite = True
            auto_subclient.virtual_machine_restore(vm_restore_options)

            # """

        except Exception as exp:
            log.error('Failed with error: ' + str(exp))
            self.result_string = str(exp)
            self.status = constants.FAILED
Beispiel #7
0
    def run(self):
        """Main function for test case execution"""
        log = logger.get_log()

        try:
            log.info("Started executing {0} testcase".format(self.id))

            log.info(
                "-------------------Initialize helper objects------------------------------------"
            )
            auto_commcell = VirtualServerHelper.AutoVSACommcell(
                self.commcell, self.csdb)
            auto_client = VirtualServerHelper.AutoVSAVSClient(
                auto_commcell, self.client)
            auto_instance = VirtualServerHelper.AutoVSAVSInstance(
                auto_client, self.agent, self.instance)
            # auto_instance.FBRMA = "fbrhv"
            auto_backupset = VirtualServerHelper.AutoVSABackupset(
                auto_instance, self.backupset)
            auto_subclient = VirtualServerHelper.AutoVSASubclient(
                auto_backupset, self.subclient)

            job_history = auto_subclient._get_all_backup_jobs()

            jobs_to_restore = []
            for cycle in job_history.keys():
                if '64' in job_history[cycle].keys():
                    job_to_restore = list((job_history[cycle]['64']).keys())[0]
                    selective_job = random.choice(
                        job_history[cycle]['64'][job_to_restore])
                elif '1' in job_history[cycle].keys():
                    job_to_restore = list((job_history[cycle]['1']).keys())[0]
                    selective_job = random.choice(
                        job_history[cycle]['1'][job_to_restore])

                jobs_to_restore.append(job_to_restore)
                jobs_to_restore.append(selective_job)
                if '2' in job_history[cycle].keys():
                    job_to_restore = random.choice(
                        list((job_history[cycle]['2']).keys()))
                    selective_job = random.choice(
                        job_history[cycle]['2'][job_to_restore])
                    jobs_to_restore.append(job_to_restore)
                    jobs_to_restore.append(selective_job)

            try:
                jobs_to_restore.remove('0')
            except ValueError:
                pass

            for job in jobs_to_restore:
                vm_restore_options = OptionsHelper.FullVMRestoreOptions(
                    auto_subclient, self)
                vm_restore_options.unconditional_overwrite = True
                vm_restore_options.power_on_after_restore = True
                vm_restore_options.restore_backup_job = job
                log.info("*" * 10 +
                         "Submitting full VM restore for job {0} ".format(
                             str(job)) + "*" * 10)
                auto_subclient.virtual_machine_restore(vm_restore_options)

        except Exception as exp:
            log.error('Failed with error: ' + str(exp))
            self.result_string = str(exp)
            self.status = constants.FAILED