<s> from contextlib import contextmanager <EOL> from cloudify . decorators import operation <EOL> class UpdatedNodeInstance ( Exception ) : <EOL> pass <EOL> @ operation <EOL> def get_state ( ** kwargs ) : <EOL> return True <EOL> @ operation <EOL> def nop_and_assert_no_runtime_update ( ctx , ** kwargs ) : <EOL> with mocked_update_node_instance ( ctx ) : <EOL> ctx . instance . update ( ) <EOL> @ operation <EOL> def read_runtime_properties_and_assert_no_runtime_update ( ctx , ** kwargs ) : <EOL> props = ctx . instance . runtime_properties <EOL> ctx . logger . info ( '<STR_LIT>' . format ( props ) ) <EOL> with mocked_update_node_instance ( ctx ) : <EOL> ctx . instance . update ( ) <EOL> @ operation <EOL> def change_runtime_properties_and_assert_runtime_update ( ctx , ** kwargs ) : <EOL> props = ctx . instance . runtime_properties <EOL> props [ '<STR_LIT>' ] = '<STR_LIT:value>' <EOL> ctx . logger . info ( '<STR_LIT>' . format ( props ) ) <EOL> with mocked_update_node_instance ( ctx ) : <EOL> try : <EOL> ctx . instance . update ( ) <EOL> except UpdatedNodeInstance : <EOL> return <EOL> raise RuntimeError ( '<STR_LIT>' ) <EOL> @ contextmanager <EOL> def mocked_update_node_instance ( ctx ) : <EOL> def mock_update_node_instance ( _ ) : <EOL> raise UpdatedNodeInstance ( ) <EOL> original_update_node_instance = ctx . _endpoint . update_node_instance <EOL> ctx . _endpoint . update_node_instance = mock_update_node_instance <EOL> try : <EOL> yield <EOL> finally : <EOL> ctx . _endpoint . update_node_instance = original_update_node_instance </s>
