<s> import datetime <EOL> from nova import exception <EOL> from nova import objects <EOL> from nova import test <EOL> class TestImageMeta ( test . NoDBTestCase ) : <EOL> def test_basic_attrs ( self ) : <EOL> image = { '<STR_LIT:status>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : <NUM_LIT:0> , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT:0>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT:yes>' , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT:yes>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } , <EOL> '<STR_LIT:size>' : <NUM_LIT> , <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:id>' : '<STR_LIT>' <EOL> } <EOL> image_meta = objects . ImageMeta . from_dict ( image ) <EOL> self . assertEqual ( '<STR_LIT>' , image_meta . status ) <EOL> self . assertEqual ( '<STR_LIT>' , image_meta . container_format ) <EOL> self . assertEqual ( <NUM_LIT:0> , image_meta . min_ram ) <EOL> self . assertIsInstance ( image_meta . updated_at , datetime . datetime ) <EOL> self . assertEqual ( <NUM_LIT:0> , image_meta . min_disk ) <EOL> self . assertEqual ( '<STR_LIT>' , image_meta . owner ) <EOL> self . assertTrue ( image_meta . protected ) <EOL> self . assertEqual ( <NUM_LIT> , image_meta . size ) <EOL> self . assertEqual ( '<STR_LIT>' , image_meta . name ) <EOL> self . assertEqual ( '<STR_LIT>' , <EOL> image_meta . checksum ) <EOL> self . assertIsInstance ( image_meta . created_at , datetime . datetime ) <EOL> self . assertEqual ( '<STR_LIT>' , image_meta . disk_format ) <EOL> self . assertEqual ( '<STR_LIT>' , image_meta . id ) <EOL> self . assertIsInstance ( image_meta . properties , objects . ImageMetaProps ) <EOL> def test_no_props ( self ) : <EOL> image_meta = objects . ImageMeta . from_dict ( { } ) <EOL> self . assertIsInstance ( image_meta . properties , objects . ImageMetaProps ) <EOL> def test_volume_backed_image ( self ) : <EOL> image = { '<STR_LIT>' : None , <EOL> '<STR_LIT:size>' : <NUM_LIT:0> , <EOL> '<STR_LIT>' : None , <EOL> '<STR_LIT>' : None , <EOL> } <EOL> image_meta = objects . ImageMeta . from_dict ( image ) <EOL> self . assertEqual ( '<STR_LIT>' , image_meta . container_format ) <EOL> self . assertEqual ( <NUM_LIT:0> , image_meta . size ) <EOL> self . assertEqual ( '<STR_LIT>' , image_meta . checksum ) <EOL> self . assertEqual ( '<STR_LIT>' , image_meta . disk_format ) <EOL> def test_null_substitution ( self ) : <EOL> image = { '<STR_LIT:name>' : None , <EOL> '<STR_LIT>' : None , <EOL> '<STR_LIT>' : None , <EOL> '<STR_LIT:size>' : None , <EOL> '<STR_LIT>' : None , <EOL> '<STR_LIT>' : None , <EOL> '<STR_LIT>' : None , <EOL> } <EOL> image_meta = objects . ImageMeta . from_dict ( image ) <EOL> self . assertEqual ( '<STR_LIT>' , image_meta . name ) <EOL> self . assertEqual ( '<STR_LIT>' , image_meta . checksum ) <EOL> self . assertEqual ( '<STR_LIT>' , image_meta . owner ) <EOL> self . assertEqual ( <NUM_LIT:0> , image_meta . size ) <EOL> self . assertEqual ( <NUM_LIT:0> , image_meta . virtual_size ) <EOL> self . assertEqual ( '<STR_LIT>' , image_meta . container_format ) <EOL> self . assertEqual ( '<STR_LIT>' , image_meta . disk_format ) <EOL> class TestImageMetaProps ( test . NoDBTestCase ) : <EOL> def test_normal_props ( self ) : <EOL> props = { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT:yes>' , <EOL> } <EOL> virtprops = objects . ImageMetaProps . from_dict ( props ) <EOL> self . assertEqual ( '<STR_LIT>' , virtprops . os_type ) <EOL> self . assertEqual ( '<STR_LIT>' , virtprops . hw_video_model ) <EOL> self . assertEqual ( <NUM_LIT> , virtprops . hw_video_ram ) <EOL> self . assertTrue ( virtprops . hw_qemu_guest_agent ) <EOL> def test_default_props ( self ) : <EOL> props = { } <EOL> virtprops = objects . ImageMetaProps . from_dict ( props ) <EOL> for prop in virtprops . fields : <EOL> self . assertIsNone ( virtprops . get ( prop ) ) <EOL> def test_default_prop_value ( self ) : <EOL> props = { } <EOL> virtprops = objects . ImageMetaProps . from_dict ( props ) <EOL> self . assertEqual ( "<STR_LIT>" , virtprops . get ( "<STR_LIT>" , "<STR_LIT>" ) ) <EOL> def test_non_existent_prop ( self ) : <EOL> props = { } <EOL> virtprops = objects . ImageMetaProps . from_dict ( props ) <EOL> self . assertRaises ( AttributeError , <EOL> virtprops . get , <EOL> "<STR_LIT>" ) <EOL> def test_legacy_compat ( self ) : <EOL> legacy_props = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT:2>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT:yes>' , <EOL> '<STR_LIT>' : '<STR_LIT:yes>' , <EOL> '<STR_LIT>' : '<STR_LIT:3>' , <EOL> '<STR_LIT>' : '<STR_LIT:2>' , <EOL> '<STR_LIT>' : '<STR_LIT:false>' , <EOL> '<STR_LIT>' : '<STR_LIT:yes>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT:yes>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT:yes>' , <EOL> '<STR_LIT>' : [ ] , <EOL> '<STR_LIT>' : [ ] , <EOL> '<STR_LIT>' : '<STR_LIT:yes>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> image_meta = objects . ImageMetaProps . from_dict ( legacy_props ) <EOL> self . assertEqual ( '<STR_LIT>' , image_meta . hw_architecture ) <EOL> self . assertEqual ( '<STR_LIT>' , image_meta . img_owner_id ) <EOL> self . assertEqual ( '<STR_LIT>' , image_meta . hw_scsi_model ) <EOL> self . assertEqual ( '<STR_LIT>' , image_meta . hw_disk_type ) <EOL> self . assertEqual ( <NUM_LIT:2> , image_meta . img_version ) <EOL> self . assertEqual ( '<STR_LIT>' , image_meta . os_distro ) <EOL> self . assertTrue ( image_meta . hw_auto_disk_config ) <EOL> self . assertTrue ( image_meta . hw_ipxe_boot ) <EOL> self . assertEqual ( <NUM_LIT:3> , image_meta . hw_device_id ) <EOL> self . assertEqual ( <NUM_LIT:2> , image_meta . img_compression_level ) <EOL> self . assertFalse ( image_meta . img_linked_clone ) <EOL> self . assertTrue ( image_meta . img_use_agent ) <EOL> self . assertFalse ( image_meta . os_skip_agent_inject_ssh ) <EOL> self . assertFalse ( image_meta . os_skip_agent_inject_files_at_boot ) <EOL> self . assertTrue ( image_meta . img_cache_in_nova ) <EOL> self . assertTrue ( image_meta . img_bittorrent ) <EOL> self . assertEqual ( [ ] , image_meta . img_mappings ) <EOL> self . assertEqual ( [ ] , image_meta . img_block_device_mapping ) <EOL> self . assertTrue ( image_meta . img_bdm_v2 ) <EOL> self . assertEqual ( "<STR_LIT>" , image_meta . img_root_device_name ) <EOL> self . assertEqual ( '<STR_LIT>' , image_meta . img_hv_requested_version ) <EOL> self . assertEqual ( '<STR_LIT>' , image_meta . img_hv_type ) <EOL> def test_legacy_compat_vmware_adapter_types ( self ) : <EOL> legacy_types = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , None , '<STR_LIT>' ] <EOL> for legacy_type in legacy_types : <EOL> legacy_props = { <EOL> '<STR_LIT>' : legacy_type , <EOL> } <EOL> image_meta = objects . ImageMetaProps . from_dict ( legacy_props ) <EOL> if legacy_type == '<STR_LIT>' : <EOL> self . assertEqual ( '<STR_LIT>' , image_meta . hw_disk_bus ) <EOL> elif not legacy_type : <EOL> self . assertFalse ( image_meta . obj_attr_is_set ( '<STR_LIT>' ) ) <EOL> self . assertFalse ( image_meta . obj_attr_is_set ( '<STR_LIT>' ) ) <EOL> else : <EOL> self . assertEqual ( '<STR_LIT>' , image_meta . hw_disk_bus ) <EOL> if legacy_type == '<STR_LIT>' : <EOL> expected = '<STR_LIT>' <EOL> elif legacy_type == '<STR_LIT>' : <EOL> expected = '<STR_LIT>' <EOL> else : <EOL> expected = legacy_type . lower ( ) <EOL> self . assertEqual ( expected , image_meta . hw_scsi_model ) <EOL> def test_duplicate_legacy_and_normal_props ( self ) : <EOL> props = { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> virtprops = objects . ImageMetaProps . from_dict ( props ) <EOL> self . assertEqual ( '<STR_LIT>' , virtprops . hw_scsi_model ) <EOL> def test_get ( self ) : <EOL> props = objects . ImageMetaProps ( os_distro = '<STR_LIT>' ) <EOL> self . assertEqual ( '<STR_LIT>' , props . get ( '<STR_LIT>' ) ) <EOL> self . assertIsNone ( props . get ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( <NUM_LIT:1> , props . get ( '<STR_LIT>' , <NUM_LIT:1> ) ) <EOL> def test_set_numa_mem ( self ) : <EOL> props = { '<STR_LIT>' : <NUM_LIT:2> , <EOL> '<STR_LIT>' : "<STR_LIT>" , <EOL> '<STR_LIT>' : "<STR_LIT>" } <EOL> virtprops = objects . ImageMetaProps . from_dict ( props ) <EOL> self . assertEqual ( <NUM_LIT:2> , virtprops . hw_numa_nodes ) <EOL> self . assertEqual ( [ <NUM_LIT> , <NUM_LIT> ] , virtprops . hw_numa_mem ) <EOL> def test_set_numa_mem_sparse ( self ) : <EOL> props = { '<STR_LIT>' : <NUM_LIT:2> , <EOL> '<STR_LIT>' : "<STR_LIT>" , <EOL> '<STR_LIT>' : "<STR_LIT>" , <EOL> '<STR_LIT>' : "<STR_LIT>" } <EOL> virtprops = objects . ImageMetaProps . from_dict ( props ) <EOL> self . assertEqual ( <NUM_LIT:2> , virtprops . hw_numa_nodes ) <EOL> self . assertEqual ( [ <NUM_LIT> , <NUM_LIT> ] , virtprops . hw_numa_mem ) <EOL> def test_set_numa_mem_no_count ( self ) : <EOL> props = { '<STR_LIT>' : "<STR_LIT>" , <EOL> '<STR_LIT>' : "<STR_LIT>" } <EOL> virtprops = objects . ImageMetaProps . from_dict ( props ) <EOL> self . assertIsNone ( virtprops . get ( "<STR_LIT>" ) ) <EOL> self . assertEqual ( [ <NUM_LIT> ] , virtprops . hw_numa_mem ) <EOL> def test_set_numa_cpus ( self ) : <EOL> props = { '<STR_LIT>' : <NUM_LIT:2> , <EOL> '<STR_LIT>' : "<STR_LIT>" , <EOL> '<STR_LIT>' : "<STR_LIT>" } <EOL> virtprops = objects . ImageMetaProps . from_dict ( props ) <EOL> self . assertEqual ( <NUM_LIT:2> , virtprops . hw_numa_nodes ) <EOL> self . assertEqual ( [ set ( [ <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ] ) , set ( [ <NUM_LIT:4> , <NUM_LIT:5> , <NUM_LIT:6> , <NUM_LIT:7> ] ) ] , <EOL> virtprops . hw_numa_cpus ) <EOL> def test_set_numa_cpus_sparse ( self ) : <EOL> props = { '<STR_LIT>' : <NUM_LIT:4> , <EOL> '<STR_LIT>' : "<STR_LIT>" , <EOL> '<STR_LIT>' : "<STR_LIT>" , <EOL> '<STR_LIT>' : "<STR_LIT>" } <EOL> virtprops = objects . ImageMetaProps . from_dict ( props ) <EOL> self . assertEqual ( <NUM_LIT:4> , virtprops . hw_numa_nodes ) <EOL> self . assertEqual ( [ set ( [ <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ] ) , set ( [ <NUM_LIT:4> , <NUM_LIT:5> ] ) ] , <EOL> virtprops . hw_numa_cpus ) <EOL> def test_set_numa_cpus_no_count ( self ) : <EOL> props = { '<STR_LIT>' : "<STR_LIT>" , <EOL> '<STR_LIT>' : "<STR_LIT>" } <EOL> virtprops = objects . ImageMetaProps . from_dict ( props ) <EOL> self . assertIsNone ( virtprops . get ( "<STR_LIT>" ) ) <EOL> self . assertEqual ( [ set ( [ <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ] ) ] , <EOL> virtprops . hw_numa_cpus ) <EOL> def test_obj_make_compatible ( self ) : <EOL> props = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT:root>' , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : True , <EOL> } <EOL> obj = objects . ImageMetaProps ( ** props ) <EOL> primitive = obj . obj_to_primitive ( '<STR_LIT:1.0>' ) <EOL> self . assertFalse ( any ( [ x in primitive [ '<STR_LIT>' ] <EOL> for x in props ] ) ) <EOL> for bus in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> obj . hw_disk_bus = bus <EOL> self . assertRaises ( exception . ObjectActionError , <EOL> obj . obj_to_primitive , '<STR_LIT:1.0>' ) </s>
