blob: 8e413a9409b7b389a3f69ecf1ba70c617592a7ae [file] [log] [blame]
Steven Hardy5de54ee2013-12-31 15:58:30 +00001# Licensed under the Apache License, Version 2.0 (the "License"); you may
2# not use this file except in compliance with the License. You may obtain
3# a copy of the License at
4#
5# http://www.apache.org/licenses/LICENSE-2.0
6#
7# Unless required by applicable law or agreed to in writing, software
8# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10# License for the specific language governing permissions and limitations
11# under the License.
12
13import json
14import os
Matthew Treinish96e9e882014-06-09 18:37:19 -040015
Steven Hardy5de54ee2013-12-31 15:58:30 +000016import yaml
17
Steven Hardy5de54ee2013-12-31 15:58:30 +000018import tempest.cli
Matthew Treinishe2b56b52014-01-29 19:25:50 +000019from tempest import config
Steven Hardy5de54ee2013-12-31 15:58:30 +000020from tempest.openstack.common import log as logging
21
Matthew Treinishe2b56b52014-01-29 19:25:50 +000022CONF = config.CONF
Steven Hardy5de54ee2013-12-31 15:58:30 +000023
24LOG = logging.getLogger(__name__)
25
26
27class SimpleReadOnlyHeatClientTest(tempest.cli.ClientTestBase):
28 """Basic, read-only tests for Heat CLI client.
29
30 Basic smoke test for the heat CLI commands which do not require
31 creating or modifying stacks.
32 """
33
34 @classmethod
35 def setUpClass(cls):
36 if (not CONF.service_available.heat):
37 msg = ("Skipping all Heat cli tests because it is "
38 "not available")
39 raise cls.skipException(msg)
40 super(SimpleReadOnlyHeatClientTest, cls).setUpClass()
41
42 def test_heat_stack_list(self):
43 self.heat('stack-list')
44
45 def test_heat_stack_list_debug(self):
46 self.heat('stack-list', flags='--debug')
47
48 def test_heat_resource_template_fmt_default(self):
49 ret = self.heat('resource-template OS::Nova::Server')
50 self.assertIn('Type: OS::Nova::Server', ret)
51
52 def test_heat_resource_template_fmt_arg_short_yaml(self):
53 ret = self.heat('resource-template -F yaml OS::Nova::Server')
54 self.assertIn('Type: OS::Nova::Server', ret)
55 self.assertIsInstance(yaml.safe_load(ret), dict)
56
57 def test_heat_resource_template_fmt_arg_long_json(self):
58 ret = self.heat('resource-template --format json OS::Nova::Server')
59 self.assertIn('"Type": "OS::Nova::Server",', ret)
60 self.assertIsInstance(json.loads(ret), dict)
61
62 def test_heat_resource_type_list(self):
63 ret = self.heat('resource-type-list')
64 rsrc_types = self.parser.listing(ret)
65 self.assertTableStruct(rsrc_types, ['resource_type'])
66
67 def test_heat_resource_type_show(self):
68 rsrc_schema = self.heat('resource-type-show OS::Nova::Server')
69 # resource-type-show returns a json resource schema
70 self.assertIsInstance(json.loads(rsrc_schema), dict)
71
72 def test_heat_template_validate_yaml(self):
73 filepath = os.path.join(os.path.dirname(os.path.realpath(__file__)),
74 'heat_templates/heat_minimal.yaml')
75 ret = self.heat('template-validate -f %s' % filepath)
76 # On success template-validate returns a json representation
77 # of the template parameters
78 self.assertIsInstance(json.loads(ret), dict)
79
80 def test_heat_template_validate_hot(self):
81 filepath = os.path.join(os.path.dirname(os.path.realpath(__file__)),
82 'heat_templates/heat_minimal_hot.yaml')
83 ret = self.heat('template-validate -f %s' % filepath)
84 self.assertIsInstance(json.loads(ret), dict)
85
86 def test_heat_help(self):
87 self.heat('help')
88
Matt Riedemann27bdb052014-07-30 14:57:55 -070089 @tempest.cli.min_client_version(client='heat', version='0.2.7')
xiejunana3d31b82014-05-15 08:03:38 +000090 def test_heat_bash_completion(self):
91 self.heat('bash-completion')
92
Steven Hardy5de54ee2013-12-31 15:58:30 +000093 def test_heat_help_cmd(self):
94 # Check requesting help for a specific command works
95 help_text = self.heat('help resource-template')
96 lines = help_text.split('\n')
97 self.assertFirstLineStartsWith(lines, 'usage: heat resource-template')
98
99 def test_heat_version(self):
100 self.heat('', flags='--version')