Changeset 451d79a in trunk
- Timestamp:
- 2022-01-07T18:49:04Z (3 years ago)
- Branches:
- master
- Children:
- 3a6f0c0a, db5c65e
- Parents:
- 4cdbf7fb (diff), 96445329 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent. - git-author:
- meejah <meejah@…> (2022-01-07 18:49:04)
- git-committer:
- GitHub <noreply@…> (2022-01-07 18:49:04)
- Files:
-
- 1 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified src/allmydata/test/web/test_root.py ¶
r4cdbf7fb r451d79a 12 12 13 13 import time 14 import json 14 15 15 16 from urllib.parse import ( … … 25 26 from twisted.application import service 26 27 from testtools.twistedsupport import succeeded 27 from twisted.internet.defer import inlineCallbacks 28 from twisted.internet.defer import ( 29 inlineCallbacks, 30 succeed, 31 ) 28 32 29 33 from ...storage_client import ( … … 31 35 StorageFarmBroker, 32 36 ) 33 from ...web.root import RootElement 37 from ...web.root import ( 38 RootElement, 39 Root, 40 ) 34 41 from ...util.connection_status import ConnectionStatus 42 from ...crypto.ed25519 import ( 43 create_signing_keypair, 44 ) 35 45 from allmydata.web.root import URIHandler 36 46 from allmydata.client import _Client … … 48 58 from ..common import ( 49 59 SyncTestCase, 60 AsyncTestCase, 50 61 ) 51 62 … … 139 150 self.assertThat(item.slotData.get("version"), Equals("")) 140 151 self.assertThat(item.slotData.get("nickname"), Equals("")) 152 153 154 class RenderRoot(AsyncTestCase): 155 156 @inlineCallbacks 157 def test_root_json(self): 158 """ 159 The 'welcome' / root page renders properly with ?t=json when some 160 servers show None for available_space while others show a 161 valid int 162 163 See also https://tahoe-lafs.org/trac/tahoe-lafs/ticket/3852 164 """ 165 ann = { 166 "anonymous-storage-FURL": "pb://w2hqnbaa25yw4qgcvghl5psa3srpfgw3@tcp:127.0.0.1:51309/vucto2z4fxment3vfxbqecblbf6zyp6x", 167 "permutation-seed-base32": "w2hqnbaa25yw4qgcvghl5psa3srpfgw3", 168 } 169 srv0 = NativeStorageServer(b"server_id0", ann, None, {}, EMPTY_CLIENT_CONFIG) 170 srv0.get_connection_status = lambda: ConnectionStatus(False, "summary0", {}, 0, 0) 171 172 srv1 = NativeStorageServer(b"server_id1", ann, None, {}, EMPTY_CLIENT_CONFIG) 173 srv1.get_connection_status = lambda: ConnectionStatus(False, "summary1", {}, 0, 0) 174 # arrange for this server to have some valid available space 175 srv1.get_available_space = lambda: 12345 176 177 class FakeClient(_Client): 178 history = [] 179 stats_provider = object() 180 nickname = "" 181 nodeid = b"asdf" 182 _node_public_key = create_signing_keypair()[1] 183 introducer_clients = [] 184 helper = None 185 186 def __init__(self): 187 service.MultiService.__init__(self) 188 self.storage_broker = StorageFarmBroker( 189 permute_peers=True, 190 tub_maker=None, 191 node_config=EMPTY_CLIENT_CONFIG, 192 ) 193 self.storage_broker.test_add_server(b"test-srv0", srv0) 194 self.storage_broker.test_add_server(b"test-srv1", srv1) 195 196 root = Root(FakeClient(), now_fn=time.time) 197 198 lines = [] 199 200 req = DummyRequest(b"") 201 req.fields = {} 202 req.args = { 203 b"t": [b"json"], 204 } 205 206 # for some reason, DummyRequest is already finished when we 207 # try to add a notifyFinish handler, so override that 208 # behavior. 209 210 def nop(): 211 return succeed(None) 212 req.notifyFinish = nop 213 req.write = lines.append 214 215 yield root.render(req) 216 217 raw_js = b"".join(lines).decode("utf8") 218 js = json.loads(raw_js) 219 servers = js["servers"] 220 self.assertEquals(len(servers), 2) 221 self.assertIn( 222 { 223 "connection_status": "summary0", 224 "nodeid": "server_id0", 225 "last_received_data": 0, 226 "version": None, 227 "available_space": None, 228 "nickname": "" 229 }, 230 servers 231 ) 232 self.assertIn( 233 { 234 "connection_status": "summary1", 235 "nodeid": "server_id1", 236 "last_received_data": 0, 237 "version": None, 238 "available_space": 12345, 239 "nickname": "" 240 }, 241 servers 242 ) -
TabularUnified src/allmydata/test/web/test_web.py ¶
r4cdbf7fb r451d79a 821 821 d = self.GET("/?t=json") 822 822 def _check(res): 823 """ 824 Check that the results are correct. 825 We can't depend on the order of servers in the output 826 """ 823 827 decoded = json.loads(res) 824 expected = { 825 u'introducers': { 826 u'statuses': [], 828 self.assertEqual(decoded['introducers'], {u'statuses': []}) 829 actual_servers = decoded[u"servers"] 830 self.assertEquals(len(actual_servers), 2) 831 self.assertIn( 832 { 833 u"nodeid": u'other_nodeid', 834 u'available_space': 123456, 835 u'connection_status': u'summary', 836 u'last_received_data': 30, 837 u'nickname': u'other_nickname \u263b', 838 u'version': u'1.0', 827 839 }, 828 u'servers': sorted([ 829 {u"nodeid": u'other_nodeid', 830 u'available_space': 123456, 831 u'connection_status': u'summary', 832 u'last_received_data': 30, 833 u'nickname': u'other_nickname \u263b', 834 u'version': u'1.0', 835 }, 836 {u"nodeid": u'disconnected_nodeid', 837 u'available_space': 123456, 838 u'connection_status': u'summary', 839 u'last_received_data': 35, 840 u'nickname': u'disconnected_nickname \u263b', 841 u'version': u'1.0', 842 }, 843 ], key=lambda o: sorted(o.items())), 844 } 845 self.assertEqual(expected, decoded) 840 actual_servers 841 ) 842 self.assertIn( 843 { 844 u"nodeid": u'disconnected_nodeid', 845 u'available_space': 123456, 846 u'connection_status': u'summary', 847 u'last_received_data': 35, 848 u'nickname': u'disconnected_nickname \u263b', 849 u'version': u'1.0', 850 }, 851 actual_servers 852 ) 853 846 854 d.addCallback(_check) 847 855 return d -
TabularUnified src/allmydata/web/root.py ¶
r4cdbf7fb r451d79a 298 298 return json.dumps(result, indent=1) + "\n" 299 299 300 301 300 def _describe_known_servers(self, broker): 302 return sorted(list(301 return list( 303 302 self._describe_server(server) 304 303 for server 305 304 in broker.get_known_servers() 306 ), key=lambda o: sorted(o.items())) 307 305 ) 308 306 309 307 def _describe_server(self, server):
Note: See TracChangeset
for help on using the changeset viewer.