Exemplo n.º 1
0
    def testAttachAsOpts(self):
        err = vmdk_ops.createVMDK(vm_name=self.vm_name,
                                  vmdk_path=self.name,
                                  vol_name=self.volName,
                                  opts=self.invalid_attach_as_choice)
        self.assertNotEqual(err, None, err)

        err = vmdk_ops.createVMDK(vm_name=self.vm_name,
                                  vmdk_path=self.name,
                                  vol_name=self.volName,
                                  opts=self.invalid_attach_as_opt)
        self.assertNotEqual(err, None, err)

        err = vmdk_ops.createVMDK(vm_name=self.vm_name,
                                  vmdk_path=self.name,
                                  vol_name=self.volName,
                                  opts=self.valid_attach_as_opt_1)
        self.assertEqual(err, None, err)

        err = vmdk_ops.removeVMDK(self.name)
        self.assertEqual(err, None, err)

        err = vmdk_ops.createVMDK(vm_name=self.vm_name,
                                  vmdk_path=self.name,
                                  vol_name=self.volName,
                                  opts=self.valid_attach_as_opt_2)
        self.assertEqual(err, None, err)

        err = vmdk_ops.removeVMDK(self.name)
        self.assertEqual(err, None, err)
Exemplo n.º 2
0
    def testAttachAsOpts(self):
        err = vmdk_ops.createVMDK(vm_name=self.vm_name,
                                  vmdk_path=self.name,
                                  vol_name=self.volName,
                                  opts=self.invalid_attach_as_choice)
        self.assertNotEqual(err, None, err)

        err = vmdk_ops.createVMDK(vm_name=self.vm_name,
                                  vmdk_path=self.name,
                                  vol_name=self.volName,
                                  opts=self.invalid_attach_as_opt)
        self.assertNotEqual(err, None, err)

        err = vmdk_ops.createVMDK(vm_name=self.vm_name,
                                  vmdk_path=self.name,
                                  vol_name=self.volName,
                                  opts=self.valid_attach_as_opt_1)
        self.assertEqual(err, None, err)

        err = vmdk_ops.removeVMDK(self.name)
        self.assertEqual(err, None, err)

        err = vmdk_ops.createVMDK(vm_name=self.vm_name,
                                  vmdk_path=self.name,
                                  vol_name=self.volName,
                                  opts=self.valid_attach_as_opt_2)
        self.assertEqual(err, None, err)

        err = vmdk_ops.removeVMDK(self.name)
        self.assertEqual(err, None, err)
    def testPolicy(self):
        # info for testPolicy
        testInfo = [
            #    size     policy   expected success?
            ["2000kb", "good", True, "zeroedthick"],
            ["14000pb", "good", False, "zeroedthick"],
            ["bad size", "good", False, "eagerzeroedthick"],
            ["100mb", "impossible", True, "eagerzeroedthick"],
            ["100mb", "good", True, "thin"],
        ]
        path = vsan_info.get_vsan_dockvols_path()
        i = 0
        for unit in testInfo:
            vol_name = '{0}{1}'.format(self.volName, i)
            vmdk_path = vmdk_utils.get_vmdk_path(path, vol_name)
            i = i + 1
            # create a volume with requests size/policy and check vs expected result
            err = vmdk_ops.createVMDK(vm_name=self.vm_name,
                                      vmdk_path=vmdk_path,
                                      vol_name=vol_name,
                                      opts={
                                          volume_kv.VSAN_POLICY_NAME: unit[1],
                                          volume_kv.SIZE: unit[0],
                                          volume_kv.DISK_ALLOCATION_FORMAT:
                                          unit[3]
                                      })
            self.assertEqual(err == None, unit[2], err)

            # clean up should fail if the created should have failed.
            err = vmdk_ops.removeVMDK(vmdk_path)
            self.assertEqual(err == None, unit[2], err)
    def testAccessOpts(self):
        err = vmdk_ops.createVMDK(vm_name=self.vm_name,
                                  vmdk_path=self.name,
                                  vol_name=self.volName,
                                  opts=self.invalid_access_choice)
        logging.info(err)
        self.assertNotEqual(err, None, err)

        err = vmdk_ops.createVMDK(vm_name=self.vm_name,
                                  vmdk_path=self.name,
                                  vol_name=self.volName,
                                  opts=self.invalid_access_opt)
        logging.info(err)
        self.assertNotEqual(err, None, err)

        err = vmdk_ops.createVMDK(vm_name=self.vm_name,
                                  vmdk_path=self.name,
                                  vol_name=self.volName,
                                  opts=self.valid_access_opt)
        logging.info(err)
        self.assertEqual(err, None, err)

        err = vmdk_ops.removeVMDK(self.name)
        logging.info(err)
        self.assertEqual(err, None, err)
    def testPolicy(self):
        # info for testPolicy
        testInfo = [
            #    size     policy   expected success?
            ["2000kb", "good", True],
            ["14000pb", "good", False],
            ["bad size", "good", False],
            ["100mb", "impossible", True],
            ["100mb", "good", True],
        ]
        path = vmdk_utils.get_vsan_dockvols_path()
        i = 0
        for unit in testInfo:
            vol_name = '{0}{1}'.format(self.volName, i)
            vmdk_path = vmdk_ops.getVmdkName(path,vol_name)
            i = i+1
            # create a volume with requestes size/policy and check vs expected result
            err = vmdk_ops.createVMDK(vm_name=self.vm_name,
                                      vmdk_path=vmdk_path,
                                      vol_name=vol_name,
                                      opts={volume_kv.VSAN_POLICY_NAME: unit[1],
                                            volume_kv.SIZE: unit[0]})
            self.assertEqual(err == None, unit[2], err)

            # clean up should fail if the created should have failed.
            err = vmdk_ops.removeVMDK(vmdk_path)
            self.assertEqual(err == None, unit[2], err)
Exemplo n.º 6
0
    def testBadOpts(self):
        err = vmdk_ops.createVMDK(vm_name=self.vm_name,
                                  vmdk_path=self.name,
                                  vol_name=self.volName,
                                  opts=self.badOpts)
        self.assertNotEqual(err, None, err)

        err = vmdk_ops.removeVMDK(self.name)
        self.assertNotEqual(err, None, err)
Exemplo n.º 7
0
    def cleanup(self):
        # remove VM
        si = vmdk_ops.get_si()
        self.remove_vm(si, self.vm_name)

        for v in self.get_testvols():
            self.assertEqual(
                None,
                vmdk_ops.removeVMDK(os.path.join(v['path'], v['filename'])))
Exemplo n.º 8
0
    def testBadOpts(self):
        err = vmdk_ops.createVMDK(vm_name=self.vm_name,
                                  vmdk_path=self.name,
                                  vol_name=self.volName,
                                  opts=self.badOpts)
        self.assertNotEqual(err, None, err)

        err = vmdk_ops.removeVMDK(self.name)
        self.assertNotEqual(err, None, err)
Exemplo n.º 9
0
    def cleanup(self):
        # remove VM
        si = vmdk_ops.get_si()
        self.remove_vm(si, self.vm_name)

        for v in self.get_testvols():
            self.assertEqual(
                None,
                vmdk_ops.removeVMDK(os.path.join(v['path'], v['filename'])))
Exemplo n.º 10
0
    def cleanup(self):
        # remove VM
        if not vmdk_ops.si:
            vmdk_ops.connectLocal()
        self.remove_vm(vmdk_ops.si, self.vm_name)

        for v in self.get_testvols():
            self.assertEqual(
                None,
                vmdk_ops.removeVMDK(os.path.join(v['path'], v['filename'])))
Exemplo n.º 11
0
    def _remove_volumes_for_tenant(self, tenant_id):
        """ Delete all volumes belongs to this tenant.

            Do not use it outside of removing a tenant.

        """
        try:
            cur = self.conn.execute("SELECT name FROM tenants WHERE id = ?",
                                    (tenant_id, ))
            result = cur.fetchone()
        except sqlite3.Error as e:
            logging.error("Error %s when querying from tenants table", e)
            return str(e)

        error_info = ""
        if result:
            logging.debug("remove_volumes_for_tenant: %s %s", tenant_id,
                          result)
            tenant_name = result[0]
            vmdks = vmdk_utils.get_volumes(tenant_name)
            # Delete all volumes for this tenant.
            dir_paths = set()
            for vmdk in vmdks:
                vmdk_path = os.path.join(vmdk['path'],
                                         "{0}".format(vmdk['filename']))
                dir_paths.add(vmdk['path'])
                logging.debug("path=%s filename=%s", vmdk['path'],
                              vmdk['filename'])
                logging.debug("Deleting volume path%s", vmdk_path)
                err = vmdk_ops.removeVMDK(vmdk_path)
                if err:
                    logging.error("remove vmdk %s failed with error %s",
                                  vmdk_path, err)
                    error_info += err

            # Delete path /vmfs/volumes/datastore_name/tenant_name
            logging.debug("Deleting dir paths %s", dir_paths)
            for path in list(dir_paths):
                try:
                    os.rmdir(path)
                except os.error as e:
                    msg = "remove dir {0} failed with error {1}".format(
                        path, e)
                    logging.error(msg)
                    error_info += msg

        err = self.remove_volumes_from_volume_table(tenant_id)
        if err:
            logging.error("Failed to remove volumes from database %s", err)
            error_info += err

        if error_info:
            return error_info

        return None
Exemplo n.º 12
0
 def testCreateDelete(self):
     err = vmdk_ops.createVMDK(vm_name=self.vm_name,
                               vmdk_path=self.name,
                               vol_name=self.volName)
     self.assertEqual(err, None, err)
     self.assertEqual(os.path.isfile(self.name), True,
                      "VMDK {0} is missing after create.".format(self.name))
     err = vmdk_ops.removeVMDK(self.name)
     self.assertEqual(err, None, err)
     self.assertEqual(
         os.path.isfile(self.name), False,
         "VMDK {0} is still present after delete.".format(self.name))
 def testCreateDelete(self):
     err = vmdk_ops.createVMDK(vm_name=self.vm_name,
                               vmdk_path=self.name,
                               vol_name=self.volName)
     self.assertEqual(err, None, err)
     self.assertEqual(
         os.path.isfile(self.name), True,
         "VMDK {0} is missing after create.".format(self.name))
     err = vmdk_ops.removeVMDK(self.name)
     self.assertEqual(err, None, err)
     self.assertEqual(
         os.path.isfile(self.name), False,
         "VMDK {0} is still present after delete.".format(self.name))
Exemplo n.º 14
0
 def cleanup(self):
     for v in self.get_testvols():
         self.assertEqual(
             None,
             vmdk_ops.removeVMDK(os.path.join(v['path'], v['filename'])))
 def tearDown(self):
     """clean up after each test (method) in this class"""
     err = vmdk_ops.removeVMDK(self.VMDK_PATH)
     self.assertEqual(err, None, err)
     pyVim.connect.Disconnect(self.si)
Exemplo n.º 16
0
 def tearDown(self):
     vmdk_ops.removeVMDK(self.name)
     self.vmdk = None
     for n in self.policy_names:
         vsan_policy.delete(n)
Exemplo n.º 17
0
            logging.error("Error %s when querying from tenants table", e)
            return str(e)

        error_info = ""
        if result:    
            logging.debug("remove_volumes_for_tenant: %s %s", tenant_id, result)
            tenant_name = result[0]
            vmdks = vmdk_utils.get_volumes(tenant_name)
            # Delete all volumes for this tenant. 
            dir_paths = set()
            for vmdk in vmdks:
                vmdk_path = os.path.join(vmdk['path'], "{0}".format(vmdk['filename']))
                dir_paths.add(vmdk['path'])
                logging.debug("path=%s filename=%s", vmdk['path'], vmdk['filename'])    
                logging.debug("Deleting volume path%s", vmdk_path)
                err = vmdk_ops.removeVMDK(vmdk_path)
                if err:
                    logging.error("remove vmdk %s failed with error %s", vmdk_path, err)
                    error_info += err
            
            # Delete path /vmfs/volumes/datastore_name/tenant_name
            logging.debug("Deleting dir paths %s", dir_paths)
            for path in list(dir_paths):
                try:
                    os.rmdir(path)
                except os.error as e:
                    msg = "remove dir %s failed with error %s".format(dir_path, e)
                    logging.error(msg)
                    error_info += msg

        err = self.remove_volumes_from_volume_table(tenant_id)
Exemplo n.º 18
0
 def tearDown(self):
     vmdk_ops.removeVMDK(self.name)
     self.vmdk = None
     for n in self.policy_names:
         vsan_policy.delete(n)
 def cleanup(self):
     for v in self.get_testvols():
         self.assertEqual(
             None,
             vmdk_ops.removeVMDK(os.path.join(v['path'], v['filename'])))
Exemplo n.º 20
0
            logging.error("Error %s when querying from tenants table", e)
            return str(e)

        logging.debug("remove_volumes_for_tenant: %s %s", tenant_id, result)
        tenant_name = result[0]
        vmdks = vmdk_utils.get_volumes(tenant_name)
        # Delete all volumes for this tenant.
        dir_path = None
        for vmdk in vmdks:
            vmdk_path = os.path.join(vmdk['path'],
                                     "{0}".format(vmdk['filename']))
            if not dir_path:
                dir_path = vmdk['path']
            print("path=%s filename=%s", vmdk['path'], vmdk['filename'])
            logging.debug("Deleting volume path%s", vmdk_path)
            err = vmdk_ops.removeVMDK(vmdk_path)
            if err:
                logging.error("remove vmdk %s failed with error %s", vmdk_path,
                              err)
                if err:
                    return err

        # Delete path /vmfs/volumes/datastore_name/tenant_name
        logging.debug("Deleting dir path%s", dir_path)
        try:
            os.rmdir(dir_path)
        except os.error as e:
            logging.error("remove dir %s failed with error %s", dir_path, e)
            return str(e)

        error_info = self.remove_volumes_from_volume_table(tenant_id)
 def tearDown(self):
     """clean up after each test (method) in this class"""
     err = vmdk_ops.removeVMDK(self.VMDK_PATH)
     self.assertEqual(err, None, err)
     pyVim.connect.Disconnect(self.si)
    def _remove_volumes_for_tenant(self, tenant_id):
        """ Delete all volumes belongs to this tenant.

            Do not use it outside of removing a tenant.

        """
        try:
            cur = self.conn.execute("SELECT name FROM tenants WHERE id = ?",
                                    (tenant_id, ))
            result = cur.fetchone()
        except sqlite3.Error as e:
            logging.error("Error %s when querying from tenants table", e)
            return str(e)

        error_msg = ""
        if result:
            logging.debug("remove_volumes_for_tenant: %s %s", tenant_id,
                          result)
            tenant_name = result[0]
            vmdks = vmdk_utils.get_volumes(tenant_name)
            # Delete all volumes for this tenant.
            dir_paths = set()
            for vmdk in vmdks:
                vmdk_path = os.path.join(vmdk['path'],
                                         "{0}".format(vmdk['filename']))
                dir_paths.add(vmdk['path'])
                logging.debug("path=%s filename=%s", vmdk['path'],
                              vmdk['filename'])
                logging.debug("Deleting volume path%s", vmdk_path)
                datastore_url = vmdk_utils.get_datastore_url(vmdk['datastore'])
                err = vmdk_ops.removeVMDK(
                    vmdk_path=vmdk_path,
                    vol_name=vmdk_utils.strip_vmdk_extension(vmdk['filename']),
                    vm_name=None,
                    tenant_uuid=tenant_id,
                    datastore_url=datastore_url)
                if err:
                    logging.error("remove vmdk %s failed with error %s",
                                  vmdk_path, err)
                    error_msg += str(err)

            VOL_RM_LOG_PREFIX = "Tenant <name> %s removal: "
            # delete the symlink /vmfs/volume/datastore_name/tenant_name
            # which point to /vmfs/volumes/datastore_name/tenant_uuid
            for (datastore, url, path) in vmdk_utils.get_datastores():
                dockvol_path, tenant_path = get_dockvol_path_tenant_path(
                    datastore_name=datastore, tenant_id=tenant_id)
                logging.debug(
                    VOL_RM_LOG_PREFIX + "try to remove symlink to %s",
                    tenant_name, tenant_path)

                if os.path.isdir(tenant_path):
                    exist_symlink_path = os.path.join(dockvol_path,
                                                      tenant_name)
                    if os.path.isdir(exist_symlink_path):
                        os.remove(exist_symlink_path)
                        logging.debug(
                            VOL_RM_LOG_PREFIX + "removing symlink %s",
                            tenant_name, exist_symlink_path)

            # Delete path /vmfs/volumes/datastore_name/tenant_uuid
            logging.debug("Deleting dir paths %s", dir_paths)
            for path in list(dir_paths):
                try:
                    os.rmdir(path)
                except os.error as e:
                    msg = "remove dir {0} failed with error {1}".format(
                        path, e)
                    logging.error(msg)
                    error_msg += str(err)

        err = self.remove_volumes_from_volumes_table(tenant_id)
        if err:
            logging.error("Failed to remove volumes from database %s", err)
            error_msg += str(err)

        if error_msg:
            return error_msg

        return None