Example #1
0
    def __init__(self, root, drive, account, logger, **kwargs):
        super(DiskAccount, self).__init__(root, drive, account, logger,
                                          **kwargs)

        if self.account == 'gsexpiring':
            # Do not bother updating object count, container count and bytes
            # used. Return immediately before metadata validation and
            # creation happens.
            info = do_stat(self.datadir)
            if info and stat.S_ISDIR(info.st_mode):
                self._dir_exists = True
            semi_fake_md = {
                'X-Object-Count': (0, 0),
                'X-Container-Count': (0, 0),
                'X-Timestamp': ((normalize_timestamp(info.st_ctime)), 0),
                'X-Type': ('Account', 0),
                'X-PUT-Timestamp': ((normalize_timestamp(info.st_mtime)), 0),
                'X-Bytes-Used': (0, 0)
            }
            self.metadata = semi_fake_md
            return

        # Since accounts should always exist (given an account maps to a
        # gluster volume directly, and the mount has already been checked at
        # the beginning of the REST API handling), just assert that that
        # assumption still holds.
        assert self._dir_exists_read_metadata()
        assert self._dir_exists

        if not self.metadata or not validate_account(self.metadata):
            create_account_metadata(self.datadir)
            self.metadata = _read_metadata(self.datadir)
Example #2
0
 def test_validate_account_good_type(self):
     md = {utils.X_TYPE: (utils.ACCOUNT, 0),
           utils.X_TIMESTAMP: ('na', 0),
           utils.X_PUT_TIMESTAMP: ('na', 0),
           utils.X_OBJECTS_COUNT: ('na', 0),
           utils.X_BYTES_USED: ('na', 0),
           utils.X_CONTAINER_COUNT: ('na', 0)}
     ret = utils.validate_account(md)
     assert ret
Example #3
0
 def test_validate_account_bad_type(self):
     md = {
         utils.X_TYPE: ("bad", 0),
         utils.X_TIMESTAMP: ("na", 0),
         utils.X_PUT_TIMESTAMP: ("na", 0),
         utils.X_OBJECTS_COUNT: ("na", 0),
         utils.X_BYTES_USED: ("na", 0),
         utils.X_CONTAINER_COUNT: ("na", 0),
     }
     ret = utils.validate_account(md)
     assert not ret
Example #4
0
 def test_validate_account_good_type(self):
     md = {
         utils.X_TYPE: (utils.ACCOUNT, 0),
         utils.X_TIMESTAMP: ('na', 0),
         utils.X_PUT_TIMESTAMP: ('na', 0),
         utils.X_OBJECTS_COUNT: ('na', 0),
         utils.X_BYTES_USED: ('na', 0),
         utils.X_CONTAINER_COUNT: ('na', 0)
     }
     ret = utils.validate_account(md)
     assert ret
Example #5
0
    def __init__(self, root, drive, account, logger):
        super(DiskAccount, self).__init__(root, drive, account, logger)

        # Since accounts should always exist (given an account maps to a
        # gluster volume directly, and the mount has already been checked at
        # the beginning of the REST API handling), just assert that that
        # assumption still holds.
        assert self._dir_exists_read_metadata()
        assert self._dir_exists

        if not self.metadata or not validate_account(self.metadata):
            create_account_metadata(self.datadir)
            self.metadata = _read_metadata(self.datadir)
Example #6
0
 def __init__(self,
              path,
              account,
              container,
              logger,
              uid=DEFAULT_UID,
              gid=DEFAULT_GID):
     self.root = path
     if container:
         self.container = container
     else:
         self.container = None
     if self.container:
         self.datadir = os.path.join(path, account, self.container)
     else:
         self.datadir = os.path.join(path, account)
     # Note that the account name has a one-to-one mapping to the gluster
     # mount point, or volume name.
     self.account = account
     assert logger is not None
     self.logger = logger
     self.metadata = {}
     self.container_info = None
     self.object_info = None
     self.uid = int(uid)
     self.gid = int(gid)
     self.db_file = _db_file
     self.dir_exists = os.path.exists(self.datadir)
     if self.dir_exists:
         try:
             self.metadata = _read_metadata(self.datadir)
         except EOFError:
             create_container_metadata(self.datadir)
     else:
         return
     if self.container:
         if not self.metadata:
             create_container_metadata(self.datadir)
             self.metadata = _read_metadata(self.datadir)
         else:
             if not validate_container(self.metadata):
                 create_container_metadata(self.datadir)
                 self.metadata = _read_metadata(self.datadir)
     else:
         if not self.metadata:
             create_account_metadata(self.datadir)
             self.metadata = _read_metadata(self.datadir)
         else:
             if not validate_account(self.metadata):
                 create_account_metadata(self.datadir)
                 self.metadata = _read_metadata(self.datadir)
Example #7
0
    def __init__(self, root, drive, account, logger, **kwargs):
        super(DiskAccount, self).__init__(root, drive, account, logger,
                                          **kwargs)

        # Since accounts should always exist (given an account maps to a
        # gluster volume directly, and the mount has already been checked at
        # the beginning of the REST API handling), just assert that that
        # assumption still holds.
        assert self._dir_exists_read_metadata()
        assert self._dir_exists

        if not self.metadata or not validate_account(self.metadata):
            create_account_metadata(self.datadir)
            self.metadata = _read_metadata(self.datadir)
Example #8
0
 def _initialize(self):
     if self.container:
         if not self.metadata:
             create_container_metadata(self.datadir)
             self.metadata = _read_metadata(self.datadir)
         else:
             if not validate_container(self.metadata):
                 create_container_metadata(self.datadir)
                 self.metadata = _read_metadata(self.datadir)
     else:
         if not self.metadata:
             create_account_metadata(self.datadir)
             self.metadata = _read_metadata(self.datadir)
         else:
             if not validate_account(self.metadata):
                 create_account_metadata(self.datadir)
                 self.metadata = _read_metadata(self.datadir)
Example #9
0
 def __init__(self, path, account, container, logger,
              uid=DEFAULT_UID, gid=DEFAULT_GID):
     self.root = path
     if container:
         self.container = container
     else:
         self.container = None
     if self.container:
         self.datadir = os.path.join(path, account, self.container)
     else:
         self.datadir = os.path.join(path, account)
     # Note that the account name has a one-to-one mapping to the gluster
     # mount point, or volume name.
     self.account = account
     assert logger is not None
     self.logger = logger
     self.metadata = {}
     self.container_info = None
     self.object_info = None
     self.uid = int(uid)
     self.gid = int(gid)
     self.db_file = _db_file
     self.dir_exists = os.path.exists(self.datadir)
     if self.dir_exists:
         try:
             self.metadata = _read_metadata(self.datadir)
         except EOFError:
             create_container_metadata(self.datadir)
     else:
         return
     if self.container:
         if not self.metadata:
             create_container_metadata(self.datadir)
             self.metadata = _read_metadata(self.datadir)
         else:
             if not validate_container(self.metadata):
                 create_container_metadata(self.datadir)
                 self.metadata = _read_metadata(self.datadir)
     else:
         if not self.metadata:
             create_account_metadata(self.datadir)
             self.metadata = _read_metadata(self.datadir)
         else:
             if not validate_account(self.metadata):
                 create_account_metadata(self.datadir)
                 self.metadata = _read_metadata(self.datadir)
Example #10
0
 def __init__(self, path, drive, account, container, logger,
              uid=DEFAULT_UID, gid=DEFAULT_GID):
     self.root = path
     if container:
         self.container = container
     else:
         self.container = None
     if self.container:
         self.datadir = os.path.join(path, drive, self.container)
     else:
         self.datadir = os.path.join(path, drive)
     self.account = account
     assert logger is not None
     self.logger = logger
     self.metadata = {}
     self.container_info = None
     self.object_info = None
     self.uid = int(uid)
     self.gid = int(gid)
     self.db_file = _db_file
     self.dir_exists = os.path.exists(self.datadir)
     if self.dir_exists:
         try:
             self.metadata = _read_metadata(self.datadir)
         except EOFError:
             create_container_metadata(self.datadir)
     else:
         return
     if self.container:
         if not self.metadata:
             create_container_metadata(self.datadir)
             self.metadata = _read_metadata(self.datadir)
         else:
             if not validate_container(self.metadata):
                 create_container_metadata(self.datadir)
                 self.metadata = _read_metadata(self.datadir)
     else:
         if not self.metadata:
             create_account_metadata(self.datadir)
             self.metadata = _read_metadata(self.datadir)
         else:
             if not validate_account(self.metadata):
                 create_account_metadata(self.datadir)
                 self.metadata = _read_metadata(self.datadir)
Example #11
0
 def test_validate_account_missing_keys(self):
     ret = utils.validate_account({'foo': 'bar'})
     assert not ret
Example #12
0
 def test_validate_account_empty(self):
     ret = utils.validate_account({})
     assert not ret
Example #13
0
 def test_validate_account_missing_keys(self):
     ret = utils.validate_account({"foo": "bar"})
     assert not ret
Example #14
0
 def test_validate_account_missing_keys(self):
     ret = utils.validate_account({'foo': 'bar'})
     assert not ret
Example #15
0
 def test_validate_account_empty(self):
     ret = utils.validate_account({})
     assert not ret