@@ -3799,6 +3799,106 @@ def test_do_cache_list_endpoint_not_provided(self):
37993799 'Direct server endpoint needs to be provided. Do '
38003800 'not use loadbalanced or catalog endpoints.' )
38013801
3802+ def test_do_cache_nodes_list (self ):
3803+ args = argparse .Namespace (
3804+ id = '3a4560a1-e585-443e-9b39-553b46ec92d1' )
3805+ expected_nodes = ['http://node1.example' , 'http://node2.example' ]
3806+ with mock .patch .object (
3807+ self .gc .cache , 'list_cached_nodes' ) as mocked_list_nodes :
3808+ mocked_list_nodes .return_value = expected_nodes
3809+ test_shell .do_cache_nodes_list (self .gc , args )
3810+ mocked_list_nodes .assert_called_once_with (args .id )
3811+ objs , fields = utils .print_list .call_args [0 ]
3812+ self .assertEqual (['Node Reference URL' ], fields )
3813+ self .assertEqual (2 , len (objs ))
3814+ self .assertEqual ('http://node1.example' , objs [0 ].node_reference_url )
3815+ self .assertEqual ('http://node2.example' , objs [1 ].node_reference_url )
3816+
3817+ def test_do_cache_nodes_list_empty (self ):
3818+ args = argparse .Namespace (
3819+ id = '3a4560a1-e585-443e-9b39-553b46ec92d1' )
3820+ with mock .patch .object (
3821+ self .gc .cache , 'list_cached_nodes' ) as mocked_list_nodes :
3822+ mocked_list_nodes .return_value = []
3823+ test_shell .do_cache_nodes_list (self .gc , args )
3824+ objs , fields = utils .print_list .call_args [0 ]
3825+ self .assertEqual (['Node Reference URL' ], fields )
3826+ self .assertEqual (0 , len (objs ))
3827+
3828+ def test_do_cache_nodes_list_unsupported (self ):
3829+ args = argparse .Namespace (
3830+ id = '3a4560a1-e585-443e-9b39-553b46ec92d1' )
3831+ with mock .patch .object (
3832+ self .gc .cache , 'list_cached_nodes' ) as mocked_list_nodes :
3833+ mocked_list_nodes .side_effect = exc .HTTPNotImplemented
3834+ self .assertRaises (exc .HTTPNotImplemented ,
3835+ test_shell .do_cache_nodes_list ,
3836+ self .gc , args )
3837+
3838+ def test_do_cache_nodes_list_forbidden (self ):
3839+ image_id = '3a4560a1-e585-443e-9b39-553b46ec92d1'
3840+ args = argparse .Namespace (id = image_id )
3841+ with mock .patch .object (
3842+ self .gc .cache , 'list_cached_nodes' ) as mocked_list_nodes :
3843+ mocked_list_nodes .side_effect = exc .HTTPForbidden
3844+ with mock .patch (
3845+ 'glanceclient.common.utils.print_err' ) as mock_print_err :
3846+ test_shell .do_cache_nodes_list (self .gc , args )
3847+ mock_print_err .assert_called_once_with (
3848+ "You are not permitted to list cached nodes for image '%s'."
3849+ % image_id )
3850+
3851+ def test_do_cache_nodes_list_conflict (self ):
3852+ image_id = '3a4560a1-e585-443e-9b39-553b46ec92d1'
3853+ args = argparse .Namespace (id = image_id )
3854+ with mock .patch .object (
3855+ self .gc .cache , 'list_cached_nodes' ) as mocked_list_nodes :
3856+ mocked_list_nodes .side_effect = exc .HTTPConflict
3857+ with mock .patch (
3858+ 'glanceclient.common.utils.print_err' ) as mock_print_err :
3859+ test_shell .do_cache_nodes_list (self .gc , args )
3860+ mock_print_err .assert_called_once_with (
3861+ "'%s': Unable to list cached nodes for image '%s'."
3862+ % (exc .HTTPConflict (), image_id ))
3863+
3864+ def test_do_cache_nodes_list_not_found (self ):
3865+ image_id = '3a4560a1-e585-443e-9b39-553b46ec92d1'
3866+ args = argparse .Namespace (id = image_id )
3867+ with mock .patch .object (
3868+ self .gc .cache , 'list_cached_nodes' ) as mocked_list_nodes :
3869+ mocked_list_nodes .side_effect = exc .HTTPNotFound
3870+ with mock .patch (
3871+ 'glanceclient.common.utils.print_err' ) as mock_print_err :
3872+ test_shell .do_cache_nodes_list (self .gc , args )
3873+ mock_print_err .assert_called_once_with (
3874+ "'%s': Unable to list cached nodes for image '%s'."
3875+ % (exc .HTTPNotFound (), image_id ))
3876+
3877+ def test_do_cache_nodes_list_http_exception (self ):
3878+ image_id = '3a4560a1-e585-443e-9b39-553b46ec92d1'
3879+ args = argparse .Namespace (id = image_id )
3880+ with mock .patch .object (
3881+ self .gc .cache , 'list_cached_nodes' ) as mocked_list_nodes :
3882+ mocked_list_nodes .side_effect = exc .HTTPBadRequest
3883+ with mock .patch (
3884+ 'glanceclient.common.utils.print_err' ) as mock_print_err :
3885+ test_shell .do_cache_nodes_list (self .gc , args )
3886+ mock_print_err .assert_called_once_with (
3887+ "'%s': Unable to list cached nodes for image '%s'."
3888+ % (exc .HTTPBadRequest (), image_id ))
3889+
3890+ def test_do_cache_nodes_list_endpoint_not_provided (self ):
3891+ args = argparse .Namespace (
3892+ id = '3a4560a1-e585-443e-9b39-553b46ec92d1' )
3893+ self .gc .endpoint_provided = False
3894+ with mock .patch ('glanceclient.common.utils.exit' ) as mock_exit :
3895+ mock_exit .side_effect = self ._mock_utils_exit
3896+ with self .assertRaises (SystemExit ):
3897+ test_shell .do_cache_nodes_list (self .gc , args )
3898+ mock_exit .assert_called_once_with (
3899+ 'Direct server endpoint needs to be provided. Do '
3900+ 'not use loadbalanced or catalog endpoints.' )
3901+
38023902 def _test_cache_queue (self , supported = True , forbidden = False ,):
38033903 args = argparse .Namespace (id = ['image1' ])
38043904 with mock .patch .object (self .gc .cache , 'queue' ) as mocked_cache_queue :
0 commit comments