Ejemplo n.º 1
0
    def test_mkdir(self):
        def fake_call_method(module, method, *args, **kwargs):
            self.assertEqual('MakeDirectory', method)
            name = kwargs.get('name')
            self.assertEqual('fake-path', name)
            datacenter = kwargs.get('datacenter')
            self.assertEqual('fake-dc-ref', datacenter)
            createParentDirectories = kwargs.get('createParentDirectories')
            self.assertTrue(createParentDirectories)

        with mock.patch.object(self.session, '_call_method', fake_call_method):
            ds_util.mkdir(self.session, 'fake-path', 'fake-dc-ref')
Ejemplo n.º 2
0
    def test_mkdir(self):
        def fake_call_method(module, method, *args, **kwargs):
            self.assertEqual('MakeDirectory', method)
            name = kwargs.get('name')
            self.assertEqual('fake-path', name)
            datacenter = kwargs.get('datacenter')
            self.assertEqual('fake-dc-ref', datacenter)
            createParentDirectories = kwargs.get('createParentDirectories')
            self.assertTrue(createParentDirectories)

        with mock.patch.object(self.session, '_call_method',
                               fake_call_method):
            ds_util.mkdir(self.session, 'fake-path', 'fake-dc-ref')
Ejemplo n.º 3
0
    def test_mkdir(self):
        def fake_call_method(module, method, *args, **kwargs):
            self.assertEqual("MakeDirectory", method)
            name = kwargs.get("name")
            self.assertEqual("[ds] fake/path", name)
            datacenter = kwargs.get("datacenter")
            self.assertEqual("fake-dc-ref", datacenter)
            createParentDirectories = kwargs.get("createParentDirectories")
            self.assertTrue(createParentDirectories)

        with mock.patch.object(self.session, "_call_method", fake_call_method):
            ds_path = ds_util.DatastorePath("ds", "fake/path")
            ds_util.mkdir(self.session, ds_path, "fake-dc-ref")
Ejemplo n.º 4
0
    def _age_cached_images(self, context, datastore, dc_info, ds_path):
        """Ages cached images."""
        age_seconds = CONF.remove_unused_original_minimum_age_seconds
        unused_images = self.originals - self.used_images
        ds_browser = self._get_ds_browser(datastore['ref'])
        for image in unused_images:
            path = self.timestamp_folder_get(ds_path, image)
            # Lock to ensure that the spawn will not try and access a image
            # that is currently being deleted on the datastore.
            with lockutils.lock(path,
                                lock_file_prefix='nova-vmware-ts',
                                external=True):
                ts = self._get_timestamp(ds_browser, path)
                if not ts:
                    ts_path = '%s/%s' % (path, self._get_timestamp_filename())
                    try:
                        ds_util.mkdir(self._session, ts_path, dc_info.ref)
                    except error_util.FileAlreadyExistsException:
                        LOG.debug(_("Timestamp already exists."))
                    LOG.info(
                        _("Image %s is no longer used by this node. "
                          "Pending deletion!"), image)
                else:
                    dt = self._get_datetime_from_filename(ts)
                    if timeutils.is_older_than(dt, age_seconds):
                        LOG.info(_("Image %s is no longer used. "
                                   "Deleting!"), path)
                        # Image has aged - delete the image ID folder
                        self._folder_delete(path, dc_info.ref)

        # If the image is used and the timestamp file exists then we delete
        # the timestamp.
        for image in self.used_images:
            path = self.timestamp_folder_get(ds_path, image)
            with lockutils.lock(path,
                                lock_file_prefix='nova-vmware-ts',
                                external=True):
                self.timestamp_cleanup(dc_info.ref, ds_browser,
                                       datastore['ref'], datastore['name'],
                                       path)
Ejemplo n.º 5
0
    def _age_cached_images(self, context, datastore, dc_info,
                           ds_path):
        """Ages cached images."""
        age_seconds = CONF.remove_unused_original_minimum_age_seconds
        unused_images = self.originals - self.used_images
        ds_browser = self._get_ds_browser(datastore['ref'])
        for image in unused_images:
            path = self.timestamp_folder_get(ds_path, image)
            # Lock to ensure that the spawn will not try and access a image
            # that is currently being deleted on the datastore.
            with lockutils.lock(path, lock_file_prefix='nova-vmware-ts',
                                external=True):
                ts = self._get_timestamp(ds_browser, path)
                if not ts:
                    ts_path = '%s/%s' % (path,
                                         self._get_timestamp_filename())
                    try:
                        ds_util.mkdir(self._session, ts_path, dc_info.ref)
                    except error_util.FileAlreadyExistsException:
                        LOG.debug(_("Timestamp already exists."))
                    LOG.info(_("Image %s is no longer used by this node. "
                               "Pending deletion!"), image)
                else:
                    dt = self._get_datetime_from_filename(ts)
                    if timeutils.is_older_than(dt, age_seconds):
                        LOG.info(_("Image %s is no longer used. "
                                   "Deleting!"), path)
                        # Image has aged - delete the image ID folder
                        self._folder_delete(path, dc_info.ref)

        # If the image is used and the timestamp file exists then we delete
        # the timestamp.
        for image in self.used_images:
            path = self.timestamp_folder_get(ds_path, image)
            with lockutils.lock(path, lock_file_prefix='nova-vmware-ts',
                                external=True):
                self.timestamp_cleanup(dc_info.ref, ds_browser,
                                       datastore['ref'], datastore['name'],
                                       path)