File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1414import abc
1515import logging
1616
17+ import openstack .exceptions
1718from osc_lib .command import command
1819from osc_lib import exceptions
1920import six
@@ -181,12 +182,16 @@ class NetworkAndComputeShowOne(command.ShowOne):
181182 """
182183
183184 def take_action (self , parsed_args ):
184- if self .app .client_manager .is_network_endpoint_enabled ():
185- return self .take_action_network (self .app .client_manager .network ,
186- parsed_args )
187- else :
188- return self .take_action_compute (self .app .client_manager .compute ,
189- parsed_args )
185+ try :
186+ if self .app .client_manager .is_network_endpoint_enabled ():
187+ return self .take_action_network (
188+ self .app .client_manager .network , parsed_args )
189+ else :
190+ return self .take_action_compute (
191+ self .app .client_manager .compute , parsed_args )
192+ except openstack .exceptions .HttpException as exc :
193+ msg = _ ("Error while executing command: %s" ) % exc .message
194+ raise exceptions .CommandError (msg )
190195
191196 def get_parser (self , prog_name ):
192197 LOG .debug ('get_parser(%s)' , prog_name )
Original file line number Diff line number Diff line change 1414import argparse
1515import mock
1616
17+ import openstack
18+ from openstackclient .common import exceptions
1719from openstackclient .network import common
1820from openstackclient .tests .unit import utils
1921
@@ -172,3 +174,15 @@ class TestNetworkAndComputeShowOne(TestNetworkAndCompute):
172174 def setUp (self ):
173175 super (TestNetworkAndComputeShowOne , self ).setUp ()
174176 self .cmd = FakeNetworkAndComputeShowOne (self .app , self .namespace )
177+
178+ def test_take_action_with_http_exception (self ):
179+ with mock .patch .object (self .cmd , 'take_action_network' ) as m_action :
180+ m_action .side_effect = openstack .exceptions .HttpException ("bar" )
181+ self .assertRaisesRegex (exceptions .CommandError , "bar" ,
182+ self .cmd .take_action , mock .Mock ())
183+
184+ self .app .client_manager .network_endpoint_enabled = False
185+ with mock .patch .object (self .cmd , 'take_action_compute' ) as m_action :
186+ m_action .side_effect = openstack .exceptions .HttpException ("bar" )
187+ self .assertRaisesRegex (exceptions .CommandError , "bar" ,
188+ self .cmd .take_action , mock .Mock ())
You can’t perform that action at this time.
0 commit comments