def test_cancel_during_install(hawkbit, config, bundle_assigned, rauc_dbus_install_success): """ Assign distribution containing bundle to target. Run rauc-hawkbit-updater and cancel the assignment once the installation started. Make sure the cancelation does not disrupt the installation. """ proc = run_pexpect(f'rauc-hawkbit-updater -c "{config}"') proc.expect('MESSAGE: Installing: ') hawkbit.cancel_action() # wait for installation to finish proc.expect('Software bundle installed successfully.') # wait for feedback to arrive at hawkbit server proc.expect(TIMEOUT, timeout=2) proc.terminate(force=True) proc.expect(EOF) cancel = hawkbit.get_action() assert cancel['type'] == 'update' assert cancel['status'] == 'finished' cancel_status = hawkbit.get_action_status() assert cancel_status[0]['type'] == 'finished' assert 'Software bundle installed successfully.' in cancel_status[0]['messages']
def rauc_dbus_install_success(rauc_bundle): """ Creates a RAUC D-Bus dummy interface on the SessionBus mimicing a successful installation on Install(). """ proc = run_pexpect(f'{sys.executable} -m rauc_dbus_dummy {rauc_bundle}', cwd=os.path.dirname(__file__)) proc.expect('Interface published') yield assert proc.isalive() assert proc.terminate(force=True)
def rauc_dbus_install_failure(rauc_bundle): """ Creates a RAUC D-Bus dummy interface on the SessionBus mimicing a failing installation on InstallBundle(). """ proc = run_pexpect(f'{sys.executable} -m rauc_dbus_dummy {rauc_bundle} --completed-code=1', cwd=os.path.dirname(__file__), timeout=None) proc.expect('Interface published') yield assert proc.isalive() assert proc.terminate(force=True)
def _nginx_proxy(options): port = available_port() proxy_config = nginx_config(port, options) try: proc = run_pexpect(f'nginx -c {proxy_config} -p .', timeout=None) except (pexpect.exceptions.EOF, pexpect.exceptions.ExceptionPexpect): pytest.skip('nginx unavailable') try: proc.expect('start worker process ') except pexpect.exceptions.EOF: pytest.skip('nginx failed, use -s to see logs') procs.append(proc) return port
def test_cancel_during_download(hawkbit, adjust_config, bundle_assigned, rate_limited_port): """ Assign distribution containing bundle to target. Run rauc-hawkbit-updater configured to comminucate via rate-limited proxy with hawkBit. Cancel the assignment once the download started and make sure the cancelation is acknowledged and no installation is started. """ port = rate_limited_port('70k') config = adjust_config( {'client': { 'hawkbit_server': f'{hawkbit.host}:{port}' }}) # note: we cannot use -r here since that prevents further polling of the base resource # announcing the cancelation proc = run_pexpect(f'rauc-hawkbit-updater -c "{config}"') proc.expect('Start downloading: ') proc.expect(TIMEOUT, timeout=1) # assuming: # - rauc-hawkbit-updater polls base resource every 5 s for cancelations during download # - download of 512 KB bundle @ 70 KB/s takes ~7.3 s # -> cancelation should be received and processed before download finishes hawkbit.cancel_action() # do not wait longer than 5 s (poll interval) + 3 s (processing margin) proc.expect(f'Received cancelation for action {hawkbit.id["action"]}', timeout=8) proc.expect('Action canceled.') # wait for feedback to arrive at hawkbit server proc.expect(TIMEOUT, timeout=2) proc.terminate(force=True) cancel = hawkbit.get_action() assert cancel['type'] == 'cancel' assert cancel['status'] == 'finished' cancel_status = hawkbit.get_action_status() assert cancel_status[0]['type'] == 'canceled' assert 'Action canceled.' in cancel_status[0]['messages']
def test_install_maintenance_window(hawkbit, config, rauc_bundle, assign_bundle, rauc_dbus_install_success): bundle_size = Path(rauc_bundle).stat().st_size maintenance_start = datetime.now() + timedelta(seconds=15) maintenance_window = { 'maintenanceWindow': { 'schedule': maintenance_start.strftime('%-S %-M %-H ? %-m * %-Y'), 'timezone': timezone_offset_utc(maintenance_start), 'duration': '00:01:00' } } assign_bundle(params=maintenance_window) proc = run_pexpect(f'rauc-hawkbit-updater -c "{config}"') proc.expect( r"hawkBit requested to skip installation, not invoking RAUC yet \(maintenance window is 'unavailable'\)" ) proc.expect('Start downloading') proc.expect('Download complete') proc.expect('File checksum OK') # wait for the maintenance window to become available and the next poll of the base resource proc.expect(TIMEOUT, timeout=30) proc.expect( r"Continuing scheduled deployment .* \(maintenance window is 'available'\)" ) # RAUC bundle should have been already downloaded completely proc.expect(f'Resuming download from offset {bundle_size}') proc.expect('Download complete') proc.expect('File checksum OK') proc.expect('Software bundle installed successfully') # let feedback propagate to hawkBit before termination proc.expect(TIMEOUT, timeout=2) proc.terminate(force=True) proc.expect(EOF) status = hawkbit.get_action_status() assert status[0]['type'] == 'finished'