def test_refresh_signals_failure_on_unexecutable_script_baderrno(self): signal = self.patch(refresh, 'signal') script_name = factory.make_name('script_name') self.patch_scripts_failure(script_name) mock_popen = self.patch(refresh, 'Popen') mock_popen.side_effect = OSError(0, 'Exec format error') system_id = factory.make_name('system_id') consumer_key = factory.make_name('consumer_key') token_key = factory.make_name('token_key') token_secret = factory.make_name('token_secret') url = factory.make_url() refresh.refresh(system_id, consumer_key, token_key, token_secret, url) self.assertThat( signal, MockAnyCall( "%s/metadata/%s/" % (url, MD_VERSION), { 'consumer_secret': '', 'consumer_key': consumer_key, 'token_key': token_key, 'token_secret': token_secret, }, 'WORKING', files={ script_name: b'[Errno 0] Exec format error', '%s.err' % script_name: b'[Errno 0] Exec format error', }, exit_status=2, error='Failed to execute %s [1/1]: 2' % script_name, ))
def test_refresh_signals_starting(self): signal = self.patch(refresh, 'signal') script_name = factory.make_name('script_name') self.patch_scripts_success(script_name) system_id = factory.make_name('system_id') consumer_key = factory.make_name('consumer_key') token_key = factory.make_name('token_key') token_secret = factory.make_name('token_secret') url = factory.make_url() refresh.refresh(system_id, consumer_key, token_key, token_secret, url) self.assertThat( signal, MockAnyCall( "%s/metadata/%s/" % (url, MD_VERSION), { 'consumer_secret': '', 'consumer_key': consumer_key, 'token_key': token_key, 'token_secret': token_secret, }, 'WORKING', 'Starting %s [1/1]' % script_name, ))
def test_refresh_signals_results(self): signal = self.patch(refresh, 'signal') script_name = factory.make_name('script_name') script_content = dedent("""\ #!/bin/bash echo 'test script' echo '{status: skipped}' > $RESULT_PATH """) self.patch_scripts_success(script_name, script_content=script_content) system_id = factory.make_name('system_id') consumer_key = factory.make_name('consumer_key') token_key = factory.make_name('token_key') token_secret = factory.make_name('token_secret') url = factory.make_url() refresh.refresh(system_id, consumer_key, token_key, token_secret, url) self.assertThat( signal, MockAnyCall( "%s/metadata/%s/" % (url, MD_VERSION), { 'consumer_secret': '', 'consumer_key': consumer_key, 'token_key': token_key, 'token_secret': token_secret, }, 'WORKING', files={ script_name: b'test script\n', '%s.out' % script_name: b'test script\n', '%s.err' % script_name: b'', '%s.yaml' % script_name: b'{status: skipped}\n', }, exit_status=0, error='Finished %s [1/1]: 0' % script_name, ))