def test_resource_task(self): _, _ctx = self._prepare_master_node() decorators.resource_task(MagicMock(), MagicMock())(MagicMock())() mock_isfile = MagicMock(return_value=True) _ctx.download_resource = MagicMock(return_value="downloaded_resource") with patch('os.path.isfile', mock_isfile): with self.assertRaises(NonRecoverableError) as error: decorators.resource_task(MagicMock(), MagicMock())( MagicMock(side_effect=KuberentesInvalidApiMethodError( 'error_text')))() self.assertEqual(str(error.exception), "error_text")
def test_resource_task_retrieve_resources_definitions(self): _, _ctx = self._prepare_master_node() decorators.resource_task(MagicMock(), MagicMock())(MagicMock())() mock_isfile = MagicMock(return_value=True) _ctx.download_resource = MagicMock(return_value="downloaded_resource") defintion = KubernetesResourceDefinition( **_ctx.node.properties['definition']) with patch('os.path.isfile', mock_isfile): with self.assertRaises(NonRecoverableError) as error: decorators.resource_task( retrieve_resources_definitions=MagicMock( return_value=[defintion]), retrieve_mapping=MagicMock(), use_existing=True)( MagicMock(side_effect=KuberentesInvalidApiMethodError( 'error_text')))() self.assertEqual(str(error.exception), "error_text")
def test_resource_task(self): _, _ctx = self._prepare_master_node() with self.assertRaises(RecoverableError) as error: tasks._resource_task(MagicMock()) self.assertEqual( str(error.exception), "Cannot initialize Kubernetes API - no suitable configuration " "variant found for {'blueprint_file_name': 'kubernetes.conf'} " "properties") mock_isfile = MagicMock(return_value=True) _ctx.download_resource = MagicMock(return_value="downloaded_resource") with patch('os.path.isfile', mock_isfile): with self.assertRaises(NonRecoverableError) as error: tasks._resource_task( MagicMock(side_effect=KuberentesInvalidApiMethodError( 'error_text'))) self.assertEqual(str(error.exception), "error_text")
def test_KuberentesInvalidApiMethodError(self): instance = KuberentesInvalidApiMethodError('message') self.assertTrue(isinstance(instance, KuberentesError))