Exemplo n.º 1
0
 def wait_for(
         self, stat, expected, blacklisted=None, poll_interval=3,
         timeout=15,
 ):
     """
     :param stat: list or tuple of keys
     :param expected: expected value
     :param blacklisted: list or tuple of blacklisted values
     :param poll_interval: number of requests per second
     :param timeout: timeout in seconds
     :return: actual value if match is found
     Raises:
         MissingDataIdException: If '@odata.id' is missing in the content
         TimedOutError: If timeout is exceeded.
         FailedError: If value matches one of the fail values
     """
     if "@odata.id" not in self._content:
         raise MissingOidException(
             "Element does not have '@odata.id' attribute, cannot wait "
             "for a stat inside inner object"
         )
     start_time = time.time()
     while time.time() <= start_time + timeout:
         self.refresh()
         actual_value = reduce(operator.getitem, stat, self._content)
         if actual_value == expected:
             return True
         if blacklisted and actual_value in blacklisted:
             raise BlacklistedValueException(
                 "Detected blacklisted value '{}'".format(actual_value)
             )
         time.sleep(poll_interval)
     raise TimedOutException(
         "Could not wait for stat {} in time".format(stat)
     )
Exemplo n.º 2
0
    def refresh(self):
        try:
            oid = self._content["@odata.id"]
        except KeyError:
            raise MissingOidException("Cannot refresh resource without @odata.id")

        self._connector.reset(oid)
        self._headers, self._content = self._init_from_oid(oid)
Exemplo n.º 3
0
 def delete(self):
     """
     Perform a DELETE at the resource.
     """
     path = self._content.get("@odata.id")
     if not path:
         raise MissingOidException("The resource cannot be DELETEd.")
     return self._connector.delete(path)
Exemplo n.º 4
0
    def patch(self, payload):
        """
        Perform a PATCH at the resource with the given payload.

        Args:
          payload: The contents of the POST payload.
        """
        path = self._content.get("@odata.id")
        if not path:
            raise MissingOidException("The resource cannot be PATCHed.")
        return self._connector.patch(path, payload=payload)
Exemplo n.º 5
0
    def refresh(self):
        try:
            oid = self._content["@odata.id"]
        except KeyError:
            raise MissingOidException("Cannot refresh resource without @odata.id")

        self._connector.reset(oid)

        if self._is_lazy:
            self._headers, self._content = {}, {"@odata.id": oid}
            self._is_stub = True
        else:
            self._headers, self._content = self._init_from_oid(oid)
Exemplo n.º 6
0
    def put(self, path=None, payload=None):
        """
        Perform a PUT at the resource or selected path with the given payload.

        Args:
          path: Custom path for PUT request.
          payload: The contents of the PUT payload.
        """
        field = self._content.get("@odata.id")
        path = self._get_path(field, path)
        if not path:
            raise MissingOidException("The resource cannot be PUT.")
        return self._connector.put(path, payload=payload)