Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions packages/omamobile-modem-sit/lib/data_call.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,12 @@ def summary(item):
# carrier profile's settings): recorded so that sitd's ownership checks know
# them, and never deactivated or claimed (no ownership record, no release).
MODEM_OWNED = RUN / 'modem-owned-bearers.json'
# The device omamobile-sit-data found carrying the internet bearer, and the
# kernel's view of the network devices. Names of their own, so the tests can
# point them away from the host: on a phone with the modem up, rmnet0 is up,
# and a package build there ran deactivate() against it.
DATA_INTERFACE = RUN / 'data-interface'
NET = Path('/sys/class/net')


def modem_owned_ids():
Expand Down Expand Up @@ -579,11 +585,10 @@ def deactivate(client, cid=None):
# rmnet<CID - 1>, and the device omamobile-sit-data found carrying it
# (data_network.find_device), while that configuration exists.
devices = {f"rmnet{owned['cid'] - 1}"}
recorded = RUN / 'data-interface'
if cid != IMS_CID and recorded.exists():
devices.add(recorded.read_text().strip())
if cid != IMS_CID and DATA_INTERFACE.exists():
devices.add(DATA_INTERFACE.read_text().strip())
for dev in devices:
flags = Path(f'/sys/class/net/{dev}/flags')
flags = NET / dev / 'flags'
if flags.exists() and int(flags.read_text(), 16) & 1:
raise RuntimeError('remove host data configuration first')
# Stock BuildDeactDataCall: CID and normal-release reason.
Expand Down
6 changes: 4 additions & 2 deletions packages/omamobile-modem-sit/test/test_attach_bearer.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ def setUp(self):
self.patches = [patch.object(data_call, 'STATE', root / 'data-session.json'),
patch.object(data_call, 'RESPONSE', root / 'data-call-response.bin'),
patch.object(data_call, 'MODEM_OWNED', root / 'modem-owned-bearers.json'),
patch.object(data_call, 'DATA_INTERFACE', root / 'data-interface'),
patch.object(data_call, 'NET', root / 'net'),
patch.object(data_call, 'SETTLE_QUIET', 0),
patch.object(data_call, 'SETTLE_LIMIT', 0),
patch.object(ims, 'REGISTRATION', root / 'ims-registration.json'),
Expand Down Expand Up @@ -138,8 +140,8 @@ def test_internet_setup_goes_ahead_beside_the_modem_owned_bearer(self):
data_call.activate(modem, 'ims', ims=True)
self.assertFalse(data_call.paths(2)[0].exists())
self.assertEqual([p[0] for i, p in modem.sent if i == 0x0600], [1])
# Releasing the internet bearer leaves the modem's alone (no rmnet
# device exists on the host, so none is up).
# Releasing the internet bearer leaves the modem's alone (the test's
# own /sys/class/net has no device, so none is up).
modem.listed = lambda: listing(item(2))
data_call.deactivate(modem, 1)
self.assertEqual([p for i, p in modem.sent if i == 0x0601], [b'\1\0'])
Expand Down
41 changes: 28 additions & 13 deletions packages/omamobile-modem-sit/test/test_data_call.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,12 @@ def setUp(self):
root = Path(self.directory.name)
self.state = root / 'owned.json'
self.response = root / 'response.bin'
self.net = root / 'net'
self.patches = [patch.object(data_call, 'STATE', self.state),
patch.object(data_call, 'RESPONSE', self.response),
patch.object(data_call, 'MODEM_OWNED', root / 'modem-owned-bearers.json'),
patch.object(data_call, 'DATA_INTERFACE', root / 'data-interface'),
patch.object(data_call, 'NET', self.net),
patch.object(data_call, 'SETTLE_QUIET', 0),
patch.object(data_call, 'SETTLE_LIMIT', 0)]
for item in self.patches:
Expand All @@ -59,6 +63,11 @@ def tearDown(self):
item.stop()
self.directory.cleanup()

def device(self, name, flags):
"""A network device in the test's own /sys/class/net."""
(self.net / name).mkdir(parents=True, exist_ok=True)
(self.net / name / 'flags').write_text(flags + '\n')

def test_rejected_setup_leaves_no_ownership(self):
modem = Modem(status=36)
with self.assertRaises(RuntimeError):
Expand Down Expand Up @@ -183,13 +192,9 @@ def timeout(ident, payload=b'', **kwargs):
def test_failed_deactivation_retains_recovery_record(self):
self.state.write_text(json.dumps({'cid': 1, 'session': 3}))
self.response.write_bytes(b'private')
original = Path.read_text
def read(path, *args, **kwargs):
if str(path) == '/sys/class/net/rmnet0/flags':
return '0x0'
return original(path, *args, **kwargs)
self.device('rmnet0', '0x0')
modem = Modem(fail_release=True)
with patch.object(Path, 'read_text', read), self.assertRaises(TimeoutError):
with self.assertRaises(TimeoutError):
data_call.deactivate(modem)
self.assertEqual(modem.sent, [(0x0601, b'\1\0')])
self.assertTrue(self.state.exists())
Expand All @@ -216,21 +221,31 @@ def existing(ident, payload=b'', **kwargs):
self.assertNotIn(0x061b, [i for i, _ in modem.sent])

def test_deactivation_releases_only_an_allocated_pdu_session(self):
original = Path.read_text
def read(path, *args, **kwargs):
if str(path) == '/sys/class/net/rmnet0/flags':
return '0x0'
return original(path, *args, **kwargs)
self.device('rmnet0', '0x0')
# session 0 (this version) and 3 (a record from 0.3.4 or earlier)
for session, sent in ((0, [(0x0601, b'\1\0'), (0x0602, b'')]),
(3, [(0x0601, b'\1\0'), (0x0602, b''), (0x061b, struct.pack('<i', 3))])):
self.state.write_text(json.dumps({'cid': 1, 'session': session}))
modem = Modem()
with patch.object(Path, 'read_text', read):
data_call.deactivate(modem)
data_call.deactivate(modem)
self.assertEqual(modem.sent, sent)
self.assertFalse(self.state.exists())

def test_deactivation_is_refused_while_a_device_is_up(self):
# rmnet<CID - 1>, or the device omamobile-sit-data recorded
for up, recorded in (('rmnet0', None), ('rmnet3', 'rmnet3')):
self.state.write_text(json.dumps({'cid': 1, 'session': 0}))
self.device('rmnet0', '0x0')
self.device(up, '0x1043')
if recorded:
data_call.DATA_INTERFACE.write_text(recorded + '\n')
modem = Modem()
with self.assertRaises(RuntimeError) as raised:
data_call.deactivate(modem)
self.assertIn('remove host data configuration first', str(raised.exception))
self.assertEqual(modem.sent, [])
self.assertTrue(self.state.exists())

def test_unowned_bearer_blocks_additional_setup(self):
modem = Modem()
request = modem.request
Expand Down
2 changes: 1 addition & 1 deletion packages/omamobile-modem-sit/version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.3.34
0.3.35