Example #1
0
    def test_cache_clear_only_selected_attr(self):
        self.res.nested_resource
        self.res.get_a()
        self.res.get_b()

        utils.cache_clear(self.res, False, only_these=['get_a'])

        # cache cleared (set to None)
        self.assertIsNone(self.res._cache_get_a)
        # cache retained
        self.assertEqual('b', self.res._cache_get_b)
        self.assertFalse(self.res._cache_nested_resource._is_stale)
Example #2
0
    def set_attributes(self, value):
        """Update many attributes at once

        Attribute update is not immediate but requires system restart.
        Committed attributes can be checked at :py:attr:`~pending_attributes`
        property

        :param value: Key-value pairs for attribute name and value
        """
        self._settings.commit(self._conn, {'Attributes': value})
        utils.cache_clear(self,
                          force_refresh=False,
                          only_these=['_pending_settings_resource'])
Example #3
0
File: bios.py Project: sapcc/sushy
    def set_attributes(self,
                       value,
                       apply_time=None,
                       maint_window_start_time=None,
                       maint_window_duration=None):
        """Update many attributes at once

        Attribute update is not immediate but requires system restart.
        Committed attributes can be checked at :py:attr:`~pending_attributes`
        property

        :param value: Key-value pairs for attribute name and value
        :param apply_time: When to update the attributes. Optional.
            APPLY_TIME_IMMEDIATE - Immediate,
            APPLY_TIME_ON_RESET - On reset,
            APPLY_TIME_MAINT_START - During specified maintenance time
            APPLY_TIME_MAINT_RESET - On reset during specified maintenance time
        :param maint_window_start_time: The start time of a maintenance window,
            datetime. Required when updating during maintenance window and
            default maintenance window not set by the system.
        :param maint_window_duration: Duration of maintenance time since
            maintenance window start time in seconds. Required when updating
            during maintenance window and default maintenance window not
            set by the system.
        """
        payload = {'Attributes': value}
        if (not apply_time
                and (maint_window_start_time or maint_window_duration)):
            raise ValueError('"apply_time" missing when passing maintenance '
                             'window settings')
        if apply_time:
            prop = '@Redfish.SettingsApplyTime'
            payload[prop] = {
                '@odata.type': '#Settings.v1_0_0.PreferredApplyTime',
                'ApplyTime': res_maps.APPLY_TIME_VALUE_MAP_REV[apply_time]
            }
            if maint_window_start_time and not maint_window_duration:
                raise ValueError('"maint_window_duration" missing')
            if not maint_window_start_time and maint_window_duration:
                raise ValueError('"maint_window_start_time" missing')
            if maint_window_start_time and maint_window_duration:
                payload[prop]['MaintenanceWindowStartTime'] =\
                    maint_window_start_time.isoformat()
                payload[prop]['MaintenanceWindowDurationInSeconds'] =\
                    maint_window_duration
        self._settings.commit(self._conn, payload)
        utils.cache_clear(self,
                          force_refresh=False,
                          only_these=['_pending_settings_resource'])
Example #4
0
    def _do_refresh(self, force):
        """Primitive method to be overridden by refresh related activities.

        Derived classes are supposed to override this method with the
        resource specific refresh operations to be performed. This is a
        primitive method in the paradigm of Template design pattern.

        As for the base implementation of this method the approach taken is:
        On refresh, all sub-resources are marked as stale. That means
        invalidate (or undefine) the exposed attributes for nested resources
        for fresh evaluation in subsequent calls to those exposed attributes.
        In other words greedy-refresh is not done for them, unless forced by
        ``force`` argument.

        :param force: should force refresh the resource and its sub-resources,
            if set to True.
        :raises: ResourceNotFoundError
        :raises: ConnectionError
        :raises: HTTPError
        """
        utils.cache_clear(self, force_refresh=force)