def test_get_interfaces_if_stats_fails_raise_exception(self):
     ex = exceptions.KempTechApiException()
     ex2 = exceptions.KempTechApiException()
     ex.status_code = 422
     self._get.side_effect = [ex, ex2]
     actual = self.lm.get_interfaces()
     expected = []
     assert_equal(actual, expected)
Пример #2
0
 def test_get_interfaces_when_new_showiface_doesnt_exist(self):
     stats_resp = """<Response stat="200" code="ok"> <Success> <Data> <CPU> <total> <User>0</User> <System>1</System> <Idle>99</Idle> <IOWaiting>0</IOWaiting> </total> <cpu0> <User>0</User> <System>1</System> <HWInterrupts>0</HWInterrupts> <SWInterrupts>0</SWInterrupts> <Idle>99</Idle> <IOWaiting>0</IOWaiting> </cpu0> <cpu1> <User>0</User> <System>1</System> <HWInterrupts>0</HWInterrupts> <SWInterrupts>0</SWInterrupts> <Idle>99</Idle> <IOWaiting>0</IOWaiting> </cpu1> </CPU> <Memory> <memused>300528</memused> <percentmemused>14</percentmemused> <memfree>1756204</memfree> <percentmemfree>86</percentmemfree> </Memory> <Network> <eth0> <ifaceID>0</ifaceID> <speed>1000</speed> <in>0.0</in> <inbytes>113</inbytes> <inbytesTotal>34664393</inbytesTotal> <out>0.0</out> <outbytes>86</outbytes> <outbytesTotal>33503963</outbytesTotal> </eth0> <eth1> <ifaceID>1</ifaceID> <speed>1000</speed> <in>0.0</in> <inbytes>0</inbytes> <inbytesTotal>900</inbytesTotal> <out>0.0</out> <outbytes>0</outbytes> <outbytesTotal>2844</outbytesTotal> </eth1> </Network> <TPS> <Total>0</Total> <SSL>0</SSL> </TPS> <VStotals> <ConnsPerSec>0</ConnsPerSec> <TotalConns>0</TotalConns> <BitsPerSec>0</BitsPerSec> <TotalBits>0</TotalBits> <BytesPerSec>0</BytesPerSec> <TotalBytes>0</TotalBytes> <PktsPerSec>0</PktsPerSec> <TotalPackets>0</TotalPackets> </VStotals> <Vs> <VSAddress>10.35.14.200</VSAddress> <VSPort>80</VSPort> <VSProt>tcp</VSProt> <Index>1</Index> <ErrorCode>0</ErrorCode> <Enable>1</Enable> <TotalConns>0</TotalConns> <TotalPkts>0</TotalPkts> <TotalBytes>0</TotalBytes> <TotalBits>0</TotalBits> <ActiveConns>0</ActiveConns> <BytesRead>0</BytesRead> <BytesWritten>0</BytesWritten> <ConnsPerSec>0</ConnsPerSec> <WafEnable>0</WafEnable> </Vs> <Rs> <VSIndex>1</VSIndex> <RSIndex>1</RSIndex> <Addr>10.35.14.7</Addr> <Port>80</Port> <Enable>1</Enable> <Weight>1000</Weight> <ActivConns>0</ActivConns> <Persist>0</Persist> <Conns>0</Conns> <Pkts>0</Pkts> <Bytes>0</Bytes> <Bits>0</Bits> <BytesRead>0</BytesRead> <BytesWritten>0</BytesWritten> <ConnsPerSec>0</ConnsPerSec> </Rs> </Data> </Success> </Response>"""
     showiface0_resp = """<Response stat="200" code="ok"> <Success> <Data> <Interface> <Id>0</Id> <IPAddress>10.35.14.5/24</IPAddress> <Mtu>1500</Mtu> <InterfaceType>Port</InterfaceType> <GeoTrafficEnable>yes</GeoTrafficEnable> <DefaultInterface>yes</DefaultInterface> <AdminWuiEnable>yes</AdminWuiEnable> </Interface> </Data> </Success> </Response>"""
     showiface1_resp = """<Response stat="200" code="ok"> <Success> <Data> <Interface> <Id>1</Id> <IPAddress>10.35.15.5/24</IPAddress> <Mtu>1500</Mtu> <InterfaceType>Port</InterfaceType> <GeoTrafficEnable>no</GeoTrafficEnable> <DefaultInterface>no</DefaultInterface> <AdminWuiEnable>no</AdminWuiEnable> </Interface> </Data> </Success> </Response>"""
     ex = exceptions.KempTechApiException()
     ex.status_code = 422
     self._get.side_effect = [ex, stats_resp, showiface0_resp, showiface1_resp]
     actual = self.lm.get_interfaces()
     expected_iface_eth0 = Interface(self.lm.access_info, 0)
     expected_iface_eth0.address = "10.35.14.5"
     expected_iface_eth0.cidr = "24"
     expected_iface_eth1 = Interface(self.lm.access_info, 1)
     expected_iface_eth1.address = "10.35.15.5"
     expected_iface_eth1.cidr = "24"
     expected = [expected_iface_eth0, expected_iface_eth1]
     assert_equal(len(expected), len(actual))
     for expected_iface, actual_iface in zip(expected, actual):
         assert_equal(expected_iface.addr, actual_iface.addr)
 def test_get_interfaces_raises_non_422_exceptions(self):
     ex = exceptions.KempTechApiException()
     ex.status_code = 401
     self._get.side_effect = ex
     with assert_raises(exceptions.KempTechApiException):
         actual = self.lm.get_interfaces()