def test_update_for_no_node(self): """Test firmware update for a not existing node.""" with tempfile.NamedTemporaryFile() as file_handle: file_handle.write(HEX_FILE_STR.encode('utf-8')) file_handle.flush() fw_bin = load_fw(file_handle.name) self.gateway.ota.make_update(1, FW_TYPE, FW_VER, fw_bin) ret = self.gateway.logic('1;255;4;0;0;01000200B00626E80300\n') self.assertEqual(ret, None)
def _setup_firmware(self, nids, hex_file_str): """Add node(s) and call update_fw method.""" if not isinstance(nids, list): nids = [nids] sensors = [self._add_sensor(node_id) for node_id in nids] with tempfile.NamedTemporaryFile() as file_handle: file_handle.write(hex_file_str.encode('utf-8')) file_handle.flush() fw_bin = load_fw(file_handle.name) self.gateway.ota.make_update( [sensor.sensor_id for sensor in sensors], FW_TYPE, FW_VER, fw_bin)
def test_restart_fw_update(self): """Test response after a new call to update firmware of node.""" self._setup_firmware(1, HEX_FILE_STR) ret = self.gateway.logic('1;255;4;0;0;01000200B00626E80300\n') # Test that firmware config request generates a response. # A detailed test of the response is done in another test. self.assertIsNotNone(ret) block = BLOCKS - 1 payload = binascii.hexlify(struct.pack('<3H', FW_TYPE, FW_VER, block)).decode('utf-8') ret = self.gateway.logic('1;255;4;0;2;{}\n'.format(payload)) payload = binascii.hexlify(struct.pack('<3H', FW_TYPE, FW_VER, block)).decode('utf-8') blk_data = binascii.unhexlify( PADDED_HEX_STR.encode('utf-8'))[block * FIRMWARE_BLOCK_SIZE:block * FIRMWARE_BLOCK_SIZE + FIRMWARE_BLOCK_SIZE] payload += binascii.hexlify(blk_data).decode('utf-8') self.assertEqual(ret, '1;255;4;0;3;{}\n'.format(payload)) with tempfile.NamedTemporaryFile() as file_handle: file_handle.write(HEX_FILE_STR.encode('utf-8')) file_handle.flush() fw_bin = load_fw(file_handle.name) self.gateway.ota.make_update(1, FW_TYPE, FW_VER, fw_bin) payload = binascii.hexlify( struct.pack('<3H', FW_TYPE, FW_VER, block - 1)).decode('utf-8') ret = self.gateway.logic('1;255;4;0;2;{}\n'.format(payload)) # Test that firmware request does not generate a response. self.assertEqual(ret, None) # Test that firmware config request generates a new response. ret = self.gateway.logic('1;255;4;0;0;01000200B00626E80300\n') self.assertIsNotNone(ret) # Test that firmware request generates all the correct responses. for block in reversed(range(BLOCKS)): payload = binascii.hexlify( struct.pack('<3H', FW_TYPE, FW_VER, block)).decode('utf-8') ret = self.gateway.logic('1;255;4;0;2;{}\n'.format(payload)) payload = binascii.hexlify( struct.pack('<3H', FW_TYPE, FW_VER, block)).decode('utf-8') blk_data = binascii.unhexlify( PADDED_HEX_STR.encode('utf-8'))[block * FIRMWARE_BLOCK_SIZE:block * FIRMWARE_BLOCK_SIZE + FIRMWARE_BLOCK_SIZE] payload += binascii.hexlify(blk_data).decode('utf-8') self.assertEqual(ret, '1;255;4;0;3;{}\n'.format(payload))