diff --git a/packages/omamobile-modem-sit/lib/data_call.py b/packages/omamobile-modem-sit/lib/data_call.py index ebe75f0c4..3c6f191fc 100644 --- a/packages/omamobile-modem-sit/lib/data_call.py +++ b/packages/omamobile-modem-sit/lib/data_call.py @@ -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(): @@ -579,11 +585,10 @@ def deactivate(client, cid=None): # rmnet, 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. diff --git a/packages/omamobile-modem-sit/test/test_attach_bearer.py b/packages/omamobile-modem-sit/test/test_attach_bearer.py index d04df240f..f6145e7a5 100644 --- a/packages/omamobile-modem-sit/test/test_attach_bearer.py +++ b/packages/omamobile-modem-sit/test/test_attach_bearer.py @@ -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'), @@ -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']) diff --git a/packages/omamobile-modem-sit/test/test_data_call.py b/packages/omamobile-modem-sit/test/test_data_call.py index ebc7dc6c4..60a3c68fc 100644 --- a/packages/omamobile-modem-sit/test/test_data_call.py +++ b/packages/omamobile-modem-sit/test/test_data_call.py @@ -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: @@ -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): @@ -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()) @@ -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(', 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 diff --git a/packages/omamobile-modem-sit/version b/packages/omamobile-modem-sit/version index 9f558ed0f..1ff34fb37 100644 --- a/packages/omamobile-modem-sit/version +++ b/packages/omamobile-modem-sit/version @@ -1 +1 @@ -0.3.34 +0.3.35