/usr/lib/python2.7/dist-packages/heatclient/tests/unit/osc/v1/test_software_deployment.py is in python-heatclient 1.1.0-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 | # 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 copy
import mock
from openstackclient.common import exceptions as exc
from heatclient import exc as heat_exc
from heatclient.osc.v1 import software_deployment
from heatclient.tests.unit.osc.v1 import fakes as orchestration_fakes
from heatclient.v1 import software_configs
from heatclient.v1 import software_deployments
class TestDeployment(orchestration_fakes.TestOrchestrationv1):
def setUp(self):
super(TestDeployment, self).setUp()
self.mock_client = self.app.client_manager.orchestration
self.config_client = self.mock_client.software_configs
self.sd_client = self.mock_client.software_deployments
class TestDeploymentCreate(TestDeployment):
server_id = '1234'
config_id = '5678'
deploy_id = '910'
config = {
'name': 'my_deploy',
'group': 'strict',
'config': '#!/bin/bash',
'inputs': [],
'outputs': [],
'options': [],
'id': config_id,
}
deployment = {
'server_id': server_id,
'input_values': {},
'action': 'UPDATE',
'status': 'IN_PROGRESS',
'status_reason': None,
'signal_id': 'signal_id',
'config_id': config_id,
'id': deploy_id,
}
config_defaults = {
'group': 'Heat::Ungrouped',
'config': '',
'options': {},
'inputs': [
{
'name': 'deploy_server_id',
'description': 'ID of the server being deployed to',
'type': 'String',
'value': server_id,
},
{
'name': 'deploy_action',
'description': 'Name of the current action being deployed',
'type': 'String',
'value': 'UPDATE',
},
{
'name': 'deploy_signal_transport',
'description': 'How the server should signal to heat with the '
'deployment output values.',
'type': 'String',
'value': 'TEMP_URL_SIGNAL',
},
{
'name': 'deploy_signal_id',
'description': 'ID of signal to use for signaling output '
'values',
'type': 'String',
'value': 'signal_id',
},
{
'name': 'deploy_signal_verb',
'description': 'HTTP verb to use for signaling output values',
'type': 'String',
'value': 'PUT',
},
],
'outputs': [],
'name': 'my_deploy',
}
deploy_defaults = {
'config_id': config_id,
'server_id': server_id,
'action': 'UPDATE',
'status': 'IN_PROGRESS',
}
def setUp(self):
super(TestDeploymentCreate, self).setUp()
self.cmd = software_deployment.CreateDeployment(self.app, None)
self.config_client.create = mock.MagicMock(return_value=(
software_configs.SoftwareConfig(None, self.config)))
self.config_client.get = mock.MagicMock(return_value=(
software_configs.SoftwareConfig(None, self.config)))
self.sd_client.create = mock.MagicMock(return_value=(
software_deployments.SoftwareDeployment(None, self.deployment)))
@mock.patch('heatclient.common.deployment_utils.build_signal_id',
return_value='signal_id')
def test_deployment_create(self, mock_build):
arglist = ['my_deploy', '--server', self.server_id]
expected_cols = ('action', 'config_id', 'id', 'input_values',
'server_id', 'signal_id', 'status', 'status_reason')
expected_data = ('UPDATE', self.config_id, self.deploy_id, {},
self.server_id, 'signal_id', 'IN_PROGRESS', None)
parsed_args = self.check_parser(self.cmd, arglist, [])
columns, data = self.cmd.take_action(parsed_args)
self.config_client.create.assert_called_with(**self.config_defaults)
self.sd_client.create.assert_called_with(
**self.deploy_defaults)
self.assertEqual(expected_cols, columns)
self.assertEqual(expected_data, data)
@mock.patch('heatclient.common.deployment_utils.build_signal_id',
return_value='signal_id')
def test_deployment_create_with_config(self, mock_build):
arglist = ['my_deploy', '--server', self.server_id,
'--config', self.config_id]
config = copy.deepcopy(self.config_defaults)
config['config'] = '#!/bin/bash'
config['group'] = 'strict'
parsed_args = self.check_parser(self.cmd, arglist, [])
columns, data = self.cmd.take_action(parsed_args)
self.config_client.get.assert_called_with(self.config_id)
self.config_client.create.assert_called_with(**config)
self.sd_client.create.assert_called_with(
**self.deploy_defaults)
def test_deployment_create_config_not_found(self):
arglist = ['my_deploy', '--server', self.server_id,
'--config', 'bad_id']
self.config_client.get.side_effect = heat_exc.HTTPNotFound
parsed_args = self.check_parser(self.cmd, arglist, [])
self.assertRaises(exc.CommandError, self.cmd.take_action, parsed_args)
def test_deployment_create_no_signal(self):
arglist = ['my_deploy', '--server', self.server_id,
'--signal-transport', 'NO_SIGNAL']
config = copy.deepcopy(self.config_defaults)
config['inputs'] = config['inputs'][:-2]
config['inputs'][2]['value'] = 'NO_SIGNAL'
parsed_args = self.check_parser(self.cmd, arglist, [])
columns, data = self.cmd.take_action(parsed_args)
self.config_client.create.assert_called_with(**config)
self.sd_client.create.assert_called_with(
**self.deploy_defaults)
@mock.patch('heatclient.common.deployment_utils.build_signal_id',
return_value='signal_id')
def test_deployment_create_invalid_signal_transport(self, mock_build):
arglist = ['my_deploy', '--server', self.server_id,
'--signal-transport', 'A']
parsed_args = self.check_parser(self.cmd, arglist, [])
self.assertRaises(heat_exc.CommandError,
self.cmd.take_action, parsed_args)
@mock.patch('heatclient.common.deployment_utils.build_signal_id',
return_value='signal_id')
def test_deployment_create_input_value(self, mock_build):
arglist = ['my_deploy', '--server', self.server_id,
'--input-value', 'foo=bar']
config = copy.deepcopy(self.config_defaults)
config['inputs'].insert(
0, {'name': 'foo', 'type': 'String', 'value': 'bar'})
parsed_args = self.check_parser(self.cmd, arglist, [])
columns, data = self.cmd.take_action(parsed_args)
self.config_client.create.assert_called_with(**config)
self.sd_client.create.assert_called_with(
**self.deploy_defaults)
@mock.patch('heatclient.common.deployment_utils.build_signal_id',
return_value='signal_id')
def test_deployment_create_action(self, mock_build):
arglist = ['my_deploy', '--server', self.server_id,
'--action', 'DELETE']
config = copy.deepcopy(self.config_defaults)
config['inputs'][1]['value'] = 'DELETE'
deploy = copy.deepcopy(self.deploy_defaults)
deploy['action'] = 'DELETE'
parsed_args = self.check_parser(self.cmd, arglist, [])
columns, data = self.cmd.take_action(parsed_args)
self.config_client.create.assert_called_with(**config)
self.sd_client.create.assert_called_with(**deploy)
class TestDeploymentDelete(TestDeployment):
def setUp(self):
super(TestDeploymentDelete, self).setUp()
self.cmd = software_deployment.DeleteDeployment(self.app, None)
def test_deployment_delete_success(self):
arglist = ['test_deployment']
parsed_args = self.check_parser(self.cmd, arglist, [])
self.sd_client.get = mock.Mock()
self.sd_client.delete = mock.Mock()
self.cmd.take_action(parsed_args)
self.sd_client.delete.assert_called_with(
deployment_id='test_deployment')
def test_deployment_delete_multiple(self):
arglist = ['test_deployment', 'test_deployment2']
parsed_args = self.check_parser(self.cmd, arglist, [])
self.sd_client.get = mock.Mock()
self.sd_client.delete = mock.Mock()
self.cmd.take_action(parsed_args)
self.sd_client.delete.assert_has_calls(
[mock.call(deployment_id='test_deployment'),
mock.call(deployment_id='test_deployment2')])
def test_deployment_delete_not_found(self):
arglist = ['test_deployment', 'test_deployment2']
parsed_args = self.check_parser(self.cmd, arglist, [])
self.sd_client.delete = mock.Mock()
self.sd_client.delete.side_effect = heat_exc.HTTPNotFound()
error = self.assertRaises(
exc.CommandError, self.cmd.take_action, parsed_args)
self.assertIn("Unable to delete 2 of the 2 deployments.", str(error))
def test_deployment_config_delete_failed(self):
arglist = ['test_deployment']
parsed_args = self.check_parser(self.cmd, arglist, [])
self.config_client.delete = mock.Mock()
self.config_client.delete.side_effect = heat_exc.HTTPNotFound()
error = self.assertRaises(
exc.CommandError, self.cmd.take_action, parsed_args)
self.assertEqual("Unable to delete 1 of the 1 deployments.",
str(error))
class TestDeploymentList(TestDeployment):
columns = ['id', 'config_id', 'server_id', 'action', 'status']
data = {"software_deployments": [
{
"status": "COMPLETE",
"server_id": "ec14c864-096e-4e27-bb8a-2c2b4dc6f3f5",
"config_id": "8da95794-2ad9-4979-8ae5-739ce314c5cd",
"output_values": {
"deploy_stdout": "Writing to /tmp/barmy Written to /tmp/barmy",
"deploy_stderr": "+ echo Writing to /tmp/barmy\n+ echo fu\n+ c"
"at /tmp/barmy\n+ echo -n The file /tmp/barmy"
"contains for server ec14c864-096e-4e27-bb8a-"
"2c2b4dc6f3f5 during CREATE\n+"
"echo Output to stderr\nOutput to stderr\n",
"deploy_status_code": 0,
"result": "The file /tmp/barmy contains fu for server "
"ec14c864-096e-4e27-bb8a-2c2b4dc6f3f5 during CREATE"
},
"input_values": None,
"action": "CREATE",
"status_reason": "Outputs received",
"id": "ef422fa5-719a-419e-a10c-72e3a367b0b8",
"creation_time": "2015-01-31T15:12:36Z",
"updated_time": "2015-01-31T15:18:21Z"
}
]
}
def setUp(self):
super(TestDeploymentList, self).setUp()
self.cmd = software_deployment.ListDeployment(self.app, None)
self.sd_client.list = mock.MagicMock(return_value=[self.data])
def test_deployment_list(self):
arglist = []
parsed_args = self.check_parser(self.cmd, arglist, [])
columns, data = self.cmd.take_action(parsed_args)
self.sd_client.list.assert_called_with()
self.assertEqual(self.columns, columns)
def test_deployment_list_server(self):
kwargs = {}
kwargs['server_id'] = 'ec14c864-096e-4e27-bb8a-2c2b4dc6f3f5'
arglist = ['--server', 'ec14c864-096e-4e27-bb8a-2c2b4dc6f3f5']
parsed_args = self.check_parser(self.cmd, arglist, [])
columns, data = self.cmd.take_action(parsed_args)
self.sd_client.list.assert_called_with(**kwargs)
self.assertEqual(self.columns, columns)
def test_deployment_list_long(self):
kwargs = {}
cols = ['id', 'config_id', 'server_id', 'action', 'status',
'creation_time', 'status_reason']
arglist = ['--long']
parsed_args = self.check_parser(self.cmd, arglist, [])
columns, data = self.cmd.take_action(parsed_args)
self.sd_client.list.assert_called_with(**kwargs)
self.assertEqual(cols, columns)
class TestDeploymentShow(TestDeployment):
get_response = {"software_deployment": {
"status": "IN_PROGRESS",
"server_id": "ec14c864-096e-4e27-bb8a-2c2b4dc6f3f5",
"config_id": "3d5ec2a8-7004-43b6-a7f6-542bdbe9d434",
"output_values": 'null',
"input_values": 'null',
"action": "CREATE",
"status_reason": "Deploy data available",
"id": "06e87bcc-33a2-4bce-aebd-533e698282d3",
"creation_time": "2015-01-31T15:12:36Z",
"updated_time": "2015-01-31T15:18:21Z"
}}
def setUp(self):
super(TestDeploymentShow, self).setUp()
self.cmd = software_deployment.ShowDeployment(self.app, None)
def test_deployment_show(self):
arglist = ['my_deployment']
cols = ['id', 'server_id', 'config_id', 'creation_time',
'updated_time', 'status', 'status_reason',
'input_values', 'action']
parsed_args = self.check_parser(self.cmd, arglist, [])
self.sd_client.get = mock.Mock(
return_value=software_deployments.SoftwareDeployment(
None, self.get_response))
columns, data = self.cmd.take_action(parsed_args)
self.sd_client.get.assert_called_with(**{
'deployment_id': 'my_deployment',
})
self.assertEqual(cols, columns)
def test_deployment_show_long(self):
arglist = ['my_deployment', '--long']
cols = ['id', 'server_id', 'config_id', 'creation_time',
'updated_time', 'status', 'status_reason',
'input_values', 'action', 'output_values']
parsed_args = self.check_parser(self.cmd, arglist, [])
self.sd_client.get = mock.Mock(
return_value=software_deployments.SoftwareDeployment(
None, self.get_response))
columns, data = self.cmd.take_action(parsed_args)
self.sd_client.get.assert_called_once_with(**{
'deployment_id': 'my_deployment',
})
self.assertEqual(cols, columns)
def test_deployment_not_found(self):
arglist = ['my_deployment']
parsed_args = self.check_parser(self.cmd, arglist, [])
self.sd_client.get = mock.Mock()
self.sd_client.get.side_effect = heat_exc.HTTPNotFound()
self.assertRaises(
exc.CommandError,
self.cmd.take_action,
parsed_args)
class TestDeploymentMetadataShow(TestDeployment):
def setUp(self):
super(TestDeploymentMetadataShow, self).setUp()
self.cmd = software_deployment.ShowMetadataDeployment(self.app, None)
self.sd_client.metadata = mock.Mock(return_value={})
def test_deployment_show_metadata(self):
arglist = ['ec14c864-096e-4e27-bb8a-2c2b4dc6f3f5']
parsed_args = self.check_parser(self.cmd, arglist, [])
self.cmd.take_action(parsed_args)
self.sd_client.metadata.assert_called_with(
server_id='ec14c864-096e-4e27-bb8a-2c2b4dc6f3f5')
class TestDeploymentOutputShow(TestDeployment):
get_response = {
"status": "IN_PROGRESS",
"server_id": "ec14c864-096e-4e27-bb8a-2c2b4dc6f3f5",
"config_id": "3d5ec2a8-7004-43b6-a7f6-542bdbe9d434",
"output_values": None,
"input_values": None,
"action": "CREATE",
"status_reason": "Deploy data available",
"id": "06e87bcc-33a2-4bce-aebd-533e698282d3",
"creation_time": "2015-01-31T15:12:36Z",
"updated_time": "2015-01-31T15:18:21Z"
}
def setUp(self):
super(TestDeploymentOutputShow, self).setUp()
self.cmd = software_deployment.ShowOutputDeployment(self.app, None)
def test_deployment_output_show(self):
arglist = ['85c3a507-351b-4b28-a7d8-531c8d53f4e6', '--all', '--long']
parsed_args = self.check_parser(self.cmd, arglist, [])
self.sd_client.get = mock.Mock(
return_value=software_deployments.SoftwareDeployment(
None, self.get_response))
self.cmd.take_action(parsed_args)
self.sd_client.get.assert_called_with(**{
'deployment_id': '85c3a507-351b-4b28-a7d8-531c8d53f4e6'
})
def test_deployment_output_show_invalid(self):
arglist = ['85c3a507-351b-4b28-a7d8-531c8d53f4e6']
parsed_args = self.check_parser(self.cmd, arglist, [])
self.sd_client.get = mock.Mock()
error = self.assertRaises(
exc.CommandError,
self.cmd.take_action,
parsed_args)
self.assertIn('either <output-name> or --all argument is needed',
str(error))
def test_deployment_output_show_not_found(self):
arglist = ['85c3a507-351b-4b28-a7d8-531c8d53f4e6', '--all']
parsed_args = self.check_parser(self.cmd, arglist, [])
self.sd_client.get = mock.Mock()
self.sd_client.get.side_effect = heat_exc.HTTPNotFound()
self.assertRaises(
exc.CommandError,
self.cmd.take_action,
parsed_args)
|