<s> from nova import exception <EOL> from nova import test <EOL> from nova . virt import diagnostics <EOL> class DiagnosticsTests ( test . NoDBTestCase ) : <EOL> def test_cpu_diagnostics_default ( self ) : <EOL> cpu = diagnostics . CpuDiagnostics ( ) <EOL> self . assertEqual ( <NUM_LIT:0> , cpu . time ) <EOL> def test_cpu_diagnostics ( self ) : <EOL> cpu = diagnostics . CpuDiagnostics ( time = <NUM_LIT:7> ) <EOL> self . assertEqual ( <NUM_LIT:7> , cpu . time ) <EOL> def test_nic_diagnostics_default ( self ) : <EOL> nic = diagnostics . NicDiagnostics ( ) <EOL> self . assertEqual ( '<STR_LIT>' , nic . mac_address ) <EOL> self . assertEqual ( <NUM_LIT:0> , nic . rx_octets ) <EOL> self . assertEqual ( <NUM_LIT:0> , nic . rx_errors ) <EOL> self . assertEqual ( <NUM_LIT:0> , nic . rx_drop ) <EOL> self . assertEqual ( <NUM_LIT:0> , nic . rx_packets ) <EOL> self . assertEqual ( <NUM_LIT:0> , nic . tx_octets ) <EOL> self . assertEqual ( <NUM_LIT:0> , nic . tx_errors ) <EOL> self . assertEqual ( <NUM_LIT:0> , nic . tx_drop ) <EOL> self . assertEqual ( <NUM_LIT:0> , nic . tx_packets ) <EOL> def test_nic_diagnostics ( self ) : <EOL> nic = diagnostics . NicDiagnostics ( mac_address = '<STR_LIT>' , <EOL> rx_octets = <NUM_LIT:1> , rx_errors = <NUM_LIT:2> , rx_drop = <NUM_LIT:3> , rx_packets = <NUM_LIT:4> , <EOL> tx_octets = <NUM_LIT:5> , tx_errors = <NUM_LIT:6> , tx_drop = <NUM_LIT:7> , tx_packets = <NUM_LIT:8> ) <EOL> self . assertEqual ( '<STR_LIT>' , nic . mac_address ) <EOL> self . assertEqual ( <NUM_LIT:1> , nic . rx_octets ) <EOL> self . assertEqual ( <NUM_LIT:2> , nic . rx_errors ) <EOL> self . assertEqual ( <NUM_LIT:3> , nic . rx_drop ) <EOL> self . assertEqual ( <NUM_LIT:4> , nic . rx_packets ) <EOL> self . assertEqual ( <NUM_LIT:5> , nic . tx_octets ) <EOL> self . assertEqual ( <NUM_LIT:6> , nic . tx_errors ) <EOL> self . assertEqual ( <NUM_LIT:7> , nic . tx_drop ) <EOL> self . assertEqual ( <NUM_LIT:8> , nic . tx_packets ) <EOL> def test_disk_diagnostics_default ( self ) : <EOL> disk = diagnostics . DiskDiagnostics ( ) <EOL> self . assertEqual ( '<STR_LIT>' , disk . id ) <EOL> self . assertEqual ( <NUM_LIT:0> , disk . read_bytes ) <EOL> self . assertEqual ( <NUM_LIT:0> , disk . read_requests ) <EOL> self . assertEqual ( <NUM_LIT:0> , disk . write_bytes ) <EOL> self . assertEqual ( <NUM_LIT:0> , disk . write_requests ) <EOL> self . assertEqual ( <NUM_LIT:0> , disk . errors_count ) <EOL> def test_disk_diagnostics ( self ) : <EOL> disk = diagnostics . DiskDiagnostics ( id = '<STR_LIT>' , <EOL> read_bytes = <NUM_LIT:1> , read_requests = <NUM_LIT:2> , <EOL> write_bytes = <NUM_LIT:3> , write_requests = <NUM_LIT:4> , <EOL> errors_count = <NUM_LIT:5> ) <EOL> self . assertEqual ( '<STR_LIT>' , disk . id ) <EOL> self . assertEqual ( <NUM_LIT:1> , disk . read_bytes ) <EOL> self . assertEqual ( <NUM_LIT:2> , disk . read_requests ) <EOL> self . assertEqual ( <NUM_LIT:3> , disk . write_bytes ) <EOL> self . assertEqual ( <NUM_LIT:4> , disk . write_requests ) <EOL> self . assertEqual ( <NUM_LIT:5> , disk . errors_count ) <EOL> def test_memory_diagnostics_default ( self ) : <EOL> memory = diagnostics . MemoryDiagnostics ( ) <EOL> self . assertEqual ( <NUM_LIT:0> , memory . maximum ) <EOL> self . assertEqual ( <NUM_LIT:0> , memory . used ) <EOL> def test_memory_diagnostics ( self ) : <EOL> memory = diagnostics . MemoryDiagnostics ( maximum = <NUM_LIT:1> , used = <NUM_LIT:2> ) <EOL> self . assertEqual ( <NUM_LIT:1> , memory . maximum ) <EOL> self . assertEqual ( <NUM_LIT:2> , memory . used ) <EOL> def test_diagnostics_default ( self ) : <EOL> diags = diagnostics . Diagnostics ( ) <EOL> self . assertIsNone ( diags . state ) <EOL> self . assertIsNone ( diags . driver ) <EOL> self . assertIsNone ( diags . hypervisor_os ) <EOL> self . assertEqual ( <NUM_LIT:0> , diags . uptime ) <EOL> self . assertFalse ( diags . config_drive ) <EOL> self . assertEqual ( [ ] , diags . cpu_details ) <EOL> self . assertEqual ( [ ] , diags . nic_details ) <EOL> self . assertEqual ( [ ] , diags . disk_details ) <EOL> self . assertEqual ( <NUM_LIT:0> , diags . memory_details . maximum ) <EOL> self . assertEqual ( <NUM_LIT:0> , diags . memory_details . used ) <EOL> self . assertEqual ( '<STR_LIT:1.0>' , diags . version ) <EOL> def test_diagnostics ( self ) : <EOL> cpu_details = [ diagnostics . CpuDiagnostics ( ) ] <EOL> nic_details = [ diagnostics . NicDiagnostics ( ) ] <EOL> disk_details = [ diagnostics . DiskDiagnostics ( ) ] <EOL> diags = diagnostics . Diagnostics ( <EOL> state = '<STR_LIT>' , driver = '<STR_LIT>' , <EOL> hypervisor_os = '<STR_LIT>' , <EOL> uptime = <NUM_LIT:1> , cpu_details = cpu_details , <EOL> nic_details = nic_details , disk_details = disk_details , <EOL> config_drive = True ) <EOL> self . assertEqual ( '<STR_LIT>' , diags . state ) <EOL> self . assertEqual ( '<STR_LIT>' , diags . driver ) <EOL> self . assertEqual ( '<STR_LIT>' , diags . hypervisor_os ) <EOL> self . assertEqual ( <NUM_LIT:1> , diags . uptime ) <EOL> self . assertTrue ( diags . config_drive ) <EOL> self . assertEqual ( <NUM_LIT:1> , len ( diags . cpu_details ) ) <EOL> self . assertEqual ( <NUM_LIT:1> , len ( diags . nic_details ) ) <EOL> self . assertEqual ( <NUM_LIT:1> , len ( diags . disk_details ) ) <EOL> self . assertEqual ( <NUM_LIT:0> , diags . memory_details . maximum ) <EOL> self . assertEqual ( <NUM_LIT:0> , diags . memory_details . used ) <EOL> self . assertEqual ( '<STR_LIT:1.0>' , diags . version ) <EOL> def test_add_cpu ( self ) : <EOL> diags = diagnostics . Diagnostics ( ) <EOL> self . assertEqual ( [ ] , diags . cpu_details ) <EOL> diags . add_cpu ( time = <NUM_LIT:7> ) <EOL> self . assertEqual ( <NUM_LIT:1> , len ( diags . cpu_details ) ) <EOL> self . assertEqual ( <NUM_LIT:7> , diags . cpu_details [ <NUM_LIT:0> ] . time ) <EOL> def test_add_nic ( self ) : <EOL> diags = diagnostics . Diagnostics ( ) <EOL> self . assertEqual ( [ ] , diags . nic_details ) <EOL> diags . add_nic ( mac_address = '<STR_LIT>' , <EOL> rx_octets = <NUM_LIT:1> , rx_errors = <NUM_LIT:2> , rx_drop = <NUM_LIT:3> , rx_packets = <NUM_LIT:4> , <EOL> tx_octets = <NUM_LIT:5> , tx_errors = <NUM_LIT:6> , tx_drop = <NUM_LIT:7> , tx_packets = <NUM_LIT:8> ) <EOL> self . assertEqual ( <NUM_LIT:1> , len ( diags . nic_details ) ) <EOL> self . assertEqual ( '<STR_LIT>' , diags . nic_details [ <NUM_LIT:0> ] . mac_address ) <EOL> self . assertEqual ( <NUM_LIT:1> , diags . nic_details [ <NUM_LIT:0> ] . rx_octets ) <EOL> self . assertEqual ( <NUM_LIT:2> , diags . nic_details [ <NUM_LIT:0> ] . rx_errors ) <EOL> self . assertEqual ( <NUM_LIT:3> , diags . nic_details [ <NUM_LIT:0> ] . rx_drop ) <EOL> self . assertEqual ( <NUM_LIT:4> , diags . nic_details [ <NUM_LIT:0> ] . rx_packets ) <EOL> self . assertEqual ( <NUM_LIT:5> , diags . nic_details [ <NUM_LIT:0> ] . tx_octets ) <EOL> self . assertEqual ( <NUM_LIT:6> , diags . nic_details [ <NUM_LIT:0> ] . tx_errors ) <EOL> self . assertEqual ( <NUM_LIT:7> , diags . nic_details [ <NUM_LIT:0> ] . tx_drop ) <EOL> self . assertEqual ( <NUM_LIT:8> , diags . nic_details [ <NUM_LIT:0> ] . tx_packets ) <EOL> def test_add_disk ( self ) : <EOL> diags = diagnostics . Diagnostics ( ) <EOL> self . assertEqual ( [ ] , diags . disk_details ) <EOL> diags . add_disk ( id = '<STR_LIT>' , <EOL> read_bytes = <NUM_LIT:1> , read_requests = <NUM_LIT:2> , <EOL> write_bytes = <NUM_LIT:3> , write_requests = <NUM_LIT:4> , <EOL> errors_count = <NUM_LIT:5> ) <EOL> self . assertEqual ( <NUM_LIT:1> , len ( diags . disk_details ) ) <EOL> self . assertEqual ( '<STR_LIT>' , diags . disk_details [ <NUM_LIT:0> ] . id ) <EOL> self . assertEqual ( <NUM_LIT:1> , diags . disk_details [ <NUM_LIT:0> ] . read_bytes ) <EOL> self . assertEqual ( <NUM_LIT:2> , diags . disk_details [ <NUM_LIT:0> ] . read_requests ) <EOL> self . assertEqual ( <NUM_LIT:3> , diags . disk_details [ <NUM_LIT:0> ] . write_bytes ) <EOL> self . assertEqual ( <NUM_LIT:4> , diags . disk_details [ <NUM_LIT:0> ] . write_requests ) <EOL> self . assertEqual ( <NUM_LIT:5> , diags . disk_details [ <NUM_LIT:0> ] . errors_count ) <EOL> def test_diagnostics_serialize_default ( self ) : <EOL> diags = diagnostics . Diagnostics ( ) <EOL> expected = { '<STR_LIT>' : False , <EOL> '<STR_LIT>' : [ ] , <EOL> '<STR_LIT>' : [ ] , <EOL> '<STR_LIT>' : None , <EOL> '<STR_LIT>' : None , <EOL> '<STR_LIT>' : { '<STR_LIT>' : <NUM_LIT:0> , '<STR_LIT>' : <NUM_LIT:0> } , <EOL> '<STR_LIT>' : [ ] , <EOL> '<STR_LIT:state>' : None , <EOL> '<STR_LIT>' : <NUM_LIT:0> , <EOL> '<STR_LIT:version>' : '<STR_LIT:1.0>' } <EOL> result = diags . serialize ( ) <EOL> self . assertEqual ( expected , result ) <EOL> def test_diagnostics_serialize ( self ) : <EOL> cpu_details = [ diagnostics . CpuDiagnostics ( ) ] <EOL> nic_details = [ diagnostics . NicDiagnostics ( ) ] <EOL> disk_details = [ diagnostics . DiskDiagnostics ( ) ] <EOL> diags = diagnostics . Diagnostics ( <EOL> state = '<STR_LIT>' , driver = '<STR_LIT>' , <EOL> hypervisor_os = '<STR_LIT>' , <EOL> uptime = <NUM_LIT:1> , cpu_details = cpu_details , <EOL> nic_details = nic_details , disk_details = disk_details , <EOL> config_drive = True ) <EOL> expected = { '<STR_LIT>' : True , <EOL> '<STR_LIT>' : [ { '<STR_LIT:time>' : <NUM_LIT:0> } ] , <EOL> '<STR_LIT>' : [ { '<STR_LIT>' : <NUM_LIT:0> , <EOL> '<STR_LIT:id>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : <NUM_LIT:0> , <EOL> '<STR_LIT>' : <NUM_LIT:0> , <EOL> '<STR_LIT>' : <NUM_LIT:0> , <EOL> '<STR_LIT>' : <NUM_LIT:0> } ] , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : { '<STR_LIT>' : <NUM_LIT:0> , '<STR_LIT>' : <NUM_LIT:0> } , <EOL> '<STR_LIT>' : [ { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : <NUM_LIT:0> , <EOL> '<STR_LIT>' : <NUM_LIT:0> , <EOL> '<STR_LIT>' : <NUM_LIT:0> , <EOL> '<STR_LIT>' : <NUM_LIT:0> , <EOL> '<STR_LIT>' : <NUM_LIT:0> , <EOL> '<STR_LIT>' : <NUM_LIT:0> , <EOL> '<STR_LIT>' : <NUM_LIT:0> , <EOL> '<STR_LIT>' : <NUM_LIT:0> } ] , <EOL> '<STR_LIT:state>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : <NUM_LIT:1> , <EOL> '<STR_LIT:version>' : '<STR_LIT:1.0>' } <EOL> result = diags . serialize ( ) <EOL> self . assertEqual ( expected , result ) <EOL> def test_diagnostics_invalid_input ( self ) : <EOL> self . assertRaises ( exception . InvalidInput , <EOL> diagnostics . Diagnostics , <EOL> cpu_details = '<STR_LIT>' ) <EOL> self . assertRaises ( exception . InvalidInput , <EOL> diagnostics . Diagnostics , <EOL> cpu_details = [ '<STR_LIT>' ] ) <EOL> self . assertRaises ( exception . InvalidInput , <EOL> diagnostics . Diagnostics , <EOL> nic_details = '<STR_LIT>' ) <EOL> self . assertRaises ( exception . InvalidInput , <EOL> diagnostics . Diagnostics , <EOL> nic_details = [ '<STR_LIT>' ] ) <EOL> self . assertRaises ( exception . InvalidInput , <EOL> diagnostics . Diagnostics , <EOL> disk_details = '<STR_LIT>' ) <EOL> self . assertRaises ( exception . InvalidInput , <EOL> diagnostics . Diagnostics , <EOL> disk_details = [ '<STR_LIT>' ] ) </s>
