Example #1
0
 def __init__(self):
     """Set up a temp directory and store paths to relevant binaries"""
     self.tmp_dir = tempfile.mkdtemp(prefix='tron-')
     cmd_path_func = functools.partial(os.path.join, repo_root, 'bin')
     cmds = 'tronctl', 'trond', 'tronfig', 'tronview'
     self.commands = {cmd: cmd_path_func(cmd) for cmd in cmds}
     self.log_file = self.abs_path('tron.log')
     self.log_conf = self.abs_path('logging.conf')
     self.pid_file = self.abs_path('tron.pid')
     self.config_path = self.abs_path('configs/')
     self.port = find_unused_port()
     self.host = 'localhost'
     self.api_uri = 'http://%s:%s' % (self.host, self.port)
     cclient = client.Client(self.api_uri)
     self.client = ClientProxy(cclient, self.log_file)
     self.setup_logging_conf()
Example #2
0
 def setup_client(self):
     self.url = 'http://localhost:8089/'
     self.client = client.Client(self.url)
     autospec_method(self.client.request)
Example #3
0
 def setup_client(self):
     self.url = 'http://localhost:8089/'
     self.client = client.Client(self.url)
def main():
    args = parse_args()
    filename = args.source
    hostname = urlparse(args.server).hostname
    if filename.endswith(".yaml"):
        tron_client = client.Client(args.server)
        jobs_status = tron_client.jobs()

        is_migration_safe = True
        with open(filename, "r") as f:
            jobs = yaml.load(f)['jobs']
            job_names = [job['name'] for job in jobs]
            if args.job is not None:  # only want to migrate specific job
                # Overwrite existing jobs since only migrating one job
                jobs = [job for job in jobs if job['name'] == args.job]
                if not jobs:
                    raise ValueError(
                        f'Invalid job specified. Options were {job_names}')
                job_name_with_ns = args.old_ns + '.' + args.job
                is_migration_safe = is_migration_safe & check_job_if_running(
                    jobs_status, job_name_with_ns)

            else:  # Migrate all jobs in namespace
                for job_name in job_names:
                    job_name_with_ns = args.old_ns + '.' + job_name
                    is_migration_safe = is_migration_safe & check_job_if_running(
                        jobs_status, job_name_with_ns)

        if is_migration_safe is True:
            print(bcolors.OKBLUE + "Jobs are not running." + bcolors.ENDC)
        else:
            print(bcolors.WARNING +
                  "Some jobs are still running, abort this migration," +
                  bcolors.ENDC)
            return

        # try stop cron
        ssh_command(hostname, "sudo service cron stop")

        # wait unitil yelpsoa-configs branch is merged
        res = input(
            "Merge and push yelpsoa-configs branch. Ready to continue? [y/n]")
        if res == 'y':
            # wait for 10 seconds after pushing the branch
            time.sleep(30)
            # rsyn yelpsoa-configs
            command = "sudo rsync -a --delay-updates --contimeout=10 --timeout=10 --chmod=Du+rwx,go+rx --port=8731 --delete yelpsoa-slave.local.yelpcorp.com::yelpsoa-configs /nail/etc/services"
            ssh_command(hostname, command)

            # migrate jobs to new namespace
            command_jobs('move', jobs, args)

            # update new namespace
            ssh_command(hostname,
                        "sudo paasta_setup_tron_namespace " + args.new_ns)

            # update old namespace if only one job is moving
            if args.job:
                ssh_command(hostname,
                            "sudo paasta_setup_tron_namespace " + args.old_ns)

        #clean up namespace
        ssh_command(hostname, "sudo paasta_cleanup_tron_namespaces")

        # start cron
        ssh_command(hostname, "sudo service cron start")

    return