Skip to content

Commit

Permalink
Added paasta local-run support for tron actions
Browse files Browse the repository at this point in the history
  • Loading branch information
solarkennedy committed Aug 14, 2018
1 parent 51b6033 commit ab04ec5
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 9 deletions.
@@ -0,0 +1,7 @@
jobs:
- name: sample_tron_job
actions:
- name: action1
command: exit 42
- name: action2
command: /bin/true
8 changes: 7 additions & 1 deletion general_itests/local_run.feature
Expand Up @@ -23,4 +23,10 @@ Feature: paasta local-run can be used
Given Docker is available
And a simple service to test
When we run paasta local-run on an interactive job
Then it should have a return code of "42"
Then it should have a return code of "42"

Scenario: Running paasta local-run against a tron action
Given Docker is available
And a simple service to test
When we run paasta local-run on a tron action
Then it should have a return code of "42"
14 changes: 14 additions & 0 deletions general_itests/steps/local_run_steps.py
Expand Up @@ -102,3 +102,17 @@ def local_run_on_chronos_job_with_cmd(context):
"--build "
)
context.return_code, context.output = _run(command=local_run_cmd, timeout=90)


@when('we run paasta local-run on a tron action')
def local_run_on_tron_action(context):
with Path("fake_simple_service"):
local_run_cmd = (
"paasta local-run "
"--yelpsoa-config-root ../fake_soa_configs_local_run/ "
"--service fake_simple_service "
"--cluster test-cluster "
"--instance sample_tron_job.action1 "
"--build "
)
context.return_code, context.output = _run(command=local_run_cmd, timeout=90)
6 changes: 6 additions & 0 deletions paasta_tools/cli/cmds/local_run.py
Expand Up @@ -777,6 +777,10 @@ def format_chronos_command(cmd):
interpolated_command = parse_time_variables(cmd, datetime.datetime.now())
return interpolated_command

def format_tron_command(cmd: str) -> str:
interpolated_command = parse_time_variables(cmd, datetime.datetime.now())
return interpolated_command

def format_adhoc_command(cmd):
return cmd

Expand All @@ -786,6 +790,8 @@ def format_adhoc_command(cmd):
return format_marathon_command
elif framework == 'adhoc':
return format_adhoc_command
elif framework == 'tron':
return format_tron_command
else:
raise ValueError("Invalid Framework")

Expand Down
20 changes: 12 additions & 8 deletions paasta_tools/tron_tools.py
Expand Up @@ -134,6 +134,9 @@ def get_executor(self):
executor = self.config_dict.get('executor', None)
return 'mesos' if executor == 'paasta' else executor

def get_healthcheck_mode(self, _) -> None:
return None

def get_node(self):
return self.config_dict.get('node')

Expand Down Expand Up @@ -168,6 +171,9 @@ def get_calculated_constraints(self):
constraints.extend(self.get_pool_constraints())
return constraints

def get_nerve_namespace(self) -> None:
return None

def validate(self) -> List[str]:
# Use InstanceConfig to validate shared config keys like cpus and mem
error_msgs = super(TronActionConfig, self).validate()
Expand Down Expand Up @@ -455,25 +461,23 @@ def load_tron_instance_config(
raise NoConfigurationForServiceError(f"No tron configuration found for {service} {instance}")


def load_tron_yaml(service: str, tron_cluster: str, soa_dir: str) -> Dict[str, Any]:
def load_tron_yaml(service: str, cluster: str, soa_dir: str) -> Dict[str, Any]:
tronfig_folder = get_tronfig_folder(soa_dir=soa_dir, cluster=cluster)
config = service_configuration_lib.read_extra_service_information(
service_name=service,
extra_info=f'tron-{tron_cluster}',
extra_info=f'tron-{cluster}',
soa_dir=soa_dir,
)
if not config:
tron_conf_path = os.path.join(
os.path.abspath(soa_dir), 'tron', tron_cluster, service + '.yaml',
)
config = service_configuration_lib._read_yaml_file(tron_conf_path)
config = service_configuration_lib._read_yaml_file(os.path.join(tronfig_folder, f"{service}.yaml"))
if not config:
raise NoConfigurationForServiceError('No Tron configuration found for service %s' % service)
return config


def load_tron_service_config(service, tron_cluster, load_deployments=True, soa_dir=DEFAULT_SOA_DIR):
def load_tron_service_config(service, cluster, load_deployments=True, soa_dir=DEFAULT_SOA_DIR):
"""Load all configured jobs for a service, and any additional config values."""
config = load_tron_yaml(service=service, tron_cluster=tron_cluster, soa_dir=soa_dir)
config = load_tron_yaml(service=service, cluster=cluster, soa_dir=soa_dir)
extra_config = {key: value for key, value in config.items() if key != 'jobs'}
job_configs = [
TronJobConfig(
Expand Down

0 comments on commit ab04ec5

Please sign in to comment.