summaryrefslogtreecommitdiff
path: root/heat/tests/convergence/framework/reality.py
blob: 055782b3898f52940727d7393057958ce78c5f2f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
#    not use this file except in compliance with the License. You may obtain
#    a copy of the License at
#
#         http://www.apache.org/licenses/LICENSE-2.0
#
#    Unless required by applicable law or agreed to in writing, software
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
#    License for the specific language governing permissions and limitations
#    under the License.

from unittest import mock

from heat.common import exception
from heat.db.sqlalchemy import api as db_api
from heat.tests import utils


class RealityStore(object):

    def __init__(self):
        self.cntxt = utils.dummy_context()

    def resources_by_logical_name(self, logical_name):
        ret = []
        resources = db_api.resource_get_all(self.cntxt)
        for res in resources:
            if (res.name == logical_name and res.action in ("CREATE", "UPDATE")
               and res.status == "COMPLETE"):
                ret.append(res)
        return ret

    def all_resources(self):
        try:
            resources = db_api.resource_get_all(self.cntxt)
        except exception.NotFound:
            return []

        ret = []
        for res in resources:
            if res.action in ("CREATE", "UPDATE") and res.status == "COMPLETE":
                ret.append(res)
        return ret

    def resource_properties(self, res, prop_name):
        res_data = db_api.resource_data_get_by_key(self.cntxt,
                                                   res.id,
                                                   prop_name)
        return res_data.value


with mock.patch("oslo_config.cfg.ConfigOpts.find_file"):
    reality = RealityStore()