summaryrefslogtreecommitdiff
path: root/heatclient/tests/functional/test_readonly_heat.py
blob: 9ccb477f1e8a660ee3b2fdb3fc7705f85af4796d (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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#    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.

import json
import os

from tempest_lib import exceptions
import yaml

from heatclient.tests.functional import base


class SimpleReadOnlyHeatClientTest(base.ClientTestBase):
    """Basic, read-only tests for Heat CLI client.

    Basic smoke test for the heat CLI commands which do not require
    creating or modifying stacks.
    """

    def test_heat_fake_action(self):
        self.assertRaises(exceptions.CommandFailed,
                          self.heat,
                          'this-does-not-exist')

    def test_heat_stack_list(self):
        self.heat('stack-list')

    def test_heat_stack_list_debug(self):
        self.heat('stack-list', flags='--debug')

    def test_heat_resource_template_fmt_default(self):
        ret = self.heat('resource-template OS::Nova::Server')
        self.assertIn('Type: OS::Nova::Server', ret)

    def test_heat_resource_template_fmt_arg_short_yaml(self):
        ret = self.heat('resource-template -F yaml OS::Nova::Server')
        self.assertIn('Type: OS::Nova::Server', ret)
        self.assertIsInstance(yaml.safe_load(ret), dict)

    def test_heat_resource_template_fmt_arg_long_json(self):
        ret = self.heat('resource-template --format json OS::Nova::Server')
        self.assertIn('"Type": "OS::Nova::Server"', ret)
        self.assertIsInstance(json.loads(ret), dict)

    def test_heat_resource_type_list(self):
        ret = self.heat('resource-type-list')
        rsrc_types = self.parser.listing(ret)
        self.assertTableStruct(rsrc_types, ['resource_type'])

    def test_heat_resource_type_show(self):
        rsrc_schema = self.heat('resource-type-show OS::Heat::RandomString')
        # resource-type-show returns a json resource schema
        self.assertIsInstance(json.loads(rsrc_schema), dict)

    def _template_validate(self, templ_name):
        heat_template_path = os.path.join(
            os.path.dirname(os.path.realpath(__file__)),
            'templates/%s' % templ_name)
        ret = self.heat('template-validate -f %s' % heat_template_path)
        # On success template-validate returns a json representation
        # of the template parameters
        self.assertIsInstance(json.loads(ret), dict)

    def test_heat_template_validate_yaml(self):
        self._template_validate('heat_minimal.yaml')

    def test_heat_template_validate_hot(self):
        self._template_validate('heat_minimal_hot.yaml')

    def test_heat_help(self):
        self.heat('help')

    def test_heat_bash_completion(self):
        self.heat('bash-completion')

    def test_heat_help_cmd(self):
        # Check requesting help for a specific command works
        help_text = self.heat('help resource-template')
        lines = help_text.split('\n')
        self.assertFirstLineStartsWith(lines, 'usage: heat resource-template')

    def test_heat_version(self):
        self.heat('', flags='--version')

    def test_heat_template_version_list(self):
        ret = self.heat('template-version-list')
        tmpl_types = self.parser.listing(ret)
        self.assertTableStruct(tmpl_types, ['version', 'type'])

    def test_heat_template_function_list(self):
        ret = self.heat('template-function-list '
                        'heat_template_version.2013-05-23')
        tmpl_functions = self.parser.listing(ret)
        self.assertTableStruct(tmpl_functions, ['functions', 'description'])