Steven Hardy | 5de54ee | 2013-12-31 15:58:30 +0000 | [diff] [blame] | 1 | # 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 | |
| 13 | import json |
| 14 | import os |
| 15 | import yaml |
| 16 | |
Steven Hardy | 5de54ee | 2013-12-31 15:58:30 +0000 | [diff] [blame] | 17 | import tempest.cli |
Matthew Treinish | e2b56b5 | 2014-01-29 19:25:50 +0000 | [diff] [blame] | 18 | from tempest import config |
Steven Hardy | 5de54ee | 2013-12-31 15:58:30 +0000 | [diff] [blame] | 19 | from tempest.openstack.common import log as logging |
| 20 | |
Matthew Treinish | e2b56b5 | 2014-01-29 19:25:50 +0000 | [diff] [blame] | 21 | CONF = config.CONF |
Steven Hardy | 5de54ee | 2013-12-31 15:58:30 +0000 | [diff] [blame] | 22 | |
| 23 | LOG = logging.getLogger(__name__) |
| 24 | |
| 25 | |
| 26 | class SimpleReadOnlyHeatClientTest(tempest.cli.ClientTestBase): |
| 27 | """Basic, read-only tests for Heat CLI client. |
| 28 | |
| 29 | Basic smoke test for the heat CLI commands which do not require |
| 30 | creating or modifying stacks. |
| 31 | """ |
| 32 | |
| 33 | @classmethod |
| 34 | def setUpClass(cls): |
| 35 | if (not CONF.service_available.heat): |
| 36 | msg = ("Skipping all Heat cli tests because it is " |
| 37 | "not available") |
| 38 | raise cls.skipException(msg) |
| 39 | super(SimpleReadOnlyHeatClientTest, cls).setUpClass() |
| 40 | |
| 41 | def test_heat_stack_list(self): |
| 42 | self.heat('stack-list') |
| 43 | |
| 44 | def test_heat_stack_list_debug(self): |
| 45 | self.heat('stack-list', flags='--debug') |
| 46 | |
| 47 | def test_heat_resource_template_fmt_default(self): |
| 48 | ret = self.heat('resource-template OS::Nova::Server') |
| 49 | self.assertIn('Type: OS::Nova::Server', ret) |
| 50 | |
| 51 | def test_heat_resource_template_fmt_arg_short_yaml(self): |
| 52 | ret = self.heat('resource-template -F yaml OS::Nova::Server') |
| 53 | self.assertIn('Type: OS::Nova::Server', ret) |
| 54 | self.assertIsInstance(yaml.safe_load(ret), dict) |
| 55 | |
| 56 | def test_heat_resource_template_fmt_arg_long_json(self): |
| 57 | ret = self.heat('resource-template --format json OS::Nova::Server') |
| 58 | self.assertIn('"Type": "OS::Nova::Server",', ret) |
| 59 | self.assertIsInstance(json.loads(ret), dict) |
| 60 | |
| 61 | def test_heat_resource_type_list(self): |
| 62 | ret = self.heat('resource-type-list') |
| 63 | rsrc_types = self.parser.listing(ret) |
| 64 | self.assertTableStruct(rsrc_types, ['resource_type']) |
| 65 | |
| 66 | def test_heat_resource_type_show(self): |
| 67 | rsrc_schema = self.heat('resource-type-show OS::Nova::Server') |
| 68 | # resource-type-show returns a json resource schema |
| 69 | self.assertIsInstance(json.loads(rsrc_schema), dict) |
| 70 | |
| 71 | def test_heat_template_validate_yaml(self): |
| 72 | filepath = os.path.join(os.path.dirname(os.path.realpath(__file__)), |
| 73 | 'heat_templates/heat_minimal.yaml') |
| 74 | ret = self.heat('template-validate -f %s' % filepath) |
| 75 | # On success template-validate returns a json representation |
| 76 | # of the template parameters |
| 77 | self.assertIsInstance(json.loads(ret), dict) |
| 78 | |
| 79 | def test_heat_template_validate_hot(self): |
| 80 | filepath = os.path.join(os.path.dirname(os.path.realpath(__file__)), |
| 81 | 'heat_templates/heat_minimal_hot.yaml') |
| 82 | ret = self.heat('template-validate -f %s' % filepath) |
| 83 | self.assertIsInstance(json.loads(ret), dict) |
| 84 | |
| 85 | def test_heat_help(self): |
| 86 | self.heat('help') |
| 87 | |
| 88 | def test_heat_help_cmd(self): |
| 89 | # Check requesting help for a specific command works |
| 90 | help_text = self.heat('help resource-template') |
| 91 | lines = help_text.split('\n') |
| 92 | self.assertFirstLineStartsWith(lines, 'usage: heat resource-template') |
| 93 | |
| 94 | def test_heat_version(self): |
| 95 | self.heat('', flags='--version') |