def testConfigGetProperties(self): gftv = gfibertv.GFiberTv('http://localhost:%d' % srv_port) self.assertEqual(gftv.Config.foo, 'bar') self.assertEqual(gftv.Config.baz, '1') self.assertEqual(gftv.Config.woowoo, 'false') # by request from ACS team, nonexistent params return empty not fault self.assertEqual(gftv.Config.nonexistent, '')
def testConfigListProperties(self): """Verify that keys in Sage.properties are pre-populated in object.""" gftv = gfibertv.GFiberTv('http://localhost:%d' % srv_port) h = tr.handle.Handle(gftv) self.assertTrue(h.IsValidExport(gftv.Config, 'foo')) self.assertTrue(h.IsValidExport(gftv.Config, 'baz')) self.assertTrue(h.IsValidExport(gftv.Config, 'woowoo')) # by request from ACS team, nonexistent params return empty not fault self.assertTrue(h.IsValidExport(gftv.Config, 'does_not_exist_yet')) self.assertEqual(sorted(h.ListExports('Config', recursive=True)), [ 'baz', 'foo', 'sub.', 'sub.a', 'sub.b.', 'sub.b.c_d', 'sub.x_y.', 'sub.x_y.z_z', 'woowoo' ]) gftv.Config.sub.does_not_exist_yet = 'now_it_does' gftv.Config.whatever = 'something' self.assertEqual(gftv.Config.does_not_exist_yet, '') self.assertEqual(gftv.Config.whatever, 'something') self.assertEqual(gftv.Config.sub.whatever, '') self.assertEqual(sorted(h.ListExports('Config', recursive=False)), ['baz', 'foo', 'sub.', 'whatever', 'woowoo']) self.assertEqual(sorted(h.ListExports('Config', recursive=True)), [ 'baz', 'foo', 'sub.', 'sub.a', 'sub.b.', 'sub.b.c_d', 'sub.does_not_exist_yet', 'sub.x_y.', 'sub.x_y.z_z', 'whatever', 'woowoo' ])
def testValidate(self): tv = gfibertv.GFiberTv('http://localhost:%d' % srv_port) # pylint:disable=pointless-statement tv.Config tv.Config.export_params tv.Config.export_objects tr.handle.ValidateExports(tv)
def testDvrSpace(self): gftv = gfibertv.GFiberTv('http://localhost:%d' % srv_port) dvrspace = gftv.DvrSpace self.assertEqual(dvrspace.PermanentFiles, 10) self.assertEqual(dvrspace.PermanentMBytes, 1) self.assertEqual(dvrspace.TransientFiles, 20) self.assertEqual(dvrspace.TransientMBytes, 2)
def testOreganoFile(self): open(self.uicontrol_fname, 'w').write('http://uicontrol\n') gftv = gfibertv.GFiberTv('http://localhost:%d' % srv_port) self.assertEqual(gftv.UiControlUrl, 'http://uicontrol') gftv.UiControlUrl = 'http://cilantro' self.loop.RunOnce() self.assertEqual( open(self.uicontrol_fname).read(), 'http://cilantro\n')
def testUiChoice(self): gftv = gfibertv.GFiberTv('http://localhost:%d' % srv_port) gfibertv.UI_IS_HTML[0] = 'testdata/gfibertv/is-html-tv-ui-yes' self.assertEqual('oregano', gftv.UiChoice) gfibertv.UI_IS_HTML[0] = 'testdata/gfibertv/is-html-tv-ui-no' self.assertEqual('sage', gftv.UiChoice) gfibertv.UI_IS_HTML[ 0] = '/this/path/does/not/exist/please/do/not/create/it' self.assertEqual('none', gftv.UiChoice)
def testTcpAlgorithm(self): open(self.tcpalgorithm_fname, 'w').write('westwood') gftv = gfibertv.GFiberTv('http://localhost:%d' % srv_port) self.assertEqual(gftv.TcpAlgorithm, 'westwood') gftv.TcpAlgorithm = '' self.loop.RunOnce() self.assertFalse(os.path.exists(self.tcpalgorithm_fname)) gftv.TcpAlgorithm = 'foo' self.loop.RunOnce() self.assertEqual(open(self.tcpalgorithm_fname).read(), 'foo\n')
def testEASHeartbeatTimestamp(self): gftv = gfibertv.GFiberTv('http://localhost:%d' % srv_port) gfibertv.EASHEARTBEATFILE[0] = 'testdata/gfibertv/eas_heartbeat' self.assertEqual(tr.cwmpdate.format(gftv.EASHeartbeatTimestamp), '2012-11-09T22:26:40Z') gfibertv.EASHEARTBEATFILE[0] = '/path/to/nonexistant' self.assertEqual(tr.cwmpdate.format(gftv.EASHeartbeatTimestamp), '0001-01-01T00:00:00Z') gfibertv.EASHEARTBEATFILE[0] = 'testdata/gfibertv/eas_heartbeat.bad' self.assertEqual(tr.cwmpdate.format(gftv.EASHeartbeatTimestamp), '0001-01-01T00:00:00Z')
def testHnvram(self): gfibertv.HNVRAM[0] = 'testdata/gfibertv/hnvram_read' gftv = gfibertv.GFiberTv('http://localhost:%d' % srv_port) self.assertEqual('ThisIsTheUiType', gftv.UiType) path = os.path.join(self.tmpdir, 'hnvram') gfibertv.HNVRAM = ['testdata/gfibertv/hnvram_write', path] self.assertFalse(os.path.exists(self.uitype_fname)) gftv.UiType = 'SomeRandomUI' self.loop.RunOnce() self.assertEqual('SomeRandomUI', open(self.uitype_fname).read()) self.assertEqual('-w UITYPE=SomeRandomUI', open(path).read())
def testTvBuffer(self): open(self.tvbufferadddress_fname, 'w').write('1.2.3.4:1337\n') open(self.tvbufferkey_fname, 'w').write('monkeys\n') gftv = gfibertv.GFiberTv('http://localhost:%d' % srv_port) self.assertEqual(gftv.TvBufferAddress, '1.2.3.4:1337') self.assertEqual(gftv.TvBufferKey, 'monkeys') gftv.TvBufferAddress = '4.3.2.1:6666' gftv.TvBufferKey = 'monkeysaurus rex' self.loop.RunOnce() self.assertEqual( open(self.tvbufferadddress_fname).read(), '4.3.2.1:6666\n') self.assertEqual( open(self.tvbufferkey_fname).read(), 'monkeysaurus rex\n')
def testFrobnicast(self): open(self.frobnicastaddress_fname, 'w').write('[2620:0:1003::a811]:9533') open(self.frobnicastkey_fname, 'w').write('flying') gftv = gfibertv.GFiberTv('http://localhost:%d' % srv_port) self.assertEqual(gftv.FrobnicastAddress, '[2620:0:1003::a811]:9533') self.assertEqual(gftv.FrobnicastKey, 'flying') gftv.FrobnicastAddress = '[2620:0:1003::a812]:9633' gftv.FrobnicastKey = 'swimming' self.loop.RunOnce() self.assertEqual( open(self.frobnicastaddress_fname).read(), '[2620:0:1003::a812]:9633\n') self.assertEqual(open(self.frobnicastkey_fname).read(), 'swimming\n')
def testListManipulation(self): gftv = gfibertv.GFiberTv('http://localhost:%d' % srv_port) gftv.ValidateExports() self.assertEqual(0, gftv.DevicePropertiesNumberOfEntries) idx, newobj = gftv.AddExportObject('DeviceProperties', None) idx = int(idx) self.assertEqual(1, gftv.DevicePropertiesNumberOfEntries) self.assertEqual(newobj, gftv.DevicePropertiesList[idx]) gftv.StartTransaction() gftv.DevicePropertiesList[idx].StartTransaction() gftv.DevicePropertiesList[idx].NickName = 'testroom' gftv.DevicePropertiesList[idx].SerialNumber = '12345' gftv.DevicePropertiesList[idx].AbandonTransaction() gftv.AbandonTransaction() self.assertEqual('', gftv.DevicePropertiesList[idx].NickName) gftv.StartTransaction() idx2, newobj = gftv.AddExportObject('DeviceProperties', None) idx2 = int(idx2) gftv.DevicePropertiesList[idx].StartTransaction() gftv.DevicePropertiesList[idx].NickName = 'testroom' gftv.DevicePropertiesList[idx].SerialNumber = '12345' gftv.DevicePropertiesList[idx].CommitTransaction() gftv.DevicePropertiesList[idx2].StartTransaction() uni_name = u'\u212ced\nroom\n\r!'.encode('utf-8') gftv.DevicePropertiesList[idx2].NickName = uni_name gftv.DevicePropertiesList[idx2].SerialNumber = '56789' gftv.DevicePropertiesList[idx2].CommitTransaction() gftv.CommitTransaction() # read the test file back in. f = file(gfibertv.NICKFILE, 'r') lines = set() lines.add(f.readline()) lines.add(f.readline()) last_line = f.readline() last_line = last_line.strip() self.assertTrue('12345/nickname=testroom\n' in lines) self.assertTrue('56789/nickname=\u212cedroom!\n' in lines) self.assertTrue(last_line.startswith('SERIALS=')) split1 = last_line.split('=') self.assertEqual(2, len(split1)) split2 = split1[1].split(',') self.assertTrue('12345' in split2) self.assertTrue('56789' in split2) f.close()
def testListManipulation(self): gftv = gfibertv.GFiberTv('http://localhost:%d' % srv_port) h = tr.handle.Handle(gftv) self.assertEqual(0, gftv.DevicePropertiesNumberOfEntries) idx, newobj = h.AddExportObject('DeviceProperties', None) idx = int(idx) self.assertEqual(1, gftv.DevicePropertiesNumberOfEntries) self.assertEqual(newobj, gftv.DevicePropertiesList[idx]) self.assertEqual(None, gftv.DevicePropertiesList[idx].NickName) idx2, newobj = h.AddExportObject('DeviceProperties', None) idx2 = int(idx2) idx3, newobj = h.AddExportObject('DeviceProperties', None) idx3 = int(idx3) idx4, newobj = h.AddExportObject('DeviceProperties', None) idx4 = int(idx4) gftv.DevicePropertiesList[idx].NickName = 'testroom' gftv.DevicePropertiesList[idx].SerialNumber = '12345' uni_name = u'\u212ced\nroom\n\r!' gftv.DevicePropertiesList[idx2].NickName = uni_name gftv.DevicePropertiesList[idx2].SerialNumber = '56789' gftv.DevicePropertiesList[idx3].NickName = "Peter's Room" gftv.DevicePropertiesList[idx3].SerialNumber = '23456' gftv.DevicePropertiesList[idx4].NickName = 'War & Peace' gftv.DevicePropertiesList[idx4].SerialNumber = '8675309' self.loop.RunOnce() # read the test file back in. lines = open(gfibertv.NICKFILE[0], 'r').readlines() last_line = lines and lines[-1].strip() self.assertTrue('12345/nickname=testroom\n' in lines) self.assertTrue('56789/nickname=\\u212ced_room__!\n' in lines) self.assertTrue("23456/nickname=Peter's Room\n" in lines) self.assertTrue('8675309/nickname=War & Peace\n' in lines) self.assertTrue(last_line.startswith('serials=')) split1 = last_line.split('=') self.assertEqual(2, len(split1)) split2 = split1[1].split(',') self.assertTrue('12345' in split2) self.assertTrue('56789' in split2) self.assertTrue('23456' in split2) self.assertTrue('8675309' in split2)
def testNoPairing(self): gftv = gfibertv.GFiberTv('http://localhost:%d' % srv_port) gftv.ValidateExports() self.assertFalse(gftv.BtNoPairing) gftv.BtNoPairing = True self.assertTrue(gftv.BtNoPairing) # Make sure setting to True works if it is already true. gftv.BtNoPairing = True self.assertTrue(gftv.BtNoPairing) gftv.BtNoPairing = False self.assertFalse(gftv.BtNoPairing) gftv.BtNoPairing = False self.assertFalse(gftv.BtNoPairing)
def PlatformInit(name, device_model_root): """Create platform-specific device models and initialize platform.""" tr.download.INSTALLER = Installer params = [] objects = [] dev_id = DeviceId() periodic_stats = dm.periodic_statistics.PeriodicStatistics() device_model_root.Device = Device(dev_id, periodic_stats) device_model_root.InternetGatewayDevice = InternetGatewayDevice( dev_id, periodic_stats) device_model_root.X_GOOGLE_COM_GVSB = gvsb.Gvsb() tvrpc = gfibertv.GFiberTv('http://localhost:51834/xmlrpc') device_model_root.X_GOOGLE_COM_GFIBERTV = tvrpc objects.append('Device') objects.append('InternetGatewayDevice') objects.append('X_GOOGLE-COM_GVSB') objects.append('X_GOOGLE-COM_GFIBERTV') return (params, objects)
def testConfigSetProperties(self): gftv = gfibertv.GFiberTv('http://localhost:%d' % srv_port) gftv.Config.foo = 'updated1' self.assertEqual(gftv.Config.foo, 'updated1') gftv.Config.baz = 3 self.assertEqual(gftv.Config.baz, '3') gftv.Config.does_not_exist_yet = 'now_it_does' self.assertEqual(gftv.Config.does_not_exist_yet, 'now_it_does') gftv.Config.sub.x_y.z = 'test' gftv.Config.sub.x_y.a = 'test2' gftv.Config.sub.b.c_d = 'hello' gftv.Config.sub.x_y.z_z = 'world' gftv._rpcclient.SaveProperties() self._CheckPropsInclude('does_not_exist_yet=now_it_does') self._CheckPropsInclude('sub/x:y/z=test') self._CheckPropsInclude('sub/x:y/a=test2') self._CheckPropsInclude('sub/b/c.d=hello') self._CheckPropsInclude('sub/x:y/z.z=world')
def testMyNickname(self): mailbox_url = 'http://localhost:%d' % srv_port my_serial = '12345' gftv = gfibertv.GFiberTv(mailbox_url=mailbox_url, my_serial=my_serial) h = tr.handle.Handle(gftv) idx, newobj = h.AddExportObject('DeviceProperties', None) idx = int(idx) self.assertEqual(newobj, gftv.DevicePropertiesList[idx]) self.assertEqual(None, gftv.DevicePropertiesList[idx].NickName) my_nickname = u'\u212ced\nroom\n\r!' gftv.DevicePropertiesList[idx].NickName = my_nickname gftv.DevicePropertiesList[idx].SerialNumber = '12345' self.loop.RunOnce() mynickfile = open(gfibertv.MYNICKFILE[0]).read() self.assertEqual(mynickfile, my_nickname.encode('utf-8'))
def testBtFiles(self): gftv = gfibertv.GFiberTv('http://localhost:%d' % srv_port) gftv.ValidateExports() def CheckNoTrashLeft(): self.assertEqual(None, gftv.config.bt_devices) self.assertEqual(None, gftv.config.bt_hh_devices) self.assertEqual(None, gftv.config.bt_hh_devices) CheckNoTrashLeft() self.assertEqual('', gftv.BtDevices) self.assertEqual('', gftv.BtHHDevices) self.assertEqual('', gftv.BtConfig) devices1 = 'This is a test' devices2 = 'devices test 2' hhdevices = 'hhdevice str\nwith a newline' config = 'btconfig str' gftv.StartTransaction() gftv.BtDevices = devices1 gftv.CommitTransaction() self.assertEqual(devices1, gftv.BtDevices) self.assertEqual('', gftv.BtHHDevices) self.assertEqual('', gftv.BtConfig) CheckNoTrashLeft() gftv.StartTransaction() gftv.BtDevices = devices2 gftv.BtHHDevices = hhdevices gftv.BtConfig = config gftv.CommitTransaction() self.assertEqual(devices2, gftv.BtDevices) self.assertEqual(hhdevices, gftv.BtHHDevices) self.assertEqual(config, gftv.BtConfig) CheckNoTrashLeft()
def testEASFipsServiceAddress(self): gftv = gfibertv.GFiberTv('http://localhost:%d' % srv_port) gftv.EASServiceAddress = 'Service Addr' self.loop.RunOnce() self.assertEqual(open(self.easaddr_fname).read(), 'Service Addr\n')
def testValidate(self): tv = gfibertv.GFiberTv('http://localhost:%d' % srv_port) tv.Mailbox.Node = 'Node1' tv.Mailbox.Name = 'Prop1' tv.ValidateExports()
def testObject41(self): gftv = gfibertv.GFiberTv('http://localhost:%d' % srv_port) h = tr.handle.Handle(gftv) h.AddExportObject('DeviceProperties', None)
def testHnvramFails(self): gfibertv.HNVRAM[0] = '/nosuchfile' gftv = gfibertv.GFiberTv('http://localhost:%d' % srv_port) self.assertRaises(OSError, lambda: setattr(gftv, 'UiType', 'foo')) gfibertv.HNVRAM[0] = 'testdata/gfibertv/hnvram_error' self.assertRaises(OSError, lambda: setattr(gftv, 'UiType', 'foo'))
def testObject50(self): gftv = gfibertv.GFiberTv('http://localhost:%d' % srv_port) _ = gftv.Config.foo self.assertTrue(1)
def testConfigProtocolError(self): gftv = gfibertv.GFiberTv('http://localhost:2') # Can't connect to server, so gets succeed, but sets fail self.assertEqual(gftv.Config.foo, 'bar') with self.assertRaises(ValueError): gftv.Config.foo = 'anything'
def testEASFipsCode(self): gftv = gfibertv.GFiberTv('http://localhost:%d' % srv_port) gftv.EASFipsCode = 'FIPS Code' self.loop.RunOnce() self.assertEqual(open(self.easfips_fname).read(), 'FIPS Code\n')
def testObject40(self): gftv = gfibertv.GFiberTv('http://localhost:%d' % srv_port) _ = gftv.UiType
def testEASFipsServicePort(self): gftv = gfibertv.GFiberTv('http://localhost:%d' % srv_port) gftv.EASServicePort = 'Service Port' self.loop.RunOnce() self.assertEqual(open(self.easport_fname).read(), 'Service Port\n')
def testObject10(self): gfibertv.GFiberTv('http://localhost:%d' % srv_port)