/usr/lib/python2.7/dist-packages/senlinclient/tests/unit/osc/v1/test_action.py is in python-senlinclient 0.4.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 | # 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 openstack.cluster.v1 import action as sdk_action
from openstack import exceptions as sdk_exc
from openstackclient.common import exceptions as exc
from senlinclient.osc.v1 import action as osc_action
from senlinclient.tests.unit.osc.v1 import fakes
class TestAction(fakes.TestClusteringv1):
def setUp(self):
super(TestAction, self).setUp()
self.mock_client = self.app.client_manager.clustering
class TestActionList(TestAction):
columns = ['id', 'name', 'action', 'status', 'target', 'depends_on',
'depended_by', 'created_at']
response = {"actions": [
{
"action": "NODE_CREATE",
"cause": "RPC Request",
"created_at": "2015-12-04T04:54:41",
"depended_by": [],
"depends_on": [],
"end_time": 1425550000.0,
"id": "2366d440-c73e-4961-9254-6d1c3af7c167",
"inputs": {},
"interval": -1,
"name": "node_create_0df0931b",
"outputs": {},
"owner": 'null',
"start_time": 1425550000.0,
"status": "SUCCEEDED",
"status_reason": "Action completed successfully.",
"target": "0df0931b-e251-4f2e-8719-4ebfda3627ba",
"timeout": 3600,
"updated_at": 'null'
},
{
"action": "NODE_DELETE",
"cause": "RPC Request",
"created_at": "2015-11-04T05:21:41",
"depended_by": [],
"depends_on": [],
"end_time": 1425550000.0,
"id": "edce3528-864f-41fb-8759-f4707925cc09",
"inputs": {},
"interval": -1,
"name": "node_delete_f0de9b9c",
"outputs": {},
"owner": 'null',
"start_time": 1425550000.0,
"status": "SUCCEEDED",
"status_reason": "Action completed successfully.",
"target": "f0de9b9c-6d48-4a46-af21-2ca8607777fe",
"timeout": 3600,
"updated_at": 'null'
}
]}
defaults = {
'marker': None,
'limit': None,
'sort': None,
}
def setUp(self):
super(TestActionList, self).setUp()
self.cmd = osc_action.ListAction(self.app, None)
self.mock_client.actions = mock.Mock(
return_value=self.response)
def test_action_list_defaults(self):
arglist = []
parsed_args = self.check_parser(self.cmd, arglist, [])
columns, data = self.cmd.take_action(parsed_args)
self.mock_client.actions.assert_called_with(**self.defaults)
self.assertEqual(self.columns, columns)
def test_action_list_full_id(self):
arglist = ['--full-id']
parsed_args = self.check_parser(self.cmd, arglist, [])
columns, data = self.cmd.take_action(parsed_args)
self.mock_client.actions.assert_called_with(**self.defaults)
self.assertEqual(self.columns, columns)
def test_action_list_limit(self):
kwargs = copy.deepcopy(self.defaults)
kwargs['limit'] = '3'
arglist = ['--limit', '3']
parsed_args = self.check_parser(self.cmd, arglist, [])
columns, data = self.cmd.take_action(parsed_args)
self.mock_client.actions.assert_called_with(**kwargs)
self.assertEqual(self.columns, columns)
def test_action_list_sort(self):
kwargs = copy.deepcopy(self.defaults)
kwargs['sort'] = 'name:asc'
arglist = ['--sort', 'name:asc']
parsed_args = self.check_parser(self.cmd, arglist, [])
columns, data = self.cmd.take_action(parsed_args)
self.mock_client.actions.assert_called_with(**kwargs)
self.assertEqual(self.columns, columns)
def test_action_list_sort_invalid_key(self):
self.mock_client.actions = mock.Mock(
return_value=self.response)
kwargs = copy.deepcopy(self.defaults)
kwargs['sort'] = 'bad_key'
arglist = ['--sort', 'bad_key']
parsed_args = self.check_parser(self.cmd, arglist, [])
self.mock_client.actions.side_effect = sdk_exc.HttpException()
self.assertRaises(sdk_exc.HttpException,
self.cmd.take_action, parsed_args)
def test_action_list_sort_invalid_direction(self):
self.mock_client.actions = mock.Mock(
return_value=self.response)
kwargs = copy.deepcopy(self.defaults)
kwargs['sort'] = 'name:bad_direction'
arglist = ['--sort', 'name:bad_direction']
parsed_args = self.check_parser(self.cmd, arglist, [])
self.mock_client.actions.side_effect = sdk_exc.HttpException()
self.assertRaises(sdk_exc.HttpException,
self.cmd.take_action, parsed_args)
def test_action_list_filter(self):
kwargs = copy.deepcopy(self.defaults)
kwargs['name'] = 'my_action'
arglist = ['--filter', 'name=my_action']
parsed_args = self.check_parser(self.cmd, arglist, [])
columns, data = self.cmd.take_action(parsed_args)
self.mock_client.actions.assert_called_with(**kwargs)
self.assertEqual(self.columns, columns)
def test_action_list_marker(self):
kwargs = copy.deepcopy(self.defaults)
kwargs['marker'] = 'a9448bf6'
arglist = ['--marker', 'a9448bf6']
parsed_args = self.check_parser(self.cmd, arglist, [])
columns, data = self.cmd.take_action(parsed_args)
self.mock_client.actions.assert_called_with(**kwargs)
self.assertEqual(self.columns, columns)
class TestActionShow(TestAction):
get_response = {
"action": "CLUSTER_DELETE",
"cause": "RPC Request",
"context": {},
"created_at": "2015-06-27T05:09:43",
"depended_by": [],
"depends_on": [],
"end_time": 1423570000.0,
"id": "ffbb9175-d510-4bc1-b676-c6aba2a4ca81",
"inputs": {},
"interval": -1,
"name": "cluster_delete_fcc9b635",
"outputs": {},
"owner": 'null',
"start_time": 1423570000.0,
"status": "FAILED",
"status_reason": "Cluster action FAILED",
"target": "fcc9b635-52e3-490b-99f2-87b1640e4e89",
"timeout": 3600,
"updated_at": 'null'}
def setUp(self):
super(TestActionShow, self).setUp()
self.cmd = osc_action.ShowAction(self.app, None)
self.mock_client.get_action = mock.Mock(
return_value=sdk_action.Action(attrs=self.get_response))
def test_action_show(self):
arglist = ['my_action']
parsed_args = self.check_parser(self.cmd, arglist, [])
self.cmd.take_action(parsed_args)
self.mock_client.get_action.assert_called_with('my_action')
def test_action_show_not_found(self):
arglist = ['my_action']
parsed_args = self.check_parser(self.cmd, arglist, [])
self.mock_client.get_action.side_effect = sdk_exc.ResourceNotFound()
error = self.assertRaises(exc.CommandError, self.cmd.take_action,
parsed_args)
self.assertEqual('Action not found: my_action', str(error))
|