Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
"""
result = run_process([executable] + [b"--help"])
self.assertIn(executable, result.output)
return ScriptTests
class CustomException(Exception):
"""
An exception that will never be raised by real code, useful for
testing.
"""
TWISTED_CHILD_PROCESS_ACTION = ActionType(
u'flocker:testtools:logged_run_process',
fields(command=list),
[],
u'A child process is spawned using Twisted',
)
STDOUT_RECEIVED = MessageType(
u'flocker:testtools:logged_run_process:stdout',
fields(output=str),
u'A chunk of stdout received from a child process',
)
STDERR_RECEIVED = MessageType(
u'flocker:testtools:logged_run_process:stdout',
fields(output=str),
u'A chunk of stderr received from a child process',
)
"""
cluster_state = compute_cluster_state(node_state, additional_node_states,
nonmanifest_datasets)
cluster_configuration = Deployment(
nodes={node_config} | additional_node_config,
leases=leases,
)
changes = deployer.calculate_changes(
cluster_configuration, cluster_state, local_state
)
case.assertEqual(expected_changes, changes)
ADDRESS_IN_USE = MessageType(
u"flocker:test:address_in_use",
fields(ip=unicode, port=int, name=bytes),
)
def _find_process_name(port_number):
"""
Get the name of the process using the given port number.
"""
for connection in psutil.net_connections():
if connection.laddr[1] == port_number:
return psutil.Process(connection.pid).name()
return None
def _retry_on_port_collision(reason, add, cleanup):
"""
Cleanup and re-add a container if it failed to start because of a port
u'txacme:acme:client:registration:create',
fields(Field(u'registration',
methodcaller('to_json'),
u'An ACME registration')),
fields(Field(u'registration',
methodcaller('to_json'),
u'The resulting registration')),
u'Registering with an ACME server')
LOG_ACME_UPDATE_REGISTRATION = ActionType(
u'txacme:acme:client:registration:update',
fields(Field(u'registration',
methodcaller('to_json'),
u'An ACME registration'),
uri=unicode),
fields(Field(u'registration',
methodcaller('to_json'),
u'The updated registration')),
u'Updating a registration')
LOG_ACME_CREATE_AUTHORIZATION = ActionType(
u'txacme:acme:client:authorization:create',
fields(Field(u'identifier',
methodcaller('to_json'),
u'An identifier')),
fields(Field(u'authorization',
methodcaller('to_json'),
u'The authorization')),
u'Creating an authorization')
LOG_ACME_ANSWER_CHALLENGE = ActionType(
u'txacme:acme:client:challenge:answer',
u'The updated registration')),
u'Updating a registration')
LOG_ACME_CREATE_AUTHORIZATION = ActionType(
u'txacme:acme:client:authorization:create',
fields(Field(u'identifier',
methodcaller('to_json'),
u'An identifier')),
fields(Field(u'authorization',
methodcaller('to_json'),
u'The authorization')),
u'Creating an authorization')
LOG_ACME_ANSWER_CHALLENGE = ActionType(
u'txacme:acme:client:challenge:answer',
fields(Field(u'challenge_body',
methodcaller('to_json'),
u'The challenge body'),
Field(u'response',
methodcaller('to_json'),
u'The challenge response')),
fields(Field(u'challenge_resource',
methodcaller('to_json'),
u'The updated challenge')),
u'Answering an authorization challenge')
LOG_ACME_POLL_AUTHORIZATION = ActionType(
u'txacme:acme:client:authorization:poll',
fields(Field(u'authorization',
methodcaller('to_json'),
u'The authorization resource')),
fields(Field(u'authorization',
LOG_JWS_HEAD = ActionType(
u'txacme:jws:http:head',
fields(),
fields(),
u'A JWSClient HEAD request')
LOG_JWS_GET = ActionType(
u'txacme:jws:http:get',
fields(),
fields(),
u'A JWSClient GET request')
LOG_JWS_POST = ActionType(
u'txacme:jws:http:post',
fields(),
fields(),
u'A JWSClient POST request')
LOG_JWS_REQUEST = ActionType(
u'txacme:jws:http:request',
fields(url=unicode),
fields(Field.for_types(u'content_type',
[unicode, None],
u'Content-Type header field'),
code=int),
u'A JWSClient request')
LOG_JWS_CHECK_RESPONSE = ActionType(
u'txacme:jws:http:check-response',
fields(Field.for_types(u'response_content_type',
[unicode, None],
u'Content-Type header field'),
u'txacme:jws:nonce:get',
fields(),
fields(NONCE),
u'Consuming a nonce')
LOG_JWS_ADD_NONCE = ActionType(
u'txacme:jws:nonce:add',
fields(Field.for_types(u'raw_nonce',
[bytes, None],
u'Nonce header field')),
fields(NONCE),
u'Adding a nonce')
LOG_HTTP_PARSE_LINKS = ActionType(
u'txacme:http:parse-links',
fields(raw_link=unicode),
fields(parsed_links=dict),
u'Parsing HTTP Links')
DIRECTORY = Field(u'directory', methodcaller('to_json'), u'An ACME directory')
URL = Field(u'url', methodcaller('asText'), u'A URL object')
LOG_ACME_CONSUME_DIRECTORY = ActionType(
u'txacme:acme:client:from-url',
fields(URL, key_type=unicode, alg=unicode),
fields(DIRECTORY),
u'Creating an ACME client from a remote directory')
LOG_ACME_REGISTER = ActionType(
u'txacme:acme:client:registration:create',
fields(Field(u'registration',
u'Adding a nonce')
LOG_HTTP_PARSE_LINKS = ActionType(
u'txacme:http:parse-links',
fields(raw_link=unicode),
fields(parsed_links=dict),
u'Parsing HTTP Links')
DIRECTORY = Field(u'directory', methodcaller('to_json'), u'An ACME directory')
URL = Field(u'url', methodcaller('asText'), u'A URL object')
LOG_ACME_CONSUME_DIRECTORY = ActionType(
u'txacme:acme:client:from-url',
fields(URL, key_type=unicode, alg=unicode),
fields(DIRECTORY),
u'Creating an ACME client from a remote directory')
LOG_ACME_REGISTER = ActionType(
u'txacme:acme:client:registration:create',
fields(Field(u'registration',
methodcaller('to_json'),
u'An ACME registration')),
fields(Field(u'registration',
methodcaller('to_json'),
u'The resulting registration')),
u'Registering with an ACME server')
LOG_ACME_UPDATE_REGISTRATION = ActionType(
u'txacme:acme:client:registration:update',
fields(Field(u'registration',
methodcaller('to_json'),
fields(Field.for_types(u'response_content_type',
[unicode, None],
u'Content-Type header field'),
expected_content_type=unicode),
fields(),
u'Checking a JWSClient response')
LOG_JWS_GET_NONCE = ActionType(
u'txacme:jws:nonce:get',
fields(),
fields(NONCE),
u'Consuming a nonce')
LOG_JWS_ADD_NONCE = ActionType(
u'txacme:jws:nonce:add',
fields(Field.for_types(u'raw_nonce',
[bytes, None],
u'Nonce header field')),
fields(NONCE),
u'Adding a nonce')
LOG_HTTP_PARSE_LINKS = ActionType(
u'txacme:http:parse-links',
fields(raw_link=unicode),
fields(parsed_links=dict),
u'Parsing HTTP Links')
DIRECTORY = Field(u'directory', methodcaller('to_json'), u'An ACME directory')
URL = Field(u'url', methodcaller('asText'), u'A URL object')
LOG_ACME_CONSUME_DIRECTORY = ActionType(
return cls
class ICommandLineScript(Interface):
"""A script which can be run by ``FlockerScriptRunner``."""
def main(reactor, options):
"""
:param reactor: A Twisted reactor.
:param dict options: A dictionary of configuration options.
:return: A ``Deferred`` which fires when the script has completed.
"""
# This should probably be built-in functionality in Eliot;
# see https://github.com/ClusterHQ/eliot/issues/143
TWISTED_LOG_MESSAGE = MessageType("twisted:log",
fields(error=bool, message=unicode),
u"A log message from Twisted.")
class EliotObserver(object):
"""
A Twisted log observer that logs to Eliot.
"""
def __init__(self, publisher=twisted_log):
"""
:param publisher: A ``LogPublisher`` to capture logs from, or if no
argument is given the default Twisted log system.
"""
self.logger = Logger()
self.publisher = publisher
def __call__(self, msg):
options = DatasetAgentOptions()
# Use CPU time instead of wallclock time.
pr = cProfile.Profile(clock)
signal.signal(signal.SIGUSR1, partial(enable_profiling, pr))
signal.signal(signal.SIGUSR2, partial(disable_profiling, pr, 'dataset'))
return FlockerScriptRunner(
script=agent_script,
options=options,
).main()
LOG_GET_EXTERNAL_IP = ActionType(u"flocker:node:script:get_external_ip",
fields(host=unicode, port=int),
fields(local_ip=unicode),
"An attempt to discover the local IP.")
def _get_external_ip(host, port):
"""
Get an external IP address for this node that can in theory connect to
the given host and port.
Failures are retried until a successful connect.
See https://clusterhq.atlassian.net/browse/FLOC-1751 for a possibly
better solution.
:param host: A host to connect to.
:param port: The port to connect to.