Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def insert_init_command_mock(init_command, **kwargs):
flexmock(module).should_receive('execute_command_without_capture').with_args(
init_command, error_on_warnings=False
).once()
def test_list_archives_with_log_info_calls_borg_with_info_parameter():
flexmock(module).should_receive('execute_command').with_args(
('borg', 'list', '--info', 'repo'),
output_log_level=logging.WARNING,
error_on_warnings=False,
)
insert_logging_mock(logging.INFO)
module.list_archives(
repository='repo',
storage_config={},
list_arguments=flexmock(archive=None, paths=None, json=False, successful=False),
)
def mock_workflow():
"""
Provide just enough structure that workflow can be used to run the plugin.
Defaults below are solely to enable that purpose; tests where those values
matter should provide their own.
"""
workflow = DockerBuildWorkflow("mock:default_built", source=SOURCE)
workflow.source = StubSource()
builder = StubInsideBuilder().for_workflow(workflow)
builder.set_df_path('/mock-path')
base_image_name = ImageName.parse("mock:tag")
builder.parent_images[ImageName.parse("mock:base")] = base_image_name
builder.base_image = base_image_name
builder.tasker = flexmock()
workflow.builder = flexmock(builder)
return workflow
# mock out writing the secret key to ~/.appscale, as well as reading it
# later
secret_key_location = LocalState.get_secret_key_location(self.keyname)
fake_secret = flexmock(name="fake_secret")
fake_secret.should_receive('read').and_return('the secret')
builtins.should_receive('open').with_args(secret_key_location, 'r') \
.and_return(fake_secret)
# and slip in a fake appcontroller to report on the two IP addrs
fake_appcontroller = flexmock(name='fake_appcontroller')
fake_appcontroller.should_receive('get_all_public_ips').with_args(
'the secret').and_return(json.dumps(['public1', 'public2', 'public3']))
fake_appcontroller.should_receive('get_role_info').with_args(
'the secret').and_return(json.dumps(nodes_info['node_info']))
flexmock(SOAPpy)
SOAPpy.should_receive('SOAPProxy').with_args('https://public1:17443') \
.and_return(fake_appcontroller)
# fake the creation of the log directories locally
flexmock(utils)
utils.should_receive('mkdir').with_args('/tmp/foobaz/symlinks/private-ips')
utils.should_receive('mkdir').with_args('/tmp/foobaz/public1')
utils.should_receive('mkdir').with_args('/tmp/foobaz/public1/cassandra')
utils.should_receive('mkdir').with_args('/tmp/foobaz/public1/rabbitmq')
utils.should_receive('mkdir').with_args('/tmp/foobaz/public2')
utils.should_receive('mkdir').with_args('/tmp/foobaz/public2/cassandra')
utils.should_receive('mkdir').with_args('/tmp/foobaz/public2/rabbitmq')
utils.should_receive('mkdir').with_args('/tmp/foobaz/public3')
utils.should_receive('mkdir').with_args('/tmp/foobaz/public3/cassandra')
utils.should_receive('mkdir').with_args('/tmp/foobaz/public3/rabbitmq')
utils.should_receive('mkdir').with_args('/tmp/foobaz/symlinks/load_balancer')
def test_run_action_in_sandcastle(packit_repository_base_with_sandcastle_object):
from sandcastle import Sandcastle
flexmock(Sandcastle).should_receive("get_api_client").and_return(None)
flexmock(SandcastleCommandHandler).should_receive("run_command").with_args(
command=["command", "-a"], env=None, shell=True
).and_return(None).once()
packit_repository_base_with_sandcastle_object.config.actions_handler = "sandcastle"
packit_repository_base_with_sandcastle_object.run_action(
ActionName.pre_sync, None, "arg", "kwarg"
)
server = Openshift('http://apis/', 'http://oauth/authorize',
k8s_api_url='http://api/v1/')
logs = (
u'Lógs'.encode('utf-8'),
u'Lðgs'.encode('utf-8'),
)
fake_response = flexmock(status_code=http_client.OK, headers={})
(fake_response
.should_receive('iter_lines')
.and_yield(*logs)
.with_args(decode_unicode=False))
(flexmock(requests)
.should_receive('request')
.and_return(fake_response))
with caplog.at_level(logging.ERROR):
for result in server.stream_logs('anything'):
assert isinstance(result, six.binary_type)
def test_prune_archives_with_stats_calls_borg_with_stats_parameter():
retention_config = flexmock()
flexmock(module).should_receive('_make_prune_flags').with_args(retention_config).and_return(
BASE_PRUNE_FLAGS
)
insert_execute_command_mock(PRUNE_COMMAND + ('--stats', 'repo'), logging.WARNING)
module.prune_archives(
dry_run=False,
repository='repo',
storage_config={},
retention_config=retention_config,
stats=True,
)
one = {
'public_ip' : 'blarg'
}
two = {
'public_ip' : 'blarg2'
}
nodes = {'node_info': [one, two]}
nodes_contents = json.dumps(nodes)
mock = self.addMockForAppScalefile(appscale, yaml_dumped_contents)
(mock.should_receive('open')
.with_args(appscale.get_locations_json_file('boo'))
.and_return(flexmock(read=lambda: nodes_contents)))
flexmock(subprocess)
subprocess.should_receive('call').with_args(["ssh", "-o",
"StrictHostkeyChecking=no", "-i", appscale.get_key_location('boo'),
"root@blarg2", "tail -F /var/log/appscale/c*"]).and_return().once()
appscale.tail(1, "c*")
def test_copy_transports(tmpdir):
"""
Tests copying trough different transports
:param tmpdir:
"""
with DockerBackend() as backend:
image = backend.ImageClass("docker.io/alpine",
tag="latest",
pull_policy=DockerImagePullPolicy.NEVER)
image2 = image.copy(target_transport=SkopeoTransport.DIRECTORY, target_path=str(tmpdir))
image3 = image2.copy(source_path=str(tmpdir), target_transport=SkopeoTransport.DOCKER_DAEMON, tag="oldest")
(flexmock(image3).should_receive("skopeo_push")
.and_raise(ConuException, "There was and error while copying repository", image3.name))
image4 = image3.copy(target_transport=SkopeoTransport.DOCKER_DAEMON)
assert image4.is_present()
yay = image3.copy("himalaya", target_transport=SkopeoTransport.DOCKER_DAEMON, source_path=str(tmpdir))
assert yay.is_present()
def test_dump_databases_runs_pg_dump_with_username_and_password():
databases = [{'name': 'foo', 'username': 'postgres', 'password': 'trustsome1'}]
flexmock(module).should_receive('make_dump_path').and_return('')
flexmock(module.dump).should_receive('make_database_dump_filename').and_return(
'databases/localhost/foo'
)
flexmock(module.os).should_receive('makedirs')
flexmock(module).should_receive('execute_command').with_args(
(
'pg_dump',
'--no-password',
'--clean',
'--file',
'databases/localhost/foo',
'--username',
'postgres',
'--format',
'custom',
'foo',